SRCS = testcase_runner.c eventloop_runner.c testcase_utils.c async_test.c
CFLAGS = -Wall -Wextra -Werror -pedantic -g
-LDFLAGS = -Wl,-export-dynamic
LDLIBS = -pthread -lxenctrl -lxlutil -lxenlight -ldl
TESTS = $(wildcard test_*.c)
ALL_SRCS = $(SRCS) $(TESTS)
.PHONY: all
-all: async_test $(TESTS:.c=.so)
-async_test: $(SRCS:.c=.o)
+all: $(TESTS:.c=)
-
-test_%.o: CFLAGS += -fPIC
-
-test_%.so: test_%.o
- $(CC) -shared $< -o $@
+test_%: $(SRCS:.c=.o) test_%.o
+ $(CC) $(LDFLAGS) $(LDLIBS) $^ -o $@
%.d: %.c
$(CC) -M $< > $@
.PHONY: clean
clean:
- rm -f $(ALL_SRCS:.c=.o) $(ALL_SRCS:.c=.d) $(TESTS:.c=.so) async_test
+ rm -f $(ALL_SRCS:.c=.o) $(ALL_SRCS:.c=.d) $(TESTS:.c=)
-include $(ALL_SRCS:.c=.d)
#include "testcase_runner.h"
#include "eventloop_runner.h"
-int main(int argc, char **argv)
+void *testcase(struct test *tc);
+
+int main(int argc __attribute__((unused)),
+ char **argv __attribute__((unused)))
{
struct test t;
xentoollog_logger *logger;
- char *test_path;
- void *test_plugin;
- void *(*testcase) (struct test *);
-
- if (argc != 2) {
- fprintf(stderr, "Usage: %s <testcase>\n", argv[0]);
- exit(EXIT_FAILURE);
- }
-
- /* dlopen only looks outside the standard library directories
- if the path contains a slash. Resolve the real path to
- the test file, to ensure that this is the case. */
- test_path = realpath(argv[1], NULL);
- if (!test_path) {
- perror(argv[1]);
- exit(EXIT_FAILURE);
- }
-
- test_plugin = dlopen(test_path, RTLD_NOW);
- free(test_path);
- if (!test_plugin) {
- fprintf(stderr, "%s\n", dlerror());
- exit(EXIT_FAILURE);
- }
- dlerror();
-
- *(void **)(&testcase) = dlsym(test_plugin, "testcase");
- if (!testcase) {
- fprintf(stderr, "%s\n", dlerror());
- exit(EXIT_FAILURE);
- }
- dlerror();
logger = (xentoollog_logger *)
xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0);
fprintf(stderr, "Test thread exited\n");
test_destroy(&t);
xtl_logger_destroy(logger);
- dlclose(test_plugin);
exit(EXIT_SUCCESS);
}