Mercurial > hg > freeDiameter
annotate tests/testloadext.c @ 1534:c83e60f28632
dict_dcca_3gpp: simplify rule creation
Refactor local_rules_definition to simplify rule creation
(to avoid c99 struct initialisers that result in long lines).
No change to generated rules.
author | Luke Mewburn <luke@mewburn.net> |
---|---|
date | Mon, 20 Apr 2020 12:12:42 +1000 |
parents | 4a9f08d6b6ba |
children |
rev | line source |
---|---|
669
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
1 /********************************************************************************************************* |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
2 * Software License Agreement (BSD License) * |
740
4a9f08d6b6ba
Updated my mail address
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
695
diff
changeset
|
3 * Author: Sebastien Decugis <sdecugis@freediameter.net> * |
669
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
4 * * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
5 * Copyright (c) 2011, WIDE Project and NICT * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
6 * All rights reserved. * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
7 * * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
8 * Redistribution and use of this software in source and binary forms, with or without modification, are * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
9 * permitted provided that the following conditions are met: * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
10 * * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
11 * * Redistributions of source code must retain the above * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
12 * copyright notice, this list of conditions and the * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
13 * following disclaimer. * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
14 * * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
15 * * Redistributions in binary form must reproduce the above * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
16 * copyright notice, this list of conditions and the * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
17 * following disclaimer in the documentation and/or other * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
18 * materials provided with the distribution. * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
19 * * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
20 * * Neither the name of the WIDE Project or NICT nor the * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
21 * names of its contributors may be used to endorse or * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
22 * promote products derived from this software without * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
23 * specific prior written permission of WIDE Project and * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
24 * NICT. * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
25 * * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
28 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
29 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
30 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
32 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
34 *********************************************************************************************************/ |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
35 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
36 #include "tests.h" |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
37 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
38 #ifndef BUILD_DIR |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
39 #error "Missing BUILD_DIR information" |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
40 #endif /* BUILD_DIR */ |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
41 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
42 #include <sys/types.h> |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
43 #include <dirent.h> |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
44 #include <libgen.h> |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
45 #include <dlfcn.h> |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
46 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
47 /* Main test routine */ |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
48 int main(int argc, char *argv[]) |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
49 { |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
50 DIR *dir; |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
51 struct dirent *dp; |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
52 char fullname[512]; |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
53 int pathlen; |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
54 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
55 /* First, initialize the daemon modules */ |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
56 INIT_FD(); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
57 CHECK( 0, fd_queues_init() ); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
58 CHECK( 0, fd_msg_init() ); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
59 CHECK( 0, fd_rtdisp_init() ); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
60 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
61 /* Find all extensions which have been compiled along the test */ |
692 | 62 TRACE_DEBUG(INFO, "Loading from: '%s'", BUILD_DIR "/extensions"); |
669
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
63 CHECK( 0, (dir = opendir (BUILD_DIR "/extensions")) == NULL ? 1 : 0 ); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
64 pathlen = snprintf(fullname, sizeof(fullname), BUILD_DIR "/extensions/"); |
676
684f9e0e0c96
Clean termination of tests when possible
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
669
diff
changeset
|
65 |
669
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
66 while ((dp = readdir (dir)) != NULL) { |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
67 char * dot = strrchr(dp->d_name, '.'); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
68 if (dot && !(strcmp(dot, ".fdx"))) { |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
69 /* We found a file with name *.fdx, attempt to load it */ |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
70 void *hdl, * ep; |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
71 snprintf(fullname + pathlen, sizeof(fullname) - pathlen, "%s", dp->d_name); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
72 |
692 | 73 TRACE_DEBUG(INFO, "Extension: '%s'", dp->d_name); |
669
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
74 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
75 /* load */ |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
76 hdl = dlopen(fullname, RTLD_NOW | RTLD_GLOBAL); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
77 if (!hdl) { |
692 | 78 TRACE_DEBUG(INFO, "Unable to load '%s': %s.", fullname, dlerror()); |
669
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
79 } |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
80 CHECK( 0, hdl == NULL ? 1 : 0 ); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
81 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
82 /* resolve entry */ |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
83 ep = dlsym( hdl, "fd_ext_init" ); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
84 if (!ep) { |
692 | 85 TRACE_DEBUG(INFO, "No 'fd_ext_init' entry point in '%s': %s.", fullname, dlerror()); |
669
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
86 } |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
87 CHECK( 0, ep == NULL ? 1 : 0 ); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
88 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
89 /* Done, now unload */ |
695
712a0bb8d3bf
Add ability to skip dlclose() calls since it creates problems on FreeBSD8.1 64bits
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
692
diff
changeset
|
90 #ifndef SKIP_DLCLOSE |
712a0bb8d3bf
Add ability to skip dlclose() calls since it creates problems on FreeBSD8.1 64bits
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
692
diff
changeset
|
91 CHECK( 0, dlclose(hdl) ); |
712a0bb8d3bf
Add ability to skip dlclose() calls since it creates problems on FreeBSD8.1 64bits
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
692
diff
changeset
|
92 #endif /* SKIP_DLCLOSE */ |
669
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
93 } |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
94 } |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
95 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
96 CHECK( 0, closedir(dir) ); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
97 |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
98 PASSTEST(); |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
99 } |
26482481d4ef
New test to check if there are linking problems with built extensions
Sebastien Decugis <sdecugis@nict.go.jp>
parents:
diff
changeset
|
100 |