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) after having limited the number of available file
30 * descriptors to 3 and expects success.
31 */
32
33 #include <sys/resource.h>
34 #include "lapi/getrandom.h"
35 #include "linux_syscall_numbers.h"
36 #include "test.h"
37
38 char *TCID = "getrandom04";
39 int TST_TOTAL = 1;
40 static char buf[128];
41
main(int ac,char ** av)42 int main(int ac, char **av)
43 {
44 tst_parse_opts(ac, av, NULL, NULL);
45
46 int r;
47
48 struct rlimit lim = {3, 3};
49
50 r = setrlimit(RLIMIT_NOFILE, &lim);
51
52 if (r == -1)
53 tst_brkm(TBROK | TTERRNO, NULL, "setrlimit failed");
54
55 TEST(ltp_syscall(__NR_getrandom, buf, 100, 0));
56 if (TEST_RETURN == -1)
57 tst_resm(TFAIL | TTERRNO, "getrandom failed");
58 else
59 tst_resm(TPASS, "getrandom returned %ld", TEST_RETURN);
60
61 tst_exit();
62 }
63