1 /* 2 * Copyright (C) 2015 Cedric Hnyda ced.hnyda (at) 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 : Cdric Hnyda 27 * DATE STARTED : 06/13/2015 28 * 29 * Calls getrandom(2), check that the return value is equal to the 30 * number of bytes required and expects success. 31 */ 32 33 #include "lapi/getrandom.h" 34 #include "linux_syscall_numbers.h" 35 #include "tst_test.h" 36 37 #define MAX_SIZE 256 38 39 static unsigned int sizes[] = { 40 1, 41 2, 42 3, 43 7, 44 8, 45 15, 46 22, 47 64, 48 127, 49 }; 50 51 static void verify_getrandom(unsigned int n) 52 { 53 char buf[MAX_SIZE]; 54 55 TEST(tst_syscall(__NR_getrandom, buf, sizes[n], 0)); 56 57 if (TEST_RETURN != sizes[n]) { 58 tst_res(TFAIL | TTERRNO, "getrandom returned %li, expected %u", 59 TEST_RETURN, sizes[n]); 60 } else { 61 tst_res(TPASS, "getrandom returned %ld", TEST_RETURN); 62 } 63 } 64 65 static struct tst_test test = { 66 .tid = "getrandom03", 67 .tcnt = ARRAY_SIZE(sizes), 68 .test = verify_getrandom, 69 }; 70