libxcoder 5.6.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_
37
38int main(int argc, char **argv)
39{
40 void *handle;
41 char *error;
42 NETINTLibxcoderAPI ni_libxcoder_api_dl;
44 int failed_func_ptr_check = 0;
45
46 handle = dlopen ("libxcoder.so", RTLD_NOW);
47 if (!handle) {
48 fprintf(stderr, "%s\n", dlerror());
49 exit(1);
50 }
51
52 // Check load error on individual function
53 // functionList.niSetVui = reinterpret_cast<decltype(ni_set_vui)*>(dlsym(handle,"ni_set_vui"));
54 // if ((error = dlerror()) != NULL) {
55 // fprintf(stderr, "%s\n", error);
56 // exit(1);
57 // }
58
59 ni_libxcoder_api_dl.NiLibxcoderAPICreateInstance(handle, &functionList);
60 if ((error = dlerror()) != NULL) {
61 fprintf(stderr, "%s\n", error);
62 exit(1);
63 }
64 printf("Dynamically loaded functionList\n");
65
66 for (int i = 0; i < (int)((sizeof(NETINT_LIBXCODER_API_FUNCTION_LIST) / \
67 sizeof(void *))); i++)
68 {
69 if (((void *) *(((void **) &functionList) + i)) == NULL)
70 {
71 fprintf(stderr, "Failed to load function pointer at function %d in "
72 "NETINT_LIBXCODER_API_FUNCTION_LIST\n", i);
73 failed_func_ptr_check = 1;
74 }
75 }
76
77 if (!failed_func_ptr_check)
78 {
79 printf("All functions in functionList were loaded.\nPass\n");
80 }
81
82 dlclose(handle);
83 exit(failed_func_ptr_check);
84}
static void NiLibxcoderAPICreateInstance(void *lib, NETINT_LIBXCODER_API_FUNCTION_LIST *functionList)
int main()
Definition client.cpp:51
Libxcoder API dynamic loading support for Linux.