void tests_quiet( int argc, char **argv ) { if ( ( argc > 1 ) && ( ( strcasecmp( argv[1], "TESTS_QUIET" ) == 0 ) || ( strcasecmp( argv[1], "-q" ) == 0 ) ) ) { TESTS_QUIET = 1; } else { int retval; retval = PAPI_set_debug( PAPI_VERB_ECONT ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_debug", retval ); } if (getenv("TESTS_COLOR")!=NULL) { TESTS_COLOR=1; } }
int main() { bert_encoder_t *encoder = test_encoder(output,OUTPUT_SIZE); bert_data_t *data; if (!(data = bert_data_create_int(0x00ffffff))) { test_fail("malloc failed"); } test_encoder_push(encoder,data); bert_data_destroy(data); bert_encoder_destroy(encoder); test_output(); return 0; }
char * stringify_granularity( int granularity ) { switch ( granularity ) { case PAPI_GRN_THR: return ( "PAPI_GRN_THR" ); case PAPI_GRN_PROC: return ( "PAPI_GRN_PROC" ); case PAPI_GRN_PROCG: return ( "PAPI_GRN_PROCG" ); case PAPI_GRN_SYS_CPU: return ( "PAPI_GRN_SYS_CPU" ); case PAPI_GRN_SYS: return ( "PAPI_GRN_SYS" ); default: test_fail( __FILE__, __LINE__, "Unrecognized granularity!", 0 ); } return ( NULL ); }
char * stringify_domain( int domain ) { switch ( domain ) { case PAPI_DOM_SUPERVISOR: return ( "PAPI_DOM_SUPERVISOR" ); case PAPI_DOM_USER: return ( "PAPI_DOM_USER" ); case PAPI_DOM_KERNEL: return ( "PAPI_DOM_KERNEL" ); case PAPI_DOM_OTHER: return ( "PAPI_DOM_OTHER" ); case PAPI_DOM_ALL: return ( "PAPI_DOM_ALL" ); default: test_fail( __FILE__, __LINE__, "Unrecognized domains!", 0 ); } return ( NULL ); }
void event_create_eventList(int *eventSet, int eventCodeSetSize, int *eventCodeSet, int threadID) { int retval, i, maxNumberHwCounters, eventCodeSetMaxSize; PAPI_event_info_t info; maxNumberHwCounters = PAPI_get_opt( PAPI_MAX_HWCTRS, NULL ); printf("Max number of hardware counters = %d \n", maxNumberHwCounters); eventCodeSetMaxSize = PAPI_get_opt( PAPI_MAX_MPX_CTRS, NULL ); printf("Max number of multiplexed counters = %d \n", eventCodeSetMaxSize); if ( eventCodeSetMaxSize < eventCodeSetSize) test_fail( __FILE__, __LINE__, "eventCodeSetMaxSize < eventCodeSetSize, too many performance events defined! ", retval ); retval = PAPI_register_thread(); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval ); retval = PAPI_create_eventset( eventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval ); retval = PAPI_assign_eventset_component( *eventSet, 0 ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", retval ); retval = PAPI_set_multiplex( *eventSet ); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", retval ); for (i = 0; i < eventCodeSetSize; i++) { retval = PAPI_get_event_info(eventCodeSet[i], &info); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval ); retval = PAPI_add_event( *eventSet, info.event_code); if ( retval != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_add_event", retval ); else printf("Adding %s \n", info.symbol); } printf("event_create_eventList done \n"); }
void polybench_papi_close() { # ifdef _OPENMP #pragma omp parallel { if (omp_get_thread_num () == polybench_papi_counters_threadid) { # endif int retval; if ((retval = PAPI_destroy_eventset (&polybench_papi_eventset)) != PAPI_OK) test_fail (__FILE__, __LINE__, "PAPI_destroy_eventset", retval); if (PAPI_is_initialized ()) PAPI_shutdown (); # ifdef _OPENMP } } #pragma omp barrier # endif }
TEST_END static bool validate_fill(const void *p, uint8_t c, size_t offset, size_t len) { bool ret = false; const uint8_t *buf = (const uint8_t *)p; size_t i; for (i = 0; i < len; i++) { uint8_t b = buf[offset+i]; if (b != c) { test_fail("Allocation at %p contains %#x rather than " "%#x at offset %zu", p, b, c, offset+i); ret = true; } } return (ret); }
char * stringify_all_granularities( int granularities ) { static char buf[PAPI_HUGE_STR_LEN]; int i, did = 0; buf[0] = '\0'; for ( i = PAPI_GRN_MIN; i <= PAPI_GRN_MAX; i = i << 1 ) if ( granularities & i ) { if ( did ) strcpy( buf + strlen( buf ), "|" ); strcpy( buf + strlen( buf ), stringify_granularity( granularities & i ) ); did++; } if ( did == 0 ) test_fail( __FILE__, __LINE__, "Unrecognized granularity!", 0 ); return ( buf ); }
void check_values(int eventset, int *events, int nevents, long long *values, long long *refvalues) { double spread[MAXEVENTS]; int i = nevents, j = 0; if (!TESTS_QUIET) { printf("\nRelative accuracy:\n"); for (j = 0; j < nevents; j++) printf(" Event %.2d", j+1); printf("\n"); } for (j = 0; j < nevents; j++) { spread[j] = abs((int)(refvalues[j] - values[j])); if (values[j]) spread[j] /= (double) values[j]; if (!TESTS_QUIET) printf("%10.3g ", spread[j]); /* Make sure that NaN get counted as errors */ if (spread[j] < MPX_TOLERANCE) i--; else if (refvalues[j] < MINCOUNTS) /* Neglect inprecise results with low counts */ i--; } printf("\n\n"); #if 0 if (!TESTS_QUIET) { for (j = 0; j < nevents; j++) { PAPI_get_event_info(events[j], &info); printf("Event %.2d: ref=", j); printf(LLDFMT10, refvalues[j]); printf(", diff/ref=%7.2g -- %s\n", spread[j], info.short_descr); printf("\n"); } printf("\n"); } #endif if (i) test_fail(__FILE__, __LINE__, "Values outside threshold", i); }
int main (int argc, char ** argv) { printf ("LUA TESTS\n"); printf ("==================\n\n"); init (argc, argv); test_variable_passing (); test_two_scripts (); printf ("\n"); printf ("========================================================================\n"); printf ("NOTE: The following errors are intended. We're testing error conditions!\n"); printf ("========================================================================\n"); test_fail (); test_wrong (); printf ("\ntest_lua RESULTS: %d test(s) done. %d error(s).\n", nbTest, nbError); return nbError; }
static void test(void) { test_pass(1); test_fail(0); test_str("aaa", ==, "aaa"); test_str("aaa", <, "bbb"); test_str("ccc", >, "bbb"); test_str("ccc", !=, "bbb"); test_mem("aaa", ==, "aaa", 3); test_mem("aaa", <, "bbb", 3); test_mem("ccc", >, "bbb", 3); test_mem("ccc", !=, "bbb", 3); test_mem("abcd", ==, "abcd", 4); test_mem("abcd", ==, "abcd", 5); test_mem("ababcd", ==, "ababff", 4); test_mem("ababcd", !=, "ababff", 6); }
void test_rule_tag(const gchar *pattern, const gchar *tag, gboolean set) { LogMessage *msg = log_msg_new_empty(); gboolean found, result; PDBInput input; log_msg_set_value(msg, LM_V_MESSAGE, pattern, strlen(pattern)); log_msg_set_value(msg, LM_V_PROGRAM, "prog2", 5); log_msg_set_value(msg, LM_V_HOST, MYHOST, strlen(MYHOST)); log_msg_set_value(msg, LM_V_PID, MYPID, strlen(MYPID)); result = pattern_db_process(patterndb, PDB_INPUT_WRAP_MESSAGE(&input, msg)); found = log_msg_is_tag_by_name(msg, tag); if (set ^ found) test_fail("Tag '%s' is %sset for pattern '%s' (%d)\n", tag, found ? "" : "not ", pattern, !!result); log_msg_unref(msg); test_clean_state(); }
int main(int argc, char **argv) { int ret; struct uterm_monitor *mon; size_t onum; onum = sizeof(options) / sizeof(*options); ret = test_prepare(options, onum, argc, argv, &eloop); if (ret) goto err_fail; if (!setlocale(LC_ALL, "")) { log_err("Cannot set locale: %m"); ret = -EFAULT; goto err_exit; } ret = uterm_monitor_new(&mon, eloop, monitor_event, NULL); if (ret) goto err_exit; ret = ev_eloop_register_signal_cb(eloop, SIGQUIT, sig_quit, NULL); if (ret) goto err_mon; system("stty -echo"); uterm_monitor_scan(mon); ev_eloop_run(eloop, -1); system("stty echo"); ev_eloop_unregister_signal_cb(eloop, SIGQUIT, sig_quit, NULL); err_mon: uterm_monitor_unref(mon); err_exit: test_exit(options, onum, eloop); err_fail: if (ret != -ECANCELED) test_fail(ret); return abs(ret); }
int main(int argc, char **argv) { struct perf_event_attr pe; int fd; int quiet=0; int kernel_size; quiet=test_quiet(); if (!quiet) { printf("This test checks what happens if attr struct is " "exactly what the kernel expects.\n"); } kernel_size=sizeof(struct perf_event_attr); memset(&pe,0,kernel_size); pe.size=kernel_size; pe.type=PERF_TYPE_HARDWARE; pe.config=PERF_COUNT_HW_INSTRUCTIONS; pe.disabled=1; pe.exclude_kernel=1; pe.exclude_hv=1; arch_adjust_domain(&pe,quiet); fd=perf_event_open(&pe,0,-1,-1,0); if (fd<0) { fprintf(stderr,"Error opening leader %llx %s\n", pe.config,strerror(errno)); test_fail(test_string); } close(fd); test_pass(test_string); return 0; }
int main(int argc, char **argv) { int ret; struct ev_eloop *eloop; struct kmscon_vt *vt; ret = test_prepare(argc, argv, &eloop); if (ret) goto err_fail; ret = kmscon_vt_new(&vt, NULL, NULL); if (ret) goto err_exit; ret = kmscon_vt_open(vt, KMSCON_VT_NEW, eloop); if (ret) goto err_vt; ret = kmscon_vt_enter(vt); if (ret) log_warn("Cannot switch to VT"); ev_eloop_run(eloop, -1); log_debug("Terminating\n"); /* switch back to previous VT but wait for eloop to process SIGUSR0 */ ret = kmscon_vt_leave(vt); if (ret == -EINPROGRESS) ev_eloop_run(eloop, 50); err_vt: kmscon_vt_unref(vt); err_exit: test_exit(eloop); err_fail: test_fail(ret); return abs(ret); }
int main(){ fixtureSetup(); resetTestCount(); testStarted("test_1_returns_false_if_string_not_matches"); setup(); test_1_returns_false_if_string_not_matches(); tearDown(); testEnded(); testStarted("test_2_returns_true_if_string_matches"); setup(); test_2_returns_true_if_string_matches(); tearDown(); testEnded(); testStarted("test_3_returns_true_if_whole_string_matches"); setup(); test_3_returns_true_if_whole_string_matches(); tearDown(); testEnded(); testStarted("test_4_returns_false_if_string_does_not_match"); setup(); test_4_returns_false_if_string_does_not_match(); tearDown(); testEnded(); testStarted("test_5_returns_false_if_string_not_matches"); setup(); test_5_returns_false_if_string_not_matches(); tearDown(); testEnded(); testStarted("test_fail"); setup(); test_fail(); tearDown(); testEnded(); summarizeTestCount(); fixtureTearDown(); return 0; }
static void test_kabi_query(void *fixture) { // Remember, matches regexes from last to first. static const char *_patterns[] = { ".*", ".*/dev/md.*", "loop" }; static struct { const char *input; int r; } _cases[] = { {"foo", 0}, {"/dev/mapper/vg-lvol1", 0}, {"/dev/mapper/vglvol1", 0}, {"/dev/md1", 1}, {"loop", 2}, }; int r; unsigned i; struct dm_pool *mem = fixture; struct dm_regex *scanner; scanner = dm_regex_create(mem, _patterns, DM_ARRAY_SIZE(_patterns)); T_ASSERT(scanner != NULL); for (i = 0; i < DM_ARRAY_SIZE(_cases); i++) { r = dm_regex_match(scanner, _cases[i].input); if (r != _cases[i].r) { test_fail("'%s' expected to match '%s', but matched %s", _cases[i].input, _cases[i].r >= DM_ARRAY_SIZE(_patterns) ? "<nothing>" : _patterns[_cases[i].r], r >= DM_ARRAY_SIZE(_patterns) ? "<nothing>" : _patterns[r]); } } }
int main(int argc, char *argv[]) { START(argc, argv, "obj_ctl_alignment"); if (argc != 2) UT_FATAL("usage: %s file-name", argv[0]); const char *path = argv[1]; if ((pop = pmemobj_create(path, LAYOUT, PMEMOBJ_MIN_POOL * 10, S_IWUSR | S_IRUSR)) == NULL) UT_FATAL("!pmemobj_create: %s", path); test_fail(); test_aligned_allocs(1024, 512, POBJ_HEADER_NONE); test_aligned_allocs(1024, 512, POBJ_HEADER_COMPACT); test_aligned_allocs(64, 64, POBJ_HEADER_COMPACT); pmemobj_close(pop); DONE(NULL); }
int add_two_nonderived_events( int *num_events, int *papi_event, int *mask ) { /* query and set up the right event to monitor */ int EventSet = PAPI_NULL; #define POTENTIAL_EVENTS 3 unsigned int potential_evt_to_add[POTENTIAL_EVENTS][2] = { {( unsigned int ) PAPI_FP_INS, MASK_FP_INS}, {( unsigned int ) PAPI_FP_OPS, MASK_FP_OPS}, {( unsigned int ) PAPI_TOT_INS, MASK_TOT_INS} }; int event_found = 0,i; *mask = 0; for(i=0;i<POTENTIAL_EVENTS;i++) { if ( PAPI_query_event( ( int ) potential_evt_to_add[i][0] ) == PAPI_OK ) { if ( !is_event_derived(potential_evt_to_add[i][0])) { event_found = 1; break; } } } if ( event_found ) { *papi_event = ( int ) potential_evt_to_add[i][0]; *mask = ( int ) potential_evt_to_add[i][1] | MASK_TOT_CYC; EventSet = add_test_events( num_events, mask, 0 ); } else { test_fail( __FILE__, __LINE__, "Not enough room to add an event!", 0 ); } return EventSet; }
int uORBTest::UnitTest::pub_test_queue_main() { struct orb_test_medium t; orb_advert_t ptopic; const unsigned int queue_size = 50; t.val = 0; if ((ptopic = orb_advertise_queue(ORB_ID(orb_test_medium_queue_poll), &t, queue_size)) == nullptr) { _thread_should_exit = true; return test_fail("advertise failed: %d", errno); } int message_counter = 0, num_messages = 20 * queue_size; ++t.val; while (message_counter < num_messages) { //simulate burst int burst_counter = 0; while (burst_counter++ < queue_size / 2 + 7) { //make interval non-boundary aligned orb_publish(ORB_ID(orb_test_medium_queue_poll), ptopic, &t); ++t.val; } message_counter += burst_counter; usleep(20 * 1000); //give subscriber a chance to catch up } _num_messages_sent = t.val; usleep(100 * 1000); _thread_should_exit = true; orb_unadvertise(ptopic); return 0; }
int main (int argc, char *argv[]) { int ret = 0; struct SplittedHTTPAddress * spa; GNUNET_log_setup ("test", "DEBUG", NULL); spa = http_split_address (""); if (NULL != spa) { clean (spa); spa = NULL; GNUNET_break (0); } spa = http_split_address ("http://"); if (NULL != spa) { clean (spa); GNUNET_break (0); } spa = http_split_address ("://"); if (NULL != spa) { clean (spa); GNUNET_break (0); } test_pass_hostname (); test_pass_ipv4 (); test_fail_ipv6 (); test_fail (); return ret; }
void parser_tests(void) { parser * par; lexer * lex; printf("Running parser tests...\n"); printf("Created script.\n"); if(0 == (lex = lex_new_file("test.oca"))) { printf("Unable to create lexer.\n"); return; } printf("Created lexer.\n"); printf("par_new()\n"); if(0 == (par = par_new(lex))) { printf("Failed to create parser\n"); test_fail(); return; } test_pass(); lex_del(lex); par_del(par); printf("Completed parser tests\n"); }
int add_two_nonderived_events( int *num_events, int *papi_event, int *mask ) { /* query and set up the right event to monitor */ int EventSet = PAPI_NULL; #define POTENTIAL_EVENTS 3 unsigned int potential_evt_to_add[POTENTIAL_EVENTS][2] = { {( unsigned int ) PAPI_FP_INS, MASK_FP_INS}, {( unsigned int ) PAPI_FP_OPS, MASK_FP_OPS}, {( unsigned int ) PAPI_TOT_INS, MASK_TOT_INS} }; int i; *mask = 0; /* could leak up to two event sets. */ for(i=0;i<POTENTIAL_EVENTS;i++) { if ( PAPI_query_event( ( int ) potential_evt_to_add[i][0] ) == PAPI_OK ) { if ( !is_event_derived(potential_evt_to_add[i][0])) { *papi_event = ( int ) potential_evt_to_add[i][0]; *mask = ( int ) potential_evt_to_add[i][1] | MASK_TOT_CYC; EventSet = add_test_events( num_events, mask, 0 ); if ( *num_events == 2 ) break; } } } if ( i == POTENTIAL_EVENTS ) { test_fail( __FILE__, __LINE__, "Can't find a non-derived event!", 0 ); } return EventSet; }
void ref_measurements(int iters, int *eventset, int *events, int nevents, long long *refvalues) { PAPI_event_info_t info; int i, retval; double x = 1.1, y; long long t1, t2; printf("PAPI reference measurements:\n"); if ((retval = PAPI_create_eventset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_create_eventset", retval); for (i = 0; i < nevents; i++) { if ((retval = PAPI_add_event(*eventset, events[i]))) test_fail(__FILE__, __LINE__, "PAPI_add_event", retval); x = 1.0; t1 = PAPI_get_real_usec(); if ((retval = PAPI_start(*eventset))) test_fail(__FILE__, __LINE__, "PAPI_start", retval); y = dummy3(x, iters); if ((retval = PAPI_stop(*eventset, &refvalues[i]))) test_fail(__FILE__, __LINE__, "PAPI_stop", retval); t2 = PAPI_get_real_usec(); #if 0 printf("\tOperations= %.1f Mflop", y * 1e-6); printf("\t(%g Mflop/s)\n\n", ((float) y / (t2 - t1))); #endif PAPI_get_event_info(events[i], &info); printf("%20s = ", info.short_descr); printf(LLDFMT, refvalues[i]); printf("\n"); if ((retval = PAPI_cleanup_eventset(*eventset))) test_fail(__FILE__, __LINE__, "PAPI_cleanup_eventset", retval); } if ((retval = PAPI_destroy_eventset(eventset))) test_fail(__FILE__, __LINE__, "PAPI_destroy_eventset", retval); *eventset = PAPI_NULL; }
void test_output() { if (output[0] != BERT_MAGIC) { test_fail("bert_encoder_push did not add the magic byte"); } if (output[1] != BERT_SMALL_TUPLE) { test_fail("bert_encoder_push did not add the SMALL_TUPLE magic byte"); } if (output[2] != EXPECTED_LENGTH) { test_fail("bert_encoder_push encoded %u as the tuple length, expected %u",output[2],EXPECTED_LENGTH); } if (output[3] != BERT_SMALL_INT) { test_fail("bert_encoder_push failed to encode the first small int of the tuple"); } if (output[4] != 1) { test_fail("bert_encoder_push wrote %u as the first small int, expected %u",output[4],1); } if (output[5] != BERT_SMALL_INT) { test_fail("bert_encoder_push failed to encode the second small int of the tuple"); } if (output[6] != 2) { test_fail("bert_encoder_push wrote %u as the second small int, expected %u",output[6],2); } }
int main( int argc, char **argv ) { int nthreads = 8, ret, i; PAPI_event_info_t info; pthread_t *threads; const PAPI_hw_info_t *hw_info; tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ if ( !TESTS_QUIET ) { if ( argc > 1 ) { int tmp = atoi( argv[1] ); if ( tmp >= 1 ) nthreads = tmp; } } ret = PAPI_library_init( PAPI_VER_CURRENT ); if ( ret != PAPI_VER_CURRENT ) { test_fail( __FILE__, __LINE__, "PAPI_library_init", ret ); } hw_info = PAPI_get_hardware_info( ); if ( hw_info == NULL ) test_fail( __FILE__, __LINE__, "PAPI_get_hardware_info", 2 ); if ( strcmp( hw_info->model_string, "POWER6" ) == 0 ) { ret = PAPI_set_domain( PAPI_DOM_ALL ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_domain", ret ); } } ret = PAPI_thread_init( ( unsigned long ( * )( void ) ) pthread_self ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_thread_init", ret ); } ret = PAPI_multiplex_init( ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_multiplex_init", ret ); } /* Fill up the event set with as many non-derived events as we can */ i = PAPI_PRESET_MASK; do { if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) { if ( info.count == 1 ) { events[numevents++] = ( int ) info.event_code; printf( "Added %s\n", info.symbol ); } else { printf( "Skipping derived event %s\n", info.symbol ); } } } while ( ( PAPI_enum_event( &i, PAPI_PRESET_ENUM_AVAIL ) == PAPI_OK ) && ( numevents < PAPI_MPX_DEF_DEG ) ); printf( "Found %d events\n", numevents ); do_stuff( ); printf( "Creating %d threads:\n", nthreads ); threads = ( pthread_t * ) malloc( ( size_t ) nthreads * sizeof ( pthread_t ) ); if ( threads == NULL ) { test_fail( __FILE__, __LINE__, "malloc", PAPI_ENOMEM ); } /* Create the threads */ for ( i = 0; i < nthreads; i++ ) { ret = pthread_create( &threads[i], NULL, thread, NULL ); if ( ret != 0 ) { test_fail( __FILE__, __LINE__, "pthread_create", PAPI_ESYS ); } } /* Wait for thread completion */ for ( i = 0; i < nthreads; i++ ) { ret = pthread_join( threads[i], NULL ); if ( ret != 0 ) { test_fail( __FILE__, __LINE__, "pthread_join", PAPI_ESYS ); } } printf( "Done." ); test_pass( __FILE__, NULL, 0 ); pthread_exit( NULL ); exit( 0 ); }
void * thread( void *arg ) { ( void ) arg; /*unused */ int eventset = PAPI_NULL; long long values[PAPI_MPX_DEF_DEG]; int ret = PAPI_register_thread( ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_register_thread", ret ); ret = PAPI_create_eventset( &eventset ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_create_eventset", ret ); printf( "Event set %d created\n", eventset ); /* In Component PAPI, EventSets must be assigned a component index before you can fiddle with their internals. 0 is always the cpu component */ ret = PAPI_assign_eventset_component( eventset, 0 ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component", ret ); } ret = PAPI_set_multiplex( eventset ); if ( ret == PAPI_ENOSUPP) { test_skip( __FILE__, __LINE__, "Multiplexing not supported", 1 ); } else if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_set_multiplex", ret ); } ret = PAPI_add_events( eventset, events, numevents ); if ( ret < PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_add_events", ret ); } ret = PAPI_start( eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_start", ret ); } do_stuff( ); ret = PAPI_stop( eventset, values ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_stop", ret ); } ret = PAPI_cleanup_eventset( eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_cleanup_eventset", ret ); } ret = PAPI_destroy_eventset( &eventset ); if ( ret != PAPI_OK ) { test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", ret ); } ret = PAPI_unregister_thread( ); if ( ret != PAPI_OK ) test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", ret ); return ( NULL ); }
int main(int argc, char** argv) { int ret,quiet,i; struct perf_event_attr pe; struct sigaction sa; void *our_mmap; char test_string[]="Testing overflows on sibling..."; quiet=test_quiet(); if (!quiet) printf("This tests that overflows of siblings work.\n"); memset(&sa, 0, sizeof(struct sigaction)); sa.sa_sigaction = our_handler; sa.sa_flags = SA_SIGINFO; if (sigaction( SIGIO, &sa, NULL) < 0) { fprintf(stderr,"Error setting up signal handler\n"); exit(1); } memset(&pe,0,sizeof(struct perf_event_attr)); pe.type=PERF_TYPE_HARDWARE; pe.size=sizeof(struct perf_event_attr); pe.config=PERF_COUNT_HW_CPU_CYCLES; pe.sample_period=0; pe.sample_type=0; pe.read_format=PERF_FORMAT_GROUP|PERF_FORMAT_ID; pe.disabled=1; pe.pinned=0; pe.exclude_kernel=1; pe.exclude_hv=1; pe.wakeup_events=1; arch_adjust_domain(&pe,quiet); fd1=perf_event_open(&pe,0,-1,-1,0); if (fd1<0) { fprintf(stderr,"Error opening leader %llx\n",pe.config); test_fail(test_string); } pe.type=PERF_TYPE_HARDWARE; pe.config=PERF_COUNT_HW_INSTRUCTIONS; pe.sample_period=100000; pe.sample_type=PERF_SAMPLE_IP; pe.read_format=0; pe.disabled=0; pe.pinned=0; pe.exclude_kernel=1; pe.exclude_hv=1; arch_adjust_domain(&pe,quiet); fd2=perf_event_open(&pe,0,-1,fd1,0); if (fd2<0) { fprintf(stderr,"Error opening %llx\n",pe.config); test_fail(test_string); } /* large enough that threshold not a problem */ our_mmap=mmap(NULL, (1+MMAP_PAGES)*getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd2, 0); fcntl(fd2, F_SETFL, O_RDWR|O_NONBLOCK|O_ASYNC); fcntl(fd2, F_SETSIG, SIGIO); fcntl(fd2, F_SETOWN,getpid()); ioctl(fd1, PERF_EVENT_IOC_RESET, 0); ioctl(fd2, PERF_EVENT_IOC_RESET, 0); ret=ioctl(fd1, PERF_EVENT_IOC_ENABLE,0); if (ret<0) { if (!quiet) fprintf(stderr,"Error with PERF_EVENT_IOC_ENABLE of group leader: " "%d %s\n",errno,strerror(errno)); test_fail(test_string); } for(i=0;i<100;i++) { instructions_million(); } ret=ioctl(fd1, PERF_EVENT_IOC_DISABLE,0); if (!quiet) printf("Count: %d %p\n",count.total,our_mmap); if (count.total==0) { if (!quiet) printf("No overflow events generated.\n"); test_fail(test_string); } if (count.total!=1000) { if (!quiet) printf("Expected %d overflows, got %d.\n", count.total,100); test_fail(test_string); } close(fd1); close(fd2); test_pass(test_string); return 0; }
int main(int argc, char** argv) { int fd1,i; struct perf_event_attr pe1; int errors=0; int result; char test_string[]="Testing PERF_EVENT_IOC_SET_FILTER ioctl..."; quiet=test_quiet(); if (!quiet) { printf("Testing PERF_EVENT_IOC_SET_FILTER ioctl.\n"); } /****************************************************/ /* Check if /sys/kernel/debug/tracing/events exists */ /****************************************************/ // result=access("/sys/kernel/debug/tracing/events",F_OK); /* Actually this is pointless, as it gives EACCESS */ /* as a normal user even if the file exists */ /************************************/ /* Creating a tracepoint event */ /************************************/ if (!quiet) { printf("Creating a tracepoint event\n"); } memset(&pe1,0,sizeof(struct perf_event_attr)); pe1.type=PERF_TYPE_TRACEPOINT; pe1.size=sizeof(struct perf_event_attr); /* Find a trace event that will let us add a particular filter */ /* It should work with */ /* writeback:writeback_start*/ /* but we can't get the id of this directly without debugfs/tracefs */ /* mounted (the id numbers change depending on machine/kernel) */ /* Valid filter */ strcpy(filter,"nr_pages==2"); if (!quiet) { printf("Trying to find an event that will allow filter %s\n", filter); } /* Usually there are fewer than 1000 trace events? */ for(i=0;i<MAX_SEARCH;i++) { pe1.config=i; pe1.disabled=1; pe1.exclude_kernel=0; pe1.exclude_hv=0; arch_adjust_domain(&pe1,quiet); fd1=perf_event_open(&pe1,0,-1,-1,0); if (fd1<0) { if (!quiet) { // fprintf(stderr,"Failed on %d\n",i); } continue; } result=ioctl(fd1, PERF_EVENT_IOC_SET_FILTER, filter); if (result==0) { if (!quiet) printf("Found proper event %d\n",i); close(fd1); break; } else { } close(fd1); } if (i==MAX_SEARCH) { if (!quiet) { printf("Could not find any trace event to filter\n"); } test_skip(test_string); errors++; } pe1.config=i; pe1.disabled=1; pe1.exclude_kernel=0; pe1.exclude_hv=0; arch_adjust_domain(&pe1,quiet); /* Create group leader */ fd1=perf_event_open(&pe1,0,-1,-1,0); if (fd1<0) { if (!quiet) { fprintf(stderr,"Unexpected error %s\n",strerror(errno)); } test_fail(test_string); } for(i=0;i<MAX_FILTER;i++) { filter[i]=0xff; } /* Check a too big value */ if (!quiet) { printf("\t+ Checking a too-big event: "); } result=ioctl(fd1, PERF_EVENT_IOC_SET_FILTER, filter); if ((result==-1) && (errno==EINVAL)) { if (!quiet) printf("Failed as expected\n"); } else { if (!quiet) printf("Unexpected %d %s\n",result,strerror(errno)); errors++; } /* Check off-by-one value */ /* Size limited to pagesize */ if (!quiet) { printf("\t+ Checking off-by-one filter: "); } filter[4096]=0; result=ioctl(fd1, PERF_EVENT_IOC_SET_FILTER, filter); if ((result==-1) && (errno==EINVAL)) { if (!quiet) printf("Failed as expected\n"); } else { if (!quiet) printf("Unexpected %d %s\n",result,strerror(errno)); errors++; } /* Check a just-right value */ if (!quiet) { printf("\t+ Checking max size invalid filter: "); } filter[4095]=0; result=ioctl(fd1, PERF_EVENT_IOC_SET_FILTER, filter); if ((result==-1) && (errno==EINVAL)) { if (!quiet) printf("Failed as expected\n"); } else { if (!quiet) printf("Unexpected %d %s\n",result,strerror(errno)); errors++; } /* Check an empty value */ if (!quiet) { printf("\t+ Checking empty filter: "); } filter[0]=0; result=ioctl(fd1, PERF_EVENT_IOC_SET_FILTER, filter); if ((result==-1) && (errno==EINVAL)) { if (!quiet) printf("Failed as expected\n"); } else { if (!quiet) printf("Unexpected %d %s\n",result,strerror(errno)); errors++; } /* Clear a filter */ if (!quiet) { printf("\t+ Clear filter (write 0): "); } filter[0]='0'; filter[1]=0; result=ioctl(fd1, PERF_EVENT_IOC_SET_FILTER, filter); if ((result==-1) && (errno==EINVAL)) { if (!quiet) printf("Failed as expected\n"); } else { if (!quiet) printf("Unexpected %d %s\n",result,strerror(errno)); errors++; } /* tracefs usually under /sys/kernel/tracing */ /* start */ ioctl(fd1, PERF_EVENT_IOC_RESET, 0); ioctl(fd1, PERF_EVENT_IOC_ENABLE,0); /* million */ result=instructions_million(); /* stop */ ioctl(fd1, PERF_EVENT_IOC_DISABLE,0); close(fd1); if (errors) { test_fail(test_string); } test_pass(test_string); return 0; }
int main( int argc, char **argv ) { int EventSet = PAPI_NULL; long long values0[2],values1[2],values2[2]; int num_flops = 3000000, retval; int mythreshold = 1000000; char event_name1[PAPI_MAX_STR_LEN]; int PAPI_event; int cid,numcmp,rapl_cid; const PAPI_component_info_t *cmpinfo = NULL; /* Set TESTS_QUIET variable */ tests_quiet( argc, argv ); quiet=TESTS_QUIET; /* Init PAPI */ retval = PAPI_library_init( PAPI_VER_CURRENT ); if ( retval != PAPI_VER_CURRENT ) { test_fail(__FILE__, __LINE__,"PAPI_library_init",retval); } numcmp = PAPI_num_components(); for(cid=0; cid<numcmp; cid++) { if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) { test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0); } if (strstr(cmpinfo->name,"linux-rapl")) { rapl_cid=cid; if (!TESTS_QUIET) printf("Found rapl component at cid %d\n", rapl_cid); if (cmpinfo->num_native_events==0) { test_skip(__FILE__,__LINE__,"No rapl events found",0); } break; } } /* Component not found */ if (cid==numcmp) { test_skip(__FILE__,__LINE__,"No rapl component found\n",0); } /* add PAPI_TOT_CYC and PAPI_TOT_INS */ retval=PAPI_create_eventset(&EventSet); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval); } retval=PAPI_add_event(EventSet,PAPI_TOT_CYC); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } retval=PAPI_add_event(EventSet,PAPI_TOT_INS); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } /* Add some RAPL events */ retval=PAPI_create_eventset(&EventSet2); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_create_eventset",retval); } retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE0"); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } retval=PAPI_add_named_event(EventSet2,"PACKAGE_ENERGY:PACKAGE1"); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_add_event",retval); } PAPI_event=PAPI_TOT_CYC; /* arbitrary */ mythreshold = 2000000; if (!TESTS_QUIET) { printf("Using %x for the overflow event, threshold %d\n", PAPI_event,mythreshold); } /* Start the run calibration run */ retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_start",retval); } do_ints(num_flops,TESTS_QUIET); do_flops( 3000000 ); /* stop the calibration run */ retval = PAPI_stop( EventSet, values0 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_stop",retval); } /* set up overflow handler */ retval = PAPI_overflow( EventSet,PAPI_event,mythreshold, 0, handler ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_overflow",retval); } /* Start overflow run */ retval = PAPI_start( EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_start",retval); } retval = PAPI_start( EventSet2 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_start",retval); } do_ints(num_flops,TESTS_QUIET); do_flops( num_flops ); /* stop overflow run */ retval = PAPI_stop( EventSet, values1 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_stop",retval); } retval = PAPI_stop( EventSet2, values2 ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_stop",retval); } retval = PAPI_overflow( EventSet, PAPI_event, 0, 0, handler ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_overflow",retval); } retval = PAPI_event_code_to_name( PAPI_event, event_name1 ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n", retval); } if (!TESTS_QUIET) { printf("%s: %lld %lld\n",event_name1,values0[0],values1[0]); } retval = PAPI_event_code_to_name( PAPI_TOT_INS, event_name1 ); if (retval != PAPI_OK) { test_fail(__FILE__, __LINE__,"PAPI_event_code_to_name\n",retval); } if (!TESTS_QUIET) { printf("%s: %lld %lld\n",event_name1,values0[1],values1[1]); } retval = PAPI_cleanup_eventset( EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_cleanup_eventset",retval); } retval = PAPI_destroy_eventset( &EventSet ); if ( retval != PAPI_OK ) { test_fail(__FILE__, __LINE__,"PAPI_destroy_eventset",retval); } if (rapl_backward) { test_fail(__FILE__, __LINE__,"RAPL counts went backward!",0); } test_pass( __FILE__, NULL, 0 ); return 0; }