linux/tools/testing/selftests/powerpc/tm/tm-exec.c
<<
>>
Prefs
   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}
  71