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) with a NULL buffer and expects failure. 6f08c3bdfSopenharmony_ci */ 7f08c3bdfSopenharmony_ci 8f08c3bdfSopenharmony_ci#include "tst_test.h" 9f08c3bdfSopenharmony_ci#include "lapi/getrandom.h" 10f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 11f08c3bdfSopenharmony_ci 12f08c3bdfSopenharmony_cistatic int modes[] = {0, GRND_RANDOM, GRND_NONBLOCK, 13f08c3bdfSopenharmony_ci GRND_RANDOM | GRND_NONBLOCK}; 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_cistatic void verify_getrandom(unsigned int n) 16f08c3bdfSopenharmony_ci{ 17f08c3bdfSopenharmony_ci TEST(tst_syscall(__NR_getrandom, NULL, 100, modes[n])); 18f08c3bdfSopenharmony_ci 19f08c3bdfSopenharmony_ci if (TST_RET == -1) { 20f08c3bdfSopenharmony_ci tst_res(TPASS | TTERRNO, "getrandom returned %ld", 21f08c3bdfSopenharmony_ci TST_RET); 22f08c3bdfSopenharmony_ci } else { 23f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "getrandom failed"); 24f08c3bdfSopenharmony_ci } 25f08c3bdfSopenharmony_ci} 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_cistatic struct tst_test test = { 28f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(modes), 29f08c3bdfSopenharmony_ci .test = verify_getrandom, 30f08c3bdfSopenharmony_ci}; 31