diff options
-rw-r--r-- | CMakeLists.txt | 29 | ||||
-rw-r--r-- | GNUmakefile | 1 | ||||
-rw-r--r-- | libcr/CMakeLists.txt | 27 | ||||
-rw-r--r-- | libcr/coroutine.c | 16 | ||||
-rw-r--r-- | libcr/tests/test_matrix.c | 20 | ||||
-rw-r--r-- | libcr/tests/test_matrix/config.h | 14 |
6 files changed, 99 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 4bffff9..4082d53 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -94,6 +94,35 @@ function(add_lib_test arg_libname arg_testname) endif() endfunction() +function(_apply_matrix_helper _m_depth _m_assignments) + list(LENGTH _m_arg_matrix _m_dimensions) + math(EXPR _m_dimensions ${_m_dimensions}/2) + if("${_m_depth}" EQUAL "${_m_dimensions}") + cmake_language(CALL "${_m_arg_action}" "${_m_n}" "${_m_assignments}") + math(EXPR _m_n "${_m_n}+1") + set(_m_n "${_m_n}" PARENT_SCOPE) + else() + math(EXPR _m_ik "${_m_depth}*2") + list(GET _m_arg_matrix "${_m_ik}" _m_tmp_key) + + math(EXPR _m_iv "${_m_ik}+1") + list(GET _m_arg_matrix "${_m_iv}" _m_tmp_vals) + string(REGEX REPLACE "^\\[(.*)\\]$" "\\1" _m_tmp_vals "${_m_tmp_vals}") + + foreach(_m_tmp_val IN LISTS _m_tmp_vals) + math(EXPR _m_tmp_depth "${_m_depth}+1") + set(_m_tmp_assignments "${_m_assignments}") + list(APPEND _m_tmp_assignments "${_m_tmp_key}=${_m_tmp_val}") + _apply_matrix_helper("${_m_tmp_depth}" "${_m_tmp_assignments}") + set(_m_n "${_m_n}" PARENT_SCOPE) + endforeach() + endif() +endfunction() +function(apply_matrix _m_arg_action _m_arg_matrix) + set(_m_n 0) + _apply_matrix_helper(0 "") +endfunction() + add_subdirectory(libmisc) add_subdirectory(libcr) add_subdirectory(libcr_ipc) diff --git a/GNUmakefile b/GNUmakefile index 518f8d6..9ebbe86 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -131,6 +131,7 @@ lint/all: lint/%: dscname_act=$$($(get_dscname) $$filename); \ dscname_exp=$$(echo "$$filename" | sed \ -e 's,.*/config/,,' \ + -e 's,.*/config\.h$$,config.h,' \ -e 's,.*include/,,' \ -e 's,^lib9p/idl/,,' \ -e 's/\.wip$$//'); \ diff --git a/libcr/CMakeLists.txt b/libcr/CMakeLists.txt index fbc7618..7f18e17 100644 --- a/libcr/CMakeLists.txt +++ b/libcr/CMakeLists.txt @@ -14,3 +14,30 @@ target_link_libraries(libcr INTERFACE target_compile_options(libcr INTERFACE -fno-split-stack ) + +set(cfg_matrix + "CONFIG_COROUTINE_MEASURE_STACK;[0;1]" + "CONFIG_COROUTINE_PROTECT_STACK;[0;1]" + "CONFIG_COROUTINE_DEBUG;[0;1]" + "CONFIG_COROUTINE_VALGRIND;[0;1]" +) +function(add_libcr_matrix_test n defs) + add_executable("test_matrix${n}" "tests/test_matrix.c") + target_link_libraries("test_matrix${n}" "libcr") + target_include_directories("test_matrix${n}" PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_matrix) + target_compile_definitions("test_matrix${n}" PUBLIC "${defs}") + if ("CONFIG_COROUTINE_VALGRIND=1" IN_LIST defs) + add_test( + NAME "libcr/test_matrix${n}" + COMMAND valgrind --error-exitcode=2 "./test_matrix${n}" + ) + else() + add_test( + NAME "libcr/test_matrix${n}" + COMMAND "./test_matrix${n}" + ) + endif() +endfunction() +if (ENABLE_TESTS) + apply_matrix(add_libcr_matrix_test "${cfg_matrix}") +endif() diff --git a/libcr/coroutine.c b/libcr/coroutine.c index 726b732..76d21f3 100644 --- a/libcr/coroutine.c +++ b/libcr/coroutine.c @@ -22,25 +22,25 @@ #include "config.h" #ifndef CONFIG_COROUTINE_DEFAULT_STACK_SIZE - #error config.h must define CONFIG_COROUTINE_DEFAULT_STACK_SIZE + #error config.h must define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (non-negative integer) #endif #ifndef CONFIG_COROUTINE_NAME_LEN - #error config.h must define CONFIG_COROUTINE_NAME_LEN + #error config.h must define CONFIG_COROUTINE_NAME_LEN (non-negative integer) #endif #ifndef CONFIG_COROUTINE_NUM - #error config.h must define CONFIG_COROUTINE_NUM + #error config.h must define CONFIG_COROUTINE_NUM (non-negative integer) #endif #ifndef CONFIG_COROUTINE_MEASURE_STACK - #error config.h must define CONFIG_COROUTINE_MEASURE_STACK + #error config.h must define CONFIG_COROUTINE_MEASURE_STACK (bool) #endif #ifndef CONFIG_COROUTINE_PROTECT_STACK - #error config.h must define CONFIG_COROUTINE_PROTECT_STACK + #error config.h must define CONFIG_COROUTINE_PROTECT_STACK (bool) #endif #ifndef CONFIG_COROUTINE_DEBUG - #error config.h must define CONFIG_COROUTINE_DEBUG + #error config.h must define CONFIG_COROUTINE_DEBUG (bool) #endif #ifndef CONFIG_COROUTINE_VALGRIND - #error config.h must define CONFIG_COROUTINE_VALGRIND + #error config.h must define CONFIG_COROUTINE_VALGRIND (bool) #endif /* Implementation *************************************************************/ @@ -314,7 +314,7 @@ uintptr_t sp; #endif } cr_plat_jmp_buf; - static inline void _cr_plat_setjmp_pre(cr_plat_jmp_buf *env) { + static inline void _cr_plat_setjmp_pre(cr_plat_jmp_buf *env [[gnu::unused]]) { #if CONFIG_COROUTINE_MEASURE_STACK env->sp = cr_plat_get_sp(); #endif diff --git a/libcr/tests/test_matrix.c b/libcr/tests/test_matrix.c new file mode 100644 index 0000000..f1aa6fe --- /dev/null +++ b/libcr/tests/test_matrix.c @@ -0,0 +1,20 @@ +/* libcr/tests/test_matrix.c - Tests for libcr + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#include <stdlib.h> /* for exit(3) */ + +#include <libcr/coroutine.h> + +COROUTINE cr_init(void *) { + cr_begin(); + exit(0); + cr_end(); +} + +int main() { + coroutine_add("init", cr_init, NULL); + coroutine_main(); +} diff --git a/libcr/tests/test_matrix/config.h b/libcr/tests/test_matrix/config.h new file mode 100644 index 0000000..9802f08 --- /dev/null +++ b/libcr/tests/test_matrix/config.h @@ -0,0 +1,14 @@ +/* config.h - TODO + * + * Copyright (C) 2024 Luke T. Shumaker <lukeshu@lukeshu.com> + * SPDX-License-Identifier: AGPL-3.0-or-later + */ + +#ifndef _CONFIG_H_ +#define _CONFIG_H_ + +#define CONFIG_COROUTINE_DEFAULT_STACK_SIZE (4*1024) +#define CONFIG_COROUTINE_NAME_LEN 16 +#define CONFIG_COROUTINE_NUM 1 + +#endif /* _CONFIG_H_ */ |