aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorMichael Ellerman <mpe@ellerman.id.au>2015-11-23 21:05:38 -0500
committerMichael Ellerman <mpe@ellerman.id.au>2015-12-14 04:41:47 -0500
commitfcb45ec074725baeb3aaa1b1854b9f44c3eebacf (patch)
tree5bed3b7b288a554cd633df3d387127638df12819 /tools
parent1901d8bb45c3b82335c48e6232871f72ad10ed95 (diff)
selftests/powerpc: Move get_auxv_entry() into utils.c
This doesn't really belong in harness.c, it's a helper function. So move it into utils.c. Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'tools')
-rw-r--r--tools/testing/selftests/powerpc/harness.c43
-rw-r--r--tools/testing/selftests/powerpc/pmu/Makefile2
-rw-r--r--tools/testing/selftests/powerpc/pmu/ebb/Makefile3
-rw-r--r--tools/testing/selftests/powerpc/tm/Makefile2
-rw-r--r--tools/testing/selftests/powerpc/utils.c58
5 files changed, 63 insertions, 45 deletions
diff --git a/tools/testing/selftests/powerpc/harness.c b/tools/testing/selftests/powerpc/harness.c
index f7997affd143..52f9be7f61f0 100644
--- a/tools/testing/selftests/powerpc/harness.c
+++ b/tools/testing/selftests/powerpc/harness.c
@@ -116,46 +116,3 @@ int test_harness(int (test_function)(void), char *name)
116 116
117 return rc; 117 return rc;
118} 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/Makefile b/tools/testing/selftests/powerpc/pmu/Makefile
index a9099d9f8f39..50326cbb372d 100644
--- a/tools/testing/selftests/powerpc/pmu/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/Makefile
@@ -12,6 +12,8 @@ $(TEST_PROGS): $(EXTRA_SOURCES)
12count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES) 12count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES)
13 $(CC) $(CFLAGS) -m64 -o $@ $^ 13 $(CC) $(CFLAGS) -m64 -o $@ $^
14 14
15per_event_excludes: ../utils.c
16
15include ../../lib.mk 17include ../../lib.mk
16 18
17DEFAULT_RUN_TESTS := $(RUN_TESTS) 19DEFAULT_RUN_TESTS := $(RUN_TESTS)
diff --git a/tools/testing/selftests/powerpc/pmu/ebb/Makefile b/tools/testing/selftests/powerpc/pmu/ebb/Makefile
index 5cdc9dbf2b27..8d2279c4bb4b 100644
--- a/tools/testing/selftests/powerpc/pmu/ebb/Makefile
+++ b/tools/testing/selftests/powerpc/pmu/ebb/Makefile
@@ -18,7 +18,8 @@ TEST_PROGS := reg_access_test event_attributes_test cycles_test \
18 18
19all: $(TEST_PROGS) 19all: $(TEST_PROGS)
20 20
21$(TEST_PROGS): ../../harness.c ../event.c ../lib.c ebb.c ebb_handler.S trace.c busy_loop.S 21$(TEST_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c \
22 ebb.c ebb_handler.S trace.c busy_loop.S
22 23
23instruction_count_test: ../loop.S 24instruction_count_test: ../loop.S
24 25
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index 4bea62a319dc..e7b9be7947c8 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -4,7 +4,7 @@ all: $(TEST_PROGS)
4 4
5$(TEST_PROGS): ../harness.c 5$(TEST_PROGS): ../harness.c
6 6
7tm-syscall: tm-syscall-asm.S 7tm-syscall: tm-syscall-asm.S ../utils.c
8tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include 8tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include
9 9
10include ../../lib.mk 10include ../../lib.mk
diff --git a/tools/testing/selftests/powerpc/utils.c b/tools/testing/selftests/powerpc/utils.c
new file mode 100644
index 000000000000..536113add380
--- /dev/null
+++ b/tools/testing/selftests/powerpc/utils.c
@@ -0,0 +1,58 @@
1/*
2 * Copyright 2013-2015, Michael Ellerman, IBM Corp.
3 * Licensed under GPLv2.
4 */
5
6#include <elf.h>
7#include <errno.h>
8#include <fcntl.h>
9#include <link.h>
10#include <stdio.h>
11#include <sys/stat.h>
12#include <sys/types.h>
13#include <unistd.h>
14
15#include "utils.h"
16
17static char auxv[4096];
18
19void *get_auxv_entry(int type)
20{
21 ElfW(auxv_t) *p;
22 void *result;
23 ssize_t num;
24 int fd;
25
26 fd = open("/proc/self/auxv", O_RDONLY);
27 if (fd == -1) {
28 perror("open");
29 return NULL;
30 }
31
32 result = NULL;
33
34 num = read(fd, auxv, sizeof(auxv));
35 if (num < 0) {
36 perror("read");
37 goto out;
38 }
39
40 if (num > sizeof(auxv)) {
41 printf("Overflowed auxv buffer\n");
42 goto out;
43 }
44
45 p = (ElfW(auxv_t) *)auxv;
46
47 while (p->a_type != AT_NULL) {
48 if (p->a_type == type) {
49 result = (void *)p->a_un.a_val;
50 break;
51 }
52
53 p++;
54 }
55out:
56 close(fd);
57 return result;
58}