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) with a NULL buffer and expects failure.
6 */
7
8 #include "lapi/getrandom.h"
9 #include "lapi/syscalls.h"
10 #include "tst_test.h"
11
12 static int modes[] = {0, GRND_RANDOM, GRND_NONBLOCK,
13 GRND_RANDOM | GRND_NONBLOCK};
14
verify_getrandom(unsigned int n)15 static void verify_getrandom(unsigned int n)
16 {
17 TEST(tst_syscall(__NR_getrandom, NULL, 100, modes[n]));
18
19 if (TST_RET == -1) {
20 tst_res(TPASS | TTERRNO, "getrandom returned %ld",
21 TST_RET);
22 } else {
23 tst_res(TFAIL | TTERRNO, "getrandom failed");
24 }
25 }
26
27 static struct tst_test test = {
28 .tcnt = ARRAY_SIZE(modes),
29 .test = verify_getrandom,
30 };
31