summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-x[-rw-r--r--]graphics.c148
-rw-r--r--reduced_system_layer.c2
-rw-r--r--test.c23
3 files changed, 159 insertions, 14 deletions
diff --git a/graphics.c b/graphics.c
index 1650d32..bc49267 100644..100755
--- a/graphics.c
+++ b/graphics.c
@@ -1,13 +1,42 @@
-// ================================================================
-//
-// graphics.c
-//
-// ----------------------------------------------------------------
-//
-// (C) 2025 Mitya Selivanov <guattari.tech>
-//
+#if 0 /*
+#/ ================================================================
+#/
+#/ graphics.c
+#/
+#/ ----------------------------------------------------------------
+#/
+#/ (C) 2025 Mitya Selivanov <guattari.tech>
+#/
+#/ ================================================================
+#/
+#/ Self-testing shell script
+#/
+#/ ================================================================
+SRC=${0##*./}
+BIN=${SRC%.*}
+gcc \
+ -Wall -Wextra -Werror -pedantic \
+ -Wno-old-style-declaration \
+ -Wno-missing-braces \
+ -Wno-unused-variable \
+ -Wno-unused-but-set-variable \
+ -Wno-unused-parameter \
+ -Wno-overlength-strings \
+ -O3 -D NDEBUG \
+ -D GRAPHICS_TEST_SUITE \
+ -lX11 -lm -lasound \
+ -o $BIN $SRC && \
+ ./$BIN $@
+STATUS=$?
+rm -f $BIN
+exit $? # */
+#endif
// ================================================================
+#ifdef EVERY_TEST_SUITE
+#define GRAPHICS_TEST_SUITE
+#endif
+
#ifndef GRAPHICS_HEADER_GUARD_
#define GRAPHICS_HEADER_GUARD_
@@ -1449,5 +1478,108 @@ void draw_text_cursor(Brush brush, f64 x, f64 y, f64 width, f64 height, f64 max_
);
}
+// ================================================================
+//
+// Test suite
+//
+// ================================================================
+
+#ifdef GRAPHICS_TEST_SUITE
+
+#define TEST_FILE graphics
+#include "test.c"
+
+vec4_f32 g_pixels[MAX_NUM_PIXELS] = {0};
+
+Brush brush = {
+ .buffer = {
+ .width = 1280,
+ .height = 720,
+ .line_size = 1280,
+ .pixels = g_pixels,
+ },
+ .position = { 0.f, 0.f, },
+ .scale = { 1.f, 1.f, },
+ .color = { 1.f, 1.f, 1.f, 1.f },
+};
+
+BENCHMARK("fill rectangle") {
+ BENCHMARK_BEGIN;
+ {
+ fill_rectangle(brush, 100, 100, 300, 200);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("fill triangle") {
+ BENCHMARK_BEGIN;
+ {
+ fill_triangle(brush, 100, 100, 300, 100, 200, 250);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("fill quad") {
+ BENCHMARK_BEGIN;
+ {
+ fill_quad(brush, 100, 100, 300, 100, 300, 200, 100, 200);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("fill ellipse") {
+ BENCHMARK_BEGIN;
+ {
+ fill_ellipse(brush, 80, 80, 340, 240);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("fill line") {
+ BENCHMARK_BEGIN;
+ {
+ fill_line(brush, 100, 100, 300, 200, 40);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+BENCHMARK("draw text area") {
+ BENCHMARK_BEGIN;
+ {
+ c32 text[] = { 'H', 'e', 'l', 'l', 'o', ',', ' ', 'S', 'a', 'i', 'l', 'o', 'r', '!', };
+ draw_text_area(brush, 100, 100, 300, 200, 100, 200, sizeof text / sizeof *text, text);
+ }
+ BENCHMARK_END;
+
+ for (i64 i = 0; i < MAX_NUM_PIXELS; ++i)
+ g_pixels[i] = (vec4_f32) {0};
+}
+
+void update_and_render_frame(void) {}
+
+i32 main(i32 argc, c8 **argv) {
+ return run_tests_and_benchmarks(argc, argv);
+}
+
+#undef TEST_FILE
+#endif // GRAPHICS_TEST_SUITE
+
+// ================================================================
+
#endif // GRAPHICS_IMPL_GUARD_
#endif // GRAPHICS_HEADER
diff --git a/reduced_system_layer.c b/reduced_system_layer.c
index a1bac25..50f3452 100644
--- a/reduced_system_layer.c
+++ b/reduced_system_layer.c
@@ -2690,7 +2690,7 @@ __attribute__((export_name("js_drop_buffer"))) void *js_drop_buffer(void) {
}
__attribute__((export_name("js_drop"))) void js_drop(i32 name_len, i32 data_size) {
- if (name_len + data_size > sizeof _drop_buffer) {
+ if (name_len + data_size > (i32) sizeof _drop_buffer) {
LOG_ERROR("File too big.");
return;
}
diff --git a/test.c b/test.c
index fc6088f..8ae0af6 100644
--- a/test.c
+++ b/test.c
@@ -47,6 +47,8 @@
//
// ================================================================
+#if !defined(__wasm__)
+
#ifndef TYPES_HEADER_GUARD_
#define TYPES_HEADER_GUARD_
@@ -97,9 +99,6 @@ typedef struct { f64 v[16]; } mat4;
extern "C" {
#endif
-#include <stddef.h>
-#include <stdint.h>
-
#ifndef TEST_FILE
#define TEST_FILE test
#endif
@@ -269,7 +268,8 @@ void bench_register(c8 const *name, c8 const *file, bench_run_fn fn);
(void) bench_ptr_; \
} while (0)
-i32 run_benchmarks(i32 argc, c8 **argv);
+i32 run_benchmarks (i32 argc, c8 **argv);
+i32 run_tests_and_benchmarks(i32 argc, c8 **argv);
#ifdef __cplusplus
}
@@ -461,6 +461,9 @@ i32 run_tests(i32 argc, c8 **argv) {
if (s[i] == '/' || s[i] == '\\')
file_root = i + 1;
}
+
+ if (file_root == -1)
+ file_root = 0;
}
for (i = 0; i < tests_list.size && i < MAX_NUM_TESTS; i++) {
@@ -799,6 +802,9 @@ i32 run_benchmarks(i32 argc, c8 **argv) {
if (s[i] == '/' || s[i] == '\\')
file_root = i + 1;
}
+
+ if (file_root == -1)
+ file_root = 0;
}
no_color || print_color_(blue_);
@@ -840,7 +846,6 @@ i32 run_benchmarks(i32 argc, c8 **argv) {
benchs_list.v[i].ready = 1;
}
-
// Run cycles.
//
@@ -995,5 +1000,13 @@ i32 run_benchmarks(i32 argc, c8 **argv) {
return status;
}
+i32 run_tests_and_benchmarks(i32 argc, c8 **argv) {
+ i32 s = run_tests (argc, argv);
+ if (s == 0) s = run_benchmarks(argc, argv);
+ return s;
+}
+
#endif // TEST_IMPL_GUARD_
#endif // TEST_HEADER
+
+#endif // !defined(__wasm__)