Fixed windows code for section retrieving and changed section names to fit under 8 bytes.

This commit is contained in:
Snaipe 2015-08-03 15:15:48 +02:00
parent 9aa9be0a41
commit 86762f8ff7
7 changed files with 44 additions and 26 deletions

View file

@ -22,7 +22,7 @@
.line_ = __LINE__, \
__VA_ARGS__ \
}; \
SECTION_("criterion_tests") \
SECTION_("cr_tst") \
const struct criterion_test IDENTIFIER_(Category, Name, meta) = { \
.name = #Name, \
.category = #Category, \
@ -38,7 +38,7 @@
.line_ = 0, \
__VA_ARGS__ \
}; \
SECTION_("crit_suites") \
SECTION_("cr_sts") \
const struct criterion_suite SUITE_IDENTIFIER_(Name, meta) = { \
.name = #Name, \
.data = &SUITE_IDENTIFIER_(Name, extra), \

View file

@ -48,9 +48,27 @@ typedef void (*f_report_hook)();
# define HOOK_PROTOTYPE_ \
void HOOK_IDENTIFIER_(impl)
// Section abbreviations
# define HOOK_SECTION_PRE_ALL cr_pra
# define HOOK_SECTION_PRE_SUITE cr_prs
# define HOOK_SECTION_PRE_INIT cr_pri
# define HOOK_SECTION_PRE_TEST cr_prt
# define HOOK_SECTION_ASSERT cr_ast
# define HOOK_SECTION_TEST_CRASH cr_tsc
# define HOOK_SECTION_POST_TEST cr_pot
# define HOOK_SECTION_POST_FINI cr_pof
# define HOOK_SECTION_POST_SUITE cr_pos
# define HOOK_SECTION_POST_ALL cr_poa
# define HOOK_SECTION(Kind) HOOK_SECTION_ ## Kind
# define HOOK_SECTION_STRINGIFY__(Sec) #Sec
# define HOOK_SECTION_STRINGIFY_(Sec) HOOK_SECTION_STRINGIFY__(Sec)
# define HOOK_SECTION_STRINGIFY(Kind) HOOK_SECTION_STRINGIFY_(HOOK_SECTION(Kind))
# define ReportHook(Kind) \
HOOK_PROTOTYPE_(); \
SECTION_("crit_" #Kind) \
SECTION_(HOOK_SECTION_STRINGIFY(Kind)) \
const f_report_hook HOOK_IDENTIFIER_(func) = HOOK_IDENTIFIER_(impl); \
HOOK_PROTOTYPE_

View file

@ -219,7 +219,7 @@ void *get_win_section_start(const char *section) {
PIMAGE_SECTION_HEADER pSecHeader = IMAGE_FIRST_SECTION(ntHeader);
for(int i = 0; i < ntHeader->FileHeader.NumberOfSections; i++, pSecHeader++) {
if (!strcmp(pSecHeader->Name, section)) {
if (!strncmp(pSecHeader->Name, section, 8)) {
return (void*) pSecHeader->VirtualAddress;
}
}
@ -235,8 +235,8 @@ void *get_win_section_end(const char *section) {
PIMAGE_SECTION_HEADER pSecHeader = IMAGE_FIRST_SECTION(ntHeader);
for(int i = 0; i < ntHeader->FileHeader.NumberOfSections; i++, pSecHeader++) {
if (!strcmp(pSecHeader->Name, section)) {
return (char*) pSecHeader->VirtualAddress + pSecHeader->SizeOfRawData);
if (!strncmp(pSecHeader->Name, section, 8)) {
return (char*) pSecHeader->VirtualAddress + pSecHeader->SizeOfRawData;
}
}
return NULL;

View file

@ -37,14 +37,14 @@
#include "extmatch.h"
#endif
#define IMPL_CALL_REPORT_HOOKS(Kind) \
IMPL_SECTION_LIMITS(f_report_hook, crit_ ## Kind); \
void call_report_hooks_##Kind(void *data) { \
for (f_report_hook *hook = GET_SECTION_START(crit_ ## Kind); \
hook < (f_report_hook*) GET_SECTION_END(crit_ ## Kind); \
++hook) { \
(*hook)(data); \
} \
#define IMPL_CALL_REPORT_HOOKS(Kind) \
IMPL_SECTION_LIMITS(f_report_hook, HOOK_SECTION(Kind)); \
void call_report_hooks_##Kind(void *data) { \
for (f_report_hook *hook = GET_SECTION_START(HOOK_SECTION(Kind)); \
hook < (f_report_hook*) GET_SECTION_END(HOOK_SECTION(Kind)); \
++hook) { \
(*hook)(data); \
} \
}
#define IMPL_REPORT_HOOK(Type) \

View file

@ -28,8 +28,8 @@
# define report(Kind, Data) call_report_hooks_##Kind(Data)
# define DECL_CALL_REPORT_HOOKS(Kind) \
DECL_SECTION_LIMITS(f_report_hook, crit_ ## Kind); \
# define DECL_CALL_REPORT_HOOKS(Kind) \
DECL_SECTION_LIMITS(f_report_hook, HOOK_SECTION(Kind)); \
void call_report_hooks_##Kind(void *data)
DECL_CALL_REPORT_HOOKS(PRE_ALL);

View file

@ -36,8 +36,8 @@
#include "posix-compat.h"
#include "abort.h"
IMPL_SECTION_LIMITS(struct criterion_test, criterion_tests);
IMPL_SECTION_LIMITS(struct criterion_suite, crit_suites);
IMPL_SECTION_LIMITS(struct criterion_test, cr_tst);
IMPL_SECTION_LIMITS(struct criterion_suite, cr_sts);
// This is here to make the test suite & test sections non-empty
TestSuite();

View file

@ -27,19 +27,19 @@
# include "criterion/types.h"
# include "posix-compat.h"
DECL_SECTION_LIMITS(struct criterion_test, criterion_tests);
DECL_SECTION_LIMITS(struct criterion_suite, crit_suites);
DECL_SECTION_LIMITS(struct criterion_test, cr_tst);
DECL_SECTION_LIMITS(struct criterion_suite, cr_sts);
struct criterion_test_set *criterion_init(void);
# define FOREACH_TEST_SEC(Test) \
for (struct criterion_test *Test = GET_SECTION_START(criterion_tests); \
Test < (struct criterion_test*) GET_SECTION_END(criterion_tests); \
# define FOREACH_TEST_SEC(Test) \
for (struct criterion_test *Test = GET_SECTION_START(cr_tst); \
Test < (struct criterion_test*) GET_SECTION_END(cr_tst); \
++Test)
# define FOREACH_SUITE_SEC(Suite) \
for (struct criterion_suite *Suite = GET_SECTION_START(crit_suites); \
Suite < (struct criterion_suite*) GET_SECTION_END(crit_suites); \
# define FOREACH_SUITE_SEC(Suite) \
for (struct criterion_suite *Suite = GET_SECTION_START(cr_sts); \
Suite < (struct criterion_suite*) GET_SECTION_END(cr_sts); \
++Suite)
#endif /* !CRITERION_RUNNER_H_ */