Skip to content

Commit 82996cd

Browse files
committed
tests: Run IPC with use-filesystem-sockets active
Provide an LD_PRELOAD library that simulates the presence of /etc/libqb/use-filesystem-sockets so that we can test that functionality without actually having the file on the system and affecting everything else running on the box.
1 parent bdc7160 commit 82996cd

File tree

3 files changed

+62
-3
lines changed

3 files changed

+62
-3
lines changed

tests/Makefile.am

+8-3
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,16 @@ endif
113113
bench_log_SOURCES = bench-log.c
114114
bench_log_LDADD = $(top_builddir)/lib/libqb.la
115115

116+
lib_LTLIBRARIES = libstat_wrapper.la
117+
libstat_wrapper_la_SOURCES = libstat_wrapper.c
118+
libstat_wrapper_la_LIBADD = -ldl
119+
libdir= $(TESTDIR)
120+
116121
if HAVE_CHECK
117-
EXTRA_DIST += start.test resources.test
122+
EXTRA_DIST += start.test resources.test ipc_sock.test
118123
EXTRA_DIST += blackbox-segfault.sh
119124

120-
TESTS = start.test array.test map.test rb.test list.test log.test blackbox-segfault.sh loop.test ipc.test resources.test
125+
TESTS = start.test array.test map.test rb.test list.test log.test blackbox-segfault.sh loop.test ipc.test ipc_sock.test resources.test
121126
TESTS_ENVIRONMENT = export PATH=.:../tools:$$PATH;
122127

123128
resources.log: rb.log log.log ipc.log
@@ -126,7 +131,7 @@ check_LTLIBRARIES =
126131
check_PROGRAMS = array.test ipc.test list.test log.test loop.test \
127132
map.test rb.test util.test \
128133
crash_test_dummy file_change_bytes
129-
dist_check_SCRIPTS = start.test resources.test blackbox-segfault.sh
134+
dist_check_SCRIPTS = start.test resources.test blackbox-segfault.sh ipc_sock.test
130135

131136
if HAVE_SLOW_TESTS
132137
TESTS += util.test

tests/ipc_sock.test

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
#
3+
# Run the IPC tests under the stat wrapper,
4+
# this simulates /etc/libqb/use-filesystem-sockets existing
5+
# so we can test both options without breaking other things
6+
# that might be running on this system
7+
#
8+
if [ "`uname -s`" = "Linux" ]
9+
then
10+
if [ -f `pwd`/.libs/libstatwrapper.so ]
11+
then
12+
export LD_PRELOAD=`pwd`/.libs/libstat_wrapper.so
13+
else
14+
export LD_PRELOAD=`pwd`/libstat_wrapper.so
15+
fi
16+
./ipc.test
17+
else
18+
exit 0
19+
fi

tests/libstat_wrapper.c

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* Simulate FORCESOCKETSFILE existing for the IPC tests
3+
*/
4+
5+
#include <stdio.h>
6+
#include <dlfcn.h>
7+
#include <string.h>
8+
#include <sys/stat.h>
9+
#include "../include/config.h"
10+
#if defined(QB_LINUX) || defined(QB_CYGWIN)
11+
#include <gnu/lib-names.h>
12+
#endif
13+
14+
int __xstat(int __ver, const char *__filename, struct stat *__stat_buf)
15+
{
16+
#if defined(QB_LINUX) || defined(QB_CYGWIN)
17+
static int opened = 0;
18+
static void *dlhandle;
19+
static int (*real_xstat)(int __ver, const char *__filename, void *__stat_buf);
20+
21+
if (!opened) {
22+
dlhandle = dlopen(LIBC_SO, RTLD_NOW);
23+
real_xstat = dlsym(dlhandle, "__xstat");
24+
opened = 1;
25+
}
26+
27+
if (strcmp(__filename, FORCESOCKETSFILE) == 0) {
28+
return 0; /* it exists! */
29+
}
30+
31+
return real_xstat(__ver, __filename, __stat_buf);
32+
#else
33+
return -1; /* Error in the unlikely event we get called on *BSD* */
34+
#endif
35+
}

0 commit comments

Comments
 (0)