aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorSam bobroff <sam.bobroff@au1.ibm.com>2015-04-10 00:16:48 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2015-04-11 06:49:20 -0400
commit2b03fc1db59d53da327cf21f77e189b4d0a8aced (patch)
treec53d1f039ff14efc82895544df2b107925c51f05 /tools
parentfeba40362b11341bee6d8ed58d54b896abbd9f84 (diff)
selftests/powerpc: Move get_auxv_entry() to harness.c
Move get_auxv_entry() from pmu/lib.c up to harness.c in order to make it available to other tests. Signed-off-by: Sam Bobroff <sam.bobroff@au1.ibm.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/powerpc/harness.c47
-rw-r--r--tools/testing/selftests/powerpc/pmu/lib.c47
-rw-r--r--tools/testing/selftests/powerpc/pmu/lib.h1
-rw-r--r--tools/testing/selftests/powerpc/utils.h2
4 files changed, 48 insertions, 49 deletions
diff --git a/tools/testing/selftests/powerpc/harness.c b/tools/testing/selftests/powerpc/harness.c
index 8ebc58a09311..f7997affd143 100644
--- a/tools/testing/selftests/powerpc/harness.c
+++ b/tools/testing/selftests/powerpc/harness.c
@@ -11,6 +11,10 @@
11#include <sys/types.h> 11#include <sys/types.h>
12#include <sys/wait.h> 12#include <sys/wait.h>
13#include <unistd.h> 13#include <unistd.h>
14#include <elf.h>
15#include <fcntl.h>
16#include <link.h>
17#include <sys/stat.h>
14 18
15#include "subunit.h" 19#include "subunit.h"
16#include "utils.h" 20#include "utils.h"
@@ -112,3 +116,46 @@ int test_harness(int (test_function)(void), char *name)
112 116
113 return rc; 117 return rc;
114} 118}
119
120static char auxv[4096];
121
122void *get_auxv_entry(int type)
123{
124 ElfW(auxv_t) *p;
125 void *result;
126 ssize_t num;
127 int fd;
128
129 fd = open("/proc/self/auxv", O_RDONLY);
130 if (fd == -1) {
131 perror("open");
132 return NULL;
133 }
134
135 result = NULL;
136
137 num = read(fd, auxv, sizeof(auxv));
138 if (num < 0) {
139 perror("read");
140 goto out;
141 }
142
143 if (num > sizeof(auxv)) {
144 printf("Overflowed auxv buffer\n");
145 goto out;
146 }
147
148 p = (ElfW(auxv_t) *)auxv;
149
150 while (p->a_type != AT_NULL) {
151 if (p->a_type == type) {
152 result = (void *)p->a_un.a_val;
153 break;
154 }
155
156 p++;
157 }
158out:
159 close(fd);
160 return result;
161}
diff --git a/tools/testing/selftests/powerpc/pmu/lib.c b/tools/testing/selftests/powerpc/pmu/lib.c
index 9768dea37bf3..a07104c2afe6 100644
--- a/tools/testing/selftests/powerpc/pmu/lib.c
+++ b/tools/testing/selftests/powerpc/pmu/lib.c
@@ -5,15 +5,10 @@
5 5
6#define _GNU_SOURCE /* For CPU_ZERO etc. */ 6#define _GNU_SOURCE /* For CPU_ZERO etc. */
7 7
8#include <elf.h>
9#include <errno.h> 8#include <errno.h>
10#include <fcntl.h>
11#include <link.h>
12#include <sched.h> 9#include <sched.h>
13#include <setjmp.h> 10#include <setjmp.h>
14#include <stdlib.h> 11#include <stdlib.h>
15#include <sys/stat.h>
16#include <sys/types.h>
17#include <sys/wait.h> 12#include <sys/wait.h>
18 13
19#include "utils.h" 14#include "utils.h"
@@ -256,45 +251,3 @@ out:
256 return rc; 251 return rc;
257} 252}
258 253
259static char auxv[4096];
260
261void *get_auxv_entry(int type)
262{
263 ElfW(auxv_t) *p;
264 void *result;
265 ssize_t num;
266 int fd;
267
268 fd = open("/proc/self/auxv", O_RDONLY);
269 if (fd == -1) {
270 perror("open");
271 return NULL;
272 }
273
274 result = NULL;
275
276 num = read(fd, auxv, sizeof(auxv));
277 if (num < 0) {
278 perror("read");
279 goto out;
280 }
281
282 if (num > sizeof(auxv)) {
283 printf("Overflowed auxv buffer\n");
284 goto out;
285 }
286
287 p = (ElfW(auxv_t) *)auxv;
288
289 while (p->a_type != AT_NULL) {
290 if (p->a_type == type) {
291 result = (void *)p->a_un.a_val;
292 break;
293 }
294
295 p++;
296 }
297out:
298 close(fd);
299 return result;
300}
diff --git a/tools/testing/selftests/powerpc/pmu/lib.h b/tools/testing/selftests/powerpc/pmu/lib.h
index 0f0339c8a6f6..ca5d72ae3be6 100644
--- a/tools/testing/selftests/powerpc/pmu/lib.h
+++ b/tools/testing/selftests/powerpc/pmu/lib.h
@@ -29,7 +29,6 @@ extern int notify_parent(union pipe write_pipe);
29extern int notify_parent_of_error(union pipe write_pipe); 29extern int notify_parent_of_error(union pipe write_pipe);
30extern pid_t eat_cpu(int (test_function)(void)); 30extern pid_t eat_cpu(int (test_function)(void));
31extern bool require_paranoia_below(int level); 31extern bool require_paranoia_below(int level);
32extern void *get_auxv_entry(int type);
33 32
34struct addr_range { 33struct addr_range {
35 uint64_t first, last; 34 uint64_t first, last;
diff --git a/tools/testing/selftests/powerpc/utils.h b/tools/testing/selftests/powerpc/utils.h
index 2ec455e37792..b7d41086bb0a 100644
--- a/tools/testing/selftests/powerpc/utils.h
+++ b/tools/testing/selftests/powerpc/utils.h
@@ -20,7 +20,7 @@ typedef uint8_t u8;
20 20
21 21
22int test_harness(int (test_function)(void), char *name); 22int test_harness(int (test_function)(void), char *name);
23 23extern void *get_auxv_entry(int type);
24 24
25/* Yes, this is evil */ 25/* Yes, this is evil */
26#define FAIL_IF(x) \ 26#define FAIL_IF(x) \