Skip to contentSkip to conversation

tests/tcg/mips64: Test Octeon POP instruction and report with TAP

PATCH Superseded Philippe Mathieu-Daudé 3 participants 9 messages Oct 29 Arm/Amlogic Meson SoC support

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

cover tests/tcg/mips64: Test Octeon POP instruction and report with TAP

Leverage support of TAP protocol by meson in the Octeon tests, simply replacing assert() by a handy CHECK() macro. We were only testing the 64-bit DPOP, add the 32-bit variant.

Based-on: <[email protected]>

Philippe Mathieu-Daudé (3):
tests/tcg: Allow tests to report results with TAP tests/tcg/mips64: Report Octeon test results with TAP tests/tcg/mips64: Test the Octeon POP instruction

 tests/tcg/mips64/octeon-insns.c | 94 ++++++++++++++++++++++-----------
 tests/tcg/meson.build           |  7 ++-
 tests/tcg/mips64/meson.build    |  1 +
 3 files changed, 68 insertions(+), 34 deletions(-)
Signature · 1 line
2.55.0
#1 lore raw

PATCH 1/3 tests/tcg: Allow tests to report results with TAP

Add an optional 'protocol' setup entry, passed to meson's test(). The default stays 'exitcode'; skipped tests (exit 77) are forced back to it.

---
 tests/tcg/meson.build | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tests/tcg/meson.build +5 -2
index 06f013fbe3d8..6666d0dcea2a 100644
@@ -323,8 +323,8 @@ foreach target, plan: tcg_tests
       # return a clear error if user misspell a setup entry
       foreach key, _ : setup
         allowed = ['exe_name', 'env_var', 'expected_output', 'cc_feat', 'cflags',
-                   'depends', 'gdb_feat', 'gdb_test', 'plugin_test', 'qemu_args',
-                   'test_name', 'wrapper']
+                   'depends', 'gdb_feat', 'gdb_test', 'plugin_test', 'protocol',
+                   'qemu_args', 'test_name', 'wrapper']
         if key not in allowed
           error('unknown tcg setup entry \'' + key + '\' for test ' + src +
                 ' (possible: [' + ', '.join(allowed) + '])')
@@ -519,7 +519,9 @@ foreach target, plan: tcg_tests
         skip_test = 'gdb not available for ' + gdb_arch
       endif
 
+      test_protocol = 'protocol' in setup ? setup['protocol'] : 'exitcode'
       if skip_test != ''
+        test_protocol = 'exitcode'
         # still declare test, but skip it and print reason
         cmd = ['sh', '-c', 'echo "' + skip_test + '" && exit 77']
       endif
@@ -530,6 +532,7 @@ foreach target, plan: tcg_tests
         test(test_name, env, args: cmd,
              depends: test_depends,
              timeout: 120,
+             protocol: test_protocol,
              suite: ['tcg', 'tcg-' + target])
       endif
       added_tests += {test_name: true}
Signature · 1 line
2.55.0
Reviewed-by on v1 1/3
#2 lore raw

Re: [PATCH 1/3] tests/tcg: Allow tests to report results with TAP

tests/tcg/meson.build foreach target, plan: tcg_tests · line 527

Quoted 10 lines · Philippe Mathieu-Daudé
tests/tcg/meson.build +2 -0
@@ -519,7 +519,9 @@ foreach target, plan: tcg_tests
          skip_test = 'gdb not available for ' + gdb_arch
        endif
 
+      test_protocol = 'protocol' in setup ? setup['protocol'] : 'exitcode'
        if skip_test != ''
+        test_protocol = 'exitcode'
          # still declare test, but skip it and print reason
          cmd = ['sh', '-c', 'echo "' + skip_test + '" && exit 77']
        endif

While this isn't wrong, is it less confusing to use else/elif than overwrite test_protocol?

Anyway,

r~

Reviewed-by on v1 1/3
#3 lore raw

Re: [PATCH 1/3] tests/tcg: Allow tests to report results with TAP

In reply to Philippe Mathieu-Daudé
Quoted 35 lines · Philippe Mathieu-Daudé

Add an optional 'protocol' setup entry, passed to meson's test(). The default stays 'exitcode'; skipped tests (exit 77) are forced back to it.

---
 tests/tcg/meson.build | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
tests/tcg/meson.build +4 -2
index 06f013fbe3d8..6666d0dcea2a 100644
@@ -323,8 +323,8 @@ foreach target, plan: tcg_tests
       # return a clear error if user misspell a setup entry
       foreach key, _ : setup
         allowed = ['exe_name', 'env_var', 'expected_output', 'cc_feat', 'cflags',
-                   'depends', 'gdb_feat', 'gdb_test', 'plugin_test', 'qemu_args',
-                   'test_name', 'wrapper']
+                   'depends', 'gdb_feat', 'gdb_test', 'plugin_test', 'protocol',
+                   'qemu_args', 'test_name', 'wrapper']
         if key not in allowed
           error('unknown tcg setup entry \'' + key + '\' for test ' + src +
                 ' (possible: [' + ', '.join(allowed) + '])')
@@ -519,7 +519,9 @@ foreach target, plan: tcg_tests
         skip_test = 'gdb not available for ' + gdb_arch
       endif
 
+      test_protocol = 'protocol' in setup ? setup['protocol'] : 'exitcode'
       if skip_test != ''
+        test_protocol = 'exitcode'
         # still declare test, but skip it and print reason
         cmd = ['sh', '-c', 'echo "' + skip_test + '" && exit 77']
       endif

tests/tcg/meson.build foreach target, plan: tcg_tests · line 538

Quoted 7 lines
tests/tcg/meson.build +1 -0
@@ -530,6 +532,7 @@ foreach target, plan: tcg_tests
         test(test_name, env, args: cmd,
              depends: test_depends,
              timeout: 120,
+             protocol: test_protocol,
              suite: ['tcg', 'tcg-' + target])
       endif
       added_tests += {test_name: true}

Please add doc for this new entry here also:
https://gitlab.com/qemu-project/qemu/-/blob/master/tests/tcg/meson.build?ref_type=heads#L35

With doc:

Regards,
Pierrick

#4 lore raw

PATCH 2/3 tests/tcg/mips64: Report Octeon test results with TAP

In reply to Philippe Mathieu-Daudé

Replace assert() by a CHECK() macro printing one TAP line per check, so a failure no longer aborts the remaining ones. Select the TAP protocol in the meson setup.

---
 tests/tcg/mips64/octeon-insns.c | 76 +++++++++++++++++++--------------
 tests/tcg/mips64/meson.build    |  1 +
 2 files changed, 45 insertions(+), 32 deletions(-)
tests/tcg/mips64/octeon-insns.c +44 -32
index 6fffc8201034..2c4fe8f58875 100644
@@ -4,8 +4,17 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-#include <assert.h>
 #include <stdint.h>
+#include <stdio.h>
+
+static int tests, failures;
+
+#define CHECK(cond) \
+    do { \
+        int ok_ = !!(cond); \
+        printf("%s %d - %s\n", ok_ ? "ok" : "not ok", ++tests, #cond); \
+        failures += !ok_; \
+    } while (0)
 
 static uint64_t octeon_baddu(uint64_t rs, uint64_t rt)
 {
@@ -385,36 +394,39 @@ static uint64_t octeon_rdhwr31_non_decreasing(void)
 
 int main(void)
 {
-    assert(octeon_baddu(0x123, 0x0f0) == 0x13);
-    assert(octeon_dmul(0x12345678, 0x10) == 0x123456780);
-    assert(octeon_dpop(0xf0f0f0f0f0f0f0f0ULL) == 32);
-    assert(octeon_seq(0xabc, 0xabc) == 1);
-    assert(octeon_seq(0xabc, 0xdef) == 0);
-    assert(octeon_sne(0xabc, 0xabc) == 0);
-    assert(octeon_sne(0xabc, 0xdef) == 1);
-    assert(octeon_qmac_lo(0x0003000000000000ULL, 2, 1) == 13);
-    assert(octeon_qmacs_state(1, 1, 0x7ffffffe) == 0x17fffffffULL);
-    assert(octeon_qmacs_state(0x8000, 0x8000, 0) == 0x17fffffffULL);
-    assert(octeon_vmulu(5, 7, 11) == 46);
-    assert(octeon_vmm0(5, 13, 7, 11) == 59);
-    assert(octeon_vmm0_zeroes_mpl1() == 0);
-    assert(octeon_mtp0_zeroes_p1() == 0);
-    assert(octeon_cop2_key0_readback(0x1122334455667788ULL) ==
-           0x1122334455667788ULL);
-    assert(octeon_cop2_key2_readback(0x8877665544332211ULL) ==
-           0x8877665544332211ULL);
-    assert(octeon_cop2_key3_readback(0x0102030405060708ULL) ==
-           0x0102030405060708ULL);
-    assert(octeon_cop2_keylength_readback(0xa5) == 1);
-    assert(octeon_cop2_hsh_dat0_readback(0x0102030405060708ULL) ==
-           0x0102030405060708ULL);
-    assert(octeon_cop2_crc_len_readback(0xb5) == 5);
-    assert(octeon_cop2_crc_poly_reflect_readback(0x12345678) == 0x482c6a1e);
-    assert(octeon_cop2_gfm_mul_reflect_write_readback(
-               0x0123456789abcdefULL) == 0xf7b3d591e6a2c480ULL);
-    assert(octeon_cop2_gfm_mul_reflect_readback(
-               0xfedcba9876543210ULL) == 0x084c2a6e195d3b7fULL);
-    assert(octeon_rdhwr31_non_decreasing());
+    printf("TAP version 14\n");
+    CHECK(octeon_baddu(0x123, 0x0f0) == 0x13);
+    CHECK(octeon_dmul(0x12345678, 0x10) == 0x123456780);
+    CHECK(octeon_dpop(0xf0f0f0f0f0f0f0f0ULL) == 32);
+    CHECK(octeon_seq(0xabc, 0xabc) == 1);
+    CHECK(octeon_seq(0xabc, 0xdef) == 0);
+    CHECK(octeon_sne(0xabc, 0xabc) == 0);
+    CHECK(octeon_sne(0xabc, 0xdef) == 1);
+    CHECK(octeon_qmac_lo(0x0003000000000000ULL, 2, 1) == 13);
+    CHECK(octeon_qmacs_state(1, 1, 0x7ffffffe) == 0x17fffffffULL);
+    CHECK(octeon_qmacs_state(0x8000, 0x8000, 0) == 0x17fffffffULL);
+    CHECK(octeon_vmulu(5, 7, 11) == 46);
+    CHECK(octeon_vmm0(5, 13, 7, 11) == 59);
+    CHECK(octeon_vmm0_zeroes_mpl1() == 0);
+    CHECK(octeon_mtp0_zeroes_p1() == 0);
+    CHECK(octeon_cop2_key0_readback(0x1122334455667788ULL) ==
+          0x1122334455667788ULL);
+    CHECK(octeon_cop2_key2_readback(0x8877665544332211ULL) ==
+          0x8877665544332211ULL);
+    CHECK(octeon_cop2_key3_readback(0x0102030405060708ULL) ==
+          0x0102030405060708ULL);
+    CHECK(octeon_cop2_keylength_readback(0xa5) == 1);
+    CHECK(octeon_cop2_hsh_dat0_readback(0x0102030405060708ULL) ==
+          0x0102030405060708ULL);
+    CHECK(octeon_cop2_crc_len_readback(0xb5) == 5);
+    CHECK(octeon_cop2_crc_poly_reflect_readback(0x12345678) == 0x482c6a1e);
+    CHECK(octeon_cop2_gfm_mul_reflect_write_readback(
+              0x0123456789abcdefULL) == 0xf7b3d591e6a2c480ULL);
+    CHECK(octeon_cop2_gfm_mul_reflect_readback(
+              0xfedcba9876543210ULL) == 0x084c2a6e195d3b7fULL);
+    CHECK(octeon_rdhwr31_non_decreasing());
 
-    return 0;
+    printf("1..%d\n", tests);
+
+    return failures ? 1 : 0;
 }
tests/tcg/mips64/meson.build +1 -0
index c80a3716f559..3b895a169758 100644
@@ -5,6 +5,7 @@ tests += tcg_tests['multiarch-linux-user']['tests']
 tests += {
   '../mips64/octeon-insns.c': {
     'qemu_args': ['-cpu', 'Octeon68XX'],
+    'protocol': 'tap',
   },
 }
 
Signature · 1 line
2.55.0
#5 lore raw

Re: [PATCH 2/3] tests/tcg/mips64: Report Octeon test results with TAP

Quoted 30 lines · Philippe Mathieu-Daudé

Replace assert() by a CHECK() macro printing one TAP line per check, so a failure no longer aborts the remaining ones. Select the TAP protocol in the meson setup.

---
  tests/tcg/mips64/octeon-insns.c | 76 +++++++++++++++++++--------------
  tests/tcg/mips64/meson.build    |  1 +
  2 files changed, 45 insertions(+), 32 deletions(-)
tests/tcg/mips64/octeon-insns.c +10 -1
index 6fffc8201034..2c4fe8f58875 100644
@@ -4,8 +4,17 @@
   * SPDX-License-Identifier: GPL-2.0-or-later
   */
 
-#include <assert.h>
  #include <stdint.h>
+#include <stdio.h>
+
+static int tests, failures;
+
+#define CHECK(cond) \
+    do { \
+        int ok_ = !!(cond); \
+        printf("%s %d - %s\n", ok_ ? "ok" : "not ok", ++tests, #cond); \
+        failures += !ok_; \
+    } while (0)

...

tests/tcg/mips64/octeon-insns.c static uint64_t octeon_rdhwr31_non_decreasing(void) · line 432

Quoted 4 lines
tests/tcg/mips64/octeon-insns.c +3 -0
+    printf("1..%d\n", tests);
+
+    return failures ? 1 : 0;
  }

I assume you're going to use this elsewhere. Header? Macro/function for finishing up in main?

r~

#6 lore raw

PATCH 3/3 tests/tcg/mips64: Test the Octeon POP instruction

In reply to Philippe Mathieu-Daudé

Check that POP counts the bits of the low 32 bits only, unlike DPOP.

---
 tests/tcg/mips64/octeon-insns.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
tests/tcg/mips64/octeon-insns.c +18 -0
index 2c4fe8f58875..ff399507f1d4 100644
@@ -48,6 +48,21 @@ static uint64_t octeon_dmul(uint64_t rs, uint64_t rt)
     return rd;
 }
 
+static uint64_t octeon_pop(uint64_t rs)
+{
+    uint64_t rd;
+
+    asm volatile(
+        "move $8, %[rs]\n\t"
+        ".word 0x7100502c\n\t" /* pop $10, $8 */
+        "move %[rd], $10\n\t"
+        : [rd] "=r" (rd)
+        : [rs] "r" (rs)
+        : "$8", "$10");
+
+    return rd;
+}
+
 static uint64_t octeon_dpop(uint64_t rs)
 {
     uint64_t rd;
@@ -397,6 +412,9 @@ int main(void)
     printf("TAP version 14\n");
     CHECK(octeon_baddu(0x123, 0x0f0) == 0x13);
     CHECK(octeon_dmul(0x12345678, 0x10) == 0x123456780);
+    CHECK(octeon_pop(0) == 0);
+    CHECK(octeon_pop(0xf0f0f0f0) == 16);
+    CHECK(octeon_pop(0xffffffff00000001ULL) == 1); /* low 32 bits only */
     CHECK(octeon_dpop(0xf0f0f0f0f0f0f0f0ULL) == 32);
     CHECK(octeon_seq(0xabc, 0xabc) == 1);
     CHECK(octeon_seq(0xabc, 0xdef) == 0);
Signature · 1 line
2.55.0