Files
codebase-memory-mcp/tests/test_platform.c
T
Martin Vogel 94a9a92f83 Add C-native pipeline with blocking clang-tidy, cppcheck, clang-format linting
Complete C implementation of the indexing pipeline (src/), parallel worker
pool, graph buffer with merge support, SQLite writer, and 1893-test suite.

Linter setup: zero warnings from clang-tidy (all checks enabled, no NOLINT
suppressions), cppcheck, and clang-format. All issues fixed at source —
proper headers for external linkage, GROW_ARRAY macro restructured to
eliminate type parameter, null-deref paths guarded, named intermediates
for suspicious-argument checks.
2026-03-15 19:26:12 +01:00

81 lines
1.9 KiB
C

/*
* test_platform.c — RED phase tests for foundation/platform.
*/
#include "test_framework.h"
#include "../src/foundation/platform.h"
#include <unistd.h>
TEST(platform_now_ns) {
uint64_t t1 = cbm_now_ns();
ASSERT_GT(t1, 0);
/* Busy-wait a tiny bit */
for (volatile int i = 0; i < 100000; i++) {}
uint64_t t2 = cbm_now_ns();
ASSERT_GT(t2, t1);
PASS();
}
TEST(platform_now_ms) {
uint64_t t1 = cbm_now_ms();
ASSERT_GT(t1, 0);
PASS();
}
TEST(platform_nprocs) {
int n = cbm_nprocs();
ASSERT_GT(n, 0);
ASSERT_LT(n, 10000); /* sanity */
PASS();
}
TEST(platform_file_exists) {
/* This test file should exist */
ASSERT_TRUE(cbm_file_exists("tests/test_platform.c"));
ASSERT_FALSE(cbm_file_exists("nonexistent_file_xyz.txt"));
PASS();
}
TEST(platform_is_dir) {
ASSERT_TRUE(cbm_is_dir("tests"));
ASSERT_FALSE(cbm_is_dir("tests/test_platform.c"));
ASSERT_FALSE(cbm_is_dir("nonexistent_dir"));
PASS();
}
TEST(platform_file_size) {
int64_t sz = cbm_file_size("tests/test_platform.c");
ASSERT_GT(sz, 0);
ASSERT_EQ(cbm_file_size("nonexistent_file_xyz.txt"), -1);
PASS();
}
TEST(platform_mmap) {
/* mmap this test file and verify first bytes */
size_t sz = 0;
void *data = cbm_mmap_read("tests/test_platform.c", &sz);
ASSERT_NOT_NULL(data);
ASSERT_GT(sz, 0);
/* First line should be the comment */
ASSERT(memcmp(data, "/*", 2) == 0);
cbm_munmap(data, sz);
PASS();
}
TEST(platform_mmap_nonexistent) {
size_t sz = 0;
void *data = cbm_mmap_read("nonexistent_xyz.txt", &sz);
ASSERT_NULL(data);
PASS();
}
SUITE(platform) {
RUN_TEST(platform_now_ns);
RUN_TEST(platform_now_ms);
RUN_TEST(platform_nprocs);
RUN_TEST(platform_file_exists);
RUN_TEST(platform_is_dir);
RUN_TEST(platform_file_size);
RUN_TEST(platform_mmap);
RUN_TEST(platform_mmap_nonexistent);
}