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 "linux_syscall_numbers.h"
31 #include "test.h"
32 
33 char *TCID = "getrandom01";
34 static int modes[] = { 0, GRND_RANDOM, GRND_NONBLOCK,
35 		       GRND_RANDOM | GRND_NONBLOCK };
36 
37 int TST_TOTAL = ARRAY_SIZE(modes);
38 
main(int ac,char ** av)39 int main(int ac, char **av)
40 {
41 	int lc, i;
42 
43 	tst_parse_opts(ac, av, NULL, NULL);
44 
45 	for (lc = 0; TEST_LOOPING(lc); lc++) {
46 
47 		tst_count = 0;
48 
49 		for (i = 0; i < TST_TOTAL; i++) {
50 			TEST(ltp_syscall(__NR_getrandom, NULL, 100, modes[i]));
51 			if (TEST_RETURN == -1) {
52 				tst_resm(TPASS, "getrandom returned %ld",
53 						TEST_RETURN);
54 			} else {
55 				tst_resm(TFAIL | TTERRNO, "getrandom failed");
56 			}
57 		}
58 	}
59 	tst_exit();
60 }
61