From patchwork Thu Mar 16 07:22:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Gao X-Patchwork-Id: 1757741 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=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=QN3Letdp; dkim-atps=neutral Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4PcdyZ18t2z1yWs for ; Thu, 16 Mar 2023 18:23:02 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 035683CD48A for ; Thu, 16 Mar 2023 08:23:00 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id A03FD3CD46B for ; Thu, 16 Mar 2023 08:22:48 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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-2.smtp.seeweb.it (Postfix) with ESMTPS id 1C4FF6013A0 for ; Thu, 16 Mar 2023 08:22:47 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id A083E1FDEC; Thu, 16 Mar 2023 07:22:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1678951367; 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: in-reply-to:in-reply-to:references:references; bh=Jt8DoljBpYvFNkNLf79z5HQPlF3TpcCBa6jpaprfEd8=; b=QN3LetdpHoOgCa17doM6YFV7Xyp4+/LFn2hRF1LEgXFUXJLs1Aqa/EbqABRFJBKsxNgUrv +TWaNAP6tgT+uEsV/dNTjHZldd7ZjznIXFFtpxztJ/ENFgPnYFaA4W/8de6dLlKUtY9vq5 OCapb+ex+n8SOeuGjHE14J14B5Ei77k= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id F2F6A133E0; Thu, 16 Mar 2023 07:22:46 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id +DmTMMbDEmTiAQAAMHmgww (envelope-from ); Thu, 16 Mar 2023 07:22:46 +0000 To: ltp@lists.linux.it Date: Thu, 16 Mar 2023 03:22:30 -0400 Message-Id: <20230316072231.19157-2-wegao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230316072231.19157-1-wegao@suse.com> References: <20230302071555.18420-1-wegao@suse.com> <20230316072231.19157-1-wegao@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean 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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v4 1/2] Move semaphore/ tests to semop/ 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: , X-Patchwork-Original-From: Wei Gao via ltp From: Wei Gao Reply-To: Wei Gao Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" There is no point in having two different directories with semop() testcaes so it would make sense to move these two tests into the syscalls/ipc/semop/ directory as semop04 and semop05. So we move ipc/semaphore/ tests to syscalls/ipc/semop/. Also update runtest files accordingly. Signed-off-by: Wei Gao --- runtest/ipc | 2 -- runtest/syscalls | 2 ++ testcases/kernel/ipc/semaphore/.gitignore | 2 -- testcases/kernel/ipc/semaphore/Makefile | 30 ------------------- .../kernel/syscalls/ipc/semop/.gitignore | 2 ++ testcases/kernel/syscalls/ipc/semop/Makefile | 5 +++- .../sem01.c => syscalls/ipc/semop/semop04.c} | 0 .../sem02.c => syscalls/ipc/semop/semop05.c} | 0 8 files changed, 8 insertions(+), 35 deletions(-) delete mode 100644 testcases/kernel/ipc/semaphore/.gitignore delete mode 100644 testcases/kernel/ipc/semaphore/Makefile rename testcases/kernel/{ipc/semaphore/sem01.c => syscalls/ipc/semop/semop04.c} (100%) rename testcases/kernel/{ipc/semaphore/sem02.c => syscalls/ipc/semop/semop05.c} (100%) diff --git a/runtest/ipc b/runtest/ipc index a2135ed80..db7f7bed5 100644 --- a/runtest/ipc +++ b/runtest/ipc @@ -28,5 +28,3 @@ pipeio_8 pipeio -T pipeio_8 -c 5 -s 5000 -i 10 -u -f x80 # spawns 5 children to write 10 chunks of 5000 bytes to an unnamed pipe # using non-blocking I/O -sem01 sem01 -sem02 sem02 diff --git a/runtest/syscalls b/runtest/syscalls index ae37a1192..54cbc6ece 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1239,6 +1239,8 @@ semget06 semget06 semop01 semop01 semop02 semop02 semop03 semop03 +semop04 semop04 +semop05 semop05 send01 send01 send02 send02 diff --git a/testcases/kernel/ipc/semaphore/.gitignore b/testcases/kernel/ipc/semaphore/.gitignore deleted file mode 100644 index 944e5ca1e..000000000 --- a/testcases/kernel/ipc/semaphore/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -/sem01 -/sem02 diff --git a/testcases/kernel/ipc/semaphore/Makefile b/testcases/kernel/ipc/semaphore/Makefile deleted file mode 100644 index 9ab85745d..000000000 --- a/testcases/kernel/ipc/semaphore/Makefile +++ /dev/null @@ -1,30 +0,0 @@ -# -# testcases/kernel/ipc/semaphore Makefile. -# -# Copyright (C) 2009, Cisco Systems Inc. -# -# 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. -# -# 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. -# -# 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. -# -# Ngie Cooper, July 2009 -# - -top_srcdir ?= ../../../.. - -include $(top_srcdir)/include/mk/testcases.mk - -CPPFLAGS += -I../include -LDLIBS += -lpthread - -include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/semop/.gitignore b/testcases/kernel/syscalls/ipc/semop/.gitignore index bb57f08af..cc67b1862 100644 --- a/testcases/kernel/syscalls/ipc/semop/.gitignore +++ b/testcases/kernel/syscalls/ipc/semop/.gitignore @@ -1,3 +1,5 @@ /semop01 /semop02 /semop03 +/semop04 +/semop05 diff --git a/testcases/kernel/syscalls/ipc/semop/Makefile b/testcases/kernel/syscalls/ipc/semop/Makefile index 6b2b26d05..43afffb3f 100644 --- a/testcases/kernel/syscalls/ipc/semop/Makefile +++ b/testcases/kernel/syscalls/ipc/semop/Makefile @@ -7,6 +7,9 @@ LTPLIBS = ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -LTPLDLIBS = -lltpnewipc +semop01: LTPLDLIBS = -lltpnewipc +semop02: LTPLDLIBS = -lltpnewipc +semop03: LTPLDLIBS = -lltpnewipc +semop05: LDLIBS += -lpthread include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/ipc/semaphore/sem01.c b/testcases/kernel/syscalls/ipc/semop/semop04.c similarity index 100% rename from testcases/kernel/ipc/semaphore/sem01.c rename to testcases/kernel/syscalls/ipc/semop/semop04.c diff --git a/testcases/kernel/ipc/semaphore/sem02.c b/testcases/kernel/syscalls/ipc/semop/semop05.c similarity index 100% rename from testcases/kernel/ipc/semaphore/sem02.c rename to testcases/kernel/syscalls/ipc/semop/semop05.c From patchwork Thu Mar 16 07:22:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Gao X-Patchwork-Id: 1757742 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=) Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=kCIUomie; dkim-atps=neutral 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 (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pcdyp1vcyz1yWs for ; Thu, 16 Mar 2023 18:23:14 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E53683CD487 for ; Thu, 16 Mar 2023 08:23:11 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 3B4013CD451 for ; Thu, 16 Mar 2023 08:22:50 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (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-2.smtp.seeweb.it (Postfix) with ESMTPS id C1E4F6018B3 for ; Thu, 16 Mar 2023 08:22:49 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 7ADF51FE00; Thu, 16 Mar 2023 07:22:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1678951369; 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: in-reply-to:in-reply-to:references:references; bh=fjTRf3TZnB5ExEMvS/Ccu5GLdneJMlU+bKnJTwHZJ78=; b=kCIUomie0TBz6hi68bTClXU/5bYP+TPj3tYrRjZ4D9oZVpo9cVFc+HuVoq7/v1ClOowPGz FVLSrCrJkoxZq988W91qGnFCbSXkoaRI4OedMmmu9dioF8GPHptWfu144XlSx8ZJtQ8GSC Wy35r3I2mwNC1hDVe0hlXh3FZOG5Abo= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id D15B0133E0; Thu, 16 Mar 2023 07:22:48 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id sLroKcjDEmTiAQAAMHmgww (envelope-from ); Thu, 16 Mar 2023 07:22:48 +0000 To: ltp@lists.linux.it Date: Thu, 16 Mar 2023 03:22:31 -0400 Message-Id: <20230316072231.19157-3-wegao@suse.com> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20230316072231.19157-1-wegao@suse.com> References: <20230302071555.18420-1-wegao@suse.com> <20230316072231.19157-1-wegao@suse.com> MIME-Version: 1.0 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean 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 autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v4 2/2] semop04:Refactor with 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: , X-Patchwork-Original-From: Wei Gao via ltp From: Wei Gao Reply-To: Wei Gao Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Wei Gao --- testcases/kernel/syscalls/ipc/semop/semop04.c | 159 ++++++------------ 1 file changed, 56 insertions(+), 103 deletions(-) diff --git a/testcases/kernel/syscalls/ipc/semop/semop04.c b/testcases/kernel/syscalls/ipc/semop/semop04.c index 582624d60..589d9b0b4 100644 --- a/testcases/kernel/syscalls/ipc/semop/semop04.c +++ b/testcases/kernel/syscalls/ipc/semop/semop04.c @@ -1,36 +1,19 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (C) 2003-2023 Linux Test Project, Inc. + * Author: 2001 Paul Larson + * Modified: 2001 Manoj Iyer * - * Copyright (c) International Business Machines Corp., 2001 - * - * 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. - * - * 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. - * - * 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 */ -/* - * FILE : sem01.c - * DESCRIPTION : Creates a semaphore and two processes. The processes - * each go through a loop where they semdown, delay for a - * random amount of time, and semup, so they will almost - * always be fighting for control of the semaphore. - * HISTORY: - * 01/15/2001 Paul Larson (plars@us.ibm.com) - * -written - * 11/09/2001 Manoj Iyer (manjo@ausin.ibm.com) - * Modified. - * - Removed compiler warnings. - * added exit to the end of function main() +/*\ + * [Description] * + * Creates a semaphore and two processes. The processes + * each go through a loop where they semdown, delay for a + * random amount of time, and semup, so they will almost + * always be fighting for control of the semaphore. */ #include @@ -41,124 +24,94 @@ #include #include #include "lapi/sem.h" +#include "tst_test.h" +#include "tst_safe_sysv_ipc.h" -int verbose = 0; -int loops = 100; -int errors = 0; +static int loops = 100; +static char *opt_loops_str; -int semup(int semid) +static void semup(int semid) { struct sembuf semops; + semops.sem_num = 0; semops.sem_op = 1; semops.sem_flg = SEM_UNDO; - if (semop(semid, &semops, 1) == -1) { - perror("semup"); - errors++; - return 1; - } - return 0; + + SAFE_SEMOP(semid, &semops, 1); } -int semdown(int semid) +static void semdown(int semid) { struct sembuf semops; + semops.sem_num = 0; semops.sem_op = -1; semops.sem_flg = SEM_UNDO; - if (semop(semid, &semops, 1) == -1) { - perror("semdown"); - errors++; - return 1; - } - return 0; + + SAFE_SEMOP(semid, &semops, 1); } -void delayloop() +static void delayloop(void) { int delay; + delay = 1 + ((100.0 * rand()) / RAND_MAX); - if (verbose) - printf("in delay function for %d microseconds\n", delay); usleep(delay); } void mainloop(int semid) { int i; + for (i = 0; i < loops; i++) { - if (semdown(semid)) { - printf("semdown failed\n"); - } - if (verbose) - printf("sem is down\n"); + semdown(semid); delayloop(); - if (semup(semid)) { - printf("semup failed\n"); - } - if (verbose) - printf("sem is up\n"); + semup(semid); } } -int main(int argc, char *argv[]) +static void run(void) { - int semid, opt; + int semid; union semun semunion; - extern char *optarg; pid_t pid; - int chstat; - - while ((opt = getopt(argc, argv, "l:vh")) != EOF) { - switch ((char)opt) { - case 'l': - loops = atoi(optarg); - break; - case 'v': - verbose = 1; - break; - case 'h': - default: - printf("Usage: -l loops [-v]\n"); - exit(1); - } - } /* set up the semaphore */ - if ((semid = semget((key_t) 9142, 1, 0666 | IPC_CREAT)) < 0) { - printf("error in semget()\n"); - exit(-1); - } + semid = SAFE_SEMGET((key_t) 9142, 1, 0666 | IPC_CREAT); + semunion.val = 1; - if (semctl(semid, 0, SETVAL, semunion) == -1) { - printf("error in semctl\n"); - } - if ((pid = fork()) < 0) { - printf("fork error\n"); - exit(-1); - } + SAFE_SEMCTL(semid, 0, SETVAL, semunion); + + pid = SAFE_FORK(); + if (pid) { /* parent */ srand(pid); mainloop(semid); - waitpid(pid, &chstat, 0); - if (!WIFEXITED(chstat)) { - printf("child exited with status\n"); - exit(-1); - } - if (semctl(semid, 0, IPC_RMID, semunion) == -1) { - printf("error in semctl\n"); - } - if (errors) { - printf("FAIL: there were %d errors\n", errors); - } else { - printf("PASS: error count is 0\n"); - } - exit(errors); + tst_reap_children(); + SAFE_SEMCTL(semid, 0, IPC_RMID, semunion); + tst_res(TPASS, "Semaphore up/down check success"); } else { /* child */ mainloop(semid); } - exit(0); } + +static void setup(void) +{ + if (opt_loops_str) + loops = SAFE_STRTOL(opt_loops_str, 1, INT_MAX); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .forks_child = 1, + .options = (struct tst_option[]) { + {"l:", &opt_loops_str, "Internal loops for semup/down"}, + {} + }, + .needs_root = 1, +};