Thread (11 messages) 11 messages, 2 authors, 2025-06-11

Re: [PATCH v5 5/6] kselftest/arm64/mte: refactor check_mmap_option test

From: Mark Brown <broonie@kernel.org>
Date: 2025-06-10 15:38:30
Also in: linux-doc, lkml

On Tue, Jun 10, 2025 at 04:01:43PM +0100, Yeoreum Yun wrote:
Before add mtefar testcase on check_mmap_option.c,
refactor check_mmap_option.
Please describe the intended refactoring here.
+#define CHECK_ANON_MEM		0
+#define CHECK_FILE_MEM		1
+#define CHECK_CLEAR_PROT_MTE	2
+
Perhaps use enums for this sort of thing?
+{
+	static char test_name[TEST_NAME_MAX];
+	const char* check_type_str;
Coding style would usually be

	const char *check_type_str;
+	snprintf(test_name, TEST_NAME_MAX,
+	         "Check %s with %s mapping, %s mode, %s memory and %s\n",
+	         check_type_str, mapping_str, sync_str, mem_type_str, tag_check_str);
sizeof(test_name).
 	evaluate_test(check_anonymous_memory_mapping(USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, TAG_CHECK_OFF),
-	"Check anonymous memory with private mapping, sync error mode, mmap memory and tag check off\n");
+		      format_test_name(CHECK_ANON_MEM, USE_MMAP, MTE_SYNC_ERR, MAP_PRIVATE, TAG_CHECK_OFF));
Looking at this I can't help but think that the more common pattern for
test programs where we have an array of test parameters that we loop
through might make sense:

	for (i = 0; i < ARRAY_SIZE(test_cases); i++) {
		format_test_name(test_cases[i]);

		switch (test_cases[i].test_type) {
		case CHECK_ANON_MEM:
			check_anonymous_memory_mapping(USE_MMAP, ...);

That seems a bit more legible and maintainable.
 	mte_disable_pstate_tco();
The management of this could be added as a parameter in the test struct.

Attachments

Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help