From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v1 1/3] syscalls/mallinfo01: Add a basic test for mallinfo
Date: Thu, 28 Jan 2021 16:50:02 +0100 [thread overview]
Message-ID: <YBLdKsBkrLuyvbjA@yuki.lan> (raw)
In-Reply-To: <1611654925-8994-1-git-send-email-xuyang2018.jy@cn.fujitsu.com>
> diff --git a/testcases/kernel/syscalls/mallinfo/mallinfo01.c b/testcases/kernel/syscalls/mallinfo/mallinfo01.c
> new file mode 100644
> index 000000000..1a2a30af1
> --- /dev/null
> +++ b/testcases/kernel/syscalls/mallinfo/mallinfo01.c
> @@ -0,0 +1,84 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
> + * Author: Yang Xu <xuyang2018.jy@cn.fujitsu.com>
> + */
> +
> +/*\
> + * [DESCRIPTION]
> + *
> + * Basic mallinfo() test. Refer to glibc test
> + * https://sourceware.org/git/?p=glibc.git;a=blob;f=malloc/tst-mallinfo2.c
> +\*/
> +
> +#include <malloc.h>
> +
> +#include "tst_test.h"
> +#include "tst_safe_macros.h"
> +
> +#ifdef HAVE_MALLINFO
> +static char *buf;
> +static struct mallinfo info1;
> +
> +static void
> +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);
> +}
> +
> +void test_mallinfo(void)
> +{
> + struct mallinfo info2;
> + int i;
> + int total = 0;
> +
> + for (i = 1; i < 20; i++) {
> + buf = SAFE_MALLOC(160 * i);
The buf here has to be array and we have to free the buffers at the end
of this function, otherwise the malloc() will fail sooner or later when
the test_mallinfo() function runs in a loop.
> + total += 16 * i;
> + }
> +
> + info2 = mallinfo();
> + print_mallinfo("Test", &info2);
> + if (info2.uordblks > info1.uordblks + total)
> + tst_res(TPASS, "mallinfo() passed");
> + else
> + tst_res(TFAIL, "mallinfo() failed");
> +
> + info1 = info2;
And then we cannot do this either.
> +}
> +
> +static void setup(void)
> +{
> + if (sizeof(info1.arena) != sizeof(int))
> + tst_res(TFAIL, "The member of mallinfo struct is not int");
> +
> + info1 = mallinfo();
> + print_mallinfo("Start", &info1);
> +}
> +
> +static void cleanup(void)
> +{
> + if (buf)
> + free(buf);
> +}
> +
> +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
> --
> 2.23.0
>
>
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
next prev parent reply other threads:[~2021-01-28 15:50 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
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 ` Cyril Hrubis [this message]
2021-02-03 6:03 ` [LTP] [PATCH v1 1/3] syscalls/mallinfo01: Add a basic test for mallinfo 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=YBLdKsBkrLuyvbjA@yuki.lan \
--to=chrubis@suse.cz \
--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