All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/4] selftests/powerpc: Move get_auxv_entry() into utils.c
@ 2015-11-24  2:05 Michael Ellerman
  2015-11-24  2:05 ` [PATCH 2/4] selftests/powerpc: Add have_hwcap2() helper Michael Ellerman
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Michael Ellerman @ 2015-11-24  2:05 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Michael Neuling

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>
---
 tools/testing/selftests/powerpc/harness.c        | 43 ------------------
 tools/testing/selftests/powerpc/pmu/Makefile     |  2 +
 tools/testing/selftests/powerpc/pmu/ebb/Makefile |  3 +-
 tools/testing/selftests/powerpc/tm/Makefile      |  2 +-
 tools/testing/selftests/powerpc/utils.c          | 58 ++++++++++++++++++++++++
 5 files changed, 63 insertions(+), 45 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/utils.c

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)
 
 	return rc;
 }
-
-static char auxv[4096];
-
-void *get_auxv_entry(int type)
-{
-	ElfW(auxv_t) *p;
-	void *result;
-	ssize_t num;
-	int fd;
-
-	fd = open("/proc/self/auxv", O_RDONLY);
-	if (fd == -1) {
-		perror("open");
-		return NULL;
-	}
-
-	result = NULL;
-
-	num = read(fd, auxv, sizeof(auxv));
-	if (num < 0) {
-		perror("read");
-		goto out;
-	}
-
-	if (num > sizeof(auxv)) {
-		printf("Overflowed auxv buffer\n");
-		goto out;
-	}
-
-	p = (ElfW(auxv_t) *)auxv;
-
-	while (p->a_type != AT_NULL) {
-		if (p->a_type == type) {
-			result = (void *)p->a_un.a_val;
-			break;
-		}
-
-		p++;
-	}
-out:
-	close(fd);
-	return result;
-}
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)
 count_instructions: loop.S count_instructions.c $(EXTRA_SOURCES)
 	$(CC) $(CFLAGS) -m64 -o $@ $^
 
+per_event_excludes: ../utils.c
+
 include ../../lib.mk
 
 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	\
 
 all: $(TEST_PROGS)
 
-$(TEST_PROGS): ../../harness.c ../event.c ../lib.c ebb.c ebb_handler.S trace.c busy_loop.S
+$(TEST_PROGS): ../../harness.c ../../utils.c ../event.c ../lib.c \
+	       ebb.c ebb_handler.S trace.c busy_loop.S
 
 instruction_count_test: ../loop.S
 
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index 0e45c7e688b4..3e6e7aaa5312 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -4,7 +4,7 @@ all: $(TEST_PROGS)
 
 $(TEST_PROGS): ../harness.c
 
-tm-syscall: tm-syscall-asm.S
+tm-syscall: tm-syscall-asm.S ../utils.c
 tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include
 
 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 @@
+/*
+ * Copyright 2013-2015, Michael Ellerman, IBM Corp.
+ * Licensed under GPLv2.
+ */
+
+#include <elf.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <link.h>
+#include <stdio.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+#include "utils.h"
+
+static char auxv[4096];
+
+void *get_auxv_entry(int type)
+{
+	ElfW(auxv_t) *p;
+	void *result;
+	ssize_t num;
+	int fd;
+
+	fd = open("/proc/self/auxv", O_RDONLY);
+	if (fd == -1) {
+		perror("open");
+		return NULL;
+	}
+
+	result = NULL;
+
+	num = read(fd, auxv, sizeof(auxv));
+	if (num < 0) {
+		perror("read");
+		goto out;
+	}
+
+	if (num > sizeof(auxv)) {
+		printf("Overflowed auxv buffer\n");
+		goto out;
+	}
+
+	p = (ElfW(auxv_t) *)auxv;
+
+	while (p->a_type != AT_NULL) {
+		if (p->a_type == type) {
+			result = (void *)p->a_un.a_val;
+			break;
+		}
+
+		p++;
+	}
+out:
+	close(fd);
+	return result;
+}
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 2/4] selftests/powerpc: Add have_hwcap2() helper
  2015-11-24  2:05 [PATCH 1/4] selftests/powerpc: Move get_auxv_entry() into utils.c Michael Ellerman
@ 2015-11-24  2:05 ` Michael Ellerman
  2015-12-15 11:27   ` [2/4] " Michael Ellerman
  2015-11-24  2:05 ` [PATCH 3/4] selftests/powerpc: Move TM helpers into tm.h Michael Ellerman
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Michael Ellerman @ 2015-11-24  2:05 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Michael Neuling

We already do this twice and want to add another so add a helper.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 tools/testing/selftests/powerpc/pmu/ebb/ebb.c   | 3 +--
 tools/testing/selftests/powerpc/tm/tm-syscall.c | 3 +--
 tools/testing/selftests/powerpc/utils.h         | 6 ++++++
 3 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c b/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
index 9729d9f90218..e67452f1bcff 100644
--- a/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
+++ b/tools/testing/selftests/powerpc/pmu/ebb/ebb.c
@@ -13,7 +13,6 @@
 #include <stdlib.h>
 #include <string.h>
 #include <sys/ioctl.h>
-#include <linux/auxvec.h>
 
 #include "trace.h"
 #include "reg.h"
@@ -324,7 +323,7 @@ bool ebb_is_supported(void)
 {
 #ifdef PPC_FEATURE2_EBB
 	/* EBB requires at least POWER8 */
-	return ((long)get_auxv_entry(AT_HWCAP2) & PPC_FEATURE2_EBB);
+	return have_hwcap2(PPC_FEATURE2_EBB);
 #else
 	return false;
 #endif
diff --git a/tools/testing/selftests/powerpc/tm/tm-syscall.c b/tools/testing/selftests/powerpc/tm/tm-syscall.c
index e835bf7ec7ae..d7256b79ec4c 100644
--- a/tools/testing/selftests/powerpc/tm/tm-syscall.c
+++ b/tools/testing/selftests/powerpc/tm/tm-syscall.c
@@ -14,7 +14,6 @@
 #include <sys/syscall.h>
 #include <asm/tm.h>
 #include <asm/cputable.h>
-#include <linux/auxvec.h>
 #include <sys/time.h>
 #include <stdlib.h>
 
@@ -80,7 +79,7 @@ pid_t getppid_tm(bool suspend)
 static inline bool have_htm_nosc(void)
 {
 #ifdef PPC_FEATURE2_HTM_NOSC
-	return ((long)get_auxv_entry(AT_HWCAP2) & PPC_FEATURE2_HTM_NOSC);
+	return have_hwcap2(PPC_FEATURE2_HTM_NOSC);
 #else
 	printf("PPC_FEATURE2_HTM_NOSC not defined, can't check AT_HWCAP2\n");
 	return false;
diff --git a/tools/testing/selftests/powerpc/utils.h b/tools/testing/selftests/powerpc/utils.h
index b7d41086bb0a..fbf2bf530e50 100644
--- a/tools/testing/selftests/powerpc/utils.h
+++ b/tools/testing/selftests/powerpc/utils.h
@@ -8,6 +8,7 @@
 
 #include <stdint.h>
 #include <stdbool.h>
+#include <linux/auxvec.h>
 
 /* Avoid headaches with PRI?64 - just use %ll? always */
 typedef unsigned long long u64;
@@ -22,6 +23,11 @@ typedef uint8_t u8;
 int test_harness(int (test_function)(void), char *name);
 extern void *get_auxv_entry(int type);
 
+static inline bool have_hwcap2(unsigned long ftr2)
+{
+	return ((unsigned long)get_auxv_entry(AT_HWCAP2) & ftr2) == ftr2;
+}
+
 /* Yes, this is evil */
 #define FAIL_IF(x)						\
 do {								\
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 3/4] selftests/powerpc: Move TM helpers into tm.h
  2015-11-24  2:05 [PATCH 1/4] selftests/powerpc: Move get_auxv_entry() into utils.c Michael Ellerman
  2015-11-24  2:05 ` [PATCH 2/4] selftests/powerpc: Add have_hwcap2() helper Michael Ellerman
@ 2015-11-24  2:05 ` Michael Ellerman
  2015-12-15 11:27   ` [3/4] " Michael Ellerman
  2015-11-24  2:05 ` [PATCH 4/4] selftests/powerpc: Skip TM tests if we don't have TM Michael Ellerman
  2015-12-15 11:27 ` [1/4] selftests/powerpc: Move get_auxv_entry() into utils.c Michael Ellerman
  3 siblings, 1 reply; 7+ messages in thread
From: Michael Ellerman @ 2015-11-24  2:05 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Michael Neuling

Move have_htm_nosc() into a new tm.h, and add a new helper, have_htm()
which we'll use in the next patch.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 tools/testing/selftests/powerpc/tm/tm-syscall.c | 12 +--------
 tools/testing/selftests/powerpc/tm/tm.h         | 34 +++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 11 deletions(-)
 create mode 100644 tools/testing/selftests/powerpc/tm/tm.h

diff --git a/tools/testing/selftests/powerpc/tm/tm-syscall.c b/tools/testing/selftests/powerpc/tm/tm-syscall.c
index d7256b79ec4c..60560cb20e38 100644
--- a/tools/testing/selftests/powerpc/tm/tm-syscall.c
+++ b/tools/testing/selftests/powerpc/tm/tm-syscall.c
@@ -13,11 +13,11 @@
 #include <unistd.h>
 #include <sys/syscall.h>
 #include <asm/tm.h>
-#include <asm/cputable.h>
 #include <sys/time.h>
 #include <stdlib.h>
 
 #include "utils.h"
+#include "tm.h"
 
 extern int getppid_tm_active(void);
 extern int getppid_tm_suspended(void);
@@ -76,16 +76,6 @@ pid_t getppid_tm(bool suspend)
 	exit(-1);
 }
 
-static inline bool have_htm_nosc(void)
-{
-#ifdef PPC_FEATURE2_HTM_NOSC
-	return have_hwcap2(PPC_FEATURE2_HTM_NOSC);
-#else
-	printf("PPC_FEATURE2_HTM_NOSC not defined, can't check AT_HWCAP2\n");
-	return false;
-#endif
-}
-
 int tm_syscall(void)
 {
 	unsigned count = 0;
diff --git a/tools/testing/selftests/powerpc/tm/tm.h b/tools/testing/selftests/powerpc/tm/tm.h
new file mode 100644
index 000000000000..24144b25772c
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2015, Michael Ellerman, IBM Corp.
+ * Licensed under GPLv2.
+ */
+
+#ifndef _SELFTESTS_POWERPC_TM_TM_H
+#define _SELFTESTS_POWERPC_TM_TM_H
+
+#include <stdbool.h>
+#include <asm/cputable.h>
+
+#include "../utils.h"
+
+static inline bool have_htm(void)
+{
+#ifdef PPC_FEATURE2_HTM
+	return have_hwcap2(PPC_FEATURE2_HTM);
+#else
+	printf("PPC_FEATURE2_HTM not defined, can't check AT_HWCAP2\n");
+	return false;
+#endif
+}
+
+static inline bool have_htm_nosc(void)
+{
+#ifdef PPC_FEATURE2_HTM_NOSC
+	return have_hwcap2(PPC_FEATURE2_HTM_NOSC);
+#else
+	printf("PPC_FEATURE2_HTM_NOSC not defined, can't check AT_HWCAP2\n");
+	return false;
+#endif
+}
+
+#endif /* _SELFTESTS_POWERPC_TM_TM_H */
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH 4/4] selftests/powerpc: Skip TM tests if we don't have TM
  2015-11-24  2:05 [PATCH 1/4] selftests/powerpc: Move get_auxv_entry() into utils.c Michael Ellerman
  2015-11-24  2:05 ` [PATCH 2/4] selftests/powerpc: Add have_hwcap2() helper Michael Ellerman
  2015-11-24  2:05 ` [PATCH 3/4] selftests/powerpc: Move TM helpers into tm.h Michael Ellerman
@ 2015-11-24  2:05 ` Michael Ellerman
  2015-12-15 11:27 ` [1/4] selftests/powerpc: Move get_auxv_entry() into utils.c Michael Ellerman
  3 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2015-11-24  2:05 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: Michael Neuling

Make the newly added TM tests skip if we don't have TM available, either
because we're running on old hardware, or the kernel doesn't have TM
support enabled.

Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
---
 tools/testing/selftests/powerpc/tm/Makefile             | 8 +++++---
 tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c | 3 +++
 tools/testing/selftests/powerpc/tm/tm-signal-stack.c    | 3 +++
 3 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index 3e6e7aaa5312..578572a3700a 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -2,10 +2,12 @@ TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack
 
 all: $(TEST_PROGS)
 
-$(TEST_PROGS): ../harness.c
+$(TEST_PROGS): ../harness.c ../utils.c
 
-tm-syscall: tm-syscall-asm.S ../utils.c
-tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include
+CFLAGS += -I../../../../../usr/include
+
+tm-syscall: tm-syscall-asm.S
+tm-syscall: CFLAGS += -mhtm
 
 include ../../lib.mk
 
diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c b/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c
index bdad34803c06..a6589582b780 100644
--- a/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c
+++ b/tools/testing/selftests/powerpc/tm/tm-signal-msr-resv.c
@@ -18,6 +18,7 @@
 #include <signal.h>
 #include <unistd.h>
 
+#include "tm.h"
 #include "utils.h"
 
 int segv_expected = 0;
@@ -49,6 +50,8 @@ int tm_signal_msr_resv()
 {
 	struct sigaction act;
 
+	SKIP_IF(!have_htm());
+
 	act.sa_sigaction = signal_usr1;
 	sigemptyset(&act.sa_mask);
 	act.sa_flags = SA_SIGINFO;
diff --git a/tools/testing/selftests/powerpc/tm/tm-signal-stack.c b/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
index 62f2a5f108c6..82c29cb222dc 100644
--- a/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
+++ b/tools/testing/selftests/powerpc/tm/tm-signal-stack.c
@@ -21,6 +21,7 @@
 #include <stdio.h>
 #include <signal.h>
 
+#include "tm.h"
 #include "utils.h"
 
 void signal_segv(int signum)
@@ -33,6 +34,8 @@ int tm_signal_stack()
 {
 	int pid;
 
+	SKIP_IF(!have_htm());
+
 	pid = fork();
 	if (pid < 0)
 		exit(1);
-- 
2.5.0

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [1/4] selftests/powerpc: Move get_auxv_entry() into utils.c
  2015-11-24  2:05 [PATCH 1/4] selftests/powerpc: Move get_auxv_entry() into utils.c Michael Ellerman
                   ` (2 preceding siblings ...)
  2015-11-24  2:05 ` [PATCH 4/4] selftests/powerpc: Skip TM tests if we don't have TM Michael Ellerman
@ 2015-12-15 11:27 ` Michael Ellerman
  3 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2015-12-15 11:27 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: Michael Neuling

On Tue, 2015-24-11 at 02:05:38 UTC, Michael Ellerman wrote:
> 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>

Applied to powerpc next.

https://git.kernel.org/powerpc/c/fcb45ec074725baeb3aaa1b1

cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [2/4] selftests/powerpc: Add have_hwcap2() helper
  2015-11-24  2:05 ` [PATCH 2/4] selftests/powerpc: Add have_hwcap2() helper Michael Ellerman
@ 2015-12-15 11:27   ` Michael Ellerman
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2015-12-15 11:27 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: Michael Neuling

On Tue, 2015-24-11 at 02:05:39 UTC, Michael Ellerman wrote:
> We already do this twice and want to add another so add a helper.
> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Applied to powerpc next.

https://git.kernel.org/powerpc/c/ede8ef3f824ea6e853a5e4b2

cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [3/4] selftests/powerpc: Move TM helpers into tm.h
  2015-11-24  2:05 ` [PATCH 3/4] selftests/powerpc: Move TM helpers into tm.h Michael Ellerman
@ 2015-12-15 11:27   ` Michael Ellerman
  0 siblings, 0 replies; 7+ messages in thread
From: Michael Ellerman @ 2015-12-15 11:27 UTC (permalink / raw)
  To: Michael Ellerman, linuxppc-dev; +Cc: Michael Neuling

On Tue, 2015-24-11 at 02:05:40 UTC, Michael Ellerman wrote:
> Move have_htm_nosc() into a new tm.h, and add a new helper, have_htm()
> which we'll use in the next patch.
> 
> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>

Applied to powerpc next.

https://git.kernel.org/powerpc/c/34dc8b279dc5dd3ce8632980

cheers

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2015-12-15 11:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-24  2:05 [PATCH 1/4] selftests/powerpc: Move get_auxv_entry() into utils.c Michael Ellerman
2015-11-24  2:05 ` [PATCH 2/4] selftests/powerpc: Add have_hwcap2() helper Michael Ellerman
2015-12-15 11:27   ` [2/4] " Michael Ellerman
2015-11-24  2:05 ` [PATCH 3/4] selftests/powerpc: Move TM helpers into tm.h Michael Ellerman
2015-12-15 11:27   ` [3/4] " Michael Ellerman
2015-11-24  2:05 ` [PATCH 4/4] selftests/powerpc: Skip TM tests if we don't have TM Michael Ellerman
2015-12-15 11:27 ` [1/4] selftests/powerpc: Move get_auxv_entry() into utils.c Michael Ellerman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.