summaryrefslogtreecommitdiff
path: root/tests/scripts/features/loadapi
blob: 8c824c049d84b9ae10c612708df92f278d4bc2f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#                                                                    -*-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;

# 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"

int plugin_is_GPL_compatible;

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 *
test_noexpand (const char *val)
{
    char *str = gmk_alloc (strlen (val) + 1);
    strcpy (str, val);
    return str;
}

static char *
func_test (const char *funcname, unsigned int argc, char **argv)
{
    char *mem;

    if (strcmp (funcname, "test-expand") == 0)
        return test_expand (argv[0]);

    if (strcmp (funcname, "test-eval") == 0)
        return test_eval (argv[0]);

    if (strcmp (funcname, "test-noexpand") == 0)
        return test_noexpand (argv[0]);

    mem = gmk_alloc (sizeof ("unknown"));
    strcpy (mem, "unknown");
    return mem;
}

int
testapi_gmk_setup ()
{
    gmk_add_function ("test-expand", func_test, 1, 1, GMK_FUNC_DEFAULT);
    gmk_add_function ("test-noexpand", func_test, 1, 1, GMK_FUNC_NOEXPAND);
    gmk_add_function ("test-eval", func_test, 1, 1, GMK_FUNC_DEFAULT);
    gmk_add_function ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.", func_test, 0, 0, 0);
    return 1;
}
EOF
close($F) or die "close: testapi.c: $!\n";

my $sobuild = "$CONFIG_FLAGS{CC} ".($srcdir? "-I$srcdir":'')." $CONFIG_FLAGS{CPPFLAGS} $CONFIG_FLAGS{CFLAGS} -shared -fPIC $CONFIG_FLAGS{LDFLAGS} -o testapi.so testapi.c";

my $clog = `$sobuild 2>&1`;
if ($? != 0) {
    $verbose and print "Failed to build testapi.so:\n$sobuild\n$_";
    return -1;
}

# 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");

# TEST 2
# Check the no-expand capability
run_make_test(q!
load testapi.so
TEST = hi
all:;@echo '$(test-noexpand $(TEST))'
!,
              '', "\$(TEST)\n");

unlink(qw(testapi.c testapi.so)) unless $keep;

# This tells the test driver that the perl test script executed properly.
1;