qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/4] tests/decode: Convert tests to meson
@ 2023-05-26  2:12 Richard Henderson
  2023-05-26  2:12 ` [PATCH v2 1/4] decodetree: Add --test-for-error Richard Henderson
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Richard Henderson @ 2023-05-26  2:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, pbonzini

Add --test-for-error to decodetree.py and convert the tests to meson.
This exposes an exception error that had been hidden by the fact that
the script as a whole did exit with error.  Which proves that this is
a better way to run the tests.


r~


Richard Henderson (4):
  decodetree: Add --test-for-error
  decodetree: Fix recursion in prop_format and build_tree
  decodetree: Diagnose empty pattern group
  tests/decode: Convert tests to meson

 scripts/decodetree.py    | 19 ++++++++++---
 tests/decode/check.sh    | 24 ----------------
 tests/decode/meson.build | 59 ++++++++++++++++++++++++++++++++++++++++
 tests/meson.build        |  5 +---
 4 files changed, 75 insertions(+), 32 deletions(-)
 delete mode 100755 tests/decode/check.sh
 create mode 100644 tests/decode/meson.build

-- 
2.34.1



^ permalink raw reply	[flat|nested] 6+ messages in thread

* [PATCH v2 1/4] decodetree: Add --test-for-error
  2023-05-26  2:12 [PATCH v2 0/4] tests/decode: Convert tests to meson Richard Henderson
@ 2023-05-26  2:12 ` Richard Henderson
  2023-05-26  2:12 ` [PATCH v2 2/4] decodetree: Fix recursion in prop_format and build_tree Richard Henderson
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2023-05-26  2:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, pbonzini

Invert the exit code, for use with the testsuite.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 scripts/decodetree.py | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index a03dc6b5e3..3f9f6876f7 100644
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -35,6 +35,7 @@
 formats = {}
 allpatterns = []
 anyextern = False
+testforerror = False
 
 translate_prefix = 'trans'
 translate_scope = 'static '
@@ -71,7 +72,7 @@ def error_with_file(file, lineno, *args):
     if output_file and output_fd:
         output_fd.close()
         os.remove(output_file)
-    exit(1)
+    exit(0 if testforerror else 1)
 # end error_with_file
 
 
@@ -1286,11 +1287,12 @@ def main():
     global bitop_width
     global variablewidth
     global anyextern
+    global testforerror
 
     decode_scope = 'static '
 
     long_opts = ['decode=', 'translate=', 'output=', 'insnwidth=',
-                 'static-decode=', 'varinsnwidth=']
+                 'static-decode=', 'varinsnwidth=', 'test-for-error']
     try:
         (opts, args) = getopt.gnu_getopt(sys.argv[1:], 'o:vw:', long_opts)
     except getopt.GetoptError as err:
@@ -1319,6 +1321,8 @@ def main():
                 bitop_width = 64
             elif insnwidth != 32:
                 error(0, 'cannot handle insns of width', insnwidth)
+        elif o == '--test-for-error':
+            testforerror = True
         else:
             assert False, 'unhandled option'
 
@@ -1417,6 +1421,7 @@ def main():
 
     if output_file:
         output_fd.close()
+    exit(1 if testforerror else 0)
 # end main
 
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 2/4] decodetree: Fix recursion in prop_format and build_tree
  2023-05-26  2:12 [PATCH v2 0/4] tests/decode: Convert tests to meson Richard Henderson
  2023-05-26  2:12 ` [PATCH v2 1/4] decodetree: Add --test-for-error Richard Henderson
@ 2023-05-26  2:12 ` Richard Henderson
  2023-05-26  2:12 ` [PATCH v2 3/4] decodetree: Diagnose empty pattern group Richard Henderson
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2023-05-26  2:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, pbonzini

Two copy-paste errors walking the parse tree.

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 scripts/decodetree.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index 3f9f6876f7..e2640cc79b 100644
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -474,7 +474,7 @@ def build_tree(self):
 
     def prop_format(self):
         for p in self.pats:
-            p.build_tree()
+            p.prop_format()
 
     def prop_width(self):
         width = None
@@ -624,7 +624,7 @@ def __build_tree(pats, outerbits, outermask):
         return t
 
     def build_tree(self):
-        super().prop_format()
+        super().build_tree()
         self.tree = self.__build_tree(self.pats, self.fixedbits,
                                       self.fixedmask)
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 3/4] decodetree: Diagnose empty pattern group
  2023-05-26  2:12 [PATCH v2 0/4] tests/decode: Convert tests to meson Richard Henderson
  2023-05-26  2:12 ` [PATCH v2 1/4] decodetree: Add --test-for-error Richard Henderson
  2023-05-26  2:12 ` [PATCH v2 2/4] decodetree: Fix recursion in prop_format and build_tree Richard Henderson
@ 2023-05-26  2:12 ` Richard Henderson
  2023-05-26  2:12 ` [PATCH v2 4/4] tests/decode: Convert tests to meson Richard Henderson
  2023-05-26  9:06 ` [PATCH v2 0/4] " Philippe Mathieu-Daudé
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2023-05-26  2:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, pbonzini

Test err_pattern_group_empty.decode failed with exception:

Traceback (most recent call last):
  File "./scripts/decodetree.py", line 1424, in <module> main()
  File "./scripts/decodetree.py", line 1342, in main toppat.build_tree()
  File "./scripts/decodetree.py", line 627, in build_tree
    self.tree = self.__build_tree(self.pats, self.fixedbits,
  File "./scripts/decodetree.py", line 607, in __build_tree
    fb = i.fixedbits & innermask
TypeError: unsupported operand type(s) for &: 'NoneType' and 'int'

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 scripts/decodetree.py | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/scripts/decodetree.py b/scripts/decodetree.py
index e2640cc79b..e4ef0a03cc 100644
--- a/scripts/decodetree.py
+++ b/scripts/decodetree.py
@@ -506,6 +506,12 @@ def output_code(self, i, extracted, outerbits, outermask):
                 output(ind, '}\n')
             else:
                 p.output_code(i, extracted, p.fixedbits, p.fixedmask)
+
+    def build_tree(self):
+        if not self.pats:
+            error_with_file(self.file, self.lineno, 'empty pattern group')
+        super().build_tree()
+
 #end IncMultiPattern
 
 
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v2 4/4] tests/decode: Convert tests to meson
  2023-05-26  2:12 [PATCH v2 0/4] tests/decode: Convert tests to meson Richard Henderson
                   ` (2 preceding siblings ...)
  2023-05-26  2:12 ` [PATCH v2 3/4] decodetree: Diagnose empty pattern group Richard Henderson
@ 2023-05-26  2:12 ` Richard Henderson
  2023-05-26  9:06 ` [PATCH v2 0/4] " Philippe Mathieu-Daudé
  4 siblings, 0 replies; 6+ messages in thread
From: Richard Henderson @ 2023-05-26  2:12 UTC (permalink / raw)
  To: qemu-devel; +Cc: peter.maydell, pbonzini

Signed-off-by: Richard Henderson <richard.henderson@linaro.org>
---
 tests/decode/check.sh    | 24 ----------------
 tests/decode/meson.build | 59 ++++++++++++++++++++++++++++++++++++++++
 tests/meson.build        |  5 +---
 3 files changed, 60 insertions(+), 28 deletions(-)
 delete mode 100755 tests/decode/check.sh
 create mode 100644 tests/decode/meson.build

diff --git a/tests/decode/check.sh b/tests/decode/check.sh
deleted file mode 100755
index 95445a0115..0000000000
--- a/tests/decode/check.sh
+++ /dev/null
@@ -1,24 +0,0 @@
-#!/bin/sh
-# This work is licensed under the terms of the GNU LGPL, version 2 or later.
-# See the COPYING.LIB file in the top-level directory.
-
-PYTHON=$1
-DECODETREE=$2
-E=0
-
-# All of these tests should produce errors
-for i in err_*.decode; do
-    if $PYTHON $DECODETREE $i > /dev/null 2> /dev/null; then
-        # Pass, aka failed to fail.
-        echo FAIL: $i 1>&2
-        E=1
-    fi
-done
-
-for i in succ_*.decode; do
-    if ! $PYTHON $DECODETREE $i > /dev/null 2> /dev/null; then
-        echo FAIL:$i 1>&2
-    fi
-done
-
-exit $E
diff --git a/tests/decode/meson.build b/tests/decode/meson.build
new file mode 100644
index 0000000000..b4850562f9
--- /dev/null
+++ b/tests/decode/meson.build
@@ -0,0 +1,59 @@
+err_tests = [
+    'err_argset1.decode',
+    'err_argset2.decode',
+    'err_field1.decode',
+    'err_field2.decode',
+    'err_field3.decode',
+    'err_field4.decode',
+    'err_field5.decode',
+    'err_field6.decode',
+    'err_init1.decode',
+    'err_init2.decode',
+    'err_init3.decode',
+    'err_init4.decode',
+    'err_overlap1.decode',
+    'err_overlap2.decode',
+    'err_overlap3.decode',
+    'err_overlap4.decode',
+    'err_overlap5.decode',
+    'err_overlap6.decode',
+    'err_overlap7.decode',
+    'err_overlap8.decode',
+    'err_overlap9.decode',
+    'err_pattern_group_empty.decode',
+    'err_pattern_group_ident1.decode',
+    'err_pattern_group_ident2.decode',
+    'err_pattern_group_nest1.decode',
+    'err_pattern_group_nest2.decode',
+    'err_pattern_group_nest3.decode',
+    'err_pattern_group_overlap1.decode',
+    'err_width1.decode',
+    'err_width2.decode',
+    'err_width3.decode',
+    'err_width4.decode',
+]
+
+succ_tests = [
+    'succ_argset_type1.decode',
+    'succ_function.decode',
+    'succ_ident1.decode',
+    'succ_pattern_group_nest1.decode',
+    'succ_pattern_group_nest2.decode',
+    'succ_pattern_group_nest3.decode',
+    'succ_pattern_group_nest4.decode',
+]
+
+suite = 'decodetree'
+decodetree = find_program(meson.project_source_root() / 'scripts/decodetree.py')
+
+foreach t: err_tests
+    test(fs.replace_suffix(t, ''),
+         decodetree, args: ['-o', '/dev/null', '--test-for-error', files(t)],
+         suite: suite)
+endforeach
+
+foreach t: succ_tests
+    test(fs.replace_suffix(t, ''),
+         decodetree, args: ['-o', '/dev/null', files(t)],
+         suite: suite)
+endforeach
diff --git a/tests/meson.build b/tests/meson.build
index 8e318ec513..083f2990bd 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -74,10 +74,7 @@ if have_tools and have_vhost_user and 'CONFIG_LINUX' in config_host
              dependencies: [qemuutil, vhost_user])
 endif
 
-test('decodetree', sh,
-     args: [ files('decode/check.sh'), config_host['PYTHON'], files('../scripts/decodetree.py') ],
-     workdir: meson.current_source_dir() / 'decode',
-     suite: 'decodetree')
+subdir('decode')
 
 if 'CONFIG_TCG' in config_all
   subdir('fp')
-- 
2.34.1



^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v2 0/4] tests/decode: Convert tests to meson
  2023-05-26  2:12 [PATCH v2 0/4] tests/decode: Convert tests to meson Richard Henderson
                   ` (3 preceding siblings ...)
  2023-05-26  2:12 ` [PATCH v2 4/4] tests/decode: Convert tests to meson Richard Henderson
@ 2023-05-26  9:06 ` Philippe Mathieu-Daudé
  4 siblings, 0 replies; 6+ messages in thread
From: Philippe Mathieu-Daudé @ 2023-05-26  9:06 UTC (permalink / raw)
  To: Richard Henderson, qemu-devel; +Cc: peter.maydell, pbonzini

On 26/5/23 04:12, Richard Henderson wrote:

> Richard Henderson (4):
>    decodetree: Add --test-for-error
>    decodetree: Fix recursion in prop_format and build_tree
>    decodetree: Diagnose empty pattern group
>    tests/decode: Convert tests to meson

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>




^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-05-26  9:06 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-26  2:12 [PATCH v2 0/4] tests/decode: Convert tests to meson Richard Henderson
2023-05-26  2:12 ` [PATCH v2 1/4] decodetree: Add --test-for-error Richard Henderson
2023-05-26  2:12 ` [PATCH v2 2/4] decodetree: Fix recursion in prop_format and build_tree Richard Henderson
2023-05-26  2:12 ` [PATCH v2 3/4] decodetree: Diagnose empty pattern group Richard Henderson
2023-05-26  2:12 ` [PATCH v2 4/4] tests/decode: Convert tests to meson Richard Henderson
2023-05-26  9:06 ` [PATCH v2 0/4] " Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).