[LTP] [PATCH v8 1/5] sched_setattr01: Convert to new API
Cyril Hrubis
chrubis@suse.cz
Thu Sep 10 12:40:56 CEST 2026
Hi!
> +static void verify_sched_setattr(unsigned int n)
> {
> - TEST(sched_setattr(*(test->pid), test->a, test->flags));
> -
> - if (TEST_RETURN != test->exp_return) {
> - tst_resm(TFAIL | TTERRNO, "sched_setattr(%i,attr,%u) "
> - "returned: %ld expected: %d",
> - *(test->pid), test->flags,
> - TEST_RETURN, test->exp_return);
> + struct tcase *tc = &tcases[n];
> + pid_t pid = tc->pid ? *tc->pid : 0;
> + struct sched_attr *target_attr = tc->bad_attr ? bad_addr : tc->attr;
> + struct sched_attr read_attr = { .size = sizeof(read_attr) };
> +
> + /*
> + * The kernel writes sizeof(struct sched_attr) back to uattr->size
> + * on the -E2BIG error path, clobbering our test input. Refresh
> + * before each call so re-runs (e.g. -i N) still exercise the
> + * intended size.
> + */
> + attr_small.size = SCHED_ATTR_SIZE_VER0 - 1;
> +
> + if (tc->exp_errno) {
> + TST_EXP_FAIL(sched_setattr(pid, target_attr, tc->flags),
> + tc->exp_errno, "%s", tc->desc);
> return;
> }
>
> - if (TEST_ERRNO == test->exp_errno) {
> - tst_resm(TPASS | TTERRNO,
> - "sched_setattr() works as expected");
> + TST_EXP_PASS(sched_setattr(pid, target_attr, tc->flags),
> + "%s", tc->desc);
> + if (!TST_PASS)
> return;
> - }
> -
> - tst_resm(TFAIL | TTERRNO, "sched_setattr(%i,attr,%u): "
> - "expected: %d - %s",
> - *(test->pid), test->flags,
> - test->exp_errno, tst_strerrno(test->exp_errno));
> -}
> -
> -int main(int argc, char **argv)
> -{
> - pthread_t thread;
> - int lc;
>
> - tst_parse_opts(argc, argv, NULL, NULL);
> -
> - setup();
> -
> - for (lc = 0; TEST_LOOPING(lc); lc++) {
> - pthread_create(&thread, NULL, do_test, NULL);
> - pthread_join(thread, NULL);
> + if (sched_getattr(pid, &read_attr, sizeof(read_attr), 0) == -1) {
> + tst_res(TFAIL | TERRNO, "sched_getattr() failed");
> + return;
> }
>
> - tst_exit();
> + TST_EXP_EQ_LU(read_attr.sched_policy, SCHED_DEADLINE);
> + TST_EXP_EQ_LU(read_attr.sched_runtime, RUNTIME_VAL);
> + TST_EXP_EQ_LU(read_attr.sched_deadline, DEADLINE_VAL);
> + TST_EXP_EQ_LU(read_attr.sched_period, PERIOD_VAL);
> +
> + reset_sched();
> }
Can we please split the passing test into a separate testcase?
Mixing possitive and negative tests into single source makes things
more complex for no good reason...
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list