[gdb/testsuite] Check avx support in gdb.arch/amd64-disp-step-avx.exp
authorTom de Vries <tdevries@suse.de>
Sat, 4 Sep 2021 10:11:35 +0000 (12:11 +0200)
committerTom de Vries <tdevries@suse.de>
Sat, 4 Sep 2021 10:11:35 +0000 (12:11 +0200)
On a machine on Open Build Service I'm running into a SIGILL for test-case
gdb.arch/amd64-disp-step-avx.exp:
...
Program received signal SIGILL, Illegal instruction.^M
test_rip_vex2 () at gdb.arch/amd64-disp-step-avx.S:40^M
40              vmovsd ro_var(%rip),%xmm0^M
(gdb) FAIL: gdb.arch/amd64-disp-step-avx.exp: vex2: \
  continue to test_rip_vex2_end
...
The SIGILL happens when trying to execute the first avx instruction in the
executable.

I can't directly access the machine, but looking at the log for test-case
gdb.arch/i386-avx.exp, it seems that there's no avx support:
...
Breakpoint 1, main (argc=1, argv=0x7fffffffd6b8) at gdb.arch/i386-avx.c:68^M
68        if (have_avx ())^M
(gdb) print have_avx ()^M
$1 = 0^M
...

Fix this by:
- adding a gdb_caching_proc have_avx, similar to have_mpx, using the have_avx
  function from gdb.arch/i386-avx.c
- using proc have_avx in both gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp
  and gdb/testsuite/gdb.arch/i386-avx.exp.

Tested on my x86_64-linux laptop with avx support, where both test-cases pass.

gdb/testsuite/ChangeLog:

2021-09-04  Tom de Vries  <tdevries@suse.de>

PR testsuite/26950
* gdb/testsuite/gdb.arch/i386-avx.c (main): Remove call to have_avx.
(have_avx): Move ...
* gdb/testsuite/lib/gdb.exp (have_avx): ... here.  New proc.
* gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp: Use have_avx.
* gdb/testsuite/gdb.arch/i386-avx.exp: Same.

gdb/testsuite/ChangeLog
gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp
gdb/testsuite/gdb.arch/i386-avx.c
gdb/testsuite/gdb.arch/i386-avx.exp
gdb/testsuite/lib/gdb.exp

index ba3eb59f773bea10f852a8a806a1bd3964200009..0552574883b9e269a5c9755f33858ef9ec2bc212 100644 (file)
@@ -1,3 +1,12 @@
+2021-09-04  Tom de Vries  <tdevries@suse.de>
+
+       PR testsuite/26950
+       * gdb/testsuite/gdb.arch/i386-avx.c (main): Remove call to have_avx.
+       (have_avx): Move ...
+       * gdb/testsuite/lib/gdb.exp (have_avx): ... here.  New proc.
+       * gdb/testsuite/gdb.arch/amd64-disp-step-avx.exp: Use have_avx.
+       * gdb/testsuite/gdb.arch/i386-avx.exp: Same.
+
 2021-09-03  Tom de Vries  <tdevries@suse.de>
 
        * gdb.gdb/complaints.exp: Use untested if clear_complaints cannot
index a729bb053c967ec3aeed8e306c8e1f29d594611e..469c6f4cd70dec84e5411bc307c9c8c6379cccce 100644 (file)
@@ -23,6 +23,11 @@ if { ![istarget x86_64-*-* ] || ![is_lp64_target] } {
     return
 }
 
+if { ![have_avx] } {
+    verbose "Skipping x86_64 displaced stepping tests."
+    return
+}
+
 standard_testfile .S
 
 set options [list debug \
index eca89b6031c54d9bc4cb9c5ee26a4f42c9c0a3e6..4e938399a24bcadd67fe7f147e678d8f1e0938fa 100644 (file)
@@ -48,81 +48,64 @@ v8sf_t data[] =
   };
 
 
-int
-have_avx (void)
-{
-  unsigned int eax, ebx, ecx, edx;
-
-  if (!x86_cpuid (1, &eax, &ebx, &ecx, &edx))
-    return 0;
-
-  if ((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
-    return 1;
-  else
-    return 0;
-}
-
 int
 main (int argc, char **argv)
 {
-  if (have_avx ())
-    {
-      asm ("vmovaps 0(%0), %%ymm0\n\t"
-           "vmovaps 32(%0), %%ymm1\n\t"
-           "vmovaps 64(%0), %%ymm2\n\t"
-           "vmovaps 96(%0), %%ymm3\n\t"
-           "vmovaps 128(%0), %%ymm4\n\t"
-           "vmovaps 160(%0), %%ymm5\n\t"
-           "vmovaps 192(%0), %%ymm6\n\t"
-           "vmovaps 224(%0), %%ymm7\n\t"
-           : /* no output operands */
-           : "r" (data) 
-           : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7");
+  asm ("vmovaps 0(%0), %%ymm0\n\t"
+       "vmovaps 32(%0), %%ymm1\n\t"
+       "vmovaps 64(%0), %%ymm2\n\t"
+       "vmovaps 96(%0), %%ymm3\n\t"
+       "vmovaps 128(%0), %%ymm4\n\t"
+       "vmovaps 160(%0), %%ymm5\n\t"
+       "vmovaps 192(%0), %%ymm6\n\t"
+       "vmovaps 224(%0), %%ymm7\n\t"
+       : /* no output operands */
+       : "r" (data)
+       : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7");
 #ifdef __x86_64__
-      asm ("vmovaps 256(%0), %%ymm8\n\t"
-           "vmovaps 288(%0), %%ymm9\n\t"
-           "vmovaps 320(%0), %%ymm10\n\t"
-           "vmovaps 352(%0), %%ymm11\n\t"
-           "vmovaps 384(%0), %%ymm12\n\t"
-           "vmovaps 416(%0), %%ymm13\n\t"
-           "vmovaps 448(%0), %%ymm14\n\t"
-           "vmovaps 480(%0), %%ymm15\n\t"
-           : /* no output operands */
-           : "r" (data) 
-           : "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15");
+  asm ("vmovaps 256(%0), %%ymm8\n\t"
+       "vmovaps 288(%0), %%ymm9\n\t"
+       "vmovaps 320(%0), %%ymm10\n\t"
+       "vmovaps 352(%0), %%ymm11\n\t"
+       "vmovaps 384(%0), %%ymm12\n\t"
+       "vmovaps 416(%0), %%ymm13\n\t"
+       "vmovaps 448(%0), %%ymm14\n\t"
+       "vmovaps 480(%0), %%ymm15\n\t"
+       : /* no output operands */
+       : "r" (data)
+       : "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15");
 #endif
 
-      asm ("nop"); /* first breakpoint here */
-
-      asm (
-           "vmovaps %%ymm0, 0(%0)\n\t"
-           "vmovaps %%ymm1, 32(%0)\n\t"
-           "vmovaps %%ymm2, 64(%0)\n\t"
-           "vmovaps %%ymm3, 96(%0)\n\t"
-           "vmovaps %%ymm4, 128(%0)\n\t"
-           "vmovaps %%ymm5, 160(%0)\n\t"
-           "vmovaps %%ymm6, 192(%0)\n\t"
-           "vmovaps %%ymm7, 224(%0)\n\t"
-           : /* no output operands */
-           : "r" (data) 
-           : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7");
+  asm ("nop"); /* first breakpoint here */
+
+  asm (
+       "vmovaps %%ymm0, 0(%0)\n\t"
+       "vmovaps %%ymm1, 32(%0)\n\t"
+       "vmovaps %%ymm2, 64(%0)\n\t"
+       "vmovaps %%ymm3, 96(%0)\n\t"
+       "vmovaps %%ymm4, 128(%0)\n\t"
+       "vmovaps %%ymm5, 160(%0)\n\t"
+       "vmovaps %%ymm6, 192(%0)\n\t"
+       "vmovaps %%ymm7, 224(%0)\n\t"
+       : /* no output operands */
+       : "r" (data)
+       : "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", "xmm7");
 #ifdef __x86_64__
-      asm (
-           "vmovaps %%ymm8, 256(%0)\n\t"
-           "vmovaps %%ymm9, 288(%0)\n\t"
-           "vmovaps %%ymm10, 320(%0)\n\t"
-           "vmovaps %%ymm11, 352(%0)\n\t"
-           "vmovaps %%ymm12, 384(%0)\n\t"
-           "vmovaps %%ymm13, 416(%0)\n\t"
-           "vmovaps %%ymm14, 448(%0)\n\t"
-           "vmovaps %%ymm15, 480(%0)\n\t"
-           : /* no output operands */
-           : "r" (data) 
-           : "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15");
+  asm (
+       "vmovaps %%ymm8, 256(%0)\n\t"
+       "vmovaps %%ymm9, 288(%0)\n\t"
+       "vmovaps %%ymm10, 320(%0)\n\t"
+       "vmovaps %%ymm11, 352(%0)\n\t"
+       "vmovaps %%ymm12, 384(%0)\n\t"
+       "vmovaps %%ymm13, 416(%0)\n\t"
+       "vmovaps %%ymm14, 448(%0)\n\t"
+       "vmovaps %%ymm15, 480(%0)\n\t"
+       : /* no output operands */
+       : "r" (data)
+       : "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15");
 #endif
 
-      puts ("Bye!"); /* second breakpoint here */
-    }
+  puts ("Bye!"); /* second breakpoint here */
 
   return 0;
 }
index 06a5ef0118aa12f40b2ed0e2add966c407d7a7ef..93e86eeb23ebb721a4b665650501bbe924f3a666 100644 (file)
@@ -24,6 +24,11 @@ if { ![istarget i?86-*-*] && ![istarget x86_64-*-* ] } {
     return
 }
 
+if { ![have_avx] } {
+    verbose "Skipping x86 AVX tests."
+    return
+}
+
 standard_testfile .c
 
 if [get_compiler_info] {
@@ -47,23 +52,6 @@ if ![runto_main] then {
     return 0
 }
 
-send_gdb "print have_avx ()\r"
-gdb_expect {
-    -re ".. = 1\r\n$gdb_prompt " {
-        pass "check whether processor supports AVX"
-    }
-    -re ".. = 0\r\n$gdb_prompt " {
-        verbose "processor does not support AVX; skipping AVX tests"
-        return
-    }
-    -re ".*$gdb_prompt $" {
-        fail "check whether processor supports AVX"
-    }
-    timeout {
-        fail "check whether processor supports AVX (timeout)"
-    }
-}
-
 gdb_test "break [gdb_get_line_number "first breakpoint here"]" \
          "Breakpoint .* at .*i386-avx.c.*" \
          "set first breakpoint in main"
index c8be0a373a1de383538980b2d6c4312e2a25a4b9..ec54b94df38a1ed6a8fba7111e22e976879ce3c3 100644 (file)
@@ -7995,5 +7995,49 @@ gdb_caching_proc have_mpx {
     return $status
 }
 
+# Return 1 if target supports avx, otherwise return 0.
+gdb_caching_proc have_avx {
+    global srcdir
+
+    set me "have_avx"
+    if { ![istarget "i?86-*-*"] && ![istarget "x86_64-*-*"] } {
+        verbose "$me: target does not support avx, returning 0" 2
+        return 0
+    }
+
+    # Compile a test program.
+    set src {
+       #include "nat/x86-cpuid.h"
+
+       int main() {
+         unsigned int eax, ebx, ecx, edx;
+
+       if (!x86_cpuid (1, &eax, &ebx, &ecx, &edx))
+         return 0;
+
+       if ((ecx & (bit_AVX | bit_OSXSAVE)) == (bit_AVX | bit_OSXSAVE))
+         return 1;
+       else
+         return 0;
+       }
+    }
+    set compile_flags "incdir=${srcdir}/.."
+    if {![gdb_simple_compile $me $src executable $compile_flags]} {
+        return 0
+    }
+
+    set result [remote_exec target $obj]
+    set status [lindex $result 0]
+    set output [lindex $result 1]
+    if { $output != "" } {
+       set status 0
+    }
+
+    remote_file build delete $obj
+
+    verbose "$me: returning $status" 2
+    return $status
+}
+
 # Always load compatibility stuff.
 load_lib future.exp
This page took 0.035506 seconds and 4 git commands to generate.