From patchwork Tue Mar 15 10:32:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605539 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" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=BPUBcoVC; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=66SV2hwY; 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)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KHqX40fk7z9sFn for ; Tue, 15 Mar 2022 21:34:12 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8E5C13C9202 for ; Tue, 15 Mar 2022 11:34:09 +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 [IPv6:2001:4b78:1:20::5]) (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 3A8F73C934A for ; Tue, 15 Mar 2022 11:33:02 +0100 (CET) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.220.28]) (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-5.smtp.seeweb.it (Postfix) with ESMTPS id 3902E600906 for ; Tue, 15 Mar 2022 11:33:02 +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-out1.suse.de (Postfix) with ESMTPS id D377C2190C; Tue, 15 Mar 2022 10:33:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647340381; 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=QOXzkZYAHn6dA1JNHPdjEl+blL2E0KrAOb4rdO/rFHo=; b=BPUBcoVCYo/RtYq982Xtb3jXGMb0wtCdBZKrlLKof6hU3DFVu+v1hjV9gfIU3t6V1ym3Si GFhKw1LQNNPNV9wuRdZVYVejzAwn+rXiinio8YfWAzp07FbFwV4w4mA50Q/sZYCnIxjjWY KPxl5MxURIxCNW86GwgmG9F90iWiaZw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647340381; 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=QOXzkZYAHn6dA1JNHPdjEl+blL2E0KrAOb4rdO/rFHo=; b=66SV2hwYjacG7fTChK68yEGIV5EvlTqORuewtOVcNexrTmoJ43kI5Xp5x4cY08nFdc7d7N zQN43Z+xyE5f75AA== 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 6A77013B59; Tue, 15 Mar 2022 10:33:01 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KEhnFF1rMGKHHwAAMHmgww (envelope-from ); Tue, 15 Mar 2022 10:33:01 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Tue, 15 Mar 2022 11:32:50 +0100 Message-Id: <20220315103254.7185-7-andrea.cervesato@suse.de> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220315103254.7185-1-andrea.cervesato@suse.de> References: <20220315103254.7185-1-andrea.cervesato@suse.de> MIME-Version: 1.0 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, T_SCC_BODY_TEXT_LINE 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 v3 06/10] Rewrite shmnstest.c using new LTP 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" Updated containers runtest file to include new shmnstest.c options. Signed-off-by: Andrea Cervesato --- runtest/containers | 6 +- .../kernel/containers/sysvipc/shmnstest.c | 180 ++++++------------ 2 files changed, 62 insertions(+), 124 deletions(-) diff --git a/runtest/containers b/runtest/containers index 3130ccfbd..b1b9b522a 100644 --- a/runtest/containers +++ b/runtest/containers @@ -43,9 +43,9 @@ netns_comm_ip_ipv4_ioctl netns_comm.sh ip ipv4 ioctl netns_comm_ip_ipv6_ioctl netns_comm.sh ip ipv6 ioctl netns_sysfs netns_sysfs.sh -shmnstest_none shmnstest none -shmnstest_clone shmnstest clone -shmnstest_unshare shmnstest unshare +shmnstest_none shmnstest -m none +shmnstest_clone shmnstest -m clone +shmnstest_unshare shmnstest -m unshare shmem_2nstest_none shmem_2nstest none shmem_2nstest_clone shmem_2nstest clone shmem_2nstest_unshare shmem_2nstest unshare diff --git a/testcases/kernel/containers/sysvipc/shmnstest.c b/testcases/kernel/containers/sysvipc/shmnstest.c index cf69cab21..e0dbcb177 100644 --- a/testcases/kernel/containers/sysvipc/shmnstest.c +++ b/testcases/kernel/containers/sysvipc/shmnstest.c @@ -1,144 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* -* Copyright (c) International Business Machines Corp., 2007 -* 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 -* -* Author: Serge Hallyn -* -* Create shm with key 0xEAEAEA -* clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC) -* In cloned process, try to get the created shm + * Copyright (c) International Business Machines Corp., 2007 + * Serge Hallyn + * Copyright (C) 2022 SUSE LLC Andrea Cervesato + */ -***************************************************************************/ +/*\ + * [Description] + * + * Test if SysV IPC shared memory with a specific key is shared between + * processes and namespaces. + */ + +#define _GNU_SOURCE -#define _GNU_SOURCE 1 #include -#include -#include -#include -#include -#include -#include -#include -#include -#include "ipcns_helper.h" -#include "test.h" +#include +#include +#include "tst_safe_sysv_ipc.h" +#include "tst_test.h" +#include "common.h" -char *TCID = "sysvipc_namespace"; -int TST_TOTAL = 1; #define TESTKEY 0xEAEAEA -int p1[2]; -int p2[2]; +static char *str_op = "clone"; +static int use_clone; +static int ipc_id = -1; -int check_shmid(void *vtest) +static int check_shmid(LTP_ATTRIBUTE_UNUSED void *vtest) { - char buf[3]; - int id; - - (void) vtest; - - close(p1[1]); - close(p2[0]); - - read(p1[0], buf, 3); - id = shmget(TESTKEY, 100, 0); - if (id == -1) { - write(p2[1], "notfnd", 7); + TEST(shmget(TESTKEY, 100, 0)); + if (TST_RET < 0) { + if (use_clone == T_NONE) + tst_res(TFAIL, "plain cloned process didn't find shmid"); + else + tst_res(TPASS, "%s: child process didn't find shmid", str_op); } else { - write(p2[1], "exists", 7); - shmctl(id, IPC_RMID, NULL); + if (use_clone == T_NONE) + tst_res(TPASS, "plain cloned process found shmid"); + else + tst_res(TFAIL, "%s: child process found shmid", str_op); } - tst_exit(); + return 0; } -static void setup(void) +static void run(void) { - tst_require_root(); - check_newipc(); + clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmid, NULL); } -#define UNSHARESTR "unshare" -#define CLONESTR "clone" -#define NONESTR "none" -int main(int argc, char *argv[]) +static void setup(void) { - int r, use_clone = T_NONE; - int id; - char *tsttype = NONESTR; - char buf[7]; - - setup(); - - if (argc != 2) { - tst_resm(TFAIL, "Usage: %s ", argv[0]); - tst_brkm(TFAIL, - NULL, - " where clone, unshare, or fork specifies unshare method."); - } - if (pipe(p1) == -1) { - perror("pipe"); - exit(EXIT_FAILURE); - } - if (pipe(p2) == -1) { - perror("pipe"); - exit(EXIT_FAILURE); - } - tsttype = NONESTR; - if (strcmp(argv[1], "clone") == 0) { - use_clone = T_CLONE; - tsttype = CLONESTR; - } else if (strcmp(argv[1], "unshare") == 0) { - use_clone = T_UNSHARE; - tsttype = UNSHARESTR; - } + use_clone = get_clone_unshare_enum(str_op); - /* first create the key */ - id = shmget(TESTKEY, 100, IPC_CREAT); - if (id == -1) { - perror("shmget"); - tst_brkm(TFAIL, NULL, "shmget failed"); - } + if (use_clone != T_NONE) + check_newipc(); - tst_resm(TINFO, "shmid namespaces test : %s", tsttype); - /* fire off the test */ - r = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmid, NULL); - if (r < 0) { - tst_brkm(TFAIL, NULL, "%s failed", tsttype); - } + ipc_id = shmget(TESTKEY, 100, IPC_CREAT); +} - close(p1[0]); - close(p2[1]); - write(p1[1], "go", 3); - read(p2[0], buf, 7); - if (strcmp(buf, "exists") == 0) { - if (use_clone == T_NONE) - tst_resm(TPASS, "plain cloned process found shmid"); - else - tst_resm(TFAIL, "%s: child process found shmid", - tsttype); - } else { - if (use_clone == T_NONE) - tst_resm(TFAIL, - "plain cloned process didn't find shmid"); - else - tst_resm(TPASS, "%s: child process didn't find shmid", - tsttype); +static void cleanup(void) +{ + if (ipc_id != -1) { + tst_res(TINFO, "Delete shared memory"); + SAFE_SHMCTL(ipc_id, IPC_RMID, NULL); } - - /* destroy the key */ - shmctl(id, IPC_RMID, NULL); - - tst_exit(); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .forks_child = 1, + .needs_root = 1, + .needs_checkpoints = 1, + .options = (struct tst_option[]) { + { "m:", &str_op, "Test execution mode " }, + {}, + }, +};