From patchwork Wed Apr 27 04:39:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1622776 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=Pp9QfNpG; dkim-atps=neutral Authentication-Results: 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=) 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kp4Gv5z8gz9s0B for ; Wed, 27 Apr 2022 13:38:47 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 274D43CA460 for ; Wed, 27 Apr 2022 05:38:45 +0200 (CEST) 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]) (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 picard.linux.it (Postfix) with ESMTPS id 5D8863CA4A1 for ; Wed, 27 Apr 2022 05:38:30 +0200 (CEST) Received: from mail1.bemta34.messagelabs.com (mail1.bemta34.messagelabs.com [195.245.231.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id E3FB21A00900 for ; Wed, 27 Apr 2022 05:38:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1651030707; i=@fujitsu.com; bh=MX4+me1kdCqEaLNg+4L3WLR7+LzLq0lkDOof37HnBLI=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=Pp9QfNpG3pXO350uQXq1N1HbTVTVp3NIE8P6JSRbInPxCOKsOi450UH0lyACaGfyw iW3jgauQ2oTVBNPJoRrDU4/+q81wLuH0TDBihtol9TFoGHEPG/T20J6YeUWnFv7ZU9 Zu3QOzO4hpmdh9tLw17zKldRpOVd1VBUzHNzBLxH0t+qOEEtVeTS32d9rnV3l2a9QV G/mjFIsyslQxnqZ0E0TfjCeFpPQNUNkHw7dLA0QDG0HIqoyt6Pethx3A/y3fiY8TqM M5+HeFO5Vqewy3O1CxVVVLF6/p/tlpFUyoMRBKLueFRaaCtLbzChoqt8jjxicLUK36 ranvQlI7SMaXQ== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFtrCIsWRWlGSWpSXmKPExsViZ8ORqLt5V0a SwY2VIhYrvu9gdGD02Pd7HWsAYxRrZl5SfkUCa8bec+tYCrY7VZzb28TSwLjetIuRi0NI4Cyj xKf7T5khnJ1MEkubljFCOHsYJU4/+wuU4eRgE9CUeNa5AMwWEZCQ6Gh4yw5iMwv4Sey7exUsL ixgLdH39wwLiM0ioCpxdcJOJhCbV8BT4vXKL2C2hICCxJSH75kh4oISJ2c+YYGYIyFx8MULZo gaRYlLHd8YIewKiVmz2qB61SSuntvEPIGRfxaS9llI2hcwMq1itE4qykzPKMlNzMzRNTQw0DU 0NNU1NtU1tDDRS6zSTdRLLdUtTy0u0TXSSywv1kstLtYrrsxNzknRy0st2cQIDMyUYuUdOxjb Vv3UO8QoycGkJMqbPDUjSYgvKT+lMiOxOCO+qDQntfgQowwHh5IEb8dOoJxgUWp6akVaZg4wS mDSEhw8SiK8k0HSvMUFibnFmekQqVOMilLivD/XACUEQBIZpXlwbbDIvMQoKyXMy8jAwCDEU5 BalJtZgir/ilGcg1FJmHcTyHiezLwSuOmvgBYzAS3+VJsKsrgkESEl1cDktv3HqjOHGg/tSfk 1V+5RxMdJEgZ34mdtOcnHzP3l8vuO3I+Xcv6FbVkUtfJJbcCtqXYfTnG75hlkOhzpcq42fHHu Ocu3NabSa1i25hzIMm4siL217JZ6trSS6+PAEC8HjoR81xal4iOlactvr7pzSOjWPNmkjy+y/ 7+R2zJb+PmyqfEzEq5ZyOra6c+WEr2mZMr29oerrJKN3oEnqmdSrCQXLSmdbDR3d9veTMZ3Fk /E0+d9O/u+edanV9uy69suzVq4ZtaXwHmrNv1pTyncsuBIucupk0XPFyrKy8v+eFW/1GGlWZb 3OY4TUy/Z7rmXzLx+Kv9NsZdbC0rtVkwp322cvsbPT+Fy0I3VKouOLlJiKc5INNRiLipOBACO QZw0RwMAAA== X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-13.tower-548.messagelabs.com!1651030707!27584!1 X-Originating-IP: [62.60.8.97] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.86.4; banners=-,-,- X-VirusChecked: Checked Received: (qmail 18945 invoked from network); 27 Apr 2022 03:38:27 -0000 Received: from unknown (HELO n03ukasimr01.n03.fujitsu.local) (62.60.8.97) by server-13.tower-548.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 27 Apr 2022 03:38:27 -0000 Received: from n03ukasimr01.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTP id DFCAF10018F for ; Wed, 27 Apr 2022 04:38:26 +0100 (BST) Received: from R01UKEXCASM126.r01.fujitsu.local (unknown [10.183.43.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTPS id C17EB10018B for ; Wed, 27 Apr 2022 04:38:26 +0100 (BST) Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Apr 2022 04:38:03 +0100 From: Yang Xu To: Date: Wed, 27 Apr 2022 12:39:21 +0800 Message-ID: <1651034362-18672-1-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: clamav-milter 0.102.4 at in-3.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-3.smtp.seeweb.it Subject: [LTP] [PATCH 1/2] syscalls/shmdt01: Convert 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Liao Huangjie Signed-off-by: Yang Xu Reviewed-by: Cyril Hrubis --- testcases/kernel/syscalls/ipc/shmdt/Makefile | 7 +- testcases/kernel/syscalls/ipc/shmdt/shmdt01.c | 241 ++++-------------- 2 files changed, 55 insertions(+), 193 deletions(-) diff --git a/testcases/kernel/syscalls/ipc/shmdt/Makefile b/testcases/kernel/syscalls/ipc/shmdt/Makefile index 26b9f264d..a48dbf48f 100644 --- a/testcases/kernel/syscalls/ipc/shmdt/Makefile +++ b/testcases/kernel/syscalls/ipc/shmdt/Makefile @@ -3,10 +3,13 @@ top_srcdir ?= ../../../../.. -LTPLIBS = ltpipc +LTPLIBS = ltpipc ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -LTPLDLIBS = -lltpipc +shmdt01: LTPLDLIBS = -lltpnewipc +shmdt02: LTPLDLIBS = -lltpipc + +LTPLDLIBS = -lltpipc ltpnewipc include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/shmdt/shmdt01.c b/testcases/kernel/syscalls/ipc/shmdt/shmdt01.c index 697613a47..0b754da29 100644 --- a/testcases/kernel/syscalls/ipc/shmdt/shmdt01.c +++ b/testcases/kernel/syscalls/ipc/shmdt/shmdt01.c @@ -1,223 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * 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 + * Copyright (c) International Business Machines Corp., 2001 */ -/* - * NAME - * shmdt01.c - * - * DESCRIPTION - * shmdt01 - check that shared memory is detached correctly +/*\ + * [Description] * - * ALGORITHM - * create a shared memory resource of size sizeof(int) - * attach it to the current process and give it a value - * call shmdt() using the TEST macro - * check the return code - * if failure, issue a FAIL message. - * otherwise, - * if doing functionality testing - * attempt to write a value to the shared memory address - * this should generate a SIGSEGV which will be caught in - * the signal handler - * if correct, - * issue a PASS message - * otherwise - * issue a FAIL message - * call cleanup - * - * USAGE: - * shmdt01 [-c n] [-f] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -f : Turn off functionality Testing. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 03/2001 - Written by Wayne Boyer - * - * 06/03/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com) - * - Fix wrong return value check on shmat system call (leading to - * segfault in case of error with this syscall). - * - * RESTRICTIONS - * none + * This case check whether we get SIGSEGV when write a value to a detached + * shared memory resource. */ +#include +#include +#include #include -#include "ipcshm.h" - -char *TCID = "shmdt01"; -int TST_TOTAL = 1; - -void sighandler(int); -struct shmid_ds buf; +#include "tst_test.h" +#include "libnewipc.h" +#include "tst_safe_sysv_ipc.h" -int shm_id_1 = -1; -int *shared; /* variable to use for shared memory attach */ -int new; -int pass = 0; +static int shm_id = -1, shm_key, pass; +static int *shared; sigjmp_buf env; -int main(int ac, char **av) +static void sighandler(int sig LTP_ATTRIBUTE_UNUSED) { - int lc; - void check_functionality(void); - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); /* global setup */ - - /* The following loop checks looping state if -i option given */ - - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; - - /* - * Use TEST macro to make the shmdt() call - */ - - TEST(shmdt((const void *)shared)); - - if (TEST_RETURN == -1) { - tst_resm(TFAIL, "%s call failed - errno = %d : %s", - TCID, TEST_ERRNO, strerror(TEST_ERRNO)); - } else { - check_functionality(); - } - - /* reattach the shared memory segment in case we are looping */ - shared = shmat(shm_id_1, 0, 0); - - if (shared == (void *)-1) { - tst_brkm(TBROK, cleanup, "memory reattach failed"); - } - - /* also reset pass */ - pass = 0; - } - - cleanup(); - - tst_exit(); + pass = 1; + siglongjmp(env, 1); } -/* - * check_functionality() - make sure the memory is detached correctly - */ -void check_functionality(void) +static void check_functionality(void) { - /* stat the shared memory segment */ - if (shmctl(shm_id_1, IPC_STAT, &buf) == -1) - tst_brkm(TBROK | TERRNO, cleanup, - "could not stat in signal handler"); + struct shmid_ds buf; + SAFE_SHMCTL(shm_id, IPC_STAT, &buf); if (buf.shm_nattch != 0) { - tst_resm(TFAIL, "# of attaches is incorrect"); + tst_res(TFAIL, "Number of attaches(%ld) is non-zero", buf.shm_nattch); return; } - /* - * Try writing to the shared memory. This should generate a - * SIGSEGV which will be caught below. - * - * This is wrapped by the sigsetjmp() call that will take care of - * restoring the program's context in an elegant way in conjunction - * with the call to siglongjmp() in the signal handler. - * - * An attempt to do the assignment without using the sigsetjmp() - * and siglongjmp() calls will result in an infinite loop. Program - * control is returned to the assignment statement after the execution - * of the signal handler and another SIGSEGV will be generated. - */ - - if (sigsetjmp(env, 1) == 0) { + if (sigsetjmp(env, 1) == 0) *shared = 2; - } - - if (pass) { - tst_resm(TPASS, "shared memory detached correctly"); - } else { - tst_resm(TFAIL, "shared memory was not detached correctly"); - } -} -void sighandler(int sig) -{ - /* if we have received a SIGSEGV, we are almost done */ - if (sig == SIGSEGV) { - /* set the global variable and jump back */ - pass = 1; - siglongjmp(env, 1); - } else - tst_brkm(TBROK, cleanup, - "received an unexpected signal: %d", sig); + if (pass) + tst_res(TPASS, "shared memory detached correctly"); + else + tst_res(TFAIL, "shared memory was not detached correctly"); } -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) +static void verify_shmdt(void) { - - tst_sig(NOFORK, sighandler, cleanup); - - TEST_PAUSE; - - /* - * Create a temporary directory and cd into it. - * This helps to ensure that a unique msgkey is created. - * See libs/libltpipc/libipc.c for more information. - */ - tst_tmpdir(); - - /* get an IPC resource key */ - shmkey = getipckey(); - - /* create a shared memory resource with read and write permissions */ - if ((shm_id_1 = shmget(shmkey, INT_SIZE, SHM_RW | IPC_CREAT | - IPC_EXCL)) == -1) { - tst_brkm(TBROK, cleanup, "Failed to create shared memory " - "resource in setup()"); - } - - /* attach the shared memory segment */ - shared = shmat(shm_id_1, 0, 0); - - if (shared == (void *)-1) { - tst_brkm(TBROK, cleanup, "Couldn't attach shared memory"); + TST_EXP_PASS_SILENT(shmdt(shared)); + if (TST_PASS) { + check_functionality(); + shared = SAFE_SHMAT(shm_id, 0, 0); } - /* give a value to the shared memory integer */ - *shared = 4; + pass = 0; } -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) +static void setup(void) { - /* if it exists, delete the shared memory resource */ - rm_shm(shm_id_1); + shm_key = GETIPCKEY(); + shm_id = SAFE_SHMGET(shm_key, INT_SIZE, SHM_RW | IPC_CREAT | IPC_EXCL); - tst_rmdir(); + SAFE_SIGNAL(SIGSEGV, sighandler); + shared = SAFE_SHMAT(shm_id, 0, 0); +} +static void cleanup(void) +{ + if (shm_id != -1) + SAFE_SHMCTL(shm_id, IPC_RMID, NULL); } + +static struct tst_test test = { + .needs_tmpdir = 1, + .needs_root = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = verify_shmdt, +}; From patchwork Wed Apr 27 04:39:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1622775 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=PpgajvmX; dkim-atps=neutral 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=) 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 bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kp4Gk38dSz9s0B for ; Wed, 27 Apr 2022 13:38:35 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7FE8B3CA45E for ; Wed, 27 Apr 2022 05:38:32 +0200 (CEST) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (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 971A03C9E2C for ; Wed, 27 Apr 2022 05:38:30 +0200 (CEST) Received: from mail1.bemta36.messagelabs.com (mail1.bemta36.messagelabs.com [85.158.142.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 01C9820035A for ; Wed, 27 Apr 2022 05:38:28 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1651030707; i=@fujitsu.com; bh=53IjtsZqUuy2+X8oY7Ydp2iRdngr/C9kLle7a0kJh/s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=PpgajvmXRzu+L0U+MaAWsxc8xPkXQJswqnsGOvgYyGOUPhgZWVQmp21jESy/E4ros EszIViIKKCxwJ6fMnGOZE0R7K7M289NK5jksxDQLoGK397wpOZLBhcNOdZowL3Klo5 Z7gjJMIEcCDomsq2XT02e2YFPpjQhbztihUXM8PI3RF0G5AzlOH7V5scVlil8AILgT ohg1YEsNQ4iHn1L6cBqUetpa5/Hh8K2qTB40oqEXT+uWaJlTVkjOn+fB/2eXz7Lf9F iTfIeccrQxZdyc3WyORghN6MhURjkaYKvkLqTnhLnHNuJs2174tNUe89LI8ZmYu0Gb WcUJhjgLj9teA== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrBIsWRWlGSWpSXmKPExsViZ8ORqLt5V0a Swfvb0hYrvu9gdGD02Pd7HWsAYxRrZl5SfkUCa8aP5WdYCz6pVyz/NYepgXGWQhcjJ4eQwFlG iecforsYuYDsnUwSu14vZodw9jBKtN76yQpSxSagKfGscwEziC0iICHR0fCWHcRmFvCT2Hf3K lCcg0NYwFri+TxpkDCLgKpE+7K5bCA2r4CnxKGtXWC2hICCxJSH78HGcAp4SbRPW8wEcYSnxI aNG1kg6gUlTs58wgIxXkLi4IsXzBC9ihKXOr4xQtgVErNmtTFB2GoSV89tYp7AKDgLSfssJO0 LGJlWMdomFWWmZ5TkJmbm6BoaGOgaGprqmpnoGpvoJVbpJuqlluomp+aVFCUCZfUSy4v1UouL 9Yorc5NzUvTyUks2MQIDOaXYQWkH49m+n3qHGCU5mJREeZOnZiQJ8SXlp1RmJBZnxBeV5qQWH 2KU4eBQkuDt2AmUEyxKTU+tSMvMAUYVTFqCg0dJhHcySJq3uCAxtzgzHSJ1ilGXY8Hva3uZhV jy8vNSpcR5f64BKhIAKcoozYMbAYvwS4yyUsK8jAwMDEI8BalFuZklqPKvGMU5GJWEeTeBrOL JzCuB2/QK6AgmoCM+1aaCHFGSiJCSamCKSVQzLbNYpHXbuL5N79mdE5Yp1v0TW2esqj9/6l5D Unrv9hMaeimZoru/9vOf5Ul7uVHo5jamaCe72jW/OMPK5SY/N72zWP3q3olfyi6VO/Fk1C0Kc tF1Sf6ZusHfh4OP7dnpppqAt2/3vIt4vFIv74OIqvjuhu4p9pOzXIxm5/3JO7nGlPFx86K66s m/Zqn/8f7c4njPtjfvTefNqQo3xSbLffeQaZdIX2xV5+7FfIHd+5fastiz1rIX9fw+vZmkrFP nWPBNR4fn+OeXUvYesfc3MIYye35lMHpow+zwLFA7rIV1xx1WrnkHo9f/+n/zQeWSU2ahrL/P 8MqsNV8sOjGGa9ILvgP7u0pWflViKc5INNRiLipOBAAh/JPyawMAAA== X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-4.tower-528.messagelabs.com!1651030707!27937!1 X-Originating-IP: [62.60.8.97] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.85.8; banners=-,-,- X-VirusChecked: Checked Received: (qmail 7927 invoked from network); 27 Apr 2022 03:38:27 -0000 Received: from unknown (HELO n03ukasimr01.n03.fujitsu.local) (62.60.8.97) by server-4.tower-528.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 27 Apr 2022 03:38:27 -0000 Received: from n03ukasimr01.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTP id E00B9100190 for ; Wed, 27 Apr 2022 04:38:26 +0100 (BST) Received: from R01UKEXCASM126.r01.fujitsu.local (unknown [10.183.43.178]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTPS id C320810018E for ; Wed, 27 Apr 2022 04:38:26 +0100 (BST) Received: from localhost.localdomain (10.167.220.84) by R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) with Microsoft SMTP Server (TLS) id 15.0.1497.32; Wed, 27 Apr 2022 04:38:14 +0100 From: Yang Xu To: Date: Wed, 27 Apr 2022 12:39:22 +0800 Message-ID: <1651034362-18672-2-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1651034362-18672-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1651034362-18672-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM126.r01.fujitsu.local (10.183.43.178) X-Virus-Scanned: clamav-milter 0.102.4 at in-7.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-7.smtp.seeweb.it Subject: [LTP] [PATCH 2/2] syscalls/shmdt02: Convert 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: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Liao Huangjie Signed-off-by: Yang Xu --- testcases/kernel/syscalls/ipc/shmdt/Makefile | 7 +- testcases/kernel/syscalls/ipc/shmdt/shmdt02.c | 134 +++++------------- 2 files changed, 34 insertions(+), 107 deletions(-) diff --git a/testcases/kernel/syscalls/ipc/shmdt/Makefile b/testcases/kernel/syscalls/ipc/shmdt/Makefile index a48dbf48f..6b2b26d05 100644 --- a/testcases/kernel/syscalls/ipc/shmdt/Makefile +++ b/testcases/kernel/syscalls/ipc/shmdt/Makefile @@ -3,13 +3,10 @@ top_srcdir ?= ../../../../.. -LTPLIBS = ltpipc ltpnewipc +LTPLIBS = ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -shmdt01: LTPLDLIBS = -lltpnewipc -shmdt02: LTPLDLIBS = -lltpipc - -LTPLDLIBS = -lltpipc ltpnewipc +LTPLDLIBS = -lltpnewipc include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c b/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c index 5cab2596b..782c6f488 100644 --- a/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c +++ b/testcases/kernel/syscalls/ipc/shmdt/shmdt02.c @@ -1,118 +1,48 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * 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 + * Copyright (c) International Business Machines Corp., 2001 */ -/* - * NAME - * shmdt02.c - * - * DESCRIPTION - * shmdt02 - check for EINVAL error - * - * ALGORITHM - * loop if that option was specified - * call shmdt() using an invalid shared memory address - * check the errno value - * issue a PASS message if we get EINVAL - * otherwise, the tests fails - * issue a FAIL message - * call cleanup +/*\ + * [Description] * - * USAGE: - * shmdt02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -P x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * Tests basic error handing of the shmdt syscall. * - * HISTORY - * 03/2001 - Written by Wayne Boyer - * - * RESTRICTIONS - * none + * -EINVAL there is no shared memory segment attached at shmaddr. + * -EINVAL shmaddr is not aligned on a page boundary. */ -#include "ipcshm.h" - -char *TCID = "shmdt02"; -int TST_TOTAL = 1; - -int main(int ac, char **av) -{ - int lc; - int unshared; /* a local variable to use to produce *//* the error in the shmdt() call */ - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); /* global setup */ - - /* The following loop checks looping state if -i option given */ +#include +#include +#include "tst_test.h" +#include "libnewipc.h" - for (lc = 0; TEST_LOOPING(lc); lc++) { - /* reset tst_count in case we are looping */ - tst_count = 0; +static void *non_attched_addr; +static void *unaligned_addr; - /* - * make the call using the TEST() macro - attempt to - * remove an invalid shared memory address - */ +struct tcase { + void **addr; + char *des; +} tcases[] = { + {&non_attched_addr, "shmdt(non_attched_addr)"}, + {&unaligned_addr, "shmdt(unaligned_addr)"} +}; - TEST(shmdt(&unshared)); - - if (TEST_RETURN != -1) { - tst_brkm(TFAIL, cleanup, "call succeeded unexpectedly"); - } - - switch (TEST_ERRNO) { - case EINVAL: - tst_resm(TPASS, "expected failure - errno = %d : %s", - TEST_ERRNO, strerror(TEST_ERRNO)); - break; - default: - tst_resm(TFAIL, "call failed with an unexpected error " - "- %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); - - } - } - - cleanup(); - - tst_exit(); -} - -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) +static void verify_shmdt(unsigned int n) { + struct tcase *tc = &tcases[n]; - tst_sig(NOFORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; + TST_EXP_FAIL(shmdt(*tc->addr), EINVAL, "%s", tc->des); } -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) +static void setup(void) { - + non_attched_addr = PROBE_FREE_ADDR(); + unaligned_addr = non_attched_addr + SHMLBA - 1; } + +static struct tst_test test = { + .setup = setup, + .test = verify_shmdt, + .tcnt = ARRAY_SIZE(tcases), +};