2012-10-29 07:05:21 +00:00
|
|
|
# -*-perl-*-
|
|
|
|
$description = "Test the load operator.";
|
|
|
|
|
|
|
|
$details = "Test dynamic loading of modules.";
|
|
|
|
|
|
|
|
# Don't do anything if this system doesn't support "load"
|
|
|
|
exists $FEATURES{load} or return -1;
|
|
|
|
|
2013-02-25 06:38:36 +00:00
|
|
|
my $sobuild = '$(CC) '.($srcdir? "-I$srcdir":'').' -g -shared -fPIC -o $@ $<';
|
|
|
|
|
2012-10-29 07:05:21 +00:00
|
|
|
# First build a shared object
|
|
|
|
# Provide both a default and non-default load symbol
|
|
|
|
|
|
|
|
unlink(qw(testload.c testload.so));
|
|
|
|
|
|
|
|
open(my $F, '> testload.c') or die "open: testload.c: $!\n";
|
|
|
|
print $F <<'EOF' ;
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2013-02-25 06:38:36 +00:00
|
|
|
#include "gnumake.h"
|
2012-10-29 07:05:21 +00:00
|
|
|
|
2013-05-15 02:53:42 +00:00
|
|
|
int plugin_is_GPL_compatible;
|
|
|
|
|
2012-10-29 07:05:21 +00:00
|
|
|
int
|
2013-05-03 13:09:12 +00:00
|
|
|
testload_gmk_setup (gmk_floc *pos)
|
2012-10-29 07:05:21 +00:00
|
|
|
{
|
2013-02-25 06:38:36 +00:00
|
|
|
gmk_eval ("TESTLOAD = implicit", 0);
|
2012-10-29 07:05:21 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2013-05-03 13:09:12 +00:00
|
|
|
explicit_setup (gmk_floc *pos)
|
2012-10-29 07:05:21 +00:00
|
|
|
{
|
2013-02-25 06:38:36 +00:00
|
|
|
gmk_eval ("TESTLOAD = explicit", 0);
|
2012-10-29 07:05:21 +00:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
EOF
|
|
|
|
close($F) or die "close: testload.c: $!\n";
|
|
|
|
|
2013-02-25 06:38:36 +00:00
|
|
|
# Make sure we can compile
|
|
|
|
run_make_test('testload.so: testload.c ; @'.$sobuild, '', '');
|
2012-10-29 07:05:21 +00:00
|
|
|
|
|
|
|
# TEST 1
|
|
|
|
run_make_test(q!
|
2013-02-25 06:38:36 +00:00
|
|
|
PRE := $(.LOADED)
|
2013-01-20 05:55:57 +00:00
|
|
|
load testload.so
|
2013-02-25 06:38:36 +00:00
|
|
|
POST := $(.LOADED)
|
|
|
|
all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
|
2012-10-29 07:05:21 +00:00
|
|
|
!,
|
2013-02-25 06:38:36 +00:00
|
|
|
'', "pre= post=testload.so implicit\n");
|
2012-10-29 07:05:21 +00:00
|
|
|
|
|
|
|
# TEST 2
|
2013-02-25 06:38:36 +00:00
|
|
|
# Load using an explicit function
|
2012-10-29 07:05:21 +00:00
|
|
|
run_make_test(q!
|
2013-02-25 06:38:36 +00:00
|
|
|
PRE := $(.LOADED)
|
2012-10-29 07:05:21 +00:00
|
|
|
load ./testload.so(explicit_setup)
|
2013-02-25 06:38:36 +00:00
|
|
|
POST := $(.LOADED)
|
|
|
|
all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
|
2012-10-29 07:05:21 +00:00
|
|
|
!,
|
2013-02-25 06:38:36 +00:00
|
|
|
'', "pre= post=testload.so explicit\n");
|
2012-10-29 07:05:21 +00:00
|
|
|
|
|
|
|
# TEST 4
|
|
|
|
# Check multiple loads
|
|
|
|
run_make_test(q!
|
2013-02-25 06:38:36 +00:00
|
|
|
PRE := $(.LOADED)
|
2012-10-29 07:05:21 +00:00
|
|
|
load ./testload.so
|
2013-01-20 05:55:57 +00:00
|
|
|
load testload.so(explicit_setup)
|
2013-02-25 06:38:36 +00:00
|
|
|
POST := $(.LOADED)
|
|
|
|
all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
|
2013-01-20 05:55:57 +00:00
|
|
|
!,
|
2013-02-25 06:38:36 +00:00
|
|
|
'', "pre= post=testload.so implicit\n");
|
2013-01-20 05:55:57 +00:00
|
|
|
|
|
|
|
# TEST 5
|
|
|
|
# Check auto-rebuild of loaded file that's out of date
|
|
|
|
utouch(-10, 'testload.so');
|
|
|
|
touch('testload.c');
|
|
|
|
|
|
|
|
run_make_test(q!
|
2013-02-25 06:38:36 +00:00
|
|
|
PRE := $(.LOADED)
|
2013-01-20 05:55:57 +00:00
|
|
|
load ./testload.so
|
2013-02-25 06:38:36 +00:00
|
|
|
POST := $(.LOADED)
|
|
|
|
all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
|
|
|
|
testload.so: testload.c ; @echo "rebuilding $@"; !.$sobuild,
|
|
|
|
'', "rebuilding testload.so\npre= post=testload.so implicit\n");
|
2013-01-20 05:55:57 +00:00
|
|
|
|
|
|
|
# TEST 5
|
|
|
|
# Check auto-rebuild of loaded file when it doesn't exist
|
|
|
|
unlink('testload.so');
|
|
|
|
|
|
|
|
run_make_test(q!
|
2013-02-25 06:38:36 +00:00
|
|
|
PRE := $(.LOADED)
|
2013-01-20 05:55:57 +00:00
|
|
|
-load ./testload.so(explicit_setup)
|
2013-02-25 06:38:36 +00:00
|
|
|
POST := $(.LOADED)
|
|
|
|
all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
|
|
|
|
%.so: %.c ; @echo "rebuilding $@"; !.$sobuild,
|
|
|
|
'', "rebuilding testload.so\npre= post=testload.so explicit\n");
|
2012-10-29 07:05:21 +00:00
|
|
|
|
|
|
|
unlink(qw(testload.c testload.so)) unless $keep;
|
|
|
|
|
|
|
|
# This tells the test driver that the perl test script executed properly.
|
|
|
|
1;
|