[LTP] [PATCH] Add case about arch_prctl syscall.

路斐 lufei@uniontech.com
Wed May 8 04:29:00 CEST 2024


Hi, Cyril. 
Thanks again very much.


As written in man page, ENODEV seems only for ARCH_SET_CPUID, so I didn't use TST_EXP_FAIL in ARCH_GET_CPUID check. ARCH_GET_CPUID always success with returning cpuid status, I've tested this on a Intel J1900 machine witch has no cpuid_fault flag. I've resent the patch.

Lu Fei
site:www.uniontech.com
tel:(+86)18501012352
addr: Xi'an, China 



 
 
------------------ Original ------------------
From:  "Cyril Hrubis"<chrubis@suse.cz>;
Date:  Tue, May 7, 2024 12:51 PM
To:  "lufei"<lufei@uniontech.com>; 
Cc:  "ltp"<ltp@lists.linux.it>; "jstancek"<jstancek@redhat.com>; 
Subject:  Re: [PATCH] Add case about arch_prctl syscall.

 

Hi!
> +static void run(unsigned int index)
> +{
> +	struct tcase tc = tcases[index];
> +
> +	TEST(arch_prctl_set(ARCH_SET_CPUID, tc.input));
> +
> +	if (TST_RET == tc.set_exp)
> +		if (tc.set_exp == -1)
> +			tst_res((TST_ERR == tc.tst_errno ? TPASS : TFAIL),
> +				"set cpuid, expect: %s, get: %s",
> +				tst_strerrno(tc.tst_errno),
> +				tst_strerrno(TST_ERR));
> +		else
> +			tst_res(TPASS, "set cpuid succeed.");
> +	else
> +		tst_res(TFAIL, "set cpuid failed.");

This is kind of ugly, why can't we just do:

	if (tag)
		TST_EXP_PASS(arch_prctl_set(ARCH_SET_CPUID, index));
	else
		TST_EXP_FAIL(arch_prctl_set(ARCH_SET_CPUID, index), ENODEV);

> +	TEST(arch_prctl_get(ARCH_GET_CPUID));
> +
> +	if (TST_RET == tc.get_exp)
> +		tst_res(TPASS, "get cpuid succeed.");
> +	else
> +		tst_res(TFAIL, "get cpuid failed.");


We have to check the errno here as well, just branch on the tag as well:

	if (tag) {
		TEST(arch_prctl_get(ARCH_GET_CPUID));

		if (TST_RET == index)
			tst_res(TPASS, "...");
		else
			tst_res(FAIL, "...");
	} else {
		TST_EXP_FAIL(arch_prctl_get(ARCH_GET_CPUID), ENODEV);
	}

Generally the use of TST_EXP_FAIL() is prefered whenever possible.

> +}
> +
> +static struct tst_test test = {
> +	.test = run,
> +	.setup = setup,
> +	.tcnt = ARRAY_SIZE(tcases),
> +	.min_kver = "4.12",
> +	.supported_archs = (const char *const []){"x86_64", "x86", NULL}
> +};
> +
> +#else /* HAVE_ASM_PRCTL_H */
> +TST_TEST_TCONF("missing <asm/prctl.h>");
> +#endif
> -- 
> 2.39.3
> 

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list