libxcoder 5.8.0
Loading...
Searching...
No Matches
ni_libxcoder_dynamic_loading_test.cpp
Go to the documentation of this file.
1/*******************************************************************************
2 *
3 * Copyright (C) 2022 NETINT Technologies
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a copy
6 * of this software and associated documentation files (the "Software"), to deal
7 * in the Software without restriction, including without limitation the rights
8 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 * copies of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
13 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
14 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
15 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
16 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
17 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 *
20 ******************************************************************************/
21
22/*!*****************************************************************************
23 * \file ni_libxcoder_dynamic_loading_test.cpp
24 *
25 * \brief Application to test that ni_libxcoder_dynamic_loading.h successfully
26 * loads all its exported functions
27 ******************************************************************************/
28
29#include <unistd.h>
30#include <sys/ioctl.h>
31#include <sys/types.h>
32
33#include <fcntl.h>
34#include <errno.h>
35#define _NETINT_LIBXCODER_DYNAMIC_LOADING_TEST_ // NOLINT(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp)
37
38int main(int argc, char **argv)
39{
40 (void)argc;
41 (void)argv;
42 void *handle;
43 const char *error;
44 const NETINTLibxcoderAPI ni_libxcoder_api_dl;
46 int failed_func_ptr_check = 0;
47
48 handle = dlopen ("libxcoder.so", RTLD_NOW);
49 if (!handle) {
50 (void)fprintf(stderr, "%s\n", dlerror()); // NOLINT(concurrency-mt-unsafe) - single-threaded CLI tool
51 exit(1); // NOLINT(concurrency-mt-unsafe) - single-threaded CLI tool
52 }
53
54 // Check load error on individual function
55 // functionList.niSetVui = reinterpret_cast<decltype(ni_set_vui)*>(dlsym(handle,"ni_set_vui"));
56 // if ((error = dlerror()) != NULL) {
57 // fprintf(stderr, "%s\n", error);
58 // exit(1);
59 // }
60
61 ni_libxcoder_api_dl.NiLibxcoderAPICreateInstance(handle, &functionList);
62 error = dlerror(); // NOLINT(concurrency-mt-unsafe) - single-threaded CLI tool
63 if (error != NULL) {
64 (void)fprintf(stderr, "%s\n", error);
65 exit(1); // NOLINT(concurrency-mt-unsafe) - single-threaded CLI tool
66 }
67 printf("Dynamically loaded functionList\n");
68
69 for (int i = 0; i < (int)((sizeof(NETINT_LIBXCODER_API_FUNCTION_LIST) / \
70 sizeof(void *))); i++)
71 {
72 if (((void *) *(((void **) &functionList) + i)) == NULL)
73 {
74 (void)fprintf(stderr, "Failed to load function pointer at function %d in "
75 "NETINT_LIBXCODER_API_FUNCTION_LIST\n", i);
76 failed_func_ptr_check = 1;
77 }
78 }
79
80 if (!failed_func_ptr_check)
81 {
82 printf("All functions in functionList were loaded.\nPass\n");
83 }
84
85 dlclose(handle);
86 exit(failed_func_ptr_check); // NOLINT(concurrency-mt-unsafe) - single-threaded CLI tool
87}
static void NiLibxcoderAPICreateInstance(void *lib, NETINT_LIBXCODER_API_FUNCTION_LIST *functionList)
int main()
Definition client.cpp:51
Libxcoder API dynamic loading support for Linux.