Name "snippets" explicitly

Earlier, this code was conceived of to test a "function" specifically,
but some future snippet could test multiple function calls, or a
subset of a function call (e.g. snippets/syscall_clock_gettime.c
already only tests one particular syscall diversion number).

Normalizing on the name "snippet" should make it easier to understand
the code going forward.
This commit is contained in:
Daniel Kahn Gillmor
2021-03-01 15:06:22 -05:00
parent 0e6b1b2460
commit 7e62881c8f
4 changed files with 15 additions and 15 deletions

View File

@@ -6,7 +6,7 @@ LDFLAGS = -lrt -lpthread
SRC = timetest.c
OBJ = ${SRC:.c=.o}
TESTFUNCS = $(notdir $(basename $(wildcard snippets/*.c)))
TEST_SNIPPETS = $(notdir $(basename $(wildcard snippets/*.c)))
EXPECTATIONS= $(notdir $(basename $(wildcard snippets/*.variable)))
all: timetest test
@@ -37,24 +37,24 @@ test_variable_data: test_variable_data.sh $(foreach f,${EXPECTATIONS},run_${f})
./test_variable_data.sh ${EXPECTATIONS}
run_%: _run_test.c snippets/%.c
sed s/FUNC_NAME/$*/g < _run_test.c | ${CC} -o $@ ${CFLAGS} -x c -
sed s/SNIPPET_NAME/$*/g < _run_test.c | ${CC} -o $@ ${CFLAGS} -x c -
## testing when interception points get called in library constructors:
test_library_constructors: test_constructors.sh $(foreach f,${TESTFUNCS},use_lib_${f} lib${f}.so)
true $(foreach f,${TESTFUNCS},&& ./test_constructors.sh ${f})
test_library_constructors: test_constructors.sh $(foreach f,${TEST_SNIPPETS},use_lib_${f} lib${f}.so)
true $(foreach f,${TEST_SNIPPETS},&& ./test_constructors.sh ${f})
lib%.so: _libtest.c snippets/%.c
sed s/FUNC_NAME/$*/g < _libtest.c | ${CC} -shared -o $@ -fpic ${CFLAGS} -x c -
sed s/SNIPPET_NAME/$*/g < _libtest.c | ${CC} -shared -o $@ -fpic ${CFLAGS} -x c -
use_lib_%: _use_lib_test.c snippets/%.c lib%.so
sed s/FUNC_NAME/$*/g < _use_lib_test.c | ${CC} -L. -o $@ ${CFLAGS} -x c - -l$*
sed s/SNIPPET_NAME/$*/g < _use_lib_test.c | ${CC} -L. -o $@ ${CFLAGS} -x c - -l$*
## cleanup and metainformation
clean:
@rm -f ${OBJ} timetest getrandom_test syscall_test $(foreach f,${TESTFUNCS},use_lib_${f} lib${f}.so run_${f})
@rm -f ${OBJ} timetest getrandom_test syscall_test $(foreach f,${TEST_SNIPPETS},use_lib_${f} lib${f}.so run_${f})
distclean: clean
@echo

View File

@@ -1,8 +1,8 @@
#include "snippets/include_headers.h"
#define where "library"
void FUNC_NAME_as_needed() {
printf(" called FUNC_NAME_as_needed() \n");
void SNIPPET_NAME_as_needed() {
printf(" called SNIPPET_NAME_as_needed() \n");
}
static __attribute__((constructor)) void init_FUNC_NAME() {
#include "snippets/FUNC_NAME.c"
static __attribute__((constructor)) void init_SNIPPET_NAME() {
#include "snippets/SNIPPET_NAME.c"
}

View File

@@ -1,5 +1,5 @@
#include "snippets/include_headers.h"
#define where "direct"
int main() {
#include "snippets/FUNC_NAME.c"
#include "snippets/SNIPPET_NAME.c"
}

View File

@@ -1,7 +1,7 @@
#include "snippets/include_headers.h"
extern void FUNC_NAME_as_needed();
extern void SNIPPET_NAME_as_needed();
#define where "program"
int main() {
FUNC_NAME_as_needed();
#include "snippets/FUNC_NAME.c"
SNIPPET_NAME_as_needed();
#include "snippets/SNIPPET_NAME.c"
}