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 "lapi/syscalls.h"
36 #include "tst_test.h"
37 
38 static void verify_getrandom(void)
39 {
40 	char buf[128];
41 	struct rlimit lold, lnew;
42 
43 	SAFE_GETRLIMIT(RLIMIT_NOFILE, &lold);
44 	lnew.rlim_max = lold.rlim_max;
45 	lnew.rlim_cur = 3;
46 	SAFE_SETRLIMIT(RLIMIT_NOFILE, &lnew);
47 
48 	TEST(tst_syscall(__NR_getrandom, buf, 100, 0));
49 	if (TEST_RETURN == -1)
50 		tst_res(TFAIL | TTERRNO, "getrandom failed");
51 	else
52 		tst_res(TPASS, "getrandom returned %ld", TEST_RETURN);
53 
54 	SAFE_SETRLIMIT(RLIMIT_NOFILE, &lold);
55 }
56 
57 static struct tst_test test = {
58 	.test_all = verify_getrandom,
59 };
60