[LTP] [PATCH 2/5] syscalls/adjtimex02: Convert to new library

Cyril Hrubis chrubis@suse.cz
Wed May 29 12:12:27 CEST 2019


Hi!
> +	buff = tim_save;
> +	buff.modes = SET_MODE;
> +	switch (nr) {
> +	case 0:
> +		break;
> +	case 1:
> +		buff.tick = 900000 / hz - 1;
> +		break;
> +	case 2:
> +		buff.tick = 1100000 / hz + 1;
> +		break;
> +	case 3:
> +		/* Switch to nobody user for correct error code collection */
> +		ltpuser = SAFE_GETPWNAM("nobody");
> +		SAFE_SETEUID(ltpuser->pw_uid);
> +		break;
> +	case 4:
> +		buff.offset = 512000L + 1;
> +		break;
> +	case 5:
> +		buff.offset = (-1) * (512000L) - 1;
> +		break;
> +	default:
> +		tst_brk(TFAIL, "Invalid test case %u ", nr);
> +	}


What I do not like about this is that half of the data is now in the
structure with errnos while the other half is encoded in this switch and
we depend on the order of the structure.

In this case I think that the cleaner option would be getting rid of the
structure and set the expected errno in the switch. That way all the
data would be in a single place at least.

> -	tst_exit();
> +	TEST(adjtimex(tcase->buffp));
> +	if ((TST_RET == -1) && (TST_ERR == tcase->exp_errno)) {
> +		tst_res(TPASS | TTERRNO,
> +				"adjtimex() error %u ", tcase->exp_errno);
> +	} else {
> +		tst_res(TFAIL | TTERRNO,
> +				"Test Failed, adjtimex() returned %ld",
> +				TST_RET);
> +	}
>  
> +	/* clean up after ourselves */
> +	if (nr == 3)
> +		SAFE_SETEUID(0);
>  }

-- 
Cyril Hrubis
chrubis@suse.cz


More information about the ltp mailing list