Run the csu tests on a DSO. This builds the tests into a shared library,

then runs these from the base test programs. With this we can check
crtbeginS.o and crtendS.o are working as expected.

MFC with:	r339738
Sponsored by:	DARPA, AFRL
This commit is contained in:
Andrew Turner 2018-10-30 09:43:26 +00:00
parent 9e26e65c16
commit 6ec0ee844c
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=339908
7 changed files with 141 additions and 16 deletions

View File

@ -273,6 +273,8 @@
csu
dynamic
..
dynamiclib
..
static
..
..

View File

@ -1,6 +1,8 @@
# $FreeBSD$
SUBDIR= dso
TESTS_SUBDIRS= dynamic
TESTS_SUBDIRS+= dynamiclib
TESTS_SUBDIRS+= static
.include <bsd.test.mk>

View File

@ -39,10 +39,18 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <unistd.h>
#ifndef DSO_LIB
#include <atf-c++.hpp>
#endif
extern volatile int constructor_run;
extern bool run_destructor_test;
#ifndef DSO_BASE
volatile int constructor_run;
bool run_destructor_test = false;
#endif
static volatile int constructor_run;
static bool run_destructor_test = false;
struct Foo {
Foo() {
constructor_run = 1;
@ -53,8 +61,12 @@ struct Foo {
}
};
extern Foo foo;
Foo foo;
#ifndef DSO_BASE
Foo foo;
#endif
#ifndef DSO_LIB
ATF_TEST_CASE_WITHOUT_HEAD(cxx_constructor);
ATF_TEST_CASE_BODY(cxx_constructor)
{
@ -90,3 +102,4 @@ ATF_INIT_TEST_CASES(tcs)
ATF_ADD_TEST_CASE(tcs, cxx_constructor);
ATF_ADD_TEST_CASE(tcs, cxx_destructor);
}
#endif

View File

@ -0,0 +1,25 @@
# $FreeBSD$
.PATH: ${.CURDIR:H}
SHLIB= h_csu
SHLIB_NAME= libh_csu.so
SHLIB_MAJOR= 1
WITHOUT_STATIC=
WITHOUT_PROFILE=
WITHOUT_PIC=
CFLAGS+= -DDSO_LIB
.include "../Makefile.tests"
SRCS=
.for src in ${ATF_TESTS_C}
SRCS+= ${src}.c
.endfor
.for src in ${ATF_TESTS_CXX}
SRCS+= ${src}.cc
.endfor
LIBDIR= ${TESTSBASE}/lib/csu/dynamiclib/
.include <bsd.lib.mk>

View File

@ -0,0 +1,17 @@
# $FreeBSD$
.PATH: ${.CURDIR:H}
CFLAGS+= -DDSO_BASE
DPADD+= ${.OBJDIR:H}/dso/libh_csu.so
LDFLAGS+= -Wl,-rpath,${TESTSDIR} -L${.OBJDIR:H}/dso
LDADD+= -lh_csu
.include "../Makefile.tests"
.for test in ${ATF_TESTS_C}
ATF_TESTS_CXX+= ${test}
SRCS.${test}= ${test}.c
.endfor
ATF_TESTS_C:=
.include <bsd.test.mk>

View File

@ -36,6 +36,7 @@ __FBSDID("$FreeBSD$");
#include <sys/wait.h>
#include <errno.h>
#include <stdbool.h>
#include <stdlib.h>
#include <unistd.h>
@ -43,10 +44,16 @@ __FBSDID("$FreeBSD$");
#include <crt.h>
extern bool run_dtors_test;
extern bool run_fini_array_test;
void dso_handle_check(void);
#ifndef DSO_BASE
typedef void (*func_ptr)(void);
static bool run_dtors_test = false;
static bool run_fini_array_test = false;
bool run_dtors_test = false;
bool run_fini_array_test = false;
static void
dtors_handler(void)
@ -57,7 +64,9 @@ dtors_handler(void)
}
__section(".dtors") __used static func_ptr dtors_func =
&dtors_handler;
#endif
#ifndef DSO_LIB
ATF_TC_WITHOUT_HEAD(dtors_test);
ATF_TC_BODY(dtors_test, tc)
{
@ -85,7 +94,9 @@ ATF_TC_BODY(dtors_test, tc)
break;
}
}
#endif
#ifndef DSO_BASE
static void
fini_array_handler(void)
{
@ -95,7 +106,9 @@ fini_array_handler(void)
}
__section(".fini_array") __used static func_ptr fini_array_func =
&fini_array_handler;
#endif
#ifndef DSO_LIB
ATF_TC_WITHOUT_HEAD(fini_array_test);
ATF_TC_BODY(fini_array_test, tc)
{
@ -118,15 +131,32 @@ ATF_TC_BODY(fini_array_test, tc)
break;
}
}
#endif
#ifndef DSO_BASE
extern void *__dso_handle;
void
dso_handle_check(void)
{
void *dso = __dso_handle;
#ifdef DSO_LIB
ATF_REQUIRE_MSG(dso != NULL,
"Null __dso_handle in DSO");
#else
ATF_REQUIRE_MSG(dso == NULL,
"Invalid __dso_handle in non-DSO");
#endif
}
#endif
#ifndef DSO_LIB
ATF_TC_WITHOUT_HEAD(dso_handle_test);
ATF_TC_BODY(dso_handle_test, tc)
{
ATF_REQUIRE_MSG(__dso_handle == NULL,
"Invalid __dso_handle in non-DSO");
dso_handle_check();
}
ATF_TP_ADD_TCS(tp)
@ -138,3 +168,4 @@ ATF_TP_ADD_TCS(tp)
return (atf_no_error());
}
#endif

View File

@ -32,23 +32,36 @@
#include <sys/cdefs.h>
__FBSDID("$FreeBSD$");
#ifndef DSO_LIB
#include <atf-c.h>
#endif
#include <crt.h>
typedef void (*func_ptr)(void);
static volatile int jcr_run;
static const func_ptr *jcr_ptr;
static volatile int ctors_run;
static volatile int preinit_array_run;
static volatile int preinit_array_state = -1;
static volatile int init_array_run;
static volatile int init_array_state = -1;
extern volatile int jcr_run;
extern const func_ptr *jcr_ptr;
extern const void *jcr_func_ptr;
extern volatile int ctors_run;
extern volatile int preinit_array_run;
extern volatile int preinit_array_state;
extern volatile int init_array_run;
extern volatile int init_array_state;
#ifndef DSO_BASE
volatile int jcr_run;
const func_ptr *jcr_ptr;
volatile int ctors_run;
volatile int preinit_array_run;
volatile int preinit_array_state = -1;
volatile int init_array_run;
volatile int init_array_state = -1;
void _Jv_RegisterClasses(const func_ptr *);
__section(".jcr") __used static func_ptr jcr_func = (func_ptr)1;
__section(".jcr") __used func_ptr static jcr_func = (func_ptr)1;
const void *jcr_func_ptr = &jcr_func;
void
_Jv_RegisterClasses(const func_ptr *jcr)
@ -57,16 +70,20 @@ _Jv_RegisterClasses(const func_ptr *jcr)
jcr_run = 1;
jcr_ptr = jcr;
}
#endif
#ifndef DSO_LIB
ATF_TC_WITHOUT_HEAD(jcr_test);
ATF_TC_BODY(jcr_test, tc)
{
ATF_REQUIRE_MSG(jcr_run == 1, ".jcr not run");
ATF_REQUIRE_MSG(jcr_ptr == &jcr_func,
ATF_REQUIRE_MSG(jcr_ptr == jcr_func_ptr,
"Incorrect pointer passed to _Jv_RegisterClasses");
}
#endif
#ifndef DSO_BASE
static void
ctors_handler(void)
{
@ -75,7 +92,9 @@ ctors_handler(void)
}
__section(".ctors") __used static func_ptr ctors_func =
&ctors_handler;
#endif
#ifndef DSO_LIB
ATF_TC_WITHOUT_HEAD(ctors_test);
ATF_TC_BODY(ctors_test, tc)
{
@ -86,7 +105,9 @@ ATF_TC_BODY(ctors_test, tc)
ATF_REQUIRE_MSG(ctors_run == 0, ".ctors run");
#endif
}
#endif
#ifndef DSO_BASE
static void
preinit_array_handler(void)
{
@ -96,16 +117,25 @@ preinit_array_handler(void)
}
__section(".preinit_array") __used static func_ptr preinit_array_func =
&preinit_array_handler;
#endif
#ifndef DSO_LIB
ATF_TC_WITHOUT_HEAD(preinit_array_test);
ATF_TC_BODY(preinit_array_test, tc)
{
#ifdef DSO_BASE
/* Check .preinit_array wasn't run in a DSO */
ATF_REQUIRE_MSG(preinit_array_run == 0, ".preinit_array run in DSO");
#else
ATF_REQUIRE_MSG(preinit_array_run == 1, ".preinit_array not run");
ATF_REQUIRE_MSG(preinit_array_state == 0,
".preinit_array was not run before .init_array");
#endif
}
#endif
#ifndef DSO_BASE
static void
init_array_handler(void)
{
@ -115,14 +145,18 @@ init_array_handler(void)
}
__section(".init_array") __used static func_ptr init_array_func =
&init_array_handler;
#endif
#ifndef DSO_LIB
ATF_TC_WITHOUT_HEAD(init_array_test);
ATF_TC_BODY(init_array_test, tc)
{
ATF_REQUIRE_MSG(init_array_run == 1, ".init_array not run");
#ifndef DSO_BASE
ATF_REQUIRE_MSG(init_array_state == 1,
".init_array was not run after .preinit_array");
#endif
}
ATF_TP_ADD_TCS(tp)
@ -135,3 +169,4 @@ ATF_TP_ADD_TCS(tp)
return (atf_no_error());
}
#endif