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