meta: re-organise tests
This commit is contained in:
+5
-3
@@ -1,5 +1,5 @@
|
|||||||
cmake_minimum_required(VERSION 3.25)
|
cmake_minimum_required(VERSION 3.25)
|
||||||
project(fx C)
|
project(fx C ASM)
|
||||||
|
|
||||||
include (TestBigEndian)
|
include (TestBigEndian)
|
||||||
|
|
||||||
@@ -35,8 +35,10 @@ message(STATUS "Floating point support: ${fx_enable_floating_point}")
|
|||||||
|
|
||||||
set(fx_system_name ${CMAKE_SYSTEM_NAME})
|
set(fx_system_name ${CMAKE_SYSTEM_NAME})
|
||||||
string(TOLOWER ${fx_system_name} fx_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_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/lib)
|
||||||
set(CMAKE_LIBRARY_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})
|
add_subdirectory(assemblies/${assembly})
|
||||||
endforeach (assembly)
|
endforeach (assembly)
|
||||||
|
|
||||||
add_executable(dynamic-test test/dynamic-test.c)
|
add_subdirectory(test)
|
||||||
|
|||||||
@@ -80,7 +80,10 @@ macro(export_fx_namespace_details ns_name)
|
|||||||
|
|
||||||
file(GLOB sys_sources
|
file(GLOB sys_sources
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/sys/${fx_system_name}/*.c
|
${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)
|
file(GLOB headers include/${namespace_path}/*.h)
|
||||||
set(namespace_sources
|
set(namespace_sources
|
||||||
${namespace_sources}
|
${namespace_sources}
|
||||||
@@ -89,8 +92,12 @@ macro(export_fx_namespace_details ns_name)
|
|||||||
${sys_sources}
|
${sys_sources}
|
||||||
${headers}
|
${headers}
|
||||||
PARENT_SCOPE)
|
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_libs ${internal_libs} PARENT_SCOPE)
|
||||||
set(internal_include_dirs ${internal_include_dirs} PARENT_SCOPE)
|
|
||||||
set(internal_defines ${internal_defines} PARENT_SCOPE)
|
set(internal_defines ${internal_defines} PARENT_SCOPE)
|
||||||
endmacro(export_fx_namespace_details)
|
endmacro(export_fx_namespace_details)
|
||||||
|
|
||||||
|
|||||||
@@ -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)
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
#include <dlfcn.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
#include <fx/core/stream.h>
|
|
||||||
#include <fx/core/stringstream.h>
|
|
||||||
#include <fx/ds/string.h>
|
|
||||||
#include <fx/io/file.h>
|
#include <fx/io/file.h>
|
||||||
#include <fx/io/path.h>
|
#include <fx/io/path.h>
|
||||||
|
#include <fx/stream.h>
|
||||||
|
#include <fx/string.h>
|
||||||
|
#include <fx/stringstream.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
|
|||||||
+3
-3
@@ -1,8 +1,8 @@
|
|||||||
#include <fx/core/stream.h>
|
|
||||||
#include <fx/core/stringstream.h>
|
|
||||||
#include <fx/ds/string.h>
|
|
||||||
#include <fx/io/file.h>
|
#include <fx/io/file.h>
|
||||||
#include <fx/io/path.h>
|
#include <fx/io/path.h>
|
||||||
|
#include <fx/stream.h>
|
||||||
|
#include <fx/string.h>
|
||||||
|
#include <fx/stringstream.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
int main(int argc, const char **argv)
|
int main(int argc, const char **argv)
|
||||||
|
|||||||
@@ -0,0 +1,30 @@
|
|||||||
|
#include <fx/reflection/function.h>
|
||||||
|
#include <fx/value.h>
|
||||||
|
#include <inttypes.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
+42
-14
@@ -1,22 +1,50 @@
|
|||||||
#include <dlfcn.h>
|
#include <fx/reflection/function.h>
|
||||||
|
#include <fx/value.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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)
|
int main(int argc, const char **argv)
|
||||||
{
|
{
|
||||||
printf("dynamic loader\n");
|
fx_value_type arg_types[] = {
|
||||||
void *assembly = dlopen(argv[1], RTLD_LAZY);
|
FX_VALUE_TYPE_INT,
|
||||||
if (!assembly) {
|
FX_VALUE_TYPE_DOUBLE,
|
||||||
printf("cannot load %s\n", argv[1]);
|
FX_VALUE_TYPE_INT,
|
||||||
return -1;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
const void *(*asm_info)(void) = dlsym(assembly, "__fx_assembly_get");
|
fx_function *func = fx_function_create(
|
||||||
if (!asm_info) {
|
"test_function",
|
||||||
printf("cannot find assembly info for %s", argv[1]);
|
FX_FUNCTION_F_VARARG,
|
||||||
return -1;
|
(fx_function_impl)test_function,
|
||||||
}
|
arg_types,
|
||||||
|
3,
|
||||||
|
FX_VALUE_TYPE_DOUBLE);
|
||||||
|
|
||||||
asm_info();
|
fx_value args[] = {
|
||||||
printf("OK\n");
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,40 @@
|
|||||||
|
#include <stdarg.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user