PAPI  5.0.1.0
describe.c
Go to the documentation of this file.
00001 /* From Paul Drongowski at HP. Thanks. */
00002 
00003 /*  I have not been able to call PAPI_describe_event without
00004     incurring a segv, including the sample code on the man page.
00005     I noticed that PAPI_describe_event is not exercised by the
00006     PAPI test programs, so I haven't been able to check the
00007     function call using known good code. (Or steal your code
00008     for that matter. :-)
00009 */
00010 
00011 /*  PAPI_describe_event has been deprecated in PAPI 3, since 
00012     its functionality exists in other API calls. Below shows
00013     several ways that this call was used, with replacement 
00014     code compatible with PAPI 3.
00015 */
00016 
00017 #include "papi_test.h"
00018 
00019 extern int TESTS_QUIET;                /* Declared in test_utils.c */
00020 
00021 int
00022 main( int argc, char **argv )
00023 {
00024     int EventSet = PAPI_NULL;
00025     int retval;
00026     long long g1[2];
00027     int eventcode = PAPI_TOT_INS;
00028     char eventname[PAPI_MAX_STR_LEN];
00029     PAPI_event_info_t info, info1, info2;
00030 
00031     tests_quiet( argc, argv );  /* Set TESTS_QUIET variable */
00032 
00033     if ( ( retval =
00034            PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT )
00035         test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
00036 
00037 
00038     if ( ( retval = PAPI_create_eventset( &EventSet ) ) != PAPI_OK )
00039         test_fail( __FILE__, __LINE__, "PAPI_create_eventset", retval );
00040 
00041     if ( ( retval = PAPI_query_event( eventcode ) ) != PAPI_OK )
00042         test_fail( __FILE__, __LINE__, "PAPI_query_event(PAPI_TOT_INS)",
00043                    retval );
00044 
00045     if ( ( retval = PAPI_add_event( EventSet, eventcode ) ) != PAPI_OK )
00046         test_fail( __FILE__, __LINE__, "PAPI_add_event(PAPI_TOT_INS)", retval );
00047 
00048     if ( ( retval = PAPI_start( EventSet ) ) != PAPI_OK )
00049         test_fail( __FILE__, __LINE__, "PAPI_start", retval );
00050 
00051     if ( ( retval = PAPI_stop( EventSet, g1 ) ) != PAPI_OK )
00052         test_fail( __FILE__, __LINE__, "PAPI_stop", retval );
00053 
00054     /* Case 0, no info, should fail */
00055     eventname[0] = '\0';
00056     eventcode = 0;
00057 /*
00058    if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) == PAPI_OK)
00059      test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);    
00060 */
00061     if ( ( retval = PAPI_get_event_info( eventcode, &info ) ) == PAPI_OK )
00062         test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
00063 
00064     /* Case 1, fill in name field. */
00065     eventcode = PAPI_TOT_INS;
00066     eventname[0] = '\0';
00067 /*
00068    if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) != PAPI_OK)
00069      test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);    
00070 */
00071     if ( ( retval = PAPI_get_event_info( eventcode, &info1 ) ) != PAPI_OK )
00072         test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
00073 
00074     if ( strcmp( info1.symbol, "PAPI_TOT_INS" ) != 0 )
00075         test_fail( __FILE__, __LINE__,
00076                    "PAPI_get_event_info symbol value is bogus", retval );
00077     if ( strlen( info1.long_descr ) == 0 )
00078         test_fail( __FILE__, __LINE__,
00079                    "PAPI_get_event_info long_descr value is bogus", retval );
00080 
00081     eventcode = 0;
00082 
00083     /* Case 2, fill in code field. */
00084 /*
00085    if ( ( retval = PAPI_describe_event(eventname,(int *)&eventcode,eventdesc) ) != PAPI_OK)
00086      test_fail(__FILE__,__LINE__,"PAPI_describe_event",retval);    
00087 */
00088     strcpy( eventname, info1.symbol );
00089     if ( ( retval =
00090            PAPI_event_name_to_code( eventname,
00091                                     ( int * ) &eventcode ) ) != PAPI_OK )
00092         test_fail( __FILE__, __LINE__, "PAPI_event_name_to_code", retval );
00093 
00094     if ( eventcode != PAPI_TOT_INS )
00095         test_fail( __FILE__, __LINE__,
00096                    "PAPI_event_name_to_code code value is bogus", retval );
00097 
00098     if ( ( retval = PAPI_get_event_info( eventcode, &info2 ) ) != PAPI_OK )
00099         test_fail( __FILE__, __LINE__, "PAPI_get_event_info", retval );
00100 
00101     if ( strcmp( info2.symbol, "PAPI_TOT_INS" ) != 0 )
00102         test_fail( __FILE__, __LINE__,
00103                    "PAPI_get_event_info symbol value is bogus", retval );
00104     if ( strlen( info2.long_descr ) == 0 )
00105         test_fail( __FILE__, __LINE__,
00106                    "PAPI_get_event_info long_descr value is bogus", retval );
00107 
00108     test_pass( __FILE__, NULL, 0 );
00109     exit( 1 );
00110 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines