1 /*
2 * Copyright (c) 2022 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #include <iostream>
17 #include <vector>
18 #include <dlfcn.h>
19 #include "directory_ex.h"
20 #include "vulkan/vulkan.h"
21
22 #ifdef __aarch64__
23 constexpr const char *LIB_CACULATE_PATH = "/system/lib64/libvulkan.so";
24 #else
25 constexpr const char *LIB_CACULATE_PATH = "/system/lib/libvulkan.so";
26 #endif
27
main(int32_t argc,const char * argv[])28 int32_t main(int32_t argc, const char* argv[])
29 {
30 std::cout << "vulkan wrapper native test is comming :: Loading libvulkan.so..." << std::endl;
31 std::string realPath;
32 if (!OHOS::PathToRealPath(LIB_CACULATE_PATH, realPath)) {
33 std::cout << "file is not real path, file path: " << LIB_CACULATE_PATH << std::endl;
34 return -1;
35 }
36 void* libVulkan = dlopen(realPath.c_str(), RTLD_LOCAL | RTLD_NOW);
37
38 if (libVulkan == nullptr) {
39 std::cout << "vulkan wrapper native test :: dlopen faild " << std::endl;
40 return -1;
41 }
42 std::cout << "vulkan wrapper native test :: dlopen "<< LIB_CACULATE_PATH <<" success" << std::endl;
43
44 // Test Load base function pointers
45 PFN_vkCreateInstance vkCreateInstance = reinterpret_cast<PFN_vkCreateInstance>(
46 dlsym(libVulkan, "vkCreateInstance"));
47 if (vkCreateInstance) {
48 std::cout << "find vulkan vkCreateInstance success" << std::endl;
49 } else {
50 std::cout << "find vulkan vkCreateInstance failed" << std::endl;
51 return -1;
52 }
53
54 std::cout << "vulkan wrapper native test is successful :: Loading libvulkan.so..." << std::endl;
55 return 0;
56 }
57