summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorMitya Selivanov <automainint@guattari.tech>2023-09-02 20:59:29 +0200
committerMitya Selivanov <automainint@guattari.tech>2023-09-02 20:59:29 +0200
commit835e1fcd131c63ee2b3b647e327b33a3bfb369e3 (patch)
tree9d6fb42d6296a7bbec4a6ea58358c0fdb5de7e05 /source
parent34ba87d8c8cfef5ed249b34bd2d2b7e41a34d2f7 (diff)
downloadkit-835e1fcd131c63ee2b3b647e327b33a3bfb369e3.zip
[Linux] Change build system; Remove CMake
Diffstat (limited to 'source')
-rw-r--r--source/CMakeLists.txt6
-rw-r--r--source/kit/CMakeLists.txt27
-rw-r--r--source/kit/_static.c14
-rw-r--r--source/kit/allocator.h4
-rw-r--r--source/kit/array_ref.h18
-rw-r--r--source/kit/async_function.h4
-rw-r--r--source/kit/atomic.h8
-rw-r--r--source/kit/bigint.h1
-rw-r--r--source/kit/input_buffer.c10
-rw-r--r--source/kit/input_stream.c10
-rw-r--r--source/kit/mersenne_twister_64.h4
-rw-r--r--source/kit/move_back.h4
-rw-r--r--source/kit/mutex.h5
-rw-r--r--source/kit/secure_random.h5
-rw-r--r--source/kit/sha256.h4
-rw-r--r--source/kit/sockets.h4
-rw-r--r--source/kit/status.h2
-rw-r--r--source/kit/string_ref.h1
-rw-r--r--source/kit/thread.h5
-rw-r--r--source/kit/types.h17
-rw-r--r--source/kit_test/CMakeLists.txt7
-rw-r--r--source/kit_test/_static.c3
-rw-r--r--source/kit_test/bench.c39
-rw-r--r--source/kit_test/bench.h1
-rw-r--r--source/kit_test/shared.inl.h38
-rw-r--r--source/kit_test/test.c38
-rw-r--r--source/kit_test/test.h4
-rw-r--r--source/test/CMakeLists.txt2
-rw-r--r--source/test/programs/CMakeLists.txt49
-rw-r--r--source/test/unittests/CMakeLists.txt8
-rw-r--r--source/tests/_static.c55
-rw-r--r--source/tests/array_ref.test.c (renamed from source/test/unittests/array_ref.test.c)4
-rw-r--r--source/tests/async_function.test.c (renamed from source/test/unittests/async_function.test.c)4
-rw-r--r--source/tests/atomic.test.c (renamed from source/test/unittests/atomic.test.c)6
-rw-r--r--source/tests/bench.test.c (renamed from source/test/unittests/foo.bench.c)4
-rw-r--r--source/tests/bigint.test.c (renamed from source/test/unittests/bigint.test.c)4
-rw-r--r--source/tests/condition_variable.test.c (renamed from source/test/unittests/condition_variable.test.c)16
-rw-r--r--source/tests/cpp.cpp (renamed from source/test/programs/cpp_example.cpp)2
-rw-r--r--source/tests/dynamic_array.test.c (renamed from source/test/unittests/dynamic_array.test.c)4
-rw-r--r--source/tests/file.test.c (renamed from source/test/unittests/file.test.c)6
-rw-r--r--source/tests/input_buffer.test.c (renamed from source/test/unittests/input_buffer.test.c)4
-rw-r--r--source/tests/input_stream.test.c (renamed from source/test/unittests/input_stream.test.c)4
-rw-r--r--source/tests/lower_bound.test.c (renamed from source/test/unittests/lower_bound.test.c)6
-rw-r--r--source/tests/main.test.c (renamed from source/test/unittests/main.test.c)4
-rw-r--r--source/tests/mersenne_twister_64.test.c (renamed from source/test/unittests/mersenne_twister_64.test.c)6
-rw-r--r--source/tests/move_back.test.c (renamed from source/test/unittests/move_back.test.c)4
-rw-r--r--source/tests/mutex.test.c (renamed from source/test/unittests/mutex.test.c)20
-rw-r--r--source/tests/secure_random.test.c (renamed from source/test/unittests/secure_random.test.c)4
-rw-r--r--source/tests/sha256.test.c (renamed from source/test/unittests/sha256.test.c)6
-rw-r--r--source/tests/signals.cpp (renamed from source/test/programs/signals.cpp)2
-rw-r--r--source/tests/string_ref.test.c (renamed from source/test/unittests/string_ref.test.c)4
-rw-r--r--source/tests/test_duration.test.c (renamed from source/test/unittests/test_duration.test.c)5
-rw-r--r--source/tests/thread.test.c (renamed from source/test/unittests/thread.test.c)4
-rw-r--r--source/tests/too_many_assertions.c (renamed from source/test/programs/too_many_assertions.c)2
-rw-r--r--source/tests/too_many_tests.c (renamed from source/test/programs/too_many_tests.c)2
55 files changed, 267 insertions, 257 deletions
diff --git a/source/CMakeLists.txt b/source/CMakeLists.txt
deleted file mode 100644
index 1444b6a..0000000
--- a/source/CMakeLists.txt
+++ /dev/null
@@ -1,6 +0,0 @@
-add_subdirectory(kit)
-add_subdirectory(kit_test)
-
-if(KIT_ENABLE_TESTING)
- add_subdirectory(test)
-endif()
diff --git a/source/kit/CMakeLists.txt b/source/kit/CMakeLists.txt
deleted file mode 100644
index 2e89133..0000000
--- a/source/kit/CMakeLists.txt
+++ /dev/null
@@ -1,27 +0,0 @@
-target_sources(
- kit
- PUBLIC
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/mutex.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/status.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/atomic.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/allocator.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/string_ref.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/thread.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/bigint.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/dynamic_array.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/condition_variable.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/async_function.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/move_back.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/secure_random.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/input_stream.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/thread_defs.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/input_buffer.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/lower_bound.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/sha256.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/file.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/array_ref.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/mersenne_twister_64.h>
- PRIVATE
- input_buffer.c secure_random.c sha256.c thread.posix.c atomic.win32.c
- condition_variable.c thread.win32.c input_stream.c file.c allocator.c
- array_ref.c dynamic_array.c mutex.c mersenne_twister_64.c)
diff --git a/source/kit/_static.c b/source/kit/_static.c
new file mode 100644
index 0000000..f098ab1
--- /dev/null
+++ b/source/kit/_static.c
@@ -0,0 +1,14 @@
+#include "allocator.c"
+#include "array_ref.c"
+#include "atomic.win32.c"
+#include "condition_variable.c"
+#include "dynamic_array.c"
+#include "file.c"
+#include "input_buffer.c"
+#include "input_stream.c"
+#include "mersenne_twister_64.c"
+#include "mutex.c"
+#include "secure_random.c"
+#include "sha256.c"
+#include "thread.posix.c"
+#include "thread.win32.c"
diff --git a/source/kit/allocator.h b/source/kit/allocator.h
index 7b73b20..f6dc62d 100644
--- a/source/kit/allocator.h
+++ b/source/kit/allocator.h
@@ -1,6 +1,10 @@
#ifndef KIT_ALLOCATOR_H
#define KIT_ALLOCATOR_H
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#include <stddef.h>
#ifdef __cplusplus
diff --git a/source/kit/array_ref.h b/source/kit/array_ref.h
index 39f1e8b..c893b49 100644
--- a/source/kit/array_ref.h
+++ b/source/kit/array_ref.h
@@ -1,6 +1,10 @@
#ifndef KIT_ARRAY_REF_H
#define KIT_ARRAY_REF_H
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#include <stddef.h>
#include <stdint.h>
@@ -21,15 +25,15 @@ int kit_ar_compare(ptrdiff_t left_element_size, ptrdiff_t left_size,
void const *right_data, kit_ar_compare_fn compare);
#define KIT_AR_MUT(type_) \
- struct { \
- ptrdiff_t size; \
- type_ *values; \
+ struct { \
+ ptrdiff_t size; \
+ type_ *values; \
}
-#define KIT_AR(type_) \
- struct { \
- ptrdiff_t size; \
- type_ const *values; \
+#define KIT_AR(type_) \
+ struct { \
+ ptrdiff_t size; \
+ type_ const *values; \
}
#define KIT_AR_MUT_WRAP(name_, element_type_, array_) \
diff --git a/source/kit/async_function.h b/source/kit/async_function.h
index 45e1089..f7a04e7 100644
--- a/source/kit/async_function.h
+++ b/source/kit/async_function.h
@@ -1,6 +1,10 @@
#ifndef KIT_ASYNC_FUNCTION_H
#define KIT_ASYNC_FUNCTION_H
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#include <stddef.h>
#include <string.h>
diff --git a/source/kit/atomic.h b/source/kit/atomic.h
index 23962a2..4d56def 100644
--- a/source/kit/atomic.h
+++ b/source/kit/atomic.h
@@ -1,8 +1,8 @@
#ifndef KIT_ATOMIC_H
#define KIT_ATOMIC_H
-#ifdef __cplusplus
-extern "C" {
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
#endif
#include <stdint.h>
@@ -16,6 +16,10 @@ extern "C" {
# define KIT_ATOMIC(type_) type_ volatile
+# ifdef __cplusplus
+extern "C" {
+# endif
+
enum {
memory_order_relaxed,
memory_order_consume,
diff --git a/source/kit/bigint.h b/source/kit/bigint.h
index b302c22..c948b57 100644
--- a/source/kit/bigint.h
+++ b/source/kit/bigint.h
@@ -2,6 +2,7 @@
#define KIT_BIGINT_H
#include "string_ref.h"
+
#include <assert.h>
#include <string.h>
diff --git a/source/kit/input_buffer.c b/source/kit/input_buffer.c
index 1ea9e94..c59031f 100644
--- a/source/kit/input_buffer.c
+++ b/source/kit/input_buffer.c
@@ -67,16 +67,12 @@ static void buf_adjust(void *p, ptrdiff_t size) {
}
}
-static ptrdiff_t min(ptrdiff_t a, ptrdiff_t b) {
- if (a < b)
- return a;
- return b;
-}
-
static ptrdiff_t buf_read(void *p, ptrdiff_t offset,
kit_out_str_t destination) {
internal_buffer_t *buf = (internal_buffer_t *) p;
- ptrdiff_t n = min(destination.size, buf->data.size - offset);
+ ptrdiff_t n = destination.size < buf->data.size - offset
+ ? destination.size
+ : buf->data.size - offset;
memcpy(destination.values, buf->data.values + offset, n);
return n;
}
diff --git a/source/kit/input_stream.c b/source/kit/input_stream.c
index df31c1d..7d8476b 100644
--- a/source/kit/input_stream.c
+++ b/source/kit/input_stream.c
@@ -20,17 +20,13 @@ static int check_type(void *state, ptrdiff_t type) {
return basic != NULL && basic->type == type;
}
-static ptrdiff_t min(ptrdiff_t a, ptrdiff_t b) {
- if (a < b)
- return a;
- return b;
-}
-
static ptrdiff_t read_str(void *state, kit_out_str_t destination) {
if (!check_type(state, input_stream_str))
return 0;
kit_is_state_str_t *str = (kit_is_state_str_t *) state;
- ptrdiff_t size = min(destination.size, str->string.size);
+ ptrdiff_t size = destination.size < str->string.size
+ ? destination.size
+ : str->string.size;
memcpy(destination.values, str->string.values, size);
str->string.values += size;
str->string.size -= size;
diff --git a/source/kit/mersenne_twister_64.h b/source/kit/mersenne_twister_64.h
index f351194..548aea4 100644
--- a/source/kit/mersenne_twister_64.h
+++ b/source/kit/mersenne_twister_64.h
@@ -1,6 +1,10 @@
#ifndef KIT_MERSENNE_TWISTER_64_H
#define KIT_MERSENNE_TWISTER_64_H
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#include <stddef.h>
#include <stdint.h>
diff --git a/source/kit/move_back.h b/source/kit/move_back.h
index 6eee4cf..0927321 100644
--- a/source/kit/move_back.h
+++ b/source/kit/move_back.h
@@ -1,6 +1,10 @@
#ifndef KIT_MOVE_BACK_H
#define KIT_MOVE_BACK_H
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#include <string.h>
#ifdef __cplusplus
diff --git a/source/kit/mutex.h b/source/kit/mutex.h
index 7816301..919d92a 100644
--- a/source/kit/mutex.h
+++ b/source/kit/mutex.h
@@ -2,9 +2,12 @@
#define KIT_MUTEX_H
#ifndef KIT_DISABLE_SYSTEM_THREADS
+# ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+# endif
+
# include "thread_defs.h"
-# define _GNU_SOURCE
# include <time.h>
# if !defined(_WIN32) || defined(__CYGWIN__)
diff --git a/source/kit/secure_random.h b/source/kit/secure_random.h
index e7a80c2..21399b7 100644
--- a/source/kit/secure_random.h
+++ b/source/kit/secure_random.h
@@ -1,9 +1,12 @@
#ifndef KIT_SECURE_RANDOM_H
#define KIT_SECURE_RANDOM_H
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#include "status.h"
-#define _GNU_SOURCE
#include <stddef.h>
#include <stdint.h>
diff --git a/source/kit/sha256.h b/source/kit/sha256.h
index 806bff3..ce74ed9 100644
--- a/source/kit/sha256.h
+++ b/source/kit/sha256.h
@@ -1,6 +1,10 @@
#ifndef KIT_SHA256_H
#define KIT_SHA256_H
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#include <stddef.h>
#include <stdint.h>
diff --git a/source/kit/sockets.h b/source/kit/sockets.h
index 8afcee6..87e37e6 100644
--- a/source/kit/sockets.h
+++ b/source/kit/sockets.h
@@ -1,6 +1,10 @@
#ifndef KIT_SOCKETS_H
#define KIT_SOCKETS_H
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#include "status.h"
#ifndef KIT_DISABLE_SYSTEM_SOCKETS
diff --git a/source/kit/status.h b/source/kit/status.h
index 0e23151..e689c5f 100644
--- a/source/kit/status.h
+++ b/source/kit/status.h
@@ -18,7 +18,7 @@ enum {
KIT_ERROR_SOCKET_CONTROL_FAILED
};
-typedef int kit_status_t;
+typedef signed int kit_status_t;
#ifdef __cplusplus
}
diff --git a/source/kit/string_ref.h b/source/kit/string_ref.h
index a5ad5c1..8cf1970 100644
--- a/source/kit/string_ref.h
+++ b/source/kit/string_ref.h
@@ -2,6 +2,7 @@
#define KIT_STRING_REF_H
#include "array_ref.h"
+
#include <string.h>
#ifdef __cplusplus
diff --git a/source/kit/thread.h b/source/kit/thread.h
index e8fb7e8..92e6a5d 100644
--- a/source/kit/thread.h
+++ b/source/kit/thread.h
@@ -2,9 +2,12 @@
#define KIT_THREAD_H
#ifndef KIT_DISABLE_SYSTEM_THREADS
+# ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+# endif
+
# include "thread_defs.h"
-# define _GNU_SOURCE
# include <stddef.h>
# include <time.h>
diff --git a/source/kit/types.h b/source/kit/types.h
new file mode 100644
index 0000000..0251b75
--- /dev/null
+++ b/source/kit/types.h
@@ -0,0 +1,17 @@
+#ifndef KIT_TYPES_H
+#define KIT_TYPES_H
+
+typedef signed char i8;
+typedef signed short i16;
+typedef signed int i32;
+typedef signed long long i64;
+
+typedef unsigned char u8;
+typedef unsigned short u16;
+typedef unsigned int u32;
+typedef unsigned long long u64;
+
+typedef float f32;
+typedef double f64;
+
+#endif
diff --git a/source/kit_test/CMakeLists.txt b/source/kit_test/CMakeLists.txt
deleted file mode 100644
index 56aa9a4..0000000
--- a/source/kit_test/CMakeLists.txt
+++ /dev/null
@@ -1,7 +0,0 @@
-target_sources(
- kit_test
- PUBLIC
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/bench.h>
- $<BUILD_INTERFACE:${CMAKE_CURRENT_LIST_DIR}/test.h>
- PRIVATE
- test.c bench.c)
diff --git a/source/kit_test/_static.c b/source/kit_test/_static.c
new file mode 100644
index 0000000..036b397
--- /dev/null
+++ b/source/kit_test/_static.c
@@ -0,0 +1,3 @@
+#include "test.c"
+
+#include "bench.c"
diff --git a/source/kit_test/bench.c b/source/kit_test/bench.c
index 9d439c3..dcf7249 100644
--- a/source/kit_test/bench.c
+++ b/source/kit_test/bench.c
@@ -1,12 +1,6 @@
#include "bench.h"
-#define _GNU_SOURCE
-#include <setjmp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
+#include "shared.inl.h"
kit_benchs_list_t kit_benchs_list = { 0 };
@@ -57,17 +51,6 @@ static void bench_end(int i) {
kit_benchs_list.v[i].duration_nsec[n] = sec * 1000000000 + nsec;
}
-enum { white, blue, light, yellow, red, green };
-
-static char const *const color_codes[] = {
- [white] = "\x1b[38m", [blue] = "\x1b[34m", [light] = "\x1b[37m",
- [yellow] = "\x1b[33m", [red] = "\x1b[31m", [green] = "\x1b[32m"
-};
-
-static int print_color(int c) {
- return printf("%s", color_codes[c]);
-}
-
void kit_bench_register(char const *name, char const *file,
kit_bench_run_fn fn) {
int n = kit_benchs_list.size++;
@@ -84,23 +67,11 @@ void kit_bench_register(char const *name, char const *file,
static jmp_buf kit_bench_restore_execution;
-static int const signums[] = { SIGINT, SIGILL, SIGABRT,
- SIGFPE, SIGSEGV, SIGTERM };
-
-static char const *const signames[] = {
- [SIGINT] = "Interactive attention signal",
- [SIGILL] = "Illegal instruction",
- [SIGABRT] = "Abnormal termination",
- [SIGFPE] = "Erroneous arithmetic operation",
- [SIGSEGV] = "Invalid access to storage",
- [SIGTERM] = "Termination request"
-};
-
-static void handle_signal(int signum) {
+static void kit_bench_handle_signal(int signum) {
longjmp(kit_bench_restore_execution, signum);
}
-static void setup_signals() {
+static void kit_bench_setup_signals() {
int i;
for (i = 0; i < sizeof signums / sizeof *signums; i++) {
@@ -110,7 +81,7 @@ static void setup_signals() {
#else
struct sigaction action;
memset(&action, 0, sizeof action);
- action.sa_handler = handle_signal;
+ action.sa_handler = kit_bench_handle_signal;
sigaction(signums[i], &action, NULL);
#endif
@@ -151,7 +122,7 @@ int kit_run_benchmarks(int argc, char **argv) {
char const *specific_bench = NULL;
- setup_signals();
+ kit_bench_setup_signals();
for (int i = 0; i < argc; i++)
if (strcmp("--no-term-color", argv[i]) == 0)
diff --git a/source/kit_test/bench.h b/source/kit_test/bench.h
index f3d71b8..dd86c17 100644
--- a/source/kit_test/bench.h
+++ b/source/kit_test/bench.h
@@ -6,6 +6,7 @@ extern "C" {
#endif
#include "test.h"
+
#include <stdint.h>
#ifndef KIT_TEST_FILE
diff --git a/source/kit_test/shared.inl.h b/source/kit_test/shared.inl.h
new file mode 100644
index 0000000..e31c9f3
--- /dev/null
+++ b/source/kit_test/shared.inl.h
@@ -0,0 +1,38 @@
+#ifndef KIT_TEST_SHARED_INL_H
+#define KIT_TEST_SHARED_INL_H
+
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
+#include <setjmp.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <time.h>
+
+enum { white, blue, light, yellow, red, green };
+
+static char const *const color_codes[] = {
+ [white] = "\x1b[38m", [blue] = "\x1b[34m", [light] = "\x1b[37m",
+ [yellow] = "\x1b[33m", [red] = "\x1b[31m", [green] = "\x1b[32m"
+};
+
+static int print_color(int c) {
+ return printf("%s", color_codes[c]);
+}
+
+static int const signums[] = { SIGINT, SIGILL, SIGABRT,
+ SIGFPE, SIGSEGV, SIGTERM };
+
+static char const *const signames[] = {
+ [SIGINT] = "Interactive attention signal",
+ [SIGILL] = "Illegal instruction",
+ [SIGABRT] = "Abnormal termination",
+ [SIGFPE] = "Erroneous arithmetic operation",
+ [SIGSEGV] = "Invalid access to storage",
+ [SIGTERM] = "Termination request"
+};
+
+#endif
diff --git a/source/kit_test/test.c b/source/kit_test/test.c
index d1e048c..034d1e7 100644
--- a/source/kit_test/test.c
+++ b/source/kit_test/test.c
@@ -1,11 +1,6 @@
#include "test.h"
-#define _GNU_SOURCE
-#include <setjmp.h>
-#include <signal.h>
-#include <stdio.h>
-#include <string.h>
-#include <time.h>
+#include "shared.inl.h"
kit_tests_list_t kit_tests_list = { 0 };
@@ -30,17 +25,6 @@ static long long sec_to_ms(long long sec) {
return 1000 * sec;
}
-enum { white, blue, light, yellow, red, green };
-
-static char const *const color_codes[] = {
- [white] = "\x1b[38m", [blue] = "\x1b[34m", [light] = "\x1b[37m",
- [yellow] = "\x1b[33m", [red] = "\x1b[31m", [green] = "\x1b[32m"
-};
-
-static int print_color(int c) {
- return printf("%s", color_codes[c]);
-}
-
void kit_test_register(char const *name, char const *file,
kit_test_run_fn fn) {
int n = kit_tests_list.size++;
@@ -54,23 +38,11 @@ void kit_test_register(char const *name, char const *file,
static jmp_buf kit_test_restore_execution;
-static int const signums[] = { SIGINT, SIGILL, SIGABRT,
- SIGFPE, SIGSEGV, SIGTERM };
-
-static char const *const signames[] = {
- [SIGINT] = "Interactive attention signal",
- [SIGILL] = "Illegal instruction",
- [SIGABRT] = "Abnormal termination",
- [SIGFPE] = "Erroneous arithmetic operation",
- [SIGSEGV] = "Invalid access to storage",
- [SIGTERM] = "Termination request"
-};
-
-static void handle_signal(int signum) {
+static void kit_test_handle_signal(int signum) {
longjmp(kit_test_restore_execution, signum);
}
-static void setup_signals() {
+static void kit_test_setup_signals() {
int i;
for (i = 0; i < sizeof signums / sizeof *signums; i++) {
@@ -80,7 +52,7 @@ static void setup_signals() {
#else
struct sigaction action;
memset(&action, 0, sizeof action);
- action.sa_handler = handle_signal;
+ action.sa_handler = kit_test_handle_signal;
sigaction(signums[i], &action, NULL);
#endif
@@ -113,7 +85,7 @@ int kit_run_tests(int argc, char **argv) {
char const *specific_test = NULL;
- setup_signals();
+ kit_test_setup_signals();
for (i = 0; i < argc; i++)
if (strcmp("--no-term-color", argv[i]) == 0)
diff --git a/source/kit_test/test.h b/source/kit_test/test.h
index 8732366..6584cbe 100644
--- a/source/kit_test/test.h
+++ b/source/kit_test/test.h
@@ -5,6 +5,10 @@
extern "C" {
#endif
+#ifndef _GNU_SOURCE
+# define _GNU_SOURCE
+#endif
+
#include <stddef.h>
#ifndef KIT_TEST_FILE
diff --git a/source/test/CMakeLists.txt b/source/test/CMakeLists.txt
deleted file mode 100644
index 4435be1..0000000
--- a/source/test/CMakeLists.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-add_subdirectory(unittests)
-add_subdirectory(programs)
diff --git a/source/test/programs/CMakeLists.txt b/source/test/programs/CMakeLists.txt
deleted file mode 100644
index 81332cf..0000000
--- a/source/test/programs/CMakeLists.txt
+++ /dev/null
@@ -1,49 +0,0 @@
-project(
- ${KIT_PROJECT}_test_programs
- VERSION 0.1.1
- DESCRIPTION "Kit test programs"
- LANGUAGES C CXX)
-
-if(KIT_ENABLE_TESTING)
- add_executable(too_many_tests too_many_tests.c)
- target_link_libraries(too_many_tests kit_test)
- add_test(
- NAME too_many_tests_test
- COMMAND too_many_tests --quiet)
- set_tests_properties(
- too_many_tests_test
- PROPERTIES
- TIMEOUT "15")
-
- add_executable(too_many_assertions too_many_assertions.c)
- target_link_libraries(too_many_assertions kit_test)
- add_test(
- NAME too_many_assertions_test
- COMMAND too_many_assertions --quiet)
- set_tests_properties(
- too_many_assertions_test
- PROPERTIES
- TIMEOUT "15")
-
- add_executable(cpp_example cpp_example.cpp)
- target_link_libraries(cpp_example kit_test)
- add_test(
- NAME cpp_example_test
- COMMAND cpp_example --quiet)
- set_tests_properties(
- cpp_example_test
- PROPERTIES
- TIMEOUT "15")
-
- if(NOT MSVC)
- add_executable(signals signals.cpp)
- target_link_libraries(signals kit_test)
- add_test(
- NAME signals_test
- COMMAND signals --no-carriage-return)
- set_tests_properties(
- signals_test
- PROPERTIES
- TIMEOUT "15")
- endif()
-endif()
diff --git a/source/test/unittests/CMakeLists.txt b/source/test/unittests/CMakeLists.txt
deleted file mode 100644
index e071ed4..0000000
--- a/source/test/unittests/CMakeLists.txt
+++ /dev/null
@@ -1,8 +0,0 @@
-target_sources(
- kit_test_suite
- PRIVATE
- async_function.test.c bigint.test.c mutex.test.c test_duration.test.c
- main.test.c string_ref.test.c atomic.test.c foo.bench.c thread.test.c
- array_ref.test.c input_stream.test.c sha256.test.c lower_bound.test.c
- secure_random.test.c condition_variable.test.c mersenne_twister_64.test.c
- input_buffer.test.c move_back.test.c dynamic_array.test.c file.test.c)
diff --git a/source/tests/_static.c b/source/tests/_static.c
new file mode 100644
index 0000000..4b7543d
--- /dev/null
+++ b/source/tests/_static.c
@@ -0,0 +1,55 @@
+#include "array_ref.test.c"
+#undef KIT_TEST_FILE
+
+#include "async_function.test.c"
+#undef KIT_TEST_FILE
+
+#include "bigint.test.c"
+#undef KIT_TEST_FILE
+
+#include "condition_variable.test.c"
+#undef KIT_TEST_FILE
+
+#include "dynamic_array.test.c"
+#undef KIT_TEST_FILE
+
+#include "file.test.c"
+#undef KIT_TEST_FILE
+
+#include "input_buffer.test.c"
+#undef KIT_TEST_FILE
+
+#include "input_stream.test.c"
+#undef KIT_TEST_FILE
+
+#include "lower_bound.test.c"
+#undef KIT_TEST_FILE
+
+#include "mersenne_twister_64.test.c"
+#undef KIT_TEST_FILE
+
+#include "move_back.test.c"
+#undef KIT_TEST_FILE
+
+#include "mutex.test.c"
+#undef KIT_TEST_FILE
+
+#include "secure_random.test.c"
+#undef KIT_TEST_FILE
+
+#include "sha256.test.c"
+#undef KIT_TEST_FILE
+
+#include "string_ref.test.c"
+#undef KIT_TEST_FILE
+
+#include "test_duration.test.c"
+#undef KIT_TEST_FILE
+
+#include "thread.test.c"
+#undef KIT_TEST_FILE
+
+#include "bench.test.c"
+#undef KIT_TEST_FILE
+
+#include "main.test.c"
diff --git a/source/test/unittests/array_ref.test.c b/source/tests/array_ref.test.c
index c6083ee..da20aa0 100644
--- a/source/test/unittests/array_ref.test.c
+++ b/source/tests/array_ref.test.c
@@ -1,7 +1,7 @@
-#include "../../kit/array_ref.h"
+#include "../kit/array_ref.h"
#define KIT_TEST_FILE array_ref
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("array ref const wrap") {
int foo[] = { 1, 2, 3 };
diff --git a/source/test/unittests/async_function.test.c b/source/tests/async_function.test.c
index 32aff4e..35ce0ce 100644
--- a/source/test/unittests/async_function.test.c
+++ b/source/tests/async_function.test.c
@@ -1,7 +1,7 @@
-#include "../../kit/async_function.h"
+#include "../kit/async_function.h"
#define KIT_TEST_FILE async_function
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
AF_STATE(int, test_foo, );
static AF_DECL(test_foo);
diff --git a/source/test/unittests/atomic.test.c b/source/tests/atomic.test.c
index 7d8b35a..c1831a3 100644
--- a/source/test/unittests/atomic.test.c
+++ b/source/tests/atomic.test.c
@@ -1,8 +1,8 @@
-#include "../../kit/atomic.h"
-#include "../../kit/thread.h"
+#include "../kit/atomic.h"
+#include "../kit/thread.h"
#define KIT_TEST_FILE atomic
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("atomic store and load") {
ATOMIC(int) value;
diff --git a/source/test/unittests/foo.bench.c b/source/tests/bench.test.c
index ac1e0b5..92e216d 100644
--- a/source/test/unittests/foo.bench.c
+++ b/source/tests/bench.test.c
@@ -1,5 +1,5 @@
-#define KIT_TEST_FILE foo
-#include "../../kit_test/bench.h"
+#define KIT_TEST_FILE bench
+#include "../kit_test/bench.h"
struct test_foo_ {
double f;
diff --git a/source/test/unittests/bigint.test.c b/source/tests/bigint.test.c
index 260b0ec..c8ac44f 100644
--- a/source/test/unittests/bigint.test.c
+++ b/source/tests/bigint.test.c
@@ -1,8 +1,8 @@
#define KIT_BIGINT_SIZE 256
-#include "../../kit/bigint.h"
+#include "../kit/bigint.h"
#define KIT_TEST_FILE bigint
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
#if __STDC_VERSION__ >= 199901L
static_assert(sizeof(bigint_t) == 256, "KIT_BIGINT_SIZE check");
diff --git a/source/test/unittests/condition_variable.test.c b/source/tests/condition_variable.test.c
index 2dba7ca..dfbe4a6 100644
--- a/source/test/unittests/condition_variable.test.c
+++ b/source/tests/condition_variable.test.c
@@ -1,8 +1,8 @@
-#include "../../kit/condition_variable.h"
-#include "../../kit/thread.h"
+#include "../kit/condition_variable.h"
+#include "../kit/thread.h"
#define KIT_TEST_FILE condition_variable
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
typedef struct {
mtx_t m;
@@ -11,10 +11,10 @@ typedef struct {
cnd_t send;
cnd_t receive;
int value;
-} test_data_t;
+} cnd_test_data_t;
-static int test_run(void *p) {
- test_data_t *data = (test_data_t *) p;
+static int cnd_test_run(void *p) {
+ cnd_test_data_t *data = (cnd_test_data_t *) p;
mtx_lock(&data->m);
data->value = 20;
@@ -41,7 +41,7 @@ TEST("condition variable") {
int ok = 1;
for (i = 0; i < 10; i++) {
- test_data_t data;
+ cnd_test_data_t data;
data.in = 0;
data.out = 0;
@@ -52,7 +52,7 @@ TEST("condition variable") {
ok = ok && (cnd_init(&data.receive) == thrd_success);
thrd_t t;
- ok = ok && (thrd_create(&t, test_run, &data) == thrd_success);
+ ok = ok && (thrd_create(&t, cnd_test_run, &data) == thrd_success);
ok = ok && (mtx_lock(&data.m) == thrd_success);
if (data.out == 0)
diff --git a/source/test/programs/cpp_example.cpp b/source/tests/cpp.cpp
index 523186b..8b762e4 100644
--- a/source/test/programs/cpp_example.cpp
+++ b/source/tests/cpp.cpp
@@ -1,4 +1,4 @@
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("foo") {
REQUIRE(20 + 22 == 42);
diff --git a/source/test/unittests/dynamic_array.test.c b/source/tests/dynamic_array.test.c
index fad8d6d..8701e6c 100644
--- a/source/test/unittests/dynamic_array.test.c
+++ b/source/tests/dynamic_array.test.c
@@ -1,7 +1,7 @@
-#include "../../kit/dynamic_array.h"
+#include "../kit/dynamic_array.h"
#define KIT_TEST_FILE dynamic_array
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("dynamic array empty") {
DA_CREATE(v, char, 0);
diff --git a/source/test/unittests/file.test.c b/source/tests/file.test.c
index 732f122..e72df83 100644
--- a/source/test/unittests/file.test.c
+++ b/source/tests/file.test.c
@@ -1,9 +1,9 @@
-#include "../../kit/file.h"
-#include "../../kit/string_ref.h"
+#include "../kit/file.h"
+#include "../kit/string_ref.h"
#include <string.h>
#define KIT_TEST_FILE file
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("file path cache") {
kit_allocator_t alloc = kit_alloc_default();
diff --git a/source/test/unittests/input_buffer.test.c b/source/tests/input_buffer.test.c
index c062052..3cd84b6 100644
--- a/source/test/unittests/input_buffer.test.c
+++ b/source/tests/input_buffer.test.c
@@ -1,7 +1,7 @@
-#include "../../kit/input_buffer.h"
+#include "../kit/input_buffer.h"
#define KIT_TEST_FILE input_buffer
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("input buffer read once") {
str_t text = { .size = 3, .values = "foo" };
diff --git a/source/test/unittests/input_stream.test.c b/source/tests/input_stream.test.c
index 7dce043..61c2254 100644
--- a/source/test/unittests/input_stream.test.c
+++ b/source/tests/input_stream.test.c
@@ -1,7 +1,7 @@
-#include "../../kit/input_stream.h"
+#include "../kit/input_stream.h"
#define KIT_TEST_FILE input_stream
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("input stream wrap string") {
char foo[] = "test";
diff --git a/source/test/unittests/lower_bound.test.c b/source/tests/lower_bound.test.c
index 24752a6..3b62325 100644
--- a/source/test/unittests/lower_bound.test.c
+++ b/source/tests/lower_bound.test.c
@@ -1,8 +1,8 @@
-#include "../../kit/lower_bound.h"
-#include "../../kit/array_ref.h"
+#include "../kit/lower_bound.h"
+#include "../kit/array_ref.h"
#define KIT_TEST_FILE lower_bound
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
static int kit_less_int(int left, int right) {
return left < right;
diff --git a/source/test/unittests/main.test.c b/source/tests/main.test.c
index 60c2e36..2a41d4b 100644
--- a/source/test/unittests/main.test.c
+++ b/source/tests/main.test.c
@@ -1,5 +1,5 @@
-#include "../../kit_test/bench.h"
-#include "../../kit_test/test.h"
+#include "../kit_test/bench.h"
+#include "../kit_test/test.h"
int main(int argc, char **argv) {
int status = run_tests(argc, argv);
diff --git a/source/test/unittests/mersenne_twister_64.test.c b/source/tests/mersenne_twister_64.test.c
index e523154..6bf5b9c 100644
--- a/source/test/unittests/mersenne_twister_64.test.c
+++ b/source/tests/mersenne_twister_64.test.c
@@ -1,8 +1,8 @@
-#include "../../kit/mersenne_twister_64.h"
-#include "../../kit/secure_random.h"
+#include "../kit/mersenne_twister_64.h"
+#include "../kit/secure_random.h"
#define KIT_TEST_FILE mersenne_twister_64
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
enum { SIZE = 1000 };
diff --git a/source/test/unittests/move_back.test.c b/source/tests/move_back.test.c
index 399619d..f08d190 100644
--- a/source/test/unittests/move_back.test.c
+++ b/source/tests/move_back.test.c
@@ -1,7 +1,7 @@
-#include "../../kit/move_back.h"
+#include "../kit/move_back.h"
#define KIT_TEST_FILE move_back
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
static int is_equal(int const x, int const y) {
return x == y;
diff --git a/source/test/unittests/mutex.test.c b/source/tests/mutex.test.c
index 1bd2b3d..ce26991 100644
--- a/source/test/unittests/mutex.test.c
+++ b/source/tests/mutex.test.c
@@ -1,19 +1,19 @@
-#include "../../kit/mutex.h"
-#include "../../kit/thread.h"
+#include "../kit/mutex.h"
+#include "../kit/thread.h"
#define KIT_TEST_FILE mutex
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
enum { SLEEP = 400000000, TICK_COUNT = 200, THREAD_COUNT = 100 };
typedef struct {
mtx_t lock;
int value;
-} test_data_t;
+} mtx_test_data_t;
-static int test_run(void *data) {
- int i;
- test_data_t *x = (test_data_t *) data;
+static int mtx_test_run(void *data) {
+ int i;
+ mtx_test_data_t *x = (mtx_test_data_t *) data;
for (i = 0; i < TICK_COUNT; i++) {
mtx_lock(&x->lock);
@@ -33,13 +33,13 @@ static int test_run(void *data) {
TEST("mutex lock") {
ptrdiff_t i;
- test_data_t data;
- thrd_t pool[THREAD_COUNT];
+ mtx_test_data_t data;
+ thrd_t pool[THREAD_COUNT];
data.value = 42;
REQUIRE(mtx_init(&data.lock, mtx_plain) == thrd_success);
for (i = 0; i < THREAD_COUNT; i++)
- thrd_create(pool + i, test_run, &data);
+ thrd_create(pool + i, mtx_test_run, &data);
for (i = 0; i < THREAD_COUNT; i++) thrd_join(pool[i], NULL);
mtx_destroy(&data.lock);
diff --git a/source/test/unittests/secure_random.test.c b/source/tests/secure_random.test.c
index bde68a5..22bdd37 100644
--- a/source/test/unittests/secure_random.test.c
+++ b/source/tests/secure_random.test.c
@@ -1,8 +1,8 @@
-#include "../../kit/secure_random.h"
+#include "../kit/secure_random.h"
#include <string.h>
#define KIT_TEST_FILE secure_random
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("secure random") {
int i, j;
diff --git a/source/test/unittests/sha256.test.c b/source/tests/sha256.test.c
index e74b286..0f751df 100644
--- a/source/test/unittests/sha256.test.c
+++ b/source/tests/sha256.test.c
@@ -1,8 +1,8 @@
-#include "../../kit/sha256.h"
-#include "../../kit/array_ref.h"
+#include "../kit/sha256.h"
+#include "../kit/array_ref.h"
#define KIT_TEST_FILE sha256_64
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
#include <string.h>
diff --git a/source/test/programs/signals.cpp b/source/tests/signals.cpp
index e2532c2..0f6d77a 100644
--- a/source/test/programs/signals.cpp
+++ b/source/tests/signals.cpp
@@ -1,4 +1,4 @@
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
#include <cstdlib>
#include <stdexcept>
diff --git a/source/test/unittests/string_ref.test.c b/source/tests/string_ref.test.c
index 5ec9414..2891f16 100644
--- a/source/test/unittests/string_ref.test.c
+++ b/source/tests/string_ref.test.c
@@ -1,7 +1,7 @@
-#include "../../kit/string_ref.h"
+#include "../kit/string_ref.h"
#define KIT_TEST_FILE string_ref
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("static string wrap") {
str_t ref = SZ("foo bar");
diff --git a/source/test/unittests/test_duration.test.c b/source/tests/test_duration.test.c
index 0912d9f..27384b4 100644
--- a/source/test/unittests/test_duration.test.c
+++ b/source/tests/test_duration.test.c
@@ -1,7 +1,5 @@
#define KIT_TEST_FILE test_duration
-#include "../../kit_test/test.h"
-
-#include <stdlib.h>
+#include "../kit_test/test.h"
#if defined(_WIN32) && !defined(__CYGWIN__)
__declspec(dllimport) void __stdcall Sleep(unsigned long timeout);
@@ -9,6 +7,7 @@ static void kit_sleep(int ms) {
Sleep(ms);
}
#else
+# include <stdlib.h>
# include <unistd.h>
static void kit_sleep(int ms) {
usleep(ms * 1000);
diff --git a/source/test/unittests/thread.test.c b/source/tests/thread.test.c
index 01198c2..50f7c04 100644
--- a/source/test/unittests/thread.test.c
+++ b/source/tests/thread.test.c
@@ -1,7 +1,7 @@
-#include "../../kit/thread.h"
+#include "../kit/thread.h"
#define KIT_TEST_FILE thread
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
static int test_nothing(void *_) {
return 0;
diff --git a/source/test/programs/too_many_assertions.c b/source/tests/too_many_assertions.c
index 06b440b..662207d 100644
--- a/source/test/programs/too_many_assertions.c
+++ b/source/tests/too_many_assertions.c
@@ -1,4 +1,4 @@
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
TEST("foo") {
int i;
diff --git a/source/test/programs/too_many_tests.c b/source/tests/too_many_tests.c
index ac1cbf7..d4842e4 100644
--- a/source/test/programs/too_many_tests.c
+++ b/source/tests/too_many_tests.c
@@ -1,4 +1,4 @@
-#include "../../kit_test/test.h"
+#include "../kit_test/test.h"
void bar(int index, kit_test_report_fn report) { }