2 $description = "Test the shared object load API.";
4 $details = "Verify the different aspects of the shared object API.";
6 # Don't do anything if this system doesn't support "load"
7 exists $FEATURES{load} or return -1;
9 my $cc = get_config('CC');
11 $verbose and print "Skipping load test: no CC defined\n";
15 # First build a shared object
16 # Provide both a default and non-default load symbol
18 unlink(qw(testapi.c testapi.so));
20 open(my $F, '> testapi.c') or die "open: testapi.c: $!\n";
27 char *getenv (const char*);
29 int plugin_is_GPL_compatible;
31 int testapi_gmk_setup ();
34 test_eval (const char *buf)
41 test_expand (const char *val)
43 return gmk_expand (val);
47 test_noexpand (const char *val)
49 char *str = gmk_alloc (strlen (val) + 1);
55 func_test (const char *funcname, unsigned int argc, char **argv)
59 if (strcmp (funcname, "test-expand") == 0)
60 return test_expand (argv[0]);
62 if (strcmp (funcname, "test-eval") == 0)
63 return test_eval (argv[0]);
65 if (strcmp (funcname, "test-noexpand") == 0)
66 return test_noexpand (argv[0]);
68 mem = gmk_alloc (sizeof ("unknown"));
69 strcpy (mem, "unknown");
74 testapi_gmk_setup (const gmk_floc *floc)
76 const char *verbose = getenv ("TESTAPI_VERBOSE");
78 gmk_add_function ("test-expand", func_test, 1, 1, GMK_FUNC_DEFAULT);
79 gmk_add_function ("test-noexpand", func_test, 1, 1, GMK_FUNC_NOEXPAND);
80 gmk_add_function ("test-eval", func_test, 1, 1, GMK_FUNC_DEFAULT);
81 gmk_add_function ("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.", func_test, 0, 0, 0);
85 printf ("testapi_gmk_setup\n");
87 if (verbose[0] == '2')
88 printf ("%s:%lu\n", floc->filenm, floc->lineno);
91 if (getenv ("TESTAPI_KEEP"))
97 close($F) or die "close: testapi.c: $!\n";
99 # Make sure we can compile
101 my $cflags = get_config('CFLAGS');
102 my $cppflags = get_config('CPPFLAGS');
103 my $ldflags = get_config('LDFLAGS');
104 my $sobuild = "$cc ".($srcdir? "-I$srcdir/src":'')." $cppflags $cflags -shared -fPIC $ldflags -o testapi.so testapi.c";
106 my $clog = `$sobuild 2>&1`;
108 $verbose and print "Failed to build testapi.so:\n$sobuild\n$_";
113 # Check the gmk_expand() function
116 all: ; @echo $(test-expand $$(EXPAND))
122 # Check the eval operation. Prove that the argument is expanded only once
126 ASSIGN = VAR = $(TEST) $(shell echo there)
127 $(test-eval $(value ASSIGN))
134 # Check the no-expand capability
138 all:;@echo '$(test-noexpand $(TEST))'
143 # During all subsequent tests testapi.so exists.
150 $(eval load testapi.so)
151 $(eval -load testapi.so)
154 for my $extra_loads (@loads) {
160 # Test that having unloaded a shared object make loads it again, even if the
161 # shared object is not updated.
162 $ENV{TESTAPI_VERBOSE} = 1;
166 all:; \$(info \$(test-expand hello))
167 testapi.so: force; \$(info \$@)
170 ", '', "testapi_gmk_setup\ntestapi.so\ntestapi_gmk_setup\nhello\n#MAKE#: 'all' is up to date.\n");
173 # Same as above, but testapi_gmk_setup returned -1.
174 $ENV{TESTAPI_KEEP} = 1;
175 $ENV{TESTAPI_VERBOSE} = 1;
179 all:; \$(info \$(test-expand hello))
180 testapi.so: force; \$(info \$@)
183 ", '', "testapi_gmk_setup\nhello\n#MAKE#: 'all' is up to date.\n");
186 # Test that make exits, unless make can successfully update an unloaded shared
188 $ENV{TESTAPI_VERBOSE} = 1;
192 all:; \$(info \$(test-expand hello))
193 testapi.so: force; @#HELPER# fail 1
196 ", '', "testapi_gmk_setup\nfail 1\n#MAKE#: *** [#MAKEFILE#:$n: testapi.so] Error 1\n", 512);
199 # Same as above, but testapi_gmk_setup returned -1.
200 $ENV{TESTAPI_KEEP} = 1;
201 $ENV{TESTAPI_VERBOSE} = 1;
205 all:; \$(info \$(test-expand hello))
206 testapi.so: force; @#HELPER# fail 1
209 ", '', "testapi_gmk_setup\nhello\n#MAKE#: 'all' is up to date.\n");
212 # Test that make supplies the correct floc when the shared object is loaded
214 $ENV{TESTAPI_VERBOSE} = 2;
218 all:; \$(info \$(test-expand hello))
219 testapi.so: force; \$(info \$@)
222 ", '', "testapi_gmk_setup\n#MAKEFILE#:2\ntestapi.so\ntestapi_gmk_setup\n#MAKEFILE#:2\nhello\n#MAKE#: 'all' is up to date.\n");
225 unlink(qw(testapi.c testapi.so)) unless $keep;
227 # This tells the test driver that the perl test script executed properly.