PAPI  5.0.1.0
derived.c
Go to the documentation of this file.
00001 /* This file performs the following test: start, stop with a derived event */
00002 
00003 #include "papi_test.h"
00004 
00005 #define OLD_TEST_DRIVER
00006 
00007 #ifdef OLD_TEST_DRIVER
00008 #define CPP_TEST_FAIL(string, retval) test_fail(__FILE__, __LINE__, string, retval);
00009 #define CPP_TEST_PASS() { test_pass(__FILE__, NULL, 0); exit(0); }
00010 #define CPP_TEST_SKIP() { test_skip(__FILE__,__LINE__,NULL,0); exit(0); }
00011 #else
00012 #define CPP_TEST_FAIL(function, retval) { fprintf(stderr,"%s:%d:%s:%d:%s:%s\n",__FILE__,__LINE__,function,retval,PAPI_strerror(retval),"$Id$\n"); test_fail(__FILE__, __LINE__, function, retval); }
00013 #define CPP_TEST_PASS() { fprintf(stderr,"$Id$\n%s:\tPASSED\n",__FILE__); exit(0); }
00014 #define CPP_TEST_SKIP() { fprintf(stderr,"$Id$\n%s:\tSKIPPED\n",__FILE__); exit(0); }
00015 #endif
00016 
00017 #define EVENTSLEN 2
00018 
00019 #define QUIETPRINTF if (!TESTS_QUIET) printf
00020 unsigned int PAPI_events[EVENTSLEN] = { 0, 0 };
00021 static const int PAPI_events_len = 1;
00022 extern int TESTS_QUIET;
00023 
00024 int
00025 main( int argc, char **argv )
00026 {
00027     int retval, tmp;
00028     int EventSet = PAPI_NULL;
00029     int i;
00030     PAPI_event_info_t info;
00031     long long values;
00032     char event_name[PAPI_MAX_STR_LEN], add_event_str[PAPI_MAX_STR_LEN];
00033 
00034 /*#if !defined(i386) || !defined(linux)
00035    CPP_TEST_SKIP();
00036 #endif
00037 */
00038     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00039 
00040     retval = PAPI_library_init( PAPI_VER_CURRENT );
00041     if ( retval != PAPI_VER_CURRENT )
00042         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00043 
00044     QUIETPRINTF( "Test case %s: start, stop with a derived counter.\n",
00045                  __FILE__ );
00046     QUIETPRINTF( "------------------------------------------------\n" );
00047     tmp = PAPI_get_opt( PAPI_DEFDOM, NULL );
00048     QUIETPRINTF( "Default domain is: %d (%s)\n", tmp,
00049                  stringify_all_domains( tmp ) );
00050     tmp = PAPI_get_opt( PAPI_DEFGRN, NULL );
00051     QUIETPRINTF( "Default granularity is: %d (%s)\n\n", tmp,
00052                  stringify_granularity( tmp ) );
00053 
00054     i = PAPI_PRESET_MASK;
00055     do {
00056         if ( PAPI_get_event_info( i, &info ) == PAPI_OK ) {
00057             if ( info.count > 1 ) {
00058                 PAPI_events[0] = ( unsigned int ) info.event_code;
00059                 break;
00060             }
00061         }
00062     } while ( PAPI_enum_event( &i, 0 ) == PAPI_OK );
00063 
00064     if ( PAPI_events[0] == 0 )
00065         CPP_TEST_SKIP(  );
00066 
00067     retval = PAPI_create_eventset( &EventSet );
00068     if ( retval != PAPI_OK )
00069         CPP_TEST_FAIL( "PAPI_create_eventset", retval );
00070 
00071     for ( i = 0; i < PAPI_events_len; i++ ) {
00072         PAPI_event_code_to_name( ( int ) PAPI_events[i], event_name );
00073         if ( !TESTS_QUIET )
00074             QUIETPRINTF( "Adding %s\n", event_name );
00075         retval = PAPI_add_event( EventSet, ( int ) PAPI_events[i] );
00076         if ( retval != PAPI_OK )
00077             CPP_TEST_FAIL( "PAPI_add_event", retval );
00078     }
00079 
00080     retval = PAPI_start( EventSet );
00081     if ( retval != PAPI_OK )
00082         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00083 
00084     QUIETPRINTF( "Running do_stuff().\n" );
00085 
00086     do_stuff(  );
00087 
00088     retval = PAPI_stop( EventSet, &values );
00089     if ( retval != PAPI_OK )
00090         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00091 
00092     sprintf( add_event_str, "%-12s : \t", event_name );
00093     QUIETPRINTF( TAB1, add_event_str, values );
00094     QUIETPRINTF( "------------------------------------------------\n" );
00095 
00096     retval = PAPI_cleanup_eventset( EventSet ); /* JT */
00097     if ( retval != PAPI_OK )
00098         CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );
00099 
00100     retval = PAPI_destroy_eventset( &EventSet );
00101     if ( retval != PAPI_OK )
00102         CPP_TEST_FAIL( "PAPI_cleanup_eventset", retval );
00103 
00104 #ifndef OLD_TEST_DRIVER
00105     PAPI_shutdown(  );
00106 #endif
00107 
00108     QUIETPRINTF( "Verification: Does it produce a non-zero value?\n" );
00109 
00110     if ( values != 0 ) {
00111         QUIETPRINTF( "Yes: " );
00112         QUIETPRINTF( LLDFMT, values );
00113         QUIETPRINTF( "\n" );
00114     }
00115 
00116     CPP_TEST_PASS(  );
00117 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines