summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorPaul Smith <psmith@gnu.org>2012-10-29 07:05:21 +0000
committerPaul Smith <psmith@gnu.org>2012-10-29 07:05:21 +0000
commit7670c84f7732db29f5a9d9c145c2327f4b575f91 (patch)
tree1fafd8949c867b89444ef57c6d068e7b8fb1a70e /tests
parent2efd6b47bf59c3202ccc6218b42ba360136d3789 (diff)
downloadgunmake-7670c84f7732db29f5a9d9c145c2327f4b575f91.tar.gz
Implement new "load" directive.
Provides support for dynamically loadable objects in GNU make, as a "technology preview".
Diffstat (limited to 'tests')
-rw-r--r--tests/ChangeLog4
-rwxr-xr-xtests/run_make_tests.pl29
-rw-r--r--tests/scripts/features/load84
-rw-r--r--tests/scripts/features/parallelism2
-rw-r--r--tests/scripts/functions/guile14
5 files changed, 117 insertions, 16 deletions
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 5e35053..7ffd6b0 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,7 @@
+2012-10-29 Paul Smith <psmith@gnu.org>
+
+ * scripts/features/load: New test suite for the "load" directive.
+
2012-09-09 Paul Smith <psmith@gnu.org>
* scripts/functions/file: Get errors in the C locale, not the
diff --git a/tests/run_make_tests.pl b/tests/run_make_tests.pl
index 477b117..4accd4a 100755
--- a/tests/run_make_tests.pl
+++ b/tests/run_make_tests.pl
@@ -97,6 +97,17 @@ sub valid_option
$old_makefile = undef;
+sub subst_make_string
+{
+ local $_ = shift;
+ $makefile and s/#MAKEFILE#/$makefile/g;
+ s/#MAKEPATH#/$mkpath/g;
+ s/#MAKE#/$make_name/g;
+ s/#PERL#/$perl_name/g;
+ s/#PWD#/$pwd/g;
+ return $_;
+}
+
sub run_make_test
{
local ($makestring, $options, $answer, $err_code, $timeout) = @_;
@@ -114,16 +125,9 @@ sub run_make_test
$makefile = &get_tmpfile();
}
- # Make sure it ends in a newline.
+ # Make sure it ends in a newline and substitute any special tokens.
$makestring && $makestring !~ /\n$/s and $makestring .= "\n";
-
- # Replace @MAKEFILE@ with the makefile name and @MAKE@ with the path to
- # make
- $makestring =~ s/#MAKEFILE#/$makefile/g;
- $makestring =~ s/#MAKEPATH#/$mkpath/g;
- $makestring =~ s/#MAKE#/$make_name/g;
- $makestring =~ s/#PERL#/$perl_name/g;
- $makestring =~ s/#PWD#/$pwd/g;
+ $makestring = subst_make_string($makestring);
# Populate the makefile!
open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n";
@@ -132,13 +136,8 @@ sub run_make_test
}
# Do the same processing on $answer as we did on $makestring.
-
$answer && $answer !~ /\n$/s and $answer .= "\n";
- $answer =~ s/#MAKEFILE#/$makefile/g;
- $answer =~ s/#MAKEPATH#/$mkpath/g;
- $answer =~ s/#MAKE#/$make_name/g;
- $answer =~ s/#PERL#/$perl_name/g;
- $answer =~ s/#PWD#/$pwd/g;
+ $answer = subst_make_string($answer);
run_make_with_options($makefile, $options, &get_logfile(0),
$err_code, $timeout);
diff --git a/tests/scripts/features/load b/tests/scripts/features/load
new file mode 100644
index 0000000..8117bbd
--- /dev/null
+++ b/tests/scripts/features/load
@@ -0,0 +1,84 @@
+# -*-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;
+
+# 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>
+
+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));
+}
+
+int
+testload_gmake_setup ()
+{
+ define_new_function (0, "func-a", 1, 1, 1, func_test);
+ return 1;
+}
+
+int
+explicit_setup ()
+{
+ define_new_function (0, "func-b", 1, 1, 1, func_test);
+ return 1;
+}
+EOF
+close($F) or die "close: testload.c: $!\n";
+
+run_make_test('testload.so: testload.c ; @$(CC) -g -shared -fPIC -o $@ $<',
+ '', '');
+
+# TEST 1
+run_make_test(q!
+all: ; @echo $(func-a foo) $(func-b bar)
+load ./testload.so
+!,
+ '', "func-a\n");
+
+# TEST 2
+# Load a different function
+run_make_test(q!
+all: ; @echo $(func-a foo) $(func-b bar)
+load ./testload.so(explicit_setup)
+!,
+ '', "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");
+
+# TEST 4
+# Check multiple loads
+run_make_test(q!
+all: ; @echo $(filter ./testload.so,$(.LOADED)) $(func-a foo) $(func-b bar)
+load ./testload.so
+load ./testload.so(explicit_setup)
+!,
+ '', "./testload.so func-a\n");
+
+unlink(qw(testload.c testload.so)) unless $keep;
+
+# This tells the test driver that the perl test script executed properly.
+1;
diff --git a/tests/scripts/features/parallelism b/tests/scripts/features/parallelism
index 76d24a7..08c822e 100644
--- a/tests/scripts/features/parallelism
+++ b/tests/scripts/features/parallelism
@@ -229,7 +229,7 @@ file2: file1 ; @touch $@
!,
'--no-print-directory -j2', "touch file3");
-#rmfiles('file1', 'file2', 'file3', 'file4');
+rmfiles('file1', 'file2', 'file3', 'file4');
if ($all_tests) {
# Jobserver FD handling is messed up in some way.
diff --git a/tests/scripts/functions/guile b/tests/scripts/functions/guile
index 82c02bc..93a18ab 100644
--- a/tests/scripts/functions/guile
+++ b/tests/scripts/functions/guile
@@ -5,6 +5,20 @@ $description = 'Test the $(guile ...) function.';
$details = 'This only works on systems that support it.';
# If this instance of make doesn't support GNU Guile, skip it
+# This detects if guile is loaded using the "load" directive
+# $makefile = get_tmpfile();
+# open(MAKEFILE, "> $makefile") || die "Failed to open $makefile: $!\n";
+# print MAKEFILE q!
+# -load guile
+# all: ; @echo $(filter guile,$(.LOADED))
+# !;
+# close(MAKEFILE) || die "Failed to write $makefile: $!\n";
+# $cmd = subst_make_string("#MAKEPATH# -f $makefile");
+# $log = get_logfile(0);
+# $code = run_command_with_output($log, $cmd);
+# read_file_into_string ($log) eq "guile\n" and $FEATURES{guile} = 1;
+
+# If we don't have Guile support, never mind.
exists $FEATURES{guile} or return -1;
# Verify simple data type conversions