Debian Codegraph @

tests/scripts/features/load

raw
1 # -*-perl-*-
2 $description = "Test the load operator.";
3
4 $details = "Test dynamic loading of modules.";
5
6 # Don't do anything if this system doesn't support "load"
7 exists $FEATURES{load} or return -1;
8
9 # First build a shared object
10 # Provide both a default and non-default load symbol
11
12 unlink(qw(testload.c testload.so));
13
14 open(my $F, '> testload.c') or die "open: testload.c: $!\n";
15 print $F <<'EOF' ;
16 #include <string.h>
17 #include <stdio.h>
18
19 #include "gnumake.h"
20
21 int plugin_is_GPL_compatible;
22
23 int
24 testload_gmk_setup (gmk_floc *pos)
25 {
26 (void)pos;
27 gmk_eval ("TESTLOAD = implicit", 0);
28 return 1;
29 }
30
31 int
32 explicit_setup (gmk_floc *pos)
33 {
34 (void)pos;
35 gmk_eval ("TESTLOAD = explicit", 0);
36 return 1;
37 }
38 EOF
39 close($F) or die "close: testload.c: $!\n";
40
41 # Make sure we can compile
42 # CONFIG_FLAGS are loaded from config-flags.pm and set by configure
43
44 my $sobuild = "$CONFIG_FLAGS{CC} ".($srcdir? "-I$srcdir":'')." $CONFIG_FLAGS{CPPFLAGS} $CONFIG_FLAGS{CFLAGS} -shared -fPIC $CONFIG_FLAGS{LDFLAGS} -o testload.so testload.c";
45
46 my $clog = `$sobuild 2>&1`;
47 if ($? != 0) {
48 $verbose and print "Failed to build testload.so:\n$sobuild\n$_";
49 unlink(qw(testload.c testload.so));
50 return -1;
51 }
52
53 # TEST 1
54 run_make_test(q!
55 PRE := $(.LOADED)
56 load testload.so
57 POST := $(.LOADED)
58 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
59 !,
60 '--warn-undefined-variables', "pre= post=testload.so implicit\n");
61
62 # TEST 2
63 # Load using an explicit function
64 run_make_test(q!
65 PRE := $(.LOADED)
66 load ./testload.so(explicit_setup)
67 POST := $(.LOADED)
68 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
69 !,
70 '', "pre= post=testload.so explicit\n");
71
72 # TEST 4
73 # Check multiple loads
74 run_make_test(q!
75 PRE := $(.LOADED)
76 load ./testload.so
77 load testload.so(explicit_setup)
78 POST := $(.LOADED)
79 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
80 !,
81 '', "pre= post=testload.so implicit\n");
82
83 # TEST 5
84 # Check auto-rebuild of loaded file that's out of date
85 utouch(-10, 'testload.so');
86 touch('testload.c');
87
88 run_make_test(q!
89 PRE := $(.LOADED)
90 load ./testload.so
91 POST := $(.LOADED)
92 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
93 testload.so: testload.c ; @echo "rebuilding $@"; !.$sobuild,
94 '', "rebuilding testload.so\npre= post=testload.so implicit\n");
95
96 # TEST 5
97 # Check auto-rebuild of loaded file when it doesn't exist
98 unlink('testload.so');
99
100 run_make_test(q!
101 PRE := $(.LOADED)
102 -load ./testload.so(explicit_setup)
103 POST := $(.LOADED)
104 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
105 %.so: %.c ; @echo "rebuilding $@"; !.$sobuild,
106 '', "rebuilding testload.so\npre= post=testload.so explicit\n");
107
108 unlink(qw(testload.c testload.so)) unless $keep;
109
110 # This tells the test driver that the perl test script executed properly.
111 1;