1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright 2015, Sam Bobroff, IBM Corp.
5 * Test the kernel's system call code to ensure that a system call
6 * made from within an active HTM transaction is aborted with the
7 * correct failure code.
8 * Conversely, ensure that a system call made from within a
9 * suspended transaction can succeed.
14 #include <sys/syscall.h>
22 extern int getppid_tm_active(void);
23 extern int getppid_tm_suspended(void);
27 #define TEST_DURATION 10 /* seconds */
29 pid_t getppid_tm(bool suspend)
34 for (i = 0; i < TM_RETRIES; i++) {
36 pid = getppid_tm_suspended();
38 pid = getppid_tm_active();
43 if (failure_is_persistent()) {
44 if (failure_is_syscall())
47 printf("Unexpected persistent transaction failure.\n");
48 printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n",
49 __builtin_get_texasr(), __builtin_get_tfiar());
56 printf("Exceeded limit of %d temporary transaction failures.\n", TM_RETRIES);
57 printf("TEXASR 0x%016lx, TFIAR 0x%016lx.\n",
58 __builtin_get_texasr(), __builtin_get_tfiar());
66 struct timeval end, now;
68 SKIP_IF(!have_htm_nosc());
69 SKIP_IF(htm_is_synthetic());
73 printf("Testing transactional syscalls for %d seconds...\n", TEST_DURATION);
75 gettimeofday(&end, NULL);
76 now.tv_sec = TEST_DURATION;
78 timeradd(&end, &now, &end);
80 for (count = 0; timercmp(&now, &end, <); count++) {
82 * Test a syscall within a suspended transaction and verify
85 FAIL_IF(getppid_tm(true) == -1); /* Should succeed. */
88 * Test a syscall within an active transaction and verify that
89 * it fails with the correct failure code.
91 FAIL_IF(getppid_tm(false) != -1); /* Should fail... */
92 FAIL_IF(!failure_is_persistent()); /* ...persistently... */
93 FAIL_IF(!failure_is_syscall()); /* ...with code syscall. */
94 gettimeofday(&now, 0);
97 printf("%d active and suspended transactions behaved correctly.\n", count);
98 printf("(There were %d transaction retries.)\n", retries);
105 return test_harness(tm_syscall, "tm_syscall");