1 /* This testcase is part of GDB, the GNU debugger. 2 3 Copyright 2022-2023 Free Software Foundation, Inc. 4 5 This program is free software; you can redistribute it and/or modify 6 it under the terms of the GNU General Public License as published by 7 the Free Software Foundation; either version 3 of the License, or 8 (at your option) any later version. 9 10 This program is distributed in the hope that it will be useful, 11 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 GNU General Public License for more details. 14 15 You should have received a copy of the GNU General Public License 16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ 17 18 /* Exercise AArch64's Scalable Vector Extension. 19 20 This test was based on QEMU's sve-ioctls.c test file. */ 21 22 #include <stdio.h> 23 #include <sys/auxv.h> 24 #include <sys/prctl.h> 25 26 static int 27 do_sve_ioctl_test (void) 28 { 29 int i, res, init_vl; 30 31 res = prctl (PR_SVE_GET_VL, 0, 0, 0, 0); 32 if (res < 0) 33 { 34 printf ("FAILED to PR_SVE_GET_VL (%d)", res); 35 return -1; 36 } 37 init_vl = res & PR_SVE_VL_LEN_MASK; 38 39 for (i = init_vl; i > 15; i /= 2) 40 { 41 printf ("Checking PR_SVE_SET_VL=%d\n", i); 42 res = prctl (PR_SVE_SET_VL, i, 0, 0, 0, 0); /* break here */ 43 if (res < 0) 44 { 45 printf ("FAILED to PR_SVE_SET_VL (%d)", res); 46 return -1; 47 } 48 } 49 return 0; 50 } 51 52 int 53 main (int argc, char **argv) 54 { 55 if (getauxval (AT_HWCAP) & HWCAP_SVE) 56 { 57 return do_sve_ioctl_test (); 58 } 59 else 60 { 61 printf ("SKIP: no HWCAP_SVE on this system\n"); 62 return 1; 63 } 64 } 65