Skip to content

Commit

Permalink
selftests/powerpc: exec() with suspended transaction
Browse files Browse the repository at this point in the history
Perform an exec() class syscall with a suspended transaction.

This is a test for the bug we fixed in 8e96a87 ("powerpc/tm: Always
reclaim in start_thread() for exec() class syscalls").

Signed-off-by: Cyril Bur <[email protected]>
[mpe: Fix build errors, use a single binary for the test]
Signed-off-by: Michael Ellerman <[email protected]>
  • Loading branch information
cyrilbur-ibm authored and mpe committed Jul 26, 2016
1 parent dd57023 commit a431b94
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 18 deletions.
1 change: 1 addition & 0 deletions tools/testing/selftests/powerpc/tm/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ tm-vmxcopy
tm-fork
tm-tar
tm-tmspr
tm-exec
7 changes: 5 additions & 2 deletions tools/testing/selftests/powerpc/tm/Makefile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack tm-vmxcopy tm-fork tm-tar tm-tmspr
TEST_PROGS := tm-resched-dscr tm-syscall tm-signal-msr-resv tm-signal-stack \
tm-vmxcopy tm-fork tm-tar tm-tmspr tm-exec tm-execed

all: $(TEST_PROGS)

$(TEST_PROGS): ../harness.c ../utils.c

CFLAGS += -mhtm

tm-syscall: tm-syscall-asm.S
tm-syscall: CFLAGS += -mhtm -I../../../../../usr/include
tm-syscall: CFLAGS += -I../../../../../usr/include
tm-tmspr: CFLAGS += -pthread

include ../../lib.mk
Expand Down
70 changes: 70 additions & 0 deletions tools/testing/selftests/powerpc/tm/tm-exec.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2016, Cyril Bur, IBM Corp.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* Syscalls can be performed provided the transactions are suspended.
* The exec() class of syscall is unique as a new process is loaded.
*
* It makes little sense for after an exec() call for the previously
* suspended transaction to still exist.
*/

#define _GNU_SOURCE
#include <errno.h>
#include <inttypes.h>
#include <libgen.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>

#include "utils.h"
#include "tm.h"

static char *path;

static int test_exec(void)
{
SKIP_IF(!have_htm());

asm __volatile__(
"tbegin.;"
"blt 1f; "
"tsuspend.;"
"1: ;"
: : : "memory");

execl(path, "tm-exec", "--child", NULL);

/* Shouldn't get here */
perror("execl() failed");
return 1;
}

static int after_exec(void)
{
asm __volatile__(
"tbegin.;"
"blt 1f;"
"tsuspend.;"
"1: ;"
: : : "memory");

FAIL_IF(failure_is_nesting());
return 0;
}

int main(int argc, char *argv[])
{
path = argv[0];

if (argc > 1 && strcmp(argv[1], "--child") == 0)
return after_exec();

return test_harness(test_exec, "tm_exec");
}
15 changes: 0 additions & 15 deletions tools/testing/selftests/powerpc/tm/tm-syscall.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,6 @@ unsigned retries = 0;
#define TEST_DURATION 10 /* seconds */
#define TM_RETRIES 100

long failure_code(void)
{
return __builtin_get_texasru() >> 24;
}

bool failure_is_persistent(void)
{
return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT;
}

bool failure_is_syscall(void)
{
return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
}

pid_t getppid_tm(bool suspend)
{
int i;
Expand Down
23 changes: 22 additions & 1 deletion tools/testing/selftests/powerpc/tm/tm.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
#ifndef _SELFTESTS_POWERPC_TM_TM_H
#define _SELFTESTS_POWERPC_TM_TM_H

#include <stdbool.h>
#include <asm/tm.h>
#include <asm/cputable.h>
#include <stdbool.h>

#include "../utils.h"

Expand All @@ -31,4 +32,24 @@ static inline bool have_htm_nosc(void)
#endif
}

static inline long failure_code(void)
{
return __builtin_get_texasru() >> 24;
}

static inline bool failure_is_persistent(void)
{
return (failure_code() & TM_CAUSE_PERSISTENT) == TM_CAUSE_PERSISTENT;
}

static inline bool failure_is_syscall(void)
{
return (failure_code() & TM_CAUSE_SYSCALL) == TM_CAUSE_SYSCALL;
}

static inline bool failure_is_nesting(void)
{
return (__builtin_get_texasru() & 0x400000);
}

#endif /* _SELFTESTS_POWERPC_TM_TM_H */

0 comments on commit a431b94

Please sign in to comment.