summaryrefslogtreecommitdiff
path: root/tests/scripts/features/load
blob: 47267feea254d1178dd9802210f2dd95c8b34da4 (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
#                                                                    -*-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;

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(testload.c testload.so));

open(my $F, '> testload.c') or die "open: testload.c: $!\n";
print $F <<'EOF' ;
#include <string.h>
#include <stdio.h>

#include "gnumake.h"

int
testload_gmk_setup ()
{
    gmk_eval ("TESTLOAD = implicit", 0);
    return 1;
}

int
explicit_setup ()
{
    gmk_eval ("TESTLOAD = explicit", 0);
    return 1;
}
EOF
close($F) or die "close: testload.c: $!\n";

# Make sure we can compile
run_make_test('testload.so: testload.c ; @'.$sobuild, '', '');

# TEST 1
run_make_test(q!
PRE := $(.LOADED)
load testload.so
POST := $(.LOADED)
all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
!,
              '', "pre= post=testload.so implicit\n");

# TEST 2
# Load using an explicit function
run_make_test(q!
PRE := $(.LOADED)
load ./testload.so(explicit_setup)
POST := $(.LOADED)
all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
!,
              '', "pre= post=testload.so explicit\n");

# TEST 4
# Check multiple loads
run_make_test(q!
PRE := $(.LOADED)
load ./testload.so
load testload.so(explicit_setup)
POST := $(.LOADED)
all: ; @echo pre=$(PRE) post=$(POST) $(TESTLOAD)
!,
              '', "pre= post=testload.so implicit\n");

# TEST 5
# Check auto-rebuild of loaded file that's out of date
utouch(-10, 'testload.so');
touch('testload.c');

run_make_test(q!
PRE := $(.LOADED)
load ./testload.so
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!
PRE := $(.LOADED)
-load ./testload.so(explicit_setup)
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;

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