diff options
Diffstat (limited to 'tests/scripts')
-rw-r--r-- | tests/scripts/features/load | 69 | ||||
-rw-r--r-- | tests/scripts/features/loadapi | 84 | ||||
-rw-r--r-- | tests/scripts/functions/guile | 8 |
3 files changed, 121 insertions, 40 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; diff --git a/tests/scripts/functions/guile b/tests/scripts/functions/guile index 93a18ab..c63bec9 100644 --- a/tests/scripts/functions/guile +++ b/tests/scripts/functions/guile @@ -44,8 +44,12 @@ x:;@echo '$(VAR)' '', "hi"); # Verify the gmk-eval function +# Prove that the string is expanded only once (by eval) run_make_test(q! -$(guile (gmk-eval "VAR = hi $(shell echo there)")) +TEST = bye +EVAL = VAR = $(TEST) $(shell echo there) +$(guile (gmk-eval "$(value EVAL)")) +TEST = hi x:;@echo '$(VAR)' !, '', "hi there"); @@ -80,7 +84,7 @@ define fib ;; A procedure for counting the n:th Fibonacci number ;; See SICP, p. 37 (define (fib n) - (cond ((= n 0) 0) + (cond ((= n 0) 0) ((= n 1) 1) (else (+ (fib (- n 1)) (fib (- n 2)))))) |