1*49cdfc7eSAndroid Build Coastguard Worker // SPDX-License-Identifier: GPL-2.0-or-later
2*49cdfc7eSAndroid Build Coastguard Worker /*
3*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) 2024 FUJITSU LIMITED. All Rights Reserved.
4*49cdfc7eSAndroid Build Coastguard Worker * Copyright (c) Linux Test Project, 2024
5*49cdfc7eSAndroid Build Coastguard Worker * Author: Yang Xu <[email protected]>
6*49cdfc7eSAndroid Build Coastguard Worker */
7*49cdfc7eSAndroid Build Coastguard Worker
8*49cdfc7eSAndroid Build Coastguard Worker /*\
9*49cdfc7eSAndroid Build Coastguard Worker * [Description]
10*49cdfc7eSAndroid Build Coastguard Worker *
11*49cdfc7eSAndroid Build Coastguard Worker * Verify that getrandom(2) fails with
12*49cdfc7eSAndroid Build Coastguard Worker *
13*49cdfc7eSAndroid Build Coastguard Worker * - EFAULT when buf address is outside the accessible address space
14*49cdfc7eSAndroid Build Coastguard Worker * - EINVAL when flag is invalid
15*49cdfc7eSAndroid Build Coastguard Worker */
16*49cdfc7eSAndroid Build Coastguard Worker
17*49cdfc7eSAndroid Build Coastguard Worker #include "tst_test.h"
18*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/getrandom.h"
19*49cdfc7eSAndroid Build Coastguard Worker
20*49cdfc7eSAndroid Build Coastguard Worker static char buff_efault[64];
21*49cdfc7eSAndroid Build Coastguard Worker static char buff_einval[64];
22*49cdfc7eSAndroid Build Coastguard Worker
23*49cdfc7eSAndroid Build Coastguard Worker static struct test_case_t {
24*49cdfc7eSAndroid Build Coastguard Worker char *buff;
25*49cdfc7eSAndroid Build Coastguard Worker size_t size;
26*49cdfc7eSAndroid Build Coastguard Worker unsigned int flag;
27*49cdfc7eSAndroid Build Coastguard Worker int expected_errno;
28*49cdfc7eSAndroid Build Coastguard Worker char *desc;
29*49cdfc7eSAndroid Build Coastguard Worker } tcases[] = {
30*49cdfc7eSAndroid Build Coastguard Worker {(void *)-1, sizeof(buff_efault), 0, EFAULT,
31*49cdfc7eSAndroid Build Coastguard Worker "buf address is outside the accessible address space"},
32*49cdfc7eSAndroid Build Coastguard Worker {buff_einval, sizeof(buff_einval), -1, EINVAL, "flag is invalid"},
33*49cdfc7eSAndroid Build Coastguard Worker };
34*49cdfc7eSAndroid Build Coastguard Worker
verify_getrandom(unsigned int i)35*49cdfc7eSAndroid Build Coastguard Worker static void verify_getrandom(unsigned int i)
36*49cdfc7eSAndroid Build Coastguard Worker {
37*49cdfc7eSAndroid Build Coastguard Worker struct test_case_t *tc = &tcases[i];
38*49cdfc7eSAndroid Build Coastguard Worker
39*49cdfc7eSAndroid Build Coastguard Worker TST_EXP_FAIL2(getrandom(tc->buff, tc->size, tc->flag),
40*49cdfc7eSAndroid Build Coastguard Worker tc->expected_errno, "%s", tc->desc);
41*49cdfc7eSAndroid Build Coastguard Worker }
42*49cdfc7eSAndroid Build Coastguard Worker
43*49cdfc7eSAndroid Build Coastguard Worker static struct tst_test test = {
44*49cdfc7eSAndroid Build Coastguard Worker .tcnt = ARRAY_SIZE(tcases),
45*49cdfc7eSAndroid Build Coastguard Worker .test = verify_getrandom,
46*49cdfc7eSAndroid Build Coastguard Worker };
47