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 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25 /*
26 * AUTHOR : Cédric Hnyda
27 * DATE STARTED : 06/13/2015
28 *
29 * Calls getrandom(2), check that the return value is equal to the
30 * number of bytes required and expects success.
31 */
32
33 #include "lapi/getrandom.h"
34 #include "linux_syscall_numbers.h"
35 #include "test.h"
36
37 #define MAX_SIZE 256
38
39 char *TCID = "getrandom03";
40 int TST_TOTAL = 5;
41
42 static char buf[256];
43
main(int ac,char ** av)44 int main(int ac, char **av)
45 {
46 int lc, i;
47 long size;
48
49 tst_parse_opts(ac, av, NULL, NULL);
50
51 for (lc = 0; TEST_LOOPING(lc); lc++) {
52 tst_count = 0;
53 for (i = 0; i < TST_TOTAL; i++) {
54 size = random() % MAX_SIZE;
55 TEST(ltp_syscall(__NR_getrandom, buf, size, 0));
56 if (TEST_RETURN != size)
57 tst_resm(TFAIL | TTERRNO, "getrandom failed");
58 else
59 tst_resm(TPASS, "getrandom returned %ld",
60 TEST_RETURN);
61 }
62 }
63 tst_exit();
64 }
65