1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2015 Cedric Hnyda <ced.hnyda@gmail.com>
4 *
5 * Calls getrandom(2), check that the return value is equal to the
6 * number of bytes required and expects success.
7 */
8
9 #include "lapi/getrandom.h"
10 #include "lapi/syscalls.h"
11 #include "tst_test.h"
12
13 #define MAX_SIZE 256
14
15 static unsigned int sizes[] = {
16 1,
17 2,
18 3,
19 7,
20 8,
21 15,
22 22,
23 64,
24 127,
25 };
26
verify_getrandom(unsigned int n)27 static void verify_getrandom(unsigned int n)
28 {
29 char buf[MAX_SIZE];
30
31 TEST(tst_syscall(__NR_getrandom, buf, sizes[n], 0));
32
33 if (TST_RET != sizes[n]) {
34 tst_res(TFAIL | TTERRNO, "getrandom returned %li, expected %u",
35 TST_RET, sizes[n]);
36 } else {
37 tst_res(TPASS, "getrandom returned %ld", TST_RET);
38 }
39 }
40
41 static struct tst_test test = {
42 .tcnt = ARRAY_SIZE(sizes),
43 .test = verify_getrandom,
44 };
45