1 /*
2 * Copyright (C) 2015 Cedric Hnyda ced.hnyda@gmail.com
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * Further, this software is distributed without any warranty that it is
13 * free of the rightful claim of any third person regarding infringement
14 * or the like. Any license provided herein, whether implied or
15 * otherwise, applies only to this software file. Patent licenses, if
16 * any, provided herein do not apply to combinations of this program with
17 * other software, or any other product whatsoever.
18 *
19 */
20
21 /*
22 * AUTHOR : Cédric Hnyda
23 * DATE STARTED : 06/13/2015
24 *
25 * Calls getrandom(2) with a NULL buffer and expects failure.
26 *
27 */
28
29 #include "lapi/getrandom.h"
30 #include "lapi/syscalls.h"
31 #include "tst_test.h"
32
33 static int modes[] = {0, GRND_RANDOM, GRND_NONBLOCK,
34 GRND_RANDOM | GRND_NONBLOCK};
35
verify_getrandom(unsigned int n)36 static void verify_getrandom(unsigned int n)
37 {
38 TEST(tst_syscall(__NR_getrandom, NULL, 100, modes[n]));
39
40 if (TEST_RETURN == -1) {
41 tst_res(TPASS | TTERRNO, "getrandom returned %ld",
42 TEST_RETURN);
43 } else {
44 tst_res(TFAIL | TTERRNO, "getrandom failed");
45 }
46 }
47
48 static struct tst_test test = {
49 .tcnt = ARRAY_SIZE(modes),
50 .test = verify_getrandom,
51 };
52