|
PAPI
5.0.1.0
|
00001 /* 00002 * File: profile.c 00003 * CVS: $Id$ 00004 * Author: Philip Mucci 00005 * mucci@cs.utk.edu 00006 * Mods: <your name here> 00007 * <your email address> 00008 */ 00009 #include "papi_test.h" 00010 00011 int 00012 main( int argc, char **argv ) 00013 { 00014 int retval; 00015 int i; 00016 00017 const PAPI_shlib_info_t *shinfo; 00018 PAPI_address_map_t *map; 00019 00020 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00021 00022 if ( ( retval = 00023 PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) 00024 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00025 00026 if ( ( shinfo = PAPI_get_shared_lib_info( ) ) == NULL ) { 00027 test_skip( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00028 } 00029 00030 if ( ( shinfo->count == 0 ) && ( shinfo->map ) ) { 00031 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00032 } 00033 00034 map = shinfo->map; 00035 for ( i = 0; i < shinfo->count; i++ ) { 00036 printf( "Library: %s\n", map->name ); 00037 printf( "Text start: %p, Text end: %p\n", map->text_start, 00038 map->text_end ); 00039 printf( "Data start: %p, Data end: %p\n", map->data_start, 00040 map->data_end ); 00041 printf( "Bss start: %p, Bss end: %p\n", map->bss_start, map->bss_end ); 00042 00043 if ( strlen( &(map->name[0]) ) == 0 ) 00044 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00045 if ( ( map->text_start == 0x0 ) || ( map->text_end == 0x0 ) || 00046 ( map->text_start >= map->text_end ) ) 00047 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00048 /* 00049 if ((map->data_start == 0x0) || (map->data_end == 0x0) || 00050 (map->data_start >= map->data_end)) 00051 test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1); 00052 if (((map->bss_start) && (!map->bss_end)) || 00053 ((!map->bss_start) && (map->bss_end)) || 00054 (map->bss_start > map->bss_end)) 00055 test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1); 00056 */ 00057 00058 map++; 00059 } 00060 00061 sleep( 1 ); /* Needed for debugging, so you can ^Z and stop the process, inspect /proc to see if it's right */ 00062 00063 #ifndef NO_DLFCN 00064 { 00065 char *_libname = "libm.so"; 00066 void *handle; 00067 double ( *pow ) ( double, double ); 00068 int oldcount; 00069 00070 handle = dlopen( _libname, RTLD_NOW ); 00071 if ( !handle ) { 00072 printf( "dlopen: %s\n", dlerror( ) ); 00073 printf 00074 ( "Did you forget to set the environmental variable LIBPATH (in AIX) or LD_LIBRARY_PATH (in linux) ?\n" ); 00075 test_fail( __FILE__, __LINE__, "dlopen", 1 ); 00076 } 00077 00078 pow = ( double ( * )( double, double ) ) dlsym( handle, "pow" ); 00079 if ( pow == NULL ) { 00080 printf( "dlsym: %s\n", dlerror( ) ); 00081 test_fail( __FILE__, __LINE__, "dlsym", 1 ); 00082 } 00083 printf( "2^2 = %lf \n", ( *pow ) ( 2, 2 ) ); 00084 00085 oldcount = shinfo->count; 00086 00087 if ( ( shinfo = PAPI_get_shared_lib_info( ) ) == NULL ) { 00088 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00089 } 00090 00091 sleep( 1 ); /* Needed for debugging, so you can ^Z and stop the process, inspect /proc to see if it's right */ 00092 00093 if ( ( shinfo->count == 0 ) && ( shinfo->map ) ) { 00094 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00095 } 00096 00097 if ( shinfo->count <= oldcount ) { 00098 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00099 } 00100 00101 map = shinfo->map; 00102 for ( i = 0; i < shinfo->count; i++ ) { 00103 printf( "Library: %s\n", map->name ); 00104 printf( "Text start: %p, Text end: %p\n", map->text_start, 00105 map->text_end ); 00106 printf( "Data start: %p, Data end: %p\n", map->data_start, 00107 map->data_end ); 00108 printf( "Bss start: %p, Bss end: %p\n", map->bss_start, 00109 map->bss_end ); 00110 00111 if ( strlen( &(map->name[0]) ) == 0 ) 00112 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00113 if ( ( map->text_start == 0x0 ) || ( map->text_end == 0x0 ) || 00114 ( map->text_start >= map->text_end ) ) 00115 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00116 /* 00117 if ((map->data_start == 0x0) || (map->data_end == 0x0) || 00118 (map->data_start >= map->data_end)) 00119 test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1); 00120 if (((map->bss_start) && (!map->bss_end)) || 00121 ((!map->bss_start) && (map->bss_end)) || 00122 (map->bss_start > map->bss_end)) 00123 test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1); 00124 */ 00125 00126 map++; 00127 } 00128 00129 sleep( 1 ); /* Needed for debugging, so you can ^Z and stop the process, inspect /proc to see if it's right */ 00130 00131 dlclose( handle ); 00132 } 00133 #endif 00134 00135 test_pass( __FILE__, NULL, 0 ); 00136 exit( 0 ); 00137 }