2022-03-21 11:05:59 +01:00
|
|
|
/* $Id: test02.c,v 2.1 2000/05/29 13:56:44 cibrario Rel $
|
|
|
|
Chf test program.
|
|
|
|
Simple initialization - multithreaded.
|
|
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <setjmp.h>
|
|
|
|
|
|
|
|
#ifdef _REENTRANT
|
2024-03-26 13:36:50 +01:00
|
|
|
# include <pthread.h>
|
2022-03-21 11:05:59 +01:00
|
|
|
#endif
|
|
|
|
|
2024-03-26 13:36:50 +01:00
|
|
|
#define CHF_MODULE_ID 255
|
2022-03-21 11:05:59 +01:00
|
|
|
#define CHF_EXTENDED_INFO
|
|
|
|
#include "Chf.h"
|
|
|
|
|
2024-03-26 13:36:50 +01:00
|
|
|
void* task( void* arg )
|
2022-03-21 11:05:59 +01:00
|
|
|
{
|
2024-03-26 13:36:50 +01:00
|
|
|
const char* msg;
|
2022-03-21 11:05:59 +01:00
|
|
|
const ChfDescriptor *d, *e;
|
|
|
|
|
2024-03-26 13:36:50 +01:00
|
|
|
printf( "\tThread %d\n", ( int )arg );
|
2022-03-21 11:05:59 +01:00
|
|
|
|
|
|
|
/* message (CHF_MODULE_ID, 1) exists, (CHF_MODULE_ID, 2) does not */
|
2024-03-26 13:36:50 +01:00
|
|
|
msg = ChfGetMessage( CHF_MODULE_ID, 1, "Default_1" );
|
|
|
|
if ( strcmp( msg, "Set_255,Message_1" ) )
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
msg = ChfGetMessage( CHF_MODULE_ID, 2, "Default_2" );
|
|
|
|
if ( strcmp( msg, "Default_2" ) )
|
|
|
|
exit( EXIT_FAILURE );
|
2022-03-21 11:05:59 +01:00
|
|
|
|
|
|
|
/* Generate a condition and check descriptor; this is line 36 */
|
|
|
|
ChfCondition 3, CHF_WARNING, 456 ChfEnd;
|
|
|
|
|
2024-03-26 13:36:50 +01:00
|
|
|
if ( ( d = ChfGetTopCondition() ) == NULL )
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
if ( d->module_id != CHF_MODULE_ID || d->condition_code != 3 || d->severity != CHF_WARNING || d->line_number != 36 ||
|
|
|
|
strcmp( d->file_name, "test02.c" ) || strcmp( d->message, "Set_255,Arg_456,Message_3" ) || d->next != NULL )
|
|
|
|
exit( EXIT_FAILURE );
|
2022-03-21 11:05:59 +01:00
|
|
|
|
|
|
|
/* Generate another condition and check; this is line 50 */
|
|
|
|
ChfCondition 4, CHF_INFO, "arg" ChfEnd;
|
|
|
|
|
2024-03-26 13:36:50 +01:00
|
|
|
if ( ( e = ChfGetTopCondition() ) == NULL )
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
if ( e->module_id != CHF_MODULE_ID || e->condition_code != 4 || e->severity != CHF_INFO || e->line_number != 50 ||
|
|
|
|
strcmp( e->file_name, "test02.c" ) || strcmp( e->message, "Set_255,Arg_arg,Message_4" ) || e->next != d )
|
|
|
|
exit( EXIT_FAILURE );
|
2022-03-21 11:05:59 +01:00
|
|
|
|
|
|
|
/* Discard the previous condition group and create a new one */
|
|
|
|
ChfDiscard();
|
|
|
|
|
|
|
|
/* This is line 67 */
|
|
|
|
ChfCondition 5, CHF_ERROR, 456, 789 ChfEnd;
|
|
|
|
|
2024-03-26 13:36:50 +01:00
|
|
|
if ( ( d = ChfGetTopCondition() ) == NULL )
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
if ( d->module_id != CHF_MODULE_ID || d->condition_code != 5 || d->severity != CHF_ERROR || d->line_number != 67 ||
|
|
|
|
strcmp( d->file_name, "test02.c" ) || strcmp( d->message, "Set_255,Arg_456-789,Message_5" ) || d->next != NULL )
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
|
|
|
|
return ( void* )0;
|
2022-03-21 11:05:59 +01:00
|
|
|
}
|
|
|
|
|
2024-03-26 13:36:50 +01:00
|
|
|
#define N_THREADS 50
|
2022-03-21 11:05:59 +01:00
|
|
|
|
2024-03-26 13:36:50 +01:00
|
|
|
int main( int argc, char* argv[] )
|
2022-03-21 11:05:59 +01:00
|
|
|
{
|
|
|
|
int st;
|
|
|
|
int i;
|
2024-03-26 13:36:50 +01:00
|
|
|
void* ret;
|
2022-03-21 11:05:59 +01:00
|
|
|
#ifdef _REENTRANT
|
2024-03-26 13:36:50 +01:00
|
|
|
pthread_t t[ N_THREADS ];
|
2022-03-21 11:05:59 +01:00
|
|
|
#endif
|
|
|
|
|
2024-03-26 13:36:50 +01:00
|
|
|
puts( "test02" );
|
2022-03-21 11:05:59 +01:00
|
|
|
|
|
|
|
#ifdef _REENTRANT
|
|
|
|
/* Initialization */
|
2024-03-26 13:36:50 +01:00
|
|
|
if ( st = ChfMsgcatInit( argv[ 0 ], CHF_DEFAULT, "./test01.cat", 50, 10, 1 ) )
|
|
|
|
exit( st );
|
2022-03-21 11:05:59 +01:00
|
|
|
|
|
|
|
/* Create */
|
2024-03-26 13:36:50 +01:00
|
|
|
for ( i = 0; i < N_THREADS; i++ )
|
|
|
|
if ( st = pthread_create( &( t[ i ] ), NULL, task, ( void* )i ) ) {
|
|
|
|
printf( "pthread_create: error %d", st );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
2022-03-21 11:05:59 +01:00
|
|
|
|
|
|
|
/* Join */
|
2024-03-26 13:36:50 +01:00
|
|
|
for ( i = 0; i < N_THREADS; i++ )
|
|
|
|
if ( st = pthread_join( t[ i ], &ret ) ) {
|
|
|
|
printf( "pthread_join: error %d", st );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
2022-03-21 11:05:59 +01:00
|
|
|
|
|
|
|
/* Exit Chf */
|
|
|
|
ChfExit();
|
|
|
|
#endif
|
2024-03-26 13:36:50 +01:00
|
|
|
exit( EXIT_SUCCESS );
|
2022-03-21 11:05:59 +01:00
|
|
|
}
|