From: Thomas Gleixner <tglx@linutronix.de>
To: LKML <linux-kernel@vger.kernel.org>
Cc: Frederic Weisbecker <frederic@kernel.org>,
Anna-Maria Behnsen <anna-maria@linutronix.de>,
John Stultz <jstultz@google.com>,
Peter Zijlstra <peterz@infradead.org>,
Ingo Molnar <mingo@kernel.org>, Stephen Boyd <sboyd@kernel.org>,
Eric Biederman <ebiederm@xmission.com>,
Oleg Nesterov <oleg@redhat.com>
Subject: [patch 02/45] selftests/timers/posix_timers: Use TAP reporting format
Date: Tue, 6 Jun 2023 16:37:21 +0200 (CEST) [thread overview]
Message-ID: <20230606142031.130432648@linutronix.de> (raw)
In-Reply-To: <20230606132949.068951363@linutronix.de>
No functional change.
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
---
tools/testing/selftests/timers/posix_timers.c | 173 +++++++++-----------------
1 file changed, 65 insertions(+), 108 deletions(-)
--- a/tools/testing/selftests/timers/posix_timers.c
+++ b/tools/testing/selftests/timers/posix_timers.c
@@ -10,6 +10,7 @@
#include <sys/time.h>
#include <stdio.h>
#include <signal.h>
+#include <string.h>
#include <unistd.h>
#include <time.h>
#include <pthread.h>
@@ -19,6 +20,20 @@
#define DELAY 2
#define USECS_PER_SEC 1000000
+static void __fatal_error(const char *test, const char *name, const char *what)
+{
+ char buf[64];
+
+ strerror_r(errno, buf, sizeof(buf));
+
+ if (name && strlen(name))
+ ksft_exit_fail_msg("%s %s %s %s\n", test, name, what, buf);
+ else
+ ksft_exit_fail_msg("%s %s %s\n", test, what, buf);
+}
+
+#define fatal_error(name, what) __fatal_error(__func__, name, what)
+
static volatile int done;
/* Busy loop in userspace to elapse ITIMER_VIRTUAL */
@@ -66,15 +81,13 @@ static int check_diff(struct timeval sta
diff = end.tv_usec - start.tv_usec;
diff += (end.tv_sec - start.tv_sec) * USECS_PER_SEC;
- if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2) {
- printf("Diff too high: %lld..", diff);
+ if (abs(diff - DELAY * USECS_PER_SEC) > USECS_PER_SEC / 2)
return -1;
- }
return 0;
}
-static int check_itimer(int which)
+static void check_itimer(int which, const char *name)
{
int err;
struct timeval start, end;
@@ -82,17 +95,6 @@ static int check_itimer(int which)
.it_value.tv_sec = DELAY,
};
- printf("Check itimer ");
-
- if (which == ITIMER_VIRTUAL)
- printf("virtual... ");
- else if (which == ITIMER_PROF)
- printf("prof... ");
- else if (which == ITIMER_REAL)
- printf("real... ");
-
- fflush(stdout);
-
done = 0;
if (which == ITIMER_VIRTUAL)
@@ -103,16 +105,12 @@ static int check_itimer(int which)
signal(SIGALRM, sig_handler);
err = gettimeofday(&start, NULL);
- if (err < 0) {
- perror("Can't call gettimeofday()\n");
- return -1;
- }
+ if (err < 0)
+ fatal_error(name, "gettimeofday()");
err = setitimer(which, &val, NULL);
- if (err < 0) {
- perror("Can't set timer\n");
- return -1;
- }
+ if (err < 0)
+ fatal_error(name, "setitimer()");
if (which == ITIMER_VIRTUAL)
user_loop();
@@ -122,20 +120,16 @@ static int check_itimer(int which)
idle_loop();
err = gettimeofday(&end, NULL);
- if (err < 0) {
- perror("Can't call gettimeofday()\n");
- return -1;
- }
+ if (err < 0)
+ fatal_error(name, "gettimeofday()");
if (!check_diff(start, end))
- printf("[OK]\n");
+ ksft_test_result_pass("check_itimer %s\n", name);
else
- printf("[FAIL]\n");
-
- return 0;
+ ksft_test_result_fail("check_itimer %s\n", name);
}
-static int check_timer_create(int which)
+static void check_timer_create(int which, const char *name)
{
int err;
timer_t id;
@@ -144,48 +138,32 @@ static int check_timer_create(int which)
.it_value.tv_sec = DELAY,
};
- printf("Check timer_create() ");
- if (which == CLOCK_THREAD_CPUTIME_ID) {
- printf("per thread... ");
- } else if (which == CLOCK_PROCESS_CPUTIME_ID) {
- printf("per process... ");
- }
- fflush(stdout);
-
done = 0;
err = timer_create(which, NULL, &id);
- if (err < 0) {
- perror("Can't create timer\n");
- return -1;
- }
- signal(SIGALRM, sig_handler);
+ if (err < 0)
+ fatal_error(name, "timer_create()");
+
+ if (signal(SIGALRM, sig_handler) == SIG_ERR)
+ fatal_error(name, "signal()");
err = gettimeofday(&start, NULL);
- if (err < 0) {
- perror("Can't call gettimeofday()\n");
- return -1;
- }
+ if (err < 0)
+ fatal_error(name, "gettimeofday()");
err = timer_settime(id, 0, &val, NULL);
- if (err < 0) {
- perror("Can't set timer\n");
- return -1;
- }
+ if (err < 0)
+ fatal_error(name, "timer_settime()");
user_loop();
err = gettimeofday(&end, NULL);
- if (err < 0) {
- perror("Can't call gettimeofday()\n");
- return -1;
- }
+ if (err < 0)
+ fatal_error(name, "gettimeofday()");
if (!check_diff(start, end))
- printf("[OK]\n");
+ ksft_test_result_pass("check_timer_create %s\n", name);
else
- printf("[FAIL]\n");
-
- return 0;
+ ksft_test_result_fail("check_timer_create %s\n", name);
}
static int remain;
@@ -208,7 +186,7 @@ static void distribution_handler(int nr)
* Test that all running threads _eventually_ receive CLOCK_PROCESS_CPUTIME_ID
* timer signals. This primarily tests that the kernel does not favour any one.
*/
-static int check_timer_distribution(void)
+static void check_timer_distribution(void)
{
const int nthreads = 10;
pthread_t threads[nthreads];
@@ -222,28 +200,22 @@ static int check_timer_distribution(void
int err, i;
timer_t id;
- printf("Check timer_create() per process signal distribution... ");
- fflush(stdout);
-
done = 0;
remain = nthreads + 1; /* worker threads + this thread */
- signal(SIGALRM, distribution_handler);
+ if (signal(SIGALRM, distribution_handler) == SIG_ERR)
+ fatal_error(NULL, "signal()");
+
err = timer_create(CLOCK_PROCESS_CPUTIME_ID, NULL, &id);
- if (err < 0) {
- perror("Can't create timer\n");
- return -1;
- }
+ if (err < 0)
+ fatal_error(NULL, "timer_create()");
+
err = timer_settime(id, 0, &val, NULL);
- if (err < 0) {
- perror("Can't set timer\n");
- return -1;
- }
+ if (err < 0)
+ fatal_error(NULL, "timer_settime()");
for (i = 0; i < nthreads; i++) {
- if (pthread_create(&threads[i], NULL, distribution_thread, NULL)) {
- perror("Can't create thread\n");
- return -1;
- }
+ if (pthread_create(&threads[i], NULL, distribution_thread, NULL))
+ fatal_error(NULL, "pthread_create()");
}
/* Wait for all threads to receive the signal. */
@@ -255,41 +227,29 @@ static int check_timer_distribution(void
}
done = 1;
- if (timer_delete(id)) {
- perror("Can't delete timer\n");
- return -1;
- }
+ if (timer_delete(id))
+ fatal_error(NULL, "timer_delete()");
for (i = 0; i < nthreads; i++) {
- if (pthread_join(threads[i], NULL)) {
- perror("Can't join thread\n");
- return -1;
- }
+ if (pthread_join(threads[i], NULL))
+ fatal_error(NULL, "pthread_join()");
}
if (now - start <= 5)
- printf("[OK]\n");
+ ksft_test_result_pass("check_signal_distribution\n");
else
- printf("%d [FAIL]\n", got_signal);
- return 0;
+ ksft_test_result_fail("check_signal_distribution\n");
}
int main(int argc, char **argv)
{
- printf("Testing posix timers. False negative may happen on CPU execution \n");
- printf("based timers if other threads run on the CPU...\n");
-
- if (check_itimer(ITIMER_VIRTUAL) < 0)
- return ksft_exit_fail();
+ ksft_print_header();
+ ksft_set_plan(6);
- if (check_itimer(ITIMER_PROF) < 0)
- return ksft_exit_fail();
-
- if (check_itimer(ITIMER_REAL) < 0)
- return ksft_exit_fail();
-
- if (check_timer_create(CLOCK_THREAD_CPUTIME_ID) < 0)
- return ksft_exit_fail();
+ check_itimer(ITIMER_VIRTUAL, "ITIMER_VIRTUAL");
+ check_itimer(ITIMER_PROF, "ITIMER_PROF");
+ check_itimer(ITIMER_REAL, "ITIMER_REAL");
+ check_timer_create(CLOCK_THREAD_CPUTIME_ID, "CLOCK_THREAD_CPUTIME_ID");
/*
* It's unfortunately hard to reliably test a timer expiration
@@ -300,11 +260,8 @@ int main(int argc, char **argv)
* to ensure true parallelism. So test only one thread until we
* find a better solution.
*/
- if (check_timer_create(CLOCK_PROCESS_CPUTIME_ID) < 0)
- return ksft_exit_fail();
-
- if (check_timer_distribution() < 0)
- return ksft_exit_fail();
+ check_timer_create(CLOCK_PROCESS_CPUTIME_ID, "CLOCK_PROCESS_CPUTIME_ID");
+ check_timer_distribution();
- return ksft_exit_pass();
+ ksft_finished();
}
next prev parent reply other threads:[~2023-06-06 14:37 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-06 14:37 [patch 00/45] posix-timers: Cure inconsistencies and the SIG_IGN mess Thomas Gleixner
2023-06-06 14:37 ` [patch 01/45] selftests/timers/posix_timers: Make signal distribution test less fragile Thomas Gleixner
2023-06-06 14:37 ` Thomas Gleixner [this message]
2023-06-06 14:37 ` [patch 03/45] selftests/timers/posix_timers: Add SIG_IGN test Thomas Gleixner
2023-06-06 14:37 ` [patch 04/45] selftests/timers/posix_timers: Validate signal rules Thomas Gleixner
2023-06-06 14:37 ` [patch 05/45] selftests/timers/posix-timers: Validate SIGEV_NONE Thomas Gleixner
2023-06-06 14:37 ` [patch 06/45] selftests/timers/posix-timers: Validate timer_gettime() Thomas Gleixner
2023-06-06 14:37 ` [patch 07/45] selftests/timers/posix-timers: Validate overrun after unblock Thomas Gleixner
2023-06-06 14:37 ` [patch 08/45] posix-timers: Convert timer list to hlist Thomas Gleixner
2023-06-22 21:18 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 09/45] posix-cpu-timers: Fix posix_cpu_timer_get() behaviour Thomas Gleixner
2023-06-26 22:46 ` Frederic Weisbecker
2023-06-29 18:14 ` Thomas Gleixner
2023-06-06 14:37 ` [patch 10/45] posix-cpu-timers: Use @now instead of @val for clarity Thomas Gleixner
2023-06-27 9:53 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 11/45] posix-cpu-timers: Remove incorrect comment in posix_cpu_timer_set() Thomas Gleixner
2023-06-27 10:30 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 12/45] posix-cpu-timers: Simplify posix_cpu_timer_set() Thomas Gleixner
2023-06-27 10:51 ` Frederic Weisbecker
2023-06-29 18:43 ` Thomas Gleixner
2023-06-06 14:37 ` [patch 13/45] posix-cpu-timers: Replace old expiry retrieval in posix_cpu_timer_set() Thomas Gleixner
2023-06-27 11:32 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 14/45] posix-timers: Consolidate interval retrieval Thomas Gleixner
2023-06-28 13:08 ` Frederic Weisbecker
2023-06-29 18:47 ` Thomas Gleixner
2023-06-30 11:25 ` Frederic Weisbecker
2023-06-30 13:07 ` Thomas Gleixner
2023-06-30 14:04 ` Frederic Weisbecker
2023-07-01 18:01 ` Thomas Gleixner
2023-06-06 14:37 ` [patch 15/45] posix-timers: Clear overrun in common_timer_set() Thomas Gleixner
2023-06-30 21:40 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 16/45] posix-timers: Consolidate timer setup Thomas Gleixner
2023-07-03 21:12 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 17/45] posix-cpu-timers: Make k_itimer::it_active consistent Thomas Gleixner
2023-07-03 22:30 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 18/45] posix-timers: Consolidate signal queueing Thomas Gleixner
2023-07-03 22:51 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 19/45] signal: Remove task argument from dequeue_signal() Thomas Gleixner
2023-07-04 10:02 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 20/45] signal: Replace BUG_ON()s Thomas Gleixner
2023-07-04 10:24 ` Frederic Weisbecker
2023-06-06 14:37 ` [patch 21/45] signal: Confine POSIX_TIMERS properly Thomas Gleixner
2023-06-06 14:37 ` [patch 22/45] signal: Get rid of resched_timer logic Thomas Gleixner
2023-06-06 14:37 ` [patch 23/45] posix-timers: Cure si_sys_private race Thomas Gleixner
2023-06-06 14:37 ` [patch 24/45] signal: Allow POSIX timer signals to be dropped Thomas Gleixner
2023-06-06 14:37 ` [patch 25/45] posix-timers: Drop signal if timer has been deleted or reprogrammed Thomas Gleixner
2023-06-06 14:38 ` [patch 26/45] posix-timers: Rename k_itimer::it_requeue_pending Thomas Gleixner
2023-06-06 14:38 ` [patch 27/45] posix-timers: Add proper state tracking Thomas Gleixner
2023-06-06 14:38 ` [patch 28/45] posix-timers: Make signal delivery consistent Thomas Gleixner
2023-06-06 14:38 ` [patch 29/45] posix-timers: Make signal overrun accounting sensible Thomas Gleixner
2023-06-06 14:38 ` [patch 30/45] posix-cpu-timers: Use dedicated flag for CPU timer nanosleep Thomas Gleixner
2023-06-06 14:38 ` [patch 31/45] posix-timers: Add a refcount to struct k_itimer Thomas Gleixner
2023-06-06 14:38 ` [patch 32/45] signal: Split up __sigqueue_alloc() Thomas Gleixner
2023-06-06 14:38 ` [patch 33/45] signal: Provide posixtimer_sigqueue_init() Thomas Gleixner
2023-06-06 14:38 ` [patch 34/45] signal: Add sys_private_ptr to siginfo::_sifields::_timer Thomas Gleixner
2023-06-06 14:38 ` [patch 35/45] signal: Refactor send_sigqueue() Thomas Gleixner
2023-06-06 14:38 ` [patch 36/45] posix-timers: Embed sigqueue in struct k_itimer Thomas Gleixner
2023-06-06 14:38 ` [patch 37/45] signal: Cleanup unused posix-timer leftovers Thomas Gleixner
2023-06-06 14:38 ` [patch 38/45] signal: Add task argument to flush_sigqueue_mask() Thomas Gleixner
2023-06-06 14:38 ` [patch 39/45] signal: Provide ignored_posix_timers list Thomas Gleixner
2023-06-06 14:38 ` [patch 40/45] posix-timers: Handle ignored list on delete and exit Thomas Gleixner
2023-06-06 14:38 ` [patch 41/45] signal: Handle ignored signals in do_sigaction(action != SIG_IGN) Thomas Gleixner
2023-06-06 14:38 ` [patch 42/45] signal: Queue ignored posixtimers on ignore list Thomas Gleixner
2023-06-06 14:38 ` [patch 43/45] posix-timers: Cleanup SIG_IGN workaround leftovers Thomas Gleixner
2023-06-06 14:38 ` [patch 44/45] alarmtimers: Remove the throttle mechanism from alarm_forward_now() Thomas Gleixner
2023-06-06 14:38 ` [patch 45/45] alarmtimers: Remove return value from alarm functions Thomas Gleixner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230606142031.130432648@linutronix.de \
--to=tglx@linutronix.de \
--cc=anna-maria@linutronix.de \
--cc=ebiederm@xmission.com \
--cc=frederic@kernel.org \
--cc=jstultz@google.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=oleg@redhat.com \
--cc=peterz@infradead.org \
--cc=sboyd@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®