diff options
author | Paul Smith <psmith@gnu.org> | 2013-02-25 01:38:36 -0500 |
---|---|---|
committer | Paul Smith <psmith@gnu.org> | 2013-02-25 01:38:36 -0500 |
commit | 5058a94ee717d96285da20423324af3478df175d (patch) | |
tree | fa24d78c8f51c77371464d6c03b3aaf886c8f86a /tests/scripts/features | |
parent | 4baf9ab4564447355b5748d1375959e817771d17 (diff) | |
download | gunmake-5058a94ee717d96285da20423324af3478df175d.tar.gz |
Expand the loadable object support.
Provide a simple API for loaded objects to interact with GNU make. I still
won't guarantee that this API won't change but it's much closer to something
that's supported and provides easy-to-use interfaces with a public header
file.
Diffstat (limited to 'tests/scripts/features')
-rw-r--r-- | tests/scripts/features/load | 69 | ||||
-rw-r--r-- | tests/scripts/features/loadapi | 84 |
2 files changed, 115 insertions, 38 deletions
diff --git a/tests/scripts/features/load b/tests/scripts/features/load index dd3daf8..47267fe 100644 --- a/tests/scripts/features/load +++ b/tests/scripts/features/load @@ -6,6 +6,8 @@ $details = "Test dynamic loading of modules."; # Don't do anything if this system doesn't support "load" exists $FEATURES{load} or return -1; +my $sobuild = '$(CC) '.($srcdir? "-I$srcdir":'').' -g -shared -fPIC -o $@ $<'; + # First build a shared object # Provide both a default and non-default load symbol @@ -16,67 +18,56 @@ print $F <<'EOF' ; #include <string.h> #include <stdio.h> -void define_new_function (void *, const char *, int, int, int, - char *(*)(char *, char **, const char *)); - -char *variable_buffer_output (char *, const char *, unsigned int); - -static char * -func_test(char *o, char **argv, const char *funcname) -{ - return variable_buffer_output (o, funcname, strlen (funcname)); -} +#include "gnumake.h" int -testload_gmake_setup () +testload_gmk_setup () { - define_new_function (0, "func-a", 1, 1, 1, func_test); + gmk_eval ("TESTLOAD = implicit", 0); return 1; } int explicit_setup () { - define_new_function (0, "func-b", 1, 1, 1, func_test); + gmk_eval ("TESTLOAD = explicit", 0); return 1; } EOF close($F) or die "close: testload.c: $!\n"; -run_make_test('testload.so: testload.c ; @$(CC) -g -shared -fPIC -o $@ $<', - '', ''); +# Make sure we can compile +run_make_test('testload.so: testload.c ; @'.$sobuild, '', ''); # TEST 1 run_make_test(q! -all: ; @echo $(func-a foo) $(func-b bar) +PRE := $(.LOADED) load testload.so +POST := $(.LOADED) +all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) !, - '', "func-a\n"); + '', "pre= post=testload.so implicit\n"); # TEST 2 -# Load a different function +# Load using an explicit function run_make_test(q! -all: ; @echo $(func-a foo) $(func-b bar) +PRE := $(.LOADED) load ./testload.so(explicit_setup) +POST := $(.LOADED) +all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) !, - '', "func-b\n"); - -# TEST 3 -# Verify the .LOADED variable -run_make_test(q! -all: ; @echo $(filter testload.so,$(.LOADED)) $(func-a foo) $(func-b bar) -load testload.so(explicit_setup) -!, - '', "testload.so func-b\n"); + '', "pre= post=testload.so explicit\n"); # TEST 4 # Check multiple loads run_make_test(q! -all: ; @echo $(filter testload.so,$(.LOADED)) $(func-a foo) $(func-b bar) +PRE := $(.LOADED) load ./testload.so load testload.so(explicit_setup) +POST := $(.LOADED) +all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) !, - '', "testload.so func-a\n"); + '', "pre= post=testload.so implicit\n"); # TEST 5 # Check auto-rebuild of loaded file that's out of date @@ -84,22 +75,24 @@ utouch(-10, 'testload.so'); touch('testload.c'); run_make_test(q! -all: ; @echo $(func-a foo) $(func-b bar) +PRE := $(.LOADED) load ./testload.so -testload.so: testload.c ; @echo "rebuilding $@"; $(CC) -g -shared -fPIC -o $@ $< -!, - '', "rebuilding testload.so\nfunc-a\n"); +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"); # TEST 5 # Check auto-rebuild of loaded file when it doesn't exist unlink('testload.so'); run_make_test(q! -all: ; @echo $(func-a foo) $(func-b bar) +PRE := $(.LOADED) -load ./testload.so(explicit_setup) -%.so: %.c ; @echo "rebuilding $@"; $(CC) -g -shared -fPIC -o $@ $< -!, - '', "rebuilding testload.so\nfunc-b\n"); +POST := $(.LOADED) +all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD) +%.so: %.c ; @echo "rebuilding $@"; !.$sobuild, + '', "rebuilding testload.so\npre= post=testload.so explicit\n"); unlink(qw(testload.c testload.so)) unless $keep; diff --git a/tests/scripts/features/loadapi b/tests/scripts/features/loadapi new file mode 100644 index 0000000..cecb114 --- /dev/null +++ b/tests/scripts/features/loadapi @@ -0,0 +1,84 @@ +# -*-perl-*- +$description = "Test the shared object load API."; + +$details = "Verify the different aspects of the shared object API."; + +# Don't do anything if this system doesn't support "load" +exists $FEATURES{load} or return -1; + +my $sobuild = '$(CC) '.($srcdir? "-I$srcdir":'').' -g -shared -fPIC -o $@ $<'; + +# First build a shared object +# Provide both a default and non-default load symbol + +unlink(qw(testapi.c testapi.so)); + +open(my $F, '> testapi.c') or die "open: testapi.c: $!\n"; +print $F <<'EOF' ; +#include <string.h> +#include <stdio.h> + +#include "gnumake.h" + +static char * +test_eval (const char *buf) +{ + gmk_eval (buf, 0); + return NULL; +} + +static char * +test_expand (const char *val) +{ + return gmk_expand (val); +} + +static char * +func_test (const char *funcname, int argc, char **argv) +{ + if (strcmp (funcname, "test-expand") == 0) + return test_expand (argv[0]); + + if (strcmp (funcname, "test-eval") == 0) + return test_eval (argv[0]); + + return strdup ("unknown"); +} + +int +testapi_gmk_setup () +{ + gmk_add_function ("test-expand", func_test, 1, 1, 1); + gmk_add_function ("test-eval", func_test, 1, 1, 1); + return 1; +} +EOF +close($F) or die "close: testapi.c: $!\n"; + +run_make_test('testapi.so: testapi.c ; @'.$sobuild, '', ''); + +# TEST 1 +# Check the gmk_expand() function +run_make_test(q! +EXPAND = expansion +all: ; @echo $(test-expand $$(EXPAND)) +load testapi.so +!, + '', "expansion\n"); + +# TEST 2 +# Check the eval operation. Prove that the argument is expanded only once +run_make_test(q! +load testapi.so +TEST = bye +ASSIGN = VAR = $(TEST) $(shell echo there) +$(test-eval $(value ASSIGN)) +TEST = hi +all:;@echo '$(VAR)' +!, + '', "hi there\n"); + +unlink(qw(testapi.c testapi.so)) unless $keep; + +# This tells the test driver that the perl test script executed properly. +1; |