From ed7db34b4d71b33c623471c47e69ded390319fc3 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Thu, 4 Apr 2024 20:12:05 -0400 Subject: [PATCH 1/3] move tests to a branch while under development --- tests/api.c | 196 ----- tests/munit.c | 2255 ------------------------------------------------- tests/munit.h | 527 ------------ tests/test.c | 449 ---------- 4 files changed, 3427 deletions(-) delete mode 100644 tests/api.c delete mode 100644 tests/munit.c delete mode 100644 tests/munit.h delete mode 100644 tests/test.c diff --git a/tests/api.c b/tests/api.c deleted file mode 100644 index ae83ac1..0000000 --- a/tests/api.c +++ /dev/null @@ -1,196 +0,0 @@ -static void * -test_api_setup(const MunitParameter params[], void *user_data) -{ - struct test_info *info = (struct test_info *)user_data; - (void)info; - (void)params; - - ex_sl_t *slist = calloc(sizeof(ex_sl_t), 1); - if (slist == NULL) - return NULL; - sl_init(slist, uint32_key_cmp); - return (void *)(uintptr_t)slist; -} - -static void -test_api_tear_down(void *fixture) -{ - ex_sl_t *slist = (ex_sl_t *)fixture; - assert_ptr_not_null(slist); - sl_node *cursor = sl_begin(slist); - while (cursor) { - assert_ptr_not_null(cursor); - ex_node_t *entry = sl_get_entry(cursor, ex_node_t, snode); - assert_ptr_not_null(entry); - assert_uint32(entry->key, ==, entry->value); - cursor = sl_next(slist, cursor); - sl_erase_node(slist, &entry->snode); - sl_release_node(&entry->snode); - sl_wait_for_free(&entry->snode); - sl_free_node(&entry->snode); - free(entry); - } - sl_free(slist); - free(fixture); -} - -static void * -test_api_insert_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_insert_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_insert(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - assert_ptr_not_null(data); - int n = munit_rand_int_range(128, 4096); - int key = munit_rand_int_range(0, (((uint32_t)0) - 1) / 10); - while (n--) { - ex_node_t *node = (ex_node_t *)calloc(sizeof(ex_node_t), 1); - sl_init_node(&node->snode); - node->key = key; - node->value = key; - sl_insert(slist, &node->snode); - } - return MUNIT_OK; -} - -static void * -test_api_remove_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_remove_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_remove(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_find_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_find_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_find(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_update_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_update_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_update(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_delete_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_delete_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_delete(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_duplicates_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_duplicates_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_duplicates(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_size_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_size_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_size(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_iterators_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_iterators_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_iterators(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} diff --git a/tests/munit.c b/tests/munit.c deleted file mode 100644 index f42f8e9..0000000 --- a/tests/munit.c +++ /dev/null @@ -1,2255 +0,0 @@ -/* Copyright (c) 2013-2018 Evan Nemerson - * - * 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. - */ - -/*** Configuration ***/ - -/* This is just where the output from the test goes. It's really just - * meant to let you choose stdout or stderr, but if anyone really want - * to direct it to a file let me know, it would be fairly easy to - * support. */ -#if !defined(MUNIT_OUTPUT_FILE) -#define MUNIT_OUTPUT_FILE stdout -#endif - -/* This is a bit more useful; it tells µnit how to format the seconds in - * timed tests. If your tests run for longer you might want to reduce - * it, and if your computer is really fast and your tests are tiny you - * can increase it. */ -#if !defined(MUNIT_TEST_TIME_FORMAT) -#define MUNIT_TEST_TIME_FORMAT "0.8f" -#endif - -/* If you have long test names you might want to consider bumping - * this. The result information takes 43 characters. */ -#if !defined(MUNIT_TEST_NAME_LEN) -#define MUNIT_TEST_NAME_LEN 37 -#endif - -/* If you don't like the timing information, you can disable it by - * defining MUNIT_DISABLE_TIMING. */ -#if !defined(MUNIT_DISABLE_TIMING) -#define MUNIT_ENABLE_TIMING -#endif - -/*** End configuration ***/ - -#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE < 200809L) -#undef _POSIX_C_SOURCE -#endif -#if !defined(_POSIX_C_SOURCE) -#define _POSIX_C_SOURCE 200809L -#endif - -/* Solaris freaks out if you try to use a POSIX or SUS standard without - * the "right" C standard. */ -#if defined(_XOPEN_SOURCE) -#undef _XOPEN_SOURCE -#endif - -#if defined(__STDC_VERSION__) -#if __STDC_VERSION__ >= 201112L -#define _XOPEN_SOURCE 700 -#elif __STDC_VERSION__ >= 199901L -#define _XOPEN_SOURCE 600 -#endif -#endif - -/* Because, according to Microsoft, POSIX is deprecated. You've got - * to appreciate the chutzpah. */ -#if defined(_MSC_VER) && !defined(_CRT_NONSTDC_NO_DEPRECATE) -#define _CRT_NONSTDC_NO_DEPRECATE -#endif - -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -#include -#elif defined(_WIN32) -/* https://msdn.microsoft.com/en-us/library/tf4dy80a.aspx */ -#endif - -#include -#include -#include -#include -#include -#include -#include -#include - -#if !defined(MUNIT_NO_NL_LANGINFO) && !defined(_WIN32) -#define MUNIT_NL_LANGINFO -#include -#include -#include -#endif - -#if !defined(_WIN32) -#include -#include - -#include -#else -#include -#include -#include -#if !defined(STDERR_FILENO) -#define STDERR_FILENO _fileno(stderr) -#endif -#endif - -#include "munit.h" - -#define MUNIT_STRINGIFY(x) #x -#define MUNIT_XSTRINGIFY(x) MUNIT_STRINGIFY(x) - -#if defined(__GNUC__) || defined(__INTEL_COMPILER) || defined(__SUNPRO_CC) || \ - defined(__IBMCPP__) -#define MUNIT_THREAD_LOCAL __thread -#elif (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201102L)) || \ - defined(_Thread_local) -#define MUNIT_THREAD_LOCAL _Thread_local -#elif defined(_WIN32) -#define MUNIT_THREAD_LOCAL __declspec(thread) -#endif - -/* MSVC 12.0 will emit a warning at /W4 for code like 'do { ... } - * while (0)', or 'do { ... } while (1)'. I'm pretty sure nobody - * at Microsoft compiles with /W4. */ -#if defined(_MSC_VER) && (_MSC_VER <= 1800) -#pragma warning(disable : 4127) -#endif - -#if defined(_WIN32) || defined(__EMSCRIPTEN__) -#define MUNIT_NO_FORK -#endif - -#if defined(__EMSCRIPTEN__) -#define MUNIT_NO_BUFFER -#endif - -/*** Logging ***/ - -static MunitLogLevel munit_log_level_visible = MUNIT_LOG_INFO; -static MunitLogLevel munit_log_level_fatal = MUNIT_LOG_ERROR; - -#if defined(MUNIT_THREAD_LOCAL) -static MUNIT_THREAD_LOCAL munit_bool munit_error_jmp_buf_valid = 0; -static MUNIT_THREAD_LOCAL jmp_buf munit_error_jmp_buf; -#endif - -/* At certain warning levels, mingw will trigger warnings about - * suggesting the format attribute, which we've explicity *not* set - * because it will then choke on our attempts to use the MS-specific - * I64 modifier for size_t (which we have to use since MSVC doesn't - * support the C99 z modifier). */ - -#if defined(__MINGW32__) || defined(__MINGW64__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsuggest-attribute=format" -#endif - -MUNIT_PRINTF(5, 0) -static void -munit_logf_exv(MunitLogLevel level, FILE *fp, const char *filename, int line, - const char *format, va_list ap) -{ - if (level < munit_log_level_visible) - return; - - switch (level) { - case MUNIT_LOG_DEBUG: - fputs("Debug", fp); - break; - case MUNIT_LOG_INFO: - fputs("Info", fp); - break; - case MUNIT_LOG_WARNING: - fputs("Warning", fp); - break; - case MUNIT_LOG_ERROR: - fputs("Error", fp); - break; - default: - munit_logf_ex(MUNIT_LOG_ERROR, filename, line, "Invalid log level (%d)", - level); - return; - } - - fputs(": ", fp); - if (filename != NULL) - fprintf(fp, "%s:%d: ", filename, line); - vfprintf(fp, format, ap); - fputc('\n', fp); -} - -MUNIT_PRINTF(3, 4) -static void -munit_logf_internal(MunitLogLevel level, FILE *fp, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - munit_logf_exv(level, fp, NULL, 0, format, ap); - va_end(ap); -} - -static void -munit_log_internal(MunitLogLevel level, FILE *fp, const char *message) -{ - munit_logf_internal(level, fp, "%s", message); -} - -void -munit_logf_ex(MunitLogLevel level, const char *filename, int line, - const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - munit_logf_exv(level, stderr, filename, line, format, ap); - va_end(ap); - - if (level >= munit_log_level_fatal) { -#if defined(MUNIT_THREAD_LOCAL) - if (munit_error_jmp_buf_valid) - longjmp(munit_error_jmp_buf, 1); -#endif - abort(); - } -} - -void -munit_errorf_ex(const char *filename, int line, const char *format, ...) -{ - va_list ap; - - va_start(ap, format); - munit_logf_exv(MUNIT_LOG_ERROR, stderr, filename, line, format, ap); - va_end(ap); - -#if defined(MUNIT_THREAD_LOCAL) - if (munit_error_jmp_buf_valid) - longjmp(munit_error_jmp_buf, 1); -#endif - abort(); -} - -#if defined(__MINGW32__) || defined(__MINGW64__) -#pragma GCC diagnostic pop -#endif - -#if !defined(MUNIT_STRERROR_LEN) -#define MUNIT_STRERROR_LEN 80 -#endif - -static void -munit_log_errno(MunitLogLevel level, FILE *fp, const char *msg) -{ -#if defined(MUNIT_NO_STRERROR_R) || \ - (defined(__MINGW32__) && !defined(MINGW_HAS_SECURE_API)) - munit_logf_internal(level, fp, "%s: %s (%d)", msg, strerror(errno), errno); -#else - char munit_error_str[MUNIT_STRERROR_LEN]; - munit_error_str[0] = '\0'; - -#if !defined(_WIN32) - strerror_r(errno, munit_error_str, MUNIT_STRERROR_LEN); -#else - strerror_s(munit_error_str, MUNIT_STRERROR_LEN, errno); -#endif - - munit_logf_internal(level, fp, "%s: %s (%d)", msg, munit_error_str, errno); -#endif -} - -/*** Memory allocation ***/ - -void * -munit_malloc_ex(const char *filename, int line, size_t size) -{ - void *ptr; - - if (size == 0) - return NULL; - - ptr = calloc(1, size); - if (MUNIT_UNLIKELY(ptr == NULL)) { - munit_logf_ex(MUNIT_LOG_ERROR, filename, line, - "Failed to allocate %" MUNIT_SIZE_MODIFIER "u bytes.", size); - } - - return ptr; -} - -/*** Timer code ***/ - -#if defined(MUNIT_ENABLE_TIMING) - -#define psnip_uint64_t munit_uint64_t -#define psnip_uint32_t munit_uint32_t - -/* Code copied from portable-snippets - * . If you need to - * change something, please do it there so we can keep the code in - * sync. */ - -/* Clocks (v1) - * Portable Snippets - https://gitub.com/nemequ/portable-snippets - * Created by Evan Nemerson - * - * To the extent possible under law, the authors have waived all - * copyright and related or neighboring rights to this code. For - * details, see the Creative Commons Zero 1.0 Universal license at - * https://creativecommons.org/publicdomain/zero/1.0/ - */ - -#if !defined(PSNIP_CLOCK_H) -#define PSNIP_CLOCK_H - -#if !defined(psnip_uint64_t) -#include "../exact-int/exact-int.h" -#endif - -#if !defined(PSNIP_CLOCK_STATIC_INLINE) -#if defined(__GNUC__) -#define PSNIP_CLOCK__COMPILER_ATTRIBUTES __attribute__((__unused__)) -#else -#define PSNIP_CLOCK__COMPILER_ATTRIBUTES -#endif - -#define PSNIP_CLOCK__FUNCTION PSNIP_CLOCK__COMPILER_ATTRIBUTES static -#endif - -enum PsnipClockType { - /* This clock provides the current time, in units since 1970-01-01 - * 00:00:00 UTC not including leap seconds. In other words, UNIX - * time. Keep in mind that this clock doesn't account for leap - * seconds, and can go backwards (think NTP adjustments). */ - PSNIP_CLOCK_TYPE_WALL = 1, - /* The CPU time is a clock which increases only when the current - * process is active (i.e., it doesn't increment while blocking on - * I/O). */ - PSNIP_CLOCK_TYPE_CPU = 2, - /* Monotonic time is always running (unlike CPU time), but it only - ever moves forward unless you reboot the system. Things like NTP - adjustments have no effect on this clock. */ - PSNIP_CLOCK_TYPE_MONOTONIC = 3 -}; - -struct PsnipClockTimespec { - psnip_uint64_t seconds; - psnip_uint64_t nanoseconds; -}; - -/* Methods we support: */ - -#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 - -#include - -#if defined(HEDLEY_UNREACHABLE) -#define PSNIP_CLOCK_UNREACHABLE() HEDLEY_UNREACHABLE() -#else -#define PSNIP_CLOCK_UNREACHABLE() assert(0) -#endif - -/* Choose an implementation */ - -/* #undef PSNIP_CLOCK_WALL_METHOD */ -/* #undef PSNIP_CLOCK_CPU_METHOD */ -/* #undef PSNIP_CLOCK_MONOTONIC_METHOD */ - -/* We want to be able to detect the libc implementation, so we include - ( isn't available everywhere). */ - -#if defined(__unix__) || defined(__unix) || defined(__linux__) -#include -#include -#endif - -#if defined(_POSIX_TIMERS) && (_POSIX_TIMERS > 0) -/* These are known to work without librt. If you know of others - * please let us know so we can add them. */ -#if (defined(__GLIBC__) && \ - (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 17))) || \ - (defined(__FreeBSD__)) -#define PSNIP_CLOCK_HAVE_CLOCK_GETTIME -#elif !defined(PSNIP_CLOCK_NO_LIBRT) -#define PSNIP_CLOCK_HAVE_CLOCK_GETTIME -#endif -#endif - -#if defined(_WIN32) -#if !defined(PSNIP_CLOCK_CPU_METHOD) -#define PSNIP_CLOCK_CPU_METHOD PSNIP_CLOCK_METHOD_GETPROCESSTIMES -#endif -#if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) -#define PSNIP_CLOCK_MONOTONIC_METHOD PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER -#endif -#endif - -#if defined(__MACH__) && !defined(__gnu_hurd__) -#if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) -#define PSNIP_CLOCK_MONOTONIC_METHOD PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME -#endif -#endif - -#if defined(PSNIP_CLOCK_HAVE_CLOCK_GETTIME) -#include -#if !defined(PSNIP_CLOCK_WALL_METHOD) -#if defined(CLOCK_REALTIME_PRECISE) -#define PSNIP_CLOCK_WALL_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME -#define PSNIP_CLOCK_CLOCK_GETTIME_WALL CLOCK_REALTIME_PRECISE -#elif !defined(__sun) -#define PSNIP_CLOCK_WALL_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME -#define PSNIP_CLOCK_CLOCK_GETTIME_WALL CLOCK_REALTIME -#endif -#endif -#if !defined(PSNIP_CLOCK_CPU_METHOD) -#if defined(_POSIX_CPUTIME) || defined(CLOCK_PROCESS_CPUTIME_ID) -#define PSNIP_CLOCK_CPU_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME -#define PSNIP_CLOCK_CLOCK_GETTIME_CPU CLOCK_PROCESS_CPUTIME_ID -#elif defined(CLOCK_VIRTUAL) -#define PSNIP_CLOCK_CPU_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME -#define PSNIP_CLOCK_CLOCK_GETTIME_CPU CLOCK_VIRTUAL -#endif -#endif -#if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) -#if defined(CLOCK_MONOTONIC_RAW) -#define PSNIP_CLOCK_MONOTONIC_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME -#define PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC CLOCK_MONOTONIC -#elif defined(CLOCK_MONOTONIC_PRECISE) -#define PSNIP_CLOCK_MONOTONIC_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME -#define PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC CLOCK_MONOTONIC_PRECISE -#elif defined(_POSIX_MONOTONIC_CLOCK) || defined(CLOCK_MONOTONIC) -#define PSNIP_CLOCK_MONOTONIC_METHOD PSNIP_CLOCK_METHOD_CLOCK_GETTIME -#define PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC CLOCK_MONOTONIC -#endif -#endif -#endif - -#if defined(_POSIX_VERSION) && (_POSIX_VERSION >= 200112L) -#if !defined(PSNIP_CLOCK_WALL_METHOD) -#define PSNIP_CLOCK_WALL_METHOD PSNIP_CLOCK_METHOD_GETTIMEOFDAY -#endif -#endif - -#if !defined(PSNIP_CLOCK_WALL_METHOD) -#define PSNIP_CLOCK_WALL_METHOD PSNIP_CLOCK_METHOD_TIME -#endif - -#if !defined(PSNIP_CLOCK_CPU_METHOD) -#define PSNIP_CLOCK_CPU_METHOD PSNIP_CLOCK_METHOD_CLOCK -#endif - -/* Primarily here for testing. */ -#if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - defined(PSNIP_CLOCK_REQUIRE_MONOTONIC) -#error No monotonic clock found. -#endif - -/* Implementations */ - -#if (defined(PSNIP_CLOCK_CPU_METHOD) && \ - (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ - (defined(PSNIP_CLOCK_WALL_METHOD) && \ - (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ - (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ - (defined(PSNIP_CLOCK_CPU_METHOD) && \ - (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK)) || \ - (defined(PSNIP_CLOCK_WALL_METHOD) && \ - (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK)) || \ - (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK)) || \ - (defined(PSNIP_CLOCK_CPU_METHOD) && \ - (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_TIME)) || \ - (defined(PSNIP_CLOCK_WALL_METHOD) && \ - (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_TIME)) || \ - (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_TIME)) -#include -#endif - -#if (defined(PSNIP_CLOCK_CPU_METHOD) && \ - (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY)) || \ - (defined(PSNIP_CLOCK_WALL_METHOD) && \ - (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY)) || \ - (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY)) -#include -#endif - -#if (defined(PSNIP_CLOCK_CPU_METHOD) && \ - (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES)) || \ - (defined(PSNIP_CLOCK_WALL_METHOD) && \ - (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES)) || \ - (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES)) || \ - (defined(PSNIP_CLOCK_CPU_METHOD) && \ - (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64)) || \ - (defined(PSNIP_CLOCK_WALL_METHOD) && \ - (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64)) || \ - (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64)) -#include -#endif - -#if (defined(PSNIP_CLOCK_CPU_METHOD) && \ - (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE)) || \ - (defined(PSNIP_CLOCK_WALL_METHOD) && \ - (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE)) || \ - (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE)) -#include -#include -#endif - -#if (defined(PSNIP_CLOCK_CPU_METHOD) && \ - (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME)) || \ - (defined(PSNIP_CLOCK_WALL_METHOD) && \ - (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME)) || \ - (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME)) -#include -#include -#include -#endif - -/*** Implementations ***/ - -#define PSNIP_CLOCK_NSEC_PER_SEC ((psnip_uint32_t)(1000000000ULL)) - -#if (defined(PSNIP_CLOCK_CPU_METHOD) && \ - (PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ - (defined(PSNIP_CLOCK_WALL_METHOD) && \ - (PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) || \ - (defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - (PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME)) -PSNIP_CLOCK__FUNCTION psnip_uint32_t -psnip_clock__clock_getres(clockid_t clk_id) -{ - struct timespec res; - int r; - - r = clock_getres(clk_id, &res); - if (r != 0) - return 0; - - return (psnip_uint32_t)(PSNIP_CLOCK_NSEC_PER_SEC / res.tv_nsec); -} - -PSNIP_CLOCK__FUNCTION int -psnip_clock__clock_gettime(clockid_t clk_id, struct PsnipClockTimespec *res) -{ - struct timespec ts; - - if (clock_gettime(clk_id, &ts) != 0) - return -10; - - res->seconds = (psnip_uint64_t)(ts.tv_sec); - res->nanoseconds = (psnip_uint64_t)(ts.tv_nsec); - - return 0; -} -#endif - -PSNIP_CLOCK__FUNCTION psnip_uint32_t -psnip_clock_wall_get_precision(void) -{ -#if !defined(PSNIP_CLOCK_WALL_METHOD) - return 0; -#elif defined(PSNIP_CLOCK_WALL_METHOD) && \ - PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME - return psnip_clock__clock_getres(PSNIP_CLOCK_CLOCK_GETTIME_WALL); -#elif defined(PSNIP_CLOCK_WALL_METHOD) && \ - PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY - return 1000000; -#elif defined(PSNIP_CLOCK_WALL_METHOD) && \ - PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_TIME - return 1; -#else - return 0; -#endif -} - -PSNIP_CLOCK__FUNCTION int -psnip_clock_wall_get_time(struct PsnipClockTimespec *res) -{ - (void)res; - -#if !defined(PSNIP_CLOCK_WALL_METHOD) - return -2; -#elif defined(PSNIP_CLOCK_WALL_METHOD) && \ - PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME - return psnip_clock__clock_gettime(PSNIP_CLOCK_CLOCK_GETTIME_WALL, res); -#elif defined(PSNIP_CLOCK_WALL_METHOD) && \ - PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_TIME - res->seconds = time(NULL); - res->nanoseconds = 0; -#elif defined(PSNIP_CLOCK_WALL_METHOD) && \ - PSNIP_CLOCK_WALL_METHOD == PSNIP_CLOCK_METHOD_GETTIMEOFDAY - struct timeval tv; - - if (gettimeofday(&tv, NULL) != 0) - return -6; - - res->seconds = tv.tv_sec; - res->nanoseconds = tv.tv_usec * 1000; -#else - return -2; -#endif - - return 0; -} - -PSNIP_CLOCK__FUNCTION psnip_uint32_t -psnip_clock_cpu_get_precision(void) -{ -#if !defined(PSNIP_CLOCK_CPU_METHOD) - return 0; -#elif defined(PSNIP_CLOCK_CPU_METHOD) && \ - PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME - return psnip_clock__clock_getres(PSNIP_CLOCK_CLOCK_GETTIME_CPU); -#elif defined(PSNIP_CLOCK_CPU_METHOD) && \ - PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK - return CLOCKS_PER_SEC; -#elif defined(PSNIP_CLOCK_CPU_METHOD) && \ - PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES - return PSNIP_CLOCK_NSEC_PER_SEC / 100; -#else - return 0; -#endif -} - -PSNIP_CLOCK__FUNCTION int -psnip_clock_cpu_get_time(struct PsnipClockTimespec *res) -{ -#if !defined(PSNIP_CLOCK_CPU_METHOD) - (void)res; - return -2; -#elif defined(PSNIP_CLOCK_CPU_METHOD) && \ - PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME - return psnip_clock__clock_gettime(PSNIP_CLOCK_CLOCK_GETTIME_CPU, res); -#elif defined(PSNIP_CLOCK_CPU_METHOD) && \ - PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_CLOCK - clock_t t = clock(); - if (t == ((clock_t)-1)) - return -5; - res->seconds = t / CLOCKS_PER_SEC; - res->nanoseconds = (t % CLOCKS_PER_SEC) * - (PSNIP_CLOCK_NSEC_PER_SEC / CLOCKS_PER_SEC); -#elif defined(PSNIP_CLOCK_CPU_METHOD) && \ - PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETPROCESSTIMES - FILETIME CreationTime, ExitTime, KernelTime, UserTime; - LARGE_INTEGER date, adjust; - - if (!GetProcessTimes(GetCurrentProcess(), &CreationTime, &ExitTime, - &KernelTime, &UserTime)) - return -7; - - /* http://www.frenk.com/2009/12/convert-filetime-to-unix-timestamp/ */ - date.HighPart = UserTime.dwHighDateTime; - date.LowPart = UserTime.dwLowDateTime; - adjust.QuadPart = 11644473600000 * 10000; - date.QuadPart -= adjust.QuadPart; - - res->seconds = date.QuadPart / 10000000; - res->nanoseconds = (date.QuadPart % 10000000) * - (PSNIP_CLOCK_NSEC_PER_SEC / 100); -#elif PSNIP_CLOCK_CPU_METHOD == PSNIP_CLOCK_METHOD_GETRUSAGE - struct rusage usage; - if (getrusage(RUSAGE_SELF, &usage) != 0) - return -8; - - res->seconds = usage.ru_utime.tv_sec; - res->nanoseconds = tv.tv_usec * 1000; -#else - (void)res; - return -2; -#endif - - return 0; -} - -PSNIP_CLOCK__FUNCTION psnip_uint32_t -psnip_clock_monotonic_get_precision(void) -{ -#if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) - return 0; -#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME - return psnip_clock__clock_getres(PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC); -#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME - static mach_timebase_info_data_t tbi = { - 0, - }; - if (tbi.denom == 0) - mach_timebase_info(&tbi); - return (psnip_uint32_t)(tbi.numer / tbi.denom); -#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64 - return 1000; -#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER - LARGE_INTEGER Frequency; - QueryPerformanceFrequency(&Frequency); - return (psnip_uint32_t)((Frequency.QuadPart > PSNIP_CLOCK_NSEC_PER_SEC) ? - PSNIP_CLOCK_NSEC_PER_SEC : - Frequency.QuadPart); -#else - return 0; -#endif -} - -PSNIP_CLOCK__FUNCTION int -psnip_clock_monotonic_get_time(struct PsnipClockTimespec *res) -{ -#if !defined(PSNIP_CLOCK_MONOTONIC_METHOD) - (void)res; - return -2; -#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_CLOCK_GETTIME - return psnip_clock__clock_gettime(PSNIP_CLOCK_CLOCK_GETTIME_MONOTONIC, res); -#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_MACH_ABSOLUTE_TIME - psnip_uint64_t nsec = mach_absolute_time(); - static mach_timebase_info_data_t tbi = { - 0, - }; - if (tbi.denom == 0) - mach_timebase_info(&tbi); - nsec *= ((psnip_uint64_t)tbi.numer) / ((psnip_uint64_t)tbi.denom); - res->seconds = nsec / PSNIP_CLOCK_NSEC_PER_SEC; - res->nanoseconds = nsec % PSNIP_CLOCK_NSEC_PER_SEC; -#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_QUERYPERFORMANCECOUNTER - LARGE_INTEGER t, f; - if (QueryPerformanceCounter(&t) == 0) - return -12; - - QueryPerformanceFrequency(&f); - res->seconds = t.QuadPart / f.QuadPart; - res->nanoseconds = t.QuadPart % f.QuadPart; - if (f.QuadPart > PSNIP_CLOCK_NSEC_PER_SEC) - res->nanoseconds /= f.QuadPart / PSNIP_CLOCK_NSEC_PER_SEC; - else - res->nanoseconds *= PSNIP_CLOCK_NSEC_PER_SEC / f.QuadPart; -#elif defined(PSNIP_CLOCK_MONOTONIC_METHOD) && \ - PSNIP_CLOCK_MONOTONIC_METHOD == PSNIP_CLOCK_METHOD_GETTICKCOUNT64 - const ULONGLONG msec = GetTickCount64(); - res->seconds = msec / 1000; - res->nanoseconds = sec % 1000; -#else - return -2; -#endif - - return 0; -} - -/* Returns the number of ticks per second for the specified clock. - * For example, a clock with millisecond precision would return 1000, - * and a clock with 1 second (such as the time() function) would - * return 1. - * - * If the requested clock isn't available, it will return 0. - * Hopefully this will be rare, but if it happens to you please let us - * know so we can work on finding a way to support your system. - * - * Note that different clocks on the same system often have a - * different precisions. - */ -PSNIP_CLOCK__FUNCTION psnip_uint32_t -psnip_clock_get_precision(enum PsnipClockType clock_type) -{ - switch (clock_type) { - case PSNIP_CLOCK_TYPE_MONOTONIC: - return psnip_clock_monotonic_get_precision(); - case PSNIP_CLOCK_TYPE_CPU: - return psnip_clock_cpu_get_precision(); - case PSNIP_CLOCK_TYPE_WALL: - return psnip_clock_wall_get_precision(); - } - - PSNIP_CLOCK_UNREACHABLE(); - return 0; -} - -/* Set the provided timespec to the requested time. Returns 0 on - * success, or a negative value on failure. */ -PSNIP_CLOCK__FUNCTION int -psnip_clock_get_time(enum PsnipClockType clock_type, - struct PsnipClockTimespec *res) -{ - assert(res != NULL); - - switch (clock_type) { - case PSNIP_CLOCK_TYPE_MONOTONIC: - return psnip_clock_monotonic_get_time(res); - case PSNIP_CLOCK_TYPE_CPU: - return psnip_clock_cpu_get_time(res); - case PSNIP_CLOCK_TYPE_WALL: - return psnip_clock_wall_get_time(res); - } - - return -1; -} - -#endif /* !defined(PSNIP_CLOCK_H) */ - -static psnip_uint64_t -munit_clock_get_elapsed(struct PsnipClockTimespec *start, - struct PsnipClockTimespec *end) -{ - psnip_uint64_t r = (end->seconds - start->seconds) * PSNIP_CLOCK_NSEC_PER_SEC; - if (end->nanoseconds < start->nanoseconds) { - r -= (start->nanoseconds - end->nanoseconds); - } else { - r += (end->nanoseconds - start->nanoseconds); - } - return r; -} - -#else -#include -#endif /* defined(MUNIT_ENABLE_TIMING) */ - -/*** PRNG stuff ***/ - -/* This is (unless I screwed up, which is entirely possible) the - * version of PCG with 32-bit state. It was chosen because it has a - * small enough state that we should reliably be able to use CAS - * instead of requiring a lock for thread-safety. - * - * If I did screw up, I probably will not bother changing it unless - * there is a significant bias. It's really not important this be - * particularly strong, as long as it is fairly random it's much more - * important that it be reproducible, so bug reports have a better - * chance of being reproducible. */ - -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ - !defined(__STDC_NO_ATOMICS__) && !defined(__EMSCRIPTEN__) && \ - (!defined(__GNUC_MINOR__) || (__GNUC__ > 4) || \ - (__GNUC__ == 4 && __GNUC_MINOR__ > 8)) -#define HAVE_STDATOMIC -#elif defined(__clang__) -#if __has_extension(c_atomic) -#define HAVE_CLANG_ATOMICS -#endif -#endif - -/* Workaround for http://llvm.org/bugs/show_bug.cgi?id=26911 */ -#if defined(__clang__) && defined(_WIN32) -#undef HAVE_STDATOMIC -#if defined(__c2__) -#undef HAVE_CLANG_ATOMICS -#endif -#endif - -#if defined(_OPENMP) -#define ATOMIC_UINT32_T uint32_t -#define ATOMIC_UINT32_INIT(x) (x) -#elif defined(HAVE_STDATOMIC) -#include -#define ATOMIC_UINT32_T _Atomic uint32_t -#define ATOMIC_UINT32_INIT(x) ATOMIC_VAR_INIT(x) -#elif defined(HAVE_CLANG_ATOMICS) -#define ATOMIC_UINT32_T _Atomic uint32_t -#define ATOMIC_UINT32_INIT(x) (x) -#elif defined(_WIN32) -#define ATOMIC_UINT32_T volatile LONG -#define ATOMIC_UINT32_INIT(x) (x) -#else -#define ATOMIC_UINT32_T volatile uint32_t -#define ATOMIC_UINT32_INIT(x) (x) -#endif - -static ATOMIC_UINT32_T munit_rand_state = ATOMIC_UINT32_INIT(42); - -#if defined(_OPENMP) -static inline void -munit_atomic_store(ATOMIC_UINT32_T *dest, ATOMIC_UINT32_T value) -{ -#pragma omp critical(munit_atomics) - *dest = value; -} - -static inline uint32_t -munit_atomic_load(ATOMIC_UINT32_T *src) -{ - int ret; -#pragma omp critical(munit_atomics) - ret = *src; - return ret; -} - -static inline uint32_t -munit_atomic_cas(ATOMIC_UINT32_T *dest, ATOMIC_UINT32_T *expected, - ATOMIC_UINT32_T desired) -{ - munit_bool ret; - -#pragma omp critical(munit_atomics) - { - if (*dest == *expected) { - *dest = desired; - ret = 1; - } else { - ret = 0; - } - } - - return ret; -} -#elif defined(HAVE_STDATOMIC) -#define munit_atomic_store(dest, value) atomic_store(dest, value) -#define munit_atomic_load(src) atomic_load(src) -#define munit_atomic_cas(dest, expected, value) \ - atomic_compare_exchange_weak(dest, expected, value) -#elif defined(HAVE_CLANG_ATOMICS) -#define munit_atomic_store(dest, value) \ - __c11_atomic_store(dest, value, __ATOMIC_SEQ_CST) -#define munit_atomic_load(src) __c11_atomic_load(src, __ATOMIC_SEQ_CST) -#define munit_atomic_cas(dest, expected, value) \ - __c11_atomic_compare_exchange_weak(dest, expected, value, __ATOMIC_SEQ_CST, \ - __ATOMIC_SEQ_CST) -#elif defined(__GNUC__) && (__GNUC__ > 4) || \ - (__GNUC__ == 4 && __GNUC_MINOR__ >= 7) -#define munit_atomic_store(dest, value) \ - __atomic_store_n(dest, value, __ATOMIC_SEQ_CST) -#define munit_atomic_load(src) __atomic_load_n(src, __ATOMIC_SEQ_CST) -#define munit_atomic_cas(dest, expected, value) \ - __atomic_compare_exchange_n(dest, expected, value, 1, __ATOMIC_SEQ_CST, \ - __ATOMIC_SEQ_CST) -#elif defined(__GNUC__) && (__GNUC__ >= 4) -#define munit_atomic_store(dest, value) \ - do { \ - *(dest) = (value); \ - } while (0) -#define munit_atomic_load(src) (*(src)) -#define munit_atomic_cas(dest, expected, value) \ - __sync_bool_compare_and_swap(dest, *expected, value) -#elif defined(_WIN32) /* Untested */ -#define munit_atomic_store(dest, value) \ - do { \ - *(dest) = (value); \ - } while (0) -#define munit_atomic_load(src) (*(src)) -#define munit_atomic_cas(dest, expected, value) \ - InterlockedCompareExchange((dest), (value), *(expected)) -#else -#warning No atomic implementation, PRNG will not be thread-safe -#define munit_atomic_store(dest, value) \ - do { \ - *(dest) = (value); \ - } while (0) -#define munit_atomic_load(src) (*(src)) -static inline munit_bool -munit_atomic_cas(ATOMIC_UINT32_T *dest, ATOMIC_UINT32_T *expected, - ATOMIC_UINT32_T desired) -{ - if (*dest == *expected) { - *dest = desired; - return 1; - } else { - return 0; - } -} -#endif - -#define MUNIT_PRNG_MULTIPLIER (747796405U) -#define MUNIT_PRNG_INCREMENT (1729U) - -static munit_uint32_t -munit_rand_next_state(munit_uint32_t state) -{ - return state * MUNIT_PRNG_MULTIPLIER + MUNIT_PRNG_INCREMENT; -} - -static munit_uint32_t -munit_rand_from_state(munit_uint32_t state) -{ - munit_uint32_t res = ((state >> ((state >> 28) + 4)) ^ state) * (277803737U); - res ^= res >> 22; - return res; -} - -void -munit_rand_seed(munit_uint32_t seed) -{ - munit_uint32_t state = munit_rand_next_state(seed + MUNIT_PRNG_INCREMENT); - munit_atomic_store(&munit_rand_state, state); -} - -static munit_uint32_t -munit_rand_generate_seed(void) -{ - munit_uint32_t seed, state; -#if defined(MUNIT_ENABLE_TIMING) - struct PsnipClockTimespec wc = { - 0, - }; - - psnip_clock_get_time(PSNIP_CLOCK_TYPE_WALL, &wc); - seed = (munit_uint32_t)wc.nanoseconds; -#else - seed = (munit_uint32_t)time(NULL); -#endif - - state = munit_rand_next_state(seed + MUNIT_PRNG_INCREMENT); - return munit_rand_from_state(state); -} - -static munit_uint32_t -munit_rand_state_uint32(munit_uint32_t *state) -{ - const munit_uint32_t old = *state; - *state = munit_rand_next_state(old); - return munit_rand_from_state(old); -} - -munit_uint32_t -munit_rand_uint32(void) -{ - munit_uint32_t old, state; - - do { - old = munit_atomic_load(&munit_rand_state); - state = munit_rand_next_state(old); - } while (!munit_atomic_cas(&munit_rand_state, &old, state)); - - return munit_rand_from_state(old); -} - -static void -munit_rand_state_memory(munit_uint32_t *state, size_t size, - munit_uint8_t data[MUNIT_ARRAY_PARAM(size)]) -{ - size_t members_remaining = size / sizeof(munit_uint32_t); - size_t bytes_remaining = size % sizeof(munit_uint32_t); - munit_uint8_t *b = data; - munit_uint32_t rv; - while (members_remaining-- > 0) { - rv = munit_rand_state_uint32(state); - memcpy(b, &rv, sizeof(munit_uint32_t)); - b += sizeof(munit_uint32_t); - } - if (bytes_remaining != 0) { - rv = munit_rand_state_uint32(state); - memcpy(b, &rv, bytes_remaining); - } -} - -void -munit_rand_memory(size_t size, munit_uint8_t data[MUNIT_ARRAY_PARAM(size)]) -{ - munit_uint32_t old, state; - - do { - state = old = munit_atomic_load(&munit_rand_state); - munit_rand_state_memory(&state, size, data); - } while (!munit_atomic_cas(&munit_rand_state, &old, state)); -} - -static munit_uint32_t -munit_rand_state_at_most(munit_uint32_t *state, munit_uint32_t salt, - munit_uint32_t max) -{ - /* We want (UINT32_MAX + 1) % max, which in unsigned arithmetic is the same - * as (UINT32_MAX + 1 - max) % max = -max % max. We compute -max using not - * to avoid compiler warnings. - */ - const munit_uint32_t min = (~max + 1U) % max; - munit_uint32_t x; - - if (max == (~((munit_uint32_t)0U))) - return munit_rand_state_uint32(state) ^ salt; - - max++; - - do { - x = munit_rand_state_uint32(state) ^ salt; - } while (x < min); - - return x % max; -} - -static munit_uint32_t -munit_rand_at_most(munit_uint32_t salt, munit_uint32_t max) -{ - munit_uint32_t old, state; - munit_uint32_t retval; - - do { - state = old = munit_atomic_load(&munit_rand_state); - retval = munit_rand_state_at_most(&state, salt, max); - } while (!munit_atomic_cas(&munit_rand_state, &old, state)); - - return retval; -} - -int -munit_rand_int_range(int min, int max) -{ - munit_uint64_t range = (munit_uint64_t)max - (munit_uint64_t)min; - - if (min > max) - return munit_rand_int_range(max, min); - - if (range > (~((munit_uint32_t)0U))) - range = (~((munit_uint32_t)0U)); - - return min + munit_rand_at_most(0, (munit_uint32_t)range); -} - -double -munit_rand_double(void) -{ - munit_uint32_t old, state; - double retval = 0.0; - - do { - state = old = munit_atomic_load(&munit_rand_state); - - /* See http://mumble.net/~campbell/tmp/random_real.c for how to do - * this right. Patches welcome if you feel that this is too - * biased. */ - retval = munit_rand_state_uint32(&state) / ((~((munit_uint32_t)0U)) + 1.0); - } while (!munit_atomic_cas(&munit_rand_state, &old, state)); - - return retval; -} - -/*** Test suite handling ***/ - -typedef struct { - unsigned int successful; - unsigned int skipped; - unsigned int failed; - unsigned int errored; -#if defined(MUNIT_ENABLE_TIMING) - munit_uint64_t cpu_clock; - munit_uint64_t wall_clock; -#endif -} MunitReport; - -typedef struct { - const char *prefix; - const MunitSuite *suite; - const char **tests; - munit_uint32_t seed; - unsigned int iterations; - MunitParameter *parameters; - munit_bool single_parameter_mode; - void *user_data; - MunitReport report; - munit_bool colorize; - munit_bool fork; - munit_bool show_stderr; - munit_bool fatal_failures; -} MunitTestRunner; - -const char * -munit_parameters_get(const MunitParameter params[], const char *key) -{ - const MunitParameter *param; - - for (param = params; param != NULL && param->name != NULL; param++) - if (strcmp(param->name, key) == 0) - return param->value; - return NULL; -} - -#if defined(MUNIT_ENABLE_TIMING) -static void -munit_print_time(FILE *fp, munit_uint64_t nanoseconds) -{ - fprintf(fp, "%" MUNIT_TEST_TIME_FORMAT, - ((double)nanoseconds) / ((double)PSNIP_CLOCK_NSEC_PER_SEC)); -} -#endif - -/* Add a paramter to an array of parameters. */ -static MunitResult -munit_parameters_add(size_t *params_size, - MunitParameter *params[MUNIT_ARRAY_PARAM(*params_size)], char *name, - char *value) -{ - *params = realloc(*params, sizeof(MunitParameter) * (*params_size + 2)); - if (*params == NULL) - return MUNIT_ERROR; - - (*params)[*params_size].name = name; - (*params)[*params_size].value = value; - (*params_size)++; - (*params)[*params_size].name = NULL; - (*params)[*params_size].value = NULL; - - return MUNIT_OK; -} - -/* Concatenate two strings, but just return one of the components - * unaltered if the other is NULL or "". */ -static char * -munit_maybe_concat(size_t *len, char *prefix, char *suffix) -{ - char *res; - size_t res_l; - const size_t prefix_l = prefix != NULL ? strlen(prefix) : 0; - const size_t suffix_l = suffix != NULL ? strlen(suffix) : 0; - if (prefix_l == 0 && suffix_l == 0) { - res = NULL; - res_l = 0; - } else if (prefix_l == 0 && suffix_l != 0) { - res = suffix; - res_l = suffix_l; - } else if (prefix_l != 0 && suffix_l == 0) { - res = prefix; - res_l = prefix_l; - } else { - res_l = prefix_l + suffix_l; - res = malloc(res_l + 1); - memcpy(res, prefix, prefix_l); - memcpy(res + prefix_l, suffix, suffix_l); - res[res_l] = 0; - } - - if (len != NULL) - *len = res_l; - - return res; -} - -/* Possbily free a string returned by munit_maybe_concat. */ -static void -munit_maybe_free_concat(char *s, const char *prefix, const char *suffix) -{ - if (prefix != s && suffix != s) - free(s); -} - -/* Cheap string hash function, just used to salt the PRNG. */ -static munit_uint32_t -munit_str_hash(const char *name) -{ - const char *p; - munit_uint32_t h = 5381U; - - for (p = name; *p != '\0'; p++) - h = (h << 5) + h + *p; - - return h; -} - -static void -munit_splice(int from, int to) -{ - munit_uint8_t buf[1024]; -#if !defined(_WIN32) - ssize_t len; - ssize_t bytes_written; - ssize_t write_res; -#else - int len; - int bytes_written; - int write_res; -#endif - do { - len = read(from, buf, sizeof(buf)); - if (len > 0) { - bytes_written = 0; - do { - write_res = write(to, buf + bytes_written, len - bytes_written); - if (write_res < 0) - break; - bytes_written += write_res; - } while (bytes_written < len); - } else - break; - } while (1); -} - -/* This is the part that should be handled in the child process */ -static MunitResult -munit_test_runner_exec(MunitTestRunner *runner, const MunitTest *test, - const MunitParameter params[], MunitReport *report) -{ - unsigned int iterations = runner->iterations; - MunitResult result = MUNIT_FAIL; -#if defined(MUNIT_ENABLE_TIMING) - struct PsnipClockTimespec wall_clock_begin = { 0, }, wall_clock_end = { 0, }; - struct PsnipClockTimespec cpu_clock_begin = { 0, }, cpu_clock_end = { 0, }; -#endif - unsigned int i = 0; - - if ((test->options & MUNIT_TEST_OPTION_SINGLE_ITERATION) == - MUNIT_TEST_OPTION_SINGLE_ITERATION) - iterations = 1; - else if (iterations == 0) - iterations = runner->suite->iterations; - - munit_rand_seed(runner->seed); - - do { - void *data = (test->setup == NULL) ? runner->user_data : - test->setup(params, runner->user_data); - -#if defined(MUNIT_ENABLE_TIMING) - psnip_clock_get_time(PSNIP_CLOCK_TYPE_WALL, &wall_clock_begin); - psnip_clock_get_time(PSNIP_CLOCK_TYPE_CPU, &cpu_clock_begin); -#endif - - result = test->test(params, data); - -#if defined(MUNIT_ENABLE_TIMING) - psnip_clock_get_time(PSNIP_CLOCK_TYPE_WALL, &wall_clock_end); - psnip_clock_get_time(PSNIP_CLOCK_TYPE_CPU, &cpu_clock_end); -#endif - - if (test->tear_down != NULL) - test->tear_down(data); - - if (MUNIT_LIKELY(result == MUNIT_OK)) { - report->successful++; -#if defined(MUNIT_ENABLE_TIMING) - report->wall_clock += munit_clock_get_elapsed(&wall_clock_begin, - &wall_clock_end); - report->cpu_clock += munit_clock_get_elapsed(&cpu_clock_begin, - &cpu_clock_end); -#endif - } else { - switch ((int)result) { - case MUNIT_SKIP: - report->skipped++; - break; - case MUNIT_FAIL: - report->failed++; - break; - case MUNIT_ERROR: - report->errored++; - break; - default: - break; - } - break; - } - } while (++i < iterations); - - return result; -} - -#if defined(MUNIT_EMOTICON) -#define MUNIT_RESULT_STRING_OK ":)" -#define MUNIT_RESULT_STRING_SKIP ":|" -#define MUNIT_RESULT_STRING_FAIL ":(" -#define MUNIT_RESULT_STRING_ERROR ":o" -#define MUNIT_RESULT_STRING_TODO ":/" -#else -#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 " -#endif - -static void -munit_test_runner_print_color(const MunitTestRunner *runner, const char *string, - char color) -{ - if (runner->colorize) - fprintf(MUNIT_OUTPUT_FILE, "\x1b[3%cm%s\x1b[39m", color, string); - else - fputs(string, MUNIT_OUTPUT_FILE); -} - -#if !defined(MUNIT_NO_BUFFER) -static int -munit_replace_stderr(FILE *stderr_buf) -{ - if (stderr_buf != NULL) { - const int orig_stderr = dup(STDERR_FILENO); - - int errfd = fileno(stderr_buf); - if (MUNIT_UNLIKELY(errfd == -1)) { - exit(EXIT_FAILURE); - } - - dup2(errfd, STDERR_FILENO); - - return orig_stderr; - } - - return -1; -} - -static void -munit_restore_stderr(int orig_stderr) -{ - if (orig_stderr != -1) { - dup2(orig_stderr, STDERR_FILENO); - close(orig_stderr); - } -} -#endif /* !defined(MUNIT_NO_BUFFER) */ - -/* Run a test with the specified parameters. */ -static void -munit_test_runner_run_test_with_params(MunitTestRunner *runner, - const MunitTest *test, const MunitParameter params[]) -{ - MunitResult result = MUNIT_OK; - MunitReport report = { - 0, - 0, - 0, - 0, -#if defined(MUNIT_ENABLE_TIMING) - 0, - 0 -#endif - }; - unsigned int output_l; - munit_bool first; - const MunitParameter *param; - FILE *stderr_buf; -#if !defined(MUNIT_NO_FORK) - int pipefd[2]; - pid_t fork_pid; - int orig_stderr; - ssize_t bytes_written = 0; - ssize_t write_res; - ssize_t bytes_read = 0; - ssize_t read_res; - int status = 0; - pid_t changed_pid; -#endif - - if (params != NULL) { - output_l = 2; - fputs(" ", MUNIT_OUTPUT_FILE); - first = 1; - for (param = params; param != NULL && param->name != NULL; param++) { - if (!first) { - fputs(", ", MUNIT_OUTPUT_FILE); - output_l += 2; - } else { - first = 0; - } - - output_l += fprintf(MUNIT_OUTPUT_FILE, "%s=%s", param->name, - param->value); - } - while (output_l++ < MUNIT_TEST_NAME_LEN) { - fputc(' ', MUNIT_OUTPUT_FILE); - } - } - - fflush(MUNIT_OUTPUT_FILE); - - stderr_buf = NULL; -#if !defined(_WIN32) || defined(__MINGW32__) - stderr_buf = tmpfile(); -#else - tmpfile_s(&stderr_buf); -#endif - if (stderr_buf == NULL) { - munit_log_errno(MUNIT_LOG_ERROR, stderr, - "unable to create buffer for stderr"); - result = MUNIT_ERROR; - goto print_result; - } - -#if !defined(MUNIT_NO_FORK) - if (runner->fork) { - pipefd[0] = -1; - pipefd[1] = -1; - if (pipe(pipefd) != 0) { - munit_log_errno(MUNIT_LOG_ERROR, stderr, "unable to create pipe"); - result = MUNIT_ERROR; - goto print_result; - } - - fork_pid = fork(); - if (fork_pid == 0) { - close(pipefd[0]); - - orig_stderr = munit_replace_stderr(stderr_buf); - munit_test_runner_exec(runner, test, params, &report); - - /* Note that we don't restore stderr. This is so we can buffer - * things written to stderr later on (such as by - * asan/tsan/ubsan, valgrind, etc.) */ - close(orig_stderr); - - do { - write_res = write(pipefd[1], - ((munit_uint8_t *)(&report)) + bytes_written, - sizeof(report) - bytes_written); - if (write_res < 0) { - if (stderr_buf != NULL) { - munit_log_errno(MUNIT_LOG_ERROR, stderr, "unable to write to pipe"); - } - exit(EXIT_FAILURE); - } - bytes_written += write_res; - } while ((size_t)bytes_written < sizeof(report)); - - if (stderr_buf != NULL) - fclose(stderr_buf); - close(pipefd[1]); - - exit(EXIT_SUCCESS); - } else if (fork_pid == -1) { - close(pipefd[0]); - close(pipefd[1]); - if (stderr_buf != NULL) { - munit_log_errno(MUNIT_LOG_ERROR, stderr, "unable to fork"); - } - report.errored++; - result = MUNIT_ERROR; - } else { - close(pipefd[1]); - do { - read_res = read(pipefd[0], ((munit_uint8_t *)(&report)) + bytes_read, - sizeof(report) - bytes_read); - if (read_res < 1) - break; - bytes_read += read_res; - } while (bytes_read < (ssize_t)sizeof(report)); - - changed_pid = waitpid(fork_pid, &status, 0); - - if (MUNIT_LIKELY(changed_pid == fork_pid) && - MUNIT_LIKELY(WIFEXITED(status))) { - if (bytes_read != sizeof(report)) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, - "child exited unexpectedly with status %d", WEXITSTATUS(status)); - report.errored++; - } else if (WEXITSTATUS(status) != EXIT_SUCCESS) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, - "child exited with status %d", WEXITSTATUS(status)); - report.errored++; - } - } else { - if (WIFSIGNALED(status)) { -#if defined(_XOPEN_VERSION) && (_XOPEN_VERSION >= 700) - munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, - "child killed by signal %d (%s)", WTERMSIG(status), - strsignal(WTERMSIG(status))); -#else - munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, - "child killed by signal %d", WTERMSIG(status)); -#endif - } else if (WIFSTOPPED(status)) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr_buf, - "child stopped by signal %d", WSTOPSIG(status)); - } - report.errored++; - } - - close(pipefd[0]); - waitpid(fork_pid, NULL, 0); - } - } else -#endif - { -#if !defined(MUNIT_NO_BUFFER) - const volatile int orig_stderr = munit_replace_stderr(stderr_buf); -#endif - -#if defined(MUNIT_THREAD_LOCAL) - if (MUNIT_UNLIKELY(setjmp(munit_error_jmp_buf) != 0)) { - result = MUNIT_FAIL; - report.failed++; - } else { - munit_error_jmp_buf_valid = 1; - result = munit_test_runner_exec(runner, test, params, &report); - } -#else - result = munit_test_runner_exec(runner, test, params, &report); -#endif - -#if !defined(MUNIT_NO_BUFFER) - munit_restore_stderr(orig_stderr); -#endif - - /* Here just so that the label is used on Windows and we don't get - * a warning */ - goto print_result; - } - -print_result: - - fputs("[ ", MUNIT_OUTPUT_FILE); - if ((test->options & MUNIT_TEST_OPTION_TODO) == MUNIT_TEST_OPTION_TODO) { - if (report.failed != 0 || report.errored != 0 || report.skipped != 0) { - munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_TODO, '3'); - result = MUNIT_OK; - } else { - munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_ERROR, '1'); - if (MUNIT_LIKELY(stderr_buf != NULL)) - munit_log_internal(MUNIT_LOG_ERROR, stderr_buf, - "Test marked TODO, but was successful."); - runner->report.failed++; - result = MUNIT_ERROR; - } - } else if (report.failed > 0) { - munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_FAIL, '1'); - runner->report.failed++; - result = MUNIT_FAIL; - } else if (report.errored > 0) { - munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_ERROR, '1'); - runner->report.errored++; - result = MUNIT_ERROR; - } else if (report.skipped > 0) { - munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_SKIP, '3'); - runner->report.skipped++; - result = MUNIT_SKIP; - } else if (report.successful > 1) { - munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_OK, '2'); -#if defined(MUNIT_ENABLE_TIMING) - fputs(" ] [ ", MUNIT_OUTPUT_FILE); - munit_print_time(MUNIT_OUTPUT_FILE, report.wall_clock / report.successful); - fputs(" / ", MUNIT_OUTPUT_FILE); - munit_print_time(MUNIT_OUTPUT_FILE, report.cpu_clock / report.successful); - fprintf(MUNIT_OUTPUT_FILE, - " CPU ]\n %-" MUNIT_XSTRINGIFY(MUNIT_TEST_NAME_LEN) "s Total: [ ", ""); - munit_print_time(MUNIT_OUTPUT_FILE, report.wall_clock); - fputs(" / ", MUNIT_OUTPUT_FILE); - munit_print_time(MUNIT_OUTPUT_FILE, report.cpu_clock); - fputs(" CPU", MUNIT_OUTPUT_FILE); -#endif - runner->report.successful++; - result = MUNIT_OK; - } else if (report.successful > 0) { - munit_test_runner_print_color(runner, MUNIT_RESULT_STRING_OK, '2'); -#if defined(MUNIT_ENABLE_TIMING) - fputs(" ] [ ", MUNIT_OUTPUT_FILE); - munit_print_time(MUNIT_OUTPUT_FILE, report.wall_clock); - fputs(" / ", MUNIT_OUTPUT_FILE); - munit_print_time(MUNIT_OUTPUT_FILE, report.cpu_clock); - fputs(" CPU", MUNIT_OUTPUT_FILE); -#endif - runner->report.successful++; - result = MUNIT_OK; - } - fputs(" ]\n", MUNIT_OUTPUT_FILE); - - if (stderr_buf != NULL) { - if (result == MUNIT_FAIL || result == MUNIT_ERROR || runner->show_stderr) { - fflush(MUNIT_OUTPUT_FILE); - - rewind(stderr_buf); - munit_splice(fileno(stderr_buf), STDERR_FILENO); - - fflush(stderr); - } - - fclose(stderr_buf); - } -} - -static void -munit_test_runner_run_test_wild(MunitTestRunner *runner, const MunitTest *test, - const char *test_name, MunitParameter *params, MunitParameter *p) -{ - const MunitParameterEnum *pe; - char **values; - MunitParameter *next; - - for (pe = test->parameters; pe != NULL && pe->name != NULL; pe++) { - if (p->name == pe->name) - break; - } - - if (pe == NULL) - return; - - for (values = pe->values; *values != NULL; values++) { - next = p + 1; - p->value = *values; - if (next->name == NULL) { - munit_test_runner_run_test_with_params(runner, test, params); - } else { - munit_test_runner_run_test_wild(runner, test, test_name, params, next); - } - if (runner->fatal_failures && - (runner->report.failed != 0 || runner->report.errored != 0)) - break; - } -} - -/* Run a single test, with every combination of parameters - * requested. */ -static void -munit_test_runner_run_test(MunitTestRunner *runner, const MunitTest *test, - const char *prefix) -{ - char *test_name = munit_maybe_concat(NULL, (char *)prefix, - (char *)test->name); - /* The array of parameters to pass to - * munit_test_runner_run_test_with_params */ - MunitParameter *params = NULL; - size_t params_l = 0; - /* Wildcard parameters are parameters which have possible values - * specified in the test, but no specific value was passed to the - * CLI. That means we want to run the test once for every - * possible combination of parameter values or, if --single was - * passed to the CLI, a single time with a random set of - * parameters. */ - MunitParameter *wild_params = NULL; - size_t wild_params_l = 0; - const MunitParameterEnum *pe; - const MunitParameter *cli_p; - munit_bool filled; - unsigned int possible; - char **vals; - size_t first_wild; - const MunitParameter *wp; - int pidx; - - munit_rand_seed(runner->seed); - - fprintf(MUNIT_OUTPUT_FILE, "%-" MUNIT_XSTRINGIFY(MUNIT_TEST_NAME_LEN) "s", - test_name); - - if (test->parameters == NULL) { - /* No parameters. Simple, nice. */ - munit_test_runner_run_test_with_params(runner, test, NULL); - } else { - fputc('\n', MUNIT_OUTPUT_FILE); - - for (pe = test->parameters; pe != NULL && pe->name != NULL; pe++) { - /* Did we received a value for this parameter from the CLI? */ - filled = 0; - for (cli_p = runner->parameters; cli_p != NULL && cli_p->name != NULL; - cli_p++) { - if (strcmp(cli_p->name, pe->name) == 0) { - if (MUNIT_UNLIKELY(munit_parameters_add(¶ms_l, ¶ms, pe->name, - cli_p->value) != MUNIT_OK)) - goto cleanup; - filled = 1; - break; - } - } - if (filled) - continue; - - /* Nothing from CLI, is the enum NULL/empty? We're not a - * fuzzer… */ - if (pe->values == NULL || pe->values[0] == NULL) - continue; - - /* If --single was passed to the CLI, choose a value from the - * list of possibilities randomly. */ - if (runner->single_parameter_mode) { - possible = 0; - for (vals = pe->values; *vals != NULL; vals++) - possible++; - /* We want the tests to be reproducible, even if you're only - * running a single test, but we don't want every test with - * the same number of parameters to choose the same parameter - * number, so use the test name as a primitive salt. */ - pidx = munit_rand_at_most(munit_str_hash(test_name), possible - 1); - if (MUNIT_UNLIKELY(munit_parameters_add(¶ms_l, ¶ms, pe->name, - pe->values[pidx]) != MUNIT_OK)) - goto cleanup; - } else { - /* We want to try every permutation. Put in a placeholder - * entry, we'll iterate through them later. */ - if (MUNIT_UNLIKELY(munit_parameters_add(&wild_params_l, &wild_params, - pe->name, NULL) != MUNIT_OK)) - goto cleanup; - } - } - - if (wild_params_l != 0) { - first_wild = params_l; - for (wp = wild_params; wp != NULL && wp->name != NULL; wp++) { - for (pe = test->parameters; - pe != NULL && pe->name != NULL && pe->values != NULL; pe++) { - if (strcmp(wp->name, pe->name) == 0) { - if (MUNIT_UNLIKELY(munit_parameters_add(¶ms_l, ¶ms, - pe->name, pe->values[0]) != MUNIT_OK)) - goto cleanup; - } - } - } - - munit_test_runner_run_test_wild(runner, test, test_name, params, - params + first_wild); - } else { - munit_test_runner_run_test_with_params(runner, test, params); - } - - cleanup: - free(params); - free(wild_params); - } - - munit_maybe_free_concat(test_name, prefix, test->name); -} - -/* Recurse through the suite and run all the tests. If a list of - * tests to run was provied on the command line, run only those - * tests. */ -static void -munit_test_runner_run_suite(MunitTestRunner *runner, const MunitSuite *suite, - const char *prefix) -{ - size_t pre_l; - char *pre = munit_maybe_concat(&pre_l, (char *)prefix, (char *)suite->prefix); - const MunitTest *test; - const char **test_name; - const MunitSuite *child_suite; - - /* Run the tests. */ - for (test = suite->tests; test != NULL && test->test != NULL; test++) { - if (runner->tests != NULL) { /* Specific tests were requested on the CLI */ - for (test_name = runner->tests; test_name != NULL && *test_name != NULL; - test_name++) { - if ((pre_l == 0 || strncmp(pre, *test_name, pre_l) == 0) && - strncmp(test->name, *test_name + pre_l, strlen(*test_name + pre_l)) == - 0) { - munit_test_runner_run_test(runner, test, pre); - if (runner->fatal_failures && - (runner->report.failed != 0 || runner->report.errored != 0)) - goto cleanup; - } - } - } else { /* Run all tests */ - munit_test_runner_run_test(runner, test, pre); - } - } - - if (runner->fatal_failures && - (runner->report.failed != 0 || runner->report.errored != 0)) - goto cleanup; - - /* Run any child suites. */ - for (child_suite = suite->suites; - child_suite != NULL && child_suite->prefix != NULL; child_suite++) { - munit_test_runner_run_suite(runner, child_suite, pre); - } - -cleanup: - - munit_maybe_free_concat(pre, prefix, suite->prefix); -} - -static void -munit_test_runner_run(MunitTestRunner *runner) -{ - munit_test_runner_run_suite(runner, runner->suite, NULL); -} - -static void -munit_print_help(int argc, char *const argv[MUNIT_ARRAY_PARAM(argc + 1)], - void *user_data, const MunitArgument arguments[]) -{ - const MunitArgument *arg; - (void)argc; - - printf("USAGE: %s [OPTIONS...] [TEST...]\n\n", argv[0]); - puts( - " --seed SEED\n" - " Value used to seed the PRNG. Must be a 32-bit integer in decimal\n" - " notation with no separators (commas, decimals, spaces, etc.), or\n" - " hexidecimal prefixed by \"0x\".\n" - " --iterations N\n" - " Run each test N times. 0 means the default number.\n" - " --param name value\n" - " A parameter key/value pair which will be passed to any test with\n" - " takes a parameter of that name. If not provided, the test will be\n" - " run once for each possible parameter value.\n" - " --list Write a list of all available tests.\n" - " --list-params\n" - " Write a list of all available tests and their possible parameters.\n" - " --single Run each parameterized test in a single configuration instead of\n" - " every possible combination\n" - " --log-visible debug|info|warning|error\n" - " --log-fatal debug|info|warning|error\n" - " Set the level at which messages of different severities are visible,\n" - " or cause the test to terminate.\n" -#if !defined(MUNIT_NO_FORK) - " --no-fork Do not execute tests in a child process. If this option is supplied\n" - " and a test crashes (including by failing an assertion), no further\n" - " tests will be performed.\n" -#endif - " --fatal-failures\n" - " Stop executing tests as soon as a failure is found.\n" - " --show-stderr\n" - " Show data written to stderr by the tests, even if the test succeeds.\n" - " --color auto|always|never\n" - " Colorize (or don't) the output.\n" - /* 12345678901234567890123456789012345678901234567890123456789012345678901234567890 - */ - " --help Print this help message and exit.\n"); -#if defined(MUNIT_NL_LANGINFO) - setlocale(LC_ALL, ""); - fputs((strcasecmp("UTF-8", nl_langinfo(CODESET)) == 0) ? "µnit" : "munit", - stdout); -#else - puts("munit"); -#endif - printf(" %d.%d.%d\n" - "Full documentation at: https://nemequ.github.io/munit/\n", - (MUNIT_CURRENT_VERSION >> 16) & 0xff, (MUNIT_CURRENT_VERSION >> 8) & 0xff, - (MUNIT_CURRENT_VERSION >> 0) & 0xff); - for (arg = arguments; arg != NULL && arg->name != NULL; arg++) - arg->write_help(arg, user_data); -} - -static const MunitArgument * -munit_arguments_find(const MunitArgument arguments[], const char *name) -{ - const MunitArgument *arg; - - for (arg = arguments; arg != NULL && arg->name != NULL; arg++) - if (strcmp(arg->name, name) == 0) - return arg; - - return NULL; -} - -static void -munit_suite_list_tests(const MunitSuite *suite, munit_bool show_params, - const char *prefix) -{ - size_t pre_l; - char *pre = munit_maybe_concat(&pre_l, (char *)prefix, (char *)suite->prefix); - const MunitTest *test; - const MunitParameterEnum *params; - munit_bool first; - char **val; - const MunitSuite *child_suite; - - for (test = suite->tests; test != NULL && test->name != NULL; test++) { - if (pre != NULL) - fputs(pre, stdout); - puts(test->name); - - if (show_params) { - for (params = test->parameters; params != NULL && params->name != NULL; - params++) { - fprintf(stdout, " - %s: ", params->name); - if (params->values == NULL) { - puts("Any"); - } else { - first = 1; - for (val = params->values; *val != NULL; val++) { - if (!first) { - fputs(", ", stdout); - } else { - first = 0; - } - fputs(*val, stdout); - } - putc('\n', stdout); - } - } - } - } - - for (child_suite = suite->suites; - child_suite != NULL && child_suite->prefix != NULL; child_suite++) { - munit_suite_list_tests(child_suite, show_params, pre); - } - - munit_maybe_free_concat(pre, prefix, suite->prefix); -} - -static munit_bool -munit_stream_supports_ansi(FILE *stream) -{ -#if !defined(_WIN32) - return isatty(fileno(stream)); -#else - -#if !defined(__MINGW32__) - size_t ansicon_size = 0; -#endif - - if (isatty(fileno(stream))) { -#if !defined(__MINGW32__) - getenv_s(&ansicon_size, NULL, 0, "ANSICON"); - return ansicon_size != 0; -#else - return getenv("ANSICON") != NULL; -#endif - } - return 0; -#endif -} - -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 result = EXIT_FAILURE; - MunitTestRunner runner; - size_t parameters_size = 0; - size_t tests_size = 0; - int arg; - - char *envptr; - unsigned long ts; - char *endptr; - unsigned long long iterations; - MunitLogLevel level; - const MunitArgument *argument; - const char **runner_tests; - unsigned int tests_run; - unsigned int tests_total; - - runner.prefix = NULL; - runner.suite = NULL; - runner.tests = NULL; - runner.seed = 0; - runner.iterations = 0; - runner.parameters = NULL; - runner.single_parameter_mode = 0; - runner.user_data = NULL; - - runner.report.successful = 0; - runner.report.skipped = 0; - runner.report.failed = 0; - runner.report.errored = 0; -#if defined(MUNIT_ENABLE_TIMING) - runner.report.cpu_clock = 0; - runner.report.wall_clock = 0; -#endif - - runner.colorize = 0; -#if !defined(_WIN32) - runner.fork = 1; -#else - runner.fork = 0; -#endif - runner.show_stderr = 0; - runner.fatal_failures = 0; - runner.suite = suite; - runner.user_data = user_data; - runner.seed = munit_rand_generate_seed(); - runner.colorize = munit_stream_supports_ansi(MUNIT_OUTPUT_FILE); - - for (arg = 1; arg < argc; arg++) { - if (strncmp("--", argv[arg], 2) == 0) { - if (strcmp("seed", argv[arg] + 2) == 0) { - if (arg + 1 >= argc) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "%s requires an argument", argv[arg]); - goto cleanup; - } - - envptr = argv[arg + 1]; - ts = strtoul(argv[arg + 1], &envptr, 0); - if (*envptr != '\0' || ts > (~((munit_uint32_t)0U))) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "invalid value ('%s') passed to %s", argv[arg + 1], argv[arg]); - goto cleanup; - } - runner.seed = (munit_uint32_t)ts; - - arg++; - } else if (strcmp("iterations", argv[arg] + 2) == 0) { - if (arg + 1 >= argc) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "%s requires an argument", argv[arg]); - goto cleanup; - } - - endptr = argv[arg + 1]; - iterations = strtoul(argv[arg + 1], &endptr, 0); - if (*endptr != '\0' || iterations > UINT_MAX) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "invalid value ('%s') passed to %s", argv[arg + 1], argv[arg]); - goto cleanup; - } - - runner.iterations = (unsigned int)iterations; - - arg++; - } else if (strcmp("param", argv[arg] + 2) == 0) { - if (arg + 2 >= argc) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "%s requires two arguments", argv[arg]); - goto cleanup; - } - - runner.parameters = realloc(runner.parameters, - sizeof(MunitParameter) * (parameters_size + 2)); - if (runner.parameters == NULL) { - munit_log_internal(MUNIT_LOG_ERROR, stderr, - "failed to allocate memory"); - goto cleanup; - } - runner.parameters[parameters_size].name = (char *)argv[arg + 1]; - runner.parameters[parameters_size].value = (char *)argv[arg + 2]; - parameters_size++; - runner.parameters[parameters_size].name = NULL; - runner.parameters[parameters_size].value = NULL; - arg += 2; - } else if (strcmp("color", argv[arg] + 2) == 0) { - if (arg + 1 >= argc) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "%s requires an argument", argv[arg]); - goto cleanup; - } - - if (strcmp(argv[arg + 1], "always") == 0) - runner.colorize = 1; - else if (strcmp(argv[arg + 1], "never") == 0) - runner.colorize = 0; - else if (strcmp(argv[arg + 1], "auto") == 0) - runner.colorize = munit_stream_supports_ansi(MUNIT_OUTPUT_FILE); - else { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "invalid value ('%s') passed to %s", argv[arg + 1], argv[arg]); - goto cleanup; - } - - arg++; - } else if (strcmp("help", argv[arg] + 2) == 0) { - munit_print_help(argc, argv, user_data, arguments); - result = EXIT_SUCCESS; - goto cleanup; - } else if (strcmp("single", argv[arg] + 2) == 0) { - runner.single_parameter_mode = 1; - } else if (strcmp("show-stderr", argv[arg] + 2) == 0) { - runner.show_stderr = 1; -#if !defined(_WIN32) - } else if (strcmp("no-fork", argv[arg] + 2) == 0) { - runner.fork = 0; -#endif - } else if (strcmp("fatal-failures", argv[arg] + 2) == 0) { - runner.fatal_failures = 1; - } else if (strcmp("log-visible", argv[arg] + 2) == 0 || - strcmp("log-fatal", argv[arg] + 2) == 0) { - if (arg + 1 >= argc) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "%s requires an argument", argv[arg]); - goto cleanup; - } - - if (strcmp(argv[arg + 1], "debug") == 0) - level = MUNIT_LOG_DEBUG; - else if (strcmp(argv[arg + 1], "info") == 0) - level = MUNIT_LOG_INFO; - else if (strcmp(argv[arg + 1], "warning") == 0) - level = MUNIT_LOG_WARNING; - else if (strcmp(argv[arg + 1], "error") == 0) - level = MUNIT_LOG_ERROR; - else { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "invalid value ('%s') passed to %s", argv[arg + 1], argv[arg]); - goto cleanup; - } - - if (strcmp("log-visible", argv[arg] + 2) == 0) - munit_log_level_visible = level; - else - munit_log_level_fatal = level; - - arg++; - } else if (strcmp("list", argv[arg] + 2) == 0) { - munit_suite_list_tests(suite, 0, NULL); - result = EXIT_SUCCESS; - goto cleanup; - } else if (strcmp("list-params", argv[arg] + 2) == 0) { - munit_suite_list_tests(suite, 1, NULL); - result = EXIT_SUCCESS; - goto cleanup; - } else { - argument = munit_arguments_find(arguments, argv[arg] + 2); - if (argument == NULL) { - munit_logf_internal(MUNIT_LOG_ERROR, stderr, - "unknown argument ('%s')", argv[arg]); - goto cleanup; - } - - if (!argument->parse_argument(suite, user_data, &arg, argc, argv)) - goto cleanup; - } - } else { - runner_tests = realloc((void *)runner.tests, - sizeof(char *) * (tests_size + 2)); - if (runner_tests == NULL) { - munit_log_internal(MUNIT_LOG_ERROR, stderr, - "failed to allocate memory"); - goto cleanup; - } - runner.tests = runner_tests; - runner.tests[tests_size++] = argv[arg]; - runner.tests[tests_size] = NULL; - } - } - - fflush(stderr); - fprintf(MUNIT_OUTPUT_FILE, - "Running test suite with seed 0x%08" PRIx32 "...\n", runner.seed); - - munit_test_runner_run(&runner); - - tests_run = runner.report.successful + runner.report.failed + - runner.report.errored; - tests_total = tests_run + runner.report.skipped; - if (tests_run == 0) { - fprintf(stderr, "No tests run, %d (100%%) skipped.\n", - runner.report.skipped); - } else { - fprintf(MUNIT_OUTPUT_FILE, - "%d of %d (%0.0f%%) tests successful, %d (%0.0f%%) test skipped.\n", - runner.report.successful, tests_run, - (((double)runner.report.successful) / ((double)tests_run)) * 100.0, - runner.report.skipped, - (((double)runner.report.skipped) / ((double)tests_total)) * 100.0); - } - - if (runner.report.failed == 0 && runner.report.errored == 0) { - result = EXIT_SUCCESS; - } - -cleanup: - free(runner.parameters); - free((void *)runner.tests); - - return result; -} - -int -munit_suite_main(const MunitSuite *suite, void *user_data, int argc, - char *const argv[MUNIT_ARRAY_PARAM(argc + 1)]) -{ - return munit_suite_main_custom(suite, user_data, argc, argv, NULL); -} diff --git a/tests/munit.h b/tests/munit.h deleted file mode 100644 index 28fbf8b..0000000 --- a/tests/munit.h +++ /dev/null @@ -1,527 +0,0 @@ -/* µnit Testing Framework - * Copyright (c) 2013-2017 Evan Nemerson - * - * 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. - */ - -#if !defined(MUNIT_H) -#define MUNIT_H - -#include -#include - -#define MUNIT_VERSION(major, minor, revision) \ - (((major) << 16) | ((minor) << 8) | (revision)) - -#define MUNIT_CURRENT_VERSION MUNIT_VERSION(0, 4, 1) - -#if defined(_MSC_VER) && (_MSC_VER < 1600) -#define munit_int8_t __int8 -#define munit_uint8_t unsigned __int8 -#define munit_int16_t __int16 -#define munit_uint16_t unsigned __int16 -#define munit_int32_t __int32 -#define munit_uint32_t unsigned __int32 -#define munit_int64_t __int64 -#define munit_uint64_t unsigned __int64 -#else -#include -#define munit_int8_t int8_t -#define munit_uint8_t uint8_t -#define munit_int16_t int16_t -#define munit_uint16_t uint16_t -#define munit_int32_t int32_t -#define munit_uint32_t uint32_t -#define munit_int64_t int64_t -#define munit_uint64_t uint64_t -#endif - -#if defined(_MSC_VER) && (_MSC_VER < 1800) -#if !defined(PRIi8) -#define PRIi8 "i" -#endif -#if !defined(PRIi16) -#define PRIi16 "i" -#endif -#if !defined(PRIi32) -#define PRIi32 "i" -#endif -#if !defined(PRIi64) -#define PRIi64 "I64i" -#endif -#if !defined(PRId8) -#define PRId8 "d" -#endif -#if !defined(PRId16) -#define PRId16 "d" -#endif -#if !defined(PRId32) -#define PRId32 "d" -#endif -#if !defined(PRId64) -#define PRId64 "I64d" -#endif -#if !defined(PRIx8) -#define PRIx8 "x" -#endif -#if !defined(PRIx16) -#define PRIx16 "x" -#endif -#if !defined(PRIx32) -#define PRIx32 "x" -#endif -#if !defined(PRIx64) -#define PRIx64 "I64x" -#endif -#if !defined(PRIu8) -#define PRIu8 "u" -#endif -#if !defined(PRIu16) -#define PRIu16 "u" -#endif -#if !defined(PRIu32) -#define PRIu32 "u" -#endif -#if !defined(PRIu64) -#define PRIu64 "I64u" -#endif -#else -#include -#endif - -#if !defined(munit_bool) -#if defined(bool) -#define munit_bool bool -#elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) -#define munit_bool _Bool -#else -#define munit_bool int -#endif -#endif - -#if defined(__cplusplus) -extern "C" { -#endif - -#if defined(__GNUC__) -#define MUNIT_LIKELY(expr) (__builtin_expect((expr), 1)) -#define MUNIT_UNLIKELY(expr) (__builtin_expect((expr), 0)) -#define MUNIT_UNUSED __attribute__((__unused__)) -#else -#define MUNIT_LIKELY(expr) (expr) -#define MUNIT_UNLIKELY(expr) (expr) -#define MUNIT_UNUSED -#endif - -#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ - !defined(__PGI) -#define MUNIT_ARRAY_PARAM(name) name -#else -#define MUNIT_ARRAY_PARAM(name) -#endif - -#if !defined(_WIN32) -#define MUNIT_SIZE_MODIFIER "z" -#define MUNIT_CHAR_MODIFIER "hh" -#define MUNIT_SHORT_MODIFIER "h" -#else -#if defined(_M_X64) || defined(__amd64__) -#define MUNIT_SIZE_MODIFIER "I64" -#else -#define MUNIT_SIZE_MODIFIER "" -#endif -#define MUNIT_CHAR_MODIFIER "" -#define MUNIT_SHORT_MODIFIER "" -#endif - -#if defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L -#define MUNIT_NO_RETURN _Noreturn -#elif defined(__GNUC__) -#define MUNIT_NO_RETURN __attribute__((__noreturn__)) -#elif defined(_MSC_VER) -#define MUNIT_NO_RETURN __declspec(noreturn) -#else -#define MUNIT_NO_RETURN -#endif - -#if defined(_MSC_VER) && (_MSC_VER >= 1500) -#define MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - __pragma(warning(push)) __pragma(warning(disable : 4127)) -#define MUNIT_POP_DISABLE_MSVC_C4127_ __pragma(warning(pop)) -#else -#define MUNIT_PUSH_DISABLE_MSVC_C4127_ -#define MUNIT_POP_DISABLE_MSVC_C4127_ -#endif - -typedef enum { - MUNIT_LOG_DEBUG, - MUNIT_LOG_INFO, - MUNIT_LOG_WARNING, - MUNIT_LOG_ERROR -} MunitLogLevel; - -#if defined(__GNUC__) && !defined(__MINGW32__) -#define MUNIT_PRINTF(string_index, first_to_check) \ - __attribute__((format(printf, string_index, first_to_check))) -#else -#define MUNIT_PRINTF(string_index, first_to_check) -#endif - -MUNIT_PRINTF(4, 5) -void munit_logf_ex(MunitLogLevel level, const char *filename, int line, - const char *format, ...); - -#define munit_logf(level, format, ...) \ - munit_logf_ex(level, __FILE__, __LINE__, format, __VA_ARGS__) - -#define munit_log(level, msg) munit_logf(level, "%s", msg) - -MUNIT_NO_RETURN -MUNIT_PRINTF(3, 4) -void munit_errorf_ex(const char *filename, int line, const char *format, ...); - -#define munit_errorf(format, ...) \ - munit_errorf_ex(__FILE__, __LINE__, format, __VA_ARGS__) - -#define munit_error(msg) munit_errorf("%s", msg) - -#define munit_assert(expr) \ - do { \ - if (!MUNIT_LIKELY(expr)) { \ - munit_error("assertion failed: " #expr); \ - } \ - MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ - -#define munit_assert_true(expr) \ - do { \ - if (!MUNIT_LIKELY(expr)) { \ - munit_error("assertion failed: " #expr " is not true"); \ - } \ - MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ - -#define munit_assert_false(expr) \ - do { \ - if (!MUNIT_LIKELY(!(expr))) { \ - munit_error("assertion failed: " #expr " is not false"); \ - } \ - MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ - -#define munit_assert_type_full(prefix, suffix, T, fmt, a, op, b) \ - do { \ - T munit_tmp_a_ = (a); \ - T munit_tmp_b_ = (b); \ - if (!(munit_tmp_a_ op munit_tmp_b_)) { \ - munit_errorf("assertion failed: %s %s %s (" prefix "%" fmt suffix \ - " %s " prefix "%" fmt suffix ")", \ - #a, #op, #b, munit_tmp_a_, #op, munit_tmp_b_); \ - } \ - MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ - -#define munit_assert_type(T, fmt, a, op, b) \ - munit_assert_type_full("", "", T, fmt, a, op, b) - -#define munit_assert_char(a, op, b) \ - munit_assert_type_full("'\\x", "'", char, "02" MUNIT_CHAR_MODIFIER "x", a, \ - op, b) -#define munit_assert_uchar(a, op, b) \ - munit_assert_type_full("'\\x", "'", unsigned char, \ - "02" MUNIT_CHAR_MODIFIER "x", a, op, b) -#define munit_assert_short(a, op, b) \ - munit_assert_type(short, MUNIT_SHORT_MODIFIER "d", a, op, b) -#define munit_assert_ushort(a, op, b) \ - munit_assert_type(unsigned short, MUNIT_SHORT_MODIFIER "u", a, op, b) -#define munit_assert_int(a, op, b) munit_assert_type(int, "d", a, op, b) -#define munit_assert_uint(a, op, b) \ - munit_assert_type(unsigned int, "u", a, op, b) -#define munit_assert_long(a, op, b) munit_assert_type(long int, "ld", a, op, b) -#define munit_assert_ulong(a, op, b) \ - munit_assert_type(unsigned long int, "lu", a, op, b) -#define munit_assert_llong(a, op, b) \ - munit_assert_type(long long int, "lld", a, op, b) -#define munit_assert_ullong(a, op, b) \ - munit_assert_type(unsigned long long int, "llu", a, op, b) - -#define munit_assert_size(a, op, b) \ - munit_assert_type(size_t, MUNIT_SIZE_MODIFIER "u", a, op, b) - -#define munit_assert_float(a, op, b) munit_assert_type(float, "f", a, op, b) -#define munit_assert_double(a, op, b) munit_assert_type(double, "g", a, op, b) -#define munit_assert_ptr(a, op, b) \ - munit_assert_type(const void *, "p", a, op, b) - -#define munit_assert_int8(a, op, b) \ - munit_assert_type(munit_int8_t, PRIi8, a, op, b) -#define munit_assert_uint8(a, op, b) \ - munit_assert_type(munit_uint8_t, PRIu8, a, op, b) -#define munit_assert_int16(a, op, b) \ - munit_assert_type(munit_int16_t, PRIi16, a, op, b) -#define munit_assert_uint16(a, op, b) \ - munit_assert_type(munit_uint16_t, PRIu16, a, op, b) -#define munit_assert_int32(a, op, b) \ - munit_assert_type(munit_int32_t, PRIi32, a, op, b) -#define munit_assert_uint32(a, op, b) \ - munit_assert_type(munit_uint32_t, PRIu32, a, op, b) -#define munit_assert_int64(a, op, b) \ - munit_assert_type(munit_int64_t, PRIi64, a, op, b) -#define munit_assert_uint64(a, op, b) \ - munit_assert_type(munit_uint64_t, PRIu64, a, op, b) - -#define munit_assert_double_equal(a, b, precision) \ - do { \ - const double munit_tmp_a_ = (a); \ - const double munit_tmp_b_ = (b); \ - const double munit_tmp_diff_ = ((munit_tmp_a_ - munit_tmp_b_) < 0) ? \ - -(munit_tmp_a_ - munit_tmp_b_) : \ - (munit_tmp_a_ - munit_tmp_b_); \ - if (MUNIT_UNLIKELY(munit_tmp_diff_ > 1e-##precision)) { \ - munit_errorf("assertion failed: %s == %s (%0." #precision \ - "g == %0." #precision "g)", \ - #a, #b, munit_tmp_a_, munit_tmp_b_); \ - } \ - MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ - -#include -#define munit_assert_string_equal(a, b) \ - do { \ - const char *munit_tmp_a_ = a; \ - const char *munit_tmp_b_ = b; \ - if (MUNIT_UNLIKELY(strcmp(munit_tmp_a_, munit_tmp_b_) != 0)) { \ - munit_errorf("assertion failed: string %s == %s (\"%s\" == \"%s\")", #a, \ - #b, munit_tmp_a_, munit_tmp_b_); \ - } \ - MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ - -#define munit_assert_string_not_equal(a, b) \ - do { \ - const char *munit_tmp_a_ = a; \ - const char *munit_tmp_b_ = b; \ - if (MUNIT_UNLIKELY(strcmp(munit_tmp_a_, munit_tmp_b_) == 0)) { \ - munit_errorf("assertion failed: string %s != %s (\"%s\" == \"%s\")", #a, \ - #b, munit_tmp_a_, munit_tmp_b_); \ - } \ - MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ - -#define munit_assert_memory_equal(size, a, b) \ - do { \ - const unsigned char *munit_tmp_a_ = (const unsigned char *)(a); \ - const unsigned char *munit_tmp_b_ = (const unsigned char *)(b); \ - const size_t munit_tmp_size_ = (size); \ - if (MUNIT_UNLIKELY(memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) != \ - 0) { \ - size_t munit_tmp_pos_; \ - for (munit_tmp_pos_ = 0; munit_tmp_pos_ < munit_tmp_size_; \ - munit_tmp_pos_++) { \ - if (munit_tmp_a_[munit_tmp_pos_] != munit_tmp_b_[munit_tmp_pos_]) { \ - munit_errorf( \ - "assertion failed: memory %s == %s, at offset %" MUNIT_SIZE_MODIFIER \ - "u", \ - #a, #b, munit_tmp_pos_); \ - break; \ - } \ - } \ - } \ - MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ - -#define munit_assert_memory_not_equal(size, a, b) \ - do { \ - const unsigned char *munit_tmp_a_ = (const unsigned char *)(a); \ - const unsigned char *munit_tmp_b_ = (const unsigned char *)(b); \ - const size_t munit_tmp_size_ = (size); \ - if (MUNIT_UNLIKELY(memcmp(munit_tmp_a_, munit_tmp_b_, munit_tmp_size_)) == \ - 0) { \ - munit_errorf("assertion failed: memory %s != %s (%zu bytes)", #a, #b, \ - munit_tmp_size_); \ - } \ - MUNIT_PUSH_DISABLE_MSVC_C4127_ \ - } while (0) MUNIT_POP_DISABLE_MSVC_C4127_ - -#define munit_assert_ptr_equal(a, b) munit_assert_ptr(a, ==, b) -#define munit_assert_ptr_not_equal(a, b) munit_assert_ptr(a, !=, b) -#define munit_assert_null(ptr) munit_assert_ptr(ptr, ==, NULL) -#define munit_assert_not_null(ptr) munit_assert_ptr(ptr, !=, NULL) -#define munit_assert_ptr_null(ptr) munit_assert_ptr(ptr, ==, NULL) -#define munit_assert_ptr_not_null(ptr) munit_assert_ptr(ptr, !=, NULL) - -/*** Memory allocation ***/ - -void *munit_malloc_ex(const char *filename, int line, size_t size); - -#define munit_malloc(size) munit_malloc_ex(__FILE__, __LINE__, (size)) - -#define munit_new(type) ((type *)munit_malloc(sizeof(type))) - -#define munit_calloc(nmemb, size) munit_malloc((nmemb) * (size)) - -#define munit_newa(type, nmemb) ((type *)munit_calloc((nmemb), sizeof(type))) - -/*** Random number generation ***/ - -void munit_rand_seed(munit_uint32_t seed); -munit_uint32_t munit_rand_uint32(void); -int munit_rand_int_range(int min, int max); -double munit_rand_double(void); -void munit_rand_memory(size_t size, - munit_uint8_t buffer[MUNIT_ARRAY_PARAM(size)]); - -/*** Tests and Suites ***/ - -typedef enum { - /* Test successful */ - MUNIT_OK, - /* Test failed */ - MUNIT_FAIL, - /* Test was skipped */ - MUNIT_SKIP, - /* Test failed due to circumstances not intended to be tested - * (things like network errors, invalid parameter value, failure to - * allocate memory in the test harness, etc.). */ - MUNIT_ERROR -} MunitResult; - -typedef struct { - char *name; - char **values; -} MunitParameterEnum; - -typedef struct { - char *name; - char *value; -} MunitParameter; - -const char *munit_parameters_get(const MunitParameter params[], - const char *key); - -typedef enum { - MUNIT_TEST_OPTION_NONE = 0, - MUNIT_TEST_OPTION_SINGLE_ITERATION = 1 << 0, - MUNIT_TEST_OPTION_TODO = 1 << 1 -} MunitTestOptions; - -typedef MunitResult ( - *MunitTestFunc)(const MunitParameter params[], void *user_data_or_fixture); -typedef void *(*MunitTestSetup)(const MunitParameter params[], void *user_data); -typedef void (*MunitTestTearDown)(void *fixture); - -typedef struct { - char *name; - MunitTestFunc test; - MunitTestSetup setup; - MunitTestTearDown tear_down; - MunitTestOptions options; - MunitParameterEnum *parameters; -} MunitTest; - -typedef enum { MUNIT_SUITE_OPTION_NONE = 0 } MunitSuiteOptions; - -typedef struct MunitSuite_ MunitSuite; - -struct MunitSuite_ { - char *prefix; - MunitTest *tests; - MunitSuite *suites; - unsigned int iterations; - MunitSuiteOptions options; -}; - -int munit_suite_main(const MunitSuite *suite, void *user_data, int argc, - char *const argv[MUNIT_ARRAY_PARAM(argc + 1)]); - -/* Note: I'm not very happy with this API; it's likely to change if I - * figure out something better. Suggestions welcome. */ - -typedef struct MunitArgument_ MunitArgument; - -struct MunitArgument_ { - char *name; - munit_bool (*parse_argument)(const MunitSuite *suite, void *user_data, - int *arg, int argc, char *const argv[MUNIT_ARRAY_PARAM(argc + 1)]); - void (*write_help)(const MunitArgument *argument, void *user_data); -}; - -int munit_suite_main_custom(const MunitSuite *suite, void *user_data, int argc, - char *const argv[MUNIT_ARRAY_PARAM(argc + 1)], - const MunitArgument arguments[]); - -#if defined(MUNIT_ENABLE_ASSERT_ALIASES) - -#define assert_true(expr) munit_assert_true(expr) -#define assert_false(expr) munit_assert_false(expr) -#define assert_char(a, op, b) munit_assert_char(a, op, b) -#define assert_uchar(a, op, b) munit_assert_uchar(a, op, b) -#define assert_short(a, op, b) munit_assert_short(a, op, b) -#define assert_ushort(a, op, b) munit_assert_ushort(a, op, b) -#define assert_int(a, op, b) munit_assert_int(a, op, b) -#define assert_uint(a, op, b) munit_assert_uint(a, op, b) -#define assert_long(a, op, b) munit_assert_long(a, op, b) -#define assert_ulong(a, op, b) munit_assert_ulong(a, op, b) -#define assert_llong(a, op, b) munit_assert_llong(a, op, b) -#define assert_ullong(a, op, b) munit_assert_ullong(a, op, b) -#define assert_size(a, op, b) munit_assert_size(a, op, b) -#define assert_float(a, op, b) munit_assert_float(a, op, b) -#define assert_double(a, op, b) munit_assert_double(a, op, b) -#define assert_ptr(a, op, b) munit_assert_ptr(a, op, b) - -#define assert_int8(a, op, b) munit_assert_int8(a, op, b) -#define assert_uint8(a, op, b) munit_assert_uint8(a, op, b) -#define assert_int16(a, op, b) munit_assert_int16(a, op, b) -#define assert_uint16(a, op, b) munit_assert_uint16(a, op, b) -#define assert_int32(a, op, b) munit_assert_int32(a, op, b) -#define assert_uint32(a, op, b) munit_assert_uint32(a, op, b) -#define assert_int64(a, op, b) munit_assert_int64(a, op, b) -#define assert_uint64(a, op, b) munit_assert_uint64(a, op, b) - -#define assert_double_equal(a, b, precision) \ - munit_assert_double_equal(a, b, precision) -#define assert_string_equal(a, b) munit_assert_string_equal(a, b) -#define assert_string_not_equal(a, b) munit_assert_string_not_equal(a, b) -#define assert_memory_equal(size, a, b) munit_assert_memory_equal(size, a, b) -#define assert_memory_not_equal(size, a, b) \ - munit_assert_memory_not_equal(size, a, b) -#define assert_ptr_equal(a, b) munit_assert_ptr_equal(a, b) -#define assert_ptr_not_equal(a, b) munit_assert_ptr_not_equal(a, b) -#define assert_ptr_null(ptr) munit_assert_null_equal(ptr) -#define assert_ptr_not_null(ptr) munit_assert_not_null(ptr) - -#define assert_null(ptr) munit_assert_null(ptr) -#define assert_not_null(ptr) munit_assert_not_null(ptr) - -#endif /* defined(MUNIT_ENABLE_ASSERT_ALIASES) */ - -#if defined(__cplusplus) -} -#endif - -#endif /* !defined(MUNIT_H) */ - -#if defined(MUNIT_ENABLE_ASSERT_ALIASES) -#if defined(assert) -#undef assert -#endif -#define assert(expr) munit_assert(expr) -#endif diff --git a/tests/test.c b/tests/test.c deleted file mode 100644 index eff568e..0000000 --- a/tests/test.c +++ /dev/null @@ -1,449 +0,0 @@ -/* - * skiplist is MIT-licensed, but for this file: - * - * To the extent possible under law, the author(s) of this file have - * waived all copyright and related or neighboring rights to this - * work. See for - * details. - */ - -#define MUNIT_NO_FORK (1) -#define MUNIT_ENABLE_ASSERT_ALIASES (1) - -#include -#include - -#define __SL_DEBUG 0 -#if __SL_DEBUG > 0 -#include - -#include -#include -#include -#include -#endif -#if __SL_DEBUG >= 1 -#define __SLD_ASSERT(cond) assert(cond) -#define __SLD_(b) b -#elif __SL_DEBUG >= 2 -#define __SLD_P(...) printf(__VA_ARGS__) -#elif __SL_DEBUG >= 3 -typedef struct dbg_node { - sl_node snode; - int value; -} dbg_node_t; - -inline void -__sld_rt_ins(int error_code, sl_node *node, int top_layer, int cur_layer) -{ - dbg_node_t *ddd = sl_get_entry(node, dbg_node_t, snode); - printf("[INS] retry (code %d) " - "%p (top %d, cur %d) %d\n", - error_code, node, top_layer, cur_layer, ddd->value); -} - -inline void -__sld_nc_ins(sl_node *node, sl_node *next_node, int top_layer, int cur_layer) -{ - dbg_node_t *ddd = sl_get_entry(node, dbg_node_t, snode); - dbg_node_t *ddd_next = sl_get_entry(next_node, dbg_node_t, snode); - - printf("[INS] next node changed, " - "%p %p (top %d, cur %d) %d %d\n", - node, next_node, top_layer, cur_layer, ddd->value, ddd_next->value); -} - -inline void -__sld_rt_rmv(int error_code, sl_node *node, int top_layer, int cur_layer) -{ - dbg_node_t *ddd = sl_get_entry(node, dbg_node_t, snode); - printf("[RMV] retry (code %d) " - "%p (top %d, cur %d) %d\n", - error_code, node, top_layer, cur_layer, ddd->value); -} - -inline void -__sld_nc_rmv(sl_node *node, sl_node *next_node, int top_layer, int cur_layer) -{ - dbg_node_t *ddd = sl_get_entry(node, dbg_node_t, snode); - dbg_node_t *ddd_next = sl_get_entry(next_node, dbg_node_t, snode); - - printf("[RMV] next node changed, " - "%p %p (top %d, cur %d) %d %d\n", - node, next_node, top_layer, cur_layer, ddd->value, ddd_next->value); -} - -inline void -__sld_bm(sl_node *node) -{ - dbg_node_t *ddd = sl_get_entry(node, dbg_node_t, snode); - printf("[RMV] node is being modified %d\n", ddd->value); -} - -#define __SLD_RT_INS(e, n, t, c) __sld_rt_ins(e, n, t, c) -#define __SLD_NC_INS(n, nn, t, c) __sld_nc_ins(n, nn, t, c) -#define __SLD_RT_RMV(e, n, t, c) __sld_rt_rmv(e, n, t, c) -#define __SLD_NC_RMV(n, nn, t, c) __sld_nc_rmv(n, nn, t, c) -#define __SLD_BM(n) __sld_bm(n) -#endif - -#include "../include/skiplist.h" -#include "munit.h" - -#if defined(_MSC_VER) -#pragma warning(disable : 4127) -#endif - -struct user_data { - size_t n_ele; -}; - -typedef struct ex_node { - sl_node snode; - uint32_t key; - uint32_t value; -} ex_node_t; - -typedef sl_raw ex_sl_t; - -static int -uint32_key_cmp(sl_node *a, sl_node *b, void *aux) -{ - ex_node_t *aa, *bb; - (void)aux; - aa = sl_get_entry(a, ex_node_t, snode); - bb = sl_get_entry(b, ex_node_t, snode); - - if (aa->key < bb->key) - return -1; - if (aa->key > bb->key) - return 1; - return 0; -} - -static size_t -__populate_slist(ex_sl_t *slist) -{ - size_t inserted = 0; - uint32_t n, key; - ex_node_t *node; - - n = munit_rand_int_range(1024, 4196); - while (n--) { - key = munit_rand_int_range(0, (((uint32_t)0) - 1) / 10); - node = (ex_node_t *)calloc(sizeof(ex_node_t), 1); - if (node == NULL) - return MUNIT_ERROR; - sl_init_node(&node->snode); - node->key = key; - node->value = key; - if (sl_insert_nodup(slist, &node->snode) == -1) - continue; /* a random duplicate appeared */ - else - inserted++; - } - return inserted; -} - -static void * -test_api_setup(const MunitParameter params[], void *user_data) -{ - struct test_info *info = (struct test_info *)user_data; - (void)info; - (void)params; - - ex_sl_t *slist = calloc(sizeof(ex_sl_t), 1); - if (slist == NULL) - return NULL; - sl_init(slist, uint32_key_cmp); - return (void *)(uintptr_t)slist; -} - -static void -test_api_tear_down(void *fixture) -{ - ex_sl_t *slist = (ex_sl_t *)fixture; - assert_ptr_not_null(slist); - sl_node *cursor = sl_begin(slist); - while (cursor) { - assert_ptr_not_null(cursor); - ex_node_t *entry = sl_get_entry(cursor, ex_node_t, snode); - assert_ptr_not_null(entry); - assert_uint32(entry->key, ==, entry->value); - cursor = sl_next(slist, cursor); - sl_erase_node(slist, &entry->snode); - sl_release_node(&entry->snode); - sl_wait_for_free(&entry->snode); - sl_free_node(&entry->snode); - free(entry); - } - sl_free(slist); - free(fixture); -} - -static void * -test_api_insert_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_insert_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_insert(const MunitParameter params[], void *data) -{ - int ret; - size_t inserted = 0; - uint32_t n, key; - sl_raw *slist = (sl_raw *)data; - ex_node_t *node; - (void)params; - - assert_ptr_not_null(slist); - n = munit_rand_int_range(4096, 8192); - while (n--) { - key = munit_rand_int_range(0, ((uint32_t)0 - 1) / 10); - node = (ex_node_t *)calloc(sizeof(ex_node_t), 1); - if (node == NULL) - return MUNIT_ERROR; - sl_init_node(&node->snode); - node->key = key; - node->value = key; - if ((ret = sl_insert_nodup(slist, &node->snode)) == -1) - continue; /* a random duplicate appeared */ - else { - assert_int(ret, ==, 0); - inserted++; - } - } - assert_size(inserted, ==, sl_get_size(slist)); - return MUNIT_OK; -} - -static void * -test_api_remove_setup(const MunitParameter params[], void *user_data) -{ - sl_raw *slist = (sl_raw *)test_api_setup(params, user_data); - __populate_slist(slist); - return (void *)slist; -} -static void -test_api_remove_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_remove(const MunitParameter params[], void *data) -{ - uint32_t key; - sl_raw *slist = (sl_raw *)data; - ex_node_t *node; - (void)params; - - assert_ptr_not_null(slist); - key = munit_rand_int_range((((uint32_t)0 - 1) / 10) + 1, ((uint32_t)0 - 1)); - node = (ex_node_t *)calloc(sizeof(ex_node_t), 1); - if (node == NULL) - return MUNIT_ERROR; - sl_init_node(&node->snode); - node->key = key; - node->value = key; - if (sl_insert_nodup(slist, &node->snode) == -1) - return MUNIT_ERROR; - else { - ex_node_t query; - query.key = key; - sl_node *cursor = sl_find(slist, &query.snode); - assert_ptr_not_null(cursor); - ex_node_t *entry = sl_get_entry(cursor, ex_node_t, snode); - sl_erase_node(slist, &entry->snode); - sl_release_node(&entry->snode); - sl_wait_for_free(&entry->snode); - sl_free_node(&entry->snode); - free(entry); - } - return MUNIT_OK; -} - -static void * -test_api_find_setup(const MunitParameter params[], void *user_data) -{ - sl_raw *slist = (sl_raw *)test_api_setup(params, user_data); - ex_node_t *node; - for (int i = 1; i <= 100; ++i) { - node = calloc(sizeof(ex_node_t), 1); - if (node == NULL) - return NULL; - node = (ex_node_t *)calloc(sizeof(ex_node_t), 1); - sl_init_node(&node->snode); - node->key = i; - node->value = i; - sl_insert(slist, &node->snode); - } - return (void *)slist; -} -static void -test_api_find_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_find(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - - /* find equal every value */ - assert_ptr_not_null(data); - for (int i = 1; i <= 100; i++) { - ex_node_t query; - query.key = i; - sl_node *cursor = sl_find(slist, &query.snode); - assert_ptr_not_null(cursor); - ex_node_t *entry = sl_get_entry(cursor, ex_node_t, snode); - assert_uint32(entry->key, ==, i); - } - - /* */ - return MUNIT_OK; -} - -static void * -test_api_update_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_update_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_update(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_delete_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_delete_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_delete(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_duplicates_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_duplicates_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_duplicates(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_size_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_size_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_size(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static void * -test_api_iterators_setup(const MunitParameter params[], void *user_data) -{ - return test_api_setup(params, user_data); -} -static void -test_api_iterators_tear_down(void *fixture) -{ - test_api_tear_down(fixture); -} -static MunitResult -test_api_iterators(const MunitParameter params[], void *data) -{ - sl_raw *slist = (sl_raw *)data; - (void)params; - (void)slist; - return MUNIT_OK; -} - -static MunitTest api_test_suite[] = { - { (char *)"/api/insert", test_api_insert, test_api_insert_setup, - test_api_insert_tear_down, MUNIT_TEST_OPTION_NONE, NULL }, - { (char *)"/api/remove", test_api_remove, test_api_remove_setup, - test_api_remove_tear_down, MUNIT_TEST_OPTION_NONE, NULL }, - { (char *)"/api/find", test_api_find, test_api_find_setup, - test_api_find_tear_down, MUNIT_TEST_OPTION_NONE, NULL }, - { (char *)"/api/update", test_api_update, test_api_update_setup, - test_api_update_tear_down, MUNIT_TEST_OPTION_NONE, NULL }, - { (char *)"/api/delete", test_api_delete, test_api_delete_setup, - test_api_delete_tear_down, MUNIT_TEST_OPTION_NONE, NULL }, - { (char *)"/api/duplicates", test_api_duplicates, test_api_duplicates_setup, - test_api_duplicates_tear_down, MUNIT_TEST_OPTION_NONE, NULL }, - { (char *)"/api/size", test_api_size, test_api_size_setup, - test_api_size_tear_down, MUNIT_TEST_OPTION_NONE, NULL }, - { (char *)"/api/iterators", test_api_iterators, test_api_iterators_setup, - test_api_iterators_tear_down, MUNIT_TEST_OPTION_NONE, NULL }, - { NULL, NULL, NULL, NULL, MUNIT_TEST_OPTION_NONE, NULL } -}; - -static MunitTest mt_tests[] = { { NULL, NULL, NULL, NULL, - MUNIT_TEST_OPTION_NONE, NULL } }; - -static MunitTest scale_tests[] = { { NULL, NULL, NULL, NULL, - MUNIT_TEST_OPTION_NONE, NULL } }; - -static MunitSuite other_test_suite[] = { { "/mt", mt_tests, NULL, 1, - MUNIT_SUITE_OPTION_NONE }, - { "/scale", scale_tests, NULL, 1, MUNIT_SUITE_OPTION_NONE }, - { NULL, NULL, NULL, 0, MUNIT_SUITE_OPTION_NONE } }; - -static const MunitSuite main_test_suite = { (char *)"/api", api_test_suite, - other_test_suite, 1, MUNIT_SUITE_OPTION_NONE }; - -int -main(int argc, char *argv[MUNIT_ARRAY_PARAM(argc + 1)]) -{ - struct user_data info; - return munit_suite_main(&main_test_suite, (void *)&info, argc, argv); -} - -/* ARGS: --no-fork --seed 8675309 */ From 9d3f87837bf98e59e2ccf84beaef6eeb4c7a3dc4 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Fri, 5 Apr 2024 10:34:59 -0400 Subject: [PATCH 2/3] add some more examples --- .gitignore | 4 +- examples/ex_1.c | 25 +++---- examples/ex_2.c | 48 +++++++++++++ examples/ex_3.c | 172 ++++++++++++++++++++++++++++++++++++++++++++ flake.lock | 61 ++++++++++++++++ flake.nix | 71 +++++++++--------- include/sparsemap.h | 2 +- src/sparsemap.c | 26 +++---- 8 files changed, 347 insertions(+), 62 deletions(-) create mode 100644 examples/ex_2.c create mode 100644 examples/ex_3.c create mode 100644 flake.lock diff --git a/.gitignore b/.gitignore index 0244d92..eb5a7e9 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,7 @@ *.so **/*.o tests/test -examples/ex_* +examples/ex_? .cache hints.txt tmp/ @@ -13,6 +13,8 @@ git.diff .codelite/ .cmaketools.json *.tags +tags +TAGS *.dll build/ cmake-build* diff --git a/examples/ex_1.c b/examples/ex_1.c index 6b777ed..ebc8f69 100644 --- a/examples/ex_1.c +++ b/examples/ex_1.c @@ -1,20 +1,22 @@ #include -#include #include -#include #include "../include/sparsemap.h" #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wvariadic-macros" -#define __diag(...) \ - do { fprintf(stderr, "%s:%d:%s(): ",__FILE__, __LINE__, __func__);\ - fprintf(stderr, __VA_ARGS__); } while (0) +#define __diag(...) \ + do { \ + fprintf(stderr, "%s:%d:%s(): ", __FILE__, __LINE__, __func__); \ + fprintf(stderr, __VA_ARGS__); \ + } while (0) #pragma GCC diagnostic pop // NOTE: currently, this code serves as a sample and unittest. -int main() { +int +main() +{ size_t size = 4; setbuf(stderr, 0); // disable buffering __diag("Please wait a moment..."); @@ -85,11 +87,11 @@ int main() { } // open and compare - sparsemap_t *sm2 = sparsemap_open(buffer, sizeof(buffer)); + sparsemap_t _sm3, *sm3 = &_sm3; + sparsemap_open(sm3, buffer, sizeof(buffer)); for (int i = 0; i < 10000; i++) { - assert(sparsemap_is_set(sm2, i) == sparsemap_is_set(map, i)); + assert(sparsemap_is_set(sm3, i) == sparsemap_is_set(map, i)); } - free(sm2); // unset [10000..0] for (int i = 10000; i >= 0; i--) { @@ -152,8 +154,7 @@ int main() { } // split and move, aligned to MiniMap capacity - sparsemap_t _sm2; - sm2 = &_sm2; + sparsemap_t _sm2, *sm2 = &_sm2; sparsemap_init(sm2, buffer2, sizeof(buffer2), 0); sparsemap_clear(sm2); for (int i = 0; i < 2048 * 2; i++) { @@ -187,4 +188,4 @@ int main() { } fprintf(stderr, " ok\n"); - } +} diff --git a/examples/ex_2.c b/examples/ex_2.c new file mode 100644 index 0000000..a255261 --- /dev/null +++ b/examples/ex_2.c @@ -0,0 +1,48 @@ +#include +#include +#include +#include +#include +#include + +#include "../include/sparsemap.h" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wvariadic-macros" +#define __diag(...) \ + do { \ + fprintf(stderr, "%s:%d:%s(): ", __FILE__, __LINE__, __func__); \ + fprintf(stderr, __VA_ARGS__); \ + } while (0) +#pragma GCC diagnostic pop + +#define SEED + +int +main(void) +{ + int i = 0; + + // disable buffering + setbuf(stderr, 0); + + // start with a 1KiB buffer, 1024 bits + uint8_t *buf = calloc(1024, sizeof(uint8_t)); + + // create the sparse bitmap + sparsemap_t *map = sparsemap(buf, sizeof(uint8_t) * 1024, 0); + + // Set every other bit (pathologically worst case) to see what happens + // when the map is full. + for (i = 0; i < 7744; i++) { + if (i % 2) + continue; + sparsemap_set(map, i, true); + assert(sparsemap_is_set(map, i) == true); + } + // On 1024 KiB of buffer with every other bit set the map holds 7744 bits + // and then runs out of space. This next _set() call will fail/abort. + sparsemap_set(map, ++i, true); + assert(sparsemap_is_set(map, i) == true); + return 0; +} diff --git a/examples/ex_3.c b/examples/ex_3.c new file mode 100644 index 0000000..dc73b53 --- /dev/null +++ b/examples/ex_3.c @@ -0,0 +1,172 @@ +#include +#include +#include +#include +#include +#include + +#include "../include/sparsemap.h" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wvariadic-macros" +#define __diag(...) \ + do { \ + fprintf(stderr, "%s:%d:%s(): ", __FILE__, __LINE__, __func__); \ + fprintf(stderr, __VA_ARGS__); \ + } while (0) +#pragma GCC diagnostic pop + +#define SEED + +/* https://burtleburtle.net/bob/rand/smallprng.html */ +typedef struct rnd_ctx { + uint32_t a; + uint32_t b; + uint32_t c; + uint32_t d; +} rnd_ctx_t; +#define __rot(x, k) (((x) << (k)) | ((x) >> (32 - (k)))) +uint32_t +__random(rnd_ctx_t *x) +{ + uint32_t e = x->a - __rot(x->b, 27); + x->a = x->b ^ __rot(x->c, 17); + x->b = x->c + x->d; + x->c = x->d + e; + x->d = e + x->a; + return x->d; +} + +void +__random_seed(rnd_ctx_t *x, uint32_t seed) +{ + uint32_t i; + x->a = 0xf1ea5eed, x->b = x->c = x->d = seed; + for (i = 0; i < 20; ++i) { + (void)__random(x); + } +} + +void +shuffle(rnd_ctx_t *prng, int *array, size_t n) +{ + size_t i, j; + + if (n > 1) { + for (i = n - 1; i > 0; i--) { + j = (unsigned int)(__random(prng) % (i + 1)); + // XOR swap algorithm + if (i != j) { // avoid self-swap leading to zero-ing the element + array[i] = array[i] ^ array[j]; + array[j] = array[i] ^ array[j]; + array[i] = array[i] ^ array[j]; + } + } + } +} + +int +main(void) +{ + int i = 0; + rnd_ctx_t prng; + int array[1024] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, + 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, + 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, + 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, + 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, + 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, + 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, + 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, + 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, + 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, + 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, + 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, + 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, + 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, + 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, + 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, + 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, + 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, + 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, + 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, + 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, + 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, + 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, + 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, + 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, + 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, + 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, + 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, + 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, + 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, + 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, + 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, + 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, + 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, + 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, + 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, + 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, + 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, + 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, + 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, + 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, + 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, + 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, + 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, + 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, + 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, + 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, + 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, + 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, + 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, + 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, + 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, + 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, + 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, + 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, + 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, + 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, + 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, + 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, + 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, + 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, + 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, + 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, + 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, + 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, + 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, + 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, + 1020, 1021, 1022, 1023, 1024 }; + + // disable buffering + setbuf(stderr, 0); + + // seed the PRNG +#ifdef SEED + __random_seed(&prng, 8675309); +#else + __random_seed(&prng, (unsigned int)time(NULL) ^ getpid()); +#endif + + // randomize setting the bits on + shuffle(&prng, array, 1024); + + // start with a 1KiB buffer, 1024 bits + uint8_t *buf = calloc(1024, sizeof(uint8_t)); + + // create the sparse bitmap + sparsemap_t *map = sparsemap(buf, sizeof(uint8_t) * 1024, 0); + + // set all the bits on in a random order + for (i = 0; i < 1024; i++) { + __diag("set %d\n", array[i]); + sparsemap_set(map, array[i], true); + assert(sparsemap_is_set(map, array[i]) == true); + } + + sparsemap_set(map, 1025, true); + assert(sparsemap_is_set(map, 1025) == true); + + return 0; +} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..c8aedb6 --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1712192574, + "narHash": "sha256-LbbVOliJKTF4Zl2b9salumvdMXuQBr2kuKP5+ZwbYq4=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f480f9d09e4b4cf87ee6151eba068197125714de", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix index 2d8d35f..cdd6e23 100644 --- a/flake.nix +++ b/flake.nix @@ -1,8 +1,10 @@ { description = "A Concurrent Skip List library for key/value pairs."; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; - inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; outputs = { self @@ -12,40 +14,45 @@ }: flake-utils.lib.eachDefaultSystem (system: let -# pkgs = nixpkgs.legacyPackages.${system}; pkgs = import nixpkgs { inherit system; config = { allowUnfree = true; }; }; - in - { - devShells.default = pkgs.mkShell { - packages = with pkgs; [ - autoconf - bashInteractive - clang-tools - ed - gdb - graphviz-nox - meson - python311Packages.rbtools - ]; + supportedSystems = [ "x86_64-linux" ]; + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + nixpkgsFor = forAllSystems (system: import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }); + in { + pkgs = import nixpkgs { + inherit system; + devShell = nixpkgs.legacyPackages.${system} { + pkgs.mkShell = { + nativeBuildInputs = with pkgs.buildPackages; [ + act + autoconf + clang + ed + gcc + gdb + gettext + graphviz-nox + libtool + m4 + perl + pkg-config + python3 + ripgrep + ]; + buildInputs = with pkgs; [ + libbacktrace + glibc.out + glibc.static + ]; + }; + DOCKER_BUILDKIT = 1; + }; }; - buildInputs = with pkgs; [ - glibc - ]; - nativeBuildInputs = with pkgs.buildPackages; [ - act - binutils - coreutils - gcc - gettext - libtool - m4 - make - perl - pkg-config - ripgrep - ]; }); } diff --git a/include/sparsemap.h b/include/sparsemap.h index f51d680..23d32b9 100644 --- a/include/sparsemap.h +++ b/include/sparsemap.h @@ -84,7 +84,7 @@ void sparsemap_init(sparsemap_t *map, uint8_t *data, size_t size, size_t used); void sparsemap_clear(sparsemap_t *map); /* Opens an existing sparsemap at the specified buffer. */ -sparsemap_t *sparsemap_open(uint8_t *data, size_t data_size); +void sparsemap_open(sparsemap_t *, uint8_t *data, size_t data_size); /* Resizes the data range. */ void sparsemap_set_data_size(sparsemap_t *map, size_t data_size); diff --git a/src/sparsemap.c b/src/sparsemap.c index a9abe20..8ec8eea 100644 --- a/src/sparsemap.c +++ b/src/sparsemap.c @@ -15,22 +15,20 @@ * PERFORMANCE OF THIS SOFTWARE. */ -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wpedantic" #include -#include +#include #include -#include #include #include -#pragma GCC diagnostic pop #include #include #ifdef SPARSEMAP_DIAGNOSTIC #pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wpedantic" #pragma GCC diagnostic ignored "-Wvariadic-macros" +#include #define __sm_diag(format, ...) \ __sm_diag_(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__) #pragma GCC diagnostic pop @@ -647,7 +645,7 @@ __sm_get_chunk_map_offset(sparsemap_t *map, size_t idx) uint8_t *p = start; for (size_t i = 0; i < count - 1; i++) { - sm_idx_t start = *(sm_idx_t *)p; //TODO wtf... + sm_idx_t start = *(sm_idx_t *)p; __sm_assert(start == __sm_get_aligned_offset(start)); __sm_chunk_t chunk; __sm_chunk_map_init(&chunk, p + sizeof(sm_idx_t)); @@ -692,7 +690,7 @@ __sm_append_data(sparsemap_t *map, uint8_t *buffer, size_t buffer_size) /** * Inserts data somewhere in the middle of m_data. */ -static void +static int __sm_insert_data(sparsemap_t *map, size_t offset, uint8_t *buffer, size_t buffer_size) { @@ -757,16 +755,12 @@ sparsemap_init(sparsemap_t *map, uint8_t *data, size_t size, size_t used) /** * Opens an existing sparsemap at the specified buffer. */ -sparsemap_t * -sparsemap_open(uint8_t *data, size_t data_size) +void +sparsemap_open(sparsemap_t *map, uint8_t *data, size_t data_size) { - sparsemap_t *map = (sparsemap_t *)calloc(1, sizeof(sparsemap_t)); - if (map) { - map->m_data = data; - map->m_data_used = 0; - map->m_data_size = data_size; - } - return map; + map->m_data = data; + map->m_data_used = 0; + map->m_data_size = data_size; } /** From f857692c3ceaa7239dff09be09dffc7817118956 Mon Sep 17 00:00:00 2001 From: Greg Burd Date: Sun, 7 Apr 2024 20:38:57 +0000 Subject: [PATCH 3/3] locate first span of length 'n' using rank and select (#3) Reviewed-on: https://git.burd.me/greg/sparsemap/pulls/3 Co-authored-by: Greg Burd Co-committed-by: Greg Burd --- .clang-format | 2 +- examples/ex_3.c | 101 +++++--------- examples/ex_4.c | 329 ++++++++++++++++++++++++++++++++++++++++++++ include/sparsemap.h | 5 +- main | Bin 126264 -> 0 bytes src/sparsemap.c | 189 +++++++++++++++---------- 6 files changed, 485 insertions(+), 141 deletions(-) create mode 100644 examples/ex_4.c delete mode 100755 main diff --git a/.clang-format b/.clang-format index 3013d6f..dcdb881 100644 --- a/.clang-format +++ b/.clang-format @@ -102,7 +102,7 @@ PointerAlignment: Right ContinuationIndentWidth: 2 IndentWidth: 2 TabWidth: 2 -ColumnLimit: 80 +ColumnLimit: 160 UseTab: Never SpaceAfterCStyleCast: false IncludeBlocks: Regroup diff --git a/examples/ex_3.c b/examples/ex_3.c index dc73b53..c3e9a9c 100644 --- a/examples/ex_3.c +++ b/examples/ex_3.c @@ -70,74 +70,39 @@ main(void) { int i = 0; rnd_ctx_t prng; - int array[1024] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, - 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, - 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, - 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, - 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, - 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, - 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, - 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, - 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, - 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, - 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, - 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, - 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, - 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, - 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, - 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, - 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, - 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, - 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, - 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, - 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, - 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, - 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, - 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, - 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, - 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, - 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, - 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, - 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, - 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, - 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, - 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, - 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, - 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, - 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, - 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, - 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, - 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, - 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, - 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, - 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, - 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, - 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, - 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, - 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, - 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, - 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, - 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, - 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, - 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, - 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, - 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, - 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, - 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, - 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, - 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, - 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, - 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, - 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, - 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, - 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, - 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, - 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, - 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, - 980, 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, - 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, - 1008, 1009, 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, - 1020, 1021, 1022, 1023, 1024 }; + int array[1024] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, + 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, + 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, + 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, + 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, + 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, + 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, + 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, + 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, + 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, + 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, + 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, + 392, 393, 394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, + 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, + 454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, + 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, + 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, + 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, + 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, + 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, + 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, + 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, 697, 698, 699, 700, 701, + 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728, 729, 730, 731, 732, + 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763, + 764, 765, 766, 767, 768, 769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, + 795, 796, 797, 798, 799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, + 826, 827, 828, 829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, + 857, 858, 859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, + 888, 889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, + 919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, + 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, + 981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, + 1010, 1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024 }; // disable buffering setbuf(stderr, 0); diff --git a/examples/ex_4.c b/examples/ex_4.c new file mode 100644 index 0000000..ac1bc84 --- /dev/null +++ b/examples/ex_4.c @@ -0,0 +1,329 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "../include/sparsemap.h" + +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wvariadic-macros" +#define __diag(...) \ + do { \ + fprintf(stderr, "%s:%d:%s(): ", __FILE__, __LINE__, __func__); \ + fprintf(stderr, __VA_ARGS__); \ + } while (0) +#pragma GCC diagnostic pop + +#define SEED + +uint32_t +xorshift(int *state) +{ + if (!state) { + return 0; + } + // Xorshift algorithm + uint32_t x = *state; // Dereference state to get the current state value + if (x == 0) x = 123456789; // Ensure the state is never zero; use a default seed if so + x ^= x << 13; + x ^= x >> 17; + x ^= x << 5; + *state = x; // Update the state + return x; // Return the new state as the next pseudo-random number +} + +void +shuffle(int *array, size_t n, int *prng) +{ + size_t i, j; + + if (n > 1) { + for (i = n - 1; i > 0; i--) { + j = (unsigned int)(xorshift(prng) % (i + 1)); + // XOR swap algorithm + if (i != j) { // avoid self-swap leading to zero-ing the element + array[i] = array[i] ^ array[j]; + array[j] = array[i] ^ array[j]; + array[i] = array[i] ^ array[j]; + } + } + } +} + +int +compare_ints(const void *a, const void *b) +{ + return *(const int *)a - *(const int *)b; +} + +// Check if there's already a sequence of 'r' sequential integers +int has_sequential_set(int *a, size_t l, int r) { + int count = 1; // Start with a count of 1 for the first number + for (size_t i = 1; i < l; ++i) { + if (a[i] - a[i - 1] == 1) { // Check if the current and previous elements are sequential + count++; + if (count >= r) return 1; // Found a sequential set of length 'r' + } else { + count = 1; // Reset count if the sequence breaks + } + } + return 0; // No sequential set of length 'r' found +} + +// Function to ensure an array contains a set of 'r' sequential integers +void ensure_sequential_set(int *a, size_t l, int r, uint32_t *prng) { + if (r > l) return; // If 'r' is greater than array length, cannot satisfy the condition + + // Sort the array to check for existing sequences + qsort(a, l, sizeof(int), compare_ints); + + // Check if a sequential set of length 'r' already exists + if (has_sequential_set(a, l, r)) { + return; // Sequence already exists, no modification needed + } + + // Find the minimum and maximum values in the array + int min_value = a[0]; + int max_value = a[l - 1]; + + // Generate a random value between min_value and max_value + int value = xorshift(prng) % (max_value - min_value - r + 1); + + // Generate a random location between 0 and l - r + int offset = xorshift(prng) % (l + r + 1); + + // Adjust the array to include a sequential set of 'r' integers at the random offset + for (int i = 0; i < r; ++i) { + a[i + offset] = value + i; + } +} + +void +print_array(int *array, size_t l) +{ + int a[l]; + memcpy(a, array, sizeof(int) * l); + qsort(a, l, sizeof(int), compare_ints); + + printf("int a[] = {"); + for (int i = 0; i < l; i++) { + printf("%d", a[i]); + if (i != l) { + printf(", "); + } + } + printf("};\n"); +} + +bool +has_span(sparsemap_t *map, int *array, size_t l, size_t n) +{ + if (n == 0 || l == 0 || n > l) { + return false; + } + + int sorted[l]; + memcpy(sorted, array, sizeof(int) * l); + qsort(sorted, l, sizeof(int), compare_ints); + + for (size_t i = 0; i <= l - n; i++) { + if (sorted[i] + n - 1 == sorted[i + n - 1]) { +#if 0 + fprintf(stderr, "Found span: "); + for (size_t j = i; j < i + n; j++) { + fprintf(stderr, "%d ", sorted[j]); + } + fprintf(stderr, "\n"); +#endif + for (size_t j = 0; j < n; j++) { + size_t pos = sorted[j + i]; + bool set = sparsemap_is_set(map, pos); + assert(set); + } + __diag("Found span: [%d, %d], length: %zu\n", sorted[i], sorted[i + n - 1], n); + return true; + } + } + + return false; +} + +bool +is_span(int *array, size_t n, int x, int l) +{ + if (n == 0 || l < 0) { + return false; + } + + int a[n]; + memcpy(a, array, sizeof(int) * n); + qsort(a, n, sizeof(int), compare_ints); + + // Iterate through the array to find a span starting at x of length l + for (size_t i = 0; i < n; i++) { + if (a[i] == x) { + // Check if the span can fit in the array + if (i + l - 1 < n && a[i + l - 1] == x + l - 1) { + return true; // Found the span + } + } + } + return false; // Span not found +} + +void +print_spans(int *array, size_t n) +{ + int a[n]; + size_t start = 0, end = 0; + + if (n == 0) { + fprintf(stderr, "Array is empty\n"); + return; + } + + memcpy(a, array, sizeof(int) * n); + qsort(a, n, sizeof(int), compare_ints); + + for (size_t i = 1; i < n; i++) { + if (a[i] == a[i - 1] + 1) { + end = i; // Extend the span + } else { + // Print the current span + if (start == end) { + fprintf(stderr, "[%d] ", a[start]); + } else { + fprintf(stderr, "[%d, %d] ", a[start], a[end]); + } + // Move to the next span + start = i; + end = i; + } + } + + // Print the last span if needed + if (start == end) { + fprintf(stderr, "[%d]\n", a[start]); + } else { + fprintf(stderr, "[%d, %d]\n", a[start], a[end]); + } +} + +bool +was_set(size_t bit, const int array[]) +{ + for (int i = 0; i < 1024; i++) { + if (array[i] == (int)bit) { + return true; + } + } + return false; +} + +#define TEST_ARRAY_SIZE 1024 + +int +is_unique(int a[], size_t l, int value) { + for (size_t i = 0; i < l; ++i) { + if (a[i] == value) { + return 0; // Not unique + } + } + return 1; // Unique +} + +void +setup_test_array(int a[], size_t l, int max_value, int *prng) +{ + if (a == NULL || prng == NULL || max_value < 0) return; // Basic error handling and validation + + for (size_t i = 0; i < l; ++i) { + int candidate; + do { + candidate = xorshift(prng) % (max_value + 1); // Generate a new value within the specified range + } while (!is_unique(a, i, candidate)); // Repeat until a unique value is found + a[i] = candidate; // Assign the unique value to the array + } +} + +int +main(void) +{ + int i = 0; + size_t rank; + int array[TEST_ARRAY_SIZE]; + int prng; + +// seed the PRNG +#ifdef SEED + prng = 8675309; +#else + prng = (unsigned int)time(NULL) ^ getpid(); +#endif + + // disable buffering + setvbuf(stdout, NULL, _IONBF, 0); // Disable buffering for stdout + setvbuf(stderr, NULL, _IONBF, 0); // Disable buffering for stdout + + // start with a 3KiB buffer, TEST_ARRAY_SIZE bits + uint8_t *buf = calloc(3 * 1024, sizeof(uint8_t)); + + // create the sparse bitmap + sparsemap_t *map = sparsemap(buf, sizeof(uint8_t) * 3 * 1024, 0); + + // create an array of ints + setup_test_array(array, TEST_ARRAY_SIZE, 1024 * 3, &prng); + + // randomize setting the bits on + shuffle(array, TEST_ARRAY_SIZE, &prng); + //print_array(array, TEST_ARRAY_SIZE); + //print_spans(array, TEST_ARRAY_SIZE); + + // set all the bits on in a random order + for (i = 0; i < TEST_ARRAY_SIZE; i++) { + sparsemap_set(map, array[i], true); + assert(sparsemap_is_set(map, array[i]) == true); + } + + // for (size_t len = 1; len < 20; len++) { + // for (size_t len = 1; len < TEST_ARRAY_SIZE - 1; len++) { + // for (size_t len = 1; len <= 1; len++) { + // for (size_t len = 2; len <= 2; len++) { + // for (size_t len = 3; len <= 3; len++) { + // for (size_t len = 4; len <= 4; len++) { + // for (size_t len = 5; len <= 5; len++) { + // for (size_t len = 8; len <= 8; len++) { + for (size_t len = 372; len <= 372; len++) { + __diag("================> %lu\n", len); + sparsemap_clear(map); + // set all the bits on in a random order + ensure_sequential_set(array, TEST_ARRAY_SIZE, len, &prng); + shuffle(array, TEST_ARRAY_SIZE, &prng); + print_spans(array, TEST_ARRAY_SIZE); + for (i = 0; i < TEST_ARRAY_SIZE; i++) { + sparsemap_set(map, array[i], true); + assert(sparsemap_is_set(map, array[i]) == true); + } + has_span(map, array, TEST_ARRAY_SIZE, len); + size_t l = sparsemap_span(map, 0, len); + if (l != (size_t)-1) { + __diag("Found span in map starting at %lu of length %lu\n", l, len); + __diag("is_span(%lu, %lu) == %s\n", l, len, is_span(array, TEST_ARRAY_SIZE, l, len) ? "yes" : "no"); + i = (int)l; + do { + bool set = sparsemap_is_set(map, i); + if (set) { + __diag("verified %d was set\n", i); + } else { + __diag("darn, %d was not really set, %s\n", i, was_set(i, array) ? "but we thought it was" : "because it wasn't"); + } + } while (++i < l + len); + } else { + __diag("UNABLE TO FIND SPAN in map of length %lu\n", len); + } + } + return 0; +} diff --git a/include/sparsemap.h b/include/sparsemap.h index 23d32b9..ce431cc 100644 --- a/include/sparsemap.h +++ b/include/sparsemap.h @@ -105,8 +105,7 @@ sm_idx_t sparsemap_get_start_offset(sparsemap_t *map); size_t sparsemap_get_size(sparsemap_t *map); /* Decompresses the whole bitmap; calls scanner for all bits. */ -void sparsemap_scan(sparsemap_t *map, void (*scanner)(sm_idx_t[], size_t), - size_t skip); +void sparsemap_scan(sparsemap_t *map, void (*scanner)(sm_idx_t[], size_t), size_t skip); /* Appends all chunk maps from |map| starting at |sstart| to |other|, then reduces the chunk map-count appropriately. */ @@ -118,4 +117,6 @@ size_t sparsemap_select(sparsemap_t *map, size_t n); /* Counts the set bits in the range [offset, idx]. */ size_t sparsemap_rank(sparsemap_t *map, size_t offset, size_t idx); +size_t sparsemap_span(sparsemap_t *map, size_t loc, size_t len); + #endif diff --git a/main b/main deleted file mode 100755 index 83e3a1b140a2d512102cb93de5b970a8ea13e96e..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 126264 zcmeFa33yaR_BVWQcZY=BB;5%K2^dHR!xGknO@e?O2y$CH5(LBrBoMZ+n+0$g1d}Lj zYz0S09rtZU$7Ng*9ha~Oh>8dzg|PEDi;fMFFT-j%!|4-@osXBArrEjOI&<lJ`7%RQ?OgMyI{9K) zwCbA2#~SKB$sWm*OtW*FF4A6!!fPdp-p(&bQgAzO$w%A7El~Kl1&Ytky|D`3!^&+w znu~lH7GH+NXXif4o_22AlQv;mY}s?M(}x=CDp#MHH9F9XNIW**V;0|I7QLN&g-X-x z+_wGrFREtz-?Ud^@f|o{2|jSXPYQN^nF4EeZnrlMe6-7d`q;yKw$6nlJdn%1`QZAWLaL>f@w>KR8$TbIJ^JcKC|bS zPcQ4!zwdw{eFhHfhf2TsGy2RgUs%1Y&$1zd`wSk~w{lV6{z@?WLsz3OjyY?h=2)RM z5N5ZlYr53i0>;N-)ona!**Dh7&xb=7FC|S&MxJVwTV}RBQUIiEw}qtp(FB|}luiD2 zNdLP><`D>}gXK0tZu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>_!>p&`P=2qX!@RPZ$}pA;dbJj^ht{y(!zYd8^{n?Au#Aod2_B(**VuNnsvqe z*(y7C;o?hYEzB;y?6Ree%d*R6UAnN5Im}t#+2+=b;oODuFP)vmLD+TY^WnQ)n|mE< zQr(pPPcWa|(70qlv!PqLG7HwaNev%WeN#4dx3@vPOO`eu`IdD}y-goQK6O(|drLFu z^?BgPRatL(aVoO)~v43gfq z=4^Lc3m=G#d{BmH?}rTZSU&ZxVal5xTTl^quF$>Q{9_;n_HWDTyeOGqT+F6 zd;*otuHA$l&5B}{P07gkiT26j#l{R)Tu0ZImLzLGm6vE!x*mI5d%8ZEKripaS=j5c zSG8=~+yRNRXQR(>t*`Is>a_KlRjO{&wvOJWwYc~8n0u>)a1eM)Pq(V;?CNc)!$IP!Gx#G&CdF@p_txA&?# zU5RzQEn5-R&9APfOLyG5mR37ZwXOrNKoHv8Y`YpB18dP=v-{NmoRiDK}JKr5!}_> zj-lKM?CD%@VD~Wl{|9)1gQ=;rh^$VBT3EH6zbw^I^vAUEYYc!q{4lN4SGVQww)~;R z%T4BQ0#8LC&M)hwgO`TuDq)cBv;gvM(Krdswc;^e*&_zz?JCoTU;%YW4JasD}QHFcBh#(^IR8WN%jLffI3|(u zxp^~|JbdLY;5n`MwG%*`zsAnHYb^h(abkom+THi$@XNYM7CHBxmlPoUg1tM3U)C*s zp`ozLFCo{uasUE-_;LP4|FX_gOMt|6((2JbQT_#f2!S}itcy=xYbb6MLVM5E-*3Y>p^gfcwe1aZ60RJnN|HZEgrMc(wj~jshAivPU^=mth z8SW_G0#6x$e^-^^e`< #include +#include +#include #include #include #include -#include -#include - #ifdef SPARSEMAP_DIAGNOSTIC #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wpedantic" #pragma GCC diagnostic ignored "-Wvariadic-macros" #include -#define __sm_diag(format, ...) \ - __sm_diag_(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__) +#define __sm_diag(format, ...) __sm_diag_(__FILE__, __LINE__, __func__, format, ##__VA_ARGS__) #pragma GCC diagnostic pop -void __attribute__((format(printf, 4, 5))) __sm_diag_(const char *file, - int line, const char *func, const char *format, ...) +void __attribute__((format(printf, 4, 5))) __sm_diag_(const char *file, int line, const char *func, const char *format, ...) { va_list args; va_start(args, format); @@ -47,10 +44,9 @@ void __attribute__((format(printf, 4, 5))) __sm_diag_(const char *file, #ifndef SPARSEMAP_ASSERT #define SPARSEMAP_ASSERT -#define __sm_assert(expr) \ - if (!(expr)) \ - fprintf(stderr, "%s:%d:%s(): assertion failed! %s", __FILE__, __LINE__, \ - __func__, #expr) +#define __sm_assert(expr) \ + if (!(expr)) \ + fprintf(stderr, "%s:%d:%s(): assertion failed! %s", __FILE__, __LINE__, __func__, #expr) #else #define __sm_assert(expr) ((void)0) #endif @@ -59,7 +55,7 @@ enum __SM_CHUNK_INFO { /* metadata overhead: 4 bytes for __sm_chunk_t count */ SM_SIZEOF_OVERHEAD = sizeof(uint32_t), - /* number of bits that can be stored in a BitVector */ + /* number of bits that can be stored in a sm_bitvec_t */ SM_BITS_PER_VECTOR = (sizeof(sm_bitvec_t) * 8), /* number of flags that can be stored in a single index byte */ @@ -137,8 +133,7 @@ static size_t __sm_chunk_map_get_position(__sm_chunk_t *map, size_t bv) { // handle 4 indices (1 byte) at a time - size_t num_bytes = bv / - ((size_t)SM_FLAGS_PER_INDEX_BYTE * SM_BITS_PER_VECTOR); + size_t num_bytes = bv / ((size_t)SM_FLAGS_PER_INDEX_BYTE * SM_BITS_PER_VECTOR); size_t position = 0; register uint8_t *p = (uint8_t *)map->m_data; @@ -148,8 +143,7 @@ __sm_chunk_map_get_position(__sm_chunk_t *map, size_t bv) bv -= num_bytes * SM_FLAGS_PER_INDEX_BYTE; for (size_t i = 0; i < bv; i++) { - size_t flags = ((*map->m_data) & ((sm_bitvec_t)SM_FLAG_MASK << (i * 2))) >> - (i * 2); + size_t flags = ((*map->m_data) & ((sm_bitvec_t)SM_FLAG_MASK << (i * 2))) >> (i * 2); if (flags == SM_PAYLOAD_MIXED) { position++; } @@ -161,7 +155,7 @@ __sm_chunk_map_get_position(__sm_chunk_t *map, size_t bv) /** * Initialize __sm_chunk_t with provided data. */ -static void +static inline void __sm_chunk_map_init(__sm_chunk_t *map, uint8_t *data) { map->m_data = (sm_bitvec_t *)data; @@ -234,8 +228,7 @@ __sm_chunk_map_is_empty(__sm_chunk_t *map) for (size_t i = 0; i < sizeof(sm_bitvec_t); i++, p++) { if (*p) { for (int j = 0; j < SM_FLAGS_PER_INDEX_BYTE; j++) { - size_t flags = ((*p) & ((sm_bitvec_t)SM_FLAG_MASK << (j * 2))) >> - (j * 2); + size_t flags = ((*p) & ((sm_bitvec_t)SM_FLAG_MASK << (j * 2))) >> (j * 2); if (flags != SM_PAYLOAD_NONE && flags != SM_PAYLOAD_ZEROS) { return (false); } @@ -273,8 +266,7 @@ __sm_chunk_map_is_set(__sm_chunk_t *map, size_t idx) __sm_assert(bv < SM_FLAGS_PER_INDEX); /* now retrieve the flags of that sm_bitvec_t */ - size_t flags = ((*map->m_data) & ((sm_bitvec_t)SM_FLAG_MASK << (bv * 2))) >> - (bv * 2); + size_t flags = ((*map->m_data) & ((sm_bitvec_t)SM_FLAG_MASK << (bv * 2))) >> (bv * 2); switch (flags) { case SM_PAYLOAD_ZEROS: case SM_PAYLOAD_NONE: @@ -302,16 +294,14 @@ __sm_chunk_map_is_set(__sm_chunk_t *map, size_t idx) * this time with |retried| = true. */ static int -__sm_chunk_map_set(__sm_chunk_t *map, size_t idx, bool value, size_t *pos, - sm_bitvec_t *fill, bool retried) +__sm_chunk_map_set(__sm_chunk_t *map, size_t idx, bool value, size_t *pos, sm_bitvec_t *fill, bool retried) { /* In which sm_bitvec_t is |idx| stored? */ size_t bv = idx / SM_BITS_PER_VECTOR; __sm_assert(bv < SM_FLAGS_PER_INDEX); /* Now retrieve the flags of that sm_bitvec_t. */ - size_t flags = ((*map->m_data) & ((sm_bitvec_t)SM_FLAG_MASK << (bv * 2))) >> - (bv * 2); + size_t flags = ((*map->m_data) & ((sm_bitvec_t)SM_FLAG_MASK << (bv * 2))) >> (bv * 2); assert(flags != SM_PAYLOAD_NONE); if (flags == SM_PAYLOAD_ZEROS) { /* Easy - set bit to 0 in a sm_bitvec_t of zeroes. */ @@ -381,11 +371,11 @@ __sm_chunk_map_set(__sm_chunk_t *map, size_t idx, bool value, size_t *pos, } /** - * Returns the index of the 'nth' set bit; sets |*pnew_n| to 0 if the + * Returns the index of the n'th set bit; sets |*pnew_n| to 0 if the * n'th bit was found in this __sm_chunk_t, or to the new, reduced value of |n| */ static size_t -__sm_chunk_map_select(__sm_chunk_t *map, ssize_t n, ssize_t *pnew_n) +__sm_chunk_map_select(__sm_chunk_t *map, size_t n, ssize_t *pnew_n) { size_t ret = 0; register uint8_t *p; @@ -417,8 +407,7 @@ __sm_chunk_map_select(__sm_chunk_t *map, ssize_t n, ssize_t *pnew_n) return (ret + n); } if (flags == SM_PAYLOAD_MIXED) { - sm_bitvec_t w = map->m_data[1 + - __sm_chunk_map_get_position(map, i * SM_FLAGS_PER_INDEX_BYTE + j)]; + sm_bitvec_t w = map->m_data[1 + __sm_chunk_map_get_position(map, i * SM_FLAGS_PER_INDEX_BYTE + j)]; for (int k = 0; k < SM_BITS_PER_VECTOR; k++) { if (w & ((sm_bitvec_t)1 << k)) { if (n == 0) { @@ -433,15 +422,15 @@ __sm_chunk_map_select(__sm_chunk_t *map, ssize_t n, ssize_t *pnew_n) } } - *pnew_n = n; + *pnew_n = (ssize_t)n; return (ret); } /** - * Counts the set bits in the range [0, idx]. + * Counts the set bits in the range [first, last] inclusive. */ static size_t -__sm_chunk_map_rank(__sm_chunk_t *map, size_t idx) +__sm_chunk_map_rank(__sm_chunk_t *map, size_t first, size_t last, size_t *after) { size_t ret = 0; @@ -453,27 +442,64 @@ __sm_chunk_map_rank(__sm_chunk_t *map, size_t idx) continue; } if (flags == SM_PAYLOAD_ZEROS) { - if (idx > SM_BITS_PER_VECTOR) { - idx -= SM_BITS_PER_VECTOR; + if (last > SM_BITS_PER_VECTOR) { + if (*after > SM_BITS_PER_VECTOR) { + *after = *after - SM_BITS_PER_VECTOR; + } else { + last -= SM_BITS_PER_VECTOR - *after; + *after = 0; + } } else { return (ret); } } else if (flags == SM_PAYLOAD_ONES) { - if (idx > SM_BITS_PER_VECTOR) { - idx -= SM_BITS_PER_VECTOR; - ret += SM_BITS_PER_VECTOR; + if (last > SM_BITS_PER_VECTOR) { + if (*after > SM_BITS_PER_VECTOR) { + *after = *after - SM_BITS_PER_VECTOR; + } else { + last -= SM_BITS_PER_VECTOR - *after; + if (*after == 0) { + ret += SM_BITS_PER_VECTOR; + } + *after = 0; + } } else { - return (ret + idx); + return (ret + last); } } else if (flags == SM_PAYLOAD_MIXED) { - if (idx > SM_BITS_PER_VECTOR) { - idx -= SM_BITS_PER_VECTOR; - ret += popcountll((uint64_t)map->m_data[1 + - __sm_chunk_map_get_position(map, i * SM_FLAGS_PER_INDEX_BYTE + j)]); + if (last > SM_BITS_PER_VECTOR) { + last -= SM_BITS_PER_VECTOR; + if (*after > SM_BITS_PER_VECTOR) { + *after = *after - SM_BITS_PER_VECTOR; + } else { + sm_bitvec_t w = map->m_data[1 + __sm_chunk_map_get_position(map, i * SM_FLAGS_PER_INDEX_BYTE + j)]; + uint64_t mask = UINT64_MAX; + if (*after > 0) { + mask = ~(mask >> (SM_BITS_PER_VECTOR - *after)); + size_t amt = popcountll(w & mask); + if (amt <= *after) { + *after = *after - amt; + } else { + *after = 0; + ret += popcountll(w & ~mask); + } + } else { + ret += popcountll(w); + } + } } else { - sm_bitvec_t w = map->m_data[1 + - __sm_chunk_map_get_position(map, i * SM_FLAGS_PER_INDEX_BYTE + j)]; - for (size_t k = 0; k < idx; k++) { + sm_bitvec_t w = map->m_data[1 + __sm_chunk_map_get_position(map, i * SM_FLAGS_PER_INDEX_BYTE + j)]; + size_t ks = 0; + if (*after > 0) { + if (*after > last) { + ks = last; + *after = *after - last; + } else { + ks += *after; + *after = 0; + } + } + for (size_t k = ks; k < last; k++) { if (w & ((sm_bitvec_t)1 << k)) { ret++; } @@ -491,8 +517,7 @@ __sm_chunk_map_rank(__sm_chunk_t *map, size_t idx) * Returns the number of (set) bits that were passed to the scanner */ static size_t -__sm_chunk_map_scan(__sm_chunk_t *map, sm_idx_t start, - void (*scanner)(sm_idx_t[], size_t), size_t skip) +__sm_chunk_map_scan(__sm_chunk_t *map, sm_idx_t start, void (*scanner)(sm_idx_t[], size_t), size_t skip) { size_t ret = 0; register uint8_t *p = (uint8_t *)map->m_data; @@ -529,8 +554,7 @@ __sm_chunk_map_scan(__sm_chunk_t *map, sm_idx_t start, ret += SM_BITS_PER_VECTOR; } } else if (flags == SM_PAYLOAD_MIXED) { - sm_bitvec_t w = map->m_data[1 + - __sm_chunk_map_get_position(map, i * SM_FLAGS_PER_INDEX_BYTE + j)]; + sm_bitvec_t w = map->m_data[1 + __sm_chunk_map_get_position(map, i * SM_FLAGS_PER_INDEX_BYTE + j)]; int n = 0; if (skip) { for (int b = 0; b < SM_BITS_PER_VECTOR; b++) { @@ -691,8 +715,7 @@ __sm_append_data(sparsemap_t *map, uint8_t *buffer, size_t buffer_size) * Inserts data somewhere in the middle of m_data. */ static int -__sm_insert_data(sparsemap_t *map, size_t offset, uint8_t *buffer, - size_t buffer_size) +__sm_insert_data(sparsemap_t *map, size_t offset, uint8_t *buffer, size_t buffer_size) { if (map->m_data_used + buffer_size > map->m_data_size) { __sm_assert(!"buffer overflow"); @@ -703,6 +726,7 @@ __sm_insert_data(sparsemap_t *map, size_t offset, uint8_t *buffer, memmove(p + buffer_size, p, map->m_data_used - offset); memcpy(p, buffer, buffer_size); map->m_data_used += buffer_size; + return 0; } /** @@ -718,8 +742,8 @@ __sm_remove_data(sparsemap_t *map, size_t offset, size_t gap_size) } /** -* Clears the whole buffer -*/ + * Clears the whole buffer + */ void sparsemap_clear(sparsemap_t *map) { @@ -916,8 +940,7 @@ sparsemap_set(sparsemap_t *map, size_t idx, bool value) /* Now update the __sm_chunk_t. */ size_t position; sm_bitvec_t fill; - int code = __sm_chunk_map_set(&chunk, idx - start, value, &position, &fill, - false); + int code = __sm_chunk_map_set(&chunk, idx - start, value, &position, &fill, false); switch (code) { case SM_OK: break; @@ -926,8 +949,7 @@ sparsemap_set(sparsemap_t *map, size_t idx, bool value) offset += sizeof(sm_idx_t) + position * sizeof(sm_bitvec_t); __sm_insert_data(map, offset, (uint8_t *)&fill, sizeof(sm_bitvec_t)); } - code = __sm_chunk_map_set(&chunk, idx - start, value, &position, &fill, - true); + code = __sm_chunk_map_set(&chunk, idx - start, value, &position, &fill, true); __sm_assert(code == SM_OK); break; case SM_NEEDS_TO_SHRINK: @@ -979,8 +1001,7 @@ sparsemap_get_size(sparsemap_t *map) * Decompresses the whole bitmap; calls scanner for all bits. */ void -sparsemap_scan(sparsemap_t *map, void (*scanner)(sm_idx_t[], size_t), - size_t skip) +sparsemap_scan(sparsemap_t *map, void (*scanner)(sm_idx_t[], size_t), size_t skip) { uint8_t *p = __sm_get_chunk_map_data(map, 0); size_t count = __sm_get_chunk_map_count(map); @@ -1129,7 +1150,6 @@ sparsemap_select(sparsemap_t *map, size_t n) assert(sparsemap_get_size(map) >= SM_SIZEOF_OVERHEAD); size_t result = 0; size_t count = __sm_get_chunk_map_count(map); - uint8_t *p = __sm_get_chunk_map_data(map, 0); for (size_t i = 0; i < count; i++) { @@ -1138,7 +1158,7 @@ sparsemap_select(sparsemap_t *map, size_t n) __sm_chunk_t chunk; __sm_chunk_map_init(&chunk, p); - ssize_t new_n = n; + ssize_t new_n = (ssize_t)n; size_t index = __sm_chunk_map_select(&chunk, n, &new_n); if (new_n == -1) { return (result + index); @@ -1147,33 +1167,62 @@ sparsemap_select(sparsemap_t *map, size_t n) p += __sm_chunk_map_get_size(&chunk); } +#ifdef DEBUG assert(!"shouldn't be here"); - return (0); +#endif + return (size_t)-1; } /** - * Counts the set bits in the range [offset, idx]. + * Counts the set bits in the range [first, last] inclusive. */ size_t -sparsemap_rank(sparsemap_t *map, size_t offset, size_t idx) +sparsemap_rank(sparsemap_t *map, size_t first, size_t last) { assert(sparsemap_get_size(map) >= SM_SIZEOF_OVERHEAD); - size_t result = 0; - size_t count = __sm_get_chunk_map_count(map); - - uint8_t *p = __sm_get_chunk_map_data(map, offset); + size_t result = 0, after = first, count = __sm_get_chunk_map_count(map); + uint8_t *p = __sm_get_chunk_map_data(map, 0); for (size_t i = 0; i < count; i++) { sm_idx_t start = *(sm_idx_t *)p; - if (start > idx) { + if (start > last) { return (result); } p += sizeof(sm_idx_t); __sm_chunk_t chunk; __sm_chunk_map_init(&chunk, p); - result += __sm_chunk_map_rank(&chunk, idx - start); + result += __sm_chunk_map_rank(&chunk, first - start, last - start, &after); p += __sm_chunk_map_get_size(&chunk); } return (result); } + +/** + * Finds a span of set bits of at least |len| after |loc|. Returns the index of + * the n'th set bit that starts a span of at least |len| bits set to true. + */ +size_t +sparsemap_span(sparsemap_t *map, size_t loc, size_t len) +{ + size_t offset, nth = 0, count = 0; + + offset = sparsemap_select(map, 0); + if (len == 1) { + return offset; + } + do { + count = sparsemap_rank(map, offset, offset + len); + if (count == len) { + return offset; + } else { + count = len; + while (--count && sparsemap_is_set(map, offset)) { + nth++; + } + } + offset = sparsemap_select(map, nth); + } while (offset != ((size_t)-1)); + + return offset; +}