[LTP] [PATCH v2 10/33] keyctl18: Test basic KEYCTL_MOVE
Cyril Hrubis
chrubis@suse.cz
Fri Sep 11 13:48:16 CEST 2026
Hi!
> +static key_serial_t ring_a, ring_b;
> +static key_serial_t key;
> +
> +static void setup(void)
> +{
> + SAFE_KEYCTL(KEYCTL_JOIN_SESSION_KEYRING, 0, 0, 0, 0);
> +
> + ring_a = new_ring(RING_A_DESC);
> + ring_b = new_ring(RING_B_DESC);
> + key = new_user_key(KEY_DESC, PAYLOAD, sizeof(PAYLOAD), ring_a);
> +}
> +
> +static void reset_state(void)
> +{
> + SAFE_KEYCTL(KEYCTL_LINK, key, ring_a, 0, 0);
> + TEST(keyctl(KEYCTL_UNLINK, key, ring_b, 0, 0));
> + if (TST_RET == -1 && TST_ERR != ENOENT)
> + tst_brk(TBROK | TTERRNO, "failed to unlink key from ring_b");
We are trying to avoid hypotetical TBROK here in the case that the MOVE
didn't work right? I'm not sure it's worth the trouble.
> +}
> +
> +static void run(void)
> +{
> + reset_state();
> +
> + TST_EXP_PASS(keyctl(KEYCTL_MOVE, key, ring_a, ring_b, 0));
> + if (!TST_PASS)
> + return;
> +
> + TST_EXP_EQ_LI(search_ring(ring_b, "user", KEY_DESC), key);
> +
> + TST_EXP_FAIL2(search_ring(ring_a, "user", KEY_DESC), ENOKEY,
> + "key no longer found in the source keyring");
Here the search_string() function actually hides the syscall being
used. I would prefer having the keyctl() call in these two.
> +}
> +
> +static struct tst_test test = {
> + .setup = setup,
> + .test_all = run,
> + .min_kver = "5.3",
> +};
>
> --
> 2.51.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
More information about the ltp
mailing list