1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2015 Cedric Hnyda <ced.hnyda@gmail.com>
4 *
5 * Calls getrandom(2) after having limited the number of available file
6 * descriptors to 3 and expects success.
7 */
8
9 #include <sys/resource.h>
10 #include "lapi/getrandom.h"
11 #include "lapi/syscalls.h"
12 #include "tst_test.h"
13
verify_getrandom(void)14 static void verify_getrandom(void)
15 {
16 char buf[128];
17 struct rlimit lold, lnew;
18
19 SAFE_GETRLIMIT(RLIMIT_NOFILE, &lold);
20 lnew.rlim_max = lold.rlim_max;
21 lnew.rlim_cur = 3;
22 SAFE_SETRLIMIT(RLIMIT_NOFILE, &lnew);
23
24 TEST(tst_syscall(__NR_getrandom, buf, 100, 0));
25 if (TST_RET == -1)
26 tst_res(TFAIL | TTERRNO, "getrandom failed");
27 else
28 tst_res(TPASS, "getrandom returned %ld", TST_RET);
29
30 SAFE_SETRLIMIT(RLIMIT_NOFILE, &lold);
31 }
32
33 static struct tst_test test = {
34 .test_all = verify_getrandom,
35 };
36