bring back UCX test - fixes #341

Wed, 20 Dec 2023 16:46:14 +0100

author
Mike Becker <universe@uap-core.de>
date
Wed, 20 Dec 2023 16:46:14 +0100
changeset 766
e59b76889f00
parent 765
b5128bb44459
child 767
d31f4d4075dc

bring back UCX test - fixes #341

Makefile file | annotate | diff | comparison | revisions
configure file | annotate | diff | comparison | revisions
make/project.xml file | annotate | diff | comparison | revisions
make/update-rules.sh file | annotate | diff | comparison | revisions
src/Makefile file | annotate | diff | comparison | revisions
src/cx/common.h file | annotate | diff | comparison | revisions
src/cx/test.h file | annotate | diff | comparison | revisions
tests/Makefile file | annotate | diff | comparison | revisions
tests/test_utils.c file | annotate | diff | comparison | revisions
tests/test_utils.h file | annotate | diff | comparison | revisions
tests/ucxtest.c file | annotate | diff | comparison | revisions
--- a/Makefile	Mon Dec 18 18:54:17 2023 +0100
+++ b/Makefile	Wed Dec 20 16:46:14 2023 +0100
@@ -23,7 +23,7 @@
 
 include config.mk
 
-all: compile
+all: compile test-compile
 
 install:
 	@cd src && $(MAKE) install
@@ -57,11 +57,10 @@
 	@cd src && $(MAKE) static
 
 check: test-compile FORCE
-	test "$(WITH_TESTS)" = "yes" && $(build_dir)/tests/ucxtest
+	$(build_dir)/tests/ucxtest
 
 test-compile:
-	@(test "$(WITH_TESTS)" = "yes" && cd tests && $(MAKE)) \
-		|| echo "[ Tests disabled - skipped ]"
+	cd tests && $(MAKE)
 
 docs: FORCE
 	@(test "$(WITH_DOCS_API)" = "yes" && cd docs && $(MAKE) all-api) \
@@ -71,5 +70,6 @@
 
 update-rules:
 	make/update-rules.sh src
+	CFLAGS='$(CFLAGS) -I../src' make/update-rules.sh tests '$$(TEST_DIR)'
 
 FORCE:
--- a/configure	Mon Dec 18 18:54:17 2023 +0100
+++ b/configure	Wed Dec 20 16:46:14 2023 +0100
@@ -36,7 +36,6 @@
 src_dir=`pwd`
 DOXYGEN=`command -v doxygen`
 PANDOC=`command -v pandoc`
-CMAKE=`command -v cmake`
 
 # features
 
@@ -76,7 +75,6 @@
 Options:
   --debug                 add extra compile flags for debug builds
   --release               add extra compile flags for release builds
-  --with-tests=(yes|no)
   --with-docs=(all|html|api|none)
 
 __EOF__
@@ -107,7 +105,6 @@
         "--help"*) printhelp; abort_configure ;;
         "--debug")           BUILD_TYPE="debug" ;;
         "--release")         BUILD_TYPE="release" ;;
-        "--with-tests="*) OPT_WITH_TESTS=${ARG#--with-tests=} ;;
         "--with-docs="*) OPT_WITH_DOCS=${ARG#--with-docs=} ;;
         "-"*) echo "unknown option: $ARG"; abort_configure ;;
     esac
@@ -222,7 +219,6 @@
 src_dir="$src_dir"
 DOXYGEN="$DOXYGEN"
 PANDOC="$PANDOC"
-CMAKE="$CMAKE"
 __EOF__
 
 # toolchain detection utilities
@@ -235,9 +231,6 @@
 # check languages
 lang_c=
 lang_cpp=
-if detect_cpp_compiler ; then
-    lang_cpp=1
-fi
 if detect_c_compiler ; then
     lang_c=1
 fi
@@ -276,22 +269,6 @@
     echo no
     return 0
 }
-dependency_error_cpp()
-{
-    printf "checking for cpp... "
-    # dependency cpp
-    while true
-    do
-        if [ -z "$lang_cpp" ] ; then
-            break
-        fi
-        echo yes
-        return 1
-    done
-
-    echo no
-    return 0
-}
 dependency_error_c()
 {
     printf "checking for c... "
@@ -384,24 +361,6 @@
     echo no
     return 0
 }
-dependency_error_cmake()
-{
-    printf "checking for cmake... "
-    # dependency cmake
-    while true
-    do
-        if test -n "$CMAKE" > /dev/null ; then
-            :
-        else
-            break
-        fi
-        echo yes
-        return 1
-    done
-
-    echo no
-    return 0
-}
 dependency_error_doxygen()
 {
     printf "checking for doxygen... "
@@ -470,32 +429,6 @@
 #
 # OPTION VALUES
 #
-checkopt_with_tests_yes()
-{
-    VERR=0
-    if dependency_error_cpp ; then
-        VERR=1
-    fi
-    if dependency_error_cmake ; then
-        VERR=1
-    fi
-    if [ $VERR -ne 0 ]; then
-        return 1
-    fi
-    cat >> "$TEMP_DIR/make.mk" << __EOF__
-WITH_TESTS=yes
-
-__EOF__
-    return 0
-}
-checkopt_with_tests_no()
-{
-    VERR=0
-    if [ $VERR -ne 0 ]; then
-        return 1
-    fi
-    return 0
-}
 checkopt_with_docs_all()
 {
     VERR=0
@@ -579,54 +512,6 @@
 
 # Features
 
-# Option: --with-tests
-if [ -z "$OPT_WITH_TESTS" ]; then
-    echo "auto-detecting option 'with-tests'"
-    SAVED_ERROR="$ERROR"
-    SAVED_DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED"
-    ERROR=1
-    while true
-    do
-        if checkopt_with_tests_yes ; then
-            echo "  with-tests: yes" >> "$TEMP_DIR/options"
-            ERROR=0
-            break
-        fi
-        if checkopt_with_tests_no ; then
-            echo "  with-tests: no" >> "$TEMP_DIR/options"
-            ERROR=0
-            break
-        fi
-        break
-    done
-    if [ $ERROR -ne 0 ]; then
-        SAVED_ERROR=1
-        SAVED_DEPENDENCIES_FAILED="option 'with-tests' $SAVED_DEPENDENCIES_FAILED"
-    fi
-    ERROR="$SAVED_ERROR"
-    DEPENDENCIES_FAILED="$SAVED_DEPENDENCIES_FAILED"
-else
-    echo "checking option with-tests = $OPT_WITH_TESTS"
-    if false; then
-        false
-    elif [ "$OPT_WITH_TESTS" = "yes" ]; then
-        echo "  with-tests: $OPT_WITH_TESTS" >> $TEMP_DIR/options
-        if checkopt_with_tests_yes ; then
-            :
-        else
-            ERROR=1
-            DEPENDENCIES_FAILED="option 'with-tests' $DEPENDENCIES_FAILED"
-        fi
-    elif [ "$OPT_WITH_TESTS" = "no" ]; then
-        echo "  with-tests: $OPT_WITH_TESTS" >> $TEMP_DIR/options
-        if checkopt_with_tests_no ; then
-            :
-        else
-            ERROR=1
-            DEPENDENCIES_FAILED="option 'with-tests' $DEPENDENCIES_FAILED"
-        fi
-    fi
-fi
 # Option: --with-docs
 if [ -z "$OPT_WITH_DOCS" ]; then
     echo "auto-detecting option 'with-docs'"
--- a/make/project.xml	Mon Dec 18 18:54:17 2023 +0100
+++ b/make/project.xml	Wed Dec 20 16:46:14 2023 +0100
@@ -4,7 +4,6 @@
 		<var name="src_dir" exec="true">pwd</var>
 		<var name="DOXYGEN" exec="true">command -v doxygen</var>
 		<var name="PANDOC" exec="true">command -v pandoc</var>
-		<var name="CMAKE" exec="true">command -v cmake</var>
 	</config>
 
 	<dependency>
@@ -61,14 +60,6 @@
 SHLIB_EXT=.so
 		</make>
 	</dependency>
-	
-	<dependency name="cpp">
-		<lang>cpp</lang>
-	</dependency>
-
-	<dependency name="cmake">
-		<test>test -n "$CMAKE"</test>
-	</dependency>
 
 	<dependency name="doxygen">
 		<test>test -n "$DOXYGEN"</test>
@@ -79,15 +70,6 @@
 	</dependency>
 	
 	<target>
-		<option arg="with-tests">
-			<value str="yes">
-				<dependencies>cpp,cmake</dependencies>
-				<make>WITH_TESTS=yes</make>
-			</value>
-			<value str="no"/>
-			<default value="yes"/>
-			<default value="no"/>
-		</option>
 		<option arg="with-docs">
 			<value str="all">
 				<dependencies>pandoc,doxygen</dependencies>
--- a/make/update-rules.sh	Mon Dec 18 18:54:17 2023 +0100
+++ b/make/update-rules.sh	Wed Dec 20 16:46:14 2023 +0100
@@ -1,12 +1,17 @@
 #!/bin/sh
 
 dir="$1"
+target="$2"
 
 if [ -z "$dir" ]; then
   echo "Usage: $0 <src_dir>"
   exit 1
 fi
 
+if [ -z "$target" ]; then
+  target='$(build_dir)'
+fi
+
 if [ -d "$dir" ]; then
   :
 else
@@ -41,7 +46,7 @@
 sed '/FORCE:/q' Makefile.old > Makefile
 echo >> Makefile
 for file in `ls *.c` ; do
-  "$CC" -MT "\$(build_dir)/${file/.c/\$(OBJ_EXT)}" -MM $CFLAGS "$file"
+  "$CC" -MT "$target/${file/.c/\$(OBJ_EXT)}" -MM $CFLAGS "$file"
   printf '\t@echo "Compiling $<"\n'
   printf '\t$(CC) -o $@ $(CFLAGS) -c $<\n\n'
 done  >> Makefile
--- a/src/Makefile	Mon Dec 18 18:54:17 2023 +0100
+++ b/src/Makefile	Wed Dec 20 16:46:14 2023 +0100
@@ -56,7 +56,7 @@
 	$(CC) -o $@ $(CFLAGS) -c $<
 
 $(build_dir)/array_list$(OBJ_EXT): array_list.c cx/array_list.h cx/list.h \
- cx/common.h cx/collection.h cx/allocator.h cx/iterator.h
+ cx/common.h cx/collection.h cx/allocator.h cx/iterator.h cx/compare.h
 	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
@@ -81,7 +81,7 @@
 
 $(build_dir)/linked_list$(OBJ_EXT): linked_list.c cx/linked_list.h \
  cx/common.h cx/list.h cx/collection.h cx/allocator.h cx/iterator.h \
- cx/utils.h
+ cx/utils.h cx/compare.h
 	@echo "Compiling $<"
 	$(CC) -o $@ $(CFLAGS) -c $<
 
--- a/src/cx/common.h	Mon Dec 18 18:54:17 2023 +0100
+++ b/src/cx/common.h	Wed Dec 20 16:46:14 2023 +0100
@@ -96,6 +96,7 @@
 #include <stdint.h>
 #include <sys/types.h>
 
+#ifndef UCX_TEST_H
 /**
  * Function pointer compatible with fwrite-like functions.
  */
@@ -105,6 +106,7 @@
         size_t,
         void *
 );
+#endif // UCX_TEST_H
 
 /**
  * Function pointer compatible with fread-like functions.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/cx/test.h	Wed Dec 20 16:46:14 2023 +0100
@@ -0,0 +1,326 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2017 Mike Becker, Olaf Wintermann All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+ 
+/**
+ * @file: test.h
+ * 
+ * UCX Test Framework.
+ * 
+ * Usage of this test framework:
+ *
+ * **** IN HEADER FILE: ****
+ *
+ * <pre>
+ * CX_TEST(function_name);
+ * CX_TEST_SUBROUTINE(subroutine_name, paramlist); // optional
+ * </pre>
+ *
+ * **** IN SOURCE FILE: ****
+ * <pre>
+ * CX_TEST_SUBROUTINE(subroutine_name, paramlist) {
+ *   // tests with CX_TEST_ASSERT()
+ * }
+ * 
+ * CX_TEST(function_name) {
+ *   // memory allocation and other stuff here
+ *   #CX_TEST_BEGIN
+ *   // tests with CX_TEST_ASSERT() and/or
+ *   // calls with CX_TEST_CALL_SUBROUTINE() here
+ *   #CX_TEST_END
+ *   // cleanup of memory here
+ * }
+ * </pre>
+ *
+ * @remark if a test fails, execution continues at the
+ * #CX_TEST_END macro! So make sure every necessary cleanup happens afterwards.
+ * 
+ * @attention Do not call own functions within a test, that use
+ * CX_TEST_ASSERT() macros and are not defined by using CX_TEST_SUBROUTINE().
+ *
+ * @author Mike Becker
+ * @author Olaf Wintermann
+ *
+ */
+
+#ifndef UCX_TEST_H
+#define	UCX_TEST_H
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <setjmp.h>
+
+#ifdef	__cplusplus
+extern "C" {
+#endif
+
+#ifndef __FUNCTION__
+/**
+ * Alias for the <code>__func__</code> preprocessor macro.
+ * Some compilers use <code>__func__</code> and others use __FUNCTION__.
+ * We use __FUNCTION__ so we define it for those compilers which use
+ * <code>__func__</code>.
+ */
+#define __FUNCTION__ __func__
+#endif
+
+#ifndef UCX_COMMON_H
+/**
+ * Function pointer compatible with fwrite-like functions.
+ */
+typedef size_t (*cx_write_func)(
+        void const *,
+        size_t,
+        size_t,
+        void *
+);
+#endif // UCX_COMMON_H
+
+/** Type for the CxTestSuite. */
+typedef struct CxTestSuite CxTestSuite;
+
+/** Pointer to a test function. */
+typedef void(*CxTest)(CxTestSuite *, void *, cx_write_func);
+
+/** Type for the internal list of test cases. */
+typedef struct CxTestSet CxTestSet;
+
+/** Structure for the internal list of test cases. */
+struct CxTestSet {
+    
+    /** Test case. */
+    CxTest test;
+    
+    /** Pointer to the next list element. */
+    CxTestSet *next;
+};
+
+/**
+ * A test suite containing multiple test cases.
+ */
+struct CxTestSuite {
+    
+    /** The number of successful tests after the suite has been run. */
+    unsigned int success;
+    
+    /** The number of failed tests after the suite has been run. */
+    unsigned int failure;
+
+    /** The optional name of this test suite. */
+    char const *name;
+    
+    /**
+     * Internal list of test cases.
+     * Use cx_test_register() to add tests to this list.
+     */
+    CxTestSet *tests;
+};
+
+/**
+ * Creates a new test suite.
+ * @param name optional name of the suite
+ * @return a new test suite
+ */
+static inline CxTestSuite* cx_test_suite_new(char const *name) {
+    CxTestSuite* suite = (CxTestSuite*) malloc(sizeof(CxTestSuite));
+    if (suite != NULL) {
+        suite->name = name;
+        suite->success = 0;
+        suite->failure = 0;
+        suite->tests = NULL;
+    }
+
+    return suite;
+}
+
+/**
+ * Destroys a test suite.
+ * @param suite the test suite to destroy
+ */
+static inline void cx_test_suite_free(CxTestSuite* suite) {
+    CxTestSet *l = suite->tests;
+    while (l != NULL) {
+        CxTestSet *e = l;
+        l = l->next;
+        free(e);
+    }
+    free(suite);
+}
+
+/**
+ * Registers a test function with the specified test suite.
+ * 
+ * @param suite the suite, the test function shall be added to
+ * @param test the test function to register
+ * @return zero on success or non-zero on failure
+ */
+static inline int cx_test_register(CxTestSuite* suite, CxTest test) {
+    CxTestSet *t = (CxTestSet*) malloc(sizeof(CxTestSet));
+    if (t) {
+        t->test = test;
+        t->next = NULL;
+        if (suite->tests == NULL) {
+            suite->tests = t;
+        } else {
+            CxTestSet *last = suite->tests;
+            while (last->next) {
+                last = last->next;
+            }
+            last->next = t;
+        }
+        return 0;
+    } else {
+        return 1;
+    }
+}
+
+/**
+ * Runs a test suite and writes the test log to the specified stream.
+ * @param suite the test suite to run
+ * @param out_target the target buffer or file to write the output to
+ * @param out_writer the write function writing to \p out_target
+ */
+static inline void cx_test_run(CxTestSuite *suite,
+                               void *out_target, cx_write_func out_writer) {
+    if (suite->name == NULL) {
+        out_writer("*** Test Suite ***\n", 1, 19, out_target);
+    } else {
+        out_writer("*** Test Suite : ", 1, 17, out_target);
+        out_writer(suite->name, 1, strlen(suite->name), out_target);
+        out_writer(" ***\n", 1, 5, out_target);
+    }
+    suite->success = 0;
+    suite->failure = 0;
+    for (CxTestSet *elem = suite->tests; elem; elem = elem->next) {
+        elem->test(suite, out_target, out_writer);
+    }
+    out_writer("\nAll test completed.\n", 1, 21, out_target);
+    char total[80];
+    int len = snprintf(
+            total, 80,
+            "  Total:   %u\n  Success: %u\n  Failure: %u\n",
+            suite->success + suite->failure, suite->success, suite->failure
+    );
+    out_writer(total, 1, len, out_target);
+}
+
+/**
+ * Runs a test suite and writes the test log to the specified FILE stream.
+ * @param suite the test suite to run
+ * @param file the target file to write the output to
+ */
+#define cx_test_run_f(suite, file) cx_test_run(suite, (void*)file, (cx_write_func)fwrite)
+
+/**
+ * Runs a test suite and writes the test log to stdout.
+ * @param suite the test suite to run
+ */
+#define cx_test_run_stdout(suite) cx_test_run_f(suite, stdout)
+
+/**
+ * Macro for a #CxTest function header.
+ * 
+ * Use this macro to declare and/or define a #CxTest function.
+ * 
+ * @param name the name of the test function
+ */
+#define CX_TEST(name) void name(CxTestSuite* _suite_,void *_output_, cx_write_func _writefnc_)
+
+/**
+ * Marks the begin of a test.
+ * <b>Note:</b> Any CX_TEST_ASSERT() calls must be performed <b>after</b>
+ * #CX_TEST_BEGIN.
+ * 
+ * @see #CX_TEST_END
+ */
+#define CX_TEST_BEGIN _writefnc_("Running ", 1, 8, _output_);\
+        _writefnc_(__FUNCTION__, 1, strlen(__FUNCTION__), _output_);\
+        _writefnc_("... ", 1, 4, _output_);\
+        jmp_buf _env_; \
+        if (!setjmp(_env_)) {
+
+/**
+ * Checks a test assertion.
+ * If the assertion is correct, the test carries on. If the assertion is not
+ * correct, the specified message (terminated by a dot and a line break) is
+ * written to the test suites output stream.
+ * @param condition the condition to check
+ * @param message the message that shall be printed out on failure
+ */
+#define CX_TEST_ASSERT(condition,message) if (!(condition)) { \
+        _writefnc_(message".\n", 1, 2+strlen(message), _output_); \
+        _suite_->failure++; \
+        longjmp(_env_, 1);\
+    }
+
+/**
+ * Macro for a test subroutine function header.
+ * 
+ * Use this to declare and/or define a subroutine that can be called by using
+ * CX_TEST_CALL_SUBROUTINE().
+ * 
+ * @param name the name of the subroutine
+ * @param ... the parameter list
+ * 
+ * @see CX_TEST_CALL_SUBROUTINE()
+ */
+#define CX_TEST_SUBROUTINE(name,...) void name(CxTestSuite* _suite_,\
+        void *_output_, jmp_buf _env_, __VA_ARGS__)
+
+/**
+ * Macro for calling a test subroutine.
+ * 
+ * Subroutines declared with CX_TEST_SUBROUTINE() can be called by using this
+ * macro.
+ * 
+ * <b>Note:</b> You may <b>only</b> call subroutines within a #CX_TEST_BEGIN-
+ * #CX_TEST_END-block.
+ * 
+ * @param name the name of the subroutine
+ * @param ... the argument list
+ * 
+ * @see CX_TEST_SUBROUTINE()
+ */
+#define CX_TEST_CALL_SUBROUTINE(name,...) \
+        name(_suite_,_output_,_writefnc_,_env_,__VA_ARGS__);
+
+/**
+ * Marks the end of a test.
+ * <b>Note:</b> Any CX_TEST_ASSERT() calls must be performed <b>before</b>
+ * #CX_TEST_END.
+ * 
+ * @see #CX_TEST_BEGIN
+ */
+#define CX_TEST_END _writefnc_("success.\n", 1, 9, _output_); _suite_->success++;}
+
+#ifdef	__cplusplus
+}
+#endif
+
+#endif	/* UCX_TEST_H */
+
--- a/tests/Makefile	Mon Dec 18 18:54:17 2023 +0100
+++ b/tests/Makefile	Wed Dec 20 16:46:14 2023 +0100
@@ -23,13 +23,42 @@
 
 include ../config.mk
 
+CFLAGS += -I../src
+
 TEST_DIR=$(build_dir)/tests
 
-all: $(TEST_DIR) $(build_dir)/libucx_static.a
-	cd $(TEST_DIR) && $(CMAKE) -DSTLIB_EXT="$(STLIB_EXT)" "$(src_dir)/tests" && $(CMAKE) --build .
-	@echo "[ Tests complete ]"
+SRC = test_utils.c ucxtest.o
+
+OBJ_EXT=.o
+OBJ=$(SRC:%.c=$(TEST_DIR)/%$(OBJ_EXT))
 
-# do not define libucx.a target - if it wasn't build, we simply fail!
+all: $(TEST_DIR) $(TEST_DIR)/ucxtest
+
+$(TEST_DIR)/ucxtest: $(build_dir)/libucx_static.a $(OBJ)
+	$(CC) -o $@ $+
+
+$(build_dir)/libucx_static.a:
+	test -f "$@"
 
 $(TEST_DIR):
-	$(MKDIR) $@
\ No newline at end of file
+	$(MKDIR) $@
+
+FORCE:
+
+$(TEST_DIR)/test_map_generics$(OBJ_EXT): test_map_generics.c \
+ test_map_generics.h ../src/cx/map.h ../src/cx/common.h \
+ ../src/cx/collection.h ../src/cx/allocator.h ../src/cx/iterator.h \
+ ../src/cx/string.h ../src/cx/hash_key.h ../src/cx/hash_map.h \
+ ../src/cx/map.h
+	@echo "Compiling $<"
+	$(CC) -o $@ $(CFLAGS) -c $<
+
+$(TEST_DIR)/test_utils$(OBJ_EXT): test_utils.c test_utils.h \
+ ../src/cx/test.h
+	@echo "Compiling $<"
+	$(CC) -o $@ $(CFLAGS) -c $<
+
+$(TEST_DIR)/ucxtest$(OBJ_EXT): ucxtest.c test_utils.h ../src/cx/test.h
+	@echo "Compiling $<"
+	$(CC) -o $@ $(CFLAGS) -c $<
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_utils.c	Wed Dec 20 16:46:14 2023 +0100
@@ -0,0 +1,37 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_utils.h"
+
+CxTestSuite *cx_test_suite_utils(void) {
+    CxTestSuite *suite = cx_test_suite_new("utils");
+
+    return suite;
+}
+
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/test_utils.h	Wed Dec 20 16:46:14 2023 +0100
@@ -0,0 +1,46 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef UCX_TEST_SUITE_UTILS_H
+#define UCX_TEST_SUITE_UTILS_H
+
+#include "cx/test.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+CxTestSuite *cx_test_suite_utils(void);
+
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif // UCX_TEST_SUITE_UTILS_H
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/ucxtest.c	Wed Dec 20 16:46:14 2023 +0100
@@ -0,0 +1,54 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2023 Mike Becker, Olaf Wintermann All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ *   1. Redistributions of source code must retain the above copyright
+ *      notice, this list of conditions and the following disclaimer.
+ *
+ *   2. Redistributions in binary form must reproduce the above copyright
+ *      notice, this list of conditions and the following disclaimer in the
+ *      documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "test_utils.h"
+
+#define run_tests(suite) cx_test_run_stdout(suite); success += (suite)->success; failure += (suite)->failure
+
+int main(void) {
+    printf("UCX Tests\n---------\n");
+
+    unsigned success = 0, failure = 0;
+
+    // create test suites
+    CxTestSuite
+    *utils = cx_test_suite_utils();
+
+    // run tests
+    run_tests(utils);
+
+    // print overall result
+    printf("\n\n*** OVERALL RESULT ***\n");
+    printf("  Total:   %u\n  Success: %u\n  Failure: %u\n",
+           success + failure, success, failure);
+
+    cx_test_suite_free(utils);
+
+    return failure > 0 ? 1 : 0;
+}
+

mercurial