Let us walk on the 3-isogeny graph
Loading...
Searching...
No Matches
munit.c File Reference
#include <limits.h>
#include <time.h>
#include <errno.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdarg.h>
#include <setjmp.h>
#include <locale.h>
#include <langinfo.h>
#include <strings.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "munit.h"
#include <assert.h>
Include dependency graph for munit.c:

Go to the source code of this file.

Data Structures

struct  PsnipClockTimespec
struct  MunitReport
struct  MunitTestRunner

Macros

#define MUNIT_OUTPUT_FILE   stdout
#define MUNIT_TEST_TIME_FORMAT   "0.8f"
#define MUNIT_TEST_NAME_LEN   60
#define MUNIT_ENABLE_TIMING
#define _POSIX_C_SOURCE   200809L
#define MUNIT_NL_LANGINFO
#define MUNIT_STRINGIFY(x)
#define MUNIT_XSTRINGIFY(x)
#define MUNIT_STRERROR_LEN   80
#define psnip_uint64_t   munit_uint64_t
#define psnip_uint32_t   munit_uint32_t
#define PSNIP_CLOCK_H
#define PSNIP_CLOCK__COMPILER_ATTRIBUTES
#define PSNIP_CLOCK__FUNCTION   PSNIP_CLOCK__COMPILER_ATTRIBUTES static
#define PSNIP_CLOCK_METHOD_CLOCK_GETTIME   1
#define PSNIP_CLOCK_METHOD_TIME   2
#define PSNIP_CLOCK_METHOD_GETTIMEOFDAY   3
#define PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER   4
#define PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME   5
#define PSNIP_CLOCK_METHOD_CLOCK   6
#define PSNIP_CLOCK_METHOD_GETPROCESSTIMES   7
#define PSNIP_CLOCK_METHOD_GETRUSAGE   8
#define PSNIP_CLOCK_METHOD_GETSYSTEMTIMEPRECISEASFILETIME   9
#define PSNIP_CLOCK_METHOD_GETTICKCOUNT64   10
#define PSNIP_CLOCK_UNREACHABLE()
#define PSNIP_CLOCK_WALL_METHOD   PSNIP_CLOCK_METHOD_TIME
#define PSNIP_CLOCK_CPU_METHOD   PSNIP_CLOCK_METHOD_CLOCK
#define PSNIP_CLOCK_NSEC_PER_SEC   ((psnip_uint32_t) (1000000000ULL))
#define ATOMIC_UINT32_T   volatile uint32_t
#define ATOMIC_UINT32_INIT(x)
#define munit_atomic_store(dest, value)
#define munit_atomic_load(src)
#define MUNIT_PRNG_MULTIPLIER   (747796405U)
#define MUNIT_PRNG_INCREMENT   (1729U)
#define MUNIT_RESULT_STRING_OK   "OK "
#define MUNIT_RESULT_STRING_SKIP   "SKIP "
#define MUNIT_RESULT_STRING_FAIL   "FAIL "
#define MUNIT_RESULT_STRING_ERROR   "ERROR"
#define MUNIT_RESULT_STRING_TODO   "TODO "

Enumerations

enum  PsnipClockType { PSNIP_CLOCK_TYPE_WALL = 1 , PSNIP_CLOCK_TYPE_CPU = 2 , PSNIP_CLOCK_TYPE_MONOTONIC = 3 }

Functions

void munit_logf_ex (MunitLogLevel level, const char *filename, int line, const char *format,...)
void munit_errorf_ex (const char *filename, int line, const char *format,...)
void * munit_malloc_ex (const char *filename, int line, size_t size)
PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_wall_get_precision (void)
PSNIP_CLOCK__FUNCTION int psnip_clock_wall_get_time (struct PsnipClockTimespec *res)
PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_cpu_get_precision (void)
PSNIP_CLOCK__FUNCTION int psnip_clock_cpu_get_time (struct PsnipClockTimespec *res)
PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_monotonic_get_precision (void)
PSNIP_CLOCK__FUNCTION int psnip_clock_monotonic_get_time (struct PsnipClockTimespec *res)
PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_get_precision (enum PsnipClockType clock_type)
PSNIP_CLOCK__FUNCTION int psnip_clock_get_time (enum PsnipClockType clock_type, struct PsnipClockTimespec *res)
void munit_rand_seed (munit_uint32_t seed)
munit_uint32_t munit_rand_uint32 (void)
void munit_rand_memory (size_t size, munit_uint8_t data[MUNIT_ARRAY_PARAM(size)])
int munit_rand_int_range (int min, int max)
double munit_rand_double (void)
const char * munit_parameters_get (const MunitParameter params[], const char *key)
int munit_suite_main_custom (const MunitSuite *suite, void *user_data, int argc, char *const argv[MUNIT_ARRAY_PARAM(argc+1)], const MunitArgument arguments[])
int munit_suite_main (const MunitSuite *suite, void *user_data, int argc, char *const argv[MUNIT_ARRAY_PARAM(argc+1)])

Macro Definition Documentation

◆ _POSIX_C_SOURCE

#define _POSIX_C_SOURCE   200809L

Definition at line 61 of file munit.c.

◆ ATOMIC_UINT32_INIT

#define ATOMIC_UINT32_INIT ( x)
Value:
(x)

Definition at line 826 of file munit.c.

◆ ATOMIC_UINT32_T

#define ATOMIC_UINT32_T   volatile uint32_t

Definition at line 825 of file munit.c.

◆ munit_atomic_load

#define munit_atomic_load ( src)
Value:
(*(src))

Definition at line 885 of file munit.c.

Referenced by munit_rand_double(), munit_rand_memory(), and munit_rand_uint32().

◆ munit_atomic_store

#define munit_atomic_store ( dest,
value )
Value:
do { *(dest) = (value); } while (0)

Definition at line 884 of file munit.c.

Referenced by munit_rand_seed().

◆ MUNIT_ENABLE_TIMING

#define MUNIT_ENABLE_TIMING

Definition at line 52 of file munit.c.

◆ MUNIT_NL_LANGINFO

#define MUNIT_NL_LANGINFO

Definition at line 102 of file munit.c.

◆ MUNIT_OUTPUT_FILE

#define MUNIT_OUTPUT_FILE   stdout

Definition at line 32 of file munit.c.

Referenced by munit_suite_main_custom().

◆ MUNIT_PRNG_INCREMENT

#define MUNIT_PRNG_INCREMENT   (1729U)

Definition at line 898 of file munit.c.

Referenced by munit_rand_seed().

◆ MUNIT_PRNG_MULTIPLIER

#define MUNIT_PRNG_MULTIPLIER   (747796405U)

Definition at line 897 of file munit.c.

◆ MUNIT_RESULT_STRING_ERROR

#define MUNIT_RESULT_STRING_ERROR   "ERROR"

Definition at line 1261 of file munit.c.

◆ MUNIT_RESULT_STRING_FAIL

#define MUNIT_RESULT_STRING_FAIL   "FAIL "

Definition at line 1260 of file munit.c.

◆ MUNIT_RESULT_STRING_OK

#define MUNIT_RESULT_STRING_OK   "OK "

Definition at line 1258 of file munit.c.

◆ MUNIT_RESULT_STRING_SKIP

#define MUNIT_RESULT_STRING_SKIP   "SKIP "

Definition at line 1259 of file munit.c.

◆ MUNIT_RESULT_STRING_TODO

#define MUNIT_RESULT_STRING_TODO   "TODO "

Definition at line 1262 of file munit.c.

◆ MUNIT_STRERROR_LEN

#define MUNIT_STRERROR_LEN   80

Definition at line 257 of file munit.c.

◆ MUNIT_STRINGIFY

#define MUNIT_STRINGIFY ( x)
Value:
#x

Definition at line 127 of file munit.c.

◆ MUNIT_TEST_NAME_LEN

#define MUNIT_TEST_NAME_LEN   60

Definition at line 46 of file munit.c.

◆ MUNIT_TEST_TIME_FORMAT

#define MUNIT_TEST_TIME_FORMAT   "0.8f"

Definition at line 40 of file munit.c.

◆ MUNIT_XSTRINGIFY

#define MUNIT_XSTRINGIFY ( x)
Value:
#define MUNIT_STRINGIFY(x)
Definition munit.c:127

Definition at line 128 of file munit.c.

◆ PSNIP_CLOCK__COMPILER_ATTRIBUTES

#define PSNIP_CLOCK__COMPILER_ATTRIBUTES

Definition at line 328 of file munit.c.

◆ PSNIP_CLOCK__FUNCTION

#define PSNIP_CLOCK__FUNCTION   PSNIP_CLOCK__COMPILER_ATTRIBUTES static

Definition at line 331 of file munit.c.

◆ PSNIP_CLOCK_CPU_METHOD

#define PSNIP_CLOCK_CPU_METHOD   PSNIP_CLOCK_METHOD_CLOCK

Definition at line 466 of file munit.c.

◆ PSNIP_CLOCK_H

#define PSNIP_CLOCK_H

Definition at line 318 of file munit.c.

◆ PSNIP_CLOCK_METHOD_CLOCK

#define PSNIP_CLOCK_METHOD_CLOCK   6

Definition at line 362 of file munit.c.

◆ PSNIP_CLOCK_METHOD_CLOCK_GETTIME

#define PSNIP_CLOCK_METHOD_CLOCK_GETTIME   1

Definition at line 357 of file munit.c.

◆ PSNIP_CLOCK_METHOD_GETPROCESSTIMES

#define PSNIP_CLOCK_METHOD_GETPROCESSTIMES   7

Definition at line 363 of file munit.c.

◆ PSNIP_CLOCK_METHOD_GETRUSAGE

#define PSNIP_CLOCK_METHOD_GETRUSAGE   8

Definition at line 364 of file munit.c.

◆ PSNIP_CLOCK_METHOD_GETSYSTEMTIMEPRECISEASFILETIME

#define PSNIP_CLOCK_METHOD_GETSYSTEMTIMEPRECISEASFILETIME   9

Definition at line 365 of file munit.c.

◆ PSNIP_CLOCK_METHOD_GETTICKCOUNT64

#define PSNIP_CLOCK_METHOD_GETTICKCOUNT64   10

Definition at line 366 of file munit.c.

◆ PSNIP_CLOCK_METHOD_GETTIMEOFDAY

#define PSNIP_CLOCK_METHOD_GETTIMEOFDAY   3

Definition at line 359 of file munit.c.

◆ PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME

#define PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME   5

Definition at line 361 of file munit.c.

◆ PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER

#define PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER   4

Definition at line 360 of file munit.c.

◆ PSNIP_CLOCK_METHOD_TIME

#define PSNIP_CLOCK_METHOD_TIME   2

Definition at line 358 of file munit.c.

◆ PSNIP_CLOCK_NSEC_PER_SEC

#define PSNIP_CLOCK_NSEC_PER_SEC   ((psnip_uint32_t) (1000000000ULL))

◆ PSNIP_CLOCK_UNREACHABLE

#define PSNIP_CLOCK_UNREACHABLE ( )
Value:
assert(var1 eq var2)

Definition at line 373 of file munit.c.

Referenced by psnip_clock_get_precision().

◆ PSNIP_CLOCK_WALL_METHOD

#define PSNIP_CLOCK_WALL_METHOD   PSNIP_CLOCK_METHOD_TIME

Definition at line 462 of file munit.c.

◆ psnip_uint32_t

#define psnip_uint32_t   munit_uint32_t

Definition at line 300 of file munit.c.

Referenced by psnip_clock_monotonic_get_precision().

◆ psnip_uint64_t

#define psnip_uint64_t   munit_uint64_t

Definition at line 299 of file munit.c.

Referenced by psnip_clock_monotonic_get_time().

Enumeration Type Documentation

◆ PsnipClockType

Enumerator
PSNIP_CLOCK_TYPE_WALL 
PSNIP_CLOCK_TYPE_CPU 
PSNIP_CLOCK_TYPE_MONOTONIC 

Definition at line 334 of file munit.c.

334 {
335 /* This clock provides the current time, in units since 1970-01-01
336 * 00:00:00 UTC not including leap seconds. In other words, UNIX
337 * time. Keep in mind that this clock doesn't account for leap
338 * seconds, and can go backwards (think NTP adjustments). */
340 /* The CPU time is a clock which increases only when the current
341 * process is active (i.e., it doesn't increment while blocking on
342 * I/O). */
344 /* Monotonic time is always running (unlike CPU time), but it only
345 ever moves forward unless you reboot the system. Things like NTP
346 adjustments have no effect on this clock. */
348};
@ PSNIP_CLOCK_TYPE_WALL
Definition munit.c:339
@ PSNIP_CLOCK_TYPE_CPU
Definition munit.c:343
@ PSNIP_CLOCK_TYPE_MONOTONIC
Definition munit.c:347

Function Documentation

◆ munit_errorf_ex()

void munit_errorf_ex ( const char * filename,
int line,
const char * format,
... )

Definition at line 238 of file munit.c.

238 {
239 va_list ap;
240
241 va_start(ap, format);
242 munit_logf_exv(MUNIT_LOG_ERROR, stderr, filename, line, format, ap);
243 va_end(ap);
244
245#if defined(MUNIT_THREAD_LOCAL)
246 if (munit_error_jmp_buf_valid)
247 longjmp(munit_error_jmp_buf, 1);
248#endif
249 abort();
250}
@ MUNIT_LOG_ERROR
Definition munit.h:181

References MUNIT_LOG_ERROR.

◆ munit_logf_ex()

void munit_logf_ex ( MunitLogLevel level,
const char * filename,
int line,
const char * format,
... )

Definition at line 221 of file munit.c.

221 {
222 va_list ap;
223
224 va_start(ap, format);
225 munit_logf_exv(level, stderr, filename, line, format, ap);
226 va_end(ap);
227
228 if (level >= munit_log_level_fatal) {
229#if defined(MUNIT_THREAD_LOCAL)
230 if (munit_error_jmp_buf_valid)
231 longjmp(munit_error_jmp_buf, 1);
232#endif
233 abort();
234 }
235}

Referenced by munit_malloc_ex().

Here is the caller graph for this function:

◆ munit_malloc_ex()

void * munit_malloc_ex ( const char * filename,
int line,
size_t size )

Definition at line 281 of file munit.c.

281 {
282 void *ptr;
283
284 if (size == 0)
285 return NULL;
286
287 ptr = calloc(1, size);
288 if (MUNIT_UNLIKELY(ptr == NULL)) {
289 munit_logf_ex(MUNIT_LOG_ERROR, filename, line, "Failed to allocate %" MUNIT_SIZE_MODIFIER "u bytes.", size);
290 }
291
292 return ptr;
293}
void munit_logf_ex(MunitLogLevel level, const char *filename, int line, const char *format,...)
Definition munit.c:221
#define MUNIT_UNLIKELY(expr)
Definition munit.h:135
#define MUNIT_SIZE_MODIFIER
Definition munit.h:146

References MUNIT_LOG_ERROR, munit_logf_ex(), MUNIT_SIZE_MODIFIER, and MUNIT_UNLIKELY.

Here is the call graph for this function:

◆ munit_parameters_get()

const char * munit_parameters_get ( const MunitParameter params[],
const char * key )

Definition at line 1075 of file munit.c.

1075 {
1076 const MunitParameter *param;
1077
1078 for (param = params; param != NULL && param->name != NULL; param++)
1079 if (strcmp(param->name, key) == 0)
1080 return param->value;
1081 return NULL;
1082}
char * value
Definition munit.h:435
char * name
Definition munit.h:434

References MunitParameter::name, and MunitParameter::value.

◆ munit_rand_double()

double munit_rand_double ( void )

Definition at line 1028 of file munit.c.

1028 {
1029 munit_uint32_t old, state;
1030 double retval = 0.0;
1031
1032 do {
1033 state = old = munit_atomic_load(&munit_rand_state);
1034
1035 /* See http://mumble.net/~campbell/tmp/random_real.c for how to do
1036 * this right. Patches welcome if you feel that this is too
1037 * biased. */
1038 retval = munit_rand_state_uint32(&state) / ((~((munit_uint32_t) 0U)) + 1.0);
1039 } while (!munit_atomic_cas(&munit_rand_state, &old, state));
1040
1041 return retval;
1042}
#define munit_atomic_load(src)
Definition munit.c:885
#define munit_uint32_t
Definition munit.h:55

References munit_atomic_load, and munit_uint32_t.

◆ munit_rand_int_range()

int munit_rand_int_range ( int min,
int max )

Definition at line 1015 of file munit.c.

1015 {
1016 munit_uint64_t range = (munit_uint64_t) max - (munit_uint64_t) min;
1017
1018 if (min > max)
1019 return munit_rand_int_range(max, min);
1020
1021 if (range > (~((munit_uint32_t) 0U)))
1022 range = (~((munit_uint32_t) 0U));
1023
1024 return min + munit_rand_at_most(0, (munit_uint32_t) range);
1025}
int munit_rand_int_range(int min, int max)
Definition munit.c:1015
#define munit_uint64_t
Definition munit.h:57

References munit_rand_int_range(), munit_uint32_t, and munit_uint64_t.

Referenced by munit_rand_int_range().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ munit_rand_memory()

void munit_rand_memory ( size_t size,
munit_uint8_t data[MUNIT_ARRAY_PARAM(size)] )

Definition at line 971 of file munit.c.

971 {
972 munit_uint32_t old, state;
973
974 do {
975 state = old = munit_atomic_load(&munit_rand_state);
976 munit_rand_state_memory(&state, size, data);
977 } while (!munit_atomic_cas(&munit_rand_state, &old, state));
978}

References munit_atomic_load, munit_uint32_t, and munit_uint8_t.

◆ munit_rand_seed()

void munit_rand_seed ( munit_uint32_t seed)

Definition at line 913 of file munit.c.

913 {
914 munit_uint32_t state = munit_rand_next_state(seed + MUNIT_PRNG_INCREMENT);
915 munit_atomic_store(&munit_rand_state, state);
916}
#define MUNIT_PRNG_INCREMENT
Definition munit.c:898
#define munit_atomic_store(dest, value)
Definition munit.c:884

References munit_atomic_store, MUNIT_PRNG_INCREMENT, and munit_uint32_t.

◆ munit_rand_uint32()

munit_uint32_t munit_rand_uint32 ( void )

Definition at line 942 of file munit.c.

942 {
943 munit_uint32_t old, state;
944
945 do {
946 old = munit_atomic_load(&munit_rand_state);
947 state = munit_rand_next_state(old);
948 } while (!munit_atomic_cas(&munit_rand_state, &old, state));
949
950 return munit_rand_from_state(old);
951}

References munit_atomic_load, and munit_uint32_t.

◆ munit_suite_main()

int munit_suite_main ( const MunitSuite * suite,
void * user_data,
int argc,
char *const argv[MUNIT_ARRAY_PARAM(argc+1)] )

Definition at line 2094 of file munit.c.

2095 {
2096 return munit_suite_main_custom(suite, user_data, argc, argv, NULL);
2097}
int munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc, char *const argv[MUNIT_ARRAY_PARAM(argc+1)], const MunitArgument arguments[])
Definition munit.c:1867

References munit_suite_main_custom().

Referenced by main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ munit_suite_main_custom()

int munit_suite_main_custom ( const MunitSuite * suite,
void * user_data,
int argc,
char *const argv[MUNIT_ARRAY_PARAM(argc+1)],
const MunitArgument arguments[] )

Definition at line 1867 of file munit.c.

1869 {
1870 int result = EXIT_FAILURE;
1871 MunitTestRunner runner;
1872 size_t parameters_size = 0;
1873 size_t tests_size = 0;
1874 int arg;
1875
1876 char *envptr;
1877 unsigned long ts;
1878 char *endptr;
1879 unsigned long long iterations;
1880 MunitLogLevel level;
1881 const MunitArgument *argument;
1882 const char **runner_tests;
1883 unsigned int tests_run;
1884 unsigned int tests_total;
1885
1886 runner.prefix = NULL;
1887 runner.suite = NULL;
1888 runner.current_suite = NULL;
1889 runner.tests = NULL;
1890 runner.seed = 0;
1891 runner.iterations = 0;
1892 runner.parameters = NULL;
1893 runner.single_parameter_mode = 0;
1894 runner.user_data = NULL;
1895
1896 runner.report.successful = 0;
1897 runner.report.skipped = 0;
1898 runner.report.failed = 0;
1899 runner.report.errored = 0;
1900#if defined(MUNIT_ENABLE_TIMING)
1901 runner.report.cpu_clock = 0;
1902 runner.report.wall_clock = 0;
1903#endif
1904
1905 runner.colorize = 0;
1906#if !defined(_WIN32)
1907 runner.fork = 1;
1908#else
1909 runner.fork = 0;
1910#endif
1911 runner.show_stderr = 0;
1912 runner.fatal_failures = 0;
1913 runner.suite = suite;
1914 runner.user_data = user_data;
1915 runner.seed = munit_rand_generate_seed();
1916 runner.colorize = munit_stream_supports_ansi(MUNIT_OUTPUT_FILE);
1917
1918 for (arg = 1; arg < argc; arg++) {
1919 if (strncmp("--", argv[arg], 2) == 0) {
1920 if (strcmp("seed", argv[arg] + 2) == 0) {
1921 if (arg + 1 >= argc) {
1922 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "%s requires an argument", argv[arg]);
1923 goto cleanup;
1924 }
1925
1926 envptr = argv[arg + 1];
1927 ts = strtoul(argv[arg + 1], &envptr, 0);
1928 if (*envptr != '\0' || ts > (~((munit_uint32_t) 0U))) {
1929 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "invalid value ('%s') passed to %s", argv[arg + 1],
1930 argv[arg]);
1931 goto cleanup;
1932 }
1933 runner.seed = (munit_uint32_t) ts;
1934
1935 arg++;
1936 } else if (strcmp("iterations", argv[arg] + 2) == 0) {
1937 if (arg + 1 >= argc) {
1938 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "%s requires an argument", argv[arg]);
1939 goto cleanup;
1940 }
1941
1942 endptr = argv[arg + 1];
1943 iterations = strtoul(argv[arg + 1], &endptr, 0);
1944 if (*endptr != '\0' || iterations > UINT_MAX) {
1945 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "invalid value ('%s') passed to %s", argv[arg + 1],
1946 argv[arg]);
1947 goto cleanup;
1948 }
1949
1950 runner.iterations = (unsigned int) iterations;
1951
1952 arg++;
1953 } else if (strcmp("param", argv[arg] + 2) == 0) {
1954 if (arg + 2 >= argc) {
1955 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "%s requires two arguments", argv[arg]);
1956 goto cleanup;
1957 }
1958
1959 runner.parameters = realloc(runner.parameters, sizeof(MunitParameter) * (parameters_size + 2));
1960 if (runner.parameters == NULL) {
1961 munit_log_internal(MUNIT_LOG_ERROR, stderr, "failed to allocate memory");
1962 goto cleanup;
1963 }
1964 runner.parameters[parameters_size].name = (char *) argv[arg + 1];
1965 runner.parameters[parameters_size].value = (char *) argv[arg + 2];
1966 parameters_size++;
1967 runner.parameters[parameters_size].name = NULL;
1968 runner.parameters[parameters_size].value = NULL;
1969 arg += 2;
1970 } else if (strcmp("color", argv[arg] + 2) == 0) {
1971 if (arg + 1 >= argc) {
1972 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "%s requires an argument", argv[arg]);
1973 goto cleanup;
1974 }
1975
1976 if (strcmp(argv[arg + 1], "always") == 0)
1977 runner.colorize = 1;
1978 else if (strcmp(argv[arg + 1], "never") == 0)
1979 runner.colorize = 0;
1980 else if (strcmp(argv[arg + 1], "auto") == 0)
1981 runner.colorize = munit_stream_supports_ansi(MUNIT_OUTPUT_FILE);
1982 else {
1983 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "invalid value ('%s') passed to %s", argv[arg + 1],
1984 argv[arg]);
1985 goto cleanup;
1986 }
1987
1988 arg++;
1989 } else if (strcmp("help", argv[arg] + 2) == 0) {
1990 munit_print_help(argc, argv, user_data, arguments);
1991 result = EXIT_SUCCESS;
1992 goto cleanup;
1993 } else if (strcmp("single", argv[arg] + 2) == 0) {
1994 runner.single_parameter_mode = 1;
1995 } else if (strcmp("show-stderr", argv[arg] + 2) == 0) {
1996 runner.show_stderr = 1;
1997#if !defined(_WIN32)
1998 } else if (strcmp("no-fork", argv[arg] + 2) == 0) {
1999 runner.fork = 0;
2000#endif
2001 } else if (strcmp("fatal-failures", argv[arg] + 2) == 0) {
2002 runner.fatal_failures = 1;
2003 } else if (strcmp("log-visible", argv[arg] + 2) == 0 ||
2004 strcmp("log-fatal", argv[arg] + 2) == 0) {
2005 if (arg + 1 >= argc) {
2006 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "%s requires an argument", argv[arg]);
2007 goto cleanup;
2008 }
2009
2010 if (strcmp(argv[arg + 1], "debug") == 0)
2011 level = MUNIT_LOG_DEBUG;
2012 else if (strcmp(argv[arg + 1], "info") == 0)
2013 level = MUNIT_LOG_INFO;
2014 else if (strcmp(argv[arg + 1], "warning") == 0)
2015 level = MUNIT_LOG_WARNING;
2016 else if (strcmp(argv[arg + 1], "error") == 0)
2017 level = MUNIT_LOG_ERROR;
2018 else {
2019 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "invalid value ('%s') passed to %s", argv[arg + 1],
2020 argv[arg]);
2021 goto cleanup;
2022 }
2023
2024 if (strcmp("log-visible", argv[arg] + 2) == 0)
2025 munit_log_level_visible = level;
2026 else
2027 munit_log_level_fatal = level;
2028
2029 arg++;
2030 } else if (strcmp("list", argv[arg] + 2) == 0) {
2031 munit_suite_list_tests(suite, 0, NULL);
2032 result = EXIT_SUCCESS;
2033 goto cleanup;
2034 } else if (strcmp("list-params", argv[arg] + 2) == 0) {
2035 munit_suite_list_tests(suite, 1, NULL);
2036 result = EXIT_SUCCESS;
2037 goto cleanup;
2038 } else {
2039 argument = munit_arguments_find(arguments, argv[arg] + 2);
2040 if (argument == NULL) {
2041 munit_logf_internal(MUNIT_LOG_ERROR, stderr, "unknown argument ('%s')", argv[arg]);
2042 goto cleanup;
2043 }
2044
2045 if (!argument->parse_argument(suite, user_data, &arg, argc, argv))
2046 goto cleanup;
2047 }
2048 } else {
2049 runner_tests = realloc((void *) runner.tests, sizeof(char *) * (tests_size + 2));
2050 if (runner_tests == NULL) {
2051 munit_log_internal(MUNIT_LOG_ERROR, stderr, "failed to allocate memory");
2052 goto cleanup;
2053 }
2054 runner.tests = runner_tests;
2055 runner.tests[tests_size++] = argv[arg];
2056 runner.tests[tests_size] = NULL;
2057 }
2058 }
2059
2060 fflush(stderr);
2061 fprintf(MUNIT_OUTPUT_FILE, "Running test suite with seed 0x%08" PRIx32 "...\n", runner.seed);
2062
2063 munit_test_runner_run(&runner);
2064
2065 tests_run = runner.report.successful + runner.report.failed + runner.report.errored;
2066 tests_total = tests_run + runner.report.skipped;
2067 if (tests_run == 0) {
2068 fprintf(stderr, "No tests run, %d (100%%) skipped.\n", runner.report.skipped);
2069 } else {
2070 fprintf(MUNIT_OUTPUT_FILE, "%d of %d (%0.0f%%) tests successful, %d (%0.0f%%) test skipped.\n",
2071 runner.report.successful, tests_run,
2072 (((double) runner.report.successful) / ((double) tests_run)) * 100.0,
2073 runner.report.skipped,
2074 (((double) runner.report.skipped) / ((double) tests_total)) * 100.0);
2075 }
2076
2077
2078#if defined(MUNIT_FAIL_NO_TEST_RUN)
2079 if (runner.report.failed == 0 && runner.report.errored == 0 && tests_run > 0) {
2080#else
2081 if (runner.report.failed == 0 && runner.report_simple.errored == 0) {
2082#endif
2083 result = EXIT_SUCCESS;
2084 }
2085
2086 cleanup:
2087 free(runner.parameters);
2088 free((void *) runner.tests);
2089
2090 return result;
2091}
#define MUNIT_OUTPUT_FILE
Definition munit.c:32
struct MunitArgument_ MunitArgument
Definition munit.h:480
MunitLogLevel
Definition munit.h:177
@ MUNIT_LOG_WARNING
Definition munit.h:180
@ MUNIT_LOG_DEBUG
Definition munit.h:178
@ MUNIT_LOG_INFO
Definition munit.h:179
munit_bool(* parse_argument)(const MunitSuite *suite, void *user_data, int *arg, int argc, char *const argv[MUNIT_ARRAY_PARAM(argc+1)])
Definition munit.h:485
munit_uint64_t wall_clock
Definition munit.c:1053
unsigned int skipped
Definition munit.c:1048
unsigned int errored
Definition munit.c:1050
unsigned int failed
Definition munit.c:1049
munit_uint64_t cpu_clock
Definition munit.c:1052
unsigned int successful
Definition munit.c:1047
munit_bool show_stderr
Definition munit.c:1070
const char ** tests
Definition munit.c:1061
void * user_data
Definition munit.c:1066
const MunitSuite * current_suite
Definition munit.c:1060
unsigned int iterations
Definition munit.c:1063
munit_bool fork
Definition munit.c:1069
const MunitSuite * suite
Definition munit.c:1059
const char * prefix
Definition munit.c:1058
MunitParameter * parameters
Definition munit.c:1064
munit_uint32_t seed
Definition munit.c:1062
munit_bool single_parameter_mode
Definition munit.c:1065
munit_bool fatal_failures
Definition munit.c:1071
munit_bool colorize
Definition munit.c:1068
MunitReport report
Definition munit.c:1067

References MunitTestRunner::colorize, MunitReport::cpu_clock, MunitTestRunner::current_suite, MunitReport::errored, MunitReport::failed, MunitTestRunner::fatal_failures, MunitTestRunner::fork, MunitTestRunner::iterations, MUNIT_LOG_DEBUG, MUNIT_LOG_ERROR, MUNIT_LOG_INFO, MUNIT_LOG_WARNING, MUNIT_OUTPUT_FILE, munit_uint32_t, MunitParameter::name, MunitTestRunner::parameters, MunitArgument_::parse_argument, MunitTestRunner::prefix, MunitTestRunner::report, MunitTestRunner::seed, MunitTestRunner::show_stderr, MunitTestRunner::single_parameter_mode, MunitReport::skipped, MunitReport::successful, MunitTestRunner::suite, MunitTestRunner::tests, MunitTestRunner::user_data, MunitParameter::value, and MunitReport::wall_clock.

Referenced by munit_suite_main().

Here is the caller graph for this function:

◆ psnip_clock_cpu_get_precision()

PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_cpu_get_precision ( void )

Definition at line 603 of file munit.c.

603 {
604#if !defined(PSNIP_CLOCK_CPU_METHOD)
605 return 0;
606#elif defined(PSNIP_CLOCK_CPU_METHOD) && PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME
607 return psnip_clock__clock_getres(PSNIP_CLOCK_CLOCK_GETTIME_CPU);
608#elif defined(PSNIP_CLOCK_CPU_METHOD) && PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK
609 return CLOCKS_PER_SEC;
610#elif defined(PSNIP_CLOCK_CPU_METHOD) && PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES
611 return PSNIP_CLOCK_NSEC_PER_SEC / 100;
612#else
613 return 0;
614#endif
615}
#define PSNIP_CLOCK_NSEC_PER_SEC
Definition munit.c:527

References PSNIP_CLOCK_NSEC_PER_SEC.

Referenced by psnip_clock_get_precision().

Here is the caller graph for this function:

◆ psnip_clock_cpu_get_time()

PSNIP_CLOCK__FUNCTION int psnip_clock_cpu_get_time ( struct PsnipClockTimespec * res)

Definition at line 618 of file munit.c.

618 {
619#if !defined(PSNIP_CLOCK_CPU_METHOD)
620 (void) res;
621 return -2;
622#elif defined(PSNIP_CLOCK_CPU_METHOD) && PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME
623 return psnip_clock__clock_gettime(PSNIP_CLOCK_CLOCK_GETTIME_CPU, res);
624#elif defined(PSNIP_CLOCK_CPU_METHOD) && PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK
625 clock_t t = clock();
626 if (t == ((clock_t) -1))
627 return -5;
628 res->seconds = t / CLOCKS_PER_SEC;
629 res->nanoseconds = (t % CLOCKS_PER_SEC) * (PSNIP_CLOCK_NSEC_PER_SEC / CLOCKS_PER_SEC);
630#elif defined(PSNIP_CLOCK_CPU_METHOD) && PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES
631 FILETIME CreationTime, ExitTime, KernelTime, UserTime;
632 LARGE_INTEGER date, adjust;
633
634 if (!GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, &KernelTime, &UserTime))
635 return -7;
636
637 /* http://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/ */
638 date.HighPart = UserTime.dwHighDateTime;
639 date.LowPart = UserTime.dwLowDateTime;
640 adjust.QuadPart = 11644473600000 * 10000;
641 date.QuadPart -= adjust.QuadPart;
642
643 res->seconds = date.QuadPart / 10000000;
644 res->nanoseconds = (date.QuadPart % 10000000) * (PSNIP_CLOCK_NSEC_PER_SEC / 100);
645#elif PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE
646 struct rusage usage;
647 if (getrusage(RUSAGE_SELF, &usage) != 0)
648 return -8;
649
650 res->seconds = usage.ru_utime.tv_sec;
651 res->nanoseconds = tv.tv_usec * 1000;
652#else
653 (void) res;
654 return -2;
655#endif
656
657 return 0;
658}
psnip_uint64_t seconds
Definition munit.c:351
psnip_uint64_t nanoseconds
Definition munit.c:352

References PsnipClockTimespec::nanoseconds, PSNIP_CLOCK_NSEC_PER_SEC, and PsnipClockTimespec::seconds.

Referenced by psnip_clock_get_time().

Here is the caller graph for this function:

◆ psnip_clock_get_precision()

PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_get_precision ( enum PsnipClockType clock_type)

Definition at line 733 of file munit.c.

733 {
734 switch (clock_type) {
741 }
742
744 return 0;
745}
PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_wall_get_precision(void)
Definition munit.c:562
PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_cpu_get_precision(void)
Definition munit.c:603
PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_monotonic_get_precision(void)
Definition munit.c:661
#define PSNIP_CLOCK_UNREACHABLE()
Definition munit.c:373

References psnip_clock_cpu_get_precision(), psnip_clock_monotonic_get_precision(), PSNIP_CLOCK_TYPE_CPU, PSNIP_CLOCK_TYPE_MONOTONIC, PSNIP_CLOCK_TYPE_WALL, PSNIP_CLOCK_UNREACHABLE, and psnip_clock_wall_get_precision().

Here is the call graph for this function:

◆ psnip_clock_get_time()

PSNIP_CLOCK__FUNCTION int psnip_clock_get_time ( enum PsnipClockType clock_type,
struct PsnipClockTimespec * res )

Definition at line 750 of file munit.c.

750 {
751 assert(res != NULL);
752
753 switch (clock_type) {
757 return psnip_clock_cpu_get_time(res);
759 return psnip_clock_wall_get_time(res);
760 }
761
762 return -1;
763}
PSNIP_CLOCK__FUNCTION int psnip_clock_wall_get_time(struct PsnipClockTimespec *res)
Definition munit.c:577
PSNIP_CLOCK__FUNCTION int psnip_clock_cpu_get_time(struct PsnipClockTimespec *res)
Definition munit.c:618
PSNIP_CLOCK__FUNCTION int psnip_clock_monotonic_get_time(struct PsnipClockTimespec *res)
Definition munit.c:683

References assert(), psnip_clock_cpu_get_time(), psnip_clock_monotonic_get_time(), PSNIP_CLOCK_TYPE_CPU, PSNIP_CLOCK_TYPE_MONOTONIC, PSNIP_CLOCK_TYPE_WALL, and psnip_clock_wall_get_time().

Here is the call graph for this function:

◆ psnip_clock_monotonic_get_precision()

PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_monotonic_get_precision ( void )

Definition at line 661 of file munit.c.

661 {
662#if !defined(PSNIP_CLOCK_MONOTONIC_METHOD)
663 return 0;
664#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME
665 return psnip_clock__clock_getres(PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC);
666#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME
667 static mach_timebase_info_data_t tbi = { 0, };
668 if (tbi.denom == 0)
669 mach_timebase_info(&tbi);
670 return (psnip_uint32_t) (tbi.numer / tbi.denom);
671#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64
672 return 1000;
673#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER
674 LARGE_INTEGER Frequency;
675 QueryPerformanceFrequency(&Frequency);
676 return (psnip_uint32_t) ((Frequency.QuadPart > PSNIP_CLOCK_NSEC_PER_SEC) ? PSNIP_CLOCK_NSEC_PER_SEC : Frequency.QuadPart);
677#else
678 return 0;
679#endif
680}
#define psnip_uint32_t
Definition munit.c:300

References PSNIP_CLOCK_NSEC_PER_SEC, and psnip_uint32_t.

Referenced by psnip_clock_get_precision().

Here is the caller graph for this function:

◆ psnip_clock_monotonic_get_time()

PSNIP_CLOCK__FUNCTION int psnip_clock_monotonic_get_time ( struct PsnipClockTimespec * res)

Definition at line 683 of file munit.c.

683 {
684#if !defined(PSNIP_CLOCK_MONOTONIC_METHOD)
685 (void) res;
686 return -2;
687#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME
688 return psnip_clock__clock_gettime(PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC, res);
689#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME
690 psnip_uint64_t nsec = mach_absolute_time();
691 static mach_timebase_info_data_t tbi = { 0, };
692 if (tbi.denom == 0)
693 mach_timebase_info(&tbi);
694 nsec *= ((psnip_uint64_t) tbi.numer) / ((psnip_uint64_t) tbi.denom);
695 res->seconds = nsec / PSNIP_CLOCK_NSEC_PER_SEC;
697#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER
698 LARGE_INTEGER t, f;
699 if (QueryPerformanceCounter(&t) == 0)
700 return -12;
701
702 QueryPerformanceFrequency(&f);
703 res->seconds = t.QuadPart / f.QuadPart;
704 res->nanoseconds = t.QuadPart % f.QuadPart;
705 if (f.QuadPart > PSNIP_CLOCK_NSEC_PER_SEC)
706 res->nanoseconds /= f.QuadPart / PSNIP_CLOCK_NSEC_PER_SEC;
707 else
708 res->nanoseconds *= PSNIP_CLOCK_NSEC_PER_SEC / f.QuadPart;
709#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64
710 const ULONGLONG msec = GetTickCount64();
711 res->seconds = msec / 1000;
712 res->nanoseconds = sec % 1000;
713#else
714 return -2;
715#endif
716
717 return 0;
718}
#define psnip_uint64_t
Definition munit.c:299

References PsnipClockTimespec::nanoseconds, PSNIP_CLOCK_NSEC_PER_SEC, psnip_uint64_t, and PsnipClockTimespec::seconds.

Referenced by psnip_clock_get_time().

Here is the caller graph for this function:

◆ psnip_clock_wall_get_precision()

PSNIP_CLOCK__FUNCTION psnip_uint32_t psnip_clock_wall_get_precision ( void )

Definition at line 562 of file munit.c.

562 {
563#if !defined(PSNIP_CLOCK_WALL_METHOD)
564 return 0;
565#elif defined(PSNIP_CLOCK_WALL_METHOD) && PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME
566 return psnip_clock__clock_getres(PSNIP_CLOCK_CLOCK_GETTIME_WALL);
567#elif defined(PSNIP_CLOCK_WALL_METHOD) && PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY
568 return 1000000;
569#elif defined(PSNIP_CLOCK_WALL_METHOD) && PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_TIME
570 return 1;
571#else
572 return 0;
573#endif
574}

Referenced by psnip_clock_get_precision().

Here is the caller graph for this function:

◆ psnip_clock_wall_get_time()

PSNIP_CLOCK__FUNCTION int psnip_clock_wall_get_time ( struct PsnipClockTimespec * res)

Definition at line 577 of file munit.c.

577 {
578 (void) res;
579
580#if !defined(PSNIP_CLOCK_WALL_METHOD)
581 return -2;
582#elif defined(PSNIP_CLOCK_WALL_METHOD) && PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME
583 return psnip_clock__clock_gettime(PSNIP_CLOCK_CLOCK_GETTIME_WALL, res);
584#elif defined(PSNIP_CLOCK_WALL_METHOD) && PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_TIME
585 res->seconds = time(NULL);
586 res->nanoseconds = 0;
587#elif defined(PSNIP_CLOCK_WALL_METHOD) && PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY
588 struct timeval tv;
589
590 if (gettimeofday(&tv, NULL) != 0)
591 return -6;
592
593 res->seconds = tv.tv_sec;
594 res->nanoseconds = tv.tv_usec * 1000;
595#else
596 return -2;
597#endif
598
599 return 0;
600}

References PsnipClockTimespec::nanoseconds, and PsnipClockTimespec::seconds.

Referenced by psnip_clock_get_time().

Here is the caller graph for this function: