From patchwork Tue Feb 27 08:42:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1904891 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=A97RlX3O; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=fj2 header.b=JkpdA/C/; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkWGP16dKz1yX4 for ; Tue, 27 Feb 2024 19:43:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1709023383; h=to : date : message-id : mime-version : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : content-type : content-transfer-encoding : sender : from; bh=9POE7v19MA0gF7ZgfJRgDgX/ir1JCjab9J7ARFtDi00=; b=A97RlX3OiLHuFt3iAv2UUTSPb4HnugvrBLzPh2XM9J/YPonT5bq/A8blzHaXjMo55AkX/ ias+ZqvBiolH7+C1AfcqCQpIJji599LWr3ubRPvlH9CRVbwbCiwvf8lV6agXVF5nfSRtkuR mGNmL4VKPGVwkhinKln35TI6UFxKVCA= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id C107E3CEED9 for ; Tue, 27 Feb 2024 09:43:03 +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 [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 2DF173CB971 for ; Tue, 27 Feb 2024 09:42:59 +0100 (CET) Authentication-Results: in-7.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=fujitsu.com (client-ip=139.138.61.253; helo=esa8.hc1455-7.c3s2.iphmx.com; envelope-from=xuyang2018.jy@fujitsu.com; receiver=lists.linux.it) Received: from esa8.hc1455-7.c3s2.iphmx.com (esa8.hc1455-7.c3s2.iphmx.com [139.138.61.253]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 6C08E207251 for ; Tue, 27 Feb 2024 09:42:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1709023378; x=1740559378; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=D165jigxpeQTcVa1nzMsujW19g/innLQ/q6ZQzrIzGU=; b=JkpdA/C/dMYUs2VxCwyXj/L/+h3LQESbaMLffOnLivnBaI5uxcELKFgZ O6vRzdm8pNcHgWqe0BazQe2w2edspUHeEoDWX9D6rhONoJlGltWclwddN EkLujEeh2vdfMYgTB36mheFRMWCRa3MFI8qpOTn8zKF+lCLfz7u17zwVS zvXlLqn42rBoIewHIU3v9UpMCuMMXkiap8T6bTl7y6TNMsn7W/q+cNwi4 uTFxgQi59JSEi2JyewmDxnVmPdRqR+flJgZ/IYXn3cKUbnMtl5pkEvwU+ ybVULIHJrOpg+YwqAKyopN625R9VpQq5Ogo6G5N5mFYsdSYk9rYhlhWqY g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="138544654" X-IronPort-AV: E=Sophos;i="6.06,187,1705330800"; d="scan'208";a="138544654" Received: from unknown (HELO oym-r1.gw.nic.fujitsu.com) ([210.162.30.89]) by esa8.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 17:42:55 +0900 Received: from oym-m1.gw.nic.fujitsu.com (oym-nat-oym-m1.gw.nic.fujitsu.com [192.168.87.58]) by oym-r1.gw.nic.fujitsu.com (Postfix) with ESMTP id 611FED4802 for ; Tue, 27 Feb 2024 17:42:53 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by oym-m1.gw.nic.fujitsu.com (Postfix) with ESMTP id 843C7D88A9 for ; Tue, 27 Feb 2024 17:42:52 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id 068F26BE7A for ; Tue, 27 Feb 2024 17:42:52 +0900 (JST) Received: from rhel93GA.g08.fujitsu.local (unknown [10.167.221.71]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 817971A006A; Tue, 27 Feb 2024 16:42:51 +0800 (CST) To: ltp@lists.linux.it Date: Tue, 27 Feb 2024 03:42:42 -0500 Message-Id: <20240227084244.33662-1-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 2.39.3 MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28216.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28216.006 X-TMASE-Result: 10--11.316000-10.000000 X-TMASE-MatchedRID: rP3/tz83A4WhhjsqgSuNbxF4zyLyne+AVBDQSDMig9HEosIs7IJbkIh+ mL+ciFCpbnRB47KLJ1QzLmfGY6iDkX5uUfhNvnKzOWUWxTQJdI8UZYubbUj2DLt4BAaULwAVJf5 otvavOZf9vT5evMX4tJhCh8+WImJUkto8AKCDbo7X3j/lf1V8LNhQO8CvZj/XfL8fHUCAmuv1ov LD2i2bwoHA6IBd3vQswTgwAtrOMM4O9fZKTjt+zzz6L+U/pejxfb+ZO7kHlEgyiHqxwIX2MVOkR ICTn8kKUjFinMvpgsNmlbstSGDENWULhS/RYteO3nHtGkYl/VpIvK4LrXs1aZsgafD1fXNh+03a +MQ8RE1Zms6w/rdLbtCPpguQSWAlZ2OZE/lyQ29KzjuZtPtIBH607foZgOWyNAzT8I6i53DDRve w35mZexdx1aMGhJ7URzLfMkqkPSlccQ8eam5EfRRFJJyf5BJe3QfwsVk0UbtuRXh7bFKB7k3Wac 5TPmZnTsbpQkYSD1VguBoo0HsmqvkUeNlBzTqdXwjihSrlWBo= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v2 1/3] mremap02: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yang Xu via ltp From: Yang Xu Reply-To: Yang Xu Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- testcases/kernel/syscalls/mremap/mremap02.c | 195 ++++---------------- 1 file changed, 40 insertions(+), 155 deletions(-) diff --git a/testcases/kernel/syscalls/mremap/mremap02.c b/testcases/kernel/syscalls/mremap/mremap02.c index 2dabc6847..9e4a67c79 100644 --- a/testcases/kernel/syscalls/mremap/mremap02.c +++ b/testcases/kernel/syscalls/mremap/mremap02.c @@ -1,178 +1,63 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) Linux Test Project, 2001-2024 + * 07/2001 Ported by Wayne Boyer */ -/* - * Test Name: mremap02 - * - * Test Description: - * Verify that, - * mremap() fails when used to expand the existing virtual memory mapped - * region to the requested size, if the virtual memory area previously - * mapped was not page aligned or invalid argument specified. - * - * Expected Result: - * mremap() should return -1 and set errno to EINVAL. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * if errno set == expected errno - * Issue sys call fails with expected return value and errno. - * Otherwise, - * Issue sys call fails with unexpected errno. - * Otherwise, - * Issue sys call returns unexpected value. - * - * Cleanup: - * Print errno log and/or timing stats if options given +/*\ + * [Description] * - * Usage: - * mremap02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -p x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * Test for EINVAL error. * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * 11/09/2001 Manoj Iyer (manjo@austin.ibm.com) - * Modified. - * - #include should not be included as per man page for - * mremap, #include alone should do the job. But inorder - * to include definition of MREMAP_MAYMOVE defined in bits/mman.h - * (included by sys/mman.h) __USE_GNU needs to be defined. - * There may be a more elegant way of doing this... - * - * - * RESTRICTIONS: - * None. + * - mremap fail with virtual memory area previously mapped was not page aligned. */ -#define _GNU_SOURCE -#include -#include -#include -#include - -#include "test.h" -char *TCID = "mremap02"; -int TST_TOTAL = 1; -char *addr; /* addr of memory mapped region */ -int memsize; /* memory mapped size */ -int newsize; /* new size of virtual memory block */ +#define _GNU_SOURCE +#include "tst_test.h" -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ +static char *addr; +static int memsize; +static int newsize; -int main(int ac, char **av) +static void verify_mremap(void) { - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { + errno = 0; + addr = mremap(addr, memsize, newsize, MREMAP_MAYMOVE); + TST_ERR = errno; - tst_count = 0; - - /* - * Attempt to expand the existing mapped - * memory region (memsize) by newsize limits using - * mremap() should fail as old virtual address is not - * page aligned. - */ - errno = 0; - addr = mremap(addr, memsize, newsize, MREMAP_MAYMOVE); - TEST_ERRNO = errno; - - /* Check for the return value of mremap() */ - if (addr != MAP_FAILED) { - tst_resm(TFAIL, - "mremap returned invalid value, expected: -1"); - - /* Unmap the mapped memory region */ - if (munmap(addr, newsize) != 0) { - tst_brkm(TBROK, cleanup, "munmap fails to " - "unmap the expanded memory region, " - "error=%d", errno); - } - continue; - } - - if (errno == EINVAL) { - tst_resm(TPASS, "mremap() Failed, 'invalid argument " - "specified' - errno %d", TEST_ERRNO); - } else { - tst_resm(TFAIL, "mremap() Failed, " - "'Unexpected errno %d", TEST_ERRNO); - } + if (addr != MAP_FAILED) { + tst_res(TFAIL | TTERRNO, + "mremap returned invalid value, expected: -1"); } - cleanup(); - tst_exit(); - + if (errno == EINVAL) { + tst_res(TPASS | TTERRNO, "mremap() Failed, 'invalid argument " + "specified' - errno %d", TST_ERR); + } else { + tst_res(TFAIL | TTERRNO, "mremap() Failed, " + "'Unexpected errno %d", TST_ERR); + } } -/* - * setup() - performs all ONE TIME setup for this test. - * - * Get system page size, Set the size of virtual memory area and the - * new size after resize, Set the virtual memory address such that it - * is not aligned. - */ -void setup(void) -{ - tst_sig(FORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - /* Get the system page size */ - if ((memsize = getpagesize()) < 0) { - tst_brkm(TFAIL, NULL, - "getpagesize() fails to get system page size"); - } - - /* Get the New size of virtual memory block after resize */ +static void setup(void) +{ + memsize = SAFE_SYSCONF(_SC_PAGESIZE); + addr = SAFE_MMAP(NULL, memsize, PROT_WRITE, + MAP_PRIVATE | MAP_ANONYMOUS, 0, 0); newsize = (memsize * 2); - - /* Set the old virtual memory address */ addr = (char *)(addr + (memsize - 1)); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - - /* Exit the program */ + if (addr != MAP_FAILED) + SAFE_MUNMAP(addr, newsize); } +static struct tst_test test = { + .test_all = verify_mremap, + .setup = setup, + .cleanup = cleanup, +}; From patchwork Tue Feb 27 08:42:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1904893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=OeUaZEk0; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=fj2 header.b=nwFj/Uer; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkWGv0nmqz1yX4 for ; Tue, 27 Feb 2024 19:43:35 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1709023412; h=to : date : message-id : in-reply-to : references : mime-version : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : content-type : content-transfer-encoding : sender : from; bh=IBQcmtaMa4KZdnxfL2GAraK6RhtiDvElW6wJVNGUal8=; b=OeUaZEk0ffNsQSXgBnhSCnv0oBkp653FjwqxVCpxrT0UWlMuMhBwOyT66Qbyyrt04SDGr aLEZwDNoBEa1udAaBEV6S+3VUjdFcSocpswu+f2lA7paND2yGqhFb7hsZclJl/RgOoxB6ym Ujg3p5wucq52Retu38RcpLIWB+1Mu18= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BF9E83CEEE7 for ; Tue, 27 Feb 2024 09:43:32 +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 (secp384r1) server-digest SHA384) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id CC0CB3CEF3C for ; Tue, 27 Feb 2024 09:43:07 +0100 (CET) Authentication-Results: in-6.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=fujitsu.com (client-ip=139.138.37.100; helo=esa12.hc1455-7.c3s2.iphmx.com; envelope-from=xuyang2018.jy@fujitsu.com; receiver=lists.linux.it) Received: from esa12.hc1455-7.c3s2.iphmx.com (esa12.hc1455-7.c3s2.iphmx.com [139.138.37.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-6.smtp.seeweb.it (Postfix) with ESMTPS id E261A1401634 for ; Tue, 27 Feb 2024 09:43:06 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1709023386; x=1740559386; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=c0yG5V5TUt1t2F3hiNeEEdffiRzedhWp/89WwB7angc=; b=nwFj/UerplAxrMvJ68UMIW7+/KwCuQZnvrXqxIbxNGO2C9zA5f1xSHLs A3HxF2kB9WrV3sC0PfMo6WaC86Alqe/PaZSZ/4na+Apf56vLFoAAnK6Et kHEZWYf3b/l95jjjuaQ7tKd90sD1lPNwVO/dCT5C6ya0lpTJvEH5GFGhl YubtDAt0ec3i0Elcw5DSX7b5zdnUHPYwMTSDDKPbTh3blxxBzNgsWCV2S Tvjgu+OlnhNSvIOyBZhMhM2xJgYshc5nkc5ISoM1l73JzjrI/nGBTdJt6 3fK8eBNbysqloOlO+qXfNByDN2kiSxHz1p+FMQT233XdcLI9Lppct2mgZ w==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="129838175" X-IronPort-AV: E=Sophos;i="6.06,187,1705330800"; d="scan'208";a="129838175" Received: from unknown (HELO yto-r2.gw.nic.fujitsu.com) ([218.44.52.218]) by esa12.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 17:43:04 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r2.gw.nic.fujitsu.com (Postfix) with ESMTP id 04A062A0DEF for ; Tue, 27 Feb 2024 17:43:02 +0900 (JST) Received: from kws-ab3.gw.nic.fujitsu.com (kws-ab3.gw.nic.fujitsu.com [192.51.206.21]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 40AA9D7B6F for ; Tue, 27 Feb 2024 17:43:01 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab3.gw.nic.fujitsu.com (Postfix) with ESMTP id C1E602008FF84 for ; Tue, 27 Feb 2024 17:43:00 +0900 (JST) Received: from rhel93GA.g08.fujitsu.local (unknown [10.167.221.71]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 406D91A006A; Tue, 27 Feb 2024 16:43:00 +0800 (CST) To: ltp@lists.linux.it Date: Tue, 27 Feb 2024 03:42:43 -0500 Message-Id: <20240227084244.33662-2-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240227084244.33662-1-xuyang2018.jy@fujitsu.com> References: <20240227084244.33662-1-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28216.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28216.006 X-TMASE-Result: 10--13.074000-10.000000 X-TMASE-MatchedRID: 7q1xkhOBgdehhjsqgSuNbxF4zyLyne+AVBDQSDMig9HEosIs7IJbkIh+ mL+ciFCpbnRB47KLJ1QzLmfGY6iDkX5uUfhNvnKzOWUWxTQJdI8UZYubbUj2DLt4BAaULwAVJf5 otvavOZf9vT5evMX4tJhCh8+WImJUkto8AKCDbo7X3j/lf1V8LNhQO8CvZj/XfL8fHUCAmuv1ov LD2i2bwoHA6IBd3vQsIvabuzhmQeA9M2SZK+EIssQ4mpKyfkqZBGvINcfHqhcli8Y5a0svLxduD +Mmm6Q2gC3FH2GME0bQsefS5WLXU3hh1unvIp4BqNtC2YatSIkcsx3IH4sq3MgVyTd/p+/Io6yI pLdrAfgD+h7g3AV/au2m4eeglpGzlTFYj5iEM4VdhZyafgPiqx+KaaVwAG43JLfQYoCQHFYTSjx b4ZTfMJ6QSKvJTnodwTWpxY8/N9Pkht9v6t8rYxQ7ky03us3D7xa8TAoa4anoTJc0BP/XCqPFjJ EFr+olwXCBO/GKkVqOhzOa6g8KrcN5HKs2rTzbbc80XJECKYhsJrgG9oG6nF4RRubAjLXFYluQl 3unzhQ= X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-6.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v2 2/3] mremap03: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yang Xu via ltp From: Yang Xu Reply-To: Yang Xu Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- testcases/kernel/syscalls/mremap/mremap03.c | 201 ++++---------------- 1 file changed, 39 insertions(+), 162 deletions(-) diff --git a/testcases/kernel/syscalls/mremap/mremap03.c b/testcases/kernel/syscalls/mremap/mremap03.c index 02b79bc47..4e55dbda6 100644 --- a/testcases/kernel/syscalls/mremap/mremap03.c +++ b/testcases/kernel/syscalls/mremap/mremap03.c @@ -1,187 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) Linux Test Project, 2001-2024 + * 07/2001 Ported by Wayne Boyer */ -/* - * Test Name: mremap03 - * - * Test Description: - * Verify that, - * mremap() fails when used to expand the existing virtual memory mapped - * region to the requested size, if there already exists mappings that - * cover the whole address space requsted or the old address specified was - * not mapped. - * - * Expected Result: - * mremap() should return -1 and set errno to EFAULT. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * if errno set == expected errno - * Issue sys call fails with expected return value and errno. - * Otherwise, - * Issue sys call fails with unexpected errno. - * Otherwise, - * Issue sys call returns unexpected value. - * - * Cleanup: - * Print errno log and/or timing stats if options given +/*\ + * [Description] * - * Usage: - * mremap03 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -p x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. + * Test for EFAULT error. * - * HISTORY - * 07/2001 Ported by Wayne Boyer - * - * 11/09/2001 Manoj Iyer (manjo@austin.ibm.com) - * Modified. - * - #include should not be included as per man page for - * mremap, #include alone should do the job. But inorder - * to include definition of MREMAP_MAYMOVE defined in bits/mman.h - * (included by sys/mman.h) __USE_GNU needs to be defined. - * There may be a more elegant way of doing this... - * - * - * RESTRICTIONS: - * None. + * - mremap fail with the old address specified was not mapped. */ -#define _GNU_SOURCE -#include -#include -#include -#include -#include "test.h" +#define _GNU_SOURCE +#include "tst_test.h" -char *TCID = "mremap03"; -int TST_TOTAL = 1; static char *bad_addr; -static char *addr; /* addr of memory mapped region */ -int memsize; /* memory mapped size */ -int newsize; /* new size of virtual memory block */ +static char *addr; +static int memsize; +static int newsize; -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ - -int main(int ac, char **av) +static void verify_mremap(void) { - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; + errno = 0; + addr = mremap(bad_addr, memsize, newsize, MREMAP_MAYMOVE); + TST_ERR = errno; - /* - * Attempt to expand the existing mapped - * memory region (memsize) by newsize limits - * using mremap() should fail as specified old - * virtual address was not mapped. - */ - errno = 0; - addr = mremap(bad_addr, memsize, newsize, MREMAP_MAYMOVE); - TEST_ERRNO = errno; - - /* Check for the return value of mremap() */ - if (addr != MAP_FAILED) { - tst_resm(TFAIL, - "mremap returned invalid value, expected: -1"); - - /* Unmap the mapped memory region */ - if (munmap(addr, newsize) != 0) { - tst_brkm(TFAIL, cleanup, "munmap fails to " - "unmap the expanded memory region, " - " error=%d", errno); - } - continue; - } - - /* Check for the expected errno */ - if (errno == EFAULT) { - tst_resm(TPASS, "mremap() Fails, 'old region not " - "mapped', errno %d", TEST_ERRNO); - } else { - tst_resm(TFAIL, "mremap() Fails, " - "'Unexpected errno %d", TEST_ERRNO); - } + if (addr != MAP_FAILED) { + tst_res(TFAIL | TTERRNO, + "mremap returned invalid value, expected: -1"); } - cleanup(); - tst_exit(); - + if (errno == EFAULT) { + tst_res(TPASS | TTERRNO, "mremap() Failed, 'old region not " + "mapped' - errno %d", TST_ERR); + } else { + tst_res(TFAIL | TTERRNO, "mremap() Failed, " + "'Unexpected errno %d", TST_ERR); + } } -/* - * setup() - performs all ONE TIME setup for this test. - * - * Get system page size. - * Set the old address point some high address which is not mapped. - */ void setup(void) { - int page_sz; /* system page size */ - - tst_sig(FORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; + int page_sz; - /* Get the system page size */ - if ((page_sz = getpagesize()) < 0) { - tst_brkm(TFAIL, NULL, - "getpagesize() fails to get system page size"); - } - - /* Get the size of virtual memory area to be mapped */ + page_sz = SAFE_SYSCONF(_SC_PAGESIZE); memsize = (1000 * page_sz); - - /* Get the New size of virtual memory block after resize */ newsize = (memsize * 2); - - /* - * Set the old virtual address point to some address - * which is not mapped. - */ - bad_addr = tst_get_bad_addr(cleanup); + bad_addr = tst_get_bad_addr(NULL); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - */ -void cleanup(void) +static void cleanup(void) { - - /* Exit the program */ - + if (addr != MAP_FAILED) + SAFE_MUNMAP(addr, newsize); } + +static struct tst_test test = { + .test_all = verify_mremap, + .setup = setup, + .cleanup = cleanup, +}; From patchwork Tue Feb 27 08:42:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1904897 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=lists.linux.it header.i=@lists.linux.it header.a=rsa-sha256 header.s=picard header.b=KPJdmsd4; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=fujitsu.com header.i=@fujitsu.com header.a=rsa-sha256 header.s=fj2 header.b=grdC5ddR; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TkWHL12q5z1yX4 for ; Tue, 27 Feb 2024 19:43:58 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=lists.linux.it; i=@lists.linux.it; q=dns/txt; s=picard; t=1709023435; h=to : date : message-id : in-reply-to : references : mime-version : subject : list-id : list-unsubscribe : list-archive : list-post : list-help : list-subscribe : from : reply-to : content-type : content-transfer-encoding : sender : from; bh=VFFd3byePFbXvT95uWHJ++ajOcVKjQ2A6gI1gKsuvHI=; b=KPJdmsd4WshA4CIk86QV9bg6eCx/0GlQryNl6z05qDsfNeDqwtJPes71Zc3ARVQBAqB3l 3xaJDUNq0m0c6Yev11iqC5ZdFqvtnVm4V4kD4fyskxsqeGhue9/lYm8+q03utCIKNcnRE3a +/o0xEbC8IpK5ahvn++/iFu0/sjrQwA= Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 827C03CEEEF for ; Tue, 27 Feb 2024 09:43:55 +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 [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 6DA2D3CEEEE for ; Tue, 27 Feb 2024 09:43:13 +0100 (CET) Authentication-Results: in-7.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=fujitsu.com (client-ip=68.232.139.130; helo=esa5.hc1455-7.c3s2.iphmx.com; envelope-from=xuyang2018.jy@fujitsu.com; receiver=lists.linux.it) Received: from esa5.hc1455-7.c3s2.iphmx.com (esa5.hc1455-7.c3s2.iphmx.com [68.232.139.130]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id 7230F207232 for ; Tue, 27 Feb 2024 09:43:11 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=fujitsu.com; i=@fujitsu.com; q=dns/txt; s=fj2; t=1709023392; x=1740559392; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=gJUnAigX5nKtd54zEPgjjXFh+Ss7T0L1OF+G3JWROdA=; b=grdC5ddR/2bZlV3RFkBcaouWlV9R0zx74qLU3SqpEKGd76F5lPLxL8/f +psAq2SWpXJ2c8yAz4DVmupSRA0KirRs4B8WAKZ2RQww+dDR2nZtfr30G ptxAyXiYgVDbg8cSjfQtmOav/LHSeVfOkbUZVEMrZaa7nOxD1whY9X8W0 yvaCilLzttHBy7GQ7z4NfpJzVp5UuX9wOtn281EQjAEmHY76UMN1m3ROc kkoSYn5zhXNVuEl5lKSudaBH52YzFSqKRLNgX7qAITufplksLCW/wVwYB dIKqqns/gKSXEQf1wvZMOVUsPYzh1eZb1jkz2oS3a0w8qblXxDcCF4gvo g==; X-IronPort-AV: E=McAfee;i="6600,9927,10996"; a="150004308" X-IronPort-AV: E=Sophos;i="6.06,187,1705330800"; d="scan'208";a="150004308" Received: from unknown (HELO yto-r4.gw.nic.fujitsu.com) ([218.44.52.220]) by esa5.hc1455-7.c3s2.iphmx.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 27 Feb 2024 17:43:10 +0900 Received: from yto-m4.gw.nic.fujitsu.com (yto-nat-yto-m4.gw.nic.fujitsu.com [192.168.83.67]) by yto-r4.gw.nic.fujitsu.com (Postfix) with ESMTP id 1857BD9F0C for ; Tue, 27 Feb 2024 17:43:08 +0900 (JST) Received: from kws-ab4.gw.nic.fujitsu.com (kws-ab4.gw.nic.fujitsu.com [192.51.206.22]) by yto-m4.gw.nic.fujitsu.com (Postfix) with ESMTP id 4E72AD7B6F for ; Tue, 27 Feb 2024 17:43:07 +0900 (JST) Received: from edo.cn.fujitsu.com (edo.cn.fujitsu.com [10.167.33.5]) by kws-ab4.gw.nic.fujitsu.com (Postfix) with ESMTP id D3BF141055 for ; Tue, 27 Feb 2024 17:43:06 +0900 (JST) Received: from rhel93GA.g08.fujitsu.local (unknown [10.167.221.71]) by edo.cn.fujitsu.com (Postfix) with ESMTP id 681BD1A006A; Tue, 27 Feb 2024 16:43:06 +0800 (CST) To: ltp@lists.linux.it Date: Tue, 27 Feb 2024 03:42:44 -0500 Message-Id: <20240227084244.33662-3-xuyang2018.jy@fujitsu.com> X-Mailer: git-send-email 2.39.3 In-Reply-To: <20240227084244.33662-1-xuyang2018.jy@fujitsu.com> References: <20240227084244.33662-1-xuyang2018.jy@fujitsu.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-TM-AS-Product-Ver: IMSS-9.1.0.1417-9.0.0.1002-28216.006 X-TM-AS-User-Approved-Sender: Yes X-TMASE-Version: IMSS-9.1.0.1417-9.0.1002-28216.006 X-TMASE-Result: 10--16.057600-10.000000 X-TMASE-MatchedRID: GyhbhdD5alRa6JkWul/UfE7nLUqYrlslFIuBIWrdOeOjEIt+uIPPOJBF C/PvU/lgmHD/QEfzXMflgC90JZPVsI0zxJrF5VMZypiC33/79mcL//VMxXlyE97p0Ru8jKvF/9T DS4zEk/zv3R81Uj/6vMjhLggtE8XmxB13Y/+OC6ap3Btb1bH20Gvaomg0i4KN/5o9BPVzGUaRh2 fOTp3PtlLawnkOVilWcfLMR+KlDOzzXojwcywrzPZNLVgVojn/l9q75JzWJRNujEcOZiInj5/bu mQx78u3gvoA8cGUyvoOe6UQgyI8ebd2u9fM9Zt+8IK7yRWPRNGBs03RHrzjM4qyjcQ3p/0Mj+B3 qsDdCHyipw58JSX3jHy8s7RgoirCxnDmzSiE8O17TXnCjI8t9ki8rgutezVpPZSk8XZgZOGXidr 9etFZ1oAAzcwNZpHF0a+qS+HYqZWfLxf8NKOlfG03YawHJvPC+LidURF+DB2chtWeykcDiuafUx jZqZZRb7vhAFDgsdM0D0Peqz8C66ceJlSdtw9ELTHwnYOikQ3vFrxMChrhqfI8LsVQUyaIObTpJ WONTOHi8zVgXoAltsIJ+4gwXrEtvECLuM+h4RB+3BndfXUhXQ== X-TMASE-SNAP-Result: 1.821001.0001-0-1-22:0,33:0,34:0-0 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS, T_SCC_BODY_TEXT_LINE shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v2 3/3] mremap04: Convert to new API X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Yang Xu via ltp From: Yang Xu Reply-To: Yang Xu Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- testcases/kernel/syscalls/mremap/Makefile | 4 +- testcases/kernel/syscalls/mremap/mremap04.c | 269 ++++---------------- 2 files changed, 53 insertions(+), 220 deletions(-) diff --git a/testcases/kernel/syscalls/mremap/Makefile b/testcases/kernel/syscalls/mremap/Makefile index 190b7659d..f286dd9bf 100644 --- a/testcases/kernel/syscalls/mremap/Makefile +++ b/testcases/kernel/syscalls/mremap/Makefile @@ -3,10 +3,10 @@ top_srcdir ?= ../../../.. -LTPLIBS = ltpipc +LTPLIBS = ltpnewipc include $(top_srcdir)/include/mk/testcases.mk -mremap04: LTPLDLIBS = -lltpipc +mremap04: LTPLDLIBS = -lltpnewipc include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/mremap/mremap04.c b/testcases/kernel/syscalls/mremap/mremap04.c index 53902df73..8d819184e 100644 --- a/testcases/kernel/syscalls/mremap/mremap04.c +++ b/testcases/kernel/syscalls/mremap/mremap04.c @@ -1,245 +1,78 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * - * Copyright (c) International Business Machines Corp., 2001 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2001 + * Copyright (c) Linux Test Project, 2001-2024 + * 07/2001 Ported by Wayne Boyer */ -/* - * Test Name: mremap04 - * - * Test Description: - * Verify that, - * mremap() fails when used to expand the existing virtual memory mapped - * region to the requested size, if the memory area cannot be expanded at - * the current virtual address and MREMAP_MAYMOVE flag not set. - * - * Expected Result: - * mremap() should return -1 and set errno to ENOMEM. - * - * Algorithm: - * Setup: - * Setup signal handling. - * Create temporary directory. - * Pause for SIGUSR1 if option specified. - * - * Test: - * Loop if the proper options are given. - * Execute system call - * Check return code, if system call failed (return=-1) - * if errno set == expected errno - * Issue sys call failed with expected return value and errno. - * Otherwise, - * Issue sys call failed with unexpected errno. - * Otherwise, - * Issue sys call returns unexpected value. - * - * Cleanup: - * Print errno log and/or timing stats if options given - * Delete the temporary directory(s)/file(s) created. - * - * Usage: - * mremap04 [-c n] [-e] [-i n] [-I x] [-P x] [-t] - * where, -c n : Run n copies concurrently. - * -e : Turn on errno logging. - * -i n : Execute test n times. - * -I x : Execute test for x seconds. - * -p x : Pause for x seconds between iterations. - * -t : Turn on syscall timing. - * - * HISTORY - * 07/2001 Ported by Wayne Boyer +/*\ + * [Description] * - * 11/09/2001 Manoj Iyer (manjo@austin.ibm.com) - * Modified. - * - #include should not be included as per man page for - * mremap, #include alone should do the job. But inorder - * to include definition of MREMAP_MAYMOVE defined in bits/mman.h - * (included by sys/mman.h) __USE_GNU needs to be defined. - * There may be a more elegant way of doing this... + * Test for ENOMEM error. * - * 26/02/2008 Renaud Lottiaux (Renaud.Lottiaux@kerlabs.com) - * - Fix concurrency issue. Use a shm key from getipckey instead of - * a fixed hard-coded value. - * - * RESTRICTIONS: - * None. + * - mremap fail when the memory area cannot be expanded at the current virtual address + * and MREMAP_MAYMOVE flag not set */ + #define _GNU_SOURCE -#include -#include -#include #include #include +#include "tst_test.h" +#include "libnewipc.h" +#include "tst_safe_sysv_ipc.h" -#include "test.h" - -#define SHM_MODE (SHM_R | SHM_W) /* mode permissions of shared memory */ +#define SHM_MODE (SHM_R | SHM_W) -char *TCID = "mremap04"; -int TST_TOTAL = 1; -char *addr; /* addr of memory mapped region */ -char *shmaddr; /* pointer to shared memory segment */ -int shmid; /* shared memory identifier. */ -int memsize; /* memory mapped size */ -int newsize; /* new size of virtual memory block */ +static char *addr; +static char *shmaddr; +static int shm_id; +static int memsize; +static int newsize; -void setup(); /* Main setup function of test */ -void cleanup(); /* cleanup function for the test */ - -extern int getipckey(); - -int main(int ac, char **av) +static void verify_mremap(void) { - int lc; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); lc++) { - - tst_count = 0; - - /* - * Attempt to expand the existing shared - * memory region of newsize by newsize limits - * using mremap() should fail as specified - * memory area already locked and MREMAP_MAYMOVE - * flag unset. - */ - errno = 0; - addr = mremap(shmaddr, memsize, newsize, 0); - TEST_ERRNO = errno; - - /* Check for the return value of mremap() */ - if (addr != MAP_FAILED) { - tst_resm(TFAIL, - "mremap returned invalid value, expected: -1"); - - /* Unmap the mapped memory region */ - if (munmap(addr, newsize) != 0) { - tst_brkm(TFAIL, cleanup, "munmap failed to " - "unmap the expanded memory region, " - "error=%d", errno); - } - continue; - } + errno = 0; + addr = mremap(shmaddr, memsize, newsize, 0); + TST_ERR = errno; - if (TEST_ERRNO == ENOMEM) { - tst_resm(TPASS, "mremap() failed, " - "'MREMAP_MAYMOVE flag unset', " - "errno %d", TEST_ERRNO); - } else { - tst_resm(TFAIL, "mremap() failed, " - "Unexpected errno %d", TEST_ERRNO); - } + if (addr != MAP_FAILED) { + tst_res(TFAIL | TTERRNO, + "mremap returned invalid value, expected: -1"); } - cleanup(); - tst_exit(); - + if (TST_ERR == ENOMEM) { + tst_res(TPASS | TTERRNO, "mremap() failed, " + "'MREMAP_MAYMOVE flag unset', " + "errno %d", TST_ERR); + } else { + tst_res(TFAIL | TTERRNO, "mremap() failed, " + "Unexpected errno %d", TST_ERR); + } } -/* - * setup() - performs all ONE TIME setup for this test. - * - * Get system page size, Set the size of virtual memory area and the - * newsize after resize, - * Create a named shared memory segment SHMKEY of newsize and mode SHM_MODE - * by using shmget() which returns a shared memory identifier associated - * with the created shared memory segment. - * Call shmat() to attach the shared memory segment to the data segment of the - * calling process. The segment is attached at the first available address as - * selected by the system. - */ -void setup(void) +static void setup(void) { key_t shmkey; - tst_sig(FORK, DEF_HANDLER, cleanup); - - TEST_PAUSE; - - tst_tmpdir(); - - /* Get the system page size */ - if ((memsize = getpagesize()) < 0) { - tst_brkm(TBROK, NULL, - "getpagesize() failed to get system page size"); - } - - /* Get the New size of virtual memory block after resize */ + memsize = SAFE_SYSCONF(_SC_PAGESIZE); newsize = (memsize * 2); - - /* get an IPC resource key */ - shmkey = getipckey(); - - /* - * Create a shared memory segment represented by SHMKEY of - * specified size 'newsize' and mode permissions 'SHM_MODE'. - */ - shmid = shmget(shmkey, newsize, IPC_CREAT | SHM_MODE); - if (shmid == -1) { - tst_brkm(TBROK, NULL, "shmget() Failed to create a shared " - "memory, error:%d", errno); - } - - /* - * Attach the shared memory segment associated with the shared - * memory identifier specified by "shmid" to the data segment of - * the calling process at the first available address as selected - * by the system. - */ - shmaddr = shmat(shmid, NULL, 0); - if (shmaddr == (void *)-1) { - tst_brkm(TBROK, cleanup, "shmat() Failed to attach shared " - "memory, error:%d", errno); - } + shmkey = GETIPCKEY(); + shm_id = SAFE_SHMGET(shmkey, newsize, IPC_CREAT | SHM_MODE); + shmaddr = SAFE_SHMAT(shm_id, NULL, 0); } -/* - * cleanup() - performs all ONE TIME cleanup for this test at - * completion or premature exit. - * Detach the shared memory segment and remove the shared memory - * identifier associated with the shared memory. - */ -void cleanup(void) +static void cleanup(void) { + SAFE_SHMDT(shmaddr); + SAFE_SHMCTL(shm_id, IPC_RMID, 0); - /* - * Detach the shared memory segment attached to - * the calling process's data segment - */ - if (shmdt(shmaddr) < 0) { - tst_brkm(TFAIL, NULL, "shmdt() Failed to detach shared " - "memory, error:%d", errno); - } - - /* - * Remove the shared memory identifier associated with - * the shared memory segment and destroy the shared memory - * segment. - */ - if (shmctl(shmid, IPC_RMID, 0) < 0) { - tst_brkm(TFAIL, NULL, "shmctl() Failed to remove shared " - "memory, error:%d", errno); - } - - tst_rmdir(); - - /* Exit the program */ - + if (addr != MAP_FAILED) + SAFE_MUNMAP(addr, newsize); } + +static struct tst_test test = { + .setup = setup, + .cleanup = cleanup, + .needs_tmpdir = 1, + .test_all = verify_mremap, +};