[LTP] [PATCH v2 4/5] syscalls/mallinfo02: Add a basic test to check use mmap or sbrk

Yang Xu
2021-02-05T09:00:02Z

Hi Li

I have reply this email, but I don't see it on inbox or patchwork, so again

> +#ifdef HAVE_MALLINFO
> +void test_mallopt(void)
>
>
> what about renaming to test_mallinfo(void) ?
Yes, sorry for this 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' ?
mallinfo should succeed always.
>
> + 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.
>
From mallopt man-page, even it fail, it doesn't set errno and only return 0
> +}
> +
> +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