Merge branch 'csptr-iso-c99' into bleeding

This commit is contained in:
Snaipe 2015-09-06 03:44:45 +02:00
commit 34aacc2dd8
33 changed files with 399 additions and 167 deletions

View file

@ -10,8 +10,6 @@ set(GIT_SUBMODULES libcsptr dyncall)
### set each submodules's commit or tag that is to be checked out ### set each submodules's commit or tag that is to be checked out
### (leave empty if you want master) ### (leave empty if you want master)
set(GIT_SUBMODULE_VERSION_libcsptr 04cd477)
set(GIT_SUBMODULE_VERSION_dyncall 68c57f6)
### First, get all submodules in ### First, get all submodules in
if(${GIT_SUBMODULES_CHECKOUT_QUIET}) if(${GIT_SUBMODULES_CHECKOUT_QUIET})

3
.gitmodules vendored
View file

@ -4,3 +4,6 @@
[submodule "dependencies/dyncall"] [submodule "dependencies/dyncall"]
path = dependencies/dyncall path = dependencies/dyncall
url = https://github.com/Snaipe/dyncall.git url = https://github.com/Snaipe/dyncall.git
[submodule "dependencies/wingetopt"]
path = dependencies/wingetopt
url = https://github.com/alex85k/wingetopt.git

View file

@ -17,6 +17,11 @@ include_directories(
dependencies/dyncall/dyncall/ dependencies/dyncall/dyncall/
) )
if (MSVC)
add_subdirectory(dependencies/wingetopt/ EXCLUDE_FROM_ALL)
include_directories(dependencies/wingetopt/src/)
endif ()
# Project setup & environment variables # Project setup & environment variables
set(PROJECT_VERSION "1.3.1") set(PROJECT_VERSION "1.3.1")
@ -24,11 +29,17 @@ set(LOCALEDIR ${CMAKE_INSTALL_PREFIX}/share/locale)
set(GettextTranslate_ALL 1) set(GettextTranslate_ALL 1)
set(GettextTranslate_GMO_BINARY 1) set(GettextTranslate_GMO_BINARY 1)
set_property(GLOBAL PROPERTY ALLOW_DUPLICATE_CUSTOM_TARGETS ON) add_definitions(-DCRITERION_BUILDING_DLL=1)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99") if (NOT MSVC)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Werror -g -std=gnu99")
endif ()
if (WIN32) if (MSVC)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
endif ()
if (WIN32 AND NOT MSVC)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-no-undefined") set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} -Wl,-no-undefined")
endif() endif()
@ -44,13 +55,13 @@ endif()
# Find dependencies # Find dependencies
#find_package(Gettext) find_package(Gettext)
#find_package(Libintl) find_package(Libintl)
#if (GETTEXT_FOUND AND LIBINTL_LIB_FOUND) if (GETTEXT_FOUND AND LIBINTL_LIB_FOUND)
# include(GettextTranslate) include(GettextTranslate)
# add_subdirectory(po) add_subdirectory(po)
# set(ENABLE_NLS 1) set(ENABLE_NLS 1)
#endif () endif ()
include(CheckLibraryExists) include(CheckLibraryExists)
CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME) CHECK_LIBRARY_EXISTS(rt clock_gettime "time.h" HAVE_CLOCK_GETTIME)
@ -120,6 +131,10 @@ include_directories(include src)
add_library(criterion SHARED ${SOURCE_FILES} ${INTERFACE_FILES}) add_library(criterion SHARED ${SOURCE_FILES} ${INTERFACE_FILES})
target_link_libraries(criterion csptr dyncall_s) target_link_libraries(criterion csptr dyncall_s)
if (MSVC)
target_link_libraries(criterion wingetopt)
endif ()
if (HAVE_CLOCK_GETTIME) if (HAVE_CLOCK_GETTIME)
target_link_libraries(criterion rt) target_link_libraries(criterion rt)
endif() endif()
@ -136,12 +151,6 @@ if (COVERALLS)
coveralls_setup("${SOURCE_FILES}" ${COVERALLS_UPLOAD}) coveralls_setup("${SOURCE_FILES}" ${COVERALLS_UPLOAD})
endif() endif()
if (WIN32)
set_target_properties(criterion PROPERTIES LINK_FLAGS
"-Wl,--output-def,${CMAKE_CURRENT_BINARY_DIR}/libcriterion.def")
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libcriterion.def DESTINATION lib)
endif ()
install(FILES ${INTERFACE_FILES} DESTINATION include/criterion) install(FILES ${INTERFACE_FILES} DESTINATION include/criterion)
install(TARGETS criterion install(TARGETS criterion
RUNTIME DESTINATION bin RUNTIME DESTINATION bin
@ -149,10 +158,6 @@ install(TARGETS criterion
ARCHIVE DESTINATION lib ARCHIVE DESTINATION lib
) )
add_custom_target(uninstall
"${CMAKE_COMMAND}" -P "${CMAKE_MODULE_PATH}/uninstall.cmake"
)
enable_testing() enable_testing()
add_subdirectory(samples) add_subdirectory(samples)
add_subdirectory(test) add_subdirectory(test)

View file

@ -1,6 +1,6 @@
version: 1.3.1_b{build}-{branch} version: 1.3.1_b{build}-{branch}
os: Windows Server 2012 os: Visual Studio 2015
init: init:
- git config --global core.autocrlf input - git config --global core.autocrlf input
@ -13,6 +13,17 @@ environment:
CI_JOB_ID: $(APPVEYOR_JOB_ID) CI_JOB_ID: $(APPVEYOR_JOB_ID)
LOCAL_INSTALL: $(APPVEYOR_BUILD_FOLDER) LOCAL_INSTALL: $(APPVEYOR_BUILD_FOLDER)
GCOV_PREFIX: $(APPVEYOR_BUILD_FOLDER) GCOV_PREFIX: $(APPVEYOR_BUILD_FOLDER)
matrix:
- COMPILER: mingw
BUILD_TARGET: all
TEST_TARGET: test
INSTALL_TARGET: install
GENERATOR: "MSYS Makefiles"
- COMPILER: msvc
BUILD_TARGET: all_build
TEST_TARGET: run_tests
INSTALL_TARGET: install
GENERATOR: "Visual Studio 14 2015"
clone_depth: 5 clone_depth: 5
@ -29,17 +40,36 @@ install:
- 'git checkout -B %APPVEYOR_REPO_BRANCH%' - 'git checkout -B %APPVEYOR_REPO_BRANCH%'
# Configure project # Configure project
- 'mkdir build && cd build' - 'mkdir build && cd build'
- 'cmake -DCMAKE_INSTALL_PREFIX=criterion-%APPVEYOR_REPO_TAG_NAME% -DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%" -DCOVERALLS=ON -DCMAKE_BUILD_TYPE=Debug -G "MSYS Makefiles" ..' - >
cmake
-Wno-dev
-DCMAKE_INSTALL_PREFIX="criterion-%APPVEYOR_REPO_TAG_NAME%"
-DCMAKE_PREFIX_PATH="%LOCAL_INSTALL%"
-G "%GENERATOR%"
..
build_script: build_script:
- 'make' - cmake --build . --target %BUILD_TARGET%
- ps: |
# HACK: We need to copy criterion.dll into the binary directory
if ($env:Compiler -eq "msvc") {
Copy-Item Debug/criterion.dll samples/Debug/
Copy-Item Debug/criterion.dll test/Debug/
}
after_build: before_deploy:
- 'make install' - ps: |
- 'bash -lc "cd $APPVEYOR_BUILD_FOLDER; tar -cvjf criterion-${APPVEYOR_REPO_BRANCH}-windows-${PLATFORM}.tar.bz2 -C build criterion-${APPVEYOR_REPO_TAG_NAME}"' if ($env:Compiler -eq "mingw" -and !$env:APPVEYOR_REPO_TAG_NAME) {
cmake --build . --target $env:INSTALL_TARGET
7z a -ttar "criterion-$env:APPVEYOR_REPO_BRANCH-windows-$env:PLATFORM.tar" "criterion-$env:APPVEYOR_REPO_TAG_NAME"
7z a -tbzip2 "../criterion-$env:APPVEYOR_REPO_TAG_NAME-windows-$env:PLATFORM.tar.bz2" "criterion-$env:APPVEYOR_REPO_TAG_NAME-windows-$env:PLATFORM.tar"
Push-AppveyorArtifact "../criterion-$env:APPVEYOR_REPO_TAG_NAME-windows-$env:PLATFORM.tar.bz2"
}
test_script: test_script:
- 'make test || bash -lc "cat $APPVEYOR_BUILD_FOLDER/build/Testing/Temporary/LastTest.log"' - ps: |
try { cmake --build . --target $env:TEST_TARGET }
catch { type Testing/Temporary/LastTest.log }
#after_test: #after_test:
# - 'make coveralls' # - 'make coveralls'
@ -50,9 +80,6 @@ notifications:
to: [franklinmathieu@gmail.com] to: [franklinmathieu@gmail.com]
on_build_status_changed: true on_build_status_changed: true
artifacts:
- path: '**\*.tar.bz2'
deploy: deploy:
provider: GitHub provider: GitHub
auth_token: auth_token:

@ -1 +1 @@
Subproject commit 04cd477d1f213e55d2ddecab2fcd52d1c7865dfa Subproject commit 2762164acfaa712fea7dec6ed760ff88f7d2e026

1
dependencies/wingetopt vendored Submodule

@ -0,0 +1 @@
Subproject commit 76a5d1ab15f684d4c9479a32624d65b3bd1a726b

View file

@ -26,6 +26,6 @@
# include "common.h" # include "common.h"
NORETURN void criterion_abort_test(void); CR_API NORETURN void criterion_abort_test(void);
#endif /* !CRITERION_ABORT_H_ */ #endif /* !CRITERION_ABORT_H_ */

View file

@ -111,4 +111,29 @@
# define FORMAT(Archetype, Index, Ftc) # define FORMAT(Archetype, Index, Ftc)
# endif # endif
# if defined _WIN32 || defined __CYGWIN__
# ifdef CRITERION_BUILDING_DLL
# ifdef __GNUC__
# define CR_API __attribute__ ((dllexport))
# else
# define CR_API __declspec(dllexport)
# endif
# else
# ifdef __GNUC__
# define CR_API __attribute__ ((dllimport))
# else
# define CR_API __declspec(dllimport)
# endif
# endif
# define CR_LOCAL
# else
# if __GNUC__ >= 4
# define CR_API __attribute__ ((visibility ("default")))
# define CR_LOCAL __attribute__ ((visibility ("hidden")))
# else
# define CR_API
# define CR_LOCAL
# endif
# endif
#endif /* !CRITERION_COMMON_H_ */ #endif /* !CRITERION_COMMON_H_ */

View file

@ -67,6 +67,6 @@
.data = &SUITE_IDENTIFIER_(Name, extra), \ .data = &SUITE_IDENTIFIER_(Name, extra), \
} SECTION_SUFFIX_ } SECTION_SUFFIX_
int criterion_run_all_tests(void); CR_API int criterion_run_all_tests(void);
#endif /* !CRITERION_H_ */ #endif /* !CRITERION_H_ */

View file

@ -26,9 +26,10 @@
# include <stddef.h> # include <stddef.h>
# include <stdio.h> # include <stdio.h>
# include "common.h"
extern FILE *g_event_pipe; extern FILE *g_event_pipe;
void send_event(int kind, void *data, size_t size); CR_API void send_event(int kind, void *data, size_t size);
#endif /* !CRITERION_EVENT_H_ */ #endif /* !CRITERION_EVENT_H_ */

View file

@ -76,13 +76,13 @@ extern const struct criterion_prefix_data g_criterion_logging_prefixes[];
# define CRITERION_PREFIX_PASS (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_PASS ]) # define CRITERION_PREFIX_PASS (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_PASS ])
# define CRITERION_PREFIX_FAIL (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_FAIL ]) # define CRITERION_PREFIX_FAIL (&g_criterion_logging_prefixes[CRITERION_LOGGING_PREFIX_FAIL ])
void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args); CR_API void criterion_vlog(enum criterion_logging_level level, const char *msg, va_list args);
FORMAT(printf, 3, 4) FORMAT(printf, 3, 4)
void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...); CR_API void criterion_plog(enum criterion_logging_level level, const struct criterion_prefix_data *prefix, const char *msg, ...);
FORMAT(printf, 2, 3) FORMAT(printf, 2, 3)
void criterion_log(enum criterion_logging_level level, const char *msg, ...); CR_API void criterion_log(enum criterion_logging_level level, const char *msg, ...);
# define criterion_info(...) criterion_log(CRITERION_INFO, __VA_ARGS__) # define criterion_info(...) criterion_log(CRITERION_INFO, __VA_ARGS__)
# define criterion_important(...) criterion_log(CRITERION_IMPORTANT, __VA_ARGS__) # define criterion_important(...) criterion_log(CRITERION_IMPORTANT, __VA_ARGS__)

View file

@ -50,10 +50,10 @@ struct criterion_test_set {
size_t tests; size_t tests;
}; };
struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp, CR_API struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp,
void (*dtor)(void *, void *)); void (*dtor)(void *, void *));
void *insert_ordered_set(struct criterion_ordered_set *l, CR_API void *insert_ordered_set(struct criterion_ordered_set *l,
void *ptr, void *ptr,
size_t size); size_t size);

View file

@ -29,14 +29,14 @@
struct criterion_theory_context; struct criterion_theory_context;
struct criterion_theory_context* cr_theory_init(void); CR_API struct criterion_theory_context* cr_theory_init(void);
void cr_theory_push_arg(struct criterion_theory_context *ctx, bool is_float, size_t size, void *ptr); CR_API void cr_theory_push_arg(struct criterion_theory_context *ctx, bool is_float, size_t size, void *ptr);
void cr_theory_free(struct criterion_theory_context *ctx); CR_API void cr_theory_free(struct criterion_theory_context *ctx);
void cr_theory_abort(void); CR_API void cr_theory_abort(void);
int cr_theory_mark(void); CR_API int cr_theory_mark(void);
void cr_theory_reset(struct criterion_theory_context *ctx); CR_API void cr_theory_reset(struct criterion_theory_context *ctx);
void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(void)); CR_API void cr_theory_call(struct criterion_theory_context *ctx, void (*fnptr)(void));
# define TheoryDataPoints(Category, Name) \ # define TheoryDataPoints(Category, Name) \
static struct criterion_datapoints IDENTIFIER_(Category, Name, dps)[] static struct criterion_datapoints IDENTIFIER_(Category, Name, dps)[]
@ -64,7 +64,7 @@ struct criterion_datapoints {
cr_theory_abort(); \ cr_theory_abort(); \
} while (0); } while (0);
void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)); CR_API void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void));
# define CR_VAARG_ID(Suffix, Category, Name, ...) \ # define CR_VAARG_ID(Suffix, Category, Name, ...) \
IDENTIFIER_(Category, Name, Suffix) IDENTIFIER_(Category, Name, Suffix)

View file

@ -1,4 +1,6 @@
set(CMAKE_C_FLAGS "-std=c99 -Wall -Wextra -pedantic") if (NOT MSVC)
set(CMAKE_C_FLAGS "-std=c99 -Wall -Wextra -pedantic")
endif ()
include_directories(../include) include_directories(../include)
@ -38,14 +40,18 @@ foreach(sample ${SAMPLES})
ENVIRONMENT "CRITERION_ALWAYS_SUCCEED=1" ENVIRONMENT "CRITERION_ALWAYS_SUCCEED=1"
) )
add_test(${sample}_compare sh ${CMAKE_CURRENT_LIST_DIR}/tests/run_test.sh "${CMAKE_CURRENT_LIST_DIR}" . . ${sample}) if (NOT MSVC) # we disable the scripted tests when building with MSVC
set_property(TEST ${sample}_compare PROPERTY add_test(${sample}_compare sh ${CMAKE_CURRENT_LIST_DIR}/tests/run_test.sh "${CMAKE_CURRENT_LIST_DIR}" . . ${sample})
ENVIRONMENT "LC_ALL=en_US.utf8" set_property(TEST ${sample}_compare PROPERTY
ENVIRONMENT "CRITERION_ALWAYS_SUCCEED=1" ENVIRONMENT "LC_ALL=en_US.utf8"
ENVIRONMENT "CRITERION_SHORT_FILENAME=1" ENVIRONMENT "CRITERION_ALWAYS_SUCCEED=1"
) ENVIRONMENT "CRITERION_SHORT_FILENAME=1"
)
endif ()
endforeach() endforeach()
if (NOT MSVC) # we disable the scripted tests when building with MSVC
foreach(script ${SCRIPTS}) foreach(script ${SCRIPTS})
add_test(${script} sh ${CMAKE_CURRENT_LIST_DIR}/tests/${script}.sh) add_test(${script} sh ${CMAKE_CURRENT_LIST_DIR}/tests/${script}.sh)
set_property(TEST ${script} PROPERTY set_property(TEST ${script} PROPERTY
@ -59,3 +65,5 @@ foreach(script ${SCRIPTS})
ENVIRONMENT "CRITERION_SHORT_FILENAME=1" ENVIRONMENT "CRITERION_SHORT_FILENAME=1"
) )
endforeach() endforeach()
endif()

View file

@ -64,6 +64,10 @@ Test(asserts, array) {
int arr1[] = {1, 2, 3, 4}; int arr1[] = {1, 2, 3, 4};
int arr2[] = {4, 3, 2, 1}; int arr2[] = {4, 3, 2, 1};
cr_assert_arrays_eq(arr1, arr1, 4);
cr_assert_arrays_neq(arr1, arr2, 4);
#ifdef __GNUC__
struct dummy_struct s1[] = {{4, 2}, {2, 4}}; struct dummy_struct s1[] = {{4, 2}, {2, 4}};
struct dummy_struct s2[2]; struct dummy_struct s2[2];
memset(s2, 0xFF, sizeof(s2)); memset(s2, 0xFF, sizeof(s2));
@ -72,9 +76,7 @@ Test(asserts, array) {
s2[1].a = 2; s2[1].a = 2;
s2[1].b = 4; s2[1].b = 4;
cr_assert_arrays_eq(arr1, arr1, 4);
cr_assert_arrays_neq(arr1, arr2, 4);
cr_assert_arrays_neq(s1, s2, 2); cr_assert_arrays_neq(s1, s2, 2);
cr_assert_arrays_eq_cmp(s1, s2, 2, eq_dummy); cr_assert_arrays_eq_cmp(s1, s2, 2, eq_dummy);
#endif
} }

37
src/common.h Normal file
View file

@ -0,0 +1,37 @@
/*
* 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 COMMON_H_
# define COMMON_H_
#ifdef __GNUC__
# define INLINE __attribute__((always_inline)) inline
#elif defined(_MSC_VER)
# define INLINE __forceinline
#else
# define INLINE
#endif
# define DEF(X, Y) ((X) ? (X) : (Y))
#endif /* !COMMON_H_ */

View file

@ -23,7 +23,8 @@
*/ */
#include <stdio.h> #include <stdio.h>
#include <csptr/smart_ptr.h> #include <string.h>
#include <csptr/smalloc.h>
#include "criterion/stats.h" #include "criterion/stats.h"
#include "criterion/common.h" #include "criterion/common.h"
#include "criterion/hooks.h" #include "criterion/hooks.h"
@ -50,9 +51,12 @@ struct event *read_event(FILE *f) {
return NULL; return NULL;
} }
return unique_ptr(struct event, struct event *ev = smalloc(
.value = { .kind = kind, .data = buf }, .size = sizeof (struct event),
.dtor = destroy_event); .dtor = destroy_event
);
*ev = (struct event) { .kind = kind, .data = buf };
return ev;
} }
case THEORY_FAIL: { case THEORY_FAIL: {
size_t *len = malloc(sizeof (size_t)); size_t *len = malloc(sizeof (size_t));
@ -69,10 +73,12 @@ struct event *read_event(FILE *f) {
} }
free(len); free(len);
return unique_ptr(struct event, struct event *ev = smalloc(
.value = { .kind = kind, .data = buf }, .size = sizeof (struct event),
.dtor = destroy_event); .dtor = destroy_event
);
*ev = (struct event) { .kind = kind, .data = buf };
return ev;
} }
case POST_TEST: { case POST_TEST: {
double *elapsed_time = malloc(sizeof (double)); double *elapsed_time = malloc(sizeof (double));
@ -81,19 +87,26 @@ struct event *read_event(FILE *f) {
return NULL; return NULL;
} }
return unique_ptr(struct event, struct event *ev = smalloc(
.value = { .kind = kind, .data = elapsed_time }, .size = sizeof (struct event),
.dtor = destroy_event); .dtor = destroy_event
);
*ev = (struct event) { .kind = kind, .data = elapsed_time };
return ev;
}
default: {
struct event *ev = smalloc(sizeof (struct event));
*ev = (struct event) { .kind = kind, .data = NULL };
return ev;
} }
default:
return unique_ptr(struct event, { .kind = kind, .data = NULL });
} }
} }
void send_event(int kind, void *data, size_t size) { void send_event(int kind, void *data, size_t size) {
unsigned char buf[sizeof (int) + size]; unsigned char *buf = malloc(sizeof (int) + size);
memcpy(buf, &kind, sizeof (int)); memcpy(buf, &kind, sizeof (int));
memcpy(buf + sizeof (int), data, size); memcpy(buf + sizeof (int), data, size);
if (fwrite(buf, sizeof (int) + size, 1, g_event_pipe) == 0) if (fwrite(buf, sizeof (int) + size, 1, g_event_pipe) == 0)
abort(); abort();
free(buf);
} }

View file

@ -28,6 +28,7 @@
#include <stdio.h> #include <stdio.h>
#include "criterion/common.h" #include "criterion/common.h"
#include "common.h"
struct context { struct context {
int depth; int depth;
@ -107,20 +108,20 @@ static int is_eos(struct context *ctx) {
static inline void handle_special(struct context *ctx, handler_arg strs[5]) { static inline void handle_special(struct context *ctx, handler_arg strs[5]) {
if (peek_char(ctx) == '(') { if (peek_char(ctx) == '(') {
if ((strs[0].validator ?: inactive)(ctx)) if (DEF(strs[0].validator, inactive)(ctx))
copy_str(ctx, strs[0].str); copy_str(ctx, strs[0].str);
dup_char(ctx); dup_char(ctx);
if ((strs[1].validator ?: inactive)(ctx)) if (DEF(strs[1].validator, inactive)(ctx))
copy_str(ctx, strs[1].str); copy_str(ctx, strs[1].str);
transform_rec(ctx); transform_rec(ctx);
if ((strs[2].validator ?: inactive)(ctx)) if (DEF(strs[2].validator, inactive)(ctx))
copy_str(ctx,strs[2].str); copy_str(ctx,strs[2].str);
copy_char(ctx, ')'); copy_char(ctx, ')');
if ((strs[3].validator ?: inactive)(ctx)) if (DEF(strs[3].validator, inactive)(ctx))
copy_str(ctx, strs[3].str); copy_str(ctx, strs[3].str);
} else if ((strs[4].validator ?: inactive)(ctx)) { } else if (DEF(strs[4].validator, inactive)(ctx)) {
copy_str(ctx, strs[4].str); copy_str(ctx, strs[4].str);
} }
} }
@ -191,7 +192,7 @@ void transform_impl(struct context *ctx) {
if (c == ')' && ctx->depth > 0) if (c == ')' && ctx->depth > 0)
return; return;
(handler ?: copy_char)(ctx, c); (handler ? handler : copy_char)(ctx, c);
if (ctx->eos) if (ctx->eos)
return; return;

View file

@ -1,8 +1,7 @@
#include "i18n.h" #include "i18n.h"
#if ENABLE_NLS
__attribute__ ((constructor))
void init_i18n(void) { void init_i18n(void) {
#if ENABLE_NLS
bindtextdomain (PACKAGE, LOCALEDIR); bindtextdomain (PACKAGE, LOCALEDIR);
}
#endif #endif
}

View file

@ -13,4 +13,6 @@
dngettext(PACKAGE, String, Plural, (Quantity)) dngettext(PACKAGE, String, Plural, (Quantity))
# endif # endif
void init_i18n(void);
#endif /* !I18N_H_ */ #endif /* !I18N_H_ */

View file

@ -34,8 +34,7 @@
#include "config.h" #include "config.h"
#include "i18n.h" #include "i18n.h"
#include "posix-compat.h" #include "posix-compat.h"
#include "common.h"
#define USED __attribute__ ((used))
#ifdef VANILLA_WIN32 #ifdef VANILLA_WIN32
// fallback to strtok on windows since strtok_s is not available everywhere // fallback to strtok on windows since strtok_s is not available everywhere
@ -119,8 +118,7 @@ void normal_log_post_test(struct criterion_test_stats *stats) {
stats->elapsed_time); stats->elapsed_time);
} }
__attribute__((always_inline)) static INLINE bool is_disabled(struct criterion_test *t,
static inline bool is_disabled(struct criterion_test *t,
struct criterion_suite *s) { struct criterion_suite *s) {
return t->data->disabled || (s->data && s->data->disabled); return t->data->disabled || (s->data && s->data->disabled);
} }

View file

@ -32,6 +32,7 @@
#include "timer.h" #include "timer.h"
#include "config.h" #include "config.h"
#include "posix-compat.h" #include "posix-compat.h"
#include "common.h"
void tap_log_pre_all(struct criterion_test_set *set) { void tap_log_pre_all(struct criterion_test_set *set) {
size_t enabled_count = 0; size_t enabled_count = 0;
@ -54,8 +55,7 @@ void tap_log_pre_suite(struct criterion_suite_set *set) {
set->suite.name); set->suite.name);
} }
__attribute__((always_inline)) static INLINE bool is_disabled(struct criterion_test *t, struct criterion_suite *s) {
static inline bool is_disabled(struct criterion_test *t, struct criterion_suite *s) {
return t->data->disabled || (s->data && s->data->disabled); return t->data->disabled || (s->data && s->data->disabled);
} }
@ -65,7 +65,7 @@ void tap_log_post_suite(struct criterion_suite_stats *stats) {
criterion_important("ok - %s::%s %s # SKIP %s is disabled\n", criterion_important("ok - %s::%s %s # SKIP %s is disabled\n",
ts->test->category, ts->test->category,
ts->test->name, ts->test->name,
ts->test->data->description ?: "", DEF(ts->test->data->description, ""),
ts->test->data->disabled ? "test" : "suite"); ts->test->data->disabled ? "test" : "suite");
} }
} }
@ -78,7 +78,7 @@ void tap_log_post_test(struct criterion_test_stats *stats) {
stats->failed ? "not ok" : "ok", stats->failed ? "not ok" : "ok",
stats->test->category, stats->test->category,
stats->test->name, stats->test->name,
stats->test->data->description ?: "", DEF(stats->test->data->description, ""),
stats->elapsed_time); stats->elapsed_time);
for (struct criterion_assert_stats *asrt = stats->asserts; asrt; asrt = asrt->next) { for (struct criterion_assert_stats *asrt = stats->asserts; asrt; asrt = asrt->next) {
if (!asrt->passed) { if (!asrt->passed) {

View file

@ -28,9 +28,10 @@
#include <stdio.h> #include <stdio.h>
#include <locale.h> #include <locale.h>
#include <getopt.h> #include <getopt.h>
#include <csptr/smart_ptr.h> #include <csptr/smalloc.h>
#include "runner.h" #include "runner.h"
#include "config.h" #include "config.h"
#include "common.h"
#if ENABLE_NLS #if ENABLE_NLS
# include <libintl.h> # include <libintl.h>
@ -90,7 +91,7 @@ bool is_disabled(struct criterion_suite *s, struct criterion_test *t) {
} }
int list_tests(bool unicode) { int list_tests(bool unicode) {
smart struct criterion_test_set *set = criterion_init(); struct criterion_test_set *set = criterion_init();
const char *node = unicode ? UTF8_TREE_NODE : ASCII_TREE_NODE; const char *node = unicode ? UTF8_TREE_NODE : ASCII_TREE_NODE;
const char *join = unicode ? UTF8_TREE_JOIN : ASCII_TREE_JOIN; const char *join = unicode ? UTF8_TREE_JOIN : ASCII_TREE_JOIN;
@ -114,10 +115,12 @@ int list_tests(bool unicode) {
is_disabled(&s->suite, t) ? " (disabled)" : ""); is_disabled(&s->suite, t) ? " (disabled)" : "");
} }
} }
sfree(set);
return 0; return 0;
} }
int main(int argc, char *argv[]) { CR_API int main(int argc, char *argv[]) {
static struct option opts[] = { static struct option opts[] = {
{"verbose", optional_argument, 0, 'b'}, {"verbose", optional_argument, 0, 'b'},
{"version", no_argument, 0, 'v'}, {"version", no_argument, 0, 'v'},
@ -135,8 +138,8 @@ int main(int argc, char *argv[]) {
{0, 0, 0, 0 } {0, 0, 0, 0 }
}; };
bool use_ascii = !strcmp("1", getenv("CRITERION_USE_ASCII") ?: "0") bool use_ascii = !strcmp("1", DEF(getenv("CRITERION_USE_ASCII"), "0"))
|| !strcmp("dumb", getenv("TERM") ?: "dumb"); || !strcmp("dumb", DEF(getenv("TERM"), "dumb"));
setlocale(LC_ALL, ""); setlocale(LC_ALL, "");
#if ENABLE_NLS #if ENABLE_NLS
@ -144,24 +147,24 @@ int main(int argc, char *argv[]) {
#endif #endif
struct criterion_options *opt = &criterion_options; struct criterion_options *opt = &criterion_options;
opt->always_succeed = !strcmp("1", getenv("CRITERION_ALWAYS_SUCCEED") ?: "0"); opt->always_succeed = !strcmp("1", DEF(getenv("CRITERION_ALWAYS_SUCCEED"), "0"));
opt->no_early_exit = !strcmp("1", getenv("CRITERION_NO_EARLY_EXIT") ?: "0"); opt->no_early_exit = !strcmp("1", DEF(getenv("CRITERION_NO_EARLY_EXIT") , "0"));
opt->fail_fast = !strcmp("1", getenv("CRITERION_FAIL_FAST") ?: "0"); opt->fail_fast = !strcmp("1", DEF(getenv("CRITERION_FAIL_FAST") , "0"));
opt->use_ascii = use_ascii; opt->use_ascii = use_ascii;
opt->logging_threshold = atoi(getenv("CRITERION_VERBOSITY_LEVEL") ?: "2"); opt->logging_threshold = atoi(DEF(getenv("CRITERION_VERBOSITY_LEVEL"), "2"));
opt->short_filename = !strcmp("1", getenv("CRITERION_SHORT_FILENAME") ?: "0"); opt->short_filename = !strcmp("1", DEF(getenv("CRITERION_SHORT_FILENAME"), "0"));
#ifdef HAVE_PCRE #ifdef HAVE_PCRE
opt->pattern = getenv("CRITERION_TEST_PATTERN"); opt->pattern = getenv("CRITERION_TEST_PATTERN");
#endif #endif
bool use_tap = !strcmp("1", getenv("CRITERION_ENABLE_TAP") ?: "0"); bool use_tap = !strcmp("1", DEF(getenv("CRITERION_ENABLE_TAP"), "0"));
bool do_list_tests = false; bool do_list_tests = false;
bool do_print_version = false; bool do_print_version = false;
bool do_print_usage = false; bool do_print_usage = false;
for (int c; (c = getopt_long(argc, argv, "hvlfS", opts, NULL)) != -1;) { for (int c; (c = getopt_long(argc, argv, "hvlfS", opts, NULL)) != -1;) {
switch (c) { switch (c) {
case 'b': criterion_options.logging_threshold = atoi(optarg ?: "1"); break; case 'b': criterion_options.logging_threshold = atoi(DEF(optarg, "1")); break;
case 'y': criterion_options.always_succeed = true; break; case 'y': criterion_options.always_succeed = true; break;
case 'z': criterion_options.no_early_exit = true; break; case 'z': criterion_options.no_early_exit = true; break;
case 'k': criterion_options.use_ascii = true; break; case 'k': criterion_options.use_ascii = true; break;

View file

@ -21,30 +21,36 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <string.h>
#include <criterion/common.h> #include <criterion/common.h>
#include <criterion/ordered-set.h> #include <criterion/ordered-set.h>
#include <csptr/smart_ptr.h> #include <csptr/smalloc.h>
#include "common.h"
static void destroy_ordered_set(void *ptr, UNUSED void *meta) { static void destroy_ordered_set(void *ptr, UNUSED void *meta) {
sfree(((struct criterion_ordered_set *) ptr)->first); sfree(((struct criterion_ordered_set *) ptr)->first);
} }
__attribute__ ((always_inline)) static INLINE void nothing() {}
static inline void nothing() {}
static void destroy_ordered_set_node(void *ptr, void *meta) { static void destroy_ordered_set_node(void *ptr, void *meta) {
struct criterion_ordered_set *set = *(void **) meta; struct criterion_ordered_set *set = *(void **) meta;
struct criterion_ordered_set_node *n = ptr; struct criterion_ordered_set_node *n = ptr;
(set->dtor ?: nothing)(n->data, NULL); DEF(set->dtor, nothing)(n->data, NULL);
sfree(((struct criterion_ordered_set_node *) ptr)->next); sfree(((struct criterion_ordered_set_node *) ptr)->next);
} }
struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp, struct criterion_ordered_set *new_ordered_set(f_criterion_cmp cmp,
f_destructor dtor) { f_destructor dtor) {
return unique_ptr(struct criterion_ordered_set, struct criterion_ordered_set *newset = smalloc(
.value = { .cmp = cmp, .dtor = dtor }, .size = sizeof (struct criterion_ordered_set),
.dtor = destroy_ordered_set); .dtor = destroy_ordered_set
);
struct criterion_ordered_set data = { .cmp = cmp, .dtor = dtor };
memcpy(newset, &data, sizeof (struct criterion_ordered_set));
return newset;
} }
void *insert_ordered_set(struct criterion_ordered_set *l, void *insert_ordered_set(struct criterion_ordered_set *l,

View file

@ -63,7 +63,7 @@
# include <sys/fcntl.h> # include <sys/fcntl.h>
#endif #endif
#include <csptr/smart_ptr.h> #include <csptr/smalloc.h>
struct proc_handle { struct proc_handle {
#ifdef VANILLA_WIN32 #ifdef VANILLA_WIN32
@ -201,14 +201,19 @@ s_proc_handle *fork_process() {
UnmapViewOfFile(ctx); UnmapViewOfFile(ctx);
CloseHandle(sharedMem); CloseHandle(sharedMem);
return unique_ptr(s_proc_handle, { info.hProcess }); s_proc_handle *handle = smalloc(sizeof (s_proc_handle));
*handle = (s_proc_handle) { info.hProcess };
return handle;
#else #else
pid_t pid = fork(); pid_t pid = fork();
if (pid == -1) if (pid == -1)
return (void *) -1; return (void *) -1;
if (pid == 0) if (pid == 0)
return NULL; return NULL;
return unique_ptr(s_proc_handle, { pid });
s_proc_handle *handle = smalloc(sizeof (s_proc_handle));
*handle = (s_proc_handle) { pid };
return handle;
#endif #endif
} }
@ -294,6 +299,7 @@ FILE *pipe_out(s_pipe_handle *p) {
} }
s_pipe_handle *stdpipe() { s_pipe_handle *stdpipe() {
s_pipe_handle *handle = smalloc(sizeof (s_pipe_handle));
#ifdef VANILLA_WIN32 #ifdef VANILLA_WIN32
HANDLE fhs[2]; HANDLE fhs[2];
SECURITY_ATTRIBUTES attr = { SECURITY_ATTRIBUTES attr = {
@ -302,21 +308,25 @@ s_pipe_handle *stdpipe() {
}; };
if (!CreatePipe(fhs, fhs + 1, &attr, 0)) if (!CreatePipe(fhs, fhs + 1, &attr, 0))
return NULL; return NULL;
return unique_ptr(s_pipe_handle, {{ fhs[0], fhs[1] }}); *handle = (s_pipe_handle) {{ fhs[0], fhs[1] }};
return handle;
#else #else
int fds[2] = { -1, -1 }; int fds[2] = { -1, -1 };
if (pipe(fds) == -1) if (pipe(fds) == -1)
return NULL; return NULL;
return unique_ptr(s_pipe_handle, {{ fds[0], fds[1] }}); *handle = (s_pipe_handle) {{ fds[0], fds[1] }};
return handle;
#endif #endif
} }
s_proc_handle *get_current_process() { s_proc_handle *get_current_process() {
s_proc_handle *handle = smalloc(sizeof (s_proc_handle));
#ifdef VANILLA_WIN32 #ifdef VANILLA_WIN32
return unique_ptr(s_proc_handle, { GetCurrentProcess() }); *handle = (s_proc_handle) { GetCurrentProcess() };
#else #else
return unique_ptr(s_proc_handle, { getpid() }); *handle = (s_proc_handle) { getpid() };
#endif #endif
return handle;
} }
bool is_current_process(s_proc_handle *proc) { bool is_current_process(s_proc_handle *proc) {

View file

@ -23,7 +23,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdbool.h> #include <stdbool.h>
#include <csptr/smart_ptr.h> #include <csptr/smalloc.h>
#include "criterion/types.h" #include "criterion/types.h"
#include "criterion/options.h" #include "criterion/options.h"
@ -76,7 +76,7 @@ void run_worker(struct worker_context *ctx) {
struct process *spawn_test_worker(struct criterion_test *test, struct process *spawn_test_worker(struct criterion_test *test,
struct criterion_suite *suite, struct criterion_suite *suite,
f_worker_func func) { f_worker_func func) {
smart s_pipe_handle *pipe = stdpipe(); s_pipe_handle *pipe = stdpipe();
if (pipe == NULL) if (pipe == NULL)
abort(); abort();
@ -86,17 +86,26 @@ struct process *spawn_test_worker(struct criterion_test *test,
.func = func, .func = func,
.pipe = pipe .pipe = pipe
}; };
struct process *ptr = NULL;
s_proc_handle *proc = fork_process(); s_proc_handle *proc = fork_process();
if (proc == (void *) -1) { if (proc == (void *) -1) {
return NULL; goto cleanup;
} else if (proc == NULL) { } else if (proc == NULL) {
run_worker(&g_worker_context); run_worker(&g_worker_context);
return NULL; goto cleanup;
} }
return unique_ptr(struct process, ptr = smalloc(
.value = { .proc = proc, .in = pipe_in(pipe) }, .size = sizeof (struct process),
.dtor = close_process); .kind = UNIQUE,
.dtor = close_process);
*ptr = (struct process) { .proc = proc, .in = pipe_in(pipe) };
cleanup:
sfree(pipe);
return ptr;
} }
struct process_status wait_proc(struct process *proc) { struct process_status wait_proc(struct process *proc) {

View file

@ -41,10 +41,36 @@ static inline void nothing() {}
for (f_report_hook *hook = GET_SECTION_START(HOOK_SECTION(Kind)); \ for (f_report_hook *hook = GET_SECTION_START(HOOK_SECTION(Kind)); \
hook < (f_report_hook*) GET_SECTION_END(HOOK_SECTION(Kind)); \ hook < (f_report_hook*) GET_SECTION_END(HOOK_SECTION(Kind)); \
++hook) { \ ++hook) { \
(*hook ?: nothing)(data); \ (*hook ? *hook : nothing)(data); \
} \ } \
} }
#ifdef _MSC_VER
f_report_hook SECTION_START_(HOOK_SECTION(PRE_ALL));
f_report_hook SECTION_START_(HOOK_SECTION(PRE_SUITE));
f_report_hook SECTION_START_(HOOK_SECTION(PRE_INIT));
f_report_hook SECTION_START_(HOOK_SECTION(PRE_TEST));
f_report_hook SECTION_START_(HOOK_SECTION(ASSERT));
f_report_hook SECTION_START_(HOOK_SECTION(THEORY_FAIL));
f_report_hook SECTION_START_(HOOK_SECTION(TEST_CRASH));
f_report_hook SECTION_START_(HOOK_SECTION(POST_TEST));
f_report_hook SECTION_START_(HOOK_SECTION(POST_FINI));
f_report_hook SECTION_START_(HOOK_SECTION(POST_SUITE));
f_report_hook SECTION_START_(HOOK_SECTION(POST_ALL));
f_report_hook SECTION_END_(HOOK_SECTION(PRE_ALL));
f_report_hook SECTION_END_(HOOK_SECTION(PRE_SUITE));
f_report_hook SECTION_END_(HOOK_SECTION(PRE_INIT));
f_report_hook SECTION_END_(HOOK_SECTION(PRE_TEST));
f_report_hook SECTION_END_(HOOK_SECTION(ASSERT));
f_report_hook SECTION_END_(HOOK_SECTION(THEORY_FAIL));
f_report_hook SECTION_END_(HOOK_SECTION(TEST_CRASH));
f_report_hook SECTION_END_(HOOK_SECTION(POST_TEST));
f_report_hook SECTION_END_(HOOK_SECTION(POST_FINI));
f_report_hook SECTION_END_(HOOK_SECTION(POST_SUITE));
f_report_hook SECTION_END_(HOOK_SECTION(POST_ALL));
#endif
IMPL_CALL_REPORT_HOOKS(PRE_ALL); IMPL_CALL_REPORT_HOOKS(PRE_ALL);
IMPL_CALL_REPORT_HOOKS(PRE_SUITE); IMPL_CALL_REPORT_HOOKS(PRE_SUITE);
IMPL_CALL_REPORT_HOOKS(PRE_INIT); IMPL_CALL_REPORT_HOOKS(PRE_INIT);

View file

@ -45,6 +45,8 @@ DECL_CALL_REPORT_HOOKS(POST_SUITE);
DECL_CALL_REPORT_HOOKS(POST_ALL); DECL_CALL_REPORT_HOOKS(POST_ALL);
#define log(Type, Arg) \ #define log(Type, Arg) \
(criterion_options.output_provider->log_ ## Type ?: nothing)(Arg); log_(criterion_options.output_provider->log_ ## Type, Arg);
#define log_(Log, Arg) \
(Log ? Log : nothing)(Arg);
#endif /* !REPORT_H_ */ #endif /* !REPORT_H_ */

View file

@ -23,7 +23,7 @@
*/ */
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <csptr/smart_ptr.h> #include <csptr/smalloc.h>
#include "criterion/criterion.h" #include "criterion/criterion.h"
#include "criterion/options.h" #include "criterion/options.h"
#include "criterion/ordered-set.h" #include "criterion/ordered-set.h"
@ -37,11 +37,20 @@
#include "posix-compat.h" #include "posix-compat.h"
#include "abort.h" #include "abort.h"
#include "config.h" #include "config.h"
#include "i18n.h"
#include "common.h"
#ifdef HAVE_PCRE #ifdef HAVE_PCRE
#include "extmatch.h" #include "extmatch.h"
#endif #endif
#ifdef _MSC_VER
struct criterion_test SECTION_START_(cr_tst);
struct criterion_suite SECTION_START_(cr_sts);
struct criterion_test SECTION_END_(cr_tst);
struct criterion_suite SECTION_END_(cr_sts);
#endif
IMPL_SECTION_LIMITS(struct criterion_test, cr_tst); IMPL_SECTION_LIMITS(struct criterion_test, cr_tst);
IMPL_SECTION_LIMITS(struct criterion_suite, cr_sts); IMPL_SECTION_LIMITS(struct criterion_suite, cr_sts);
@ -49,8 +58,7 @@ IMPL_SECTION_LIMITS(struct criterion_suite, cr_sts);
TestSuite(); TestSuite();
Test(,) {}; Test(,) {};
__attribute__ ((always_inline)) static INLINE void nothing() {}
static inline void nothing() {}
int cmp_suite(void *a, void *b) { int cmp_suite(void *a, void *b) {
struct criterion_suite *s1 = a, *s2 = b; struct criterion_suite *s1 = a, *s2 = b;
@ -104,10 +112,17 @@ struct criterion_test_set *criterion_init(void) {
++nb_tests; ++nb_tests;
} }
return unique_ptr(struct criterion_test_set, { struct criterion_test_set *set = smalloc(
.size = sizeof (struct criterion_test_set),
.dtor = dtor_test_set
);
*set = (struct criterion_test_set) {
suites, suites,
nb_tests, nb_tests,
}, dtor_test_set); };
return set;
} }
typedef void (*f_test_run)(struct criterion_global_stats *, typedef void (*f_test_run)(struct criterion_global_stats *,
@ -126,7 +141,7 @@ static void map_tests(struct criterion_test_set *set,
report(PRE_SUITE, s); report(PRE_SUITE, s);
log(pre_suite, s); log(pre_suite, s);
smart struct criterion_suite_stats *suite_stats = suite_stats_init(&s->suite); struct criterion_suite_stats *suite_stats = suite_stats_init(&s->suite);
struct event ev = { .kind = PRE_SUITE }; struct event ev = { .kind = PRE_SUITE };
stat_push_event(stats, suite_stats, NULL, &ev); stat_push_event(stats, suite_stats, NULL, &ev);
@ -135,13 +150,18 @@ static void map_tests(struct criterion_test_set *set,
fun(stats, suite_stats, t, &s->suite); fun(stats, suite_stats, t, &s->suite);
if (criterion_options.fail_fast && stats->tests_failed > 0) if (criterion_options.fail_fast && stats->tests_failed > 0)
break; break;
if (!is_runner()) if (!is_runner()) {
sfree(suite_stats);
return; return;
}
} }
report(POST_SUITE, suite_stats); report(POST_SUITE, suite_stats);
log(post_suite, suite_stats); log(post_suite, suite_stats);
sfree(suite_stats);
} }
} }
static void run_test_child(struct criterion_test *test, static void run_test_child(struct criterion_test *test,
@ -149,14 +169,14 @@ static void run_test_child(struct criterion_test *test,
send_event(PRE_INIT, NULL, 0); send_event(PRE_INIT, NULL, 0);
if (suite->data) if (suite->data)
(suite->data->init ?: nothing)(); (suite->data->init ? suite->data->init : nothing)();
(test->data->init ?: nothing)(); (test->data->init ? test->data->init : nothing)();
send_event(PRE_TEST, NULL, 0); send_event(PRE_TEST, NULL, 0);
struct timespec_compat ts; struct timespec_compat ts;
if (setup_abort_test()) { if (setup_abort_test()) {
timer_start(&ts); timer_start(&ts);
(test->test ?: nothing)(); (test->test ? test->test : nothing)();
} }
double elapsed_time; double elapsed_time;
@ -164,14 +184,13 @@ static void run_test_child(struct criterion_test *test,
elapsed_time = -1; elapsed_time = -1;
send_event(POST_TEST, &elapsed_time, sizeof (double)); send_event(POST_TEST, &elapsed_time, sizeof (double));
(test->data->fini ?: nothing)(); (test->data->fini ? test->data->fini : nothing)();
if (suite->data) if (suite->data)
(suite->data->fini ?: nothing)(); (suite->data->fini ? suite->data->fini : nothing)();
send_event(POST_FINI, NULL, 0); send_event(POST_FINI, NULL, 0);
} }
__attribute__((always_inline)) static INLINE bool is_disabled(struct criterion_test *t,
static inline bool is_disabled(struct criterion_test *t,
struct criterion_suite *s) { struct criterion_suite *s) {
return t->data->disabled || (s->data && s->data->disabled); return t->data->disabled || (s->data && s->data->disabled);
@ -191,19 +210,20 @@ static void run_test(struct criterion_global_stats *stats,
struct criterion_test *test, struct criterion_test *test,
struct criterion_suite *suite) { struct criterion_suite *suite) {
smart struct criterion_test_stats *test_stats = test_stats_init(test); struct criterion_test_stats *test_stats = test_stats_init(test);
struct process *proc = NULL;
if (is_disabled(test, suite)) { if (is_disabled(test, suite)) {
stat_push_event(stats, stat_push_event(stats,
suite_stats, suite_stats,
test_stats, test_stats,
&(struct event) { .kind = PRE_INIT }); &(struct event) { .kind = PRE_INIT });
return; goto cleanup;
} }
smart struct process *proc = spawn_test_worker(test, suite, run_test_child); proc = spawn_test_worker(test, suite, run_test_child);
if (proc == NULL && !is_runner()) if (proc == NULL && !is_runner())
return; goto cleanup;
bool test_started = false; bool test_started = false;
bool normal_finish = false; bool normal_finish = false;
@ -257,7 +277,7 @@ static void run_test(struct criterion_global_stats *stats,
test_stats, test_stats,
&(struct event) { .kind = TEST_CRASH }); &(struct event) { .kind = TEST_CRASH });
} }
return; goto cleanup;
} }
test_stats->signal = status.status; test_stats->signal = status.status;
if (test->data->signal == 0) { if (test->data->signal == 0) {
@ -279,7 +299,7 @@ static void run_test(struct criterion_global_stats *stats,
test_stats, test_stats,
&(struct event) { .kind = TEST_CRASH }); &(struct event) { .kind = TEST_CRASH });
} }
return; goto cleanup;
} }
test_stats->exit_code = status.status; test_stats->exit_code = status.status;
if (!normal_finish) { if (!normal_finish) {
@ -295,6 +315,10 @@ static void run_test(struct criterion_global_stats *stats,
} }
} }
} }
cleanup:
sfree(test_stats);
sfree(proc);
} }
#ifdef HAVE_PCRE #ifdef HAVE_PCRE
@ -321,7 +345,7 @@ static int criterion_run_all_tests_impl(void) {
if (resume_child()) // (windows only) resume from the fork if (resume_child()) // (windows only) resume from the fork
return -1; return -1;
smart struct criterion_test_set *set = criterion_init(); struct criterion_test_set *set = criterion_init();
#ifdef HAVE_PCRE #ifdef HAVE_PCRE
if (criterion_options.pattern) if (criterion_options.pattern)
disable_unmatching(set); disable_unmatching(set);
@ -332,18 +356,25 @@ static int criterion_run_all_tests_impl(void) {
fflush(NULL); // flush everything before forking fflush(NULL); // flush everything before forking
smart struct criterion_global_stats *stats = stats_init(); struct criterion_global_stats *stats = stats_init();
map_tests(set, stats, run_test); map_tests(set, stats, run_test);
int result = is_runner() ? stats->tests_failed == 0 : -1;
if (!is_runner()) if (!is_runner())
return -1; goto cleanup;
report(POST_ALL, stats); report(POST_ALL, stats);
log(post_all, stats); log(post_all, stats);
return stats->tests_failed == 0;
cleanup:
sfree(set);
sfree(stats);
return result;
} }
int criterion_run_all_tests(void) { int criterion_run_all_tests(void) {
init_i18n();
set_runner_process(); set_runner_process();
int res = criterion_run_all_tests_impl(); int res = criterion_run_all_tests_impl();
unset_runner_process(); unset_runner_process();

View file

@ -21,9 +21,11 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <csptr/smart_ptr.h> #include <string.h>
#include <csptr/smalloc.h>
#include "criterion/common.h" #include "criterion/common.h"
#include "stats.h" #include "stats.h"
#include "common.h"
#include <assert.h> #include <assert.h>
@ -48,7 +50,12 @@ static void destroy_stats(void *ptr, UNUSED void *meta) {
} }
s_glob_stats *stats_init(void) { s_glob_stats *stats_init(void) {
return unique_ptr(s_glob_stats, .dtor = destroy_stats); s_glob_stats *stats = smalloc(
.size = sizeof (s_glob_stats),
.dtor = destroy_stats
);
*stats = (s_glob_stats) { .suites = NULL };
return stats;
} }
static void destroy_suite_stats(void *ptr, UNUSED void *meta) { static void destroy_suite_stats(void *ptr, UNUSED void *meta) {
@ -60,9 +67,13 @@ static void destroy_suite_stats(void *ptr, UNUSED void *meta) {
} }
s_suite_stats *suite_stats_init(struct criterion_suite *s) { s_suite_stats *suite_stats_init(struct criterion_suite *s) {
return shared_ptr(s_suite_stats, { s_suite_stats *stats = smalloc(
.suite = s, .size = sizeof (s_suite_stats),
}, destroy_suite_stats); .kind = SHARED,
.dtor = destroy_suite_stats
);
*stats = (s_suite_stats) { .suite = s };
return stats;
} }
static void destroy_test_stats(void *ptr, UNUSED void *meta) { static void destroy_test_stats(void *ptr, UNUSED void *meta) {
@ -74,11 +85,17 @@ static void destroy_test_stats(void *ptr, UNUSED void *meta) {
} }
s_test_stats *test_stats_init(struct criterion_test *t) { s_test_stats *test_stats_init(struct criterion_test *t) {
return shared_ptr(s_test_stats, { s_test_stats *stats = smalloc(
.test = t, .size = sizeof (s_test_stats),
.progress = t->data->line_, .kind = SHARED,
.file = t->data->file_ .dtor = destroy_test_stats
}, destroy_test_stats); );
*stats = (s_test_stats) {
.test = t,
.progress = t->data->line_,
.file = t->data->file_
};
return stats;
} }
void stat_push_event(s_glob_stats *stats, void stat_push_event(s_glob_stats *stats,
@ -114,8 +131,7 @@ static void push_pre_suite(s_glob_stats *stats,
++stats->nb_suites; ++stats->nb_suites;
} }
__attribute__((always_inline)) static INLINE bool is_disabled(struct criterion_test *t,
static inline bool is_disabled(struct criterion_test *t,
struct criterion_suite *s) { struct criterion_suite *s) {
return t->data->disabled || (s->data && s->data->disabled); return t->data->disabled || (s->data && s->data->disabled);
@ -140,7 +156,9 @@ static void push_assert(s_glob_stats *stats,
s_suite_stats *suite, s_suite_stats *suite,
s_test_stats *test, s_test_stats *test,
s_assert_stats *data) { s_assert_stats *data) {
s_assert_stats *dup = unique_ptr(s_assert_stats, (*data)); s_assert_stats *dup = smalloc(sizeof (s_assert_stats));
memcpy(dup, data, sizeof (s_assert_stats));
dup->next = test->asserts; dup->next = test->asserts;
test->asserts = dup; test->asserts = dup;

View file

@ -186,7 +186,7 @@ static void concat_arg(char (*msg)[4096], struct criterion_datapoints *dps, size
void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)) { void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*fnptr)(void)) {
struct criterion_theory_context *ctx = cr_theory_init(); struct criterion_theory_context *ctx = cr_theory_init();
size_t indices[datapoints]; size_t *indices = malloc(sizeof (size_t) * datapoints);
memset(indices, 0, datapoints * sizeof (size_t)); memset(indices, 0, datapoints * sizeof (size_t));
bool has_next = true; bool has_next = true;
@ -237,5 +237,6 @@ void cr_theory_main(struct criterion_datapoints *dps, size_t datapoints, void (*
} }
} }
free(indices);
cr_theory_free(ctx); cr_theory_free(ctx);
} }

View file

@ -1,4 +1,6 @@
set(CMAKE_C_FLAGS "-std=gnu99 -Wall -Wextra") if (NOT MSVC)
set(CMAKE_C_FLAGS "-std=gnu99 -Wall -Wextra")
endif ()
include_directories(../include ../src) include_directories(../include ../src)

View file

@ -1,4 +1,4 @@
#include <csptr/smart_ptr.h> #include <csptr/smalloc.h>
#include "criterion/criterion.h" #include "criterion/criterion.h"
#include "criterion/ordered-set.h" #include "criterion/ordered-set.h"
@ -14,7 +14,7 @@ int compare_lt(void *a, void *b) {
} }
Test(ordered_set, contract_lt) { Test(ordered_set, contract_lt) {
smart struct criterion_ordered_set *set = new_ordered_set(compare_lt, NULL); struct criterion_ordered_set *set = new_ordered_set(compare_lt, NULL);
insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int)); insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int));
insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int)); insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int));
@ -26,10 +26,12 @@ Test(ordered_set, contract_lt) {
cr_assert_lt(*prev, *e); cr_assert_lt(*prev, *e);
prev = e; prev = e;
} }
sfree(set);
} }
Test(ordered_set, contract_gt) { Test(ordered_set, contract_gt) {
smart struct criterion_ordered_set *set = new_ordered_set(compare_gt, NULL); struct criterion_ordered_set *set = new_ordered_set(compare_gt, NULL);
insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int)); insert_ordered_set(set, &(int[1]) { 1 }, sizeof (int));
insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int)); insert_ordered_set(set, &(int[1]) { 8 }, sizeof (int));
@ -41,4 +43,6 @@ Test(ordered_set, contract_gt) {
cr_assert_gt(*prev, *e); cr_assert_gt(*prev, *e);
prev = e; prev = e;
} }
sfree(set);
} }