From patchwork Wed Jan 6 07:27:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Feiyu Zhu X-Patchwork-Id: 1422845 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: 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: ozlabs.org; dmarc=none (p=none dis=none) header.from=cn.fujitsu.com 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4D9gvr38SWz9sTv for ; Wed, 6 Jan 2021 18:28:39 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 04D343C6E30 for ; Wed, 6 Jan 2021 08:28:37 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) by picard.linux.it (Postfix) with ESMTP id ED06D3C549D for ; Wed, 6 Jan 2021 08:27:58 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-3.smtp.seeweb.it (Postfix) with ESMTP id B31F61A00915 for ; Wed, 6 Jan 2021 08:27:57 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.78,479,1599494400"; d="scan'208";a="103232512" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 06 Jan 2021 15:27:49 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id B18764CE602D for ; Wed, 6 Jan 2021 15:27:48 +0800 (CST) Received: from RHEL74GA.g08.fujitsu.local (10.167.220.48) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Wed, 6 Jan 2021 15:27:48 +0800 From: Feiyu Zhu To: Date: Wed, 6 Jan 2021 02:27:43 -0500 Message-ID: <1609918063-15810-5-git-send-email-zhufy.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1609918063-15810-1-git-send-email-zhufy.jy@cn.fujitsu.com> References: <1609918063-15810-1-git-send-email-zhufy.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.48] X-ClientProxiedBy: G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) To G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) X-yoursite-MailScanner-ID: B18764CE602D.AA836 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: zhufy.jy@cn.fujitsu.com X-Spam-Status: No, score=0.2 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.4 X-Virus-Scanned: clamav-milter 0.102.4 at in-3.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH 5/5] syscalls/ipc: semctl07: Convert to new API and cleanup 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Feiyu Zhu --- testcases/kernel/syscalls/ipc/semctl/Makefile | 4 +- testcases/kernel/syscalls/ipc/semctl/semctl07.c | 179 ++++++++---------------- 2 files changed, 62 insertions(+), 121 deletions(-) diff --git a/testcases/kernel/syscalls/ipc/semctl/Makefile b/testcases/kernel/syscalls/ipc/semctl/Makefile index 4923010..7b7a11d 100644 --- a/testcases/kernel/syscalls/ipc/semctl/Makefile +++ b/testcases/kernel/syscalls/ipc/semctl/Makefile @@ -7,7 +7,7 @@ LTPLIBS = ltpipc ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -semctl01 semctl06 semctl07: LTPLDLIBS = -lltpipc -semctl02 semctl03 semctl04 semctl05 semctl08 semctl09: LTPLDLIBS = -lltpnewipc +semctl01 semctl06: LTPLDLIBS = -lltpipc +semctl02 semctl03 semctl04 semctl05 semctl07 semctl08 semctl09: LTPLDLIBS = -lltpnewipc include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/semctl/semctl07.c b/testcases/kernel/syscalls/ipc/semctl/semctl07.c index 5d7fad3..df92482 100644 --- a/testcases/kernel/syscalls/ipc/semctl/semctl07.c +++ b/testcases/kernel/syscalls/ipc/semctl/semctl07.c @@ -1,176 +1,117 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2002 - * - * 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 + * Copyright (c) International Business Machines Corp., 2002 */ - -/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */ -/* 10/30/2002 Port to LTP dbarrera@us.ibm.com */ - /* - * NAME - * semctl07 - * - * CALLS - * semctl(2) semget(2) - * - * ALGORITHM + * DESCRIPTION * Get and manipulate a set of semaphores. * - * RESTRICTIONS - * * HISTORY - * 10/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com) - * - Fix concurrency issue. A statically defined key was used. Leading - * to conflict with other instances of the same test. + * 06/30/2001 Port to Linux nsharoff@us.ibm.com + * 10/30/2002 Port to LTP dbarrera@us.ibm.com + * 10/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com) + * - Fix concurrency issue. A statically defined key was used. Leading + * to conflict with other instances of the same test. */ -#include -#include #include -#include #include #include #include -#include "ipcsem.h" -#include "test.h" - -void setup(void); -void cleanup(void); - -char *TCID = "semctl07"; -int TST_TOTAL = 1; +#include "tst_test.h" +#include "tst_safe_sysv_ipc.h" +#include "libnewipc.h" +#include "lapi/sem.h" -key_t key; -int semid = -1, nsems; +static int semid = -1; +static unsigned long nsems; -int main(int argc, char *argv[]) +static void verify_semctl(void) { int status; struct semid_ds buf_ds; union semun arg; - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - arg.buf = &buf_ds; - if ((status = semctl(semid, 0, IPC_STAT, arg)) == -1) { - tst_resm(TFAIL, "semctl() failed errno = %d", errno); - semctl(semid, 1, IPC_RMID, arg); - - } - - /* - * Check contents of semid_ds structure. - */ + status = SAFE_SEMCTL(semid, 0, IPC_STAT, arg); if (arg.buf->sem_nsems != nsems) { - tst_resm(TFAIL, "error: unexpected number of sems %lu", + tst_res(TFAIL, "error: unexpected number of sems %lu", arg.buf->sem_nsems); - } + if (arg.buf->sem_perm.uid != getuid()) { - tst_resm(TFAIL, "error: unexpected uid %d", + tst_res(TFAIL, "error: unexpected uid %d", arg.buf->sem_perm.uid); - } + if (arg.buf->sem_perm.gid != getgid()) { - tst_resm(TFAIL, "error: unexpected gid %d", + tst_res(TFAIL, "error: unexpected gid %d", arg.buf->sem_perm.gid); - } + if (arg.buf->sem_perm.cuid != getuid()) { - tst_resm(TFAIL, "error: unexpected cuid %d", + tst_res(TFAIL, "error: unexpected cuid %d", arg.buf->sem_perm.cuid); - } + if (arg.buf->sem_perm.cgid != getgid()) { - tst_resm(TFAIL, "error: unexpected cgid %d", + tst_res(TFAIL, "error: unexpected cgid %d", arg.buf->sem_perm.cgid); - } - if ((status = semctl(semid, 0, GETVAL, arg)) == -1) { - tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno); - } + if ((status = semctl(semid, 0, GETVAL, arg)) == -1) + tst_res(TFAIL, "semctl(GETVAL) failed errno = %d", errno); + arg.val = 1; - if ((status = semctl(semid, 0, SETVAL, arg)) == -1) { - tst_resm(TFAIL, "SEMCTL(SETVAL) failed errno = %d", errno); + if ((status = semctl(semid, 0, SETVAL, arg)) == -1) + tst_res(TFAIL, "SEMCTL(SETVAL) failed errno = %d", errno); - } - if ((status = semctl(semid, 0, GETVAL, arg)) == -1) { - tst_resm(TFAIL, "semctl(GETVAL) failed errno = %d", errno); + if ((status = semctl(semid, 0, GETVAL, arg)) == -1) + tst_res(TFAIL, "semctl(GETVAL) failed errno = %d", errno); - } - if (status != arg.val) { - tst_resm(TFAIL, "error: unexpected value %d", status); + if (status != arg.val) + tst_res(TFAIL, "error: unexpected value %d", status); - } - if ((status = semctl(semid, 0, GETPID, arg)) == -1) { - tst_resm(TFAIL, "semctl(GETPID) failed errno = %d", errno); + if ((status = semctl(semid, 0, GETPID, arg)) == -1) + tst_res(TFAIL, "semctl(GETPID) failed errno = %d", errno); - } status = getpid(); - if (status == 0) { - tst_resm(TFAIL, "error: unexpected pid %d", status); + if (status == 0) + tst_res(TFAIL, "error: unexpected pid %d", status); - } - if ((status = semctl(semid, 0, GETNCNT, arg)) == -1) { - tst_resm(TFAIL, "semctl(GETNCNT) failed errno = %d", errno); + if ((status = semctl(semid, 0, GETNCNT, arg)) == -1) + tst_res(TFAIL, "semctl(GETNCNT) failed errno = %d", errno); - } - if (status != 0) { - tst_resm(TFAIL, "error: unexpected semncnt %d", status); + if (status != 0) + tst_res(TFAIL, "error: unexpected semncnt %d", status); - } - if ((status = semctl(semid, 0, GETZCNT, arg)) == -1) { - tst_resm(TFAIL, "semctl(GETZCNT) failed errno = %d", errno); - - } - if (status != 0) { - tst_resm(TFAIL, "error: unexpected semzcnt %d", status); - - } + if ((status = semctl(semid, 0, GETZCNT, arg)) == -1) + tst_res(TFAIL, "semctl(GETZCNT) failed errno = %d", errno); - tst_resm(TPASS, "semctl07 ran successfully!"); + if (status != 0) + tst_res(TFAIL, "error: unexpected semzcnt %d", status); - cleanup(); - tst_exit(); + tst_res(TPASS, "semctl07 ran successfully!"); } -void setup(void) +static void setup(void) { - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - /* get an IPC resource key */ - key = getipckey(); + key_t key = GETIPCKEY(); nsems = 1; - if ((semid = semget(key, nsems, SEM_RA | IPC_CREAT)) == -1) { - tst_brkm(TFAIL, NULL, "semget() failed errno = %d", errno); - } + semid = SAFE_SEMGET(key, nsems, SEM_RA | IPC_CREAT); } -void cleanup(void) +static void cleanup(void) { - rm_sema(semid); - tst_rmdir(); + if (semid != -1) + SAFE_SEMCTL(semid, 0, IPC_RMID); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .test_all = verify_semctl, +};