Imported Upstream version 4.0
[platform/upstream/make.git] / tests / scripts / features / load
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 my $sobuild = '$(CC) '.($srcdir? "-I$srcdir":'').' -g -shared -fPIC -o $@ $<';
10
11 # First build a shared object
12 # Provide both a default and non-default load symbol
13
14 unlink(qw(testload.c testload.so));
15
16 open(my $F, '> testload.c') or die "open: testload.c: $!\n";
17 print $F <<'EOF' ;
18 #include <string.h>
19 #include <stdio.h>
20
21 #include "gnumake.h"
22
23 int plugin_is_GPL_compatible;
24
25 int
26 testload_gmk_setup (gmk_floc *pos)
27 {
28     gmk_eval ("TESTLOAD = implicit", 0);
29     return 1;
30 }
31
32 int
33 explicit_setup (gmk_floc *pos)
34 {
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 run_make_test('testload.so: testload.c ; @'.$sobuild, '', '');
43
44 # TEST 1
45 run_make_test(q!
46 PRE := $(.LOADED)
47 load testload.so
48 POST := $(.LOADED)
49 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
50 !,
51               '', "pre= post=testload.so implicit\n");
52
53 # TEST 2
54 # Load using an explicit function
55 run_make_test(q!
56 PRE := $(.LOADED)
57 load ./testload.so(explicit_setup)
58 POST := $(.LOADED)
59 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
60 !,
61               '', "pre= post=testload.so explicit\n");
62
63 # TEST 4
64 # Check multiple loads
65 run_make_test(q!
66 PRE := $(.LOADED)
67 load ./testload.so
68 load testload.so(explicit_setup)
69 POST := $(.LOADED)
70 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
71 !,
72               '', "pre= post=testload.so implicit\n");
73
74 # TEST 5
75 # Check auto-rebuild of loaded file that's out of date
76 utouch(-10, 'testload.so');
77 touch('testload.c');
78
79 run_make_test(q!
80 PRE := $(.LOADED)
81 load ./testload.so
82 POST := $(.LOADED)
83 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
84 testload.so: testload.c ; @echo "rebuilding $@"; !.$sobuild,
85               '', "rebuilding testload.so\npre= post=testload.so implicit\n");
86
87 # TEST 5
88 # Check auto-rebuild of loaded file when it doesn't exist
89 unlink('testload.so');
90
91 run_make_test(q!
92 PRE := $(.LOADED)
93 -load ./testload.so(explicit_setup)
94 POST := $(.LOADED)
95 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
96 %.so: %.c ; @echo "rebuilding $@"; !.$sobuild,
97               '', "rebuilding testload.so\npre= post=testload.so explicit\n");
98
99 unlink(qw(testload.c testload.so)) unless $keep;
100
101 # This tells the test driver that the perl test script executed properly.
102 1;