Replace Criterion by CUnit
Signed-off-by: Jeroen Koekkoek <jeroen@koekkoek.nl>
This commit is contained in:
		
							parent
							
								
									60752b3fd8
								
							
						
					
					
						commit
						74a48c5731
					
				
					 47 changed files with 4486 additions and 5388 deletions
				
			
		| 
						 | 
				
			
			@ -9,6 +9,7 @@
 | 
			
		|||
#
 | 
			
		||||
# SPDX-License-Identifier: EPL-2.0 OR BSD-3-Clause
 | 
			
		||||
#
 | 
			
		||||
include(Criterion)
 | 
			
		||||
add_criterion_executable(criterion_util .)
 | 
			
		||||
target_link_libraries(criterion_util util)
 | 
			
		||||
include(CUnit)
 | 
			
		||||
 | 
			
		||||
add_cunit_executable(CUnit_util "handleserver.c")
 | 
			
		||||
target_link_libraries(CUnit_util util)
 | 
			
		||||
| 
						 | 
				
			
			@ -11,13 +11,10 @@
 | 
			
		|||
 */
 | 
			
		||||
#include "os/os.h"
 | 
			
		||||
#include "util/ut_handleserver.h"
 | 
			
		||||
#include <criterion/criterion.h>
 | 
			
		||||
#include <criterion/logging.h>
 | 
			
		||||
 | 
			
		||||
/* Add --verbose command line argument to get the cr_log_info traces (if there are any). */
 | 
			
		||||
#include "CUnit/Test.h"
 | 
			
		||||
 | 
			
		||||
/*****************************************************************************************/
 | 
			
		||||
Test(util_handleserver, basic)
 | 
			
		||||
CU_Test(util_handleserver, basic)
 | 
			
		||||
{
 | 
			
		||||
    const os_time zero  = { 0, 0 };
 | 
			
		||||
    int32_t kind = 0x10000000;
 | 
			
		||||
| 
						 | 
				
			
			@ -27,29 +24,29 @@ Test(util_handleserver, basic)
 | 
			
		|||
    void *argx;
 | 
			
		||||
 | 
			
		||||
    ret = ut_handleserver_init();
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handleserver_init");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    hdl = ut_handle_create(kind, (void*)&arg);
 | 
			
		||||
    cr_assert(hdl > 0, "ut_handle_create");
 | 
			
		||||
    CU_ASSERT_FATAL(hdl > 0);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl, NULL, kind, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_claim ret");
 | 
			
		||||
    cr_assert_eq(argx, &arg, "ut_handle_claim arg");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(argx, &arg);
 | 
			
		||||
 | 
			
		||||
    ut_handle_release(hdl, NULL);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_delete(hdl, NULL, zero);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_delete");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl, NULL, kind, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_DELETED, "ut_handle_claim ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_DELETED);
 | 
			
		||||
 | 
			
		||||
    ut_handleserver_fini();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*****************************************************************************************/
 | 
			
		||||
Test(util_handleserver, close)
 | 
			
		||||
CU_Test(util_handleserver, close)
 | 
			
		||||
{
 | 
			
		||||
    const os_time zero  = { 0, 0 };
 | 
			
		||||
    int32_t kind = 0x10000000;
 | 
			
		||||
| 
						 | 
				
			
			@ -60,33 +57,33 @@ Test(util_handleserver, close)
 | 
			
		|||
    bool closed;
 | 
			
		||||
 | 
			
		||||
    ret = ut_handleserver_init();
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handleserver_init");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    hdl = ut_handle_create(kind, (void*)&arg);
 | 
			
		||||
    cr_assert(hdl > 0, "ut_handle_create");
 | 
			
		||||
    CU_ASSERT_FATAL(hdl > 0);
 | 
			
		||||
 | 
			
		||||
    closed = ut_handle_is_closed(hdl, NULL);
 | 
			
		||||
    cr_assert_eq(closed, false, "ut_handle_is_closed ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(closed, false);
 | 
			
		||||
 | 
			
		||||
    ut_handle_close(hdl, NULL);
 | 
			
		||||
 | 
			
		||||
    closed = ut_handle_is_closed(hdl, NULL);
 | 
			
		||||
    cr_assert_eq(closed, true, "ut_handle_is_closed ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(closed, true);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl, NULL, kind, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_CLOSED, "ut_handle_claim ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_CLOSED);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_delete(hdl, NULL, zero);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_delete");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl, NULL, kind, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_DELETED, "ut_handle_claim ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_DELETED);
 | 
			
		||||
 | 
			
		||||
    ut_handleserver_fini();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/*****************************************************************************************/
 | 
			
		||||
Test(util_handleserver, link)
 | 
			
		||||
CU_Test(util_handleserver, link)
 | 
			
		||||
{
 | 
			
		||||
    const os_time zero  = { 0, 0 };
 | 
			
		||||
    int32_t kind = 0x10000000;
 | 
			
		||||
| 
						 | 
				
			
			@ -97,32 +94,32 @@ Test(util_handleserver, link)
 | 
			
		|||
    void *argx;
 | 
			
		||||
 | 
			
		||||
    ret = ut_handleserver_init();
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handleserver_init");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    hdl = ut_handle_create(kind, (void*)&arg);
 | 
			
		||||
    cr_assert(hdl > 0, "ut_handle_create");
 | 
			
		||||
    CU_ASSERT_FATAL(hdl > 0);
 | 
			
		||||
 | 
			
		||||
    link = ut_handle_get_link(hdl);
 | 
			
		||||
    cr_assert_neq(link, NULL, "ut_handle_get_link");
 | 
			
		||||
    CU_ASSERT_NOT_EQUAL_FATAL(link, NULL);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl, link, kind, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_claim ret");
 | 
			
		||||
    cr_assert_eq(argx, &arg, "ut_handle_claim arg");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(argx, &arg);
 | 
			
		||||
 | 
			
		||||
    ut_handle_release(hdl, link);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_delete(hdl, link, zero);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_delete");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    link = ut_handle_get_link(hdl);
 | 
			
		||||
    cr_assert_eq(link, NULL, "ut_handle_get_link");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(link, NULL);
 | 
			
		||||
 | 
			
		||||
    ut_handleserver_fini();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*****************************************************************************************/
 | 
			
		||||
Test(util_handleserver, types)
 | 
			
		||||
CU_Test(util_handleserver, types)
 | 
			
		||||
{
 | 
			
		||||
    const os_time zero  = { 0, 0 };
 | 
			
		||||
    int32_t kind1 = 0x10000000;
 | 
			
		||||
| 
						 | 
				
			
			@ -137,55 +134,55 @@ Test(util_handleserver, types)
 | 
			
		|||
    void *argx;
 | 
			
		||||
 | 
			
		||||
    ret = ut_handleserver_init();
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handleserver_init");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    hdl1a = ut_handle_create(kind1, (void*)&arg1a);
 | 
			
		||||
    cr_assert(hdl1a > 0, "ut_handle_create");
 | 
			
		||||
    CU_ASSERT_FATAL(hdl1a > 0);
 | 
			
		||||
 | 
			
		||||
    hdl1b = ut_handle_create(kind1, (void*)&arg1b);
 | 
			
		||||
    cr_assert(hdl1b > 0, "ut_handle_create");
 | 
			
		||||
    CU_ASSERT_FATAL(hdl1b > 0);
 | 
			
		||||
 | 
			
		||||
    hdl2 = ut_handle_create(kind2, (void*)&arg2);
 | 
			
		||||
    cr_assert(hdl2 > 0, "ut_handle_create");
 | 
			
		||||
    CU_ASSERT_FATAL(hdl2 > 0);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl1a, NULL, kind1, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_claim ret");
 | 
			
		||||
    cr_assert_eq(argx, &arg1a, "ut_handle_claim arg");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(argx, &arg1a);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl1b, NULL, kind1, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_claim ret");
 | 
			
		||||
    cr_assert_eq(argx, &arg1b, "ut_handle_claim arg");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(argx, &arg1b);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl2, NULL, kind2, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_claim ret");
 | 
			
		||||
    cr_assert_eq(argx, &arg2, "ut_handle_claim arg");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(argx, &arg2);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl1a, NULL, kind2, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_UNEQUAL_KIND, "ut_handle_claim ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_UNEQUAL_KIND);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl1a, NULL, kind2, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_UNEQUAL_KIND, "ut_handle_claim ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_UNEQUAL_KIND);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl2, NULL, kind1, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_UNEQUAL_KIND, "ut_handle_claim ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_UNEQUAL_KIND);
 | 
			
		||||
 | 
			
		||||
    ut_handle_release(hdl1a, NULL);
 | 
			
		||||
    ut_handle_release(hdl1b, NULL);
 | 
			
		||||
    ut_handle_release(hdl2,  NULL);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_delete(hdl1a, NULL, zero);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_delete");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
    ret = ut_handle_delete(hdl1b, NULL, zero);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_delete");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
    ret = ut_handle_delete(hdl2,  NULL, zero);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_delete");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    ut_handleserver_fini();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*****************************************************************************************/
 | 
			
		||||
Test(util_handleserver, timeout)
 | 
			
		||||
CU_Test(util_handleserver, timeout)
 | 
			
		||||
{
 | 
			
		||||
    const os_time zero  = { 0, 0 };
 | 
			
		||||
    int32_t kind = 0x10000000;
 | 
			
		||||
| 
						 | 
				
			
			@ -195,22 +192,22 @@ Test(util_handleserver, timeout)
 | 
			
		|||
    void *argx;
 | 
			
		||||
 | 
			
		||||
    ret = ut_handleserver_init();
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handleserver_init");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    hdl = ut_handle_create(kind, (void*)&arg);
 | 
			
		||||
    cr_assert(hdl > 0, "ut_handle_create");
 | 
			
		||||
    CU_ASSERT_FATAL(hdl > 0);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl, NULL, kind, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_claim ret");
 | 
			
		||||
    cr_assert_eq(argx, &arg, "ut_handle_claim arg");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(argx, &arg);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_delete(hdl, NULL, zero);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_TIMEOUT, "ut_handle_delete");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_TIMEOUT);
 | 
			
		||||
 | 
			
		||||
    ut_handle_release(hdl, NULL);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_delete(hdl, NULL, zero);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_delete");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    ut_handleserver_fini();
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -238,7 +235,7 @@ deleting_thread(void *a)
 | 
			
		|||
    arg->state = DELETING;
 | 
			
		||||
    /* This should block until the main test released all claims. */
 | 
			
		||||
    ret = ut_handle_delete(arg->hdl, NULL, ten);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_delete ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
    arg->state = STOPPED;
 | 
			
		||||
 | 
			
		||||
    return 0;
 | 
			
		||||
| 
						 | 
				
			
			@ -256,7 +253,7 @@ thread_reached_state(thread_state_t *actual, thread_state_t expected, int32_t ms
 | 
			
		|||
    return (*actual == expected) ? os_resultSuccess : os_resultTimeout;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
Test(util_handleserver, wakeup)
 | 
			
		||||
CU_Test(util_handleserver, wakeup)
 | 
			
		||||
{
 | 
			
		||||
    int32_t kind = 0x10000000;
 | 
			
		||||
    ut_handle_retcode_t ret;
 | 
			
		||||
| 
						 | 
				
			
			@ -270,37 +267,37 @@ Test(util_handleserver, wakeup)
 | 
			
		|||
    os_result     osr;
 | 
			
		||||
 | 
			
		||||
    ret = ut_handleserver_init();
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handleserver_init");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    hdl = ut_handle_create(kind, (void*)&arg);
 | 
			
		||||
    cr_assert(hdl > 0, "ut_handle_create");
 | 
			
		||||
    CU_ASSERT_FATAL(hdl > 0);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl, NULL, kind, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_claim1 ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    ret = ut_handle_claim(hdl, NULL, kind, &argx);
 | 
			
		||||
    cr_assert_eq(ret, UT_HANDLE_OK, "ut_handle_claim2 ret");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(ret, UT_HANDLE_OK);
 | 
			
		||||
 | 
			
		||||
    /* Try deleting in other thread, which should block. */
 | 
			
		||||
    thread_arg.hdl   = hdl;
 | 
			
		||||
    thread_arg.state = STARTING;
 | 
			
		||||
    os_threadAttrInit(&thread_attr);
 | 
			
		||||
    osr = os_threadCreate(&thread_id, "deleting_thread", &thread_attr, deleting_thread, (void*)&thread_arg);
 | 
			
		||||
    cr_assert_eq(osr, os_resultSuccess, "os_threadCreate");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(osr, os_resultSuccess);
 | 
			
		||||
    osr = thread_reached_state(&thread_arg.state, DELETING, 1000);
 | 
			
		||||
    cr_assert_eq(osr, os_resultSuccess, "deleting");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(osr, os_resultSuccess);
 | 
			
		||||
    osr = thread_reached_state(&thread_arg.state, STOPPED, 500);
 | 
			
		||||
    cr_assert_eq(osr, os_resultTimeout, "deleting");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(osr, os_resultTimeout);
 | 
			
		||||
 | 
			
		||||
    /* First release of the hdl should not unblock the thread. */
 | 
			
		||||
    ut_handle_release(hdl, NULL);
 | 
			
		||||
    osr = thread_reached_state(&thread_arg.state, STOPPED, 500);
 | 
			
		||||
    cr_assert_eq(osr, os_resultTimeout, "deleting");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(osr, os_resultTimeout);
 | 
			
		||||
 | 
			
		||||
    /* Second release of the hdl should unblock the thread. */
 | 
			
		||||
    ut_handle_release(hdl, NULL);
 | 
			
		||||
    osr = thread_reached_state(&thread_arg.state, STOPPED, 500);
 | 
			
		||||
    cr_assert_eq(osr, os_resultSuccess, "deleting");
 | 
			
		||||
    CU_ASSERT_EQUAL_FATAL(osr, os_resultSuccess);
 | 
			
		||||
    os_threadWaitExit(thread_id, NULL);
 | 
			
		||||
 | 
			
		||||
    /* The handle is deleted within the thread. */
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue