PAPI 7.1.0.0
Loading...
Searching...
No Matches
shlib.c
Go to the documentation of this file.
1/*
2* File: profile.c
3* Author: Philip Mucci
4* mucci@cs.utk.edu
5*/
6
7#include <stdio.h>
8#include <stdlib.h>
9#include <string.h>
10#include <unistd.h>
11
12#if (!defined(NO_DLFCN) && !defined(_BGL) && !defined(_BGP))
13#include <dlfcn.h>
14#endif
15
16#include "papi.h"
17#include "papi_test.h"
18
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}
53
54void display( char *msg )
55{
56 int i;
57 for (i=0; i<64; i++)
58 {
59 printf( "%1d", (msg[i] ? 1 : 0) );
60 }
61 printf("\n");
62}
63
64int
65main( int argc, char **argv )
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
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
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}
static papi_handle_t handle
Definition: Gamum.c:21
int i
Get address info about the shared libraries used by the process.
initialize the PAPI library.
#define PAPI_VER_CURRENT
Definition: f90papi.h:54
static pthread_key_t key
Return codes and api definitions.
int tests_quiet(int argc, char **argv)
Definition: test_utils.c:376
void PAPI_NORETURN test_fail(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:491
void PAPI_NORETURN test_pass(const char *filename)
Definition: test_utils.c:432
void PAPI_NORETURN test_skip(const char *file, int line, const char *call, int retval)
Definition: test_utils.c:584
int main()
Definition: pernode.c:20
int quiet
Definition: rapl_overflow.c:19
void print_shlib_info_map(const PAPI_shlib_info_t *shinfo, int quiet)
Definition: shlib.c:19
void display(char *msg)
Definition: shlib.c:54
get the executable's address space info
Definition: papi.h:684
vptr_t text_start
Definition: papi.h:686
char name[PAPI_HUGE_STR_LEN]
Definition: papi.h:685
vptr_t text_end
Definition: papi.h:687
vptr_t bss_start
Definition: papi.h:690
vptr_t data_end
Definition: papi.h:689
vptr_t data_start
Definition: papi.h:688
vptr_t bss_end
Definition: papi.h:691
PAPI_address_map_t * map
Definition: papi.h:703
int retval
Definition: zero_fork.c:53