summaryrefslogtreecommitdiff
path: root/source/kit_test
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/kit_test
parent34ba87d8c8cfef5ed249b34bd2d2b7e41a34d2f7 (diff)
downloadkit-835e1fcd131c63ee2b3b647e327b33a3bfb369e3.zip
[Linux] Change build system; Remove CMake
Diffstat (limited to 'source/kit_test')
-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
7 files changed, 56 insertions, 74 deletions
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