Skip to contentSkip to conversation

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

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

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

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

Missing review: 1 and 3

v2:
- add generic tests/tcg/include/tap.h for reuse (rth)
- cover it in MAINTAINERS

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é (4):
tests/tcg: Add minimal TAP helper header 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

 MAINTAINERS                     |  1 +
 tests/tcg/include/tap.h         | 60 ++++++++++++++++++++++++
 tests/tcg/mips64/octeon-insns.c | 83 ++++++++++++++++++++-------------
 tests/tcg/meson.build           |  9 +++-
 tests/tcg/mips64/meson.build    |  1 +
 5 files changed, 120 insertions(+), 34 deletions(-)
 create mode 100644 tests/tcg/include/tap.h
Signature · 1 line
2.55.0
#1 lore raw

PATCH v2 1/4 tests/tcg: Add minimal TAP helper header

Add a small header to report test results using the Test Anything Protocol, which meson parses when the test declares the 'tap' protocol:

- TAP_START() prints the TAP version line.
- tap_report() prints one numbered "ok" / "not ok" line, with a printf-style description.
- TAP_CHECK() reports a condition, using its text as description.
- tap_assert() is a non-fatal assert: it prints a '# FAIL' TAP diagnostic and counts the failure in tap_assert_failures, for tests grouping several asserts into a single reported result.
- tap_done() prints the plan and returns the exit status for main().

The counters are static, so each test must be a single translation unit.

---
 MAINTAINERS             |  1 +
 tests/tcg/include/tap.h | 60 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 tests/tcg/include/tap.h
MAINTAINERS +1 -0
index 8884e4177e4f..761b2f5d4dc6 100644
@@ -4699,6 +4699,7 @@ Guest Test Compilation Support
 M: Alex Bennée <[email protected]>
 M: Pierrick Bouvier <[email protected]>
 S: Maintained
+F: tests/tcg/include/tap.h
 F: tests/tcg/meson.build
 
 GitLab custom runners (HW sponsored by Linaro, OSUOSL and IBM)
tests/tcg/include/tap.h new file +60 -0

60 lines not on this page · raw message

Signature · 1 line
2.55.0
Reviewed-by on v2 1/4
#2 lore raw

Re: [PATCH v2 1/4] tests/tcg: Add minimal TAP helper header

Quoted 16 lines · Philippe Mathieu-Daudé

Add a small header to report test results using the Test Anything Protocol, which meson parses when the test declares the 'tap' protocol:

- TAP_START() prints the TAP version line.
- tap_report() prints one numbered "ok" / "not ok" line, with a printf-style description.
- TAP_CHECK() reports a condition, using its text as description.
- tap_assert() is a non-fatal assert: it prints a '# FAIL' TAP diagnostic and counts the failure in tap_assert_failures, for tests grouping several asserts into a single reported result.
- tap_done() prints the plan and returns the exit status for main().

The counters are static, so each test must be a single translation unit.

Quoted 6 lines
---
  MAINTAINERS             |  1 +
  tests/tcg/include/tap.h | 60 +++++++++++++++++++++++++++++++++++++++++
  2 files changed, 61 insertions(+)

create mode 100644 tests/tcg/include/tap.h

r~

#3 lore raw

PATCH v2 2/4 tests/tcg: Allow tests to report results with TAP

In reply to 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 | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
tests/tcg/meson.build +7 -2
index 06f013fbe3d8..b61ddf805148 100644
@@ -42,6 +42,7 @@ tcg_tests = {}
 #           'gdb_test': ['gdb test args'],
 #           'gdb_feat': ['feature name, must be present in gdb_feat_version'],
 #           'env_var': ['VAR=value', ...],
+#           'protocol': 'meson test protocol, default is exitcode',
 #           'wrapper': [program_to_launch_test, 'args'...],
 #           'plugin_test': {
 #             'plugin': 'plugin_name',
@@ -323,8 +324,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) + '])')
@@ -520,8 +521,11 @@ foreach target, plan: tcg_tests
       endif
 
       if skip_test != ''
+        test_protocol = 'exitcode'
         # still declare test, but skip it and print reason
         cmd = ['sh', '-c', 'echo "' + skip_test + '" && exit 77']
+      else
+        test_protocol = 'protocol' in setup ? setup['protocol'] : 'exitcode'
       endif
 
       # Do not add a skipped test when compiler is missing,
@@ -530,6 +534,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
#4 lore raw

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

In reply to Philippe Mathieu-Daudé

Replace assert() by a TAP_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 | 65 +++++++++++++++++----------------
 tests/tcg/mips64/meson.build    |  1 +
 2 files changed, 34 insertions(+), 32 deletions(-)
tests/tcg/mips64/octeon-insns.c +33 -32
index 6fffc8201034..208002c711a2 100644
@@ -4,8 +4,8 @@
  * SPDX-License-Identifier: GPL-2.0-or-later
  */
 
-#include <assert.h>
 #include <stdint.h>
+#include "../include/tap.h"
 
 static uint64_t octeon_baddu(uint64_t rs, uint64_t rt)
 {
@@ -385,36 +385,37 @@ 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());
+    TAP_START();
+    TAP_CHECK(octeon_baddu(0x123, 0x0f0) == 0x13);
+    TAP_CHECK(octeon_dmul(0x12345678, 0x10) == 0x123456780);
+    TAP_CHECK(octeon_dpop(0xf0f0f0f0f0f0f0f0ULL) == 32);
+    TAP_CHECK(octeon_seq(0xabc, 0xabc) == 1);
+    TAP_CHECK(octeon_seq(0xabc, 0xdef) == 0);
+    TAP_CHECK(octeon_sne(0xabc, 0xabc) == 0);
+    TAP_CHECK(octeon_sne(0xabc, 0xdef) == 1);
+    TAP_CHECK(octeon_qmac_lo(0x0003000000000000ULL, 2, 1) == 13);
+    TAP_CHECK(octeon_qmacs_state(1, 1, 0x7ffffffe) == 0x17fffffffULL);
+    TAP_CHECK(octeon_qmacs_state(0x8000, 0x8000, 0) == 0x17fffffffULL);
+    TAP_CHECK(octeon_vmulu(5, 7, 11) == 46);
+    TAP_CHECK(octeon_vmm0(5, 13, 7, 11) == 59);
+    TAP_CHECK(octeon_vmm0_zeroes_mpl1() == 0);
+    TAP_CHECK(octeon_mtp0_zeroes_p1() == 0);
+    TAP_CHECK(octeon_cop2_key0_readback(0x1122334455667788ULL) ==
+              0x1122334455667788ULL);
+    TAP_CHECK(octeon_cop2_key2_readback(0x8877665544332211ULL) ==
+              0x8877665544332211ULL);
+    TAP_CHECK(octeon_cop2_key3_readback(0x0102030405060708ULL) ==
+              0x0102030405060708ULL);
+    TAP_CHECK(octeon_cop2_keylength_readback(0xa5) == 1);
+    TAP_CHECK(octeon_cop2_hsh_dat0_readback(0x0102030405060708ULL) ==
+              0x0102030405060708ULL);
+    TAP_CHECK(octeon_cop2_crc_len_readback(0xb5) == 5);
+    TAP_CHECK(octeon_cop2_crc_poly_reflect_readback(0x12345678) == 0x482c6a1e);
+    TAP_CHECK(octeon_cop2_gfm_mul_reflect_write_readback(
+                  0x0123456789abcdefULL) == 0xf7b3d591e6a2c480ULL);
+    TAP_CHECK(octeon_cop2_gfm_mul_reflect_readback(
+                  0xfedcba9876543210ULL) == 0x084c2a6e195d3b7fULL);
+    TAP_CHECK(octeon_rdhwr31_non_decreasing());
 
-    return 0;
+    return tap_done();
 }
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
Reviewed-by on v2 3/4
#5 lore raw

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

Quoted 10 lines · Philippe Mathieu-Daudé

Replace assert() by a TAP_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 | 65 +++++++++++++++++----------------
 tests/tcg/mips64/meson.build    |  1 +
 2 files changed, 34 insertions(+), 32 deletions(-)
#6 lore raw

PATCH v2 4/4 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 208002c711a2..ea8ad4baee4d 100644
@@ -39,6 +39,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;
@@ -388,6 +403,9 @@ int main(void)
     TAP_START();
     TAP_CHECK(octeon_baddu(0x123, 0x0f0) == 0x13);
     TAP_CHECK(octeon_dmul(0x12345678, 0x10) == 0x123456780);
+    TAP_CHECK(octeon_pop(0) == 0);
+    TAP_CHECK(octeon_pop(0xf0f0f0f0) == 16);
+    TAP_CHECK(octeon_pop(0xffffffff00000001ULL) == 1); /* low 32 bits only */
     TAP_CHECK(octeon_dpop(0xf0f0f0f0f0f0f0f0ULL) == 32);
     TAP_CHECK(octeon_seq(0xabc, 0xabc) == 1);
     TAP_CHECK(octeon_seq(0xabc, 0xdef) == 0);
Signature · 1 line
2.55.0