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), check that the return value is equal to the 6f08c3bdfSopenharmony_ci * number of bytes required and expects success. 7f08c3bdfSopenharmony_ci */ 8f08c3bdfSopenharmony_ci 9f08c3bdfSopenharmony_ci#include "tst_test.h" 10f08c3bdfSopenharmony_ci#include "lapi/getrandom.h" 11f08c3bdfSopenharmony_ci#include "lapi/syscalls.h" 12f08c3bdfSopenharmony_ci 13f08c3bdfSopenharmony_ci#define MAX_SIZE 256 14f08c3bdfSopenharmony_ci 15f08c3bdfSopenharmony_cistatic unsigned int sizes[] = { 16f08c3bdfSopenharmony_ci 1, 17f08c3bdfSopenharmony_ci 2, 18f08c3bdfSopenharmony_ci 3, 19f08c3bdfSopenharmony_ci 7, 20f08c3bdfSopenharmony_ci 8, 21f08c3bdfSopenharmony_ci 15, 22f08c3bdfSopenharmony_ci 22, 23f08c3bdfSopenharmony_ci 64, 24f08c3bdfSopenharmony_ci 127, 25f08c3bdfSopenharmony_ci}; 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_cistatic void verify_getrandom(unsigned int n) 28f08c3bdfSopenharmony_ci{ 29f08c3bdfSopenharmony_ci char buf[MAX_SIZE]; 30f08c3bdfSopenharmony_ci 31f08c3bdfSopenharmony_ci TEST(tst_syscall(__NR_getrandom, buf, sizes[n], 0)); 32f08c3bdfSopenharmony_ci 33f08c3bdfSopenharmony_ci if (TST_RET != sizes[n]) { 34f08c3bdfSopenharmony_ci tst_res(TFAIL | TTERRNO, "getrandom returned %li, expected %u", 35f08c3bdfSopenharmony_ci TST_RET, sizes[n]); 36f08c3bdfSopenharmony_ci } else { 37f08c3bdfSopenharmony_ci tst_res(TPASS, "getrandom returned %ld", TST_RET); 38f08c3bdfSopenharmony_ci } 39f08c3bdfSopenharmony_ci} 40f08c3bdfSopenharmony_ci 41f08c3bdfSopenharmony_cistatic struct tst_test test = { 42f08c3bdfSopenharmony_ci .tcnt = ARRAY_SIZE(sizes), 43f08c3bdfSopenharmony_ci .test = verify_getrandom, 44f08c3bdfSopenharmony_ci}; 45