2 $description = "Test the load operator.";
4 $details = "Test dynamic loading of modules.";
6 # Don't do anything if this system doesn't support "load"
7 exists $FEATURES{'load'} or return -1;
9 my $cc = get_config('CC');
11 $verbose and print "Skipping load test: no CC defined\n";
15 # First build a shared object
16 # Provide both a default and non-default load symbol
18 unlink(qw(testload.c testload.so));
20 open(my $F, '> testload.c') or die "open: testload.c: $!\n";
24 char* getenv (const char*);
26 int plugin_is_GPL_compatible;
28 int testload_gmk_setup (gmk_floc *);
29 int explicit_setup (gmk_floc *);
32 testload_gmk_setup (gmk_floc *pos)
35 gmk_eval ("TESTLOAD = implicit", 0);
36 if (getenv("TESTAPI_KEEP"))
42 explicit_setup (gmk_floc *pos)
45 gmk_eval ("TESTLOAD = explicit", 0);
46 if (getenv("TESTAPI_KEEP"))
51 close($F) or die "close: testload.c: $!\n";
53 # Make sure we can compile
55 my $cppflags = get_config('CPPFLAGS') . ($srcdir ? " -I$srcdir/src" : '');
56 my $cflags = get_config('CFLAGS') . ' -fPIC';
57 my $ldflags = get_config('LDFLAGS') . ' -shared';
58 my $sobuild = "$cc $cppflags $cflags $ldflags -o testload.so testload.c";
60 my $clog = `$sobuild 2>&1`;
62 $verbose and print "Failed to build testload.so:\n$sobuild\n$clog";
71 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
73 '--warn-undefined-variables', "pre= post=testload.so implicit\n");
76 # Load using an explicit function
79 load ./testload.so(explicit_setup)
81 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
83 '', "pre= post=testload.so explicit\n");
86 # Check multiple loads
90 load testload.so(explicit_setup)
92 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
94 '', "pre= post=testload.so implicit\n");
97 # Check auto-rebuild of loaded file that's out of date
98 utouch(-10, 'testload.so');
105 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
106 testload.so: testload.c ; @echo "rebuilding $@"; !.$sobuild,
107 '', "rebuilding testload.so\npre= post=testload.so implicit\n");
110 # Check auto-rebuild of loaded file when it doesn't exist
111 unlink('testload.so');
115 -load ./testload.so(explicit_setup)
117 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
118 %.so: %.c ; @echo "rebuilding $@"; !.$sobuild,
119 '', "rebuilding testload.so\npre= post=testload.so explicit\n");
122 # Test that the loaded shared object is present in .LOADED when the setup
123 # routine returns -1.
124 $ENV{TESTAPI_KEEP} = 1;
129 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
131 '--warn-undefined-variables', "pre= post=testload.so implicit\n");
133 # Check that we don't auto-rebuild of loaded file that's out of date
134 # if we return -1 from the setup
135 utouch(-10, 'testload.so');
138 $ENV{TESTAPI_KEEP} = 1;
143 all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
144 testload.so: testload.c ; @echo "rebuilding $@"; !.$sobuild,
145 '', "pre= post=testload.so implicit\n");
147 unlink(qw(testload.c testload.so)) unless $keep;
149 # This tells the test driver that the perl test script executed properly.