-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.c
123 lines (94 loc) · 3.31 KB
/
main_test.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/* Copyright (C) 2020 ~ 2021 Uniontech Software Technology Co., Ltd.
* file name: main_test.c
* Author: shuaijie <[email protected]>
* Maintainer: shuaijie <[email protected]>
* descrition: This file is part of test libgpuinfo.
*
* This program is free software: you can redistribute it and/or modify,it underthe terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or any later version.
*
* This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.You should have
* received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// #include "./usr/include/libgpuinfo/libgpuinfo_decoder.h"
#include "../src/libgpuinfo/libgpuinfo_decoder.h"
// gcc main_test.c -g -o test -ldl
#include <getopt.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <locale.h>
#include <dlfcn.h>
#include <limits.h>
#include <time.h>
#include "../build/config/version.h"
#include <dirent.h>
static int countOpenFDs(void)
{
DIR *dir = opendir("/proc/self/fd");
int count = 0;
if (!dir) {
fprintf(stderr, "Couldn't open /proc/self/fd; skipping file descriptor "
"leak test\n");
return 0;
}
while (readdir(dir) != NULL) {
count++;
}
closedir(dir);
return count;
}
// gcc main_test.c -g -o test -ldl
// gcc -shared -fpic -lm -ldl -o libtest.so pci_wrapper.c vdpau_wrapper.c
#define LUSR_LIB_PATH "../build/src/libgpuinfo"
void main(void)
{
struct timeval tpstart,tpend;
float timeuse;
char path[256];
snprintf( path, 255, "%s/libgpuinfo.so", LUSR_LIB_PATH );
//printf("path:%s\n",path);
int nOpenFDs = countOpenFDs();
gettimeofday(&tpstart,NULL);
void *driver = NULL;
driver = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
if( NULL == driver)
{
printf("open( %s )fail\n ",path);
// dlclose(driver);
snprintf( path, 255, "%s/libgpuinfo.so", USR_LIB_PATH );
driver = dlopen(path, RTLD_LAZY | RTLD_GLOBAL);
if( NULL == driver)
goto fail;
}
else{
printf("open( %s ) sucess\n ",path);
}
unsigned int (*vdp_Iter_decoderInfo)(decoder_profile , VDP_Decoder_t *) =NULL;
vdp_Iter_decoderInfo = dlsym(driver, "vdp_Iter_decoderInfo");
VDP_Decoder_t head ;
int i;
i = vdp_Iter_decoderInfo( H264, &head );
printf("--2-test: %d, %s",i, head.ret_info);
i = vdp_Iter_decoderInfo( MPEG2, &head );
printf("--3-test: %d, %s",i, head.ret_info);
i = vdp_Iter_decoderInfo( VC1, &head );
printf("--2-test: %d, %s",i, head.ret_info);
gettimeofday(&tpend,NULL);
dlclose(driver);
timeuse=1000000*(tpend.tv_sec-tpstart.tv_sec)+tpend.tv_usec-tpstart.tv_usec;
timeuse/=1000;
printf( "Used Time:%f ms\n ",timeuse);
// Make sure no file descriptors were leaked.
if (countOpenFDs() != nOpenFDs) {
fprintf(stderr, "Mismatch in the number %d of open file descriptors!\n", countOpenFDs()-nOpenFDs);
return ;
}
else
fprintf(stderr, "ok match in the number of open file descriptors!\n");
fail:
return ;
}