| 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 |
unlink(qw(testapi.c testapi.so)); |
| 81 |
return -1; |
| 82 |
} |
| 83 |
|
| 84 |
# TEST 1 |
| 85 |
# Check the gmk_expand() function |
| 86 |
run_make_test(q! |
| 87 |
EXPAND = expansion |
| 88 |
all: ; @echo $(test-expand $$(EXPAND)) |
| 89 |
load testapi.so |
| 90 |
!, |
| 91 |
'', "expansion\n"); |
| 92 |
|
| 93 |
# TEST 2 |
| 94 |
# Check the eval operation. Prove that the argument is expanded only once |
| 95 |
run_make_test(q! |
| 96 |
load testapi.so |
| 97 |
TEST = bye |
| 98 |
ASSIGN = VAR = $(TEST) $(shell echo there) |
| 99 |
$(test-eval $(value ASSIGN)) |
| 100 |
TEST = hi |
| 101 |
all:;@echo '$(VAR)' |
| 102 |
!, |
| 103 |
'', "hi there\n"); |
| 104 |
|
| 105 |
# TEST 2 |
| 106 |
# Check the no-expand capability |
| 107 |
run_make_test(q! |
| 108 |
load testapi.so |
| 109 |
TEST = hi |
| 110 |
all:;@echo '$(test-noexpand $(TEST))' |
| 111 |
!, |
| 112 |
'', "\$(TEST)\n"); |
| 113 |
|
| 114 |
unlink(qw(testapi.c testapi.so)) unless $keep; |
| 115 |
|
| 116 |
# This tells the test driver that the perl test script executed properly. |
| 117 |
1; |