PAPI  5.3.2.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shlib.c
Go to the documentation of this file.
1 /*
2 * File: profile.c
3 * CVS: $Id$
4 * Author: Philip Mucci
5 * mucci@cs.utk.edu
6 * Mods: <your name here>
7 * <your email address>
8 */
9 #include "papi_test.h"
10 
12 {
13  PAPI_address_map_t *map = shinfo->map;
14  int i;
15  if (NULL == map) {
16  test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info", 1);
17  }
18 
19  for ( i = 0; i < shinfo->count; i++ ) {
20  printf( "Library: %s\n", map->name );
21  printf( "Text start: %p, Text end: %p\n", map->text_start,
22  map->text_end );
23  printf( "Data start: %p, Data end: %p\n", map->data_start,
24  map->data_end );
25  printf( "Bss start: %p, Bss end: %p\n", map->bss_start, map->bss_end );
26 
27  if ( strlen( &(map->name[0]) ) == 0 )
28  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
29  if ( ( map->text_start == 0x0 ) || ( map->text_end == 0x0 ) ||
30  ( map->text_start >= map->text_end ) )
31  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
32 /*
33  if ((map->data_start == 0x0) || (map->data_end == 0x0) ||
34  (map->data_start >= map->data_end))
35  test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1);
36  if (((map->bss_start) && (!map->bss_end)) ||
37  ((!map->bss_start) && (map->bss_end)) ||
38  (map->bss_start > map->bss_end))
39  test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1);
40 */
41 
42  map++;
43  }
44 }
45 
46 void display( char *msg )
47 {
48  int i;
49  for (i=0; i<64; i++)
50  {
51  printf( "%1d", (msg[i] ? 1 : 0) );
52  }
53  printf("\n");
54 }
55 
56 int
57 main( int argc, char **argv )
58 {
59  int retval;
60 
61  const PAPI_shlib_info_t *shinfo;
62 
63  tests_quiet( argc, argv ); /* Set TESTS_QUIET variable */
64 
65  if ( ( retval =
67  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
68 
69  if ( ( shinfo = PAPI_get_shared_lib_info( ) ) == NULL ) {
70  test_skip( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
71  }
72 
73  if ( ( shinfo->count == 0 ) && ( shinfo->map ) ) {
74  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
75  }
76 
77  print_shlib_info_map(shinfo);
78 
79  sleep( 1 ); /* Needed for debugging, so you can ^Z and stop the process, inspect /proc to see if it's right */
80 
81 #ifndef NO_DLFCN
82  {
83  char *_libname = "libcrypt.so";
84  void *handle;
85  void ( *setkey) (const char *key);
86  void ( *encrypt) (char block[64], int edflag);
87  char key[64]={
88  1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
89  1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
90  1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
91  1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
92  }; /* bit pattern for key */
93  char orig[64]; /* bit pattern for messages */
94  char txt[64]; /* bit pattern for messages */
95 
96  int oldcount;
97 
98  handle = dlopen( _libname, RTLD_NOW );
99  if ( !handle ) {
100  printf( "dlopen: %s\n", dlerror( ) );
101  printf
102  ( "Did you forget to set the environmental variable LIBPATH (in AIX) or LD_LIBRARY_PATH (in linux) ?\n" );
103  test_fail( __FILE__, __LINE__, "dlopen", 1 );
104  }
105 
106  setkey = dlsym( handle, "setkey" );
107  encrypt = dlsym( handle, "encrypt" );
108  if ( setkey == NULL || encrypt == NULL) {
109  printf( "dlsym: %s\n", dlerror( ) );
110  test_fail( __FILE__, __LINE__, "dlsym", 1 );
111  }
112 
113  memset(orig,0,64);
114  memcpy(txt,orig,64);
115  setkey(key);
116 
117  printf("original "); display(txt);
118  encrypt(txt, 0); /* encode */
119  printf("encrypted "); display(txt);
120  if (!memcmp(txt,orig,64))
121  test_fail( __FILE__, __LINE__, "encode", 1 );
122  encrypt(txt, 1); /* decode */
123  printf("decrypted "); display(txt);
124  if (memcmp(txt,orig,64))
125  test_fail( __FILE__, __LINE__, "decode", 1 );
126 
127 
128  oldcount = shinfo->count;
129 
130  if ( ( shinfo = PAPI_get_shared_lib_info( ) ) == NULL ) {
131  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
132  }
133 
134  sleep( 1 ); /* Needed for debugging, so you can ^Z and stop the process, inspect /proc to see if it's right */
135 
136  if ( ( shinfo->count == 0 ) && ( shinfo->map ) ) {
137  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
138  }
139 
140  if ( shinfo->count <= oldcount ) {
141  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
142  }
143 
144  print_shlib_info_map(shinfo);
145 
146  sleep( 1 ); /* Needed for debugging, so you can ^Z and stop the process, inspect /proc to see if it's right */
147 
148  dlclose( handle );
149  }
150 #endif
151 
152  test_pass( __FILE__, NULL, 0 );
153  exit( 0 );
154 }
char name[PAPI_HUGE_STR_LEN]
Definition: papi.h:691
memset(eventId, 0, size)
sleep(1)
const PAPI_shlib_info_t * PAPI_get_shared_lib_info(void)
Definition: papi.c:6018
caddr_t text_end
Definition: papi.h:693
void test_skip(char *file, int line, char *call, int retval)
Definition: test_utils.c:614
caddr_t bss_start
Definition: papi.h:696
tests_quiet(argc, argv)
void
Definition: iozone.c:18627
#define printf
Definition: papi_test.h:125
test_pass(__FILE__, NULL, 0)
int int argc
Definition: iozone.c:1609
char ** argv
Definition: iozone.c:1610
void display(char *msg)
Definition: shlib.c:46
test_fail(__FILE__, __LINE__,"PAPI_library_init", retval)
int PAPI_library_init(int version)
Definition: papi.c:495
int i
Definition: fileop.c:140
caddr_t text_start
Definition: papi.h:692
pthread_key_t key
get the executable&#39;s address space info
Definition: papi.h:690
#define PAPI_VER_CURRENT
Definition: fpapi.h:14
nvmlDevice_t handle
Definition: linux-nvml.c:399
void print_shlib_info_map(const PAPI_shlib_info_t *shinfo)
Definition: shlib.c:11
caddr_t data_start
Definition: papi.h:694
PAPI_address_map_t * map
Definition: papi.h:709
caddr_t bss_end
Definition: papi.h:697
caddr_t data_end
Definition: papi.h:695
ssize_t retval
Definition: libasync.c:338
int main(int argc, char **argv)
List all appio events codes and names.
void exit()