1 /*
2 * Copyright (C) 2025 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 #include "functionalext.h"
16 #include "common.h"
17
18 #define RESOLVE(handle, symbol) \
19 do { \
20 symbol = reinterpret_cast<int(*)()>(dlsym(handle, #symbol)); \
21 if ((symbol) == 0) { \
22 t_error("RESOLVE: %s not found\n", #symbol); \
23 } \
24 } while (0)
25
Deps_TestDlopen()26 static void Deps_TestDlopen() {
27 const char *libname = "libadlt_base_deps_e.so";
28
29 // init
30 void *handle = dlopen(libname, RTLD_LAZY);
31 if (!handle) {
32 EXPECT_TRUE(__func__, handle);
33 return;
34 }
35
36 // check
37 int (*fE)() = nullptr;
38 RESOLVE(handle, fE);
39 int res = fE();
40 EXPECT_EQ(__func__, res, 2);
41
42 dlclose(handle);
43 }
44
main(int argc,char ** argv)45 int main(int argc, char **argv) {
46 Deps_TestDlopen();
47 return t_status;
48 }
49