static void test_varbuf_map_char(void) { struct varbuf vb; varbuf_init(&vb, 5); varbuf_add_buf(&vb, "1234a5678a9012a", 15); varbuf_map_char(&vb, 'a', 'z'); test_pass(vb.used == 15); test_pass(vb.size >= vb.used); test_mem(vb.buf, ==, "1234z5678z9012z", 15); varbuf_destroy(&vb); }
int main( int argc, char **argv ) { int i, rc, retval; pthread_t id[NUM_THREADS]; pthread_attr_t attr; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ printf( "%s: Using %d threads\n\n", argv[0], NUM_THREADS ); printf ( "Does non-threaded overflow work with extraneous threads present?\n" ); pthread_attr_init( &attr ); #ifdef PTHREAD_CREATE_UNDETACHED pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED ); #endif #ifdef PTHREAD_SCOPE_SYSTEM retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); if ( retval != 0 ) test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval ); #endif for ( i = 0; i < NUM_THREADS; i++ ) { rc = pthread_create( &id[i], &attr, thread_fn, NULL ); if ( rc ) test_fail( __FILE__, __LINE__, "pthread_create", rc ); } pthread_attr_destroy( &attr ); mainloop( NUM_ITERS ); test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
static void test_trig_name_is_illegal(void) { /* Test invalid trigger names. */ test_fail(trig_name_is_illegal("") == NULL); test_fail(trig_name_is_illegal("\a") == NULL); test_fail(trig_name_is_illegal("\t") == NULL); test_fail(trig_name_is_illegal("\200") == NULL); test_fail(trig_name_is_illegal("trigger name") == NULL); /* Test valid trigger names. */ test_pass(trig_name_is_illegal("TRIGGER") == NULL); test_pass(trig_name_is_illegal("trigger") == NULL); test_pass(trig_name_is_illegal("0123456789") == NULL); test_pass(trig_name_is_illegal("/file/trigger") == NULL); }
int main(int argc, char **argv) { int num_tests = 6; long length; int mask; int retval; int mythreshold=THRESHOLD; const PAPI_hw_info_t *hw_info; const PAPI_exe_info_t *prginfo; caddr_t start, end; prof_init(argc, argv, &hw_info, &prginfo); mask = prof_events(num_tests,hw_info); #ifdef PROFILE_ALL /* use these lines to profile entire code address space */ start = prginfo->address_info.text_start; end = prginfo->address_info.text_end; #else /* use these lines to profile only do_flops address space */ start = (caddr_t)do_flops; end = (caddr_t)fdo_flops; /* Itanium and ppc64 processors return function descriptors instead of function addresses. You must dereference the descriptor to get the address. */ #if defined(ITANIUM1) || defined(ITANIUM2) || defined(__powerpc64__) start = (caddr_t)(((struct fdesc *)start)->ip); end = (caddr_t)(((struct fdesc *)end)->ip); #endif #endif #if defined(linux) { char *tmp = getenv("THRESHOLD"); if (tmp) mythreshold = atoi(tmp); } #endif length = end - start; if (length < 0) test_fail(__FILE__, __LINE__, "Profile length < 0!", length); prof_print_address("Test case profile: POSIX compatible profiling with hardware counters.\n",prginfo); prof_print_prof_info(start,end,mythreshold,event_name); retval = do_profile(start, length, FULL_SCALE, mythreshold, PAPI_PROFIL_BUCKET_16); if (retval) retval = do_profile(start, length, FULL_SCALE, mythreshold, PAPI_PROFIL_BUCKET_32); if (retval) retval = do_profile(start, length, FULL_SCALE, mythreshold, PAPI_PROFIL_BUCKET_64); remove_test_events(&EventSet, mask); if (retval) test_pass(__FILE__, values, num_tests); else test_fail(__FILE__, __LINE__, "No information in buffers", 1); exit(1); }
int main(int argc, char **argv) { int i, retval; long long elapsed_us, elapsed_cyc; tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ retval = PAPI_library_init(PAPI_VER_CURRENT); if (retval != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); hw_info = PAPI_get_hardware_info(); if (hw_info == NULL) test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2); elapsed_us = PAPI_get_real_usec(); elapsed_cyc = PAPI_get_real_cyc(); #if defined(_AIX) retval = PAPI_thread_init((unsigned long (*)(void)) (pthread_self)); if (retval != PAPI_OK) { if (retval == PAPI_ESBSTR) test_skip(__FILE__, __LINE__, "PAPI_thread_init", retval); else test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval); } #pragma ibm parallel_loop #elif defined(sgi) && defined(mips) retval = PAPI_thread_init((unsigned long (*)(void)) (mp_my_threadnum)); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval); } #pragma parallel #pragma local(i) #pragma pfor #elif defined(sun) && defined(sparc) retval = PAPI_thread_init((unsigned long (*)(void)) (thr_self)); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval); } #pragma MP taskloop private(i) #else #error "Architecture not included in this test file yet." #endif for (i = 1; i < 3; i++) Thread(i, 10000000 * i); elapsed_cyc = PAPI_get_real_cyc() - elapsed_cyc; elapsed_us = PAPI_get_real_usec() - elapsed_us; if (!TESTS_QUIET) { printf("Master real usec : \t%lld\n", elapsed_us); printf("Master real cycles : \t%lld\n", elapsed_cyc); } test_pass(__FILE__, NULL, 0); exit(1); }
int main(int argc, char **argv) { int retval; const PAPI_component_info_t *cmpinfo; tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); if ((cmpinfo = PAPI_get_component_info(0)) == NULL) test_fail(__FILE__, __LINE__, "PAPI_get_component_info", retval); printf("name: %s\n",cmpinfo->name); printf("substrate_version: %s\n",cmpinfo->version); printf("support_version: %s\n",cmpinfo->support_version); printf("kernel_version: %s\n",cmpinfo->kernel_version); printf("num_cntrs: %d\n",cmpinfo->num_cntrs); printf("num_mpx_cntrs: %d\n",cmpinfo->num_mpx_cntrs); printf("num_preset_events: %d\n",cmpinfo->num_preset_events); /* Number of counters the substrate supports */ printf("num_native_events: %d\n",cmpinfo->num_native_events); /* Number of counters the substrate supports */ printf("default_domain: 0x%x (%s)\n",cmpinfo->default_domain,stringify_all_domains(cmpinfo->default_domain)); printf("available_domains: 0x%x (%s)\n",cmpinfo->available_domains,stringify_all_domains(cmpinfo->available_domains)); /* Available domains */ printf("default_granularity: 0x%x (%s)\n",cmpinfo->default_granularity,stringify_granularity(cmpinfo->default_granularity)); /* The default granularity when this substrate is used */ printf("available_granularities: 0x%x (%s)\n",cmpinfo->available_granularities,stringify_all_granularities(cmpinfo->available_granularities)); /* Available granularities */ printf("itimer_sig: %d\n",cmpinfo->itimer_sig); printf("itimer_num: %d\n",cmpinfo->itimer_num); printf("itimer_ns: %d\n",cmpinfo->itimer_ns); printf("itimer_res_ns: %d\n",cmpinfo->itimer_res_ns); printf("hardware_intr_sig: %d\n",cmpinfo->hardware_intr_sig); /* Width of opcode matcher if exists, 0 if not */ printf("clock_ticks: %d\n",cmpinfo->clock_ticks); printf("opcode_match_width: %d\n",cmpinfo->opcode_match_width); /* Width of opcode matcher if exists, 0 if not */ /* printf("reserved_ints[4]: %d\n",cmpinfo->reserved_ints[4]); */ printf("hardware_intr: %d\n",cmpinfo->hardware_intr); /* Needs hw overflow intr to be emulated in software*/ printf("precise_intr: %d\n",cmpinfo->precise_intr); /* Performance interrupts happen precisely */ printf("posix1b_timers: %d\n",cmpinfo->posix1b_timers); /* Performance interrupts happen precisely */ printf("kernel_profile: %d\n",cmpinfo->kernel_profile); /* Needs kernel profile support (buffered interrupts) to be emulated */ printf("kernel_multiplex: %d\n",cmpinfo->kernel_multiplex); /* In kernel multiplexing */ printf("data_address_range: %d\n",cmpinfo->data_address_range); /* Supports data address range limiting */ printf("instr_address_range: %d\n",cmpinfo->instr_address_range); /* Supports instruction address range limiting */ printf("fast_counter_read: %d\n",cmpinfo->fast_counter_read); /* Has a fast counter read */ printf("fast_real_timer: %d\n",cmpinfo->fast_real_timer); /* Has a fast real timer */ printf("fast_virtual_timer: %d\n",cmpinfo->fast_virtual_timer); /* Has a fast virtual timer */ printf("attach: %d\n",cmpinfo->attach); /* Has a fast virtual timer */ printf("attach_must_ptrace: %d\n",cmpinfo->attach_must_ptrace); /* Has a fast virtual timer */ printf("edge_detect: %d\n",cmpinfo->edge_detect); /* Has a fast virtual timer */ printf("invert: %d\n",cmpinfo->invert); /* Has a fast virtual timer */ printf("profile_ear: %d\n",cmpinfo->profile_ear); /* Supports data/instr/tlb miss address sampling */ printf("cntr_groups: %d\n",cmpinfo->cntr_groups); /* Underlying hardware uses counter groups */ printf("cntr_umasks: %d\n",cmpinfo->cntr_umasks); /* counters have unit masks */ printf("cntr_IEAR_events: %d\n",cmpinfo->cntr_IEAR_events); /* counters support instr event addr register */ printf("cntr_DEAR_events: %d\n",cmpinfo->cntr_DEAR_events); /* counters support data event addr register */ printf("cntr_OPCM_events: %d\n",cmpinfo->cntr_OPCM_events); /* counter events support opcode matching */ test_pass(__FILE__, NULL, 0); exit(0); }
int main( int argc, char **argv ) { extern void dummy( void * ); float matrixa[INDEX][INDEX], matrixb[INDEX][INDEX], mresult[INDEX][INDEX]; float real_time, proc_time, ipc; long long ins; int retval; int i, j, k; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ /* Initialize the Matrix arrays */ for( i = 0; i < INDEX; i++ ) { for( j= 0; j < INDEX; j++ ) { mresult[i][j] = 0.0; matrixa[i][j] = matrixb[i][j] = ( float ) rand( ) * ( float ) 1.1; } } /* Setup PAPI library and begin collecting data from the counters */ if ( ( retval = PAPI_ipc( &real_time, &proc_time, &ins, &ipc ) ) < PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_ipc", retval ); /* Matrix-Matrix multiply */ for ( i = 0; i < INDEX; i++ ) for ( j = 0; j < INDEX; j++ ) for ( k = 0; k < INDEX; k++ ) mresult[i][j] = mresult[i][j] + matrixa[i][k] * matrixb[k][j]; /* Collect the data into the variables passed in */ if ( ( retval = PAPI_ipc( &real_time, &proc_time, &ins, &ipc ) ) < PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_ipc", retval ); dummy( ( void * ) mresult ); if ( !TESTS_QUIET ) { printf( "Real_time: %f Proc_time: %f Total ins: ", real_time, proc_time ); printf( LLDFMT, ins ); printf( " IPC: %f\n", ipc ); } /* This should not happen unless the optimizer */ /* gets too good */ if (ins < INDEX*INDEX) { test_fail( __FILE__, __LINE__, "Instruction count too low.", 5 ); } /* Something is broken, or else you have a really */ /* slow processor */ if (ipc<0.01 ) { test_fail( __FILE__, __LINE__, "IPC equals zero.", 5 ); } test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
int main(void) { char tmp[] = test_simple; if(test(tmp, test_simple_right)) test_fail(); test_pass(); }
static void test_ctype(void) { int c; for (c = -1; c < 256; c++) { /* Test blank. */ if (c == '\t' || c == ' ') test_pass(c_isblank(c)); else test_fail(c_isblank(c)); /* Test white. */ if (c == '\t' || c == ' ' || c == '\n') test_pass(c_iswhite(c)); else test_fail(c_iswhite(c)); /* Test space. */ if (c == '\t' || c == '\v' || c == '\f' || c == '\r' || c == '\n' || c == ' ') test_pass(c_isspace(c)); else test_fail(c_isspace(c)); /* Test digit. */ if (c >= '0' && c <= '9') test_pass(c_isdigit(c)); else test_fail(c_isdigit(c)); /* Test lower case. */ if (c >= 'a' && c <= 'z') test_pass(c_islower(c)); else test_fail(c_islower(c)); /* Test upper case. */ if (c >= 'A' && c <= 'Z') test_pass(c_isupper(c)); else test_fail(c_isupper(c)); /* Test alpha. */ if (c_islower(c) || c_isupper(c)) test_pass(c_isalpha(c)); else test_fail(c_isalpha(c)); /* Test alphanumeric. */ if (c_isdigit(c) || c_isalpha(c)) test_pass(c_isalnum(c)); else test_fail(c_isalnum(c)); } }
static void test_varbuf_grow(void) { struct varbuf vb; size_t old_size; int i; varbuf_init(&vb, 10); /* Test that we grow when needed. */ varbuf_grow(&vb, 100); test_pass(vb.used == 0); test_pass(vb.size >= 100); old_size = vb.size; /* Test that we are not leaking. */ for (i = 0; i < 10; i++) { varbuf_grow(&vb, 100); test_pass(vb.used == 0); test_pass(vb.size >= 100); test_pass(vb.size == old_size); } /* Test that we grow when needed, with used space. */ vb.used = 10; varbuf_grow(&vb, 100); test_pass(vb.used == 10); test_pass(vb.size >= 110); varbuf_destroy(&vb); }
int main(int argc, char** argv) { int Events[NUM_EVENTS]; const char* names[NUM_EVENTS] = {"OPEN_CALLS", "OPEN_FDS", "READ_CALLS", "READ_BYTES", "READ_USEC", "READ_ERR", "READ_INTERRUPTED", "READ_WOULD_BLOCK", "WRITE_CALLS","WRITE_BYTES","WRITE_USEC", "WRITE_WOULD_BLOCK"}; long long values[NUM_EVENTS]; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); int version = PAPI_library_init (PAPI_VER_CURRENT); if (version != PAPI_VER_CURRENT) { fprintf(stderr, "PAPI_library_init version mismatch\n"); exit(1); } if (!TESTS_QUIET) fprintf(stderr, "This program will read from stdin and echo it to stdout\n"); int retval; int e; for (e=0; e<NUM_EVENTS; e++) { retval = PAPI_event_name_to_code((char*)names[e], &Events[e]); if (retval != PAPI_OK) { fprintf(stderr, "Error getting code for %s\n", names[e]); exit(2); } } /* Start counting events */ if (PAPI_start_counters(Events, NUM_EVENTS) != PAPI_OK) { fprintf(stderr, "Error in PAPI_start_counters\n"); exit(1); } int bytes = 0; char buf[1024]; //if (PAPI_read_counters(values, NUM_EVENTS) != PAPI_OK) // handle_error(1); //printf("After reading the counters: %lld\n",values[0]); while ((bytes = read(0, buf, 1024)) > 0) { write(1, buf, bytes); } /* Stop counting events */ if (PAPI_stop_counters(values, NUM_EVENTS) != PAPI_OK) { fprintf(stderr, "Error in PAPI_stop_counters\n"); } if (!TESTS_QUIET) { printf("----\n"); for (e=0; e<NUM_EVENTS; e++) printf("%s: %lld\n", names[e], values[e]); } test_pass( __FILE__, NULL, 0 ); return 0; }
static void test_varbuf_dup_char(void) { struct varbuf vb; varbuf_init(&vb, 5); varbuf_dup_char(&vb, 'z', 10); test_pass(vb.used == 10); test_pass(vb.size >= vb.used); test_mem(vb.buf, ==, "zzzzzzzzzz", 10); varbuf_dup_char(&vb, 'y', 5); test_pass(vb.used == 15); test_pass(vb.size >= vb.used); test_mem(vb.buf, ==, "zzzzzzzzzzyyyyy", 15); varbuf_destroy(&vb); }
static void test_varbuf_addbuf(void) { struct varbuf vb; varbuf_init(&vb, 5); varbuf_add_buf(&vb, "1234567890", 10); test_pass(vb.used == 10); test_pass(vb.size >= vb.used); test_mem(vb.buf, ==, "1234567890", 10); varbuf_add_buf(&vb, "abcde", 5); test_pass(vb.used == 15); test_pass(vb.size >= vb.used); test_mem(vb.buf, ==, "1234567890abcde", 15); varbuf_destroy(&vb); }
static void test_varbuf_detach(void) { struct varbuf vb; char *str; varbuf_init(&vb, 0); varbuf_add_buf(&vb, "1234567890", 10); str = varbuf_detach(&vb); test_mem(str, ==, "1234567890", 10); test_pass(vb.used == 0); test_pass(vb.size == 0); test_pass(vb.buf == NULL); free(str); }
void verify_results( int dest[], int ref[], int size ) { int i; for ( i = 0; i < size; i++ ) { if ( !( dest[i] == ref[i] ) ) { test_fail( i, dest[i], ref[i] ); } } test_pass(); }
static void test_varbuf_trunc(void) { struct varbuf vb; varbuf_init(&vb, 50); /* Test that we truncate (grow). */ varbuf_trunc(&vb, 20); test_pass(vb.used == 20); test_pass(vb.size >= 50); /* Test that we truncate (shrink). */ varbuf_trunc(&vb, 10); test_pass(vb.used == 10); test_pass(vb.size >= 50); varbuf_destroy(&vb); }
int main( int argc, char **argv ) { double c, a = 0.999, b = 1.001; int n = 1000; int EventSet = PAPI_NULL; int retval; int i, j = 0; long long g1[2]; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ if ( ( retval = PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); if ( PAPI_query_event( PAPI_L2_TCM ) == PAPI_OK ) j++; if ( j == 1 && ( retval = PAPI_add_event( EventSet, PAPI_L2_TCM ) ) != PAPI_OK ) { if ( retval != PAPI_ECNFLCT ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); j--; /* The event was not added */ } i = j; if ( PAPI_query_event( PAPI_L2_DCM ) == PAPI_OK ) j++; if ( j == ( i + 1 ) && ( retval = PAPI_add_event( EventSet, PAPI_L2_DCM ) ) != PAPI_OK ) { if ( retval != PAPI_ECNFLCT ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); j--; /* The event was not added */ } if ( j ) { if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_start", retval ); for ( i = 0; i < n; i++ ) { c = a * b; } if (!TESTS_QUIET) fprintf(stdout,"c=%lf\n",c); if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_stop", retval ); } test_pass( __FILE__, NULL, 0 ); exit( 1 ); }
int main(int argc, char **argv) { pthread_t slaves[MAX_THREADS]; int rc, i, nthr; int retval; const PAPI_hw_info_t *hwinfo = NULL; #if defined(__ALPHA) && defined(__osf__) test_skip(__FILE__, __LINE__, "thread support not available on this platform!", PAPI_ESBSTR); #endif tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); if ((hwinfo = PAPI_get_hardware_info()) == NULL) test_fail(__FILE__, __LINE__, "PAPI_get_hardware_info", 2); retval = PAPI_thread_init((unsigned long (*)(void)) (pthread_self)); if (retval != PAPI_OK) { if (retval == PAPI_ESBSTR) test_skip(__FILE__, __LINE__, "PAPI_thread_init", retval); else test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval); } if (hwinfo->ncpu > MAX_THREADS) nthr = MAX_THREADS; else nthr = hwinfo->ncpu; printf("Creating %d threads\n", nthr); for (i=0;i<nthr;i++) { rc = pthread_create(&slaves[i], NULL, Slave, NULL); if (rc) { retval = PAPI_ESYS; test_fail(__FILE__, __LINE__, "pthread_create", retval); } } for (i=0;i<nthr;i++) { pthread_join(slaves[i], NULL); } printf("Expected: %lld Received: %lld\n", (long long)nthr*num_iters, count); if (nthr*num_iters != count) test_fail(__FILE__, __LINE__, "Thread Locks", 1); test_pass(__FILE__, NULL, 0); exit(1); }
void verify_results( uint dest[], uint ref[], int size ) { int temp = 0; int i; for ( i = 0; i < size*size; i++ ) { if ( !( dest[i] == ref[i] ) ) { test_fail( temp ); } } test_pass( temp ); }
int main( int argc, char **argv ) { pthread_t *td = NULL; long n; tests_quiet( argc, argv ); /*Set TESTS_QUIET variable */ if ( argc < 2 || sscanf( argv[1], "%d", &program_time ) < 1 ) program_time = 6; if ( argc < 3 || sscanf( argv[2], "%d", &threshold ) < 1 ) threshold = 20000000; if ( argc < 4 || sscanf( argv[3], "%d", &num_threads ) < 1 ) num_threads = 3; td = malloc((num_threads+1) * sizeof(pthread_t)); if (!td) test_fail( __FILE__, __LINE__, "td malloc failed", 1 ); printf( "program_time = %d, threshold = %d, num_threads = %d\n\n", program_time, threshold, num_threads ); if ( PAPI_library_init( PAPI_VER_CURRENT ) != PAPI_VER_CURRENT ) test_fail( __FILE__, __LINE__, "PAPI_library_init failed", 1 ); if ( PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) ) != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_thread_init failed", 1 ); if ( pthread_key_create( &key, NULL ) != 0 ) test_fail( __FILE__, __LINE__, "pthread key create failed", 1 ); gettimeofday( &start, NULL ); for ( n = 1; n <= num_threads; n++ ) { if ( pthread_create( &(td[n]), NULL, my_thread, ( void * ) n ) != 0 ) test_fail( __FILE__, __LINE__, "pthread create failed", 1 ); } my_thread( ( void * ) 0 ); /* wait for all the threads */ for ( n = 1; n <= num_threads; n++ ) { if ( pthread_join( td[n], NULL)) test_fail( __FILE__, __LINE__, "pthread join failed", 1 ); } free(td); printf( "done\n" ); test_pass( __FILE__, NULL, 0 ); return ( 0 ); }
static void test_varbuf_reset(void) { struct varbuf vb; varbuf_init(&vb, 10); varbuf_add_buf(&vb, "1234567890", 10); varbuf_reset(&vb); test_pass(vb.used == 0); test_pass(vb.size >= vb.used); varbuf_add_buf(&vb, "abcdefghijklmno", 15); test_pass(vb.used == 15); test_pass(vb.size >= vb.used); test_mem(vb.buf, ==, "abcdefghijklmno", 15); varbuf_destroy(&vb); }
int main( int argc, char **argv ) { int i, rc, retval; pthread_t id[NUM_THREADS]; pthread_attr_t attr; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ printf( "%s: Using %d threads\n\n", argv[0], NUM_THREADS ); printf ( "Does non-threaded multiplexing work with extraneous threads present?\n" ); /* Create a bunch of unused pthreads, to simulate threads created * by the system that the user doesn't know about. */ pthread_attr_init( &attr ); #ifdef PTHREAD_CREATE_UNDETACHED pthread_attr_setdetachstate( &attr, PTHREAD_CREATE_UNDETACHED ); #endif #ifdef PTHREAD_SCOPE_SYSTEM retval = pthread_attr_setscope( &attr, PTHREAD_SCOPE_SYSTEM ); if ( retval != 0 ) test_skip( __FILE__, __LINE__, "pthread_attr_setscope", retval ); #endif #ifdef PPC64 sigset_t sigprof; sigemptyset( &sigprof ); sigaddset( &sigprof, SIGPROF ); retval = sigprocmask( SIG_BLOCK, &sigprof, NULL ); if ( retval != 0 ) test_fail( __FILE__, __LINE__, "sigprocmask SIG_BLOCK", retval ); #endif for ( i = 0; i < NUM_THREADS; i++ ) { rc = pthread_create( &id[i], &attr, thread_fn, NULL ); if ( rc ) test_fail( __FILE__, __LINE__, "pthread_create", rc ); } pthread_attr_destroy( &attr ); #ifdef PPC64 retval = sigprocmask( SIG_UNBLOCK, &sigprof, NULL ); if ( retval != 0 ) test_fail( __FILE__, __LINE__, "sigprocmask SIG_UNBLOCK", retval ); #endif mainloop( NUM_ITERS ); test_pass( __FILE__, NULL, 0 ); exit( 0 ); }
int main(int argc, char **argv) { tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ printf("%s: Does PAPI_multiplex_init() handle lots of events?\n",argv[0]); printf("Using %d iterations\n", NUM_ITERS); case1(); test_pass(__FILE__, NULL, 0); exit(1); }
static void test_version_compare(void) { struct versionrevision a, b; blankversion(&a); blankversion(&b); test_fail(epochsdiffer(&a, &b)); a.epoch = 1; b.epoch = 2; test_pass(epochsdiffer(&a, &b)); /* Test for version equality. */ a = b = version(0, "0", "0"); test_pass(versioncompare(&a, &b) == 0); a = version(0, "0", "00"); b = version(0, "00", "0"); test_pass(versioncompare(&a, &b) == 0); a = b = version(1, "2", "3"); test_pass(versioncompare(&a, &b) == 0); /* Test for epoch difference. */ a = version(0, "0", "0"); b = version(1, "0", "0"); test_pass(versioncompare(&a, &b) < 0); test_pass(versioncompare(&b, &a) > 0); /* FIXME: Complete. */ }
/* Code coverage test for Node and List functions. */ void test_task_f(void *user_data) { List l; Node n1; Node n2; list_init(&l); n1.prio = 3; n1.name = "one"; n2.prio = 8; n2.name = "two"; assert(true == list_is_empty(&l)); assert(NULL == list_get_head(&l)); list_add_tail(&l, &n1); assert(false == list_is_empty(&l)); assert(&n1 == list_get_head(&l)); list_add_tail(&l, &n2); assert(&n1 == list_get_head(&l)); assert(&n1 == list_find(&l, "one")); assert(&n2 == list_find(&l, "two")); list_rem_head(&l); assert(&n2 == list_get_head(&l)); assert(NULL == list_find(&l, "one")); list_rem_head(&l); list_enqueue(&l, &n1); assert(&n1 == list_get_head(&l)); list_enqueue(&l, &n2); assert(&n2 == list_get_head(&l)); list_unlink(&n1); assert(&n2 == list_get_head(&l)); list_enqueue(&l, &n1); assert(&n2 == list_get_head(&l)); assert(&n2 == list_rem_head(&l)); assert(&n1 == list_rem_head(&l)); assert(NULL == list_rem_head(&l)); assert(NULL == list_rem_head(&l)); assert(3 == n1.prio); assert(8 == n2.prio); assert(NULL == list_find(&l, "one")); assert(NULL == list_find(&l, "two")); test_pass(); }
static void test_varbuf_end_str(void) { struct varbuf vb; varbuf_init(&vb, 10); varbuf_add_buf(&vb, "1234567890X", 11); test_pass(vb.used == 11); test_pass(vb.size >= vb.used); test_mem(vb.buf, ==, "1234567890X", 11); varbuf_trunc(&vb, 10); varbuf_end_str(&vb); test_pass(vb.used == 10); test_pass(vb.size >= vb.used + 1); test_pass(vb.buf[10] == '\0'); test_str(vb.buf, ==, "1234567890"); varbuf_destroy(&vb); }
static void test(void) { int fd; /* XXX: Shut up output, we just want the error code. */ fd = open("/dev/null", O_RDWR); test_pass(fd >= 0); dup2(fd, 1); dup2(fd, 2); test_subproc_fork(); }
int main(int argc, char** argv) { pthread_t *callThd; int i, numthrds; int retval; pthread_attr_t attr; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); int version = PAPI_library_init (PAPI_VER_CURRENT); if (version != PAPI_VER_CURRENT) { fprintf(stderr, "PAPI_library_init version mismatch\n"); exit(1); } pthread_attr_init(&attr); if (PAPI_thread_init(pthread_self) != PAPI_OK) { fprintf(stderr, "PAPI_thread_init returned an error\n"); exit(1); } #ifdef PTHREAD_CREATE_UNDETACHED pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED); #endif #ifdef PTHREAD_SCOPE_SYSTEM retval = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); if (retval != 0) { fprintf(stderr,"This system does not support kernel scheduled pthreads.\n"); exit(1); } #endif numthrds = NUM_INFILES; if (!TESTS_QUIET) printf("%d threads\n",numthrds); callThd = (pthread_t *)malloc(numthrds*sizeof(pthread_t)); int rc ; for (i=0;i<(numthrds-1);i++) { rc = pthread_create(callThd+i, &attr, ThreadIO, (void *) files[i]); if (rc != 0) perror("Error creating thread using pthread_create()"); } ThreadIO((void *)files[numthrds-1]); pthread_attr_destroy(&attr); for (i=0;i<(numthrds-1);i++) pthread_join(callThd[i], NULL); test_pass( __FILE__, NULL, 0 ); return 0; }
int main(void) { char *tmp; if(!(tmp = a_strdup(test_string))) test_fail(); if(strcmp(tmp, test_string)) test_fail(); a_free(tmp); test_pass(); }
int main(int argc, char **argv) { pthread_t t1, t2, t3, t4; pthread_attr_t attr; int retval; tests_quiet(argc, argv); /* Set TESTS_QUIET variable */ if ((retval = PAPI_library_init(PAPI_VER_CURRENT)) != PAPI_VER_CURRENT) test_fail(__FILE__, __LINE__, "PAPI_library_init", retval); retval = PAPI_thread_init((unsigned long (*)(void)) (pthread_self)); if (retval != PAPI_OK) { if (retval == PAPI_ESBSTR) test_skip(__FILE__, __LINE__, "PAPI_thread_init", retval); else test_fail(__FILE__, __LINE__, "PAPI_thread_init", retval); } if (!TESTS_QUIET) { printf("Test case: Clock latency and resolution.\n"); printf("Note: Virtual timers are proportional to # CPU's.\n"); printf("-------------------------------------------------\n"); } pthread_attr_init(&attr); #ifdef PTHREAD_CREATE_UNDETACHED pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_UNDETACHED); #endif #ifdef PTHREAD_SCOPE_SYSTEM retval = pthread_attr_setscope(&attr, PTHREAD_SCOPE_SYSTEM); if (retval != 0) test_skip(__FILE__, __LINE__, "pthread_attr_setscope", retval); #endif pthread_create(&t1, &attr, pthread_main, NULL); pthread_create(&t2, &attr, pthread_main, NULL); pthread_create(&t3, &attr, pthread_main, NULL); pthread_create(&t4, &attr, pthread_main, NULL); pthread_main(NULL); pthread_join(t1, NULL); pthread_join(t2, NULL); pthread_join(t3, NULL); pthread_join(t4, NULL); test_pass(__FILE__, NULL, 0); exit(0); }