|
PAPI
5.3.0.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 void print_shlib_info_map(const PAPI_shlib_info_t *shinfo) 00012 { 00013 PAPI_address_map_t *map = shinfo->map; 00014 int i; 00015 if (NULL == map) { 00016 test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info", 1); 00017 } 00018 00019 for ( i = 0; i < shinfo->count; i++ ) { 00020 printf( "Library: %s\n", map->name ); 00021 printf( "Text start: %p, Text end: %p\n", map->text_start, 00022 map->text_end ); 00023 printf( "Data start: %p, Data end: %p\n", map->data_start, 00024 map->data_end ); 00025 printf( "Bss start: %p, Bss end: %p\n", map->bss_start, map->bss_end ); 00026 00027 if ( strlen( &(map->name[0]) ) == 0 ) 00028 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00029 if ( ( map->text_start == 0x0 ) || ( map->text_end == 0x0 ) || 00030 ( map->text_start >= map->text_end ) ) 00031 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00032 /* 00033 if ((map->data_start == 0x0) || (map->data_end == 0x0) || 00034 (map->data_start >= map->data_end)) 00035 test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1); 00036 if (((map->bss_start) && (!map->bss_end)) || 00037 ((!map->bss_start) && (map->bss_end)) || 00038 (map->bss_start > map->bss_end)) 00039 test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1); 00040 */ 00041 00042 map++; 00043 } 00044 } 00045 00046 void display( char *msg ) 00047 { 00048 int i; 00049 for (i=0; i<64; i++) 00050 { 00051 printf( "%1d", (msg[i] ? 1 : 0) ); 00052 } 00053 printf("\n"); 00054 } 00055 00056 int 00057 main( int argc, char **argv ) 00058 { 00059 int retval; 00060 00061 const PAPI_shlib_info_t *shinfo; 00062 00063 tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */ 00064 00065 if ( ( retval = 00066 PAPI_library_init( PAPI_VER_CURRENT ) ) != PAPI_VER_CURRENT ) 00067 test_fail( __FILE__, __LINE__, "PAPI_library_init", retval ); 00068 00069 if ( ( shinfo = PAPI_get_shared_lib_info( ) ) == NULL ) { 00070 test_skip( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00071 } 00072 00073 if ( ( shinfo->count == 0 ) && ( shinfo->map ) ) { 00074 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00075 } 00076 00077 print_shlib_info_map(shinfo); 00078 00079 sleep( 1 ); /* Needed for debugging, so you can ^Z and stop the process, inspect /proc to see if it's right */ 00080 00081 #ifndef NO_DLFCN 00082 { 00083 char *_libname = "libcrypt.so"; 00084 void *handle; 00085 void ( *setkey) (const char *key); 00086 void ( *encrypt) (char block[64], int edflag); 00087 char key[64]={ 00088 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0, 00089 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0, 00090 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0, 00091 1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0, 00092 }; /* bit pattern for key */ 00093 char orig[64]; /* bit pattern for messages */ 00094 char txt[64]; /* bit pattern for messages */ 00095 00096 int oldcount; 00097 00098 handle = dlopen( _libname, RTLD_NOW ); 00099 if ( !handle ) { 00100 printf( "dlopen: %s\n", dlerror( ) ); 00101 printf 00102 ( "Did you forget to set the environmental variable LIBPATH (in AIX) or LD_LIBRARY_PATH (in linux) ?\n" ); 00103 test_fail( __FILE__, __LINE__, "dlopen", 1 ); 00104 } 00105 00106 setkey = dlsym( handle, "setkey" ); 00107 encrypt = dlsym( handle, "encrypt" ); 00108 if ( setkey == NULL || encrypt == NULL) { 00109 printf( "dlsym: %s\n", dlerror( ) ); 00110 test_fail( __FILE__, __LINE__, "dlsym", 1 ); 00111 } 00112 00113 memset(orig,0,64); 00114 memcpy(txt,orig,64); 00115 setkey(key); 00116 00117 printf("original "); display(txt); 00118 encrypt(txt, 0); /* encode */ 00119 printf("encrypted "); display(txt); 00120 if (!memcmp(txt,orig,64)) 00121 test_fail( __FILE__, __LINE__, "encode", 1 ); 00122 encrypt(txt, 1); /* decode */ 00123 printf("decrypted "); display(txt); 00124 if (memcmp(txt,orig,64)) 00125 test_fail( __FILE__, __LINE__, "decode", 1 ); 00126 00127 00128 oldcount = shinfo->count; 00129 00130 if ( ( shinfo = PAPI_get_shared_lib_info( ) ) == NULL ) { 00131 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00132 } 00133 00134 sleep( 1 ); /* Needed for debugging, so you can ^Z and stop the process, inspect /proc to see if it's right */ 00135 00136 if ( ( shinfo->count == 0 ) && ( shinfo->map ) ) { 00137 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00138 } 00139 00140 if ( shinfo->count <= oldcount ) { 00141 test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 ); 00142 } 00143 00144 print_shlib_info_map(shinfo); 00145 00146 sleep( 1 ); /* Needed for debugging, so you can ^Z and stop the process, inspect /proc to see if it's right */ 00147 00148 dlclose( handle ); 00149 } 00150 #endif 00151 00152 test_pass( __FILE__, NULL, 0 ); 00153 exit( 0 ); 00154 }