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

Mark Brown broonie at kernel.org
Tue Jun 10 08:38:25 PDT 2025


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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20250610/c43330b3/attachment.sig>


More information about the linux-arm-kernel mailing list