aboutsummaryrefslogtreecommitdiffstats
path: root/tools/testing/selftests
diff options
context:
space:
mode:
authorCyril Bur <cyrilbur@gmail.com>2016-06-29 07:41:51 -0400
committerMichael Ellerman <mpe@ellerman.id.au>2016-07-26 00:28:22 -0400
commita431b946db581d6a121d035a887d370cdc4b8dea (patch)
treeb0b6a6c2049643a5920b8f2b3f63d9a3eecdb64a /tools/testing/selftests
parentdd57023747e33572b31867f890b0d99f55b5cc2f (diff)
selftests/powerpc: exec() with suspended transaction
Perform an exec() class syscall with a suspended transaction. This is a test for the bug we fixed in 8e96a87c5431 ("powerpc/tm: Always reclaim in start_thread() for exec() class syscalls"). Signed-off-by: Cyril Bur <cyrilbur@gmail.com> [mpe: Fix build errors, use a single binary for the test] Signed-off-by: Michael Ellerman <mpe@ellerman.id.au>
Diffstat (limited to 'tools/testing/selftests')
-rw-r--r--tools/testing/selftests/powerpc/tm/.gitignore1
-rw-r--r--tools/testing/selftests/powerpc/tm/Makefile7
-rw-r--r--tools/testing/selftests/powerpc/tm/tm-exec.c70
-rw-r--r--tools/testing/selftests/powerpc/tm/tm-syscall.c15
-rw-r--r--tools/testing/selftests/powerpc/tm/tm.h23
5 files changed, 98 insertions, 18 deletions
diff --git a/tools/testing/selftests/powerpc/tm/.gitignore b/tools/testing/selftests/powerpc/tm/.gitignore
index bb942db845bf..82c0a9ce6e74 100644
--- a/tools/testing/selftests/powerpc/tm/.gitignore
+++ b/tools/testing/selftests/powerpc/tm/.gitignore
@@ -6,3 +6,4 @@ tm-vmxcopy
6tm-fork 6tm-fork
7tm-tar 7tm-tar
8tm-tmspr 8tm-tmspr
9tm-exec
diff --git a/tools/testing/selftests/powerpc/tm/Makefile b/tools/testing/selftests/powerpc/tm/Makefile
index d0505dbd22d5..9d301d785d9e 100644
--- a/tools/testing/selftests/powerpc/tm/Makefile
+++ b/tools/testing/selftests/powerpc/tm/Makefile
@@ -1,11 +1,14 @@
1TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack tm-vmxcopy tm-fork tm-tar tm-tmspr 1TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
2 tm-vmxcopy tm-fork tm-tar tm-tmspr tm-exec tm-execed
2 3
3all: $(TEST_PROGS) 4all: $(TEST_PROGS)
4 5
5$(TEST_PROGS): ../harness.c ../utils.c 6$(TEST_PROGS): ../harness.c ../utils.c
6 7
8CFLAGS += -mhtm
9
7tm-syscall: tm-syscall-asm.S 10tm-syscall: tm-syscall-asm.S
8tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include 11tm-syscall: CFLAGS += -I../../../../../usr/include
9tm-tmspr: CFLAGS += -pthread 12tm-tmspr: CFLAGS += -pthread
10 13
11include ../../lib.mk 14include ../../lib.mk
diff --git a/tools/testing/selftests/powerpc/tm/tm-exec.c b/tools/testing/selftests/powerpc/tm/tm-exec.c
new file mode 100644
index 000000000000..3d27fa0ece04
--- /dev/null
+++ b/tools/testing/selftests/powerpc/tm/tm-exec.c
@@ -0,0 +1,70 @@
1/*
2 * Copyright 2016, Cyril Bur, IBM Corp.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version
7 * 2 of the License, or (at your option) any later version.
8 *
9 * Syscalls can be performed provided the transactions are suspended.
10 * The exec() class of syscall is unique as a new process is loaded.
11 *
12 * It makes little sense for after an exec() call for the previously
13 * suspended transaction to still exist.
14 */
15
16#define _GNU_SOURCE
17#include <errno.h>
18#include <inttypes.h>
19#include <libgen.h>
20#include <pthread.h>
21#include <stdio.h>
22#include <stdlib.h>
23#include <string.h>
24#include <unistd.h>
25
26#include "utils.h"
27#include "tm.h"
28
29static char *path;
30
31static int test_exec(void)
32{
33 SKIP_IF(!have_htm());
34
35 asm __volatile__(
36 "tbegin.;"
37 "blt 1f; "
38 "tsuspend.;"
39 "1: ;"
40 : : : "memory");
41
42 execl(path, "tm-exec", "--child", NULL);
43
44 /* Shouldn't get here */
45 perror("execl() failed");
46 return 1;
47}
48
49static int after_exec(void)
50{
51 asm __volatile__(
52 "tbegin.;"
53 "blt 1f;"
54 "tsuspend.;"
55 "1: ;"
56 : : : "memory");
57
58 FAIL_IF(failure_is_nesting());
59 return 0;
60}
61
62int main(int argc, char *argv[])
63{
64 path = argv[0];
65
66 if (argc > 1 && strcmp(argv[1], "--child") == 0)
67 return after_exec();
68
69 return test_harness(test_exec, "tm_exec");
70}
diff --git a/tools/testing/selftests/powerpc/tm/tm-syscall.c b/tools/testing/selftests/powerpc/tm/tm-syscall.c
index 60560cb20e38..454b965a2db3 100644
--- a/tools/testing/selftests/powerpc/tm/tm-syscall.c
+++ b/tools/testing/selftests/powerpc/tm/tm-syscall.c
@@ -27,21 +27,6 @@ unsigned retries = 0;
27#define TEST_DURATION 10 /* seconds */ 27#define TEST_DURATION 10 /* seconds */
28#define TM_RETRIES 100 28#define TM_RETRIES 100
29 29
30long failure_code(void)
31{
32 return __builtin_get_texasru() >> 24;
33}
34
35bool failure_is_persistent(void)
36{
37 return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT;
38}
39
40bool failure_is_syscall(void)
41{
42 return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
43}
44
45pid_t getppid_tm(bool suspend) 30pid_t getppid_tm(bool suspend)
46{ 31{
47 int i; 32 int i;
diff --git a/tools/testing/selftests/powerpc/tm/tm.h b/tools/testing/selftests/powerpc/tm/tm.h
index 24144b25772c..60318bad7d7a 100644
--- a/tools/testing/selftests/powerpc/tm/tm.h
+++ b/tools/testing/selftests/powerpc/tm/tm.h
@@ -6,8 +6,9 @@
6#ifndef _SELFTESTS_POWERPC_TM_TM_H 6#ifndef _SELFTESTS_POWERPC_TM_TM_H
7#define _SELFTESTS_POWERPC_TM_TM_H 7#define _SELFTESTS_POWERPC_TM_TM_H
8 8
9#include <stdbool.h> 9#include <asm/tm.h>
10#include <asm/cputable.h> 10#include <asm/cputable.h>
11#include <stdbool.h>
11 12
12#include "../utils.h" 13#include "../utils.h"
13 14
@@ -31,4 +32,24 @@ static inline bool have_htm_nosc(void)
31#endif 32#endif
32} 33}
33 34
35static inline long failure_code(void)
36{
37 return __builtin_get_texasru() >> 24;
38}
39
40static inline bool failure_is_persistent(void)
41{
42 return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT;
43}
44
45static inline bool failure_is_syscall(void)
46{
47 return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
48}
49
50static inline bool failure_is_nesting(void)
51{
52 return (__builtin_get_texasru() & 0x400000);
53}
54
34#endif /* _SELFTESTS_POWERPC_TM_TM_H */ 55#endif /* _SELFTESTS_POWERPC_TM_TM_H */