Skip to content

Commit

Permalink
Add CTSRD-CHERI/cheri-c-tests to cheriabitest.
Browse files Browse the repository at this point in the history
The cheri-c-tests has been added as a submodule in contrib/cheri-c-tests.
The cheritest infrastructure has been modified to support building these
tests into the main test program when requested.  This makes sense only
when compiling for the pure capabilty ABI so cheriabitest does this.

Because submodules are somewhat fragile and require additional steps, the
Makefile infrastructure attempts to avoid building the cheri-c-tests code
if they are not present and derives a list of tests from the submodule
rather than hardcoding one.

Currently tests requiring fault handlers are not supported.  In principle
they should work, but currently they do not so the are not included in the
cheri_tests array.
  • Loading branch information
brooksdavis committed Feb 5, 2016
1 parent 92209de commit 9081a9c
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
@@ -0,0 +1,3 @@
[submodule "contrib/cheri-c-tests"]
path = contrib/cheri-c-tests
url = https://github.com/CTSRD-CHERI/cheri-c-tests.git
4 changes: 3 additions & 1 deletion bin/cheriabitest/Makefile
Expand Up @@ -5,4 +5,6 @@ SRCDIR= ${.CURDIR}/../cheritest

PROG= cheriabitest

.include <${SRCDIR}/Makefile>
CHERI_C_TESTS= yes

.include <${SRCDIR}/Makefile>
25 changes: 23 additions & 2 deletions bin/cheritest/Makefile
Expand Up @@ -21,6 +21,27 @@ SRCS+= cheritest_bounds_stack.c \
cheritest_vm_swap.c
.endif

CHERITEST_DIR:= ${.PARSEDIR}

.ifdef CHERI_C_TESTS
CHERI_C_TESTS_DIR= ${SRCTOP}/contrib/cheri-c-tests
.if exists(${CHERI_C_TESTS_DIR}/Makefile)
.PATH: ${CHERI_C_TESTS_DIR}
CFLAGS+= -DCHERI_C_TESTS \
-I${CHERI_C_TESTS_DIR}

.ifndef BOOTSTRAPPING

CFLAGS+= -DTEST_CUSTOM_FRAMEWORK -I${CHERITEST_DIR}
.warning PARSEDIR=${.PARSEDIR}
TEST_SRCS!= grep ^DECLARE_TEST ${CHERI_C_TESTS_DIR}/cheri_c_testdecls.h | \
sed -e 's/.*(\([^,]*\),.*/\1.c/'
SRCS+= test_runtime.c \
${TEST_SRCS}
.endif
.endif
.endif

MAN=

.ifndef BOOTSTRAPPING
Expand All @@ -41,8 +62,8 @@ NO_WERROR= YES

.ifdef BOOTSTRAPPING
CFLAGS+= -DLIST_ONLY \
-I${.CURDIR}/../../libexec/cheritest-helper \
-I${.CURDIR}/../../contrib/libxo
-I${SRCTOP}/libexec/cheritest-helper \
-I${SRCTOP}/contrib/libxo
LDFLAGS+= -L${.OBJDIR}/../../lib/libxo
.endif

Expand Down
21 changes: 21 additions & 0 deletions bin/cheritest/cheri_c_test_framework.h
@@ -0,0 +1,21 @@
#ifndef __CHERI_C_TEST_FRAMEWORK_H__
#define __CHERI_C_TEST_FRAMEWORK_H__
#include <sys/types.h>
#include <stdlib.h>
#include <cheritest.h>

#define assert(x) \
do { \
if (!(x)) \
cheritest_failure_errx("%s is false: %s:%d", #x, __FILE__, __LINE__); \
} while(0)

#define DECLARE_TEST(name, desc) \
void cheri_c_test_ ## name(const struct cheri_test *ctp __unused);
#define DECLARE_TEST_FAULT(name, desc) /* Not supported */
#define BEGIN_TEST(name) \
void cheri_c_test_ ## name(const struct cheri_test *ctp __unused) { \
test_setup();
#define END_TEST cheritest_success(); }

#endif /* __CHERI_C_TEST_FRAMEWORK_H__ */
9 changes: 9 additions & 0 deletions bin/cheritest/cheritest.c
Expand Up @@ -859,6 +859,15 @@ static const struct cheri_test cheri_tests[] = {
{ .ct_name = "test_string_memmove_c",
.ct_desc = "Test explicit capability memmove",
.ct_func = test_string_memmove_c },
#ifdef CHERI_C_TESTS
#define DECLARE_TEST(name, desc) \
{ .ct_name = "cheri_c_test_" #name, \
.ct_desc = desc, \
.ct_func = cheri_c_test_ ## name },
#define DECLARE_TEST_FAULT(name, desc) /* No supported */
#include <cheri_c_testdecls.h>
#undef DECLARE_TEST
#endif
};
static const u_int cheri_tests_len = sizeof(cheri_tests) /
sizeof(cheri_tests[0]);
Expand Down
8 changes: 8 additions & 0 deletions bin/cheritest/cheritest.h
Expand Up @@ -323,4 +323,12 @@ const char *xfail_need_writable_tmp(const char *name);
void cheritest_vm_swap(const struct cheri_test *ctp __unused);
const char *xfail_swap_required(const char *name);

#ifdef CHERI_C_TESTS
#define DECLARE_TEST(name, desc) \
void cheri_c_test_ ## name(const struct cheri_test *ctp __unused);
#define DECLARE_TEST_FAULT(name, desc) /* Not supported */
#include <cheri_c_testdecls.h>
#undef DECLARE_TEST
#endif

#endif /* !_CHERITEST_H_ */
9 changes: 9 additions & 0 deletions bin/cheritest/cheritest_list_only.h
Expand Up @@ -208,4 +208,13 @@
#define xfail_swap_required NULL
#define xfail_need_writable_tmp NULL

#ifdef CHERI_C_TESTS
#define DECLARE_TEST(name, desc) \
inline void cheri_c_test_ ## name( \
const struct cheri_test *ctp __unused) {}
#include <cheri_c_testdecls.h>
#undef DECLARE_TEST
#endif


#endif /* !_CHERITEST_LIST_ONLY_H_ */
1 change: 1 addition & 0 deletions contrib/cheri-c-tests
Submodule cheri-c-tests added at b66835

0 comments on commit 9081a9c

Please sign in to comment.