diff options
author | Mitya Selivanov <automainint@guattari.tech> | 2025-04-16 20:12:57 +0200 |
---|---|---|
committer | Mitya Selivanov <automainint@guattari.tech> | 2025-04-16 20:12:57 +0200 |
commit | 84c1df59c4857eeaa0d209ab08f983fac20d38db (patch) | |
tree | 61e760b8f73f82dceec829b41feec3916d327b4d | |
parent | e748e39c669506cfcb2eb8f2549dfd201d6a6b53 (diff) | |
download | reduced_system_layer-84c1df59c4857eeaa0d209ab08f983fac20d38db.zip |
Testing
-rwxr-xr-x | reduced_system_layer.c | 65 | ||||
-rwxr-xr-x | run_tests.c | 37 |
2 files changed, 89 insertions, 13 deletions
diff --git a/reduced_system_layer.c b/reduced_system_layer.c index 0240f08..a81e02d 100755 --- a/reduced_system_layer.c +++ b/reduced_system_layer.c @@ -273,6 +273,10 @@ i32 main(i32 argc, c8 **argv); #define ENABLE_X11 1 #endif +#ifndef ENABLE_ALSA +#define ENABLE_ALSA 1 +#endif + #ifndef STATIC_MEMORY_BUFFER_SIZE #define STATIC_MEMORY_BUFFER_SIZE (400 * 1024 * 1024) #endif @@ -1604,6 +1608,24 @@ void PROFILER_end(u32 slot) { normalize_time_(&_profiler_slots[slot].time_sec, &_profiler_slots[slot].time_nsec); } +void PROFILER_report_(void) { + // TODO: Implement printing for WebAssembly. + +#if !defined(__wasm__) + if (_profiler_num_slots > 0) { + printf("\nPROFILER REPORT\n\n"); + for (i64 i = 0; i < _profiler_num_slots; ++i) { + if (_profiler_slots[i].name == NULL || _profiler_slots[i].amount == 0) + continue; + f64 k = _profiler_slots[i].amount == 0 ? 0. : 1. / _profiler_slots[i].amount; + f64 f = ((f64) _profiler_slots[i].time_sec) * k + ((f64 )_profiler_slots[i].time_nsec * .000000001) * k; + printf("%-31s %3lld.%09lld / %4lld = %.6f\n", _profiler_slots[i].name, _profiler_slots[i].time_sec, _profiler_slots[i].time_nsec, _profiler_slots[i].amount, f); + } + printf("\n"); + } +#endif +} + // ================================================================ // // Platform @@ -2358,7 +2380,7 @@ i64 network_send(u16 slot, Network_Address address, i64 size, u8 *data, u16 *loc // // ================================================================ -#if defined(__linux__) +#if defined(__linux__) && ENABLE_ALSA #include <alsa/asoundlib.h> @@ -2526,7 +2548,7 @@ void queue_primary_sound(i64 delay_in_samples, i64 num_samples, f32 *frames) { } } -#endif // defined(__linux__) +#endif // defined(__linux__) && ENABLE_ALSA // ================================================================ // @@ -3399,17 +3421,7 @@ void init_main_window(void) { } void shutdown_all_systems(void) { - if (_profiler_num_slots > 0) { - printf("\nPROFILER REPORT\n\n"); - for (i64 i = 0; i < _profiler_num_slots; ++i) { - if (_profiler_slots[i].name == NULL || _profiler_slots[i].amount == 0) - continue; - f64 k = _profiler_slots[i].amount == 0 ? 0. : 1. / _profiler_slots[i].amount; - f64 f = ((f64) _profiler_slots[i].time_sec) * k + ((f64 )_profiler_slots[i].time_nsec * .000000001) * k; - printf("%-31s %3lld.%09lld / %4lld = %.6f\n", _profiler_slots[i].name, _profiler_slots[i].time_sec, _profiler_slots[i].time_nsec, _profiler_slots[i].amount, f); - } - printf("\n"); - } + PROFILER_report_(); g_platform.done = 1; @@ -4599,6 +4611,33 @@ __attribute__((export_name("js_drop_data"))) void *js_drop_data(void) { // ================================================================ // +// No system +// +// ================================================================ + +#if !defined(__linux__) || !ENABLE_X11 || !ENABLE_WAYLAND +void init_main_window(void) { + LOG_ERROR("Not implemented."); +} + +void update_and_render_frame(void) { + LOG_ERROR("Not implemented."); +} + +void shutdown_all_systems(void) { + // TODO: Factor out common code. + + PROFILER_report_(); + + g_platform.done = 1; +} +#endif + +#if !defined(__linux__) || !ENABLE_ALSA +#endif + +// ================================================================ +// // Test suite // // ================================================================ diff --git a/run_tests.c b/run_tests.c new file mode 100755 index 0000000..38f6461 --- /dev/null +++ b/run_tests.c @@ -0,0 +1,37 @@ +#if 0 /* +SRC=${0##*./} +BIN=${SRC%.*} +gcc \ + -Wall -Wextra -Werror -pedantic \ + -Wno-missing-braces \ + -Wno-old-style-declaration \ + -Wno-overlength-strings \ + -Wno-unused-parameter \ + -Wno-unused-variable \ + -Wno-unused-but-set-variable \ + -Wno-unused-function \ + -O3 -D NDEBUG \ + -fsanitize=undefined,address,leak \ + -lm \ + -o $BIN $SRC && \ + ./$BIN $@ +STATUS=$? +rm -f $BIN +exit $STATUS # */ +#endif + +#ifndef EVERY_TEST_SUITE +#define EVERY_TEST_SUITE +#endif + +#define ENABLE_X11 0 +#define ENABLE_WAYLAND 0 +#define ENABLE_ALSA 0 + +#include "reduced_system_layer.c" +#include "graphics.c" +#include "stackless_coroutine.c" + +i32 main(i32 argc, c8 **argv) { + return run_tests(argc, argv); +} |