Skip to contentSkip to conversation

syscalls/mallinfo201: Add a basic test for mallinfo2 when setting 2G size

PATCH New Yang Xu 4 participants 11 messages May 7, 2021 – Jun 16, 2021

lore
Share & tools
lore

Yang Xu

author
#0 lore raw

PATCH 1/1 syscalls/mallinfo201: Add a basic test for mallinfo2 when setting 2G size

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. So we test mallinfo2 whether works well.

---
 configure.ac                                  |  1 +
 runtest/syscalls                              |  2 +
 .../syscalls/mallinfo/mallinfo_common.h       | 18 +++++++
 .../kernel/syscalls/mallinfo2/.gitignore      |  1 +
 testcases/kernel/syscalls/mallinfo2/Makefile  |  8 ++++
 .../kernel/syscalls/mallinfo2/mallinfo201.c   | 47 +++++++++++++++++++
 6 files changed, 77 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mallinfo2/.gitignore
 create mode 100644 testcases/kernel/syscalls/mallinfo2/Makefile
 create mode 100644 testcases/kernel/syscalls/mallinfo2/mallinfo201.c
configure.ac +1 -0
index 136d82d09..eb675b367 100644
@@ -102,6 +102,7 @@ AC_CHECK_FUNCS_ONCE([ \
     io_uring_enter \
     kcmp \
     mallinfo \
+    mallinfo2 \
     mallopt \
     mkdirat \
     mknodat \
runtest/syscalls +2 -0
index aa7fa24dd..ea48efd26 100644
@@ -693,6 +693,8 @@ lstat02_64 lstat02_64
 mallinfo01 mallinfo01
 mallinfo02 mallinfo02
 
+mallinfo201 mallinfo201
+
 mallopt01 mallopt01
 
 mbind01 mbind01
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +18 -0
index a00cc7a64..e7737b270 100644
@@ -28,4 +28,22 @@ static inline void print_mallinfo(const char *msg, struct mallinfo *m)
 }
 #endif
 
+#ifdef HAVE_MALLINFO2
+static inline void print_mallinfo2(const char *msg, struct mallinfo2 *m)
+{
+	tst_res(TINFO, "%s...", msg);
+#define P2(f) tst_res(TINFO, "%s: %ld", #f, m->f)
+	P2(arena);
+	P2(ordblks);
+	P2(smblks);
+	P2(hblks);
+	P2(hblkhd);
+	P2(usmblks);
+	P2(fsmblks);
+	P2(uordblks);
+	P2(fordblks);
+	P2(keepcost);
+}
+#endif
+
 #endif
testcases/kernel/syscalls/mallinfo2/.gitignore new file +1 -0
new file mode 100644
index 000000000..848f00130
@@ -0,0 +1 @@
+/mallinfo201
testcases/kernel/syscalls/mallinfo2/Makefile new file +8 -0
new file mode 100644
index 000000000..044619fb8
@@ -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
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +47 -0

47 lines not on this page · raw message

Signature · 1 line
2.23.0
#1 lore raw

PATCH 1/1 syscalls/mallinfo201: Add a basic test for mallinfo2 when setting 2G size

Hi Xu,

Quoted 4 lines

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. So we test mallinfo2 whether works well.

Quoted 8 lines
---
 configure.ac                                  |  1 +
 runtest/syscalls                              |  2 +
 .../syscalls/mallinfo/mallinfo_common.h       | 18 +++++++
 .../kernel/syscalls/mallinfo2/.gitignore      |  1 +
 testcases/kernel/syscalls/mallinfo2/Makefile  |  8 ++++
 .../kernel/syscalls/mallinfo2/mallinfo201.c   | 47 +++++++++++++++++++

nit: Maybe rename test: mallinfo201.c => mallinfo2_01.c ? Now it looks like mallinfo() 201st test.

Quoted 4 lines
 6 files changed, 77 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mallinfo2/.gitignore
 create mode 100644 testcases/kernel/syscalls/mallinfo2/Makefile
 create mode 100644 testcases/kernel/syscalls/mallinfo2/mallinfo201.c

...

Quoted 15 lines
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +7 -0
index a00cc7a64..e7737b270 100644
@@ -28,4 +28,22 @@ static inline void print_mallinfo(const char *msg, struct mallinfo *m)
 }
 #endif
 
+#ifdef HAVE_MALLINFO2
+static inline void print_mallinfo2(const char *msg, struct mallinfo2 *m)
+{
+	tst_res(TINFO, "%s...", msg);
+#define P2(f) tst_res(TINFO, "%s: %ld", #f, m->f)
+	P2(arena);
+	P2(ordblks);

testcases/kernel/syscalls/mallinfo/mallinfo_common.h static inline void print_mallinfo(const char *msg, struct mallinfo *m) · line 47

Quoted 10 lines
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +10 -0
+	P2(smblks);
+	P2(hblks);
+	P2(hblkhd);
+	P2(usmblks);
+	P2(fsmblks);
+	P2(uordblks);
+	P2(fordblks);
+	P2(keepcost);
+}
+#endif

BTW did you copy this from glibc? (and previously in 7eb7a97a1)? Code is similar as that one in malloc/tst-mallinfo2.c in glibc, which you modified.

I guess we should also add glibc copyright to mallinfo_common.h Copyright (C) 2020 Free Software Foundation, Inc.
(+ probably keep our)

...

testcases/kernel/syscalls/mallinfo2/Makefile line 2

Quoted 8 lines
testcases/kernel/syscalls/mallinfo2/Makefile new file +2 -0
new file mode 100644
index 000000000..044619fb8
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001

Here should be your or LTP copyright with 2021.

testcases/kernel/syscalls/mallinfo2/Makefile line 6

Quoted 4 lines
testcases/kernel/syscalls/mallinfo2/Makefile new file +4 -0
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk

CFLAGS += -I../mallinfo
(see description below)

Quoted 2 lines
testcases/kernel/syscalls/mallinfo2/Makefile new file +2 -0
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk

...

Quoted 7 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +4 -0
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>

testcases/kernel/syscalls/mallinfo2/mallinfo201.c line 14

Quoted 10 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +10 -0
+ */
+
+/*\
+ * [DESCRIPTION]
+ *
+ * Basic mallinfo2() test. Test the member of struct mallinfo2
+ * 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.
+ */

I'd format it a bit and remove info which is not related to the test and people can find in man page.

/*\
* [DESCRIPTION]
*
* Basic mallinfo2() test.
*
* Test members of struct mallinfo2() whether overflow when setting 2G size. */

testcases/kernel/syscalls/mallinfo2/mallinfo201.c line 16

Quoted 1 line
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +1 -0
+#include "../mallinfo/mallinfo_common.h"

Please use
#include "mallinfo_common.h"

and add include path to to Makefile
CFLAGS += -I../mallinfo

Quoted 5 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +5 -0
+#include "tst_safe_macros.h"
+
+#ifdef HAVE_MALLINFO2
+
+void test_mallinfo2(void)

testcases/kernel/syscalls/mallinfo2/mallinfo201.c line 31

Quoted 10 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +10 -0
+{
+	struct mallinfo2 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;
+	}

BTW sometimes I wonder if we should have something like SAFE_*() functions which would result with TCONF, not with TBROK.

Quoted 6 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +6 -0
+	info = mallinfo2();
+	if (info.hblkhd < size) {
+		print_mallinfo2("Test malloc 2G", &info);
+		tst_brk(TFAIL, "The member of struct mallinfo2 overflow?");
+	}
+	tst_res(TPASS, "The member of struct mallinfo2 doesn't overflow");

testcases/kernel/syscalls/mallinfo2/mallinfo201.c line 47

Quoted 10 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +10 -0
+	free(buf);
+}
+
+static struct tst_test test = {
+	.test_all = test_mallinfo2,
+};
+
+#else
+TST_TEST_TCONF("system doesn't implement non-POSIX mallinfo2()");
+#endif

The rest LGTM.

Kind regards,
Petr

#2 lore raw

PATCH 1/1 syscalls/mallinfo201: Add a basic test for mallinfo2 when setting 2G size

Hi Petr
Sorry for late reply. I am busy recently.

Quoted 14 lines

Hi Xu,

Quoted 4 lines

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. So we test mallinfo2 whether works well.

Quoted 8 lines
---
  configure.ac                                  |  1 +
  runtest/syscalls                              |  2 +
  .../syscalls/mallinfo/mallinfo_common.h       | 18 +++++++
  .../kernel/syscalls/mallinfo2/.gitignore      |  1 +
  testcases/kernel/syscalls/mallinfo2/Makefile  |  8 ++++
  .../kernel/syscalls/mallinfo2/mallinfo201.c   | 47 +++++++++++++++++++
Quoted 2 lines

nit: Maybe rename test: mallinfo201.c => mallinfo2_01.c ? Now it looks like mallinfo() 201st test.

Agree.

Quoted 25 lines
Quoted 4 lines
  6 files changed, 77 insertions(+)

create mode 100644 testcases/kernel/syscalls/mallinfo2/.gitignore create mode 100644 testcases/kernel/syscalls/mallinfo2/Makefile create mode 100644 testcases/kernel/syscalls/mallinfo2/mallinfo201.c

...

Quoted 19 lines
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +11 -0
index a00cc7a64..e7737b270 100644
@@ -28,4 +28,22 @@ static inline void print_mallinfo(const char *msg, struct mallinfo *m)
  }
  #endif
 
+#ifdef HAVE_MALLINFO2
+static inline void print_mallinfo2(const char *msg, struct mallinfo2 *m)
+{
+	tst_res(TINFO, "%s...", msg);
+#define P2(f) tst_res(TINFO, "%s: %ld", #f, m->f)
+	P2(arena);
+	P2(ordblks);
+	P2(smblks);
+	P2(hblks);
+	P2(hblkhd);
+	P2(usmblks);
Quoted 8 lines

testcases/kernel/syscalls/mallinfo/mallinfo_common.h static inline void print_mallinfo(const char *msg, struct mallinfo *m) · line 47

Quoted 6 lines
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +6 -0
+	P2(fsmblks);
+	P2(uordblks);
+	P2(fordblks);
+	P2(keepcost);
+}
+#endif

BTW did you copy this from glibc? (and previously in 7eb7a97a1)?

Yes.

Quoted 6 lines

Code is similar as that one in malloc/tst-mallinfo2.c in glibc, which you modified.

I guess we should also add glibc copyright to mallinfo_common.h Copyright (C) 2020 Free Software Foundation, Inc.
(+ probably keep our)

I will add glibc copyright.

Quoted 12 lines

...

testcases/kernel/syscalls/mallinfo2/Makefile line 2

Quoted 8 lines
testcases/kernel/syscalls/mallinfo2/Makefile new file +2 -0
new file mode 100644
index 000000000..044619fb8
@@ -0,0 +1,8 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001

Here should be your or LTP copyright with 2021.

OK.

Quoted 31 lines

testcases/kernel/syscalls/mallinfo2/Makefile line 6

Quoted 4 lines
testcases/kernel/syscalls/mallinfo2/Makefile new file +4 -0
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk

CFLAGS += -I../mallinfo
(see description below)

Quoted 2 lines
testcases/kernel/syscalls/mallinfo2/Makefile new file +2 -0
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk

...

Quoted 7 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +4 -0
@@ -0,0 +1,47 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu<[email protected]>

testcases/kernel/syscalls/mallinfo2/mallinfo201.c line 14

Quoted 10 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +10 -0
+ */
+
+/*\
+ * [DESCRIPTION]
+ *
+ * Basic mallinfo2() test. Test the member of struct mallinfo2
+ * 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.
+ */

I'd format it a bit and remove info which is not related to the test and people can find in man page.

Quoted 8 lines

/*\
* [DESCRIPTION]
*
* Basic mallinfo2() test.
*
* Test members of struct mallinfo2() whether overflow when setting 2G size. */

Looks well.

Quoted 7 lines

testcases/kernel/syscalls/mallinfo2/mallinfo201.c line 16

Quoted 1 line
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +1 -0
+#include "../mallinfo/mallinfo_common.h"

Please use
#include "mallinfo_common.h"

and add include path to to Makefile
CFLAGS += -I../mallinfo

OK.

Quoted 9 lines
Quoted 9 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +9 -0
+#include "tst_safe_macros.h"
+
+#ifdef HAVE_MALLINFO2
+
+void test_mallinfo2(void)
+{
+	struct mallinfo2 info;
+	char *buf;
+	size_t size = 2UL * 1024UL * 1024UL * 1024UL;
Quoted 8 lines

testcases/kernel/syscalls/mallinfo2/mallinfo201.c line 31

Quoted 6 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +6 -0
+
+	buf = malloc(size);
+	if (!buf) {
+		tst_res(TCONF, "Current system can not malloc 2G space, skip it");
+		return;
+	}

BTW sometimes I wonder if we should have something like SAFE_*() functions which would result with TCONF, not with TBROK.

IMO, I don't want to add a flag in SAFE_* functions to control return TCONF or TBORK because it is clear enough now. Other maintainers may have different option. But Now, I want to keep it.

Quoted 11 lines
Quoted 11 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +10 -0
+	info = mallinfo2();
+	if (info.hblkhd<  size) {
+		print_mallinfo2("Test malloc 2G",&info);
+		tst_brk(TFAIL, "The member of struct mallinfo2 overflow?");
+	}
+	tst_res(TPASS, "The member of struct mallinfo2 doesn't overflow");
+	free(buf);
+}
+
+static struct tst_test test = {
Quoted 8 lines

testcases/kernel/syscalls/mallinfo2/mallinfo201.c line 47

Quoted 6 lines
testcases/kernel/syscalls/mallinfo2/mallinfo201.c new file +6 -0
+	.test_all = test_mallinfo2,
+};
+
+#else
+TST_TEST_TCONF("system doesn't implement non-POSIX mallinfo2()");
+#endif

The rest LGTM.

Thanks for your review. I will send a v2 patch soon.

Quoted 3 lines

Kind regards,
Petr

author
#3 lore raw

PATCH v2 1/1 syscalls/mallinfo2_01: Add a basic test for mallinfo2 when setting 2G size

In reply to Petr Vorel

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. So we test mallinfo2 whether works well.

---
 configure.ac                                  |  1 +
 runtest/syscalls                              |  2 +
 .../syscalls/mallinfo/mallinfo_common.h       | 19 ++++++++
 .../kernel/syscalls/mallinfo2/.gitignore      |  1 +
 testcases/kernel/syscalls/mallinfo2/Makefile  | 11 +++++
 .../kernel/syscalls/mallinfo2/mallinfo2_01.c  | 46 +++++++++++++++++++
 6 files changed, 80 insertions(+)
 create mode 100644 testcases/kernel/syscalls/mallinfo2/.gitignore
 create mode 100644 testcases/kernel/syscalls/mallinfo2/Makefile
 create mode 100644 testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c
configure.ac +1 -0
index 136d82d09..eb675b367 100644
@@ -102,6 +102,7 @@ AC_CHECK_FUNCS_ONCE([ \
     io_uring_enter \
     kcmp \
     mallinfo \
+    mallinfo2 \
     mallopt \
     mkdirat \
     mknodat \
runtest/syscalls +2 -0
index 9df181b76..11bb58a83 100644
@@ -692,6 +692,8 @@ lstat02_64 lstat02_64
 
 mallinfo02 mallinfo02
 
+mallinfo2_01 mallinfo2_01
+
 mallopt01 mallopt01
 
 mbind01 mbind01
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +19 -0
index a00cc7a64..d64a9344b 100644
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (C) 2020 Free Software Foundation, Inc.
  * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <[email protected]>
  */
@@ -28,4 +29,22 @@ static inline void print_mallinfo(const char *msg, struct mallinfo *m)
 }
 #endif
 
+#ifdef HAVE_MALLINFO2
+static inline void print_mallinfo2(const char *msg, struct mallinfo2 *m)
+{
+	tst_res(TINFO, "%s...", msg);
+#define P2(f) tst_res(TINFO, "%s: %ld", #f, m->f)
+	P2(arena);
+	P2(ordblks);
+	P2(smblks);
+	P2(hblks);
+	P2(hblkhd);
+	P2(usmblks);
+	P2(fsmblks);
+	P2(uordblks);
+	P2(fordblks);
+	P2(keepcost);
+}
+#endif
+
 #endif
testcases/kernel/syscalls/mallinfo2/.gitignore new file +1 -0
new file mode 100644
index 000000000..349222c14
@@ -0,0 +1 @@
+/mallinfo2_01
testcases/kernel/syscalls/mallinfo2/Makefile new file +11 -0
new file mode 100644
index 000000000..b3c7d9552
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) International Business Machines  Corp., 2001
+# Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS += -I../mallinfo
+
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
2.23.0
#4 lore raw

PATCH v2 1/1 syscalls/mallinfo2_01: Add a basic test for mallinfo2 when setting 2G size

Hi Xu,

...

Quoted 9 lines

+++ b/testcases/kernel/syscalls/mallinfo/mallinfo_common.h

testcases/kernel/syscalls/mallinfo/mallinfo_common.h +1 -0
@@ -1,5 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
+ * Copyright (C) 2020 Free Software Foundation, Inc.
  * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
  * Author: Yang Xu <[email protected]>
  */

testcases/kernel/syscalls/mallinfo/mallinfo_common.h static inline void print_mallinfo(const char *msg, struct mallinfo *m) · line 35

Quoted 7 lines
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +4 -0
@@ -28,4 +29,22 @@ static inline void print_mallinfo(const char *msg, struct mallinfo *m)
 }
 #endif
 
+#ifdef HAVE_MALLINFO2
+static inline void print_mallinfo2(const char *msg, struct mallinfo2 *m)
+{
+	tst_res(TINFO, "%s...", msg);

nit: I'd remove "..." and add extra space before #define (readability) And also change it on previously added print_mallinfo().

Quoted 13 lines
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +13 -0
+#define P2(f) tst_res(TINFO, "%s: %ld", #f, m->f)
+	P2(arena);
+	P2(ordblks);
+	P2(smblks);
+	P2(hblks);
+	P2(hblkhd);
+	P2(usmblks);
+	P2(fsmblks);
+	P2(uordblks);
+	P2(fordblks);
+	P2(keepcost);
+}
+#endif

...

Quoted 4 lines

+++ b/testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c

testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +2 -0
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*

testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c line 12

Quoted 10 lines
testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +10 -0
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu <[email protected]>
+ */
+
+/*\
+ * [DESCRIPTION]
+ *
+ * Basic mallinfo2() test.
+ *
+ * Test members of struct mallinfo2() whether overflow when setting 2G size.

* Test hblkhd member of struct mallinfo2 whether overflow when setting 2G size.

Quoted 8 lines
testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +8 -0
+ */
+
+#include "mallinfo_common.h"
+#include "tst_safe_macros.h"
+
+#ifdef HAVE_MALLINFO2
+
+void test_mallinfo2(void)

testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c line 30

Quoted 10 lines
testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +10 -0
+{
+	struct mallinfo2 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;
+	}

Here could be just:

	if (!buf)
		tst_brk(TCONF, "Current system can not malloc 2G space, skip it");

testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c line 34

Quoted 4 lines
testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +4 -0
+	info = mallinfo2();
+	if (info.hblkhd < size) {
+		print_mallinfo2("Test malloc 2G", &info);
+		tst_brk(TFAIL, "The member of struct mallinfo2 overflow?");

You don't free buf here.

Maybe something like:

	if (info.hblkhd < size) {
		print_mallinfo2("Test malloc 2G", &info);
		tst_res(TFAIL, "hblkhd member of struct mallinfo2 overflow?");
	} else {
		tst_res(TPASS, "hblkhd member of struct mallinfo2 doesn't overflow");
	}

	free(buf);

If you're ok with it, no need to repost, I'll change it before merge.

Kind regards,
Petr

#5 lore raw

PATCH v2 1/1 syscalls/mallinfo2_01: Add a basic test for mallinfo2 when setting 2G size

Hi Petr

Quoted 92 lines

Hi Xu,

...

Quoted 9 lines

+++ b/testcases/kernel/syscalls/mallinfo/mallinfo_common.h

testcases/kernel/syscalls/mallinfo/mallinfo_common.h +1 -0
@@ -1,5 +1,6 @@
  // SPDX-License-Identifier: GPL-2.0-or-later
  /*
+ * Copyright (C) 2020 Free Software Foundation, Inc.
   * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
   * Author: Yang Xu<[email protected]>
   */

testcases/kernel/syscalls/mallinfo/mallinfo_common.h static inline void print_mallinfo(const char *msg, struct mallinfo *m) · line 35

Quoted 7 lines
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +4 -0
@@ -28,4 +29,22 @@ static inline void print_mallinfo(const char *msg, struct mallinfo *m)
  }
  #endif
 
+#ifdef HAVE_MALLINFO2
+static inline void print_mallinfo2(const char *msg, struct mallinfo2 *m)
+{
+	tst_res(TINFO, "%s...", msg);

nit: I'd remove "..." and add extra space before #define (readability) And also change it on previously added print_mallinfo().

Quoted 13 lines
testcases/kernel/syscalls/mallinfo/mallinfo_common.h +13 -0
+#define P2(f) tst_res(TINFO, "%s: %ld", #f, m->f)
+	P2(arena);
+	P2(ordblks);
+	P2(smblks);
+	P2(hblks);
+	P2(hblkhd);
+	P2(usmblks);
+	P2(fsmblks);
+	P2(uordblks);
+	P2(fordblks);
+	P2(keepcost);
+}
+#endif

...

Quoted 4 lines

+++ b/testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c

testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +2 -0
@@ -0,0 +1,46 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*

testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c line 12

Quoted 10 lines
testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +10 -0
+ * Copyright (c) 2021 FUJITSU LIMITED. All rights reserved.
+ * Author: Yang Xu<[email protected]>
+ */
+
+/*\
+ * [DESCRIPTION]
+ *
+ * Basic mallinfo2() test.
+ *
+ * Test members of struct mallinfo2() whether overflow when setting 2G size.

* Test hblkhd member of struct mallinfo2 whether overflow when setting 2G size.

Quoted 8 lines
testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +8 -0
+ */
+
+#include "mallinfo_common.h"
+#include "tst_safe_macros.h"
+
+#ifdef HAVE_MALLINFO2
+
+void test_mallinfo2(void)

testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c line 30

Quoted 10 lines
testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +10 -0
+{
+	struct mallinfo2 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;
+	}

Here could be just:

	if (!buf)
		tst_brk(TCONF, "Current system can not malloc 2G space, skip it");

testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c line 34

Quoted 4 lines
testcases/kernel/syscalls/mallinfo2/mallinfo2_01.c new file +4 -0
+	info = mallinfo2();
+	if (info.hblkhd<  size) {
+		print_mallinfo2("Test malloc 2G",&info);
+		tst_brk(TFAIL, "The member of struct mallinfo2 overflow?");

You don't free buf here.

Maybe something like:

	if (info.hblkhd<  size) {
		print_mallinfo2("Test malloc 2G",&info);
		tst_res(TFAIL, "hblkhd member of struct mallinfo2 overflow?");
	} else {
		tst_res(TPASS, "hblkhd member of struct mallinfo2 doesn't overflow");
	}

	free(buf);
Quoted 1 line

If you're ok with it, no need to repost, I'll change it before merge.

I am ok with these changes. Thanks for your review.

Best Regards
Yang Xu

Quoted 3 lines

Kind regards,
Petr

#6 lore raw

PATCH v2 1/1 syscalls/mallinfo2_01: Add a basic test for mallinfo2 when setting 2G size

In reply to Yang Xu

Hi Xu,

Quoted 1 line

+++ b/testcases/kernel/syscalls/mallinfo2/Makefile

...

testcases/kernel/syscalls/mallinfo2/Makefile line 9

Quoted 6 lines
testcases/kernel/syscalls/mallinfo2/Makefile new file +6 -0
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS += -I../mallinfo

Also this needs to be
CFLAGS += -I$(abs_srcdir)/../mallinfo

otherwise out of tree builds fail:
https://github.com/pevik/ltp/actions/runs/941820122

BTW Cyril also suggested recently to drop out of tree support, because build system dependencies are broken and fixing it would be much easier when supporting only in tree build.

Kind regards,
Petr

#7 lore raw

PATCH v2 1/1 syscalls/mallinfo2_01: Add a basic test for mallinfo2 when setting 2G size

Hi Petr

Quoted 4 lines

Hi Xu,

Quoted 1 line

+++ b/testcases/kernel/syscalls/mallinfo2/Makefile

...

Quoted 9 lines

testcases/kernel/syscalls/mallinfo2/Makefile line 9

Quoted 6 lines
testcases/kernel/syscalls/mallinfo2/Makefile new file +6 -0
+
+top_srcdir		?= ../../../..
+
+include $(top_srcdir)/include/mk/testcases.mk
+
+CFLAGS += -I../mallinfo

Also this needs to be
CFLAGS += -I$(abs_srcdir)/../mallinfo

You are right. It will fail when out of tree.

Quoted 6 lines

otherwise out of tree builds fail:
https://github.com/pevik/ltp/actions/runs/941820122

BTW Cyril also suggested recently to drop out of tree support, because build system dependencies are broken and fixing it would be much easier when supporting only in tree build.

On my test envrionment, I never use out of tree build. So I am fine with removing it.

Quoted 3 lines

Kind regards,
Petr

#8 lore raw

PATCH v2 1/1 syscalls/mallinfo2_01: Add a basic test for mallinfo2 when setting 2G size

Hi Xu,

Merged with all my suggested changes + slightly adjusted docparse description and commit message.

Thanks a lot!

Kind regards,
Petr

#9 lore raw

PATCH v2 1/1 syscalls/mallinfo2_01: Add a basic test for mallinfo2 when setting 2G size

In reply to Petr Vorel

Hi,

Quoted 4 lines · Petr Vorel

BTW Cyril also suggested recently to drop out of tree support, because build system dependencies are broken and fixing it would be much easier when supporting only in tree build.

Really? I got the feeling out-of-tree builds are becoming the new normal and even complex pieces of software like the kernel, glibc and gcc are able to be built out-of-tree or even enforce it.
Maybe it is time to abandon autoconf/automake and switch to a better build configuration systems like cmake instead of abandoning out-of-tree builds.

J?rg

#10 lore raw

PATCH v2 1/1 syscalls/mallinfo2_01: Add a basic test for mallinfo2 when setting 2G size

Hi!

Quoted 6 lines
Quoted 3 lines

BTW Cyril also suggested recently to drop out of tree support, because build system dependencies are broken and fixing it would be much easier when supporting only in tree build.

Really? I got the feeling out-of-tree builds are becoming the new normal and even complex pieces of software like the kernel, glibc and gcc are able to be built out-of-tree or even enforce it.

The question here really if support of out-of-tree build is worth the trouble. The problem is that the complexity it adds to the build system is quite high. The way it's implemented in LTP the build system has to work with absolute paths and you have to make sure you have the right path to a file all the time and people are often confused by this. Also it crashes and burns with cryptic error messages if you happen to have characters interpreted by make in a directory name anywhere from the LTP dir to the filesystems root (try adding : to a directory name for instance). We used to have out-of-tree build broken for years, before we set up a CI, and nobody complained. So considering all of this it may be for the better to just get rid of it.

I'm not against out-of-tree build in principle but given that the way it's implemented in LTP is subtly broken by design and that there does not seem to be real users it does not make that much sense to keep it maintained and spend any effort to keep it afloat.

Quoted 3 lines

Maybe it is time to abandon autoconf/automake and switch to a better build configuration systems like cmake instead of abandoning out-of-tree builds.

I'm not againts this, the main problem is that this will take a significant effort my guess is at least month to implement and and even more to iron out all the corner cases. Also the choosen build systems has to be generally available even on 10 years old system, but I guess that cmake should classify easily here.

Signature · 2 lines
Cyril Hrubis
[email protected]