| 1 | # -*-perl-*-
|
|---|
| 2 | $description = "Test the shared object load API.";
|
|---|
| 3 |
|
|---|
| 4 | $details = "Verify the different aspects of the shared object API.";
|
|---|
| 5 |
|
|---|
| 6 | # Don't do anything if this system doesn't support "load"
|
|---|
| 7 | exists $FEATURES{load} or return -1;
|
|---|
| 8 |
|
|---|
| 9 | # First build a shared object
|
|---|
| 10 | # Provide both a default and non-default load symbol
|
|---|
| 11 |
|
|---|
| 12 | unlink(qw(testapi.c testapi.so));
|
|---|
| 13 |
|
|---|
| 14 | open(my $F, '> testapi.c') or die "open: testapi.c: $!\n";
|
|---|
| 15 | print $F <<'EOF' ;
|
|---|
| 16 | #include <string.h>
|
|---|
| 17 | #include <stdio.h>
|
|---|
| 18 |
|
|---|
| 19 | #include "gnumake.h"
|
|---|
| 20 |
|
|---|
| 21 | int plugin_is_GPL_compatible;
|
|---|
| 22 |
|
|---|
| 23 | static char *
|
|---|
| 24 | test_eval (const char *buf)
|
|---|
| 25 | {
|
|---|
| 26 | gmk_eval (buf, 0);
|
|---|
| 27 | return NULL;
|
|---|
| 28 | }
|
|---|
| 29 |
|
|---|
| 30 | static char *
|
|---|
| 31 | test_expand (const char *val)
|
|---|
| 32 | {
|
|---|
| 33 | return gmk_expand (val);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | static char *
|
|---|
| 37 | test_noexpand (const char *val)
|
|---|
| 38 | {
|
|---|
| 39 | char *str = gmk_alloc (strlen (val) + 1);
|
|---|
| 40 | strcpy (str, val);
|
|---|
| 41 | return str;
|
|---|
| 42 | }
|
|---|
| 43 |
|
|---|
| 44 | static char *
|
|---|
| 45 | func_test (const char *funcname, unsigned int argc, char **argv)
|
|---|
| 46 | {
|
|---|
| 47 | char *mem;
|
|---|
| 48 |
|
|---|
| 49 | if (strcmp (funcname, "test-expand") == 0)
|
|---|
| 50 | return test_expand (argv[0]);
|
|---|
| 51 |
|
|---|
| 52 | if (strcmp (funcname, "test-eval") == 0)
|
|---|
| 53 | return test_eval (argv[0]);
|
|---|
| 54 |
|
|---|
| 55 | if (strcmp (funcname, "test-noexpand") == 0)
|
|---|
| 56 | return test_noexpand (argv[0]);
|
|---|
| 57 |
|
|---|
| 58 | mem = gmk_alloc (sizeof ("unknown"));
|
|---|
| 59 | strcpy (mem, "unknown");
|
|---|
| 60 | return mem;
|
|---|
| 61 | }
|
|---|
| 62 |
|
|---|
| 63 | int
|
|---|
| 64 | testapi_gmk_setup ()
|
|---|
| 65 | {
|
|---|
| 66 | gmk_add_function ("test-expand", func_test, 1, 1, GMK_FUNC_DEFAULT);
|
|---|
| 67 | gmk_add_function ("test-noexpand", func_test, 1, 1, GMK_FUNC_NOEXPAND);
|
|---|
| 68 | gmk_add_function ("test-eval", func_test, 1, 1, GMK_FUNC_DEFAULT);
|
|---|
| 69 | gmk_add_function ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.", func_test, 0, 0, 0);
|
|---|
| 70 | return 1;
|
|---|
| 71 | }
|
|---|
| 72 | EOF
|
|---|
| 73 | close($F) or die "close: testapi.c: $!\n";
|
|---|
| 74 |
|
|---|
| 75 | my $sobuild = "$CONFIG_FLAGS{CC} ".($srcdir? "-I$srcdir":'')." $CONFIG_FLAGS{CPPFLAGS} $CONFIG_FLAGS{CFLAGS} -shared -fPIC $CONFIG_FLAGS{LDFLAGS} -o testapi.so testapi.c";
|
|---|
| 76 |
|
|---|
| 77 | my $clog = `$sobuild 2>&1`;
|
|---|
| 78 | if ($? != 0) {
|
|---|
| 79 | $verbose and print "Failed to build testapi.so:\n$sobuild\n$_";
|
|---|
| 80 | return -1;
|
|---|
| 81 | }
|
|---|
| 82 |
|
|---|
| 83 | # TEST 1
|
|---|
| 84 | # Check the gmk_expand() function
|
|---|
| 85 | run_make_test(q!
|
|---|
| 86 | EXPAND = expansion
|
|---|
| 87 | all: ; @echo $(test-expand $$(EXPAND))
|
|---|
| 88 | load testapi.so
|
|---|
| 89 | !,
|
|---|
| 90 | '', "expansion\n");
|
|---|
| 91 |
|
|---|
| 92 | # TEST 2
|
|---|
| 93 | # Check the eval operation. Prove that the argument is expanded only once
|
|---|
| 94 | run_make_test(q!
|
|---|
| 95 | load testapi.so
|
|---|
| 96 | TEST = bye
|
|---|
| 97 | ASSIGN = VAR = $(TEST) $(shell echo there)
|
|---|
| 98 | $(test-eval $(value ASSIGN))
|
|---|
| 99 | TEST = hi
|
|---|
| 100 | all:;@echo '$(VAR)'
|
|---|
| 101 | !,
|
|---|
| 102 | '', "hi there\n");
|
|---|
| 103 |
|
|---|
| 104 | # TEST 2
|
|---|
| 105 | # Check the no-expand capability
|
|---|
| 106 | run_make_test(q!
|
|---|
| 107 | load testapi.so
|
|---|
| 108 | TEST = hi
|
|---|
| 109 | all:;@echo '$(test-noexpand $(TEST))'
|
|---|
| 110 | !,
|
|---|
| 111 | '', "\$(TEST)\n");
|
|---|
| 112 |
|
|---|
| 113 | unlink(qw(testapi.c testapi.so)) unless $keep;
|
|---|
| 114 |
|
|---|
| 115 | # This tells the test driver that the perl test script executed properly.
|
|---|
| 116 | 1;
|
|---|