summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog9
-rwxr-xr-xtests/run_make_tests.pl35
-rw-r--r--tests/scripts/features/load69
-rw-r--r--tests/scripts/features/loadapi84
-rw-r--r--tests/scripts/functions/guile8
5 files changed, 157 insertions, 48 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 2c1cb1b..afa1cbe 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,12 @@
+2013-02-25 Paul Smith <psmith@gnu.org>
+
+ * run_make_tests.pl (valid_option): Support the -srcdir flag.
+ (set_more_defaults): Set up $srcdir if it's not set yet.
+
+ * scripts/functions/guile: Verify gmk-eval doesn't expand twice.
+ * scripts/features/load: Rework to test just the load capability.
+ * scripts/features/loadapi: New set of tests for the load API.
+
2013-01-19 Paul Smith <psmith@gnu.org>
* scripts/features/load: Test loaded files with and without "./"
diff --git a/tests/run_make_tests.pl b/tests/run_make_tests.pl
index 4accd4a..a596328 100755
--- a/tests/run_make_tests.pl
+++ b/tests/run_make_tests.pl
@@ -35,6 +35,9 @@ $memcheck_args = '--num-callers=15 --tool=memcheck --leak-check=full --suppressi
$massif_args = '--num-callers=15 --tool=massif --alloc-fn=xmalloc --alloc-fn=xcalloc --alloc-fn=xrealloc --alloc-fn=xstrdup --alloc-fn=xstrndup';
$pure_log = undef;
+# The location of the GNU make source directory
+$srcdir = '';
+
$command_string = '';
$all_tests = 0;
@@ -59,6 +62,15 @@ sub valid_option
return 1;
}
+ if ($option =~ /^-srcdir$/i) {
+ $srcdir = shift @argv;
+ if (! -f "$srcdir/gnumake.h") {
+ print "$option $srcdir: Not a valid GNU make source directory.\n";
+ exit 0;
+ }
+ return 1;
+ }
+
if ($option =~ /^-all([-_]?tests)?$/i) {
$all_tests = 1;
return 1;
@@ -226,14 +238,16 @@ sub run_make_with_options {
sub print_usage
{
&print_standard_usage ("run_make_tests",
- "[-make_path make_pathname] [-memcheck] [-massif]",);
+ "[-make MAKE_PATHNAME] [-srcdir SRCDIR] [-memcheck] [-massif]",);
}
sub print_help
{
&print_standard_help (
- "-make_path",
+ "-make",
"\tYou may specify the pathname of the copy of make to run.",
+ "-srcdir",
+ "\tSpecify the make source directory.",
"-valgrind",
"-memcheck",
"\tRun the test suite under valgrind's memcheck tool.",
@@ -327,12 +341,8 @@ sub set_more_defaults
$make_name = $1;
}
else {
- if ($make_path =~ /$pathsep([^\n$pathsep]*)$/) {
- $make_name = $1;
- }
- else {
- $make_name = $make_path;
- }
+ $make_path =~ /^(?:.*$pathsep)?(.+)$/;
+ $make_name = $1;
}
# prepend pwd if this is a relative path (ie, does not
@@ -348,6 +358,15 @@ sub set_more_defaults
$mkpath = $make_path;
}
+ # If srcdir wasn't provided on the command line, see if the
+ # location of the make program gives us a clue. Don't fail if not;
+ # we'll assume it's been installed into /usr/include or wherever.
+ if (! $srcdir) {
+ $make_path =~ /^(.*$pathsep)?/;
+ my $d = $1 || '../';
+ -f "${d}gnumake.h" and $srcdir = $d;
+ }
+
# Get Purify log info--if any.
if (exists $ENV{PURIFYOPTIONS}
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))))))