PAPI  5.6.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
shlib.c File Reference
Include dependency graph for shlib.c:

Go to the source code of this file.

Functions

void print_shlib_info_map (const PAPI_shlib_info_t *shinfo, int quiet)
 
void display (char *msg)
 
int main (int argc, char **argv)
 

Function Documentation

void display ( char *  msg)

Definition at line 54 of file shlib.c.

55 {
56  int i;
57  for (i=0; i<64; i++)
58  {
59  printf( "%1d", (msg[i] ? 1 : 0) );
60  }
61  printf("\n");
62 }
int i
Definition: fileop.c:140
printf("\tTry: -i 0 -i 1 \n\n")

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char **  argv 
)

Definition at line 65 of file shlib.c.

66 {
67  int retval,quiet;
68 
69  const PAPI_shlib_info_t *shinfo;
70 
71  /* Set TESTS_QUIET variable */
72  quiet = tests_quiet( argc, argv );
73 
75  if (retval != PAPI_VER_CURRENT ) {
76  test_fail( __FILE__, __LINE__, "PAPI_library_init", retval );
77  }
78 
79  if ( ( shinfo = PAPI_get_shared_lib_info( ) ) == NULL ) {
80  test_skip( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
81  }
82 
83  if ( ( shinfo->count == 0 ) && ( shinfo->map ) ) {
84  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
85  }
86 
87  print_shlib_info_map(shinfo, quiet);
88 
89  /* Needed for debugging, so you can ^Z and stop the process, */
90  /* inspect /proc to see if it's right */
91  sleep( 1 );
92 
93 #ifndef NO_DLFCN
94  {
95 
96  const char *_libname = "libcrypt.so";
97  void *handle;
98  void ( *setkey) (const char *key);
99  void ( *encrypt) (char block[64], int edflag);
100  char key[64]={
101  1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
102  1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
103  1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
104  1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,
105  }; /* bit pattern for key */
106  char orig[64]; /* bit pattern for messages */
107  char txt[64]; /* bit pattern for messages */
108 
109  int oldcount;
110 
111  handle = dlopen( _libname, RTLD_NOW );
112  if ( !handle ) {
113  printf( "dlopen: %s\n", dlerror( ) );
114  if (!quiet) printf( "Did you forget to set the environmental "
115  "variable LIBPATH (in AIX) or "
116  "LD_LIBRARY_PATH (in linux) ?\n" );
117  test_fail( __FILE__, __LINE__, "dlopen", 1 );
118  }
119 
120  setkey = dlsym( handle, "setkey" );
121  encrypt = dlsym( handle, "encrypt" );
122  if ( setkey == NULL || encrypt == NULL) {
123  if (!quiet) printf( "dlsym: %s\n", dlerror( ) );
124  test_fail( __FILE__, __LINE__, "dlsym", 1 );
125  }
126 
127  memset(orig,0,64);
128  memcpy(txt,orig,64);
129  setkey(key);
130 
131  if (!quiet) {
132  printf("original ");
133  display(txt);
134  }
135 
136  encrypt(txt, 0); /* encode */
137 
138  if (!quiet) {
139  printf("encrypted ");
140  display(txt);
141  }
142 
143  if (!memcmp(txt,orig,64)) {
144  test_fail( __FILE__, __LINE__, "encode", 1 );
145  }
146 
147  encrypt(txt, 1); /* decode */
148 
149  if (!quiet) {
150  printf("decrypted ");
151  display(txt);
152  }
153 
154  if (memcmp(txt,orig,64)) {
155  test_fail( __FILE__, __LINE__, "decode", 1 );
156  }
157 
158  oldcount = shinfo->count;
159 
160  if ( ( shinfo = PAPI_get_shared_lib_info( ) ) == NULL ) {
161  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
162  }
163 
164  /* Needed for debugging, so you can ^Z and stop the process, */
165  /* inspect /proc to see if it's right */
166  sleep( 1 );
167 
168  if ( ( shinfo->count == 0 ) && ( shinfo->map ) ) {
169  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
170  }
171 
172  if ( shinfo->count <= oldcount ) {
173  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
174  }
175 
176  print_shlib_info_map(shinfo, quiet);
177 
178  /* Needed for debugging, so you can ^Z and stop the process, */
179  /* inspect /proc to see if it's right */
180  sleep( 1 );
181 
182  dlclose( handle );
183 
184  }
185 #endif
186 
187  test_pass( __FILE__ );
188 
189  return 0;
190 
191 }
void test_pass(const char *filename)
Definition: test_utils.c:432
sleep(1)
const PAPI_shlib_info_t * PAPI_get_shared_lib_info(void)
Definition: papi.c:6144
void print_shlib_info_map(const PAPI_shlib_info_t *shinfo, int quiet)
Definition: shlib.c:19
void
Definition: iozone.c:18627
int int argc
Definition: iozone.c:1609
void test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:559
char ** argv
Definition: iozone.c:1610
void display(char *msg)
Definition: shlib.c:54
int PAPI_library_init(int version)
Definition: papi.c:500
int quiet
Definition: rapl_overflow.c:18
static pthread_key_t key
nvmlDevice_t handle
Definition: linux-nvml.c:427
printf("\tTry: -i 0 -i 1 \n\n")
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
PAPI_address_map_t * map
Definition: papi.h:714
ssize_t retval
Definition: libasync.c:338
#define PAPI_VER_CURRENT
Definition: papi.h:225

Here is the call graph for this function:

void print_shlib_info_map ( const PAPI_shlib_info_t shinfo,
int  quiet 
)

Definition at line 19 of file shlib.c.

20 {
21  PAPI_address_map_t *map = shinfo->map;
22  int i;
23  if (NULL == map) {
24  test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info", 1);
25  }
26 
27  if (!quiet) for ( i = 0; i < shinfo->count; i++ ) {
28  printf( "Library: %s\n", map->name );
29  printf( "Text start: %p, Text end: %p\n", map->text_start,
30  map->text_end );
31  printf( "Data start: %p, Data end: %p\n", map->data_start,
32  map->data_end );
33  printf( "Bss start: %p, Bss end: %p\n", map->bss_start, map->bss_end );
34 
35  if ( strlen( &(map->name[0]) ) == 0 )
36  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
37  if ( ( map->text_start == 0x0 ) || ( map->text_end == 0x0 ) ||
38  ( map->text_start >= map->text_end ) )
39  test_fail( __FILE__, __LINE__, "PAPI_get_shared_lib_info", 1 );
40 /*
41  if ((map->data_start == 0x0) || (map->data_end == 0x0) ||
42  (map->data_start >= map->data_end))
43  test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1);
44  if (((map->bss_start) && (!map->bss_end)) ||
45  ((!map->bss_start) && (map->bss_end)) ||
46  (map->bss_start > map->bss_end))
47  test_fail(__FILE__, __LINE__, "PAPI_get_shared_lib_info",1);
48 */
49 
50  map++;
51  }
52 }
char name[PAPI_HUGE_STR_LEN]
Definition: papi.h:696
caddr_t text_end
Definition: papi.h:698
caddr_t bss_start
Definition: papi.h:701
int i
Definition: fileop.c:140
int quiet
Definition: rapl_overflow.c:18
caddr_t text_start
Definition: papi.h:697
get the executable&#39;s address space info
Definition: papi.h:695
caddr_t data_start
Definition: papi.h:699
printf("\tTry: -i 0 -i 1 \n\n")
void test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:468
PAPI_address_map_t * map
Definition: papi.h:714
caddr_t bss_end
Definition: papi.h:702
caddr_t data_end
Definition: papi.h:700

Here is the call graph for this function:

Here is the caller graph for this function: