aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Gu <timothygu99@gmail.com>2014-02-10 03:30:50 +0000
committerTimothy Gu <timothygu99@gmail.com>2014-02-10 03:30:50 +0000
commitf1642131d79a4854164c47ca8abb4821aa74682c (patch)
treeee1530e122ee20f412f1602cd04188d22d1b351c
parent507ae09fede6b17eddc5bff1a0b0572a3f3db37b (diff)
downloaddlfcn-win32-f1642131d79a4854164c47ca8abb4821aa74682c.tar.gz
dlfcn-win32-f1642131d79a4854164c47ca8abb4821aa74682c.tar.bz2
dlfcn-win32-f1642131d79a4854164c47ca8abb4821aa74682c.zip
test: more updates and fixes
-rw-r--r--test.c80
1 files changed, 43 insertions, 37 deletions
diff --git a/test.c b/test.c
index 546a05b..8977fbc 100644
--- a/test.c
+++ b/test.c
@@ -23,10 +23,19 @@
23 23
24/* If these dlclose's fails, we don't care as the handles are going to be 24/* If these dlclose's fails, we don't care as the handles are going to be
25 closed eventually when the program ends. */ 25 closed eventually when the program ends. */
26#define CLOSE_LIB dlclose( library ); 26#define CLOSE_LIB dlclose( library )
27#define CLOSE_GLOBAL dlclose( global ); 27#define CLOSE_GLOBAL dlclose( global )
28 28
29#define RETURN_ERROR return 1; 29#define RETURN_ERROR return 1
30#define RUNFUNC do { \
31 ret = function (); \
32 if( ret != 0) { \
33 CLOSE_LIB; \
34 CLOSE_GLOBAL; \
35 RETURN_ERROR; \
36 } \
37 } while( 0 )
38
30 39
31/* This is what this test does: 40/* This is what this test does:
32 * - Open library with RTLD_GLOBAL 41 * - Open library with RTLD_GLOBAL
@@ -45,6 +54,8 @@
45 * - Get symbol from library through global object <- works 54 * - Get symbol from library through global object <- works
46 * - Close library 55 * - Close library
47 * - Close global object 56 * - Close global object
57 *
58 * If one test fails, the program terminates itself.
48 */ 59 */
49 60
50int main() 61int main()
@@ -60,6 +71,7 @@ int main()
60 { 71 {
61 error = dlerror( ); 72 error = dlerror( );
62 printf( "ERROR\tCould not open library globally: %s\n", error ? error : "" ); 73 printf( "ERROR\tCould not open library globally: %s\n", error ? error : "" );
74 RETURN_ERROR;
63 } 75 }
64 else 76 else
65 printf( "SUCCESS\tOpened library globally: %p\n", library ); 77 printf( "SUCCESS\tOpened library globally: %p\n", library );
@@ -69,8 +81,8 @@ int main()
69 { 81 {
70 error = dlerror( ); 82 error = dlerror( );
71 printf( "ERROR\tCould not open global handle: %s\n", error ? error : "" ); 83 printf( "ERROR\tCould not open global handle: %s\n", error ? error : "" );
72 CLOSE_LIB 84 CLOSE_LIB;
73 RETURN_ERROR 85 RETURN_ERROR;
74 } 86 }
75 else 87 else
76 printf( "SUCCESS\tGot global handle: %p\n", global ); 88 printf( "SUCCESS\tGot global handle: %p\n", global );
@@ -81,15 +93,14 @@ int main()
81 error = dlerror( ); 93 error = dlerror( );
82 printf( "ERROR\tCould not get symbol from library handle: %s\n", 94 printf( "ERROR\tCould not get symbol from library handle: %s\n",
83 error ? error : "" ); 95 error ? error : "" );
84 CLOSE_LIB 96 CLOSE_LIB;
85 CLOSE_GLOBAL 97 CLOSE_GLOBAL;
86 RETURN_ERROR 98 RETURN_ERROR;
87 } 99 }
88 else 100 else
89 printf( "SUCCESS\tGot symbol from library handle: %p\n", function ); 101 printf( "SUCCESS\tGot symbol from library handle: %p\n", function );
90 102
91 if( function ) 103 RUNFUNC;
92 function( );
93 104
94 function = dlsym( global, "function" ); 105 function = dlsym( global, "function" );
95 if( !function ) 106 if( !function )
@@ -97,22 +108,21 @@ int main()
97 error = dlerror( ); 108 error = dlerror( );
98 printf( "ERROR\tCould not get symbol from global handle: %s\n", 109 printf( "ERROR\tCould not get symbol from global handle: %s\n",
99 error ? error : "" ); 110 error ? error : "" );
100 CLOSE_LIB 111 CLOSE_LIB;
101 CLOSE_GLOBAL 112 CLOSE_GLOBAL;
102 RETURN_ERROR 113 RETURN_ERROR;
103 } 114 }
104 else 115 else
105 printf( "SUCCESS\tGot symbol from global handle: %p\n", function ); 116 printf( "SUCCESS\tGot symbol from global handle: %p\n", function );
106 117
107 if( function ) 118 RUNFUNC;
108 function( );
109 119
110 ret = dlclose( library ); 120 ret = dlclose( library );
111 if( ret ) 121 if( ret )
112 { 122 {
113 error = dlerror( ); 123 error = dlerror( );
114 printf( "ERROR\tCould not close library: %s\n", error ? error : "" ); 124 printf( "ERROR\tCould not close library: %s\n", error ? error : "" );
115 RETURN_ERROR 125 RETURN_ERROR;
116 } 126 }
117 else 127 else
118 printf( "SUCCESS\tClosed library.\n" ); 128 printf( "SUCCESS\tClosed library.\n" );
@@ -122,9 +132,9 @@ int main()
122 { 132 {
123 error = dlerror( ); 133 error = dlerror( );
124 printf( "ERROR\tCould not open library locally: %s\n", error ? error : "" ); 134 printf( "ERROR\tCould not open library locally: %s\n", error ? error : "" );
125 CLOSE_LIB 135 CLOSE_LIB;
126 CLOSE_GLOBAL 136 CLOSE_GLOBAL;
127 RETURN_ERROR 137 RETURN_ERROR;
128 } 138 }
129 else 139 else
130 printf( "SUCCESS\tOpened library locally: %p\n", library ); 140 printf( "SUCCESS\tOpened library locally: %p\n", library );
@@ -135,39 +145,35 @@ int main()
135 error = dlerror( ); 145 error = dlerror( );
136 printf( "ERROR\tCould not get symbol from library handle: %s\n", 146 printf( "ERROR\tCould not get symbol from library handle: %s\n",
137 error ? error : "" ); 147 error ? error : "" );
138 CLOSE_LIB 148 CLOSE_LIB;
139 CLOSE_GLOBAL 149 CLOSE_GLOBAL;
140 RETURN_ERROR 150 RETURN_ERROR;
141 } 151 }
142 else 152 else
143 printf( "SUCCESS\tGot symbol from library handle: %p\n", function ); 153 printf( "SUCCESS\tGot symbol from library handle: %p\n", function );
144 154
145 if( function ) 155 RUNFUNC;
146 function( );
147 156
148 function = dlsym( global, "function" ); 157 function = dlsym( global, "function" );
149 if( function ) 158 if( function )
150 { 159 {
151 error = dlerror( ); 160 error = dlerror( );
152 printf( "ERROR\tGot local symbol from global handle: %s\n", 161 printf( "ERROR\tGot local symbol from global handle: %s @ %p\n",
153 error ? error : "" ); 162 error ? error : "", function );
154 CLOSE_LIB 163 CLOSE_LIB;
155 CLOSE_GLOBAL 164 CLOSE_GLOBAL;
156 RETURN_ERROR 165 RETURN_ERROR;
157 } 166 }
158 else 167 else
159 printf( "SUCCESS\tDid not get local symbol from global handle: %p\n", function ); 168 printf( "SUCCESS\tDid not get local symbol from global handle.\n" );
160
161 if( function )
162 function( );
163 169
164 ret = dlclose( library ); 170 ret = dlclose( library );
165 if( ret ) 171 if( ret )
166 { 172 {
167 error = dlerror( ); 173 error = dlerror( );
168 printf( "ERROR\tCould not close library: %s\n", error ? error : "" ); 174 printf( "ERROR\tCould not close library: %s\n", error ? error : "" );
169 CLOSE_GLOBAL 175 CLOSE_GLOBAL;
170 RETURN_ERROR 176 RETURN_ERROR;
171 } 177 }
172 else 178 else
173 printf( "SUCCESS\tClosed library.\n" ); 179 printf( "SUCCESS\tClosed library.\n" );
@@ -177,7 +183,7 @@ int main()
177 { 183 {
178 error = dlerror( ); 184 error = dlerror( );
179 printf( "ERROR\tCould not close global handle: %s\n", error ? error : "" ); 185 printf( "ERROR\tCould not close global handle: %s\n", error ? error : "" );
180 RETURN_ERROR 186 RETURN_ERROR;
181 } 187 }
182 else 188 else
183 printf( "SUCCESS\tClosed global handle.\n" ); 189 printf( "SUCCESS\tClosed global handle.\n" );