From patchwork Thu Jul 11 10:43:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1959214 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=ymd1XBaK; dkim=fail reason="signature verification failed" header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=P1dDOHPd; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.cz header.i=@suse.cz header.a=rsa-sha256 header.s=susede2_rsa header.b=ymd1XBaK; dkim=neutral header.d=suse.cz header.i=@suse.cz header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=P1dDOHPd; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WKWYp6LZVz1xqr for ; Thu, 11 Jul 2024 20:44:14 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 5E5DA3CBB49 for ; Thu, 11 Jul 2024 12:44:12 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 780F43C21C7 for ; Thu, 11 Jul 2024 12:44:09 +0200 (CEST) Authentication-Results: in-6.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.cz (client-ip=195.135.223.131; helo=smtp-out2.suse.de; envelope-from=pvorel@suse.cz; receiver=lists.linux.it) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id CF5FA14010C2 for ; Thu, 11 Jul 2024 12:44:08 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id C36FE1F8BE; Thu, 11 Jul 2024 10:44:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1720694647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lj8XuX46LdW2LurCCm6u3IaSAAlraAEQKWFQfzb5eKo=; b=ymd1XBaK2odRRhhdVcozD8ZbDBdmEcR9yDDtn4R8neDd9alfj+C+ryCb6l/xxq+zhmCt+r mCsEAOnUvrY/0f9rwZbsczWRs7tQPJIcU1yuzTa6JHZqNV/tKo4UfhHE9CmfOeaJ0HsW4+ EDfnw6dqGzhHp6UD/aByOpw9tl+5uLw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1720694647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lj8XuX46LdW2LurCCm6u3IaSAAlraAEQKWFQfzb5eKo=; b=P1dDOHPdZ01S/kH6yOklkXROxu5roi69m3FZR8VSfUliF6IoJ1D7FUQuk5UmzlYWgP/fqD Fu2247BBx11zkcCQ== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1720694647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lj8XuX46LdW2LurCCm6u3IaSAAlraAEQKWFQfzb5eKo=; b=ymd1XBaK2odRRhhdVcozD8ZbDBdmEcR9yDDtn4R8neDd9alfj+C+ryCb6l/xxq+zhmCt+r mCsEAOnUvrY/0f9rwZbsczWRs7tQPJIcU1yuzTa6JHZqNV/tKo4UfhHE9CmfOeaJ0HsW4+ EDfnw6dqGzhHp6UD/aByOpw9tl+5uLw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1720694647; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=lj8XuX46LdW2LurCCm6u3IaSAAlraAEQKWFQfzb5eKo=; b=P1dDOHPdZ01S/kH6yOklkXROxu5roi69m3FZR8VSfUliF6IoJ1D7FUQuk5UmzlYWgP/fqD Fu2247BBx11zkcCQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id A94F3136AF; Thu, 11 Jul 2024 10:44:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id 9QOcKHe3j2bUSgAAD6G6ig (envelope-from ); Thu, 11 Jul 2024 10:44:07 +0000 From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 11 Jul 2024 12:43:57 +0200 Message-ID: <20240711104400.63355-1-pvorel@suse.cz> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spamd-Result: default: False [-2.80 / 50.00]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.999]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; DKIM_SIGNED(0.00)[suse.cz:s=susede2_rsa,suse.cz:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.cz:email,imap1.dmz-prg2.suse.org:helo]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -2.80 X-Spam-Level: X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [RFC PATCH 1/2] realtime: Use offsetof() macro from X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Stultz Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" offsetof() macro from which uses __builtin_offsetof() should be equivalent to the LTP custom implementation. The replacement is required due sched_football.c rewrite into new API (LTP library uses , thus there is a redefinition). Signed-off-by: Petr Vorel Reviewed-by: Cyril Hrubis --- testcases/realtime/include/list.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/testcases/realtime/include/list.h b/testcases/realtime/include/list.h index f87d602e4a..01159e34fc 100644 --- a/testcases/realtime/include/list.h +++ b/testcases/realtime/include/list.h @@ -39,6 +39,8 @@ #ifndef _LINUX_LIST_H #define _LINUX_LIST_H +#include + /* * These are non-NULL pointers that will result in page faults * under normal circumstances, used to verify that nobody uses @@ -241,7 +243,6 @@ static inline void list_splice_init(struct list_head *list, } } -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) /** * container_of - cast a member of a structure out to the containing structure * @ptr: the pointer to the member. From patchwork Thu Jul 11 10:43:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Petr Vorel X-Patchwork-Id: 1959215 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4WKWZD3tsKz1xqr for ; Thu, 11 Jul 2024 20:44:36 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 656283CE11A for ; Thu, 11 Jul 2024 12:44:34 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [217.194.8.6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 2AFAB3C21C7 for ; Thu, 11 Jul 2024 12:44:10 +0200 (CEST) Authentication-Results: in-6.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.cz (client-ip=2a07:de40:b251:101:10:150:64:1; helo=smtp-out1.suse.de; envelope-from=pvorel@suse.cz; receiver=lists.linux.it) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2a07:de40:b251:101:10:150:64:1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id 2654C14010CB for ; Thu, 11 Jul 2024 12:44:08 +0200 (CEST) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id E919021A7E; Thu, 11 Jul 2024 10:44:07 +0000 (UTC) Authentication-Results: smtp-out1.suse.de; none Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id C3282139E7; Thu, 11 Jul 2024 10:44:07 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id qEU4L3e3j2bUSgAAD6G6ig (envelope-from ); Thu, 11 Jul 2024 10:44:07 +0000 From: Petr Vorel To: ltp@lists.linux.it Date: Thu, 11 Jul 2024 12:43:58 +0200 Message-ID: <20240711104400.63355-2-pvorel@suse.cz> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240711104400.63355-1-pvorel@suse.cz> References: <20240711104400.63355-1-pvorel@suse.cz> MIME-Version: 1.0 X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Rspamd-Queue-Id: E919021A7E X-Spam-Score: -4.00 X-Rspamd-Action: no action X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Pre-Result: action=no action; module=replies; Message is reply to one we originated X-Spamd-Result: default: False [-4.00 / 50.00]; REPLY(-4.00)[] X-Spam-Level: X-Spam-Status: No, score=0.0 required=7.0 tests=SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [RFC PATCH 2/2] sched_football: Rewrite into new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: John Stultz Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This is due test compilation broken on old gcc 4.8 we still support since 8fc3cf4ad6. Combining LTP librealtime (librttest.c) and LTP library is somehow experimental. -lltp was needed to be added to CFLAGS but yet on musl it fails to find the function on runtime: tst_test.c:985: TBROK: No test function specified librttest.c getopts were ignored, port just test specific -l and -n. Fixes: 8fc3cf4ad6 ("sched_football: Re-add the crazy fans to interrupt everyone") Signed-off-by: Petr Vorel Reviewed-by: Cyril Hrubis --- .../realtime/func/sched_football/Makefile | 1 + .../func/sched_football/sched_football.c | 196 +++++++----------- 2 files changed, 81 insertions(+), 116 deletions(-) diff --git a/testcases/realtime/func/sched_football/Makefile b/testcases/realtime/func/sched_football/Makefile index 61753f0309..f194c2fbfc 100644 --- a/testcases/realtime/func/sched_football/Makefile +++ b/testcases/realtime/func/sched_football/Makefile @@ -25,4 +25,5 @@ top_srcdir ?= ../../../.. INSTALL_TARGETS := run_auto.sh include $(top_srcdir)/include/mk/env_pre.mk include $(abs_srcdir)/../../config.mk +LDLIBS += -lltp include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/realtime/func/sched_football/sched_football.c b/testcases/realtime/func/sched_football/sched_football.c index b6ae692af7..a3e4cbb344 100644 --- a/testcases/realtime/func/sched_football/sched_football.c +++ b/testcases/realtime/func/sched_football/sched_football.c @@ -1,62 +1,37 @@ -/****************************************************************************** +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright © International Business Machines Corp., 2007, 2008 + * Copyright (c) 2024 Petr Vorel + * Author: John Stultz + */ + +/*\ + * [Description] * - * Copyright © International Business Machines Corp., 2007, 2008 + * Scheduler test that uses a football analogy. * - * 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. + * The premise is that we want to make sure that lower priority threads + * don't run while we have runnable higher priority threads. + * The offense is trying to increment the balls position, while the + * defense is trying to block that from happening. + * And the ref (highest priority thread) will blow the wistle if the + * ball moves. Finally, we have crazy fans (higer prority) that try to + * distract the defense by occasionally running onto the field. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. + * [Algorithm] * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * NAME - * sched_football.c - * - * DESCRIPTION - * This is a scheduler test that uses a football analogy. - * The premise is that we want to make sure that lower priority threads - * don't run while we have runnable higher priority threads. - * The offense is trying to increment the balls position, while the - * defense is trying to block that from happening. - * And the ref (highest priority thread) will blow the wistle if the - * ball moves. Finally, we have crazy fans (higer prority) that try to - * distract the defense by occasionally running onto the field. - * - * Steps: - * - Create NR_CPU offense threads (lower priority) - * - Create NR_CPU defense threads (mid priority) - * - Create 2*NR_CPU fan threads (high priority) - * - Create a referee thread (highest priority) - * - Once everyone is on the field, the offense thread spins incrementing - * the value of 'the_ball'. The defense thread tries to block the ball - * by never letting the offense players get the CPU (it just spins). - * The crazy fans sleep a bit, then jump the rail and run across the - * field, disrupting the players on the field. - * - The refree threads wakes up regularly to check if the game is over :) - * - In the end, if the value of 'the_ball' is >0, the test is considered - * to have failed. - * - * USAGE: - * Use run_auto.sh script in current directory to build and run test. - * - * AUTHOR - * John Stultz - * - * HISTORY - * 2006-03-16 Reduced verbosity, non binary failure reporting, removal of - * crazy_fans thread, added game_length argument by Darren Hart. - * 2007-08-01 Remove all thread cleanup in favor of simply exiting.Various - * bugfixes and cleanups. -- Josh Triplett - * 2009-06-23 Simplified atomic startup mechanism, avoiding thundering herd - * scheduling at the beginning of the game. -- Darren Hart - *****************************************************************************/ + * - Create NR_CPU offense threads (lower priority). + * - Create NR_CPU defense threads (mid priority). + * - Create 2*NR_CPU fan threads (high priority). + * - Create a referee thread (highest priority). + * - Once everyone is on the field, the offense thread spins incrementing + * the value of ball. The defense thread tries to block the ball + * by never letting the offense players get the CPU (it just spins). + * The crazy fans sleep a bit, then jump the rail and run across the + * field, disrupting the players on the field. + * - The refree threads wakes up regularly to check if the game is over :). + * - If the value of ball is > 0, the test is considered to have failed. + */ #include #include @@ -71,55 +46,25 @@ #include #include #include -#include #include -#define TST_NO_DEFAULT_MAIN #include - +#include "librttest.h" +#include "tst_test.h" #define DEF_GAME_LENGTH 5 +#define SPIN_TIME_NS 200000000ULL +#define SLEEP_TIME_NS 50000000ULL -/* Here's the position of the ball */ -static int the_ball; - +static int ball; static int players_per_team = 0; static int game_length = DEF_GAME_LENGTH; static int players_ready; -void usage(void) -{ - rt_help(); - printf("sched_football specific options:\n"); - printf(" -nPLAYERS players per team (defaults to num_cpus)\n"); - printf(" -lGAME_LENGTH game length in seconds (defaults to %d s)\n", - DEF_GAME_LENGTH); -} - -int parse_args(int c, char *v) -{ +static char *str_game_length; +static char *str_players_per_team; - int handled = 1; - switch (c) { - case 'h': - usage(); - exit(0); - case 'n': - players_per_team = atoi(v); - break; - case 'l': - game_length = atoi(v); - break; - default: - handled = 0; - break; - } - return handled; -} - -#define SPIN_TIME_NS 200000000ULL -#define SLEEP_TIME_NS 50000000ULL /* These are fans running across the field. They're trying to interrupt/distract everyone */ -void *thread_fan(void *arg) +void *thread_fan(void *arg LTP_ATTRIBUTE_UNUSED) { prctl(PR_SET_NAME, "crazy_fan", 0, 0, 0); tst_atomic_add_return(1, &players_ready); @@ -139,38 +84,43 @@ void *thread_fan(void *arg) nsec = tst_timespec_diff_ns(stop, start); } } + return NULL; } /* This is the defensive team. They're trying to block the offense */ -void *thread_defense(void *arg) +void *thread_defense(void *arg LTP_ATTRIBUTE_UNUSED) { prctl(PR_SET_NAME, "defense", 0, 0, 0); tst_atomic_add_return(1, &players_ready); /*keep the ball from being moved */ while (1) { } + return NULL; } /* This is the offensive team. They're trying to move the ball */ -void *thread_offense(void *arg) +void *thread_offense(void *arg LTP_ATTRIBUTE_UNUSED) { prctl(PR_SET_NAME, "offense", 0, 0, 0); tst_atomic_add_return(1, &players_ready); while (1) { - tst_atomic_add_return(1, &the_ball); /* move the ball ahead one yard */ + tst_atomic_add_return(1, &ball); /* move the ball ahead one yard */ } + return NULL; } -int referee(int game_length) +void referee(int game_length) { struct timeval start, now; int final_ball; + tst_res(TINFO, "Starting referee thread"); + prctl(PR_SET_NAME, "referee", 0, 0, 0); - printf("Game On (%d seconds)!\n", game_length); + tst_res(TINFO, "Starting the game (%d sec)", game_length); /* open trace marker early to avoid latency with the first message */ trace_marker_prep(); @@ -178,7 +128,7 @@ int referee(int game_length) now = start; /* Start the game! */ - tst_atomic_store(0, &the_ball); + tst_atomic_store(0, &ball); atrace_marker_write("sched_football", "Game_started!"); /* Watch the game */ @@ -187,29 +137,26 @@ int referee(int game_length) gettimeofday(&now, NULL); } atrace_marker_write("sched_football", "Game_Over!"); - final_ball = tst_atomic_load(&the_ball); + final_ball = tst_atomic_load(&ball); + /* Blow the whistle */ - printf("Game Over!\n"); - printf("Final ball position: %d\n", final_ball); - return final_ball != 0; + tst_res(TINFO, "Final ball position: %d", final_ball); + + TST_EXP_EXPR(final_ball == 0); } -int main(int argc, char *argv[]) +static void do_test(void) { struct sched_param param; int priority; int i; - int result; - setup(); - - rt_init("n:l:h", parse_args, argc, argv); if (players_per_team == 0) players_per_team = sysconf(_SC_NPROCESSORS_ONLN); tst_atomic_store(0, &players_ready); - printf("Running with: players_per_team=%d game_length=%d\n", + tst_res(TINFO, "players_per_team: %d game_length: %d", players_per_team, game_length); /* We're the ref, so set our priority right */ @@ -221,7 +168,7 @@ int main(int argc, char *argv[]) * They are lower priority than defense, so they must be started first. */ priority = 15; - printf("Starting %d offense threads at priority %d\n", + tst_res(TINFO, "Starting %d offense threads at priority %d", players_per_team, priority); for (i = 0; i < players_per_team; i++) create_fifo_thread(thread_offense, NULL, priority); @@ -232,7 +179,7 @@ int main(int argc, char *argv[]) /* Start the defense */ priority = 30; - printf("Starting %d defense threads at priority %d\n", + tst_res(TINFO, "Starting %d defense threads at priority %d", players_per_team, priority); for (i = 0; i < players_per_team; i++) create_fifo_thread(thread_defense, NULL, priority); @@ -243,7 +190,7 @@ int main(int argc, char *argv[]) /* Start the crazy fans*/ priority = 50; - printf("Starting %d fan threads at priority %d\n", + tst_res(TINFO, "Starting %d fan threads at priority %d", players_per_team, priority); for (i = 0; i < players_per_team*2; i++) create_fifo_thread(thread_fan, NULL, priority); @@ -255,9 +202,26 @@ int main(int argc, char *argv[]) /* let things get into steady state */ sleep(2); /* Ok, everyone is on the field, bring out the ref */ - printf("Starting referee thread\n"); - result = referee(game_length); - printf("Result: %s\n", result ? "FAIL" : "PASS"); - return result; + referee(game_length); } + +static void do_setup(void) +{ + if (tst_parse_int(str_game_length, &game_length, 1, INT_MAX)) + tst_brk(TBROK, "Invalid game length '%s'", str_game_length); + + if (tst_parse_int(str_players_per_team, &players_per_team, 1, INT_MAX)) + tst_brk(TBROK, "Invalid number of players '%s'", str_players_per_team); +} + +static struct tst_test test = { + .test_all = do_test, + .setup = do_setup, + .options = (struct tst_option[]) { + {"l:", &str_game_length, "Game length in sec (default: " + TST_TO_STR(DEF_GAME_LENGTH) " sec)"}, + {"n:", &str_players_per_team, "Number of players (default: number of CPU)"}, + {} + }, +};