summaryrefslogtreecommitdiffstats
path: root/test/main.c
diff options
context:
space:
mode:
authorEthan Werner <mail@ethanwerner.com>2026-07-01 09:42:39 +0400
committerEthan Werner <mail@ethanwerner.com>2026-07-01 09:42:39 +0400
commit07e18043145f3d91c8ea7ec3ad41b3c905585277 (patch)
tree2bdeae46973f4bdfce263679a4008ac768011f28 /test/main.c
initial commit: ts time series analysis library v0.1.0
- 354 financial and mathematical time-series indicators - Uniform C11 API with consistent function signatures - 349 passing tests with -Werror - Static and shared library builds - pkg-config integration - Python bindings - Fuzzing and sanitizer support - Security hardening flags
Diffstat (limited to 'test/main.c')
-rw-r--r--test/main.c73
1 files changed, 73 insertions, 0 deletions
diff --git a/test/main.c b/test/main.c
new file mode 100644
index 0000000..2854d1c
--- /dev/null
+++ b/test/main.c
@@ -0,0 +1,73 @@
+#define _POSIX_C_SOURCE 200809L
+#include <errno.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
+#include "ts.h"
+
+#include "main_generated.c"
+
+int main(void)
+{
+ struct sigaction sa = {0};
+ sa.sa_handler = SIG_IGN;
+ sigaction(SIGALRM, &sa, NULL);
+
+ size_t passed = 0;
+ size_t failed = 0;
+ size_t crashed = 0;
+ size_t skipped = 0;
+
+ for (size_t i = 0; i < NUM_TESTS; i++)
+ {
+ pid_t pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, " SKIP %s (fork failed: %s)\n", tests[i].name, strerror(errno));
+ skipped++;
+ continue;
+ }
+ if (pid == 0) {
+ bool ok = tests[i].func();
+ _exit(ok ? 0 : 1);
+ }
+ int status = 0;
+ alarm(30);
+ pid_t result = waitpid(pid, &status, 0);
+ alarm(0);
+ if (result < 0) {
+ if (errno == EINTR) {
+ kill(pid, SIGKILL);
+ waitpid(pid, &status, 0);
+ fprintf(stderr, " CRASH %s (timeout)\n", tests[i].name);
+ crashed++;
+ } else {
+ fprintf(stderr, " CRASH %s (waitpid failed: %s)\n", tests[i].name, strerror(errno));
+ crashed++;
+ }
+ continue;
+ }
+ if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
+ printf(" PASS %s\n", tests[i].name);
+ passed++;
+ } else if (WIFEXITED(status)) {
+ fprintf(stderr, " FAIL %s\n", tests[i].name);
+ failed++;
+ } else if (WIFSIGNALED(status)) {
+ fprintf(stderr, " CRASH %s (signal %d)\n", tests[i].name, WTERMSIG(status));
+ crashed++;
+ } else {
+ fprintf(stderr, " CRASH %s\n", tests[i].name);
+ crashed++;
+ }
+ }
+
+ printf("\n--- %zu tests: %zu passed, %zu failed, %zu crashed, %zu skipped ---\n",
+ NUM_TESTS, passed, failed, crashed, skipped);
+
+ return (failed > 0 || crashed > 0) ? 1 : 0;
+}