From 18c9d30c60c9df9b14e4333ddfdd15e25afa4ae3 Mon Sep 17 00:00:00 2001 From: Max Wash Date: Mon, 4 May 2026 16:37:06 +0100 Subject: [PATCH] meta: re-organise tests --- CMakeLists.txt | 8 ++- cmake/Templates.cmake | 11 +++- {test/cmd => fx.cmdline/test}/example.c | 0 {test/ds => fx.collections/test}/arrays.c | 0 {test/ds => fx.collections/test}/numbers.c | 0 {test/ds => fx.collections/test}/simple.c | 0 {test/ds => fx.collections/test}/streams.c | 0 {test/ds => fx.collections/test}/strings.c | 0 {test/ds => fx.collections/test}/trees.c | 0 .../test}/unicode-strings.c | 0 .../test/unit-tests.c | 0 {test/ds => fx.collections/test}/uuids.c | 0 .../test}/mix-compress.c | 0 .../test}/mix-decompress.c | 0 .../test}/simple1.c | 0 .../compress => fx.compression/test}/stream.c | 0 {test/io => fx.io/test}/mkdir.c | 0 {test/io => fx.io/test}/rmdir.c | 0 {test/io => fx.io/test}/streams.c | 0 {test/io => fx.io/test}/tree.c | 0 test/io/io-units.c => fx.io/test/unit-tests.c | 0 {test/serial => fx.serial/test}/streams.c | 0 {test/serial => fx.serial/test}/toml-decode.c | 0 {test/serial => fx.serial/test}/toml-encode.c | 0 {test/term => fx.term/test}/errors.c | 0 {test/term => fx.term/test}/printing.c | 0 {test/core => fx/test}/errors.c | 0 {test/core => fx/test}/hash.c | 0 {test/core => fx/test}/randomise.c | 0 {test/core => fx/test}/ringbuffers.c | 0 {test/core => fx/test}/ropes.c | 0 {test/core => fx/test}/streams.c | 0 .../core/core-units.c => fx/test/unit-tests.c | 0 test/CMakeLists.txt | 7 +++ test/assembly-info.c | 22 ++++++++ test/cat.c | 6 +- test/cat1.c | 6 +- test/dynamic-printf.c | 30 ++++++++++ test/dynamic-test.c | 56 ++++++++++++++----- test/hello.c | 40 +++++++++++++ 40 files changed, 161 insertions(+), 25 deletions(-) rename {test/cmd => fx.cmdline/test}/example.c (100%) rename {test/ds => fx.collections/test}/arrays.c (100%) rename {test/ds => fx.collections/test}/numbers.c (100%) rename {test/ds => fx.collections/test}/simple.c (100%) rename {test/ds => fx.collections/test}/streams.c (100%) rename {test/ds => fx.collections/test}/strings.c (100%) rename {test/ds => fx.collections/test}/trees.c (100%) rename {test/ds => fx.collections/test}/unicode-strings.c (100%) rename test/ds/ds-units.c => fx.collections/test/unit-tests.c (100%) rename {test/ds => fx.collections/test}/uuids.c (100%) rename {test/compress => fx.compression/test}/mix-compress.c (100%) rename {test/compress => fx.compression/test}/mix-decompress.c (100%) rename {test/compress => fx.compression/test}/simple1.c (100%) rename {test/compress => fx.compression/test}/stream.c (100%) rename {test/io => fx.io/test}/mkdir.c (100%) rename {test/io => fx.io/test}/rmdir.c (100%) rename {test/io => fx.io/test}/streams.c (100%) rename {test/io => fx.io/test}/tree.c (100%) rename test/io/io-units.c => fx.io/test/unit-tests.c (100%) rename {test/serial => fx.serial/test}/streams.c (100%) rename {test/serial => fx.serial/test}/toml-decode.c (100%) rename {test/serial => fx.serial/test}/toml-encode.c (100%) rename {test/term => fx.term/test}/errors.c (100%) rename {test/term => fx.term/test}/printing.c (100%) rename {test/core => fx/test}/errors.c (100%) rename {test/core => fx/test}/hash.c (100%) rename {test/core => fx/test}/randomise.c (100%) rename {test/core => fx/test}/ringbuffers.c (100%) rename {test/core => fx/test}/ropes.c (100%) rename {test/core => fx/test}/streams.c (100%) rename test/core/core-units.c => fx/test/unit-tests.c (100%) create mode 100644 test/CMakeLists.txt create mode 100644 test/assembly-info.c create mode 100644 test/dynamic-printf.c create mode 100644 test/hello.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bcbaf0..4890a41 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.25) -project(fx C) +project(fx C ASM) include (TestBigEndian) @@ -35,8 +35,10 @@ message(STATUS "Floating point support: ${fx_enable_floating_point}") set(fx_system_name ${CMAKE_SYSTEM_NAME}) string(TOLOWER ${fx_system_name} fx_system_name) +set(fx_system_arch ${CMAKE_SYSTEM_PROCESSOR}) +string(TOLOWER ${fx_system_arch} fx_system_arch) -message(STATUS "System name: ${fx_system_name}") +message(STATUS "Target system: ${fx_system_name}-${fx_system_arch}") set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib) @@ -48,4 +50,4 @@ foreach (assembly ${fx_assemblies}) add_subdirectory(assemblies/${assembly}) endforeach (assembly) -add_executable(dynamic-test test/dynamic-test.c) +add_subdirectory(test) diff --git a/cmake/Templates.cmake b/cmake/Templates.cmake index 47f25a0..2cfa27d 100644 --- a/cmake/Templates.cmake +++ b/cmake/Templates.cmake @@ -80,7 +80,10 @@ macro(export_fx_namespace_details ns_name) file(GLOB sys_sources ${CMAKE_CURRENT_SOURCE_DIR}/sys/${fx_system_name}/*.c - ${CMAKE_CURRENT_SOURCE_DIR}/sys/${fx_system_name}/*.h) + ${CMAKE_CURRENT_SOURCE_DIR}/sys/${fx_system_name}/*.h + ${CMAKE_CURRENT_SOURCE_DIR}/sys/${fx_system_name}/${fx_system_arch}/*.c + ${CMAKE_CURRENT_SOURCE_DIR}/sys/${fx_system_name}/${fx_system_arch}/*.h + ${CMAKE_CURRENT_SOURCE_DIR}/sys/${fx_system_name}/${fx_system_arch}/*.S) file(GLOB headers include/${namespace_path}/*.h) set(namespace_sources ${namespace_sources} @@ -89,8 +92,12 @@ macro(export_fx_namespace_details ns_name) ${sys_sources} ${headers} PARENT_SCOPE) + set(internal_include_dirs + ${internal_include_dirs} + ${CMAKE_CURRENT_SOURCE_DIR}/sys/${fx_system_name}/include + ${CMAKE_CURRENT_SOURCE_DIR}/sys/${fx_system_name}/${fx_system_arch}/include + PARENT_SCOPE) set(internal_libs ${internal_libs} PARENT_SCOPE) - set(internal_include_dirs ${internal_include_dirs} PARENT_SCOPE) set(internal_defines ${internal_defines} PARENT_SCOPE) endmacro(export_fx_namespace_details) diff --git a/test/cmd/example.c b/fx.cmdline/test/example.c similarity index 100% rename from test/cmd/example.c rename to fx.cmdline/test/example.c diff --git a/test/ds/arrays.c b/fx.collections/test/arrays.c similarity index 100% rename from test/ds/arrays.c rename to fx.collections/test/arrays.c diff --git a/test/ds/numbers.c b/fx.collections/test/numbers.c similarity index 100% rename from test/ds/numbers.c rename to fx.collections/test/numbers.c diff --git a/test/ds/simple.c b/fx.collections/test/simple.c similarity index 100% rename from test/ds/simple.c rename to fx.collections/test/simple.c diff --git a/test/ds/streams.c b/fx.collections/test/streams.c similarity index 100% rename from test/ds/streams.c rename to fx.collections/test/streams.c diff --git a/test/ds/strings.c b/fx.collections/test/strings.c similarity index 100% rename from test/ds/strings.c rename to fx.collections/test/strings.c diff --git a/test/ds/trees.c b/fx.collections/test/trees.c similarity index 100% rename from test/ds/trees.c rename to fx.collections/test/trees.c diff --git a/test/ds/unicode-strings.c b/fx.collections/test/unicode-strings.c similarity index 100% rename from test/ds/unicode-strings.c rename to fx.collections/test/unicode-strings.c diff --git a/test/ds/ds-units.c b/fx.collections/test/unit-tests.c similarity index 100% rename from test/ds/ds-units.c rename to fx.collections/test/unit-tests.c diff --git a/test/ds/uuids.c b/fx.collections/test/uuids.c similarity index 100% rename from test/ds/uuids.c rename to fx.collections/test/uuids.c diff --git a/test/compress/mix-compress.c b/fx.compression/test/mix-compress.c similarity index 100% rename from test/compress/mix-compress.c rename to fx.compression/test/mix-compress.c diff --git a/test/compress/mix-decompress.c b/fx.compression/test/mix-decompress.c similarity index 100% rename from test/compress/mix-decompress.c rename to fx.compression/test/mix-decompress.c diff --git a/test/compress/simple1.c b/fx.compression/test/simple1.c similarity index 100% rename from test/compress/simple1.c rename to fx.compression/test/simple1.c diff --git a/test/compress/stream.c b/fx.compression/test/stream.c similarity index 100% rename from test/compress/stream.c rename to fx.compression/test/stream.c diff --git a/test/io/mkdir.c b/fx.io/test/mkdir.c similarity index 100% rename from test/io/mkdir.c rename to fx.io/test/mkdir.c diff --git a/test/io/rmdir.c b/fx.io/test/rmdir.c similarity index 100% rename from test/io/rmdir.c rename to fx.io/test/rmdir.c diff --git a/test/io/streams.c b/fx.io/test/streams.c similarity index 100% rename from test/io/streams.c rename to fx.io/test/streams.c diff --git a/test/io/tree.c b/fx.io/test/tree.c similarity index 100% rename from test/io/tree.c rename to fx.io/test/tree.c diff --git a/test/io/io-units.c b/fx.io/test/unit-tests.c similarity index 100% rename from test/io/io-units.c rename to fx.io/test/unit-tests.c diff --git a/test/serial/streams.c b/fx.serial/test/streams.c similarity index 100% rename from test/serial/streams.c rename to fx.serial/test/streams.c diff --git a/test/serial/toml-decode.c b/fx.serial/test/toml-decode.c similarity index 100% rename from test/serial/toml-decode.c rename to fx.serial/test/toml-decode.c diff --git a/test/serial/toml-encode.c b/fx.serial/test/toml-encode.c similarity index 100% rename from test/serial/toml-encode.c rename to fx.serial/test/toml-encode.c diff --git a/test/term/errors.c b/fx.term/test/errors.c similarity index 100% rename from test/term/errors.c rename to fx.term/test/errors.c diff --git a/test/term/printing.c b/fx.term/test/printing.c similarity index 100% rename from test/term/printing.c rename to fx.term/test/printing.c diff --git a/test/core/errors.c b/fx/test/errors.c similarity index 100% rename from test/core/errors.c rename to fx/test/errors.c diff --git a/test/core/hash.c b/fx/test/hash.c similarity index 100% rename from test/core/hash.c rename to fx/test/hash.c diff --git a/test/core/randomise.c b/fx/test/randomise.c similarity index 100% rename from test/core/randomise.c rename to fx/test/randomise.c diff --git a/test/core/ringbuffers.c b/fx/test/ringbuffers.c similarity index 100% rename from test/core/ringbuffers.c rename to fx/test/ringbuffers.c diff --git a/test/core/ropes.c b/fx/test/ropes.c similarity index 100% rename from test/core/ropes.c rename to fx/test/ropes.c diff --git a/test/core/streams.c b/fx/test/streams.c similarity index 100% rename from test/core/streams.c rename to fx/test/streams.c diff --git a/test/core/core-units.c b/fx/test/unit-tests.c similarity index 100% rename from test/core/core-units.c rename to fx/test/unit-tests.c diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt new file mode 100644 index 0000000..6847509 --- /dev/null +++ b/test/CMakeLists.txt @@ -0,0 +1,7 @@ +file(GLOB test_sources *.c) + +foreach (f ${test_sources}) + get_filename_component(test_name ${f} NAME_WLE) + add_executable(${test_name} ${f}) + target_link_libraries(${test_name} ${fx_assemblies}) +endforeach (f) diff --git a/test/assembly-info.c b/test/assembly-info.c new file mode 100644 index 0000000..e7f3d2c --- /dev/null +++ b/test/assembly-info.c @@ -0,0 +1,22 @@ +#include +#include + +int main(int argc, const char **argv) +{ + printf("dynamic loader\n"); + void *assembly = dlopen(argv[1], RTLD_LAZY); + if (!assembly) { + printf("cannot load %s\n", argv[1]); + return -1; + } + + const void *(*asm_info)(void) = dlsym(assembly, "__fx_assembly_get"); + if (!asm_info) { + printf("cannot find assembly info for %s", argv[1]); + return -1; + } + + asm_info(); + printf("OK\n"); + return 0; +} diff --git a/test/cat.c b/test/cat.c index 943b561..142a38d 100644 --- a/test/cat.c +++ b/test/cat.c @@ -1,8 +1,8 @@ -#include -#include -#include #include #include +#include +#include +#include #include int main(int argc, const char **argv) diff --git a/test/cat1.c b/test/cat1.c index 5e62beb..11e9a2c 100644 --- a/test/cat1.c +++ b/test/cat1.c @@ -1,8 +1,8 @@ -#include -#include -#include #include #include +#include +#include +#include #include int main(int argc, const char **argv) diff --git a/test/dynamic-printf.c b/test/dynamic-printf.c new file mode 100644 index 0000000..a78bb21 --- /dev/null +++ b/test/dynamic-printf.c @@ -0,0 +1,30 @@ +#include +#include +#include +#include + +int main(int argc, const char **argv) +{ + fx_value_type arg_types[] = { + FX_VALUE_TYPE_CSTR, + }; + + fx_function *func = fx_function_create( + "test_function", + FX_FUNCTION_F_VARARG, + (fx_function_impl)printf, + arg_types, + 1, + FX_VALUE_TYPE_INT); + + fx_value args[] = { + FX_VALUE_CSTR("Hello %s! You are number %lf\n"), + FX_VALUE_CSTR("Jonh"), + FX_VALUE_DOUBLE(2.5), + }; + + fx_value result = FX_VALUE_EMPTY; + int r = fx_function_invoke(func, args, 3, &result); + printf("%" PRIdPTR "\n", result.v_int); + return 0; +} diff --git a/test/dynamic-test.c b/test/dynamic-test.c index e7f3d2c..9bbbbe3 100644 --- a/test/dynamic-test.c +++ b/test/dynamic-test.c @@ -1,22 +1,50 @@ -#include +#include +#include #include +static double test_function(int a, double b, int c, ...) +{ +#if 1 + va_list args; + va_start(args, c); + int d = va_arg(args, int); + double e = va_arg(args, double); + int f = va_arg(args, int); + printf("a=%d, b=%lf, c=%d, d=%d, e=%lf, f=%d\n", a, b, c, d, e, f); + return (a + b + c + d + e + f) + 0.5; +#else + printf("a=%d, b=%lf, c=%d\n", a, b, c); + return 32; +#endif +} + int main(int argc, const char **argv) { - printf("dynamic loader\n"); - void *assembly = dlopen(argv[1], RTLD_LAZY); - if (!assembly) { - printf("cannot load %s\n", argv[1]); - return -1; - } + fx_value_type arg_types[] = { + FX_VALUE_TYPE_INT, + FX_VALUE_TYPE_DOUBLE, + FX_VALUE_TYPE_INT, + }; - const void *(*asm_info)(void) = dlsym(assembly, "__fx_assembly_get"); - if (!asm_info) { - printf("cannot find assembly info for %s", argv[1]); - return -1; - } + fx_function *func = fx_function_create( + "test_function", + FX_FUNCTION_F_VARARG, + (fx_function_impl)test_function, + arg_types, + 3, + FX_VALUE_TYPE_DOUBLE); - asm_info(); - printf("OK\n"); + fx_value args[] = { + FX_VALUE_INT(1), + FX_VALUE_DOUBLE(2.5), + FX_VALUE_INT(3), + FX_VALUE_INT(4), + FX_VALUE_DOUBLE(5.5), + FX_VALUE_INT(6), + }; + + fx_value result = FX_VALUE_EMPTY; + int r = fx_function_invoke(func, args, 6, &result); + printf("%lf\n", result.v_double); return 0; } diff --git a/test/hello.c b/test/hello.c new file mode 100644 index 0000000..5b88f72 --- /dev/null +++ b/test/hello.c @@ -0,0 +1,40 @@ +#include +#include + +static double another_function(int a, double b, int c) +{ + printf("a=%d, b=%lf, c=%d\n", a, b, c); + return 1.2; +} + +static int test_function(int a, int b, int c, ...) +{ + va_list args; + va_start(args, c); + int d = va_arg(args, int); + int e = va_arg(args, int); + int f = va_arg(args, int); + int g = va_arg(args, int); + int h = va_arg(args, int); + int i = va_arg(args, int); + int j = va_arg(args, int); + printf("a=%d, b=%d, c=%d, d=%d, e=%d, f=%d, g=%d, h=%d, i=%d, j=%d\n", + a, + b, + c, + d, + e, + f, + g, + h, + i, + j); + return a + b + c + d + e; +} + +int main(void) +{ + test_function(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); + another_function(1, 2.5, 5); + return 0; +}