Skip to contentSkip to conversation

Migrating the libhugetlbfs/testcases/quota.c

PATCH In review Pavithra 2 participants 2 messages Feb 19 – Mar 24

lore
Share & tools
lore

Pavithra

author
#0 lore raw

PATCH 1/1 Migrating the libhugetlbfs/testcases/quota.c

Test hugetlbfs quota accounting with filesystem size limits.

---
 runtest/hugetlb                               |   1 +
 testcases/kernel/mem/.gitignore               |   1 +
 .../kernel/mem/hugetlb/hugemmap/hugemmap33.c  | 298 ++++++++++++++++++
 3 files changed, 300 insertions(+)
 create mode 100644 testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c
runtest/hugetlb +1 -0
index 0896d3c94..24fa717ec 100644
@@ -35,6 +35,7 @@ hugemmap29 hugemmap29
 hugemmap30 hugemmap30
 hugemmap31 hugemmap31
 hugemmap32 hugemmap32
+hugemmap33 hugemmap33
 hugemmap34 hugemmap34
 hugemmap05_1 hugemmap05 -m
 hugemmap05_2 hugemmap05 -s
testcases/kernel/mem/.gitignore +1 -0
index b4455de51..7f1bcd4e7 100644
@@ -35,6 +35,7 @@
 /hugetlb/hugemmap/hugemmap30
 /hugetlb/hugemmap/hugemmap31
 /hugetlb/hugemmap/hugemmap32
+/hugetlb/hugemmap/hugemmap33
 /hugetlb/hugemmap/hugemmap34
 /hugetlb/hugeshmat/hugeshmat01
 /hugetlb/hugeshmat/hugeshmat02
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +298 -0

298 lines not on this page · raw message

Signature · 5 lines
2.52.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi Pavithra,

Consider this as a simple first-looking review. Probably more will come when you will send more patches.

Thanks for working on migrating this test. A few issues below that need to be addressed before this can be merged.

Quoted 3 lines

+/*\
+ * [Description]
+ *

The [Description] tag is deprecated and must be removed. Just start the doc comment directly with the text.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 31

Quoted 9 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +9 -0
+#define _GNU_SOURCE
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <sys/vfs.h>
+#include <sys/statfs.h>
+#include <sys/mount.h>
+
+#include "hugetlb.h"
+#include "tst_safe_macros.h"

The "tst_safe_macros.h" include is redundant since tst_test.h (pulled in by hugetlb.h) already includes it. Please drop it.

Quoted 8 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +5 -0
+static void verify_quota_stat(int line, long tot, long free, long avail)
+{
+[...]
+		tst_res_(NULL, line, TFAIL,
 
+#define VERIFY_QUOTA_STAT(t, f, a) verify_quota_stat(__LINE__, t, f, a)

static void do_map(unsigned long size, int mmap_flags, int action_flags)

In this function it's better to use goto to cleanup memory at the end of it. So we reduce nesting after mmap() failure. Also, should we TBROK mmap() when there's no quota pressure but the syscall fails? At the moment we are failing for mmap() for any type of errno.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 146

Quoted 6 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +5 -0
+static void test_quota_scenario(int line, int expected_result,
+[...]
+		tst_res_(NULL, line, TFAIL,
 
+#define TEST_QUOTA(exp, size, flags, actions) \
+	test_quota_scenario(__LINE__, exp, size, flags, actions)

tst_res_() is an internal LTP API and must not be used directly by tests. Drop the __LINE__ parameter and the wrapper macros, and use plain tst_res(TFAIL, ...) instead. The failure messages already contain enough context (quota counter values, expected vs actual result) to identify which check failed without needing line numbers.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 138

Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3 -0
+	if (actual_result != expected_result) {
+		const char *result_names[] = {"success", "signal", "failure"};
+		tst_res_(NULL, line, TFAIL,

checkpatch flags two issues here:
- result_names[] should be static const
- missing blank line after the declaration

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 267

Quoted 3 lines
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +3 -0
+	if (mount("none", quota_mnt, "hugetlbfs", 0, mount_opts) == -1) {
+		if (errno == ENOSYS || errno == ENODEV)
+			tst_brk(TCONF, "hugetlbfs not supported");

checkpatch warns about ENOSYS here. ENOSYS means "invalid syscall number" and mount() will not return it. ENODEV alone is sufficient to detect missing hugetlbfs support.

testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c line 292

Quoted 1 line
testcases/kernel/mem/hugetlb/hugemmap/hugemmap33.c new file +1 -0
+	.needs_tmpdir = 1,

The test already has .mntpoint and .needs_hugetlbfs set, so it gets a temporary directory via the hugetlbfs mount infrastructure. Is .needs_tmpdir = 1 actually needed here? If the test does not create files outside MNTPOINT (it does not appear to), this can be dropped.

Also, in general, I think that we should have multiple test cases for different types of quota, instead of calling the test_quota_scenario() with different parameters one after another. In this way we can organise test in a better way and reduce redundancy inside the code.

Regards,
--
Andrea Cervesato
SUSE QE Automation Engineer Linux
[email protected]

Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp