From patchwork Tue Mar 15 10:32:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605532 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=ZHEsxhm1; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=+k9Apbyo; 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)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KHqVz0TMVz9sFn for ; Tue, 15 Mar 2022 21:33:15 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 0318C3C920A for ; Tue, 15 Mar 2022 11:33:13 +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 [IPv6:2001:4b78:1:20::6]) (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 12CF83C20CC for ; Tue, 15 Mar 2022 11:33:00 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id F32D51400F30 for ; Tue, 15 Mar 2022 11:32:58 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 9419D1F391; Tue, 15 Mar 2022 10:32:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647340378; 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=WicFYpupDKu/q1zEmppP+OQ7uNdIPLg3brbe0lhOJ6s=; b=ZHEsxhm1XuPPyvhQrQVW2Xzj6xhIH+CViI8K0IDb0Qo/YGHUPaagARxqILgUXmfuS3hlx7 4/azd/jYvg/g3j4CPIck+9ZFVfbSlL1Ee7opPps1i+g9PuRdOR4DClm2TZRCZeaCpW/vwm g6mwI1jcNU9kL1z3uDn3DvykhL3PhDE= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647340378; 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=WicFYpupDKu/q1zEmppP+OQ7uNdIPLg3brbe0lhOJ6s=; b=+k9ApbyoeP7QTV7jsU5dBN6RfBN4qwi1kcy09Xv49HyOrbjR8Q6ZopLMwXZFPL0iIdW+8J 0hQ955ehRMG151BA== 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 F2BB413B59; Tue, 15 Mar 2022 10:32:57 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id ICQoOVlrMGKHHwAAMHmgww (envelope-from ); Tue, 15 Mar 2022 10:32:57 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Tue, 15 Mar 2022 11:32:45 +0100 Message-Id: <20220315103254.7185-2-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-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, T_SCC_BODY_TEXT_LINE 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 v3 01/10] Rewrite mesgq_nstest.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" Added common.h that is replacing ipcns_helper.h for refactored tests. Updated containers runtime file to include the new mesgq_nstest.c command line options. Signed-off-by: Andrea Cervesato --- runtest/containers | 6 +- testcases/kernel/containers/sysvipc/common.h | 108 ++++++++ .../kernel/containers/sysvipc/mesgq_nstest.c | 243 +++++++----------- 3 files changed, 202 insertions(+), 155 deletions(-) create mode 100644 testcases/kernel/containers/sysvipc/common.h diff --git a/runtest/containers b/runtest/containers index eea7bfadb..d863c10a4 100644 --- a/runtest/containers +++ b/runtest/containers @@ -50,9 +50,9 @@ shmem_2nstest_none shmem_2nstest none shmem_2nstest_clone shmem_2nstest clone shmem_2nstest_unshare shmem_2nstest unshare shm_comm shm_comm -mesgq_nstest_none mesgq_nstest none -mesgq_nstest_clone mesgq_nstest clone -mesgq_nstest_unshare mesgq_nstest unshare +mesgq_nstest_none mesgq_nstest -m none +mesgq_nstest_clone mesgq_nstest -m clone +mesgq_nstest_unshare mesgq_nstest -m unshare msg_comm msg_comm sem_nstest_none sem_nstest none sem_nstest_clone sem_nstest clone diff --git a/testcases/kernel/containers/sysvipc/common.h b/testcases/kernel/containers/sysvipc/common.h new file mode 100644 index 000000000..c70449fd9 --- /dev/null +++ b/testcases/kernel/containers/sysvipc/common.h @@ -0,0 +1,108 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) International Business Machines Corp., 2007 + * Rishikesh K Rajak + * Copyright (C) 2022 SUSE LLC Andrea Cervesato + */ + +#ifndef COMMON_H +#define COMMON_H + +#include +#include "tst_test.h" +#include "lapi/syscalls.h" +#include "lapi/namespaces_constants.h" + +enum { + T_CLONE, + T_UNSHARE, + T_NONE, +}; + +static int dummy_child(void *v) +{ + (void)v; + return 0; +} + +static void check_newipc(void) +{ + int pid, status; + + pid = ltp_clone_quick(CLONE_NEWIPC | SIGCHLD, dummy_child, NULL); + if (pid < 0) + tst_brk(TCONF | TERRNO, "CLONE_NEWIPC not supported"); + + SAFE_WAITPID(pid, &status, 0); +} + +static inline int get_clone_unshare_enum(const char* str_op) +{ + int use_clone; + + if (!strcmp(str_op, "clone")) + use_clone = T_CLONE; + else if (!strcmp(str_op, "unshare")) + use_clone = T_UNSHARE; + else if (!strcmp(str_op, "none")) + use_clone = T_NONE; + else + tst_brk(TBROK, "Test execution mode "); + + return use_clone; +} + +static void clone_test(unsigned long clone_flags, int (*fn1)(void *arg), void *arg1) +{ + int pid; + + pid = ltp_clone_quick(clone_flags | SIGCHLD, fn1, arg1); + if (pid < 0) + tst_brk(TBROK | TERRNO, "ltp_clone_quick error"); +} + +static void unshare_test(unsigned long clone_flags, int (*fn1)(void *arg), void *arg1) +{ + int pid; + + pid = SAFE_FORK(); + + if (!pid) { + int ret; + + SAFE_UNSHARE(clone_flags); + + ret = fn1(arg1); + exit(ret); + } +} + +static void plain_test(int (*fn1)(void *arg), void *arg1) +{ + int pid; + + pid = SAFE_FORK(); + if (!pid) + exit(fn1(arg1)); +} + +static void clone_unshare_test(int use_clone, unsigned long clone_flags, + int (*fn1)(void *arg), void *arg1) +{ + switch (use_clone) { + case T_NONE: + plain_test(fn1, arg1); + break; + case T_CLONE: + clone_test(clone_flags, fn1, arg1); + break; + case T_UNSHARE: + unshare_test(clone_flags, fn1, arg1); + break; + default: + tst_brk(TBROK, "%s: bad use_clone option: %d", __FUNCTION__, use_clone); + break; + } +} + +#endif diff --git a/testcases/kernel/containers/sysvipc/mesgq_nstest.c b/testcases/kernel/containers/sysvipc/mesgq_nstest.c index dbf311dc8..a3ed78f2f 100644 --- a/testcases/kernel/containers/sysvipc/mesgq_nstest.c +++ b/testcases/kernel/containers/sysvipc/mesgq_nstest.c @@ -1,175 +1,114 @@ -/* ************************************************************************* -* Copyright (c) International Business Machines Corp., 2009 -* 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: Veerendra C -* -* In Parent Process , create mesgq with key 154326L -* Now create container by passing 1 of the flag values.. -* Flag = clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC) -* In cloned process, try to access the created mesgq -* Test PASS: If the mesgq is readable when flag is None. -* Test FAIL: If the mesgq is readable when flag is Unshare or Clone. -***************************************************************************/ - -#define _GNU_SOURCE 1 -#include -#include -#include -#include -#include +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) International Business Machines Corp., 2009 + * Veerendra C + * Copyright (C) 2022 SUSE LLC Andrea Cervesato + */ + +/*\ + * [Description] + * + * Test SysV IPC message passing through different namespaces. + * + * [Algorithm] + * + * In parent process create a new mesgq with a specific key. + * In cloned process try to access the created mesgq. + * + * Test will PASS if the mesgq is readable when flag is None. + * Test will FAIL if the mesgq is readable when flag is Unshare or Clone or + * the message received is wrong. + */ + +#define _GNU_SOURCE + +#include #include -#include -#include "test.h" -#include "ipcns_helper.h" - -#define KEY_VAL 154326L -#define UNSHARESTR "unshare" -#define CLONESTR "clone" -#define NONESTR "none" - -char *TCID = "mesgq_nstest"; -int TST_TOTAL = 1; -int p1[2]; -int p2[2]; -struct msg_buf { - long int mtype; /* type of received/sent message */ - char mtext[80]; /* text of the message */ +#include +#include "tst_safe_sysv_ipc.h" +#include "tst_test.h" +#include "common.h" + +#define KEY_VAL 154326L +#define MSG_TYPE 5 +#define MSG_TEXT "My message!" + +static char *str_op = "clone"; +static int use_clone; +static int ipc_id = -1; + +static struct msg_buf { + long mtype; + char mtext[80]; } msg; -void mesgq_read(int id) +static int check_mesgq(LTP_ATTRIBUTE_UNUSED void *vtest) { - int READMAX = 80; - int n; - /* read msg type 5 on the Q; msgtype, flags are last 2 params.. */ + int id, n; - n = msgrcv(id, &msg, READMAX, 5, 0); - if (n == -1) - perror("msgrcv"), tst_exit(); - - tst_resm(TINFO, "Mesg read of %d bytes; Type %ld: Msg: %.*s", - n, msg.mtype, n, msg.mtext); -} + id = msgget(KEY_VAL, 0); -int check_mesgq(void *vtest) -{ - char buf[3]; - int id; + if (id < 0) { + if (use_clone == T_NONE) + tst_res(TFAIL, "Plain cloned process didn't find mesgq"); + else + tst_res(TPASS, "%s: container didn't find mesgq", str_op); + } else { + if (use_clone == T_NONE) + tst_res(TPASS, "Plain cloned process found mesgq inside container"); + else + tst_res(TFAIL, "%s: container init process found mesgq", str_op); - (void) vtest; + n = SAFE_MSGRCV(id, &msg, sizeof(msg.mtext), MSG_TYPE, 0); - close(p1[1]); - close(p2[0]); + tst_res(TINFO, "Mesg read of %d bytes, Type %ld, Msg: %s", n, msg.mtype, msg.mtext); - read(p1[0], buf, 3); - id = msgget(KEY_VAL, 0); - if (id == -1) - write(p2[1], "notfnd", 7); - else { - write(p2[1], "exists", 7); - mesgq_read(id); + if (strcmp(msg.mtext, MSG_TEXT)) + tst_res(TFAIL, "Received the wrong text message"); } - tst_exit(); -} -static void setup(void) -{ - tst_require_root(); - check_newipc(); + return 0; } -int main(int argc, char *argv[]) +static void run(void) { - int ret, use_clone = T_NONE, id, n; - char *tsttype = NONESTR; - char buf[7]; - - setup(); + msg.mtype = MSG_TYPE; + strcpy(msg.mtext, "My message!"); - if (argc != 2) { - tst_resm(TFAIL, "Usage: %s ", argv[0]); - tst_brkm(TFAIL, NULL, " where clone, unshare, or fork specifies" - " unshare method."); - } - - /* Using PIPE's to sync between container and Parent */ - if (pipe(p1) == -1) { - perror("pipe"); - exit(EXIT_FAILURE); - } - if (pipe(p2) == -1) { - perror("pipe"); - exit(EXIT_FAILURE); - } + if (use_clone == T_NONE) + SAFE_MSGSND(ipc_id, &msg, strlen(msg.mtext), 0); - tsttype = NONESTR; + tst_res(TINFO, "mesgq namespaces test: %s", str_op); - 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; - } + clone_unshare_test(use_clone, CLONE_NEWIPC, check_mesgq, NULL); +} - id = msgget(KEY_VAL, IPC_CREAT | IPC_EXCL | 0600); - if (id == -1) { - perror("msgget"); - /* Retry without attempting to create the MQ */ - id = msgget(KEY_VAL, 0); - if (id == -1) - perror("msgget failure"), exit(1); - } +static void setup(void) +{ + use_clone = get_clone_unshare_enum(str_op); - msg.mtype = 5; - strcpy(msg.mtext, "Message of type 5!"); - n = msgsnd(id, &msg, strlen(msg.mtext), 0); - if (n == -1) - perror("msgsnd"), tst_exit(); - - tst_resm(TINFO, "mesgq namespaces test : %s", tsttype); - /* fire off the test */ - ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_mesgq, NULL); - if (ret < 0) { - tst_brkm(TFAIL, NULL, "%s failed", tsttype); - } + if (use_clone != T_NONE) + check_newipc(); - close(p1[0]); - close(p2[1]); - write(p1[1], "go", 3); + ipc_id = SAFE_MSGGET(KEY_VAL, IPC_CREAT | IPC_EXCL | 0600); +} - read(p2[0], buf, 7); - if (strcmp(buf, "exists") == 0) { - if (use_clone == T_NONE) - tst_resm(TPASS, "Plain cloned process found mesgq " - "inside container"); - else - tst_resm(TFAIL, - "%s: Container init process found mesgq", - tsttype); - } else { - if (use_clone == T_NONE) - tst_resm(TFAIL, - "Plain cloned process didn't find mesgq"); - else - tst_resm(TPASS, "%s: Container didn't find mesgq", - tsttype); +static void cleanup(void) +{ + if (ipc_id != -1) { + tst_res(TINFO, "Destroy message"); + SAFE_MSGCTL(ipc_id, IPC_RMID, NULL); } - - /* Delete the mesgQ */ - id = msgget(KEY_VAL, 0); - msgctl(id, IPC_RMID, NULL); - - tst_exit(); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .forks_child = 1, + .options = (struct tst_option[]) { + { "m:", &str_op, "Test execution mode " }, + {}, + }, +}; From patchwork Tue Mar 15 10:32:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605533 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=pIQEbuwV; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=5OtpHwEL; 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)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KHqWC03wLz9sFn for ; Tue, 15 Mar 2022 21:33:26 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C3CD13C20CC for ; Tue, 15 Mar 2022 11:33:24 +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 [IPv6:2001:4b78:1:20::3]) (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 89E253C91FC for ; Tue, 15 Mar 2022 11:33:00 +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-3.smtp.seeweb.it (Postfix) with ESMTPS id C25661A00A5D for ; Tue, 15 Mar 2022 11:32:59 +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 3319821906; Tue, 15 Mar 2022 10:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647340379; 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=86yzZ9WBnOoSJy1Amjal3Yn0YUIKOGZ+w4ebCdaVk+M=; b=pIQEbuwVGd4JIMTUuoI7qj4JdwfXAH+W97Jh8JfD/Bay0vPvL4QZK+YMhXN16pLQqBmDmC MjzU8C9WnL4N8EZzTLyTI9/Af/kNlBAn5hRXJQOJR6gGJnXZtslOffhrZ8YuQaQvywqIIf avHKMWuUGePxP2UtnT1tbVNJUXSJIJ8= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647340379; 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=86yzZ9WBnOoSJy1Amjal3Yn0YUIKOGZ+w4ebCdaVk+M=; b=5OtpHwELKQDQ77lCw33P/9+TSLa66XSq1S87gvBcw60r5IaUDybWRzpYNJACY4tFEpFa3v Gv+izWIpZu8nXvAQ== 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 BE06413B59; Tue, 15 Mar 2022 10:32:58 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id wAgtKFprMGKHHwAAMHmgww (envelope-from ); Tue, 15 Mar 2022 10:32:58 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Tue, 15 Mar 2022 11:32:46 +0100 Message-Id: <20220315103254.7185-3-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-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, T_SCC_BODY_TEXT_LINE 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 v3 02/10] Rewrite msg_comm.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" Signed-off-by: Andrea Cervesato --- .../kernel/containers/sysvipc/msg_comm.c | 180 ++++++------------ 1 file changed, 55 insertions(+), 125 deletions(-) diff --git a/testcases/kernel/containers/sysvipc/msg_comm.c b/testcases/kernel/containers/sysvipc/msg_comm.c index 0da328997..674922159 100644 --- a/testcases/kernel/containers/sysvipc/msg_comm.c +++ b/testcases/kernel/containers/sysvipc/msg_comm.c @@ -1,20 +1,16 @@ -/* Copyright (c) 2014 Red Hat, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of version 2 the GNU General Public License as - * published by the Free Software Foundation. +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2014 Red Hat, Inc. + * Copyright (C) 2022 SUSE LLC Andrea Cervesato + */ + +/*\ + * [Description] * - * 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. + * Test SysV IPC message passing through different processes. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - *********************************************************************** - * File: msg_comm.c + * [Algorithm] * - * Description: * 1. Clones two child processes with CLONE_NEWIPC flag, each child * gets System V message queue (msg) with the _identical_ key. * 2. Child1 appends a message with identifier #1 to the message queue. @@ -27,152 +23,86 @@ */ #define _GNU_SOURCE -#include + +#include #include #include -#include -#include -#include -#include "ipcns_helper.h" -#include "test.h" -#include "safe_macros.h" +#include "tst_safe_sysv_ipc.h" +#include "tst_test.h" +#include "common.h" #define TESTKEY 124426L -#define MSGSIZE 50 -char *TCID = "msg_comm"; -int TST_TOTAL = 1; struct sysv_msg { long mtype; - char mtext[MSGSIZE]; + char mtext[1]; }; -static void cleanup(void) +static int chld1_msg(LTP_ATTRIBUTE_UNUSED void *arg) { - tst_rmdir(); -} - -static void setup(void) -{ - tst_require_root(); - check_newipc(); - tst_tmpdir(); - TST_CHECKPOINT_INIT(tst_rmdir); -} - -int chld1_msg(void *arg) -{ - int id, n, rval = 0; + int id; struct sysv_msg m; struct sysv_msg rec; - id = msgget(TESTKEY, IPC_CREAT | 0600); - if (id == -1) { - perror("msgget"); - return 2; - } + id = SAFE_MSGGET(TESTKEY, IPC_CREAT | 0600); m.mtype = 1; m.mtext[0] = 'A'; - if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) { - perror("msgsnd"); - msgctl(id, IPC_RMID, NULL); - return 2; - } - /* wait for child2 to write into the message queue */ - TST_SAFE_CHECKPOINT_WAIT(NULL, 0); + SAFE_MSGSND(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0); + + TST_CHECKPOINT_WAIT(0); + + TEST(msgrcv(id, &rec, sizeof(struct sysv_msg) - sizeof(long), 2, IPC_NOWAIT)); + if (TST_RET < 0 && TST_ERR != ENOMSG) + tst_brk(TBROK | TERRNO, "msgrcv error"); /* if child1 message queue has changed (by child2) report fail */ - n = msgrcv(id, &rec, sizeof(struct sysv_msg) - sizeof(long), - 2, IPC_NOWAIT); - if (n == -1 && errno != ENOMSG) { - perror("msgrcv"); - msgctl(id, IPC_RMID, NULL); - return 2; - } - /* if mtype #2 was found in the message queue, it is fail */ - if (n > 0) { - rval = 1; - } - - /* tell child2 to continue */ - TST_SAFE_CHECKPOINT_WAKE(NULL, 0); - - msgctl(id, IPC_RMID, NULL); - return rval; + if (TST_RET > 0) + tst_res(TFAIL, "messages leak between namespacess"); + else + tst_res(TPASS, "messages does not leak between namespaces"); + + TST_CHECKPOINT_WAKE(0); + + SAFE_MSGCTL(id, IPC_RMID, NULL); + + return 0; } -int chld2_msg(void *arg) +static int chld2_msg(LTP_ATTRIBUTE_UNUSED void *arg) { int id; struct sysv_msg m; - id = msgget(TESTKEY, IPC_CREAT | 0600); - if (id == -1) { - perror("msgget"); - return 2; - } + id = SAFE_MSGGET(TESTKEY, IPC_CREAT | 0600); m.mtype = 2; m.mtext[0] = 'B'; - if (msgsnd(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0) == -1) { - perror("msgsnd"); - msgctl(id, IPC_RMID, NULL); - return 2; - } - /* tell child1 to continue and wait for it */ - TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0); + SAFE_MSGSND(id, &m, sizeof(struct sysv_msg) - sizeof(long), 0); + + TST_CHECKPOINT_WAKE_AND_WAIT(0); + + SAFE_MSGCTL(id, IPC_RMID, NULL); - msgctl(id, IPC_RMID, NULL); return 0; } -static void test(void) +static void run(void) { - int status, ret = 0; - - ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_msg, NULL); - if (ret == -1) - tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); - - ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_msg, NULL); - if (ret == -1) - tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); - - - while (wait(&status) > 0) { - if (WIFEXITED(status) && WEXITSTATUS(status) == 1) - ret = 1; - if (WIFEXITED(status) && WEXITSTATUS(status) == 2) - tst_brkm(TBROK | TERRNO, cleanup, "error in child"); - if (WIFSIGNALED(status)) { - tst_resm(TFAIL, "child was killed with signal %s", - tst_strsig(WTERMSIG(status))); - return; - } - } - - if (ret) - tst_resm(TFAIL, "SysV msg: communication with identical keys" - " between namespaces"); - else - tst_resm(TPASS, "SysV msg: communication with identical keys" - " between namespaces"); + clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_msg, NULL); + clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_msg, NULL); } -int main(int argc, char *argv[]) +static void setup(void) { - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) - test(); - - cleanup(); - tst_exit(); + check_newipc(); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, + .needs_checkpoints = 1, +}; From patchwork Tue Mar 15 10:32:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605534 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=gzpiDNmU; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=7MNia9R8; 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 4KHqWR2TCPz9sFn for ; Tue, 15 Mar 2022 21:33:39 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 44F3D3C9346 for ; Tue, 15 Mar 2022 11:33:35 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [217.194.8.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id E7DC33C91FE for ; Tue, 15 Mar 2022 11:33:00 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 60930600120 for ; Tue, 15 Mar 2022 11:33:00 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id E1B801F37E; Tue, 15 Mar 2022 10:32:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647340379; 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=C6iBPr2FHmcincmnnZPRMXZ4euf6dwft8b5fE9Advak=; b=gzpiDNmUCb9xG8hnx5IWEfXQVqCm6wsBtS1iPwsbtINvPpst0HNHV9cCOdwzWnEplHK/bT HzwJGhhH67vBBk2GRHUyTewpV8o/zaKtpK3SznRasJvkzas029H1+m/vELLzeO1k4ZCDTg t7pw9Nmn/JbkyCAmu3056+KMCi8dWQ0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647340379; 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=C6iBPr2FHmcincmnnZPRMXZ4euf6dwft8b5fE9Advak=; b=7MNia9R8fGaUKFneZttQNF5N8txs8W6ciUlWTq47EhQxUvviGyFNWwgAvtmqqChXL8vV9P 528TVOcHK0xxMuBw== 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 5F1C513B59; Tue, 15 Mar 2022 10:32:59 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id KAuYEVtrMGKHHwAAMHmgww (envelope-from ); Tue, 15 Mar 2022 10:32:59 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Tue, 15 Mar 2022 11:32:47 +0100 Message-Id: <20220315103254.7185-4-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-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v3 03/10] Rewrite sem_comm.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" Signed-off-by: Andrea Cervesato --- .../kernel/containers/sysvipc/sem_comm.c | 180 ++++++------------ 1 file changed, 56 insertions(+), 124 deletions(-) diff --git a/testcases/kernel/containers/sysvipc/sem_comm.c b/testcases/kernel/containers/sysvipc/sem_comm.c index a2c354a08..854452528 100644 --- a/testcases/kernel/containers/sysvipc/sem_comm.c +++ b/testcases/kernel/containers/sysvipc/sem_comm.c @@ -1,20 +1,16 @@ -/* Copyright (c) 2014 Red Hat, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of version 2 the GNU General Public License as - * published by the Free Software Foundation. +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2014 Red Hat, Inc. + * Copyright (C) 2022 SUSE LLC Andrea Cervesato + */ + +/*\ + * [Description] * - * 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. + * Test SysV IPC semaphore usage between cloned processes. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - *********************************************************************** - * File: sem_comm.c + * [Algorithm] * - * Description: * 1. Clones two child processes with CLONE_NEWIPC flag, each child * creates System V semaphore (sem) with the _identical_ key. * 2. Child1 locks the semaphore. @@ -26,166 +22,102 @@ */ #define _GNU_SOURCE -#include -#include + #include -#include -#include -#include "ipcns_helper.h" -#include "test.h" -#include "safe_macros.h" +#include +#include +#include "tst_safe_sysv_ipc.h" +#include "tst_test.h" #include "lapi/sem.h" +#include "common.h" #define TESTKEY 124426L -char *TCID = "sem_comm"; -int TST_TOTAL = 1; - -static void cleanup(void) -{ - tst_rmdir(); -} - -static void setup(void) -{ - tst_require_root(); - check_newipc(); - tst_tmpdir(); - TST_CHECKPOINT_INIT(tst_rmdir); -} -int chld1_sem(void *arg) +static int chld1_sem(LTP_ATTRIBUTE_UNUSED void *arg) { int id; union semun su; struct sembuf sm; - id = semget(TESTKEY, 1, IPC_CREAT); - if (id == -1) { - perror("semget"); - return 2; - } + id = SAFE_SEMGET(TESTKEY, 1, IPC_CREAT); su.val = 1; - if (semctl(id, 0, SETVAL, su) == -1) { - perror("semctl"); - semctl(id, 0, IPC_RMID); - return 2; - } + SAFE_SEMCTL(id, 0, SETVAL, su); /* tell child2 to continue and wait for it to create the semaphore */ - TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0); + TST_CHECKPOINT_WAKE_AND_WAIT(0); sm.sem_num = 0; sm.sem_op = -1; sm.sem_flg = IPC_NOWAIT; - if (semop(id, &sm, 1) == -1) { - perror("semop"); - semctl(id, 0, IPC_RMID); - return 2; - } + SAFE_SEMOP(id, &sm, 1); /* tell child2 to continue and wait for it to lock the semaphore */ - TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0); + TST_CHECKPOINT_WAKE_AND_WAIT(0); sm.sem_op = 1; - semop(id, &sm, 1); + SAFE_SEMOP(id, &sm, 1); + + SAFE_SEMCTL(id, 0, IPC_RMID); - semctl(id, 0, IPC_RMID); return 0; } -int chld2_sem(void *arg) +static int chld2_sem(LTP_ATTRIBUTE_UNUSED void *arg) { - int id, rval = 0; + int id; struct sembuf sm; union semun su; /* wait for child1 to create the semaphore */ - TST_SAFE_CHECKPOINT_WAIT(NULL, 0); + TST_CHECKPOINT_WAIT(0); - id = semget(TESTKEY, 1, IPC_CREAT); - if (id == -1) { - perror("semget"); - return 2; - } + id = SAFE_SEMGET(TESTKEY, 1, IPC_CREAT); su.val = 1; - if (semctl(id, 0, SETVAL, su) == -1) { - perror("semctl"); - semctl(id, 0, IPC_RMID); - return 2; - } + SAFE_SEMCTL(id, 0, SETVAL, su); /* tell child1 to continue and wait for it to lock the semaphore */ - TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0); + TST_CHECKPOINT_WAKE_AND_WAIT(0); sm.sem_num = 0; sm.sem_op = -1; sm.sem_flg = IPC_NOWAIT; - if (semop(id, &sm, 1) == -1) { - if (errno == EAGAIN) { - rval = 1; - } else { - perror("semop"); - semctl(id, 0, IPC_RMID); - return 2; - } + TEST(semop(id, &sm, 1)); + if (TST_RET < 0) { + if (TST_ERR != EAGAIN) + tst_brk(TBROK | TERRNO, "semop error"); + + tst_res(TFAIL, "can't lock semaphore between namespaces"); + } else { + tst_res(TPASS, "locked semaphore between namespaces"); } /* tell child1 to continue */ - TST_SAFE_CHECKPOINT_WAKE(NULL, 0); + TST_CHECKPOINT_WAKE(0); sm.sem_op = 1; - semop(id, &sm, 1); + SAFE_SEMOP(id, &sm, 1); + + SAFE_SEMCTL(id, 0, IPC_RMID); - semctl(id, 0, IPC_RMID); - return rval; + return 0; } -static void test(void) +static void run(void) { - int status, ret = 0; - - ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_sem, NULL); - if (ret == -1) - tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); - - ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_sem, NULL); - if (ret == -1) - tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); - - - while (wait(&status) > 0) { - if (WIFEXITED(status) && WEXITSTATUS(status) == 1) - ret = 1; - if (WIFEXITED(status) && WEXITSTATUS(status) == 2) - tst_brkm(TBROK | TERRNO, cleanup, "error in child"); - if (WIFSIGNALED(status)) { - tst_resm(TFAIL, "child was killed with signal %s", - tst_strsig(WTERMSIG(status))); - return; - } - } - - if (ret) - tst_resm(TFAIL, "SysV sem: communication with identical keys" - " between namespaces"); - else - tst_resm(TPASS, "SysV sem: communication with identical keys" - " between namespaces"); + clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_sem, NULL); + clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_sem, NULL); } -int main(int argc, char *argv[]) +static void setup(void) { - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) - test(); - - cleanup(); - tst_exit(); + check_newipc(); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, + .needs_checkpoints = 1, +}; From patchwork Tue Mar 15 10:32:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605536 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=Cjhiyjb1; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=DoPm4yns; 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)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KHqWf1bprz9sFn for ; Tue, 15 Mar 2022 21:33:50 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 183BA3C934A for ; Tue, 15 Mar 2022 11:33:48 +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 4B6D33C933A 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 5632D6008EA for ; Tue, 15 Mar 2022 11:33:01 +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 B84C321906; Tue, 15 Mar 2022 10:33:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647340380; 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=OfDKvQ+V5qAq8+O2XbbZFWZ/QmHHyoUaZyhUEcj8mIg=; b=Cjhiyjb17EarvVOm6YH22rS2EC8BSpybG/SnoF9Jv+JTrFGRD8Awo4MmTmE9rtYuZgM1w8 YFooaRkp9hh3mwzHCMu1qaJ231CT6NbLRtCFjwjn07jYE0WT5T2GcRd5vPYbvqQJeN9+hI Qr99kJUwUJx+QxLQEceT5Jelpxp67uw= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647340380; 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=OfDKvQ+V5qAq8+O2XbbZFWZ/QmHHyoUaZyhUEcj8mIg=; b=DoPm4ynsmoWVdZMBd8Y25Em7SZT0LgSBuSf0N5+QytLB8A46CcuV6PpvhHcrTOfXy/4tNG BQTQpq8vxzLrWVDw== 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 19AB413B59; Tue, 15 Mar 2022 10:33:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id QItrAFxrMGKHHwAAMHmgww (envelope-from ); Tue, 15 Mar 2022 10:33:00 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Tue, 15 Mar 2022 11:32:48 +0100 Message-Id: <20220315103254.7185-5-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 04/10] Rewrite sem_nstest.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 sem_nstest.c options. Signed-off-by: Andrea Cervesato --- runtest/containers | 6 +- .../kernel/containers/sysvipc/sem_nstest.c | 210 ++++++------------ 2 files changed, 76 insertions(+), 140 deletions(-) diff --git a/runtest/containers b/runtest/containers index d863c10a4..4f56b1b4d 100644 --- a/runtest/containers +++ b/runtest/containers @@ -54,9 +54,9 @@ mesgq_nstest_none mesgq_nstest -m none mesgq_nstest_clone mesgq_nstest -m clone mesgq_nstest_unshare mesgq_nstest -m unshare msg_comm msg_comm -sem_nstest_none sem_nstest none -sem_nstest_clone sem_nstest clone -sem_nstest_unshare sem_nstest unshare +sem_nstest_none sem_nstest -m none +sem_nstest_clone sem_nstest -m clone +sem_nstest_unshare sem_nstest -m unshare semtest_2ns_none semtest_2ns none semtest_2ns_clone semtest_2ns clone semtest_2ns_unshare semtest_2ns unshare diff --git a/testcases/kernel/containers/sysvipc/sem_nstest.c b/testcases/kernel/containers/sysvipc/sem_nstest.c index 72e04fe4f..ce927ca91 100644 --- a/testcases/kernel/containers/sysvipc/sem_nstest.c +++ b/testcases/kernel/containers/sysvipc/sem_nstest.c @@ -1,158 +1,94 @@ -/* ************************************************************************* -* Copyright (c) International Business Machines Corp., 2009 -* 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: Veerendra C -* -* In Parent Process , create semaphore with key 154326L -* Now create container by passing 1 of the below flag values.. -* clone(NONE), clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC) -* In cloned process, try to access the created semaphore -* Test PASS: If the semaphore is readable when flag is None. -* Test FAIL: If the semaphore is readable when flag is Unshare or Clone. -***************************************************************************/ - -#define _GNU_SOURCE 1 -#include -#include -#include -#include -#include +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) International Business Machines Corp., 2009 + * Veerendra C + * Copyright (C) 2022 SUSE LLC Andrea Cervesato + */ + +/*\ + * [Description] + * + * Test SysV IPC semaphore usage between namespaces. + * + * [Algorithm] + * + * In parent process create a new semaphore with a specific key. + * In cloned process, try to access the created semaphore + * + * Test PASS if the semaphore is readable when flag is None. + * Test FAIL if the semaphore is readable when flag is Unshare or Clone. + */ + +#define _GNU_SOURCE + +#include +#include +#include #include -#include -#include "test.h" -#include "ipcns_helper.h" +#include "tst_safe_sysv_ipc.h" +#include "tst_test.h" +#include "common.h" -#define MY_KEY 154326L -#define UNSHARESTR "unshare" -#define CLONESTR "clone" -#define NONESTR "none" +#define MY_KEY 154326L -char *TCID = "sem_nstest"; -int TST_TOTAL = 1; -int p1[2]; -int p2[2]; +static char *str_op = "clone"; +static int use_clone; +static int ipc_id = -1; -int check_semaphore(void *vtest) +static int check_semaphore(LTP_ATTRIBUTE_UNUSED void *vtest) { - char buf[3]; int id; - (void) vtest; + id = semget(MY_KEY, 1, 0); - close(p1[1]); - close(p2[0]); + if (id < 0) { + if (use_clone == T_NONE) + tst_res(TFAIL, "Plain cloned process didn't find semaphore"); + else + tst_res(TPASS, "%s: container didn't find semaphore", str_op); + } else { + tst_res(TINFO, "PID %d: fetched existing semaphore..id = %d", getpid(), id); - read(p1[0], buf, 3); - id = semget(MY_KEY, 1, 0); - if (id == -1) - write(p2[1], "notfnd", 7); - else { - write(p2[1], "exists", 7); - tst_resm(TINFO, "PID %d: Fetched existing semaphore..id = %d", - getpid(), id); + if (use_clone == T_NONE) + tst_res(TPASS, "Plain cloned process found semaphore inside container"); + else + tst_res(TFAIL, "%s: Container init process found semaphore", 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_semaphore, NULL); } -int main(int argc, char *argv[]) +static void setup(void) { - int ret, use_clone = T_NONE, 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."); - } - - /* Using PIPE's to sync between container and Parent */ - if (pipe(p1) == -1) { - perror("pipe"); - exit(EXIT_FAILURE); - } - if (pipe(p2) == -1) { - perror("pipe"); - exit(EXIT_FAILURE); - } + use_clone = get_clone_unshare_enum(str_op); - 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; - } - - /* 1. Create (or fetch if existing) the binary semaphore */ - id = semget(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666); - if (id == -1) { - perror("Semaphore create"); - if (errno != EEXIST) { - perror("semget failure"); - tst_brkm(TBROK, NULL, "Semaphore creation failed"); - } - id = semget(MY_KEY, 1, 0); - if (id == -1) { - perror("Semaphore create"); - tst_brkm(TBROK, NULL, "Semaphore operation failed"); - } - } - - tst_resm(TINFO, "Semaphore namespaces Isolation test : %s", tsttype); - /* fire off the test */ - ret = - do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_semaphore, - NULL); - if (ret < 0) { - tst_brkm(TFAIL, NULL, "%s failed", tsttype); - } + if (use_clone != T_NONE) + check_newipc(); - close(p1[0]); - close(p2[1]); - write(p1[1], "go", 3); - read(p2[0], buf, 7); + ipc_id = SAFE_SEMGET(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666); +} - if (strcmp(buf, "exists") == 0) { - if (use_clone == T_NONE) - tst_resm(TPASS, "Plain cloned process found semaphore " - "inside container"); - else - tst_resm(TFAIL, - "%s: Container init process found semaphore", - tsttype); - } else { - if (use_clone == T_NONE) - tst_resm(TFAIL, - "Plain cloned process didn't find semaphore"); - else - tst_resm(TPASS, "%s: Container didn't find semaphore", - tsttype); +static void cleanup(void) +{ + if (ipc_id != -1) { + tst_res(TINFO, "Delete semaphore"); + SAFE_SEMCTL(ipc_id, IPC_RMID, 0); } - - /* Delete the semaphore */ - id = semget(MY_KEY, 1, 0); - semctl(id, IPC_RMID, 0); - - tst_exit(); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .forks_child = 1, + .options = (struct tst_option[]) { + { "m:", &str_op, "Test execution mode " }, + {}, + }, +}; From patchwork Tue Mar 15 10:32:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605537 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=EcJ5gj9V; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=PRAezejb; 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 4KHqWt2sRRz9sFn for ; Tue, 15 Mar 2022 21:34:02 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 9D48D3C20CC for ; Tue, 15 Mar 2022 11:33:59 +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) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 8F2473C9347 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 A27F86008F6 for ; Tue, 15 Mar 2022 11:33:01 +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 44A7E2191E; 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=ZFtjcF3xAvUULgwgsk73NPlNNY9NuYh+P1YiaEq3khQ=; b=EcJ5gj9VAYOSHm0HucmMthmdpYk7M8qN6XXy9VY2lVhUzwZ16TrO77g6OigvJ8J0wwBfEh TyaZGXEkm5T0Vk0+l8h4o8UsDXJI+HVVCmhPEbHiYD9p+6sY8ZFtYSusa4OYRAO1lAuDDK o2gYbS6JXVoLeKmOlBQ3pg8xapWuBmk= 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=ZFtjcF3xAvUULgwgsk73NPlNNY9NuYh+P1YiaEq3khQ=; b=PRAezejbN82jqRYu9AuEJxNXhSnGEOMN9HWBmEmDkK9kXGm2z5i9p3uV7T0aPrxeVmClnV NAuhRsr34XPL9pBw== 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 E187213B59; Tue, 15 Mar 2022 10:33:00 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id UAYyMVxrMGKHHwAAMHmgww (envelope-from ); Tue, 15 Mar 2022 10:33:00 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Tue, 15 Mar 2022 11:32:49 +0100 Message-Id: <20220315103254.7185-6-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 05/10] Rewrite semtest_2ns.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 semtest_2ns.c options. Signed-off-by: Andrea Cervesato --- runtest/containers | 6 +- .../kernel/containers/sysvipc/semtest_2ns.c | 326 +++++++----------- 2 files changed, 127 insertions(+), 205 deletions(-) diff --git a/runtest/containers b/runtest/containers index 4f56b1b4d..3130ccfbd 100644 --- a/runtest/containers +++ b/runtest/containers @@ -57,9 +57,9 @@ msg_comm msg_comm sem_nstest_none sem_nstest -m none sem_nstest_clone sem_nstest -m clone sem_nstest_unshare sem_nstest -m unshare -semtest_2ns_none semtest_2ns none -semtest_2ns_clone semtest_2ns clone -semtest_2ns_unshare semtest_2ns unshare +semtest_2ns_none semtest_2ns -m none +semtest_2ns_clone semtest_2ns -m clone +semtest_2ns_unshare semtest_2ns -m unshare sem_comm sem_comm utstest_unshare_1 utstest unshare 1 diff --git a/testcases/kernel/containers/sysvipc/semtest_2ns.c b/testcases/kernel/containers/sysvipc/semtest_2ns.c index c3483b675..d1eb5d8ff 100644 --- a/testcases/kernel/containers/sysvipc/semtest_2ns.c +++ b/testcases/kernel/containers/sysvipc/semtest_2ns.c @@ -1,230 +1,152 @@ -/* ************************************************************************* -* Copyright (c) International Business Machines Corp., 2009 -* 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: Veerendra C -* -* Test Assertion: -* This testcase verifies the semaphore isoloation in 2 diff containers. -* It tries to create/access a semaphore created with the same KEY. -* -* Description: -* Create 2 'containers' with the below flag value -* Flag = clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC) -* In Cont1, create semaphore with key 124326L -* In Cont2, try to access the semaphore created in Cont1. -* PASS : -* If flag = None and the semaphore is accessible in Cont2. -* If flag = unshare/clone and the semaphore is not accessible in Cont2. -* If semaphore is not accessible in Cont2, creates new semaphore with -* the same key to double check isloation in IPCNS. -* -* FAIL : -* If flag = none and the semaphore is not accessible. -* If flag = unshare/clone and semaphore is accessible in Cont2. -* If the new semaphore creation Fails. -***************************************************************************/ - -#define _GNU_SOURCE 1 -#include -#include -#include -#include -#include -#include -#include -#include "test.h" -#include "ipcns_helper.h" - -#define MY_KEY 124326L -#define UNSHARESTR "unshare" -#define CLONESTR "clone" -#define NONESTR "none" - -char *TCID = "semtest_2ns"; -int TST_TOTAL = 1; -int p1[2]; -int p2[2]; -static struct sembuf semop_lock[2] = { - /* sem_num, sem_op, flag */ - {0, 0, 0}, /* wait for sem#0 to become 0 */ - {0, 1, SEM_UNDO} /* then increment sem#0 by 1 */ -}; - -static struct sembuf semop_unlock[1] = { - /* sem_num, sem_op, flag */ - {0, -1, (IPC_NOWAIT | SEM_UNDO)} /* decrement sem#0 by 1 (sets it to 0) */ -}; - +// SPDX-License-Identifier: GPL-2.0-or-later /* - * sem_lock() - Locks the semaphore for crit-sec updation, and unlocks it later + * Copyright (c) International Business Machines Corp., 2009 + * Veerendra C + * Copyright (C) 2022 SUSE LLC Andrea Cervesato */ -void sem_lock(int id) -{ - /* Checking the semlock and simulating as if the crit-sec is updated */ - if (semop(id, &semop_lock[0], 2) < 0) { - perror("sem lock error"); - tst_brkm(TBROK, NULL, "semop failed"); - } - tst_resm(TINFO, "Sem1: File locked, Critical section is updated..."); - sleep(2); - if (semop(id, &semop_unlock[0], 1) < 0) { - perror("sem unlock error"); - tst_brkm(TBROK, NULL, "semop failed"); - } -} -/* - * check_sem1 - does not read -- it writes to check_sem2() when it's done. +/*\ + * [Description] + * + * Test SysV IPC semaphore usage between namespaces and processes. + * + * [Algorithm] + * + * Create 2 'containers' + * In container1 create semaphore with a specific key and lock it + * In container2 try to access the semaphore created in container1 and try to + * unlock it. + * + * If mode = None, test will PASS when semaphore created process1 can be read + * and unlocked from process2. + * If mode = Clone, test will PASS when semaphore created in container1 can't + * be accessed from container2. + * If mode = Unshare, test will PASS when semaphore created in container2 can't + * be accessed from container2. */ -int check_sem1(void *vtest) -{ - int id1; - - (void) vtest; - - close(p1[0]); - /* 1. Create (or fetch if existing) the binary semaphore */ - id1 = semget(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666); - if (id1 == -1) { - perror("Semaphore create"); - if (errno != EEXIST) { - perror("semget failure"); - tst_brkm(TBROK, NULL, "semget failure"); - } - id1 = semget(MY_KEY, 1, 0); - if (id1 == -1) { - perror("Semaphore create"); - tst_brkm(TBROK, NULL, "semget failure"); - } - } - write(p1[1], "go", 3); - tst_resm(TINFO, "Cont1: Able to create semaphore"); - tst_exit(); -} +#define _GNU_SOURCE -/* - * check_sem2() reads from check_sem1() and writes to main() when it's done. - */ +#include +#include +#include +#include +#include "tst_safe_sysv_ipc.h" +#include "tst_test.h" +#include "common.h" -int check_sem2(void *vtest) +#define MY_KEY 124326L + +static char *str_op = "clone"; +static int use_clone; + +static int check_sem1(LTP_ATTRIBUTE_UNUSED void *vtest) { - char buf[3]; - int id2; + int id; + struct sembuf sm; - (void) vtest; + id = SAFE_SEMGET(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666); - close(p1[1]); - close(p2[0]); - read(p1[0], buf, 3); + tst_res(TINFO, "%s: created key in child1", str_op); - id2 = semget(MY_KEY, 1, 0); - if (id2 != -1) { - sem_lock(id2); - write(p2[1], "exists", 7); - } else { - /* Trying to create a new semaphore, if semaphore is not existing */ - id2 = semget(MY_KEY, 1, IPC_CREAT | IPC_EXCL | 0666); - if (id2 == -1) { - perror("Semaphore create"); - if (errno != EEXIST) { - perror("semget failure"); - tst_resm(TBROK, "semget failure"); - } - } else - tst_resm(TINFO, - "Cont2: Able to create semaphore with sameKey"); - /* Passing the pipe Not-found mesg */ - write(p2[1], "notfnd", 7); - } + TST_CHECKPOINT_WAKE_AND_WAIT(0); - tst_exit(); -} + tst_res(TINFO, "Lock semaphore in container1"); + sm.sem_num = 0; + sm.sem_op = 1; + sm.sem_flg = SEM_UNDO; + SAFE_SEMOP(id, &sm, 1); -static void setup(void) -{ - tst_require_root(); - check_newipc(); + TST_CHECKPOINT_WAKE_AND_WAIT(0); + + return 0; } -int main(int argc, char *argv[]) +static int check_sem2(LTP_ATTRIBUTE_UNUSED void *vtest) { - int ret, id, use_clone = T_NONE; - char *tsttype = NONESTR; - char buf[7]; + int id; + struct sembuf sm; - setup(); + TST_CHECKPOINT_WAIT(0); - if (argc != 2) { - tst_resm(TINFO, "Usage: %s ", argv[0]); - tst_resm(TINFO, " where clone, unshare, or fork specifies" - " unshare method."); - tst_exit(); - } + tst_res(TINFO, "%s: reading key in child2", str_op); - /* Using PIPE's to sync between container and Parent */ - if (pipe(p1) == -1) { - perror("pipe1"); - tst_exit(); - } - if (pipe(p2) == -1) { - perror("pipe2"); - tst_exit(); + id = semget(MY_KEY, 1, 0); + if (id >= 0) { + if (use_clone == T_NONE) + tst_res(TPASS, "Plain cloned process able to access the semaphore created"); + else + tst_res(TFAIL, "%s: In namespace2 found semaphore created in namespace1", str_op); + } else { + if (use_clone == T_NONE) + tst_res(TFAIL, "Plain cloned process didn't find semaphore"); + else + tst_res(TPASS, "%s: In namespace2 unable to access semaphore created in namespace1", str_op); } - 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; + TST_CHECKPOINT_WAKE_AND_WAIT(0); + + if (id >= 0) { + tst_res(TINFO, "Trying to unlock semaphore in container2"); + sm.sem_num = 0; + sm.sem_op = -1; + sm.sem_flg = IPC_NOWAIT | SEM_UNDO; + TEST(semop(id, &sm, 1)); + + if (TST_RET >= 0) { + if (use_clone == T_NONE) + tst_res(TPASS, "Plain cloned process able to unlock semaphore"); + else + tst_res(TFAIL, "%s: In namespace2 able to unlock the semaphore created in an namespace1", str_op); + } else { + if (use_clone == T_NONE) + tst_res(TFAIL, "Plain cloned process unable to unlock semaphore"); + else + tst_res(TPASS, "%s: In namespace2 unable to unlock the semaphore created in an namespace1", str_op); + } + + SAFE_SEMCTL(id, IPC_RMID, 0); } - tst_resm(TINFO, "Semaphore Namespaces Test : %s", tsttype); + TST_CHECKPOINT_WAKE(0); - /* Create 2 containers */ - ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem1, NULL); - if (ret < 0) { - tst_brkm(TFAIL, NULL, "clone/unshare failed"); - } + return 0; +} - ret = do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem2, NULL); - if (ret < 0) { - tst_brkm(TFAIL, NULL, "clone/unshare failed"); - } - close(p2[1]); - read(p2[0], buf, 7); +static void run(void) +{ + clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem1, NULL); + clone_unshare_test(use_clone, CLONE_NEWIPC, check_sem2, NULL); +} + +static void setup(void) +{ + use_clone = get_clone_unshare_enum(str_op); + + if (use_clone != T_NONE) + check_newipc(); +} + +static void cleanup(void) +{ + int id; - if (strcmp(buf, "exists") == 0) - if (use_clone == T_NONE) - tst_resm(TPASS, - "Plain cloned process able to access the semaphore " - "created"); - else - tst_resm(TFAIL, - "%s : In namespace2 found the semaphore " - "created in Namespace1", tsttype); - else if (use_clone == T_NONE) - tst_resm(TFAIL, "Plain cloned process didn't find semaphore"); - else - tst_resm(TPASS, - "%s : In namespace2 unable to access the semaphore " - "created in Namespace1", tsttype); - - /* Delete the semaphore */ id = semget(MY_KEY, 1, 0); - semctl(id, IPC_RMID, 0); - tst_exit(); + if (id >= 0) { + tst_res(TINFO, "Destroy semaphore"); + SAFE_SEMCTL(id, IPC_RMID, 0); + } } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, + .forks_child = 1, + .needs_checkpoints = 1, + .options = (struct tst_option[]) { + { "m:", &str_op, "Test execution mode " }, + {}, + }, +}; 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 " }, + {}, + }, +}; From patchwork Tue Mar 15 10:32:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605540 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=IrFAtCRd; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Ga/TYzSZ; 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 4KHqXG5CvJz9sFn for ; Tue, 15 Mar 2022 21:34:22 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E1C0B3C9204 for ; Tue, 15 Mar 2022 11:34:19 +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 [IPv6:2001:4b78:1:20::3]) (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 7D7393C934A for ; Tue, 15 Mar 2022 11:33:03 +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-3.smtp.seeweb.it (Postfix) with ESMTPS id B8D061A00CA3 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 5D58321906; Tue, 15 Mar 2022 10:33:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647340382; 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=8LgWdg4NbQ6GVArWeDExwSdF5aywatXql188rDlXgEI=; b=IrFAtCRdkgSZaZME0BxiUXSoyCHZg2LopJ8keqZtvGTEcQrly20Db7VkOzM4U2Y4AYN51K oJrkI3h194JVr9Vv4+IvBmVz2wvIaEyLU/iIpou0zrmKmxXStwD7HWygSDzKhS4U80qiU4 P8pHLqsO8ywD6IHaPiMFAb4JFSEHM5A= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647340382; 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=8LgWdg4NbQ6GVArWeDExwSdF5aywatXql188rDlXgEI=; b=Ga/TYzSZnWpxvbScqqqdk0JMQ7qXBzJdbrtq54vFRuroQf7PbtZ4b/X1acaC20ly0t33la j4gWwkGsHe50HqBg== 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 F0DDC13B59; 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 gCPnOF1rMGKHHwAAMHmgww (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:51 +0100 Message-Id: <20220315103254.7185-8-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-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, T_SCC_BODY_TEXT_LINE 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 v3 07/10] Rewrite shmem_2nstest.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 runtime file to include new shmem_2nstest.c options. Signed-off-by: Andrea Cervesato --- runtest/containers | 6 +- .../kernel/containers/sysvipc/shmem_2nstest.c | 239 ++++++------------ 2 files changed, 86 insertions(+), 159 deletions(-) diff --git a/runtest/containers b/runtest/containers index b1b9b522a..591d56b18 100644 --- a/runtest/containers +++ b/runtest/containers @@ -46,9 +46,9 @@ netns_sysfs netns_sysfs.sh 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 +shmem_2nstest_none shmem_2nstest -m none +shmem_2nstest_clone shmem_2nstest -m clone +shmem_2nstest_unshare shmem_2nstest -m unshare shm_comm shm_comm mesgq_nstest_none mesgq_nstest -m none mesgq_nstest_clone mesgq_nstest -m clone diff --git a/testcases/kernel/containers/sysvipc/shmem_2nstest.c b/testcases/kernel/containers/sysvipc/shmem_2nstest.c index b172ee07c..fe3715509 100644 --- a/testcases/kernel/containers/sysvipc/shmem_2nstest.c +++ b/testcases/kernel/containers/sysvipc/shmem_2nstest.c @@ -1,187 +1,114 @@ -/* ************************************************************************* -* Copyright (c) International Business Machines Corp., 2009 -* 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: Veerendra C -* -* Test Assertion: -* This testcase verifies the Shared Memory isoloation in 2 containers. -* It tries to create/access a Shared Memory created with the same KEY. -* -* Description: -* Create 2 'containers' with the below flag value -* Flag = clone, clone(CLONE_NEWIPC), or unshare(CLONE_NEWIPC) -* In Cont1, create Shared Memory segment with key 124426L -* In Cont2, try to access the MQ created in Cont1. -* PASS : -* If flag = None and the shmem seg is accessible in Cont2. -* If flag = unshare/clone and the shmem seg is not accessible in Cont2. -* If shmem seg is not accessible in Cont2, -* creates new shmem with same key to double check isloation in IPCNS. -* -* FAIL : -* If flag = none and the shmem seg is not accessible. -* If flag = unshare/clone and shmem seg is accessible in Cont2. -* If the new shmem seg creation Fails. -***************************************************************************/ - -#define _GNU_SOURCE 1 -#include -#include -#include -#include -#include -#include -#include -#include "test.h" -#include "safe_macros.h" -#include "ipcns_helper.h" - -#define TESTKEY 124426L -#define UNSHARESTR "unshare" -#define CLONESTR "clone" -#define NONESTR "none" - -char *TCID = "shmem_2nstest"; -int TST_TOTAL = 1; -int p2[2]; -int p1[2]; - +// SPDX-License-Identifier: GPL-2.0-or-later /* - * check_shmem1() does not read -- it writes to check_shmem2() when it's done. + * Copyright (c) International Business Machines Corp., 2009 + * Veerendra C + * Copyright (C) 2022 SUSE LLC Andrea Cervesato + */ + +/*\ + * [Description] + * + * Test if SysV IPC shared memory is properly used between two namespaces. + * + * [Algorithm] + * + * Create two 'containers'. + * In container1, create Shared Memory segment with a specific key. + * In container2, try to access the MQ created in container1. + * + * Test is PASS if flag = none and the shmem seg is accessible in container2. + * If flag = unshare/clone and the shmem seg is not accessible in container2. + * If shmem seg is not accessible in container2, creates new shmem with same + * key to double check isloation in IPCNS. + * + * Test is FAIL if flag = none and the shmem seg is not accessible, if + * flag = unshare/clone and shmem seg is accessible in container2 or if the new + * shmem seg creation Fails. */ -int check_shmem1(void *vtest) -{ - int id1; - (void) vtest; +#define _GNU_SOURCE - close(p1[0]); +#include +#include +#include +#include "tst_safe_sysv_ipc.h" +#include "tst_test.h" +#include "common.h" - /* first create the key */ - id1 = shmget(TESTKEY, 100, IPC_CREAT); - if (id1 == -1) - tst_brkm(TFAIL | TERRNO, NULL, "shmget failed"); +#define TESTKEY 124426L - tst_resm(TINFO, "Cont1: Able to create shared mem segment"); - write(p1[1], "done", 5); - tst_exit(); -} +static char *str_op = "clone"; +static int use_clone; /* - * check_shmem2() reads from check_shmem1() and writes to main() when it's done. + * check_shmem1() does not read -- it writes to check_shmem2() when it's done. */ -int check_shmem2(void *vtest) +static int check_shmem1(LTP_ATTRIBUTE_UNUSED void *vtest) { - char buf[3]; - int id2; + SAFE_SHMGET(TESTKEY, 100, IPC_CREAT); - (void) vtest; + tst_res(TINFO, "container1: able to create shared mem segment"); - close(p1[1]); - close(p2[0]); + TST_CHECKPOINT_WAKE(0); - read(p1[0], buf, 3); - /* Trying to access shmem, if not existing create new shmem */ - id2 = shmget(TESTKEY, 100, 0); - if (id2 == -1) { - id2 = shmget(TESTKEY, 100, IPC_CREAT); - if (id2 == -1) - tst_resm(TFAIL | TERRNO, "shmget failed"); - else - tst_resm(TINFO, - "Cont2: Able to allocate shmem seg with " - "the same key"); - write(p2[1], "notfnd", 7); - } else - write(p2[1], "exists", 7); - - tst_exit(); -} - -static void setup(void) -{ - tst_require_root(); - check_newipc(); + return 0; } -int main(int argc, char *argv[]) +/* + * check_shmem2() reads from check_shmem1() and writes to main() when it's done. + */ +static int check_shmem2(LTP_ATTRIBUTE_UNUSED void *vtest) { - int ret, use_clone = T_NONE; - char *tsttype = NONESTR; - char buf[7]; int id; - setup(); + TST_CHECKPOINT_WAIT(0); - if (argc != 2) { - tst_resm(TINFO, "Usage: %s ", argv[0]); - tst_resm(TINFO, " where clone, unshare, or fork specifies" - " unshare method."); - tst_exit(); - } - - /* Using PIPE's to sync between containers and Parent */ - SAFE_PIPE(NULL, p1); - SAFE_PIPE(NULL, p2); - - 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; - } + TEST(shmget(TESTKEY, 100, 0)); - tst_resm(TINFO, "Shared Memory namespace test : %s", tsttype); + if (TST_RET < 0) { + SAFE_SHMGET(TESTKEY, 100, IPC_CREAT); - /* Create 2 containers */ - ret = - do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem1, NULL); - if (ret < 0) - tst_brkm(TFAIL, NULL, "clone/unshare failed"); + tst_res(TINFO, "container2: able to allocate shmem seg with the same key"); - ret = - do_clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem2, NULL); - if (ret < 0) - tst_brkm(TFAIL, NULL, "clone/unshare failed"); - - close(p2[1]); - read(p2[0], buf, 7); - - if (strcmp(buf, "exists") == 0) { if (use_clone == T_NONE) - tst_resm(TPASS, - "Plain cloned process able to access shmem " - "segment created"); + tst_res(TFAIL, "Plain cloned process didn't find shmem segment"); else - tst_resm(TFAIL, - "%s : In namespace2 found the shmem segment " - "created in Namespace1", tsttype); + tst_res(TPASS, "%s: in namespace2 unable to access the shmem seg created in namespace1", str_op); } else { if (use_clone == T_NONE) - tst_resm(TFAIL, - "Plain cloned process didn't find shmem seg"); + tst_res(TPASS, "Plain cloned process able to access shmem segment created"); else - tst_resm(TPASS, - "%s : In namespace2 unable to access the shmem seg " - "created in Namespace1", tsttype); + tst_res(TFAIL, "%s: in namespace2 found the shmem segment created in namespace1", str_op); } - /* destroy the key */ - id = shmget(TESTKEY, 100, 0); - shmctl(id, IPC_RMID, NULL); + id = SAFE_SHMGET(TESTKEY, 100, 0); + SAFE_SHMCTL(id, IPC_RMID, NULL); - tst_exit(); + return 0; } + +static void run(void) +{ + clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem1, NULL); + clone_unshare_test(use_clone, CLONE_NEWIPC, check_shmem2, NULL); +} + +static void setup(void) +{ + use_clone = get_clone_unshare_enum(str_op); + + if (use_clone != T_NONE) + check_newipc(); +} + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .forks_child = 1, + .needs_root = 1, + .needs_checkpoints = 1, + .options = (struct tst_option[]) { + { "m:", &str_op, "Test execution mode " }, + {}, + }, +}; From patchwork Tue Mar 15 10:32:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605543 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=SUX7m6x7; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=PSrLFJif; 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 4KHqXt5TjRz9sFn for ; Tue, 15 Mar 2022 21:34:54 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id E74533C934D for ; Tue, 15 Mar 2022 11:34:51 +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 [IPv6:2001:4b78:1:20::3]) (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 AC6FC3C932C for ; Tue, 15 Mar 2022 11:33:05 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 7A9B31A00CAC for ; Tue, 15 Mar 2022 11:33:03 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id DA8351F37E; Tue, 15 Mar 2022 10:33:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647340382; 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=nCwGgLBxduNGFREGs0cswOTgJzLRuo3Y8Lpd5IABBd0=; b=SUX7m6x7Iu0ez/Mso0mMnWqEY6Jx4YpzlsKmKtioaUT+uzyT/idlPe0B5J+CF0h7s8jWra 4S0WIFd7zN4Gna2HZtBZflEucqVyZCqMM+HiSyXtQhXY3ZiK2YVeigALxuOL5JXP2y5Mid t/uK34xsqoeeLtVKZoNoOrqdITj8XSI= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647340382; 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=nCwGgLBxduNGFREGs0cswOTgJzLRuo3Y8Lpd5IABBd0=; b=PSrLFJifbreG7wlC030LxX7EjyYEGxIcMZB9qvywaFBABRGNrgfBsmD+b1G+Pf++o8Ov5y tUzlWv7TP9ILYZAA== 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 79D7C13B59; Tue, 15 Mar 2022 10:33:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id eHvSG15rMGKHHwAAMHmgww (envelope-from ); Tue, 15 Mar 2022 10:33:02 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Tue, 15 Mar 2022 11:32:52 +0100 Message-Id: <20220315103254.7185-9-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-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, T_SCC_BODY_TEXT_LINE 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 v3 08/10] Rewrite shm_comm.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" Signed-off-by: Andrea Cervesato --- .../kernel/containers/sysvipc/shm_comm.c | 167 ++++++------------ 1 file changed, 50 insertions(+), 117 deletions(-) diff --git a/testcases/kernel/containers/sysvipc/shm_comm.c b/testcases/kernel/containers/sysvipc/shm_comm.c index 4b3bbfaa8..12ad49110 100644 --- a/testcases/kernel/containers/sysvipc/shm_comm.c +++ b/testcases/kernel/containers/sysvipc/shm_comm.c @@ -1,20 +1,17 @@ -/* Copyright (c) 2014 Red Hat, Inc. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of version 2 the GNU General Public License as - * published by the Free Software Foundation. +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2014 Red Hat, Inc. + * Copyright (C) 2022 SUSE LLC Andrea Cervesato + */ + +/*\ + * [Description] * - * 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. + * Test if SysV IPC shared memory is properly working between two different + * namespaces. * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - *********************************************************************** - * File: shm_comm.c + * [Algorithm] * - * Description: * 1. Clones two child processes with CLONE_NEWIPC flag, each child * allocates System V shared memory segment (shm) with the _identical_ * key and attaches that segment into its address space. @@ -27,141 +24,77 @@ */ #define _GNU_SOURCE -#include -#include -#include -#include -#include -#include -#include "ipcns_helper.h" -#include "test.h" -#include "safe_macros.h" +#include +#include +#include +#include "tst_safe_sysv_ipc.h" +#include "tst_test.h" +#include "common.h" #define TESTKEY 124426L #define SHMSIZE 50 -char *TCID = "shm_comm"; -int TST_TOTAL = 1; - -static void cleanup(void) -{ - tst_rmdir(); -} - -static void setup(void) -{ - tst_require_root(); - check_newipc(); - tst_tmpdir(); - TST_CHECKPOINT_INIT(tst_rmdir); -} -int chld1_shm(void *arg) +static int chld1_shm(LTP_ATTRIBUTE_UNUSED void *arg) { - int id, rval = 0; + int id; char *shmem; - id = shmget(TESTKEY, SHMSIZE, IPC_CREAT); - if (id == -1) { - perror("shmget"); - return 2; - } - - if ((shmem = shmat(id, NULL, 0)) == (char *) -1) { - perror("shmat"); - shmctl(id, IPC_RMID, NULL); - return 2; - } + id = SAFE_SHMGET(TESTKEY, SHMSIZE, IPC_CREAT); + shmem = SAFE_SHMAT(id, NULL, 0); *shmem = 'A'; - TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0); + TST_CHECKPOINT_WAKE_AND_WAIT(0); - /* if child1 shared segment has changed (by child2) report fail */ if (*shmem != 'A') - rval = 1; + tst_res(TFAIL, "shared memory leak between namespaces"); + else + tst_res(TPASS, "shared memory didn't leak between namespaces"); + + TST_CHECKPOINT_WAKE(0); - /* tell child2 to continue */ - TST_SAFE_CHECKPOINT_WAKE(NULL, 0); + SAFE_SHMDT(shmem); + SAFE_SHMCTL(id, IPC_RMID, NULL); - shmdt(shmem); - shmctl(id, IPC_RMID, NULL); - return rval; + return 0; } -int chld2_shm(void *arg) +static int chld2_shm(LTP_ATTRIBUTE_UNUSED void *arg) { int id; char *shmem; - id = shmget(TESTKEY, SHMSIZE, IPC_CREAT); - if (id == -1) { - perror("shmget"); - return 2; - } + id = SAFE_SHMGET(TESTKEY, SHMSIZE, IPC_CREAT); - if ((shmem = shmat(id, NULL, 0)) == (char *) -1) { - perror("shmat"); - shmctl(id, IPC_RMID, NULL); - return 2; - } + shmem = SAFE_SHMAT(id, NULL, 0); - /* wait for child1 to write to his segment */ - TST_SAFE_CHECKPOINT_WAIT(NULL, 0); + TST_CHECKPOINT_WAIT(0); *shmem = 'B'; - TST_SAFE_CHECKPOINT_WAKE_AND_WAIT(NULL, 0); + TST_CHECKPOINT_WAKE_AND_WAIT(0); + + SAFE_SHMDT(shmem); + SAFE_SHMCTL(id, IPC_RMID, NULL); - shmdt(shmem); - shmctl(id, IPC_RMID, NULL); return 0; } -static void test(void) +static void run(void) { - int status, ret = 0; - - ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_shm, NULL); - if (ret == -1) - tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); - - ret = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_shm, NULL); - if (ret == -1) - tst_brkm(TBROK | TERRNO, cleanup, "clone failed"); - - - while (wait(&status) > 0) { - if (WIFEXITED(status) && WEXITSTATUS(status) == 1) - ret = 1; - if (WIFEXITED(status) && WEXITSTATUS(status) == 2) - tst_brkm(TBROK | TERRNO, cleanup, "error in child"); - if (WIFSIGNALED(status)) { - tst_resm(TFAIL, "child was killed with signal %s", - tst_strsig(WTERMSIG(status))); - return; - } - } - - if (ret) - tst_resm(TFAIL, "SysV shm: communication with identical keys" - " between namespaces"); - else - tst_resm(TPASS, "SysV shm: communication with identical keys" - " between namespaces"); + clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld1_shm, NULL); + clone_unshare_test(T_CLONE, CLONE_NEWIPC, chld2_shm, NULL); } -int main(int argc, char *argv[]) +static void setup(void) { - int lc; - - tst_parse_opts(argc, argv, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) - test(); - - cleanup(); - tst_exit(); + check_newipc(); } + +static struct tst_test test = { + .test_all = run, + .setup = setup, + .needs_root = 1, + .needs_checkpoints = 1, +}; From patchwork Tue Mar 15 10:32:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605541 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=DvuD9bO1; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=ihS5SYuE; 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 4KHqXS4CYdz9sFn for ; Tue, 15 Mar 2022 21:34:32 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id DC17C3C9318 for ; Tue, 15 Mar 2022 11:34:29 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 6560F3C932C for ; Tue, 15 Mar 2022 11:33:05 +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-2.smtp.seeweb.it (Postfix) with ESMTPS id E5BE360067D for ; Tue, 15 Mar 2022 11:33:03 +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 958F221906; Tue, 15 Mar 2022 10:33:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647340383; 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=YgZZfRuNwaWkyXn1kXDvw+UKSPHvnW0AhEgQf13kXZA=; b=DvuD9bO196dMg6f7RCpoeSE5G7TS85K6xkChnNkbyj8/NF/6X8twOhov5rSEVtChhhbZF1 O+cHU32p3P8T+KX3pmrIq0cm1BUWjqKzB1cUZQTACWxu3cg+TTDZpOEBYnZWclHYGHiKut wQuFA0x0uCtXyeEIHq2h4I/6ahODVMs= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647340383; 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=YgZZfRuNwaWkyXn1kXDvw+UKSPHvnW0AhEgQf13kXZA=; b=ihS5SYuE37zmLDFt6bPBcc9R/980FENf5NG0PricgyI9InD3vrldPeDGvSg3HMg5xNa9Lc NPvFj2tD3a7+gHAA== 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 1342813B59; Tue, 15 Mar 2022 10:33:02 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 8Kr4OV5rMGKHHwAAMHmgww (envelope-from ); Tue, 15 Mar 2022 10:33:02 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Tue, 15 Mar 2022 11:32:53 +0100 Message-Id: <20220315103254.7185-10-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-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v3 09/10] Remove libclone dependency from sysvipc test suite 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: Andrea Cervesato --- testcases/kernel/containers/sysvipc/Makefile | 26 +++----------------- 1 file changed, 3 insertions(+), 23 deletions(-) diff --git a/testcases/kernel/containers/sysvipc/Makefile b/testcases/kernel/containers/sysvipc/Makefile index 00b537f6a..426fe5292 100644 --- a/testcases/kernel/containers/sysvipc/Makefile +++ b/testcases/kernel/containers/sysvipc/Makefile @@ -1,28 +1,8 @@ -################################################################################ -## ## -## 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 ## -## ## -################################################################################ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) International Business Machines Corp., 2007 +# Copyright (C) 2021 SUSE LLC Andrea Cervesato top_srcdir ?= ../../../.. include $(top_srcdir)/include/mk/testcases.mk -include $(abs_srcdir)/../Makefile.inc - -LDLIBS := -lclone $(LDLIBS) - include $(top_srcdir)/include/mk/generic_leaf_target.mk From patchwork Tue Mar 15 10:32:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 1605542 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=VajZQeKb; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=m42dwvbO; 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)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4KHqXd6Jtlz9sFn for ; Tue, 15 Mar 2022 21:34:41 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BF05A3C9318 for ; Tue, 15 Mar 2022 11:34:39 +0100 (CET) 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 828863C9216 for ; Tue, 15 Mar 2022 11:33:05 +0100 (CET) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 611C92009DE for ; Tue, 15 Mar 2022 11:33:04 +0100 (CET) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 083C41F391; Tue, 15 Mar 2022 10:33:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1647340384; 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=0w3Qyf5dcIQcXwt5zZqWtEJYXfBKD8QYgjyHujCFZe8=; b=VajZQeKbtQl1DqBkObWAZKnoi2DxlfasyqFTEMfR6vi3hkLOFeS21FSoUhik2BYQzwslsL E9lRtoNTJDdpBFNYfF3iKlheAFojyvBTGBMxskkLBzQlGSj0bZspnFC4vBe5CyZnwe9Rnv 4j8qwsd94CMky8kzNBveV7KquwD3/SQ= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1647340384; 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=0w3Qyf5dcIQcXwt5zZqWtEJYXfBKD8QYgjyHujCFZe8=; b=m42dwvbONmx5ulUeJzbEtnOnfIM/0ISP/5zS3vrJw84EtDb0GZTndkDRTs7sYSJcTImsci iGoulkaq+9lnElAw== 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 C155513B59; Tue, 15 Mar 2022 10:33:03 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aBVKKV9rMGKHHwAAMHmgww (envelope-from ); Tue, 15 Mar 2022 10:33:03 +0000 From: Andrea Cervesato To: ltp@lists.linux.it Date: Tue, 15 Mar 2022 11:32:54 +0100 Message-Id: <20220315103254.7185-11-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-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, T_SCC_BODY_TEXT_LINE 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 v3 10/10] Delete ipcns_helper.h in the sysvipc test suite 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: Andrea Cervesato --- .../kernel/containers/sysvipc/ipcns_helper.h | 41 ------------------- 1 file changed, 41 deletions(-) delete mode 100644 testcases/kernel/containers/sysvipc/ipcns_helper.h diff --git a/testcases/kernel/containers/sysvipc/ipcns_helper.h b/testcases/kernel/containers/sysvipc/ipcns_helper.h deleted file mode 100644 index 01ad0fff6..000000000 --- a/testcases/kernel/containers/sysvipc/ipcns_helper.h +++ /dev/null @@ -1,41 +0,0 @@ -/* -* 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: Rishikesh K Rajak -***************************************************************************/ -#include -#include "../libclone/libclone.h" -#include "test.h" -#include "safe_macros.h" - -static int dummy_child(void *v) -{ - (void) v; - return 0; -} - -static void check_newipc(void) -{ - int pid, status; - - if (tst_kvercmp(2, 6, 19) < 0) - tst_brkm(TCONF, NULL, "CLONE_NEWIPC not supported"); - - pid = do_clone_unshare_test(T_CLONE, CLONE_NEWIPC, dummy_child, NULL); - if (pid == -1) - tst_brkm(TCONF | TERRNO, NULL, "CLONE_NEWIPC not supported"); - - SAFE_WAIT(NULL, &status); -}