diff options
author | Michael Ellerman <mpe@ellerman.id.au> | 2015-11-23 21:05:38 -0500 |
---|---|---|
committer | Michael Ellerman <mpe@ellerman.id.au> | 2015-12-14 04:41:47 -0500 |
commit | fcb45ec074725baeb3aaa1b1854b9f44c3eebacf (patch) | |
tree | 5bed3b7b288a554cd633df3d387127638df12819 /tools | |
parent | 1901d8bb45c3b82335c48e6232871f72ad10ed95 (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.c | 43 | ||||
-rw-r--r-- | tools/testing/selftests/powerpc/pmu/Makefile | 2 | ||||
-rw-r--r-- | tools/testing/selftests/powerpc/pmu/ebb/Makefile | 3 | ||||
-rw-r--r-- | tools/testing/selftests/powerpc/tm/Makefile | 2 | ||||
-rw-r--r-- | tools/testing/selftests/powerpc/utils.c | 58 |
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 | |||
120 | static char auxv[4096]; | ||
121 | |||
122 | void *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 | } | ||
158 | out: | ||
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) | |||
12 | count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES) | 12 | count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES) |
13 | $(CC) $(CFLAGS) -m64 -o $@ $^ | 13 | $(CC) $(CFLAGS) -m64 -o $@ $^ |
14 | 14 | ||
15 | per_event_excludes: ../utils.c | ||
16 | |||
15 | include ../../lib.mk | 17 | include ../../lib.mk |
16 | 18 | ||
17 | DEFAULT_RUN_TESTS := $(RUN_TESTS) | 19 | DEFAULT_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 | ||
19 | all: $(TEST_PROGS) | 19 | all: $(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 | ||
23 | instruction_count_test: ../loop.S | 24 | instruction_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 | ||
7 | tm-syscall: tm-syscall-asm.S | 7 | tm-syscall: tm-syscall-asm.S ../utils.c |
8 | tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include | 8 | tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include |
9 | 9 | ||
10 | include ../../lib.mk | 10 | include ../../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 | |||
17 | static char auxv[4096]; | ||
18 | |||
19 | void *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 | } | ||
55 | out: | ||
56 | close(fd); | ||
57 | return result; | ||
58 | } | ||