From patchwork Thu Feb 4 12:12:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1435978 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 4DWcrZ3rdPz9sVt for ; Thu, 4 Feb 2021 23:13:02 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7912A3C7361 for ; Thu, 4 Feb 2021 13:12:59 +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]) by picard.linux.it (Postfix) with ESMTP id 5CD7C3C7360 for ; Thu, 4 Feb 2021 13:12:41 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id 5B40A60080A for ; Thu, 4 Feb 2021 13:12:32 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.79,400,1602518400"; d="scan'208";a="104197340" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Feb 2021 20:12:29 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id B7E334CE6D8A; Thu, 4 Feb 2021 20:12:27 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Feb 2021 20:12:27 +0800 From: Yang Xu To: , Date: Thu, 4 Feb 2021 20:12:38 +0800 Message-ID: <1612440762-22389-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) To G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) X-yoursite-MailScanner-ID: B7E334CE6D8A.AD231 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.4 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 1/5] tst_mallinfo.c: Add a common print helper for mallinfo 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: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" This function can be used for mallopt and subsequent mallinfo/mallinfo2 test. Signed-off-by: Yang Xu --- configure.ac | 1 + include/tst_mallinfo.h | 17 +++++++++++++++++ lib/tst_mallinfo.c | 28 ++++++++++++++++++++++++++++ 3 files changed, 46 insertions(+) create mode 100644 include/tst_mallinfo.h create mode 100644 lib/tst_mallinfo.c diff --git a/configure.ac b/configure.ac index 8bdb96300..223900ca1 100644 --- a/configure.ac +++ b/configure.ac @@ -94,6 +94,7 @@ AC_CHECK_FUNCS_ONCE([ \ io_uring_register \ io_uring_enter \ kcmp \ + mallinfo \ mallopt \ mkdirat \ mknodat \ diff --git a/include/tst_mallinfo.h b/include/tst_mallinfo.h new file mode 100644 index 000000000..bd69d032c --- /dev/null +++ b/include/tst_mallinfo.h @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +#ifndef TST_MALLINFO_H__ +#define TST_MALLINFO_H__ + +#include +#include "config.h" + +#ifdef HAVE_MALLINFO +void tst_print_mallinfo(const char *msg, struct mallinfo *m); +#endif + +#endif diff --git a/lib/tst_mallinfo.c b/lib/tst_mallinfo.c new file mode 100644 index 000000000..229e5aa2e --- /dev/null +++ b/lib/tst_mallinfo.c @@ -0,0 +1,28 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +#define TST_NO_DEFAULT_MAIN +#include "tst_test.h" +#include "tst_mallinfo.h" + +// To DO for mallinfo2 +#ifdef HAVE_MALLINFO +void tst_print_mallinfo(const char *msg, struct mallinfo *m) +{ + tst_res(TINFO, "%s...", msg); +#define P(f) tst_res(TINFO, "%s: %d", #f, m->f) + P(arena); + P(ordblks); + P(smblks); + P(hblks); + P(hblkhd); + P(usmblks); + P(fsmblks); + P(uordblks); + P(fordblks); + P(keepcost); +} +#endif From patchwork Thu Feb 4 12:12:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1435977 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DWcrQ2TKlz9sVt for ; Thu, 4 Feb 2021 23:12:52 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 2AA6A3C736D for ; Thu, 4 Feb 2021 13:12:49 +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]) by picard.linux.it (Postfix) with ESMTP id 9B8F33C015D for ; Thu, 4 Feb 2021 13:12:38 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id E56A6601412 for ; Thu, 4 Feb 2021 13:12:37 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.79,400,1602518400"; d="scan'208";a="104197344" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Feb 2021 20:12:35 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 543064CE6D8A; Thu, 4 Feb 2021 20:12:29 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Feb 2021 20:12:29 +0800 From: Yang Xu To: , Date: Thu, 4 Feb 2021 20:12:39 +0800 Message-ID: <1612440762-22389-2-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1612440762-22389-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <1612440762-22389-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) To G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) X-yoursite-MailScanner-ID: 543064CE6D8A.AB1BE X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.4 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/5] syscalls/mallopt01: Use tst_print_mallinfo 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: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Signed-off-by: Yang Xu --- testcases/kernel/syscalls/mallopt/mallopt01.c | 22 +++---------------- 1 file changed, 3 insertions(+), 19 deletions(-) diff --git a/testcases/kernel/syscalls/mallopt/mallopt01.c b/testcases/kernel/syscalls/mallopt/mallopt01.c index f799aaf9d..271079c12 100644 --- a/testcases/kernel/syscalls/mallopt/mallopt01.c +++ b/testcases/kernel/syscalls/mallopt/mallopt01.c @@ -12,10 +12,9 @@ * Basic mallinfo() and mallopt() testing. \*/ -#include - #include "tst_test.h" #include "tst_safe_macros.h" +#include "tst_mallinfo.h" #ifdef HAVE_MALLOPT @@ -23,21 +22,6 @@ struct mallinfo info; -void print_mallinfo(void) -{ - tst_res(TINFO, "mallinfo structure:"); - tst_res(TINFO, "mallinfo.arena = %d", info.arena); - tst_res(TINFO, "mallinfo.ordblks = %d", info.ordblks); - tst_res(TINFO, "mallinfo.smblks = %d", info.smblks); - tst_res(TINFO, "mallinfo.hblkhd = %d", info.hblkhd); - tst_res(TINFO, "mallinfo.hblks = %d", info.hblks); - tst_res(TINFO, "mallinfo.usmblks = %d", info.usmblks); - tst_res(TINFO, "mallinfo.fsmblks = %d", info.fsmblks); - tst_res(TINFO, "mallinfo.uordblks = %d", info.uordblks); - tst_res(TINFO, "mallinfo.fordblks = %d", info.fordblks); - tst_res(TINFO, "mallinfo.keepcost = %d", info.keepcost); -} - void test_mallopt(void) { char *buf; @@ -46,11 +30,11 @@ void test_mallopt(void) info = mallinfo(); if (info.uordblks < 20480) { - print_mallinfo(); + tst_print_mallinfo("Test uordblks", &info); tst_res(TFAIL, "mallinfo() failed: uordblks < 20K"); } if (info.smblks != 0) { - print_mallinfo(); + tst_print_mallinfo("Test smblks", &info); tst_res(TFAIL, "mallinfo() failed: smblks != 0"); } if (info.uordblks >= 20480 && info.smblks == 0) From patchwork Thu Feb 4 12:12:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1435976 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DWcrL0D04z9sVt for ; Thu, 4 Feb 2021 23:12:43 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 79E033C015D for ; Thu, 4 Feb 2021 13:12:40 +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]) by picard.linux.it (Postfix) with ESMTP id 445AC3C015D for ; Thu, 4 Feb 2021 13:12:37 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-2.smtp.seeweb.it (Postfix) with ESMTP id 9F76F60020E for ; Thu, 4 Feb 2021 13:12:36 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.79,400,1602518400"; d="scan'208";a="104197343" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Feb 2021 20:12:35 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id A6AC34CE6D90; Thu, 4 Feb 2021 20:12:34 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Feb 2021 20:12:35 +0800 From: Yang Xu To: , Date: Thu, 4 Feb 2021 20:12:40 +0800 Message-ID: <1612440762-22389-3-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1612440762-22389-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <1612440762-22389-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) To G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) X-yoursite-MailScanner-ID: A6AC34CE6D90.AED9B X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.4 X-Virus-Scanned: clamav-milter 0.102.4 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/5] syscalls/mallinfo01: Add a basic test for mallinfo 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: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Referring to glibc test tst-mallinfo2.c[1], add a test to test mallinfo. Also check mallinfo in autotools. [1]https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/tst-mallinfo2.c Signed-off-by: Yang Xu --- v1->v2 1.use tst_print_mallinfo api 2.use buf array 3.use 160 multiple instead of 16 4.add free chunk check runtest/syscalls | 2 + testcases/kernel/syscalls/mallinfo/.gitignore | 1 + testcases/kernel/syscalls/mallinfo/Makefile | 8 ++ .../kernel/syscalls/mallinfo/mallinfo01.c | 82 +++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 testcases/kernel/syscalls/mallinfo/.gitignore create mode 100644 testcases/kernel/syscalls/mallinfo/Makefile create mode 100644 testcases/kernel/syscalls/mallinfo/mallinfo01.c diff --git a/runtest/syscalls b/runtest/syscalls index 11a1e83c2..753340068 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -682,6 +682,8 @@ lstat01_64 lstat01_64 lstat02 lstat02 lstat02_64 lstat02_64 +mallinfo01 mallinfo01 + mallopt01 mallopt01 mbind01 mbind01 diff --git a/testcases/kernel/syscalls/mallinfo/.gitignore b/testcases/kernel/syscalls/mallinfo/.gitignore new file mode 100644 index 000000000..a7e32a637 --- /dev/null +++ b/testcases/kernel/syscalls/mallinfo/.gitignore @@ -0,0 +1 @@ +/mallinfo01 diff --git a/testcases/kernel/syscalls/mallinfo/Makefile b/testcases/kernel/syscalls/mallinfo/Makefile new file mode 100644 index 000000000..044619fb8 --- /dev/null +++ b/testcases/kernel/syscalls/mallinfo/Makefile @@ -0,0 +1,8 @@ +# SPDX-License-Identifier: GPL-2.0-or-later +# Copyright (c) International Business Machines Corp., 2001 + +top_srcdir ?= ../../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/syscalls/mallinfo/mallinfo01.c b/testcases/kernel/syscalls/mallinfo/mallinfo01.c new file mode 100644 index 000000000..add3c0df3 --- /dev/null +++ b/testcases/kernel/syscalls/mallinfo/mallinfo01.c @@ -0,0 +1,82 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +/*\ + * [DESCRIPTION] + * + * Basic mallinfo() test. Refer to glibc test mallinfo2 test + * https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/tst-mallinfo2.c +\*/ + +#include "tst_test.h" +#include "tst_safe_macros.h" +#include "tst_mallinfo.h" + +#ifdef HAVE_MALLINFO +#define M_NUM 20 +static struct mallinfo info1; +static void *buf[M_NUM + 1]; + +static void cleanup(void) +{ + int i; + + for (i = M_NUM; i > 0; i--) { + if (buf[i]) { + free(buf[i]); + buf[i] = NULL; + } + } +} + +void test_mallinfo(void) +{ + int i; + int total = 0; + struct mallinfo info2; + + for (i = 1; i <= M_NUM; i++) { + buf[i] = SAFE_MALLOC(160 * i); + total += 160 * i; + } + info2 = mallinfo(); + tst_print_mallinfo("Test uordblks", &info2); + if (info2.uordblks > info1.uordblks + total) + tst_res(TPASS, "mallinfo() uordblks passed"); + else + tst_res(TFAIL, "mallinfo() uordblks failed"); + + //Create another free chunk + free(buf[M_NUM/2]); + buf[M_NUM/2] = NULL; + info2 = mallinfo(); + tst_print_mallinfo("Test ordblks", &info2); + if (info2.ordblks == info1.ordblks + 1) + tst_res(TPASS, "mallinfo() ordblks passed"); + else + tst_res(TFAIL, "mallinfo() ordblks failed"); + + cleanup(); +} + +static void setup(void) +{ + if (sizeof(info1.arena) != sizeof(int)) + tst_res(TFAIL, "The member of mallinfo struct is not int"); + + info1 = mallinfo(); + tst_print_mallinfo("Start", &info1); +} + +static struct tst_test test = { + .setup = setup, + .test_all = test_mallinfo, + .cleanup = cleanup, +}; + +#else +TST_TEST_TCONF("system doesn't implement non-POSIX mallinfo()"); +#endif From patchwork Thu Feb 4 12:12:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1435979 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 4DWcrk3gzhz9sVw for ; Thu, 4 Feb 2021 23:13:10 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id B18423C7375 for ; Thu, 4 Feb 2021 13:13:07 +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]) by picard.linux.it (Postfix) with ESMTP id 8A4A03C7381 for ; Thu, 4 Feb 2021 13:12:44 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-6.smtp.seeweb.it (Postfix) with ESMTP id 432B714010E5 for ; Thu, 4 Feb 2021 13:12:42 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.79,400,1602518400"; d="scan'208";a="104197347" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Feb 2021 20:12:41 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id B970F4CE6D8D; Thu, 4 Feb 2021 20:12:38 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Feb 2021 20:12:39 +0800 From: Yang Xu To: , Date: Thu, 4 Feb 2021 20:12:41 +0800 Message-ID: <1612440762-22389-4-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1612440762-22389-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <1612440762-22389-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) To G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) X-yoursite-MailScanner-ID: B970F4CE6D8D.AFA30 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.4 X-Virus-Scanned: clamav-milter 0.102.4 at in-6.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-6.smtp.seeweb.it Subject: [LTP] [PATCH v2 4/5] syscalls/mallinfo02: Add a basic test to check use mmap or sbrk 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: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" According mallinfo man-page, hblkhd member represents "The number of bytes in blocks currently allocated using mmap(2).". For allocations greater than or equal to 128K and that can't be satisfied from the free list, the memory-allocation functions employ mmap(2) instead of increasing the program break using sbrk(2). In this case, we test 20k size to use sbrk and 128k size to use mmap. Signed-off-by: Yang Xu --- v1->v2: 1.Use mallopt(M_MMAP_THRESHOLD, 131072) to avoid dynamic mmap threshold 2.Use tst_print_malinfo api runtest/syscalls | 1 + testcases/kernel/syscalls/mallinfo/.gitignore | 1 + .../kernel/syscalls/mallinfo/mallinfo02.c | 64 +++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 testcases/kernel/syscalls/mallinfo/mallinfo02.c diff --git a/runtest/syscalls b/runtest/syscalls index 753340068..a8fa3f7bf 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -683,6 +683,7 @@ lstat02 lstat02 lstat02_64 lstat02_64 mallinfo01 mallinfo01 +mallinfo02 mallinfo02 mallopt01 mallopt01 diff --git a/testcases/kernel/syscalls/mallinfo/.gitignore b/testcases/kernel/syscalls/mallinfo/.gitignore index a7e32a637..678ac277e 100644 --- a/testcases/kernel/syscalls/mallinfo/.gitignore +++ b/testcases/kernel/syscalls/mallinfo/.gitignore @@ -1 +1,2 @@ /mallinfo01 +/mallinfo02 diff --git a/testcases/kernel/syscalls/mallinfo/mallinfo02.c b/testcases/kernel/syscalls/mallinfo/mallinfo02.c new file mode 100644 index 000000000..d5bed45a8 --- /dev/null +++ b/testcases/kernel/syscalls/mallinfo/mallinfo02.c @@ -0,0 +1,64 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +/*\ + * [DESCRIPTION] + * + * Basic mallinfo() test for malloc() using sbrk or mmap. + * It size > MMAP_THRESHOLD, it will use mmap. Otherwise, use sbrk. +\*/ + +#include "tst_test.h" +#include "tst_safe_macros.h" +#include "tst_mallinfo.h" + +#ifdef HAVE_MALLINFO +void test_mallopt(void) +{ + struct mallinfo info; + int size; + char *buf; + + buf = SAFE_MALLOC(20480); + + info = mallinfo(); + if (info.uordblks > 20480 && info.hblkhd == 0) { + tst_res(TPASS, "malloc() uses sbrk when size < 128k"); + } else { + tst_res(TFAIL, "malloc() use mmap when size < 128k"); + tst_print_mallinfo("Test malloc(20480)", &info); + } + free(buf); + + info = mallinfo(); + size = MAX(info.fordblks, 131072); + + buf = SAFE_MALLOC(size); + info = mallinfo(); + if (info.hblkhd > size && info.hblks > 0) { + tst_res(TPASS, "malloc() uses mmap when size >= 128k"); + } else { + tst_res(TFAIL, "malloc uses sbrk when size >= 128k"); + tst_print_mallinfo("Test malloc(1024*128)", &info); + } + + free(buf); +} + +static void setup(void) +{ + if (mallopt(M_MMAP_THRESHOLD, 131072) == 0) + tst_res(TFAIL, "mallopt(M_MMAP_THRESHOLD, 128K) failed"); +} + +static struct tst_test test = { + .setup = setup, + .test_all = test_mallopt, +}; + +#else +TST_TEST_TCONF("system doesn't implement non-POSIX mallinfo()"); +#endif From patchwork Thu Feb 4 12:12:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Xu X-Patchwork-Id: 1435980 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 ozlabs.org (Postfix) with ESMTPS id 4DWcrx0YCvz9sVt for ; Thu, 4 Feb 2021 23:13:20 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 4BE4E3C7343 for ; Thu, 4 Feb 2021 13:13:18 +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]) by picard.linux.it (Postfix) with ESMTP id C135C3C7389 for ; Thu, 4 Feb 2021 13:12:50 +0100 (CET) Received: from heian.cn.fujitsu.com (mail.cn.fujitsu.com [183.91.158.132]) by in-7.smtp.seeweb.it (Postfix) with ESMTP id 64901200072 for ; Thu, 4 Feb 2021 13:12:48 +0100 (CET) X-IronPort-AV: E=Sophos;i="5.79,400,1602518400"; d="scan'208";a="104197357" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 04 Feb 2021 20:12:47 +0800 Received: from G08CNEXMBPEKD04.g08.fujitsu.local (unknown [10.167.33.201]) by cn.fujitsu.com (Postfix) with ESMTP id 68C1A4CE6D74; Thu, 4 Feb 2021 20:12:41 +0800 (CST) Received: from localhost.localdomain (10.167.220.84) by G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 4 Feb 2021 20:12:41 +0800 From: Yang Xu To: , Date: Thu, 4 Feb 2021 20:12:42 +0800 Message-ID: <1612440762-22389-5-git-send-email-xuyang2018.jy@cn.fujitsu.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1612440762-22389-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> References: <1612440762-22389-1-git-send-email-xuyang2018.jy@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.220.84] X-ClientProxiedBy: G08CNEXCHPEKD06.g08.fujitsu.local (10.167.33.205) To G08CNEXMBPEKD04.g08.fujitsu.local (10.167.33.201) X-yoursite-MailScanner-ID: 68C1A4CE6D74.ADE1B X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: xuyang2018.jy@cn.fujitsu.com X-Spam-Status: No, score=0.4 required=7.0 tests=KHOP_HELO_FCRDNS, SPF_HELO_NONE, SPF_NONE autolearn=disabled version=3.4.4 X-Virus-Scanned: clamav-milter 0.102.4 at in-7.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on in-7.smtp.seeweb.it Subject: [LTP] [PATCH v2 5/5] syscalls/mallinfo03: Add an overflow test when setting 2G size 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: , Cc: ltp@lists.linux.it Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" Since these members of mallinfo struct use int data type, it will overflow when allocating 2G size. mallinfo() is deprecated and we should use mallinfo2() in the future. Signed-off-by: Yang Xu --- v1->v2 1.use tst_print_mallinfo api 2.skip test if we can't malloc 2g space runtest/syscalls | 1 + testcases/kernel/syscalls/mallinfo/.gitignore | 1 + .../kernel/syscalls/mallinfo/mallinfo03.c | 51 +++++++++++++++++++ 3 files changed, 53 insertions(+) create mode 100644 testcases/kernel/syscalls/mallinfo/mallinfo03.c diff --git a/runtest/syscalls b/runtest/syscalls index a8fa3f7bf..c5cf78381 100644 --- a/runtest/syscalls +++ b/runtest/syscalls @@ -684,6 +684,7 @@ lstat02_64 lstat02_64 mallinfo01 mallinfo01 mallinfo02 mallinfo02 +mallinfo03 mallinfo03 mallopt01 mallopt01 diff --git a/testcases/kernel/syscalls/mallinfo/.gitignore b/testcases/kernel/syscalls/mallinfo/.gitignore index 678ac277e..30c315cf2 100644 --- a/testcases/kernel/syscalls/mallinfo/.gitignore +++ b/testcases/kernel/syscalls/mallinfo/.gitignore @@ -1,2 +1,3 @@ /mallinfo01 /mallinfo02 +/mallinfo03 diff --git a/testcases/kernel/syscalls/mallinfo/mallinfo03.c b/testcases/kernel/syscalls/mallinfo/mallinfo03.c new file mode 100644 index 000000000..36d9e5d85 --- /dev/null +++ b/testcases/kernel/syscalls/mallinfo/mallinfo03.c @@ -0,0 +1,51 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved. + * Author: Yang Xu + */ + +/*\ + * [DESCRIPTION] + * + * Basic mallinfo() test. Test the member of struct mallinfo + * whether overflow when setting 2G size. mallinfo() is deprecated + * since the type used for the fields is too small. We should use + * mallinfo2() and it was added since glibc 2.33. +\*/ + +#include "tst_test.h" +#include "tst_safe_macros.h" +#include "tst_mallinfo.h" + +#ifdef HAVE_MALLINFO + +void test_mallinfo(void) +{ + struct mallinfo info; + char *buf; + size_t size = 2UL * 1024UL * 1024UL * 1024UL; + + buf = malloc(size); + if (!buf) { + tst_res(TCONF, "Current system can not malloc 2G space, skip it"); + return; + } + info = mallinfo(); + if (info.hblkhd < 0) { + tst_print_mallinfo("Test malloc 2G", &info); + tst_res(TFAIL, "The member of struct mallinfo overflow, we should use mallinfo2"); + } else { + /*We will never get here*/ + tst_res(TPASS, "The member of struct mallinfo doesn't overflow"); + } + + free(buf); +} + +static struct tst_test test = { + .test_all = test_mallinfo, +}; + +#else +TST_TEST_TCONF("system doesn't implement non-POSIX mallinfo()"); +#endif