mirror of
https://github.com/outbackdingo/parodus.git
synced 2026-01-27 10:20:04 +00:00
Added test for spin_thread.c
This commit is contained in:
@@ -80,3 +80,18 @@ endif (NOT EXCLUDE_SIMPLE)
|
||||
add_test(NAME test_time COMMAND test_time)
|
||||
add_executable(test_time test_time.c ../src/time.c)
|
||||
target_link_libraries (test_time ${PARODUS_COMMON_LIBS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_spin_thread error
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_spin_thread_e COMMAND test_spin_thread_e)
|
||||
add_executable(test_spin_thread_e test_spin_thread_e.c ../src/spin_thread.c)
|
||||
target_link_libraries (test_spin_thread_e ${PARODUS_COMMON_LIBS})
|
||||
|
||||
#-------------------------------------------------------------------------------
|
||||
# test_spin_thread success
|
||||
#-------------------------------------------------------------------------------
|
||||
add_test(NAME test_spin_thread_s COMMAND test_spin_thread_s)
|
||||
add_executable(test_spin_thread_s test_spin_thread_s.c ../src/spin_thread.c)
|
||||
target_link_libraries (test_spin_thread_s ${PARODUS_COMMON_LIBS})
|
||||
|
||||
|
||||
92
tests/test_spin_thread_e.c
Normal file
92
tests/test_spin_thread_e.c
Normal file
@@ -0,0 +1,92 @@
|
||||
/**
|
||||
* Copyright 2010-2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/spin_thread.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine) (void *), void *arg)
|
||||
{
|
||||
(void) thread; (void) attr; (void) start_routine; (void) arg;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void exit(int status)
|
||||
{
|
||||
if( 1 == status ) {
|
||||
printf("Correct exit status\n");
|
||||
} else {
|
||||
printf("Wrong exit status\n");
|
||||
}
|
||||
_exit(0);
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void *_routine(void *v)
|
||||
{
|
||||
(void) v;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void test_StartThread_error()
|
||||
{
|
||||
StartThread(&_routine);
|
||||
}
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
{
|
||||
ParodusInfo("--------Start of Test Cases Execution ---------\n");
|
||||
*suite = CU_add_suite( "tests", NULL, NULL );
|
||||
CU_add_test( *suite, "Test 1", test_StartThread_error );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main( void )
|
||||
{
|
||||
unsigned rv = 1;
|
||||
CU_pSuite suite = NULL;
|
||||
|
||||
if( CUE_SUCCESS == CU_initialize_registry() ) {
|
||||
add_suites( &suite );
|
||||
|
||||
if( NULL != suite ) {
|
||||
CU_basic_set_mode( CU_BRM_VERBOSE );
|
||||
CU_basic_run_tests();
|
||||
ParodusPrint( "\n" );
|
||||
CU_basic_show_failures( CU_get_failure_list() );
|
||||
ParodusPrint( "\n\n" );
|
||||
rv = CU_get_number_of_tests_failed();
|
||||
}
|
||||
|
||||
CU_cleanup_registry();
|
||||
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
82
tests/test_spin_thread_s.c
Normal file
82
tests/test_spin_thread_s.c
Normal file
@@ -0,0 +1,82 @@
|
||||
/**
|
||||
* Copyright 2010-2016 Comcast Cable Communications Management, LLC
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <CUnit/Basic.h>
|
||||
|
||||
#include "../src/ParodusInternal.h"
|
||||
#include "../src/spin_thread.h"
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Mocks */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int pthread_create(pthread_t *thread, const pthread_attr_t *attr,
|
||||
void *(*start_routine) (void *), void *arg)
|
||||
{
|
||||
(void) thread; (void) attr; (void) start_routine; (void) arg;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* Tests */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
void *_routine(void *v)
|
||||
{
|
||||
(void) v;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void test_StartThread_success()
|
||||
{
|
||||
StartThread(&_routine);
|
||||
}
|
||||
|
||||
void add_suites( CU_pSuite *suite )
|
||||
{
|
||||
ParodusInfo("--------Start of Test Cases Execution ---------\n");
|
||||
*suite = CU_add_suite( "tests", NULL, NULL );
|
||||
CU_add_test( *suite, "Test 1", test_StartThread_success );
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------*/
|
||||
/* External Functions */
|
||||
/*----------------------------------------------------------------------------*/
|
||||
int main( void )
|
||||
{
|
||||
unsigned rv = 1;
|
||||
CU_pSuite suite = NULL;
|
||||
|
||||
if( CUE_SUCCESS == CU_initialize_registry() ) {
|
||||
add_suites( &suite );
|
||||
|
||||
if( NULL != suite ) {
|
||||
CU_basic_set_mode( CU_BRM_VERBOSE );
|
||||
CU_basic_run_tests();
|
||||
ParodusPrint( "\n" );
|
||||
CU_basic_show_failures( CU_get_failure_list() );
|
||||
ParodusPrint( "\n\n" );
|
||||
rv = CU_get_number_of_tests_failed();
|
||||
}
|
||||
|
||||
CU_cleanup_registry();
|
||||
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
Reference in New Issue
Block a user