summaryrefslogtreecommitdiff
path: root/libcr
diff options
context:
space:
mode:
Diffstat (limited to 'libcr')
-rw-r--r--libcr/CMakeLists.txt27
-rw-r--r--libcr/coroutine.c16
-rw-r--r--libcr/tests/test_matrix.c20
-rw-r--r--libcr/tests/test_matrix/config.h14
4 files changed, 69 insertions, 8 deletions
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_ */