[Issue #17] Fixed nested failed asserts not aborting the test

This commit is contained in:
Snaipe 2015-04-14 18:39:40 +02:00
parent ea2721dbb8
commit c583e7e742
7 changed files with 109 additions and 3 deletions

View file

@ -25,6 +25,7 @@ EXTRA_DIST = config.rpath LICENSE
subdirincludedir = $(includedir)/criterion/
subdirinclude_HEADERS = \
include/criterion/assert.h \
include/criterion/abort.h \
include/criterion/common.h \
include/criterion/criterion.h \
include/criterion/event.h \
@ -36,6 +37,8 @@ subdirinclude_HEADERS = \
include/criterion/stats.h
libcriterion_la_SOURCES = \
src/abort.c \
src/abort.h \
src/event.c \
src/event.h \
src/report.c \

31
include/criterion/abort.h Normal file
View file

@ -0,0 +1,31 @@
/*
* The MIT License (MIT)
*
* Copyright © 2015 Franklin "Snaipe" Mathieu <http://snai.pe/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef CRITERION_ABORT_H_
# define CRITERION_ABORT_H_
# include "common.h"
NORETURN void criterion_abort_test(void);
#endif /* !CRITERION_ABORT_H_ */

View file

@ -31,6 +31,7 @@
# include "stats.h"
# include "hooks.h"
# include "event.h"
# include "abort.h"
enum criterion_assert_kind {
NORMAL,
@ -60,7 +61,7 @@ struct criterion_assert_args {
}; \
send_event(ASSERT, &stat, sizeof (stat)); \
if (!passed && (Kind) == FATAL) \
return; \
criterion_abort_test(); \
} while (0)
// Common asserts

View file

@ -56,6 +56,7 @@
Type *const SECTION_END(Name) = &SECTION_END_(Name)
# define UNUSED __attribute__((unused))
# define NORETURN __attribute__((noreturn))
# ifdef _WIN32
# define SIZE_T_FORMAT "%Iu"

35
src/abort.c Normal file
View file

@ -0,0 +1,35 @@
/*
* The MIT License (MIT)
*
* Copyright © 2015 Franklin "Snaipe" Mathieu <http://snai.pe/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#include <setjmp.h>
#include "abort.h"
static jmp_buf g_pre_test;
int setup_abort_test(void) {
return !setjmp(g_pre_test);
}
void criterion_abort_test(void) {
longjmp(g_pre_test, 1);
}

31
src/abort.h Normal file
View file

@ -0,0 +1,31 @@
/*
* The MIT License (MIT)
*
* Copyright © 2015 Franklin "Snaipe" Mathieu <http://snai.pe/>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
#ifndef ABORT_H_
# define ABORT_H_
# include <criterion/abort.h>
int setup_abort_test(void);
#endif /* !ABORT_H_ */

View file

@ -34,6 +34,7 @@
#include "process.h"
#include "timer.h"
#include "posix-compat.h"
#include "abort.h"
IMPL_SECTION_LIMITS(struct criterion_test, criterion_tests);
IMPL_SECTION_LIMITS(struct criterion_suite, crit_suites);
@ -139,8 +140,11 @@ static void run_test_child(struct criterion_test *test,
send_event(PRE_TEST, NULL, 0);
struct timespec_compat ts;
timer_start(&ts);
(test->test ?: nothing)();
if (setup_abort_test()) {
timer_start(&ts);
(test->test ?: nothing)();
}
double elapsed_time;
if (!timer_end(&elapsed_time, &ts))
elapsed_time = -1;