From: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 4/5] syscalls/mallinfo02: Add a basic test to check use mmap or sbrk
Date: Fri, 5 Feb 2021 15:51:21 +0800 [thread overview]
Message-ID: <601CF8F9.7040006@cn.fujitsu.com> (raw)
In-Reply-To: <CAEemH2ehgnR0Ad5VzR63KgtjFBoqH5N_1b13T7f5Gw6n3EkzdA@mail.gmail.com>
Hi Li
>
>
> On Thu, Feb 4, 2021 at 8:12 PM Yang Xu <xuyang2018.jy@cn.fujitsu.com
> <mailto:xuyang2018.jy@cn.fujitsu.com>> wrote:
>
> 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 <xuyang2018.jy@cn.fujitsu.com
> <mailto:xuyang2018.jy@cn.fujitsu.com>>
> ---
> 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 <xuyang2018.jy@cn.fujitsu.com
> <mailto:xuyang2018.jy@cn.fujitsu.com>>
> + */
> +
> +/*\
> + * [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)
>
>
> what about renaming to test_mallinfo(void) ?
Yes, sorry for typo.
>
> +{
> + 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");
>
>
> Why not 'TFAIL | TERRNO' ?
I don't see mallinfo() will fail and it should always succeed.
>
> + 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");
>
>
> Here as well.
Look mallopt man-pages, it said "
RETURN VALUE
On success, mallopt() returns 1. On error, it returns 0.
ERRORS
On error, errno is not set
"
That is why I don't use TERRNO.
>
> +}
> +
> +static struct tst_test test = {
> + .setup = setup,
> + .test_all = test_mallopt,
> +};
> +
> +#else
> +TST_TEST_TCONF("system doesn't implement non-POSIX mallinfo()");
> +#endif
> --
> 2.23.0
>
>
>
>
>
> --
> Regards,
> Li Wang
next prev parent reply other threads:[~2021-02-05 7:51 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-26 9:55 [LTP] [PATCH v1 1/3] syscalls/mallinfo01: Add a basic test for mallinfo Yang Xu
2021-01-26 9:55 ` [LTP] [PATCH v1 2/3] syscalls/mallinfo02: Add a basic test to check use mmap or sbrk Yang Xu
2021-01-28 15:37 ` Cyril Hrubis
2021-02-03 9:47 ` Yang Xu
2021-02-03 10:46 ` Yang Xu
2021-02-04 6:08 ` Li Wang
2021-02-04 9:53 ` Yang Xu
2021-01-26 9:55 ` [LTP] [PATCH v1 3/3] syscalls/mallinfo03: Add an overflow test when setting 2G size Yang Xu
2021-01-28 15:42 ` Cyril Hrubis
2021-02-03 9:49 ` Yang Xu
2021-02-04 8:54 ` Li Wang
2021-02-04 10:01 ` Yang Xu
2021-02-04 13:56 ` Li Wang
2021-02-04 12:12 ` [LTP] [PATCH v2 1/5] tst_mallinfo.c: Add a common print helper for mallinfo Yang Xu
2021-02-04 12:12 ` [LTP] [PATCH v2 2/5] syscalls/mallopt01: Use tst_print_mallinfo api Yang Xu
2021-02-04 12:12 ` [LTP] [PATCH v2 3/5] syscalls/mallinfo01: Add a basic test for mallinfo Yang Xu
2021-02-04 12:12 ` [LTP] [PATCH v2 4/5] syscalls/mallinfo02: Add a basic test to check use mmap or sbrk Yang Xu
2021-02-04 13:51 ` Li Wang
2021-02-05 7:51 ` Yang Xu [this message]
2021-02-05 8:15 ` Yang Xu
2021-02-05 9:00 ` Yang Xu
2021-02-05 9:20 ` Li Wang
2021-02-04 12:12 ` [LTP] [PATCH v2 5/5] syscalls/mallinfo03: Add an overflow test when setting 2G size Yang Xu
2021-02-04 13:29 ` [LTP] [PATCH v2 1/5] tst_mallinfo.c: Add a common print helper for mallinfo Li Wang
2021-02-05 7:44 ` Yang Xu
2021-02-05 8:00 ` Li Wang
2021-02-05 11:21 ` Petr Vorel
2021-02-08 15:30 ` Cyril Hrubis
2021-02-18 5:52 ` [LTP] [PATCH v3 1/4] syscalls/mallinfo01: Add a basic test " Yang Xu
2021-02-18 5:52 ` [LTP] [PATCH v3 2/4] syscalls/mallopt01: Use unified print_mallinfo api Yang Xu
2021-02-18 5:52 ` [LTP] [PATCH v3 3/4] syscalls/mallinfo02: Add a basic test to check use mmap or sbrk Yang Xu
2021-02-22 6:32 ` Li Wang
2021-02-22 6:40 ` Yang Xu
2021-02-23 1:45 ` Yang Xu
2021-02-18 5:52 ` [LTP] [PATCH v3 4/4] syscalls/mallinfo03: Add an overflow test when setting 2G size Yang Xu
2021-01-28 15:50 ` [LTP] [PATCH v1 1/3] syscalls/mallinfo01: Add a basic test for mallinfo Cyril Hrubis
2021-02-03 6:03 ` Yang Xu
2021-02-04 6:42 ` Li Wang
2021-02-04 9:54 ` Yang Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=601CF8F9.7040006@cn.fujitsu.com \
--to=xuyang2018.jy@cn.fujitsu.com \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox