PAPI  5.0.1.0
case1.c
Go to the documentation of this file.
00001 /* From Dave McNamara at PSRV. Thanks! */
00002 
00003 /* If you try to add an event that doesn't exist, you get the correct error
00004 message, yet you get subsequent Seg. Faults when you try to do PAPI_start and
00005 PAPI_stop. I would expect some bizarre behavior if I had no events added to the
00006 event set and then tried to PAPI_start but if I had successfully added one
00007 event, then the 2nd one get an error when I tried to add it, is it possible for
00008 PAPI_start to work but just count the first event?
00009 */
00010 
00011 #include "papi_test.h"
00012 
00013 extern int TESTS_QUIET;                /* Declared in test_utils.c */
00014 
00015 int
00016 main( int argc, char **argv )
00017 {
00018   double c, a = 0.999, b = 1.001;
00019     int n = 1000;
00020     int EventSet = PAPI_NULL;
00021     int retval;
00022     int i, j = 0;
00023     long long g1[2];
00024 
00025     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00026 
00027     if ( ( retval =
00028            PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
00029         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00030 
00031 
00032     if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
00033         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00034 
00035     if ( PAPI_query_event( PAPI_L2_TCM ) == PAPI_OK )
00036         j++;
00037 
00038     if ( j == 1 &&
00039          ( retval = PAPI_add_event( EventSet, PAPI_L2_TCM ) ) != PAPI_OK ) {
00040         if ( retval != PAPI_ECNFLCT )
00041             test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00042         j--;                 /* The event was not added */
00043     }
00044 
00045     i = j;
00046     if ( PAPI_query_event( PAPI_L2_DCM ) == PAPI_OK )
00047         j++;
00048 
00049     if ( j == ( i + 1 ) &&
00050          ( retval = PAPI_add_event( EventSet, PAPI_L2_DCM ) ) != PAPI_OK ) {
00051         if ( retval != PAPI_ECNFLCT )
00052             test_fail( __FILE__, __LINE__, "PAPI_add_event", retval );
00053         j--;                 /* The event was not added */
00054     }
00055 
00056     if ( j ) {
00057         if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
00058             test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00059         for ( i = 0; i < n; i++ ) {
00060             c = a * b;
00061         }
00062         if (!TESTS_QUIET) fprintf(stdout,"c=%lf\n",c);
00063 
00064         if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK )
00065             test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00066     }
00067     test_pass( __FILE__, NULL, 0 );
00068     exit( 1 );
00069 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines