Exemple #1
0
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 );

	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_ECMP )
			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
    test_skip(__FILE__, __LINE__, "Architecture not included in this test file yet.", 0);
#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)
{
   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);
}
int main(int argc, char *argv[]) {
        log_set_max_level(LOG_DEBUG);

        arg_keep = argc > 1;

        test_skip(setup_sequential);
        test_skip(setup_interleaved);

        test_sequence_numbers();

        return 0;
}
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);
}
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 );
}
int main(int argc, char *argv[]) {
    log_set_max_level(LOG_DEBUG);

    /* journal_file_open requires a valid machine id */
    if (access("/etc/machine-id", F_OK) != 0)
        return EXIT_TEST_SKIP;

    arg_keep = argc > 1;

    test_skip(setup_sequential);
    test_skip(setup_interleaved);

    test_sequence_numbers();

    return 0;
}
void decide_which_events(int *events, int *nevents)
{
  int i, j = 0;
  PAPI_event_info_t info;
  int newevents[MAXEVENTS];

  for (i = 0; i < MAXEVENTS; i++) 
    {
      if (PAPI_get_event_info(events[i], &info) == PAPI_OK) 
	{
	  if (info.count && (strcmp(info.derived,"NOT_DERIVED") == 0)) 
	    {
	      printf("Added %s\n", info.symbol);
	      newevents[j++] = events[i];
	    }
	}
    }

  if (j < 2)
    test_skip(__FILE__, __LINE__, "Not enough events to multiplex...", 0);
  *nevents = j;
  memcpy(events,newevents,sizeof(newevents));

  printf("Using %d events\n\n",*nevents);
}
void test_plan_skip_all(const char *reason)
{
    if (test_num < test_cases)
    {
        test_skip(reason, test_cases - test_num, 0);
    }
}
static void
test_io_close(int with_timer, bool from_path)
{
	#define chunks 4
	#define READSIZE (512*1024)
	unsigned int i;
	const char *path = LARGE_FILE;
	int fd = open(path, O_RDONLY);
	if (fd == -1) {
		if (errno == ENOENT) {
			test_skip("Large file not found");
			return;
		}
		test_errno("open", errno, 0);
		test_stop();
	}
#ifdef F_GLOBAL_NOCACHE
	if (fcntl(fd, F_GLOBAL_NOCACHE, 1) == -1) {
		test_errno("fcntl F_GLOBAL_NOCACHE", errno, 0);
		test_stop();
	}
#endif
	struct stat sb;
	if (fstat(fd, &sb)) {
		test_errno("fstat", errno, 0);
		test_stop();
	}
	const size_t size = (size_t)sb.st_size / chunks;
	const int expected_error = with_timer? ECANCELED : 0;
	dispatch_source_t t = NULL;
	dispatch_group_t g = dispatch_group_create();
	dispatch_group_enter(g);
	void (^cleanup_handler)(int error) = ^(int error) {
		test_errno("create error", error, 0);
		dispatch_group_leave(g);
		close(fd);
	};
	dispatch_io_t io;
	if (!from_path) {
		io = dispatch_io_create(DISPATCH_IO_RANDOM, fd,
				dispatch_get_global_queue(0, 0), cleanup_handler);
	} else {
#if DISPATCHTEST_IO_PATH
		io = dispatch_io_create_with_path(DISPATCH_IO_RANDOM, path, O_RDONLY, 0,
				dispatch_get_global_queue(0, 0), cleanup_handler);
#endif
	}
	dispatch_io_set_high_water(io, READSIZE);
	if (with_timer == 1) {
		dispatch_io_set_low_water(io, READSIZE);
		dispatch_io_set_interval(io,  2 * NSEC_PER_SEC,
				DISPATCH_IO_STRICT_INTERVAL);
	} else if (with_timer == 2) {
		t = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,
				dispatch_get_global_queue(0,0));
		dispatch_retain(io);
		dispatch_source_set_event_handler(t, ^{
			dispatch_io_close(io, DISPATCH_IO_STOP);
			dispatch_source_cancel(t);
		});
Exemple #10
0
void
test_skip_file_and_function (void)
{
  test_skip ();
  skip1_test_skip_file_and_function ();
  end_test_skip_file_and_function ();
}
Exemple #11
0
int main(int argc, char **argv)
{
    int rval = 0;
    printf("Testing read functions ... ");
    rval = test_read();
    if (rval != 0) {
        fprintf(stderr, "FAILED!\n");
        return (-1);
    } else {
        printf("passed!\n");
    }

    printf("Testing skip functions ... ");
    rval = test_skip();
    if (rval != 0) {
        fprintf(stderr, "FAILED!\n");
        return (-1);
    } else {
        printf("passed!\n");
    }

    printf("Testing position functions ... ");
    rval = test_position();
    if (rval != 0) {
        fprintf(stderr, "FAILED!\n");
        return (-1);
    } else {
        printf("passed!\n");
    }
 
    return (0);
}
void test_plan_skip_all(const char *reason)
{
    if (test_num > test_cases)
    {
        test_skip(reason, test_cases - test_num, 0);
        exit(test_fails > 255 ? 255 : test_fails);
    }
}
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 );
}
Exemple #14
0
int
main(void)
{
	const char *path = "/usr/share/dict/words";
	struct stat sb;

	dispatch_test_start("Dispatch Source Read");

	int infd = open(path, O_RDONLY);
	if (infd == -1) {
		perror(path);
		exit(EXIT_FAILURE);
	}
	if (fstat(infd, &sb) == -1) {
		perror(path);
		exit(EXIT_FAILURE);
	}
	bytes_total = sb.st_size;

	if (fcntl(infd, F_SETFL, O_NONBLOCK) != 0) {
		perror(path);
		exit(EXIT_FAILURE);
	}

	if (!dispatch_test_check_evfilt_read_for_fd(infd)) {
		test_skip("EVFILT_READ kevent not firing for test file");
		test_fin(NULL);
	}

	dispatch_queue_t main_q = dispatch_get_main_queue();
	test_ptr_notnull("dispatch_get_main_queue", main_q);

	dispatch_source_t reader = dispatch_source_create(DISPATCH_SOURCE_TYPE_READ, infd, 0, main_q);
	test_ptr_notnull("dispatch_source_create", reader);
	assert(reader);

	dispatch_source_set_event_handler(reader, ^{
		size_t estimated = dispatch_source_get_data(reader);
		fprintf(stderr, "bytes available: %zu\n", estimated);
		test_double_less_than_or_equal("estimated", estimated, bytes_total - bytes_read);
		const ssize_t bufsiz = 1024*500; // 500 KB buffer
		static char buffer[1024*500];	// 500 KB buffer
		ssize_t actual = read(infd, buffer, sizeof(buffer));
		bytes_read += actual;
		printf("bytes read: %zd\n", actual);
		if (actual < bufsiz) {
			actual = read(infd, buffer, sizeof(buffer));
			bytes_read += actual;
			// confirm EOF condition
			test_long("EOF", actual, 0);
			dispatch_source_cancel(reader);
		}
	});
int
main(void)
{
	dispatch_test_start("Dispatch VM Pressure test"); // rdar://problem/7000945
	if (!dispatch_test_check_evfilt_vm()) {
		test_skip("EVFILT_VM not supported");
		test_stop();
		return 0;
	}
	initial = time(NULL);
	uint64_t memsize = _dispatch_get_memory_size();
	max_page_count = MIN(memsize, MAXMEM) / ALLOC_SIZE;
	pages = calloc(max_page_count, sizeof(char*));

	vm_queue = dispatch_queue_create("VM Pressure", NULL);
	vm_source = dispatch_source_create(DISPATCH_SOURCE_TYPE_VM, 0,
			DISPATCH_VM_PRESSURE, vm_queue);
	dispatch_source_set_event_handler(vm_source, ^{
		if (!page_count) {
			// Too much memory pressure already to start the test
			test_skip("Memory pressure at start of test");
			cleanup();
		}
		if (__sync_add_and_fetch(&handler_call_count, 1) != NOTIFICATIONS) {
			log_msg("Ignoring vm pressure notification\n");
			interval = 1;
			return;
		}
		test_long("dispatch_source_get_data()",
				dispatch_source_get_data(vm_source), NOTE_VM_PRESSURE);
		int32_t i, pc = page_count + 1;
		for (i = 0; i < pc && pages[i]; ++i) {
				free(pages[i]);
				pages[i] = NULL;
		}
		log_msg("Freed %ldMB\n", pg2mb(i));
	});
int main(int argc, char **argv) {

	int events[1];
	long long counts[1];

	int retval,quiet;

	char test_string[]="Testing PAPI_SYC_INS predefined event...";

	quiet=test_quiet();

	retval = PAPI_library_init(PAPI_VER_CURRENT);
	if (retval != PAPI_VER_CURRENT) {
		if (!quiet) printf("Error! PAPI_library_init %d\n",retval);
		test_fail(test_string);
	}

	retval = PAPI_query_event(PAPI_SYC_INS);
	if (retval != PAPI_OK) {
		if (!quiet) printf("PAPI_SYC_INS not available\n");
		test_skip(test_string);
	}

	events[0]=PAPI_SYC_INS;

	PAPI_start_counters(events,1);

	PAPI_stop_counters(counts,1);

	if (counts[0]<1) {
		if (!quiet) printf("Error! Count too low\n");
		test_fail(test_string);
	}

	PAPI_shutdown();

	test_unimplemented(test_string);

	return 0;
}
Exemple #17
0
int test_harness(int (test_function)(void), char *name)
{
	int rc;

	test_start(name);
	test_set_git_version(GIT_VERSION);

	if (sigaction(SIGALRM, &alarm_action, NULL)) {
		perror("sigaction");
		test_error(name);
		return 1;
	}

	rc = run_test(test_function, name);

	if (rc == MAGIC_SKIP_RETURN_VALUE)
		test_skip(name);
	else
		test_finish(name, rc);

	return rc;
}
Exemple #18
0
int main(void) {
  CRYPTO_library_init();

  if (!test_skip() ||
      !test_get_u() ||
      !test_get_prefixed() ||
      !test_get_prefixed_bad() ||
      !test_get_asn1() ||
      !test_cbb_basic() ||
      !test_cbb_fixed() ||
      !test_cbb_finish_child() ||
      !test_cbb_misuse() ||
      !test_cbb_prefixed() ||
      !test_cbb_asn1() ||
      !test_ber_convert() ||
      !test_asn1_uint64() ||
      !test_get_optional_asn1_bool()) {
    return 1;
  }

  printf("PASS\n");
  return 0;
}
Exemple #19
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;
}
int main (int argc, char **argv)
{
    int retval,cid,numcmp;
    int EventSet = PAPI_NULL;
    long long value;
    int code;
    char event_name[PAPI_MAX_STR_LEN];
    int total_events=0;
    int r;
    const PAPI_component_info_t *cmpinfo = NULL;

    /* Set TESTS_QUIET variable */
    tests_quiet( argc, argv );

    /* PAPI Initialization */
    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT ) {
        test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
    }

    if (!TESTS_QUIET) {
        printf("Trying all net events\n");
    }

    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",-1);
        }

        if (!TESTS_QUIET) {
            printf("Component %d - %d events - %s\n", cid,
                cmpinfo->num_native_events, cmpinfo->name);
        }

        if ( strstr(cmpinfo->name, "infiniband") == NULL) {
            continue;
        }

        code = PAPI_NATIVE_MASK;

        r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );
        while ( r == PAPI_OK ) {

            retval = PAPI_event_code_to_name( code, event_name );
            if ( retval != PAPI_OK ) {
                test_fail( __FILE__, __LINE__, "PAPI_event_code_to_name", retval );
            }

            if (!TESTS_QUIET) {
                printf("%#x %-24s = ", code, event_name);
            }

            EventSet = PAPI_NULL;

            retval = PAPI_create_eventset( &EventSet );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_create_eventset()", retval);
            }

            retval = PAPI_add_event( EventSet, code );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_add_event()", retval);
            }

            retval = PAPI_start( EventSet );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_start()", retval);
            }

            if (strcmp(event_name, "_recv") == 0) {
                /* XXX figure out a general method to  generate some traffic 
                 * for infiniband
                 * the operation should take more than one second in order
                 * to guarantee that the network counters are updated */
                retval = system("ping -c 4 " PINGADDR " > /dev/null");
                if (retval < 0) {
					test_fail(__FILE__, __LINE__, "Unable to start ping", retval);
				}
            }

            retval = PAPI_stop( EventSet, &value );
            if (retval != PAPI_OK) {
                test_fail(__FILE__, __LINE__, "PAPI_stop()", retval);
            }

            if (!TESTS_QUIET) printf("%lld\n", value);

            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);
            }

            total_events++;

            r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
        }

    }

    if (total_events==0) {
        test_skip(__FILE__,__LINE__,"No net events found", 0);
    }

    test_pass( __FILE__, NULL, 0 );

    return 0;
}
Exemple #21
0
int main (int argc, char **argv)
{

    int retval,cid,rapl_cid=-1,numcmp;
    int EventSet = PAPI_NULL;
    long long *values;
    int num_events=0;
    int code;
    char event_names[MAX_RAPL_EVENTS][PAPI_MAX_STR_LEN];
    char units[MAX_RAPL_EVENTS][PAPI_MIN_STR_LEN];
    int r,i;
    const PAPI_component_info_t *cmpinfo = NULL;
    PAPI_event_info_t evinfo;
    long long before_time,after_time;
    double elapsed_time;

        /* Set TESTS_QUIET variable */
     tests_quiet( argc, argv );      

	/* PAPI Initialization */
     retval = PAPI_library_init( PAPI_VER_CURRENT );
     if ( retval != PAPI_VER_CURRENT ) {
	test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
     }

     if (!TESTS_QUIET) {
	printf("Trying all RAPL events\n");
     }

     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,"rapl")) {

	   rapl_cid=cid;

	   if (!TESTS_QUIET) {
	      printf("Found rapl component at cid %d\n",rapl_cid);
	   }

           if (cmpinfo->disabled) {
	      if (!TESTS_QUIET) {
		 printf("RAPL component disabled: %s\n",
                        cmpinfo->disabled_reason);
	      } 
              test_skip(__FILE__,__LINE__,"RAPL component disabled",0);
           }
	   break;
	}
     }

     /* Component not found */
     if (cid==numcmp) {
       test_skip(__FILE__,__LINE__,"No rapl component found\n",0);
     }

     /* Create EventSet */
     retval = PAPI_create_eventset( &EventSet );
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, 
                              "PAPI_create_eventset()",retval);
     }

     /* Add all events */

     code = PAPI_NATIVE_MASK;

     r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, rapl_cid );

     while ( r == PAPI_OK ) {

        retval = PAPI_event_code_to_name( code, event_names[num_events] );
	if ( retval != PAPI_OK ) {
	   printf("Error translating %#x\n",code);
	   test_fail( __FILE__, __LINE__, 
                            "PAPI_event_code_to_name", retval );
	}

	retval = PAPI_get_event_info(code,&evinfo);
	if (retval != PAPI_OK) {
	  test_fail( __FILE__, __LINE__,
             "Error getting event info\n",retval);
	}
	
	strncpy(units[num_events],evinfo.units,PAPI_MIN_STR_LEN);

        retval = PAPI_add_event( EventSet, code );
        if (retval != PAPI_OK) {
	  break; /* We've hit an event limit */
	}
	num_events++;
  	      
        r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, rapl_cid );
     }

     values=calloc(num_events,sizeof(long long));
     if (values==NULL) {
	test_fail(__FILE__, __LINE__, 
                              "No memory",retval);
     }

     if (!TESTS_QUIET) {
	printf("\nStarting measurements...\n\n");
     }

     /* Start Counting */
     before_time=PAPI_get_real_nsec();
     retval = PAPI_start( EventSet);
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
     }

     /* Run test */
     run_test(TESTS_QUIET);

     /* Stop Counting */
     after_time=PAPI_get_real_nsec();
     retval = PAPI_stop( EventSet, values);
     if (retval != PAPI_OK) {
	test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
     }

     elapsed_time=((double)(after_time-before_time))/1.0e9;

     if (!TESTS_QUIET) {
        printf("\nStopping measurements, took %.3fs, gathering results...\n\n",
	       elapsed_time);

	printf("Energy measurements:\n");

	for(i=0;i<num_events;i++) {
	   if (strstr(units[i],"nJ")) {

	      printf("%s\t%.6fJ\t(Average Power %.1fW)\n",
		    event_names[i],
		    (double)values[i]/1.0e9,
		    ((double)values[i]/1.0e9)/elapsed_time);
	   }
	}

	printf("\n");
	printf("Fixed values:\n");

	for(i=0;i<num_events;i++) {
	   if (!strstr(units[i],"nJ")) {

	     union {
	       long long ll;
	       double fp;
	     } result;

	     result.ll=values[i];

	      printf("%s\t%0.3f%s\n",
		    event_names[i],
		    result.fp,
		    units[i]);
	   }
	}

     }

     /* Done, clean up */
     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);
     }
        
     test_pass( __FILE__, NULL, 0 );
		
     return 0;
}
int main(int argc, char **argv) {

  int events[MAX_TEST_EVENTS];
  int fd[MAX_TEST_EVENTS];
  int count=MAX_TEST_EVENTS;

  int i,j,n;
  int ret1,ret2,ret3;

  struct perf_event_attr pe;

  int quiet,nmi_enabled;
  char test_string[]="Testing if we can determine maximum events despite NMI watchdog...";

  quiet=test_quiet();

  if (!quiet) {
    printf("If the NMI watchdog is enabled it will steal a performance\n");
    printf("   counter.  There is a bug that if you try to use the\n");
    printf("   maximum number of counters anyway, sys_perf_open()\n");
    printf("   will succede but will fail when you try to read()\n");
    printf("   the values.\n\n");
  }

  nmi_enabled=detect_nmi_watchdog();
  if (!nmi_enabled) {
    if (!quiet) {
       printf("No NMI watchdog detected, so skipping test.\n\n");
    }
    test_skip(test_string);
  }

  if (copy_events(events)) {
     test_unimplemented(test_string);
  }

  for(i=1;i<count;i++) {

    if (!quiet) printf("Trying %d events:\n",i);

     memset(&pe,0,sizeof(struct perf_event_attr));

     pe.type=PERF_TYPE_RAW;
     pe.size=sizeof(struct perf_event_attr);
     pe.read_format=PERF_FORMAT_GROUP|PERF_FORMAT_ID;

     fd[0]=-1;

     for(j=0;j<i;j++) {
        pe.config=events[j];

        if (j==0) {
           pe.disabled=1;
           pe.pinned=1;
	}
        else {
           pe.disabled=0;
           pe.pinned=0;
	}

        fd[j]=perf_event_open(&pe,0,-1,fd[0],0);
        if (fd[j]<0) {
	 
	   if (!quiet) printf("Finished after event %d\n\n",j);
	   test_pass(test_string);
	   exit(1);
	}
     }

     /* start */
     ret1=ioctl(fd[0], PERF_EVENT_IOC_ENABLE,0);

     /* stop */
     ret2=ioctl(fd[0], PERF_EVENT_IOC_DISABLE,0);


     #define BUFFER_SIZE 256
     long long buffer[BUFFER_SIZE];
     
     ret3=read(fd[0],buffer,BUFFER_SIZE*sizeof(long long));
   
     if (ret3<=0) {
        if (!quiet) {
           printf("Unexpected read result %d %s\n",ret3,strerror(errno));
	}
	test_fail(test_string);
     }

     if (buffer[0]!=j){
       if (!quiet) printf("Error!  buffer count is %lld not %d!\n",
			  buffer[0],j);
       test_fail(test_string);
     }
   
     if (ret1<0) {
       if (!quiet) printf("Error starting!\n");
       test_fail(test_string);
     }
   
     if (ret2<0) {
       if (!quiet) printf("Error stopping!\n");
       test_fail(test_string);
     }
  
     if (!quiet) {
        for(n=0;n<buffer[0];n++) {
           printf("\t%x %lld\n",events[n],buffer[1+(n*2)]);
	}
     }

     for(n=0;n<j;n++) {
        close(fd[n]);
     }
  }

   test_pass(test_string);

   return 0;
}
void *
thd_start(void *arg)
{
	int err;
	size_t sz;
	bool e0, e1;

	sz = sizeof(bool);
	if ((err = mallctl("thread.tcache.enabled", &e0, &sz, NULL, 0))) {
		if (err == ENOENT) {
			assert_false(config_tcache,
			    "ENOENT should only be returned if tcache is "
			    "disabled");
		}
		goto label_ENOENT;
	}

	if (e0) {
		e1 = false;
		assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz),
		    0, "Unexpected mallctl() error");
		assert_true(e0, "tcache should be enabled");
	}

	e1 = true;
	assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
	    "Unexpected mallctl() error");
	assert_false(e0, "tcache should be disabled");

	e1 = true;
	assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
	    "Unexpected mallctl() error");
	assert_true(e0, "tcache should be enabled");

	e1 = false;
	assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
	    "Unexpected mallctl() error");
	assert_true(e0, "tcache should be enabled");

	e1 = false;
	assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
	    "Unexpected mallctl() error");
	assert_false(e0, "tcache should be disabled");

	free(malloc(1));
	e1 = true;
	assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
	    "Unexpected mallctl() error");
	assert_false(e0, "tcache should be disabled");

	free(malloc(1));
	e1 = true;
	assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
	    "Unexpected mallctl() error");
	assert_true(e0, "tcache should be enabled");

	free(malloc(1));
	e1 = false;
	assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
	    "Unexpected mallctl() error");
	assert_true(e0, "tcache should be enabled");

	free(malloc(1));
	e1 = false;
	assert_d_eq(mallctl("thread.tcache.enabled", &e0, &sz, &e1, sz), 0,
	    "Unexpected mallctl() error");
	assert_false(e0, "tcache should be disabled");

	free(malloc(1));
	return (NULL);
label_ENOENT:
	test_skip("\"thread.tcache.enabled\" mallctl not available");
	return (NULL);
}
Exemple #24
0
int
main( int argc, char *argv[] )
{
	extern void dummy( void * );

	float aa, *a, *b, *c, *x, *y;
	double aad, *ad, *bd, *cd, *xd, *yd;
	int i, j, n;
	int inner = 0;
	int vector = 0;
	int matrix = 0;
	int double_precision = 0;
	int retval = PAPI_OK;
	char papi_event_str[PAPI_MIN_STR_LEN] = "PAPI_FP_OPS";
	int papi_event;
	int EventSet = PAPI_NULL;

/* Parse the input arguments */
	for ( i = 0; i < argc; i++ ) {
		if ( strstr( argv[i], "-i" ) )
			inner = 1;
		else if ( strstr( argv[i], "-v" ) )
			vector = 1;
		else if ( strstr( argv[i], "-m" ) )
			matrix = 1;
		else if ( strstr( argv[i], "-e" ) ) {
			if ( ( argv[i + 1] == NULL ) || ( strlen( argv[i + 1] ) == 0 ) ) {
				print_help( argv );
				exit( 1 );
			}
			strncpy( papi_event_str, argv[i + 1], sizeof ( papi_event_str ) );
			i++;
		} else if ( strstr( argv[i], "-d" ) )
			double_precision = 1;
		else if ( strstr( argv[i], "-h" ) ) {
			print_help( argv );
			exit( 1 );
		}
	}

	/* if no options specified, set all tests to TRUE */
	if ( inner + vector + matrix == 0 )
		inner = vector = matrix = 1;


	tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */

	if ( !TESTS_QUIET )
		printf( "Initializing..." );

	/* Initialize PAPI */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT )
		test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );

	/* Translate name */
	retval = PAPI_event_name_to_code( papi_event_str, &papi_event );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );

	if ( PAPI_query_event( papi_event ) != PAPI_OK )
		test_skip( __FILE__, __LINE__, "PAPI_query_event", PAPI_ENOEVNT );

	if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );

	if ( ( retval = PAPI_add_event( EventSet, papi_event ) ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );

	printf( "\n" );

	retval = PAPI_OK;

	/* Inner Product test */
	if ( inner ) {
		/* Allocate the linear arrays */
	   if (double_precision) {
	        xd = malloc( INDEX5 * sizeof(double) );
	        yd = malloc( INDEX5 * sizeof(double) );
		if ( !( xd && yd ) )
			retval = PAPI_ENOMEM;
	   }
	   else {
	        x = malloc( INDEX5 * sizeof(float) );
		y = malloc( INDEX5 * sizeof(float) );
		if ( !( x && y ) )
			retval = PAPI_ENOMEM;
	   }

		if ( retval == PAPI_OK ) {
			headerlines( "Inner Product Test", TESTS_QUIET );

			/* step through the different array sizes */
			for ( n = 0; n < INDEX5; n++ ) {
				if ( n < INDEX1 || ( ( n + 1 ) % 50 ) == 0 ) {

					/* Initialize the needed arrays at this size */
					if ( double_precision ) {
						for ( i = 0; i <= n; i++ ) {
							xd[i] = ( double ) rand(  ) * ( double ) 1.1;
							yd[i] = ( double ) rand(  ) * ( double ) 1.1;
						}
					} else {
						for ( i = 0; i <= n; i++ ) {
							x[i] = ( float ) rand(  ) * ( float ) 1.1;
							y[i] = ( float ) rand(  ) * ( float ) 1.1;
						}
					}

					/* reset PAPI flops count */
					reset_flops( "Inner Product Test", EventSet );

					/* do the multiplication */
					if ( double_precision ) {
						aad = inner_double( n, xd, yd );
						dummy( ( void * ) &aad );
					} else {
						aa = inner_single( n, x, y );
						dummy( ( void * ) &aa );
					}
					resultline( n, 1, EventSet );
				}
			}
		}
		if (double_precision) {
			free( xd );
			free( yd );
		} else {
			free( x );
			free( y );
		}
	}

	/* Matrix Vector test */
	if ( vector && retval != PAPI_ENOMEM ) {
		/* Allocate the needed arrays */
	  if (double_precision) {
	        ad = malloc( INDEX5 * INDEX5 * sizeof(double) );
	        xd = malloc( INDEX5 * sizeof(double) );
	        yd = malloc( INDEX5 * sizeof(double) );
		if ( !( ad && xd && yd ) )
			retval = PAPI_ENOMEM;
	  } else {
	        a = malloc( INDEX5 * INDEX5 * sizeof(float) );
	        x = malloc( INDEX5 * sizeof(float) );
	        y = malloc( INDEX5 * sizeof(float) );
		if ( !( a && x && y ) )
			retval = PAPI_ENOMEM;
	  }

		if ( retval == PAPI_OK ) {
			headerlines( "Matrix Vector Test", TESTS_QUIET );

			/* step through the different array sizes */
			for ( n = 0; n < INDEX5; n++ ) {
				if ( n < INDEX1 || ( ( n + 1 ) % 50 ) == 0 ) {

					/* Initialize the needed arrays at this size */
					if ( double_precision ) {
						for ( i = 0; i <= n; i++ ) {
							yd[i] = 0.0;
							xd[i] = ( double ) rand(  ) * ( double ) 1.1;
							for ( j = 0; j <= n; j++ )
								ad[i * n + j] =
									( double ) rand(  ) * ( double ) 1.1;
						}
					} else {
						for ( i = 0; i <= n; i++ ) {
							y[i] = 0.0;
							x[i] = ( float ) rand(  ) * ( float ) 1.1;
							for ( j = 0; j <= n; j++ )
								a[i * n + j] =
									( float ) rand(  ) * ( float ) 1.1;
						}
					}

					/* reset PAPI flops count */
					reset_flops( "Matrix Vector Test", EventSet );

					/* compute the resultant vector */
					if ( double_precision ) {
						vector_double( n, ad, xd, yd );
						dummy( ( void * ) yd );
					} else {
						vector_single( n, a, x, y );
						dummy( ( void * ) y );
					}
					resultline( n, 2, EventSet );
				}
			}
		}
		if (double_precision) {
			free( ad );
			free( xd );
			free( yd );
		} else {
			free( a );
			free( x );
			free( y );
		}
	}

	/* Matrix Multiply test */
	if ( matrix && retval != PAPI_ENOMEM ) {
		/* Allocate the needed arrays */
	  if (double_precision) {
	        ad = malloc( INDEX5 * INDEX5 * sizeof(double) );
	        bd = malloc( INDEX5 * INDEX5 * sizeof(double) );
	        cd = malloc( INDEX5 * INDEX5 * sizeof(double) );
		if ( !( ad && bd && cd ) )
			retval = PAPI_ENOMEM;
	  } else {
	        a = malloc( INDEX5 * INDEX5 * sizeof(float) );
	        b = malloc( INDEX5 * INDEX5 * sizeof(float) );
	        c = malloc( INDEX5 * INDEX5 * sizeof(float) );
		if ( !( a && b && c ) )
			retval = PAPI_ENOMEM;
	  }


		if ( retval == PAPI_OK ) {
			headerlines( "Matrix Multiply Test", TESTS_QUIET );

			/* step through the different array sizes */
			for ( n = 0; n < INDEX5; n++ ) {
				if ( n < INDEX1 || ( ( n + 1 ) % 50 ) == 0 ) {

					/* Initialize the needed arrays at this size */
					if ( double_precision ) {
						for ( i = 0; i <= n * n + n; i++ ) {
							cd[i] = 0.0;
							ad[i] = ( double ) rand(  ) * ( double ) 1.1;
							bd[i] = ( double ) rand(  ) * ( double ) 1.1;
						}
					} else {
						for ( i = 0; i <= n * n + n; i++ ) {
							c[i] = 0.0;
							a[i] = ( float ) rand(  ) * ( float ) 1.1;
							b[i] = ( float ) rand(  ) * ( float ) 1.1;
						}
					}

					/* reset PAPI flops count */
					reset_flops( "Matrix Multiply Test", EventSet );

					/* compute the resultant matrix */
					if ( double_precision ) {
						matrix_double( n, cd, ad, bd );
						dummy( ( void * ) c );
					} else {
						matrix_single( n, c, a, b );
						dummy( ( void * ) c );
					}
					resultline( n, 3, EventSet );
				}
			}
		}
		if (double_precision) {
			free( ad );
			free( bd );
			free( cd );
		} else {
			free( a );
			free( b );
			free( c );
		}
	}

	/* exit with status code */
	if ( retval == PAPI_ENOMEM )
		test_fail( __FILE__, __LINE__, "malloc", retval );
	else
		test_pass( __FILE__, NULL, 0 );
	exit( 1 );
}
int
main( int argc, char **argv )
{
	pthread_t id[NUM_THREADS];
	int flops[NUM_THREADS];
	int i, rc, retval;
	pthread_attr_t attr;
	long long elapsed_us, elapsed_cyc;
	const PAPI_exe_info_t *prginfo = NULL;

	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_thread_init( ( unsigned
							   long ( * )( void ) ) ( pthread_self ) ) ) !=
		 PAPI_OK ) {
		if ( retval == PAPI_ECMP )
			test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
		else
			test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
	}
	if ( ( prginfo = PAPI_get_executable_info(  ) ) == NULL ) {
		retval = 1;
		test_fail( __FILE__, __LINE__, "PAPI_get_executable_info", retval );
	}
	my_start = prginfo->address_info.text_start;
	my_end = prginfo->address_info.text_end;
	length = ( unsigned int ) ( my_end - my_start );

	elapsed_us = PAPI_get_real_usec(  );

	elapsed_cyc = PAPI_get_real_cyc(  );

	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++ ) {
		flops[i] = FLOPS * ( i + 1 );
		rc = pthread_create( &id[i], &attr, Thread, ( void * ) &flops[i] );
		if ( rc )
			return ( FAILURE );
	}
	for ( i = 0; i < NUM_THREADS; i++ )
		pthread_join( id[i], NULL );

	pthread_attr_destroy( &attr );

	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 );
	pthread_exit( NULL );
	exit( 1 );
}
Exemple #26
0
int main (int argc, char **argv)
{

        int retval,cid,numcmp;
	int EventSet = PAPI_NULL;
	long long values[NUM_EVENTS];
	int code;
	char event_name[PAPI_MAX_STR_LEN];
	int total_events=0;
	int r;
	const PAPI_component_info_t *cmpinfo = NULL;

        /* Set TESTS_QUIET variable */
        tests_quiet( argc, argv );      

	/* PAPI Initialization */
	retval = PAPI_library_init( PAPI_VER_CURRENT );
	if ( retval != PAPI_VER_CURRENT ) {
	   test_fail(__FILE__, __LINE__,"PAPI_library_init failed\n",retval);
	}

        numcmp = PAPI_num_components();

	for(cid=0; cid<numcmp; cid++) {

	   if (!TESTS_QUIET) {
	      if ( (cmpinfo = PAPI_get_component_info(cid)) == NULL) {
	         test_fail(__FILE__, __LINE__,"PAPI_get_component_info failed\n", 0);
	      }
	      printf("\tComponent %d - %s\n", cid, cmpinfo->name);
	   }

	   code = PAPI_NATIVE_MASK;

           r = PAPI_enum_cmp_event( &code, PAPI_ENUM_FIRST, cid );

	   while ( r == PAPI_OK ) {
	      retval = PAPI_event_code_to_name( code, event_name );
	      if ( retval != PAPI_OK ) {
		 printf("Error translating %x\n",code);
	         test_fail( __FILE__, __LINE__, 
                            "PAPI_event_code_to_name", retval );
	      }

	      if (!strncmp(event_name,"micpower",8)) {
	         if (!TESTS_QUIET) printf("0x%x %s ",code,event_name);
	     
	         EventSet = PAPI_NULL;

	         retval = PAPI_create_eventset( &EventSet );
	         if (retval != PAPI_OK) {
	            test_fail(__FILE__, __LINE__, 
                              "PAPI_create_eventset()",retval);
		 }

	         retval = PAPI_add_event( EventSet, code );
	         if (retval != PAPI_OK) {
	            test_fail(__FILE__, __LINE__, 
                                 "PAPI_add_event()",retval);
		 }

	         retval = PAPI_start( EventSet);
	         if (retval != PAPI_OK) {
	            test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
		 }

	         retval = PAPI_stop( EventSet, values);
	         if (retval != PAPI_OK) {
	            test_fail(__FILE__, __LINE__, "PAPI_start()",retval);
		 }

	         if (!TESTS_QUIET) printf(" value: %lld\n",values[0]);

	         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);
		 }

	         total_events++;
	      }
	      r = PAPI_enum_cmp_event( &code, PAPI_ENUM_EVENTS, cid );
	   }
        }

	if (total_events==0) {

	   test_skip(__FILE__,__LINE__,"No coretemp events found",0);
	}

	test_pass( __FILE__, NULL, 0 );
		
	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;
}
Exemple #28
0
int
main( int argc, char **argv )
{
    int status, retval, num_tests = 1, tmp;
    int EventSet1 = PAPI_NULL;
    long long **values;
    long long elapsed_us, elapsed_cyc, elapsed_virt_us, elapsed_virt_cyc;
    char event_name[PAPI_MAX_STR_LEN];;
    const PAPI_hw_info_t *hw_info;
    const PAPI_component_info_t *cmpinfo;
    pid_t pid;

    /* Fork before doing anything with the PMU */

    setbuf(stdout,NULL);
    pid = fork(  );
    if ( pid < 0 )
        test_fail( __FILE__, __LINE__, "fork()", PAPI_ESYS );
    if ( pid == 0 )
        exit( wait_for_attach_and_loop(  ) );

    tests_quiet( argc, argv );	/* Set TESTS_QUIET variable */


    /* Master only process below here */

    retval = PAPI_library_init( PAPI_VER_CURRENT );
    if ( retval != PAPI_VER_CURRENT )
        test_fail_exit( __FILE__, __LINE__, "PAPI_library_init", retval );

    if ( ( cmpinfo = PAPI_get_component_info( 0 ) ) == NULL )
        test_fail_exit( __FILE__, __LINE__, "PAPI_get_component_info", 0 );

    if ( cmpinfo->attach == 0 )
        test_skip( __FILE__, __LINE__, "Platform does not support attaching",
                   0 );

    hw_info = PAPI_get_hardware_info(  );
    if ( hw_info == NULL )
        test_fail_exit( __FILE__, __LINE__, "PAPI_get_hardware_info", 0 );

    /* add PAPI_TOT_CYC and one of the events in PAPI_FP_INS, PAPI_FP_OPS or
       PAPI_TOT_INS, depending on the availability of the event on the
       platform */
    retval = PAPI_create_eventset(&EventSet1);
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval );

    /* Force addition of component */

    retval = PAPI_assign_eventset_component( EventSet1, 0 );
    if ( retval != PAPI_OK )
        test_fail( __FILE__, __LINE__, "PAPI_assign_eventset_component",
                   retval );

    /* The following call causes this test to fail for perf_events */

    retval = PAPI_attach( EventSet1, ( unsigned long ) pid );
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_attach", retval );

    sprintf(event_name,"PAPI_TOT_CYC");

    retval = PAPI_add_event(EventSet1, PAPI_TOT_CYC);
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
    retval = PAPI_add_event(EventSet1, PAPI_FP_INS);
    if ( retval == PAPI_ENOEVNT ) {
        test_warn( __FILE__, __LINE__, "PAPI_FP_INS", retval);
    } else if ( retval != PAPI_OK ) {
        test_fail_exit( __FILE__, __LINE__, "PAPI_add_event", retval );
    }

    values = allocate_test_space( 1, 2);

    elapsed_us = PAPI_get_real_usec(  );

    elapsed_cyc = PAPI_get_real_cyc(  );

    elapsed_virt_us = PAPI_get_virt_usec(  );

    elapsed_virt_cyc = PAPI_get_virt_cyc(  );

    printf("must_ptrace is %d\n",cmpinfo->attach_must_ptrace);
    pid_t  child = wait( &status );
    printf( "Debugger exited wait() with %d\n",child );
    if (WIFSTOPPED( status ))
    {
        printf( "Child has stopped due to signal %d (%s)\n",
                WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
    }
    if (WIFSIGNALED( status ))
    {
        printf( "Child %ld received signal %d (%s)\n",
                (long)child,
                WTERMSIG(status) , strsignal(WTERMSIG( status )) );
    }
    printf("After %d\n",retval);

    retval = PAPI_start( EventSet1 );
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_start", retval );

    printf("Continuing\n");
    if ( ptrace( PTRACE_CONT, pid, NULL, NULL ) == -1 ) {
        perror( "ptrace(PTRACE_CONT)" );
        return 1;
    }


    do {
        child = wait( &status );
        printf( "Debugger exited wait() with %d\n", child);
        if (WIFSTOPPED( status ))
        {
            printf( "Child has stopped due to signal %d (%s)\n",
                    WSTOPSIG( status ), strsignal(WSTOPSIG( status )) );
        }
        if (WIFSIGNALED( status ))
        {
            printf( "Child %ld received signal %d (%s)\n",
                    (long)child,
                    WTERMSIG(status) , strsignal(WTERMSIG( status )) );
        }
    } while (!WIFEXITED( status ));

    printf("Child exited with value %d\n",WEXITSTATUS(status));
    if (WEXITSTATUS(status) != 0)
        test_fail_exit( __FILE__, __LINE__, "Exit status of child to attach to", PAPI_EMISC);

    retval = PAPI_stop( EventSet1, values[0] );
    if ( retval != PAPI_OK )
        test_fail_exit( __FILE__, __LINE__, "PAPI_stop", retval );

    elapsed_virt_us = PAPI_get_virt_usec(  ) - elapsed_virt_us;

    elapsed_virt_cyc = PAPI_get_virt_cyc(  ) - elapsed_virt_cyc;

    elapsed_us = PAPI_get_real_usec(  ) - elapsed_us;

    elapsed_cyc = PAPI_get_real_cyc(  ) - elapsed_cyc;

    retval = PAPI_cleanup_eventset(EventSet1);
    if (retval != PAPI_OK)
        test_fail_exit( __FILE__, __LINE__, "PAPI_cleanup_eventset", retval );

    retval = PAPI_destroy_eventset(&EventSet1);
    if (retval != PAPI_OK)
        test_fail_exit( __FILE__, __LINE__, "PAPI_destroy_eventset", retval );

    printf( "Test case: 3rd party attach start, stop.\n" );
    printf( "-----------------------------------------------\n" );
    tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
    printf( "Default domain is: %d (%s)\n", tmp, stringify_all_domains( tmp ) );
    tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
    printf( "Default granularity is: %d (%s)\n", tmp,
            stringify_granularity( tmp ) );
    printf( "Using %d iterations of c += a*b\n", NUM_FLOPS );
    printf
    ( "-------------------------------------------------------------------------\n" );

    printf( "Test type    : \t           1\n" );

    printf( TAB1, "PAPI_TOT_CYC : \t", ( values[0] )[0] );
    printf( TAB1, "PAPI_FP_INS  : \t", ( values[0] )[1] );
    printf( TAB1, "Real usec    : \t", elapsed_us );
    printf( TAB1, "Real cycles  : \t", elapsed_cyc );
    printf( TAB1, "Virt usec    : \t", elapsed_virt_us );
    printf( TAB1, "Virt cycles  : \t", elapsed_virt_cyc );

    printf
    ( "-------------------------------------------------------------------------\n" );

    printf( "Verification: none\n" );

    test_pass( __FILE__, values, num_tests );
    exit( 1 );
}
Exemple #29
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 );
}
Exemple #30
0
int
main( int argc, char **argv )
{
	pthread_t e_th, f_th, g_th, h_th;
	int flops1, flops2, flops3, flops4, flops5;
	int retval, rc;
	pthread_attr_t attr;

	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 );

	retval =
		PAPI_thread_init( ( unsigned long ( * )( void ) ) ( pthread_self ) );
	if ( retval != PAPI_OK ) {
		if ( retval == PAPI_ECMP )
			test_skip( __FILE__, __LINE__, "PAPI_thread_init", retval );
		else
			test_fail( __FILE__, __LINE__, "PAPI_thread_init", retval );
	}

	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

	flops1 = 1000000;
	rc = pthread_create( &e_th, &attr, Thread, ( void * ) &flops1 );
	if ( rc ) {
		retval = PAPI_ESYS;
		test_fail( __FILE__, __LINE__, "pthread_create", retval );
	}
	flops2 = 2000000;
	rc = pthread_create( &f_th, &attr, Thread, ( void * ) &flops2 );
	if ( rc ) {
		retval = PAPI_ESYS;
		test_fail( __FILE__, __LINE__, "pthread_create", retval );
	}

	flops3 = 4000000;
	rc = pthread_create( &g_th, &attr, Thread, ( void * ) &flops3 );
	if ( rc ) {
		retval = PAPI_ESYS;
		test_fail( __FILE__, __LINE__, "pthread_create", retval );
	}

	flops4 = 8000000;
	rc = pthread_create( &h_th, &attr, Thread, ( void * ) &flops4 );
	if ( rc ) {
		retval = PAPI_ESYS;
		test_fail( __FILE__, __LINE__, "pthread_create", retval );
	}

	pthread_attr_destroy( &attr );
	flops5 = 500000;
	Thread( &flops5 );
	pthread_join( h_th, NULL );
	pthread_join( g_th, NULL );
	pthread_join( f_th, NULL );
	pthread_join( e_th, NULL );

	test_pass( __FILE__, NULL, 0 );
	pthread_exit( NULL );
	exit( 1 );
}