From patchwork Mon Mar 20 06:30:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu (Fujitsu)" X-Patchwork-Id: 1758836 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" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=b2mqVG76; 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 4Pg4cs6QD4z246f for ; Mon, 20 Mar 2023 17:31:08 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 548B63CA8C7 for ; Mon, 20 Mar 2023 07:31:00 +0100 (CET) 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 (P-384) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 77E9E3CA728 for ; Mon, 20 Mar 2023 07:30:58 +0100 (CET) Received: from mail1.bemta32.messagelabs.com (mail1.bemta32.messagelabs.com [195.245.230.1]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id EDFD91400278 for ; Mon, 20 Mar 2023 07:30:56 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1679293855; i=@fujitsu.com; bh=tift1TjXbRsbeRgQ52sKA8rsQgi1e+eaQlIxaA82S10=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=b2mqVG76RXKJw/o/TfGw8+mP6goi1y2p9lFoQrSd200eEEDPTuF+D3T+VY/6MQOlg cn9rVR+vM+GjG07s9GzS0dPYSb3UJyzRANB9/GxO/gC7Dw9xd5laIviWaE0yJfchmy CZ5scsoQUHC/FODW1kaUCxfhk21jR6KCZyA7dlK5V74nj7Dxv1452KMQkxjkuTlEWb UlHFatt6Qi5EOug1SHUaISOV0Wo+4x+epptVvHOSHfqKqYSso8OIDBiW4+/3qW2DYr W+T8BaH/3ry0OZeEIV5vIwlWq/xivoBye2t4QxK9MiekS4K24P6g20gP3uE0SIkgX9 EK0MytkHrqpGg== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFlrPIsWRWlGSWpSXmKPExsViZ8ORpDv/r3i KwezLIhYrvu9gdGD02Pd7HWsAYxRrZl5SfkUCa8ak30vYCs4zV5zom8zewNjB3MXIxSEkcIpR Ys72GSwQzl4miS/bJkJl9jJKTJj3lLGLkZODTUBT4lnnAmYQW0RAQqKj4S07iM0soC6xfNIvJ hBbWMBQYu3E22D1LAKqEst2vGEFsXkFPCWevfvKAmJLCChITHn4nhkiLihxcuYTFog5EhIHX7 xghqhRkmhrvcIKYVdINE4/xARhq0lcPbeJeQIj/ywk7bOQtC9gZFrFaFacWlSWWqRraKmXVJS ZnlGSm5iZo5dYpZuol1qqW55aXKJrqJdYXqyXWlysV1yZm5yTopeXWrKJERiOKcWsx3cwzur7 q3eIUZKDSUmU9/gb8RQhvqT8lMqMxOKM+KLSnNTiQ4wyHBxKErxHfwHlBItS01Mr0jJzgLEBk 5bg4FES4bX+BJTmLS5IzC3OTIdInWJUlBLn/f8bKCEAksgozYNrg8XjJUZZKWFeRgYGBiGegt Si3MwSVPlXjOIcjErCvB9BpvBk5pXATX8FtJgJaPH9SSIgi0sSEVJSDUxM7FE9kvP+OQhxugd eUGH5zyEmkLhx82eTP27tjbe7xN8dVDn55/mUgGubvrk4OKSddfP9Ki/2/6XjYjHWuD1fSjfP D1d1CO7QKFrueTfkmrnbj3usl117Lb/v0HyhYKAdypPisG2p9/nTtzuK+lmMyy08P376uv9F5 vL8xkU7zqQVT5RdoaDcan20Jm8d98Ydc6YeP3jDgt3CZ5KvbsjMpAWunh3urUfbpXrfibiXbw /n660urRDbqSO4oerzpMuTc6vbZKqNCt9ff+S/Zo7tcyu+/YqBntNdP0isjNm7YJGDqKDOvIw M8V+/mqNKkhVKJD0Ol/+Qf1Wv3N7I9zHd/cQu9luq3Av1vQTeKLEUZyQaajEXFScCAIyTt69C AwAA X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-12.tower-587.messagelabs.com!1679293855!468588!1 X-Originating-IP: [62.60.8.98] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.104.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10048 invoked from network); 20 Mar 2023 06:30:55 -0000 Received: from unknown (HELO n03ukasimr03.n03.fujitsu.local) (62.60.8.98) by server-12.tower-587.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Mar 2023 06:30:55 -0000 Received: from n03ukasimr03.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr03.n03.fujitsu.local (Postfix) with ESMTP id EB4AD1B2 for ; Mon, 20 Mar 2023 06:30:54 +0000 (GMT) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr03.n03.fujitsu.local (Postfix) with ESMTPS id E04B41AC for ; Mon, 20 Mar 2023 06:30:54 +0000 (GMT) Received: from localhost.localdomain (10.167.215.131) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 20 Mar 2023 06:30:53 +0000 From: Yang Xu To: Date: Mon, 20 Mar 2023 14:30:19 +0800 Message-ID: <1679293822-19378-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.215.131] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: clamav-milter 0.102.4 at in-6.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-6.smtp.seeweb.it Subject: [LTP] [PATCH 1/4] lapi/sem.h: Add SEMMSL macro 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" This macro is used to trigger semget EINVAL error. Signed-off-by: Yang Xu --- include/lapi/sem.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/include/lapi/sem.h b/include/lapi/sem.h index 495afe937..ba559d2f1 100644 --- a/include/lapi/sem.h +++ b/include/lapi/sem.h @@ -24,4 +24,8 @@ union semun { # define SEM_STAT_ANY 20 #endif +#ifndef SEMMSL +# define SEMMSL 32000 +#endif + #endif /* LAPI_SEM_H__ */ From patchwork Mon Mar 20 06:30:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu (Fujitsu)" X-Patchwork-Id: 1758837 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" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=Gf6eppQl; 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 4Pg4cy6dw4z246f for ; Mon, 20 Mar 2023 17:31:14 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id AE4743CA8FF for ; Mon, 20 Mar 2023 07:31:12 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [217.194.8.5]) (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 E109D3CCD08 for ; Mon, 20 Mar 2023 07:31:03 +0100 (CET) Received: from mail3.bemta32.messagelabs.com (mail3.bemta32.messagelabs.com [195.245.230.82]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id 0C1176005CE for ; Mon, 20 Mar 2023 07:31:01 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1679293861; i=@fujitsu.com; bh=7/PNSiKoucwdc4h2hJW3ym+Xg5A9iVsCaXIWBoT+I30=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Gf6eppQlFo0ndNvILKNBLn9ACSh4Ovvb1e39jxlpu0OrqUpZpzKiBzV1gBJdnKWcE FAhKgTHDch+Vqk30hKHg9ZQ6N/HuaHl2IOvvJT6ZLf8ut5jOgi99mrH+e6CfXqA1HI Zzzg+GIUyT3XbZKzmtLOizI0goUVceIPy0hvIpUKoB5xTt+6O+Chz0SuK5qw+rII5q /T0t/owYMPR/fGjCGCQz3zCwsNjbECcO175Mqx6V+LJhGgwb6G9PcApW4x7kkWrWCd 0XNNtJGcZWtGynYOXahBmPy0+qrXy5f3yXIJvMK428inEeXv0jHTsfZ0nobGUXj30t vQmBpEFxWaYTg== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrOIsWRWlGSWpSXmKPExsViZ8ORqLvkr3i KwYFjihYrvu9gdGD02Pd7HWsAYxRrZl5SfkUCa8ap6VOYC3Y3MFbMfvSdpYGxOa2LkYtDSOAs o8TC++fYIJwDTBKfdjUyQzh7GSV61qwBcjg52AQ0JZ51LgCzRQQkJDoa3rKD2MwC6hLLJ/1iA rGFBWwlDq44yQZiswioSkxsew5Uw8HBK+ApsWtiAkhYQkBBYsrD92BjOAW8JHa9+wFmCwGVHL v6C6yVV0BQ4uTMJywQ4yUkDr54wQzRqyTR1nqFFcKukGicfogJwlaTuHpuE/MERsFZSNpnIWl fwMi0itGsOLWoLLVI19BAL6koMz2jJDcxM0cvsUo3US+1VLc8tbhE11AvsbxYL7W4WK+4Mjc5 J0UvL7VkEyMwfFOKGZN3MF7t+6t3iFGSg0lJlPf4G/EUIb6k/JTKjMTijPii0pzU4kOMMhwcS hK8R38B5QSLUtNTK9Iyc4CxBJOW4OBREuG1/gSU5i0uSMwtzkyHSJ1iVJQS5/3/GyghAJLIKM 2Da4PF7yVGWSlhXkYGBgYhnoLUotzMElT5V4ziHIxKwrwfQabwZOaVwE1/BbSYCWjx/UkiIIt LEhFSUg1MvbVB8k933kiTSokwK0q2erNywYW5nDy83+ZzbTmxufTb0/tGliW6pmlm1zUMrrzz 3Scecy/q8Kbmnx8/Rv+Z29tU8MPwg0ioT+zehAfXp509xmCzIcD8wNtvV1cwnTzk+SHKf2m17 sRendDpb8/LljBN4y5pPqf2588dHVsh+VWzlwf3TNXTdrM7Y6q3/LiNRbjUxoNLTu80b6tcFl Lvq1V0q+617tQP7x5EnklX99O+W3PO14zFO2KbGfulJp+JjgZMJtNu1ls/3Cq7etLy7S1eNr8 tnCYbsy+/K3NfS7945roMjbXeOlw/FN9FVX2cU7joQeSmXt6bDPkR3r3ccpfYtj+61cgl0rHl 5bYyJZbijERDLeai4kQAZDPs9loDAAA= X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-11.tower-585.messagelabs.com!1679293860!161281!1 X-Originating-IP: [62.60.8.97] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.104.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 15172 invoked from network); 20 Mar 2023 06:31:00 -0000 Received: from unknown (HELO n03ukasimr01.n03.fujitsu.local) (62.60.8.97) by server-11.tower-585.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Mar 2023 06:31:00 -0000 Received: from n03ukasimr01.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr01.n03.fujitsu.local (Postfix) with ESMTP id 27D401001A6 for ; Mon, 20 Mar 2023 06:31:00 +0000 (GMT) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (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 257CC1001A3 for ; Mon, 20 Mar 2023 06:31:00 +0000 (GMT) Received: from localhost.localdomain (10.167.215.131) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 20 Mar 2023 06:30:58 +0000 From: Yang Xu To: Date: Mon, 20 Mar 2023 14:30:20 +0800 Message-ID: <1679293822-19378-2-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679293822-19378-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1679293822-19378-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.215.131] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: clamav-milter 0.102.4 at in-5.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-5.smtp.seeweb.it Subject: [LTP] [PATCH 2/4] ipc/semget02,03,06: 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" Merged semget03.c and semget06.c into semget02.c. Also use SEMMSL macro instead of 32000 and add EINVAL error test when key exists but nsems is larger than old. Signed-off-by: Yang Xu --- runtest/syscalls | 2 - runtest/syscalls-ipc | 2 - .../kernel/syscalls/ipc/semget/.gitignore | 2 - testcases/kernel/syscalls/ipc/semget/Makefile | 4 +- .../kernel/syscalls/ipc/semget/semget02.c | 221 +++++++----------- .../kernel/syscalls/ipc/semget/semget03.c | 133 ----------- .../kernel/syscalls/ipc/semget/semget06.c | 143 ------------ 7 files changed, 81 insertions(+), 426 deletions(-) delete mode 100644 testcases/kernel/syscalls/ipc/semget/semget03.c delete mode 100644 testcases/kernel/syscalls/ipc/semget/semget06.c diff --git a/runtest/syscalls b/runtest/syscalls index b9d4a43c8..9c96f57f7 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -1237,9 +1237,7 @@ semctl09 semctl09 semget01 semget01 semget02 semget02 -semget03 semget03 semget05 semget05 -semget06 semget06 semop01 semop01 semop02 semop02 diff --git a/runtest/syscalls-ipc b/runtest/syscalls-ipc index b758158c3..df41140a7 100644 --- a/runtest/syscalls-ipc +++ b/runtest/syscalls-ipc @@ -41,9 +41,7 @@ semctl09 semctl09 semget01 semget01 semget02 semget02 -semget03 semget03 semget05 semget05 -semget06 semget06 semop01 semop01 semop02 semop02 diff --git a/testcases/kernel/syscalls/ipc/semget/.gitignore b/testcases/kernel/syscalls/ipc/semget/.gitignore index ce26c93b0..4519b30d2 100644 --- a/testcases/kernel/syscalls/ipc/semget/.gitignore +++ b/testcases/kernel/syscalls/ipc/semget/.gitignore @@ -1,5 +1,3 @@ /semget01 /semget02 -/semget03 /semget05 -/semget06 diff --git a/testcases/kernel/syscalls/ipc/semget/Makefile b/testcases/kernel/syscalls/ipc/semget/Makefile index c41744764..2f98c36ca 100644 --- a/testcases/kernel/syscalls/ipc/semget/Makefile +++ b/testcases/kernel/syscalls/ipc/semget/Makefile @@ -7,7 +7,7 @@ LTPLIBS = ltpipc ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -semget01: LTPLDLIBS = -lltpnewipc -semget02 semget03 semget04 semget05 semget06: LTPLDLIBS = -lltpipc +semget01 semget02: LTPLDLIBS = -lltpnewipc +semget05: LTPLDLIBS = -lltpipc include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/semget/semget02.c b/testcases/kernel/syscalls/ipc/semget/semget02.c index 4124514c2..4273c84c7 100644 --- a/testcases/kernel/syscalls/ipc/semget/semget02.c +++ b/testcases/kernel/syscalls/ipc/semget/semget02.c @@ -1,165 +1,102 @@ +// 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 - * semget02.c +/*\ + * [Description] * - * DESCRIPTION - * semget02 - test for EACCES and EEXIST errors + * This basic error handing of the semget syscall. * - * ALGORITHM - * create a semaphore set without read or alter permissions - * loop if that option was specified - * call semget() using two different invalid cases - * check the errno value - * issue a PASS message if we get EACCES or EEXIST - * otherwise, the tests fails - * issue a FAIL message - * call cleanup - * - * USAGE: - * semget02 [-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. - * - * HISTORY - * 03/2001 - Written by Wayne Boyer - * - * RESTRICTIONS - * none + * - EACCES - a semaphore set exists for key, but the calling process does not + * have permission to access the set + * - EEXIST - a semaphore set already exists for key and IPC_CREAT | IPC_EXCL + * is given + * - ENOENT - No semaphore set exists for key and semflg did not specify + * IPC_CREAT + * - EINVAL - nsems is less than 0 or greater than the limit on the number of + * semaphores per semaphore set(SEMMSL) + * - EINVAL - a semaphore set corresponding to key already exists, but nsems is + * larger than the number of semaphores in that set */ -#include - -#include "ipcsem.h" -char *TCID = "semget02"; -int TST_TOTAL = 2; - -char nobody_uid[] = "nobody"; -struct passwd *ltpuser; - -int sem_id_1 = -1; - -struct test_case_t { +#include +#include +#include +#include +#include +#include +#include "tst_test.h" +#include "tst_safe_sysv_ipc.h" +#include "libnewipc.h" +#include "lapi/sem.h" + +static int sem_id = -1; +static key_t semkey, semkey1; +static struct passwd *pw; +static struct tcase { + int *key; + int nsems; int flags; - int error; -} TC[] = { - /* EACCES - the semaphore has no read or alter permissions */ - { - SEM_RA, EACCES}, - /* EEXIST - the semaphore id exists and semget() was called with */ - /* IPC_CREAT and IPC_EXCL */ - { - IPC_CREAT | IPC_EXCL, EEXIST} + int exp_err; + /*1: nobody expected, 0: root expected */ + int exp_user; +} tcases[] = { + {&semkey, PSEMS, SEM_RA, EACCES, 1}, + {&semkey, PSEMS, IPC_CREAT | IPC_EXCL, EEXIST, 0}, + {&semkey1, PSEMS, SEM_RA, ENOENT, 0}, + {&semkey1, -1, IPC_CREAT | IPC_EXCL, EINVAL, 0}, + {&semkey1, SEMMSL + 1, IPC_CREAT | IPC_EXCL, EINVAL, 0}, + {&semkey, PSEMS + 1, SEM_RA, EINVAL, 0}, }; -int main(int ac, char **av) +static void verify_semget(struct tcase *tc) { - int lc; - int i; - - 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; - - for (i = 0; i < TST_TOTAL; i++) { - /* use the TEST macro to make the call */ - - TEST(semget(semkey, PSEMS, TC[i].flags)); - - if (TEST_RETURN != -1) { - sem_id_1 = TEST_RETURN; - tst_resm(TFAIL, "call succeeded"); - continue; - } + TST_EXP_FAIL2(semget(*tc->key, tc->nsems, tc->flags), tc->exp_err, + "semget(%i, %i, %i)", *tc->key, tc->nsems, tc->flags); +} - if (TEST_ERRNO == TC[i].error) { - tst_resm(TPASS, "expected failure - errno " - "= %d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - } else { - tst_resm(TFAIL, "unexpected error - %d : %s", - TEST_ERRNO, strerror(TEST_ERRNO)); - } +static void do_test(unsigned int n) +{ + pid_t pid; + struct tcase *tc = &tcases[n]; + + if (tc->exp_user == 0) { + verify_semget(tc); + } else { + pid = SAFE_FORK(); + if (pid) { + tst_reap_children(); + } else { + SAFE_SETUID(pw->pw_uid); + verify_semget(tc); + exit(0); } } - - cleanup(); - - tst_exit(); } -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) +static void setup(void) { - tst_require_root(); - - /* Switch to nobody user for correct error code collection */ - ltpuser = getpwnam(nobody_uid); - if (seteuid(ltpuser->pw_uid) == -1) { - tst_resm(TINFO, "setreuid failed to " - "to set the effective uid to %d", ltpuser->pw_uid); - perror("setreuid"); - } - - tst_sig(NOFORK, DEF_HANDLER, cleanup); + semkey = GETIPCKEY(); + semkey1 = GETIPCKEY(); - TEST_PAUSE; + sem_id = SAFE_SEMGET(semkey, PSEMS, IPC_CREAT | IPC_EXCL); - /* - * 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 */ - semkey = getipckey(); - - /* create a semaphore set without read or alter permissions */ - if ((sem_id_1 = semget(semkey, PSEMS, IPC_CREAT | IPC_EXCL)) == -1) { - tst_brkm(TBROK, cleanup, "couldn't create semaphore in setup"); - } + pw = SAFE_GETPWNAM("nobody"); } -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - /* if it exists, remove the semaphore resource */ - rm_sema(sem_id_1); - - tst_rmdir(); - + if (sem_id != -1) + SAFE_SEMCTL(sem_id, PSEMS, IPC_RMID); } + +static struct tst_test test = { + .needs_tmpdir = 1, + .needs_root = 1, + .forks_child = 1, + .tcnt = ARRAY_SIZE(tcases), + .setup = setup, + .cleanup = cleanup, + .test = do_test, +}; diff --git a/testcases/kernel/syscalls/ipc/semget/semget03.c b/testcases/kernel/syscalls/ipc/semget/semget03.c deleted file mode 100644 index 995b4bd3a..000000000 --- a/testcases/kernel/syscalls/ipc/semget/semget03.c +++ /dev/null @@ -1,133 +0,0 @@ -/* - * - * 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 - */ - -/* - * NAME - * semget03.c - * - * DESCRIPTION - * semget03 - test for ENOENT error - * - * ALGORITHM - * loop if that option was specified - * call semget() with a valid key but with no associated semaphore set - * and IPC_CREAT is not asserted - * check the errno value - * issue a PASS message if we get ENOENT - * otherwise, the tests fails - * issue a FAIL message - * call cleanup - * - * USAGE: - * semget03 [-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. - * - * HISTORY - * 03/2001 - Written by Wayne Boyer - * - * RESTRICTIONS - * none - */ - -#include "ipcsem.h" - -char *TCID = "semget03"; -int TST_TOTAL = 1; - -int sem_id_1 = -1; - -int main(int ac, char **av) -{ - int lc; - - 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 the TEST macro to make the call */ - - TEST(semget(semkey, PSEMS, SEM_RA)); - - if (TEST_RETURN != -1) { - sem_id_1 = TEST_RETURN; - tst_resm(TFAIL, "call succeeded when error expected"); - continue; - } - - switch (TEST_ERRNO) { - case ENOENT: - tst_resm(TPASS, "expected failure - errno " - "= %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); - break; - default: - tst_resm(TFAIL, "unexpected error - %d : %s", - TEST_ERRNO, strerror(TEST_ERRNO)); - break; - } - } - - cleanup(); - - tst_exit(); -} - -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) -{ - - tst_sig(NOFORK, DEF_HANDLER, 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 */ - semkey = getipckey(); -} - -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) -{ - /* if it exists, remove the semaphore resource */ - rm_sema(sem_id_1); - - tst_rmdir(); - -} diff --git a/testcases/kernel/syscalls/ipc/semget/semget06.c b/testcases/kernel/syscalls/ipc/semget/semget06.c deleted file mode 100644 index 52297c010..000000000 --- a/testcases/kernel/syscalls/ipc/semget/semget06.c +++ /dev/null @@ -1,143 +0,0 @@ -/* - * - * 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 - */ - -/* - * NAME - * semget06.c - * - * DESCRIPTION - * semget06 - test for EINVAL error - * - * ALGORITHM - * loop if that option was specified - * call semget() using two different invalid cases - too many and too - * few primitive semaphores - * check the errno value - * issue a PASS message if we get EINVAL - * otherwise, the tests fails - * issue a FAIL message - * call cleanup - * - * USAGE: - * semget06 [-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. - * - * HISTORY - * 03/2001 - Written by Wayne Boyer - * - * RESTRICTIONS - * none - */ - -#include "ipcsem.h" - -char *TCID = "semget06"; -int TST_TOTAL = 2; - -#define LARGENUM 1024 * 32 -#define SMALLNUM -1 - -int sem_id_1 = -1; - -int num_sems[] = { LARGENUM, SMALLNUM }; - -int main(int ac, char **av) -{ - int lc; - int i; - - 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; - - /* loop through the test cases */ - - for (i = 0; i < TST_TOTAL; i++) { - TEST(semget(semkey, num_sems[i], - IPC_CREAT | IPC_EXCL | SEM_RA)); - - if (TEST_RETURN != -1) { - sem_id_1 = TEST_RETURN; - tst_resm(TFAIL, "call succeeded"); - continue; - } - - switch (TEST_ERRNO) { - case EINVAL: - tst_resm(TPASS, "expected failure - errno " - "= %d : %s", TEST_ERRNO, - strerror(TEST_ERRNO)); - break; - default: - tst_resm(TFAIL, "unexpected error - %d : %s", - TEST_ERRNO, strerror(TEST_ERRNO)); - break; - } - } - } - - cleanup(); - - tst_exit(); -} - -/* - * setup() - performs all the ONE TIME setup for this test. - */ -void setup(void) -{ - - tst_sig(NOFORK, DEF_HANDLER, 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 */ - semkey = getipckey(); -} - -/* - * cleanup() - performs all the ONE TIME cleanup for this test at completion - * or premature exit. - */ -void cleanup(void) -{ - /* if it exists, remove the semaphore resource */ - rm_sema(sem_id_1); - - tst_rmdir(); - -} From patchwork Mon Mar 20 06:30:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Yang Xu (Fujitsu)" X-Patchwork-Id: 1758838 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" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=FKCIl8RD; 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 4Pg4dF1QjKz246f for ; Mon, 20 Mar 2023 17:31:29 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id EC8D23CBC31 for ; Mon, 20 Mar 2023 07:31:26 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [IPv6:2001:4b78:1:20::4]) (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 AD7E33CCD24 for ; Mon, 20 Mar 2023 07:31:05 +0100 (CET) Received: from mail1.bemta32.messagelabs.com (mail1.bemta32.messagelabs.com [195.245.230.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 72E6D10000EA for ; Mon, 20 Mar 2023 07:31:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1679293863; i=@fujitsu.com; bh=3Iw34bnV3ALpvCqfieRqmvQhGX3UFddqm8EgNkfVeVI=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=FKCIl8RDptMcaPpZU1zCpL7XQ8xTlghaGJNIpmDT7xBqPIFJLm/KVqq7gELyhQbww QLsx1ttMbV4B5gjYWx5V7xmZLWA6kzlsaHDLuz3vewrVYLbU8jq+zi8o6PD1b36oki MNsLVmkUVxQB4sOhFQm8hMf2pRWfFbuxqWFt92CcuQiHI7KshefBontWcbx3yPxEch ItaVyk1/L5u+LnKDRfjZ78kjAusUgf5XLNkLUL3UhTRIVzAhDo7Ma51MPd9PT4FPWX zOQh6zs7rG1Jb8x0G2k6hNglOkYn4++Sxg4zdxYpDSIAYBXIM1KnlNt2swVFcpPJ7e lHL9Cmo7j6TUg== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFjrMIsWRWlGSWpSXmKPExsViZ8OxWXf5X/E Ug5P/WSxWfN/B6MDose/3OtYAxijWzLyk/IoE1oxDv20LfrFWzLp8ia2BcS5rFyMXh5DAKUaJ vY+nsHcxcgI5e5kkvsz3h0jsZZT4vb4FLMEmoCnxrHMBM4gtIiAh0dHwFizOLKAusXzSLyYQW 1jARuL2vZksXYwcHCwCqhIL2sRAwrwCnhIPp01nA7ElBBQkpjx8DzaGU8BLYte7H8wQez0ljl 39xQZRLyhxcuYTFojxEhIHX7xghuhVkmhrvcIKYVdINE4/xARhq0lcPbeJeQKj4Cwk7bOQtC9 gZFrFaFqcWlSWWqRrppdUlJmeUZKbmJmjl1ilm6iXWqpbnlpcomuol1herJdaXKxXXJmbnJOi l5dasokRGLYpxQw3djDO6furd4hRkoNJSZT3+BvxFCG+pPyUyozE4oz4otKc1OJDjDIcHEoSv Ed/AeUEi1LTUyvSMnOAMQSTluDgURLhtf4ElOYtLkjMLc5Mh0idYlSUEuf9/xsoIQCSyCjNg2 uDxe0lRlkpYV5GBgYGIZ6C1KLczBJU+VeM4hyMSsK8H0Gm8GTmlcBNfwW0mAlo8f1JIiCLSxI RUlINTJ2HRDcbrykofpq+3vOlwq3kMtvg+7tmvFRyP/JPsurWaanNRidUSj4/vH7iz9z4x2/7 7rkfjnDRz5z7IWQ237U5qZdTAg3+sk+rl9npXXLZ/OvFZtaIhxsmXZLf1zj1xM9/xx4HWJ78o 5mjpXNA+t2/6ZUx70J9HsQzeZhMP2z4uEvh3zz9gsv2s78f2t0+78nJtCulrT+v2vmu33Vcmk t7xcxPl0rPS91/0WQWO+HEvSk2QoHXbu5VOu/bfn8Fm9R+5vdn6uQ2vjaftfLZ0W1tr4yYcqK kzm4Kiz9a9f/H27fpMpP7j869O3legB0L20n3z/cDbD9MNrgv/VT3oTzjdteNyrcMZzgk5K40 zWFLV2Ipzkg01GIuKk4EALAAFl5WAwAA X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-2.tower-591.messagelabs.com!1679293862!321973!1 X-Originating-IP: [62.60.8.179] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.104.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 2829 invoked from network); 20 Mar 2023 06:31:03 -0000 Received: from unknown (HELO n03ukasimr04.n03.fujitsu.local) (62.60.8.179) by server-2.tower-591.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Mar 2023 06:31:03 -0000 Received: from n03ukasimr04.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTP id AD4C3157 for ; Mon, 20 Mar 2023 06:31:02 +0000 (GMT) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr04.n03.fujitsu.local (Postfix) with ESMTPS id A0202154 for ; Mon, 20 Mar 2023 06:31:02 +0000 (GMT) Received: from localhost.localdomain (10.167.215.131) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 20 Mar 2023 06:31:01 +0000 From: Yang Xu To: Date: Mon, 20 Mar 2023 14:30:21 +0800 Message-ID: <1679293822-19378-3-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679293822-19378-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1679293822-19378-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.215.131] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: clamav-milter 0.102.4 at in-4.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-4.smtp.seeweb.it Subject: [LTP] [PATCH 3/4] libs/libnewipc: Add GET_USED_ARRAYS 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" This api is used to get the semaphore arrays resource total. Signed-off-by: Yang Xu --- include/libnewipc.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/libnewipc.h b/include/libnewipc.h index 1e126ca1c..969c93292 100644 --- a/include/libnewipc.h +++ b/include/libnewipc.h @@ -53,6 +53,8 @@ int get_used_sysvipc(const char *file, const int lineno, const char *sysvipc_fil get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/msg") #define GET_USED_SEGMENTS() \ get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/shm") +#define GET_USED_ARRAYS() \ + get_used_sysvipc(__FILE__, __LINE__, "/proc/sysvipc/sem") void *probe_free_addr(const char *file, const int lineno); #define PROBE_FREE_ADDR() \ From patchwork Mon Mar 20 06:30:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Yang Xu (Fujitsu)" X-Patchwork-Id: 1758839 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" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=170520fj header.b=kG5n3tnH; 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)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Pg4dS1MHmz246f for ; Mon, 20 Mar 2023 17:31:40 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 39E913CD355 for ; Mon, 20 Mar 2023 07:31:38 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (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 62E813CD351 for ; Mon, 20 Mar 2023 07:31:08 +0100 (CET) Received: from mail1.bemta34.messagelabs.com (mail1.bemta34.messagelabs.com [195.245.231.2]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id 5F45410000EA for ; Mon, 20 Mar 2023 07:31:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fujitsu.com; s=170520fj; t=1679293866; i=@fujitsu.com; bh=xBO8VUwX9WtlxHrNBGeGehiYqaToKwMI9lnjfu4MH9s=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; b=kG5n3tnHmpWMes6uSUtVXIeel+P8yGG8A/JO7aA9LFMBPsnlwYjzCuXgE7bZ+FNqK Pf9x1l1CeX6JK8jGlRkIBOl9bEurtxeAkSAY+9r8qykG+3pUFAK7vaIlM4bNdr3xTK IvHuWiqL5bRDHoEW9emD/HjIfzTt53wXaOpDZKf+65whNfIAGQfidoMI+UyYWfYPoM cM0gvldHhsERyflhbgNZi1WGSaxLfN72+B96zyccGi3a3/+n+cz9Ccuby73Ol+RU48 S884/pNvtuS7QnxS7QhfKUXUN3FsM+0QfkqfQ3deffqaJjaXk9Oucfut2GT/0Otm56 Jya9cw4ck5dqg== X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrLIsWRWlGSWpSXmKPExsViZ8MxSXflX/E Ug5VLDCxWfN/B6MDose/3OtYAxijWzLyk/IoE1ozzaxuYCtaZVrQ9Ws3cwLhYu4uRi0NI4Cyj xKbj95m6GDmBnANMEsunK0Ek9jJKbLvZzgySYBPQlHjWuQDMFhGQkOhoeMsOYjMLqEssn/QLq JmDQ1jAXOL7qhCQMIuAqsTz7iY2EJtXwFPi5K9OMFtCQEFiysP3YGM4Bbwkdr37wQyx11Pi2N VfUPWCEidnPmGBGK8q0X3kKROELS/RvHU2M8QcJYm21iusEHaFROP0Q0wQtprE1XObmCcwCs1 CMmoWklGzkIxawMi8itGsOLWoLLVI19BML6koMz2jJDcxM0cvsUo3US+1VLc8tbhE10gvsbxY L7W4WK+4Mjc5J0UvL7VkEyMw1FOK1d13MB7p+6t3iFGSg0lJlPf4G/EUIb6k/JTKjMTijPii0 pzU4kOMMhwcShK8R38B5QSLUtNTK9Iyc4BxB5OW4OBREuG1/gSU5i0uSMwtzkyHSJ1iVJQS5/ 3/GyghAJLIKM2Da4PF+iVGWSlhXkYGBgYhnoLUotzMElT5V4ziHIxKwrwfQabwZOaVwE1/BbS YCWjx/UkiIItLEhFSUg1M1W1lHDsezLTte9m9eFm82WKBmWfVbWcfeiR2IXD2b6VrHec13rx4 fi1xrQXn/kutlTorVf5xLz7xWC5RfKpW6gtt556ZwrnRYtf+uynVB3765MVx81Hszs0V2zd+E tvH+cZz07GW7F3O3HxXPVgXfwo+bMc66aBzTJ5u3bI5pz5dr30pmTZ3jfX30Fz7+dof+9w/7R FJfexdzjXziN4PBs8VrxODmZt3+3/OTuf4LPuH+0+83avfJcdrb87x2NI60+6ErX7LnyutbDc VjZX27F6kn/asbWJvUN3l4MBl3Z1VMu4151f8+NG7mSVwy4vIAypfMxsiDKVjXzDv1s47obnS tnJ9YMrUiZNCIzP/KLEUZyQaajEXFScCABI2JFRwAwAA X-Env-Sender: xuyang2018.jy@fujitsu.com X-Msg-Ref: server-4.tower-548.messagelabs.com!1679293865!141890!1 X-Originating-IP: [62.60.8.146] X-SYMC-ESS-Client-Auth: outbound-route-from=pass X-StarScan-Received: X-StarScan-Version: 9.104.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 9611 invoked from network); 20 Mar 2023 06:31:05 -0000 Received: from unknown (HELO n03ukasimr02.n03.fujitsu.local) (62.60.8.146) by server-4.tower-548.messagelabs.com with ECDHE-RSA-AES256-GCM-SHA384 encrypted SMTP; 20 Mar 2023 06:31:05 -0000 Received: from n03ukasimr02.n03.fujitsu.local (localhost [127.0.0.1]) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTP id 7E8E71000E7 for ; Mon, 20 Mar 2023 06:31:05 +0000 (GMT) Received: from R01UKEXCASM121.r01.fujitsu.local (R01UKEXCASM121 [10.183.43.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by n03ukasimr02.n03.fujitsu.local (Postfix) with ESMTPS id 717041000DC for ; Mon, 20 Mar 2023 06:31:05 +0000 (GMT) Received: from localhost.localdomain (10.167.215.131) by R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 20 Mar 2023 06:31:03 +0000 From: Yang Xu To: Date: Mon, 20 Mar 2023 14:30:22 +0800 Message-ID: <1679293822-19378-4-git-send-email-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1679293822-19378-1-git-send-email-xuyang2018.jy@fujitsu.com> References: <1679293822-19378-1-git-send-email-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.215.131] X-ClientProxiedBy: G08CNEXCHPEKD07.g08.fujitsu.local (10.167.33.80) To R01UKEXCASM121.r01.fujitsu.local (10.183.43.173) X-Virus-Scanned: clamav-milter 0.102.4 at in-4.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-4.smtp.seeweb.it Subject: [LTP] [PATCH 4/4] ipc/semget05: 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" Use the same logic as shmget03 and msget02 to trigger ENOSPC error. Signed-off-by: Yang Xu Reviewed-by: Li Wang --- testcases/kernel/syscalls/ipc/semget/Makefile | 5 +- .../kernel/syscalls/ipc/semget/semget05.c | 187 ++++++------------ 2 files changed, 59 insertions(+), 133 deletions(-) diff --git a/testcases/kernel/syscalls/ipc/semget/Makefile b/testcases/kernel/syscalls/ipc/semget/Makefile index 2f98c36ca..b1201281d 100644 --- a/testcases/kernel/syscalls/ipc/semget/Makefile +++ b/testcases/kernel/syscalls/ipc/semget/Makefile @@ -3,11 +3,10 @@ top_srcdir ?= ../../../../.. -LTPLIBS = ltpipc ltpnewipc +LTPLIBS = ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -semget01 semget02: LTPLDLIBS = -lltpnewipc -semget05: LTPLDLIBS = -lltpipc +LTPLDLIBS = -lltpnewipc include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/ipc/semget/semget05.c b/testcases/kernel/syscalls/ipc/semget/semget05.c index f801cb8ed..38b0fad3c 100644 --- a/testcases/kernel/syscalls/ipc/semget/semget05.c +++ b/testcases/kernel/syscalls/ipc/semget/semget05.c @@ -1,152 +1,79 @@ +// 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 - * semget05.c +/*\ + * [Description] * - * DESCRIPTION - * semget05 - test for ENOSPC error + * Test for ENOSPC error. * - * ALGORITHM - * create semaphore sets in a loop until the system limit is reached - * loop if that option was specified - * attempt to create yet another semaphore set - * check the errno value - * issue a PASS message if we get ENOSPC - * otherwise, the tests fails - * issue a FAIL message - * call cleanup - * - * USAGE: - * HISTORY - * 03/2001 - Written by Wayne Boyer - * 07/2006 - Changes By Michael Reed - * - Changed the value of MAXIDS for the specific machine by reading - * the system limit for SEMMNI - The maximum number of sempahore sets - * 03/2008 - Matthieu Fertré (mfertre@irisa.fr) - * - Fix concurrency issue. Create private semaphores to - * avoid conflict with concurrent processes. - * - * RESTRICTIONS - * none + * ENOSPC - a semaphore set exceed the maximum number of semaphore sets(SEMMNI) */ -#include "ipcsem.h" - -char *TCID = "semget05"; -int TST_TOTAL = 1; - -/* - * The MAXIDS value is somewhat arbitrary and may need to be increased - * depending on the system being tested. - */ - -int MAXIDS = 2048; - -int *sem_id_arr = NULL; -int num_sems = 0; /* count the semaphores created */ - -int main(int ac, char **av) +#include +#include +#include +#include +#include +#include "lapi/sem.h" +#include "tst_test.h" +#include "libnewipc.h" +#include "tst_safe_sysv_ipc.h" + +static int *sem_id_arr; +static int maxsems, array_cnt, used_cnt; +static key_t semkey; + +static void verify_semget(void) { - int lc; - FILE *fp; - - tst_parse_opts(ac, av, NULL, NULL); - - /* Set the MAXIDS for the specific machine by reading the system limit - * for SEMMNI - The maximum number of sempahore sets - */ - fp = fopen("/proc/sys/kernel/sem", "r"); - if (fp != NULL) { - int getmaxid; - if (fscanf(fp, "%*d %*d %*d %d", &getmaxid) == 1) - MAXIDS = getmaxid + 1; - fclose(fp); - } - - sem_id_arr = malloc(sizeof(int) * MAXIDS); - if (sem_id_arr == NULL) - tst_brkm(TBROK, cleanup, "malloc failed"); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - tst_count = 0; - - - TEST(semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA)); - if (TEST_RETURN != -1) { - tst_resm(TFAIL, "call succeeded when error expected"); - continue; - } - - switch (TEST_ERRNO) { - case ENOSPC: - tst_resm(TPASS, "expected failure - errno " - "= %d : %s", TEST_ERRNO, strerror(TEST_ERRNO)); - break; - default: - tst_resm(TFAIL, "unexpected error - %d : %s", - TEST_ERRNO, strerror(TEST_ERRNO)); - break; - } - } - - cleanup(); - - tst_exit(); + TST_EXP_FAIL2(semget(semkey + maxsems, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA), + ENOSPC, "semget(%i, %i, %i)", semkey + maxsems, PSEMS, + IPC_CREAT | IPC_EXCL | SEM_RA); } -void setup(void) +static void setup(void) { - int sem_q; - - tst_sig(NOFORK, DEF_HANDLER, cleanup); + int res, num; - TEST_PAUSE; + semkey = GETIPCKEY(); + used_cnt = GET_USED_ARRAYS(); + tst_res(TINFO, "Current environment %d semaphore arrays are already in use", + used_cnt); + SAFE_FILE_SCANF("/proc/sys/kernel/sem", "%*d %*d %*d %d", &maxsems); - tst_tmpdir(); - - while ((sem_q = semget(IPC_PRIVATE, PSEMS, IPC_CREAT | IPC_EXCL)) != -1) { - sem_id_arr[num_sems++] = sem_q; - if (num_sems == MAXIDS) { - tst_brkm(TBROK, cleanup, "The maximum number of " - "semaphore ID's has been\n\t reached. Please " - "increase the MAXIDS value in the test."); - } - } + sem_id_arr = SAFE_MALLOC((maxsems - used_cnt) * sizeof(int)); + for (num = 0; num < maxsems - used_cnt; num++) { + res = semget(semkey + num, PSEMS, IPC_CREAT | IPC_EXCL | SEM_RA); + if (res == -1) + tst_brk(TBROK | TERRNO, "semget failed unexpectedly"); - if (errno != ENOSPC) { - tst_brkm(TBROK, cleanup, "Didn't get ENOSPC in test setup" - " - errno = %d : %s", errno, strerror(errno)); + sem_id_arr[array_cnt++] = res; } + tst_res(TINFO, "The maximum number of semaphore arrays (%d) has been reached", + maxsems); } -void cleanup(void) +static void cleanup(void) { - int i; + int num; - for (i = 0; i < num_sems; i++) { - rm_sema(sem_id_arr[i]); - } + if (!sem_id_arr) + return; + + for (num = 0; num < array_cnt; num++) + SAFE_SEMCTL(sem_id_arr[num], PSEMS, IPC_RMID); free(sem_id_arr); - tst_rmdir(); } + +static struct tst_test test = { + .needs_tmpdir = 1, + .setup = setup, + .cleanup = cleanup, + .test_all = verify_semget, + .save_restore = (const struct tst_path_val[]){ + {"/proc/sys/kernel/sem", NULL, TST_SR_TCONF}, + {} + } +};