[gdb/testsuite] Handle unordered dict in gdb.python/py-mi-cmd.exp
authorTom de Vries <tdevries@suse.de>
Tue, 14 Jun 2022 17:50:44 +0000 (19:50 +0200)
committerTom de Vries <tdevries@suse.de>
Tue, 14 Jun 2022 17:50:44 +0000 (19:50 +0200)
When running test-case gdb.python/py-mi-cmd.exp on openSUSE Leap 42.3 with
python 3.4, I occasionally run into:
...
Expecting: ^(-pycmd dct[^M
]+)?(\^done,result={hello="world",times="42"}[^M
]+[(]gdb[)] ^M
[ ]*)
-pycmd dct^M
^done,result={times="42",hello="world"}^M
(gdb) ^M
FAIL: gdb.python/py-mi-cmd.exp: -pycmd dct (unexpected output)
...

The problem is that the data type used here in py-mi-cmd.py:
...
        elif argv[0] == "dct":
            return {"result": {"hello": "world", "times": 42}}
...
is a dictionary, and only starting version 3.6 are dictionaries insertion
ordered, so using PyDict_Next in serialize_mi_result doesn't guarantee a
fixed order.

Fix this by allowing the alternative order.

Tested on x86_64-linux.

gdb/testsuite/gdb.python/py-mi-cmd.exp

index d372518a03119731b16ec5bf3c9693b396ac3c8a..733686098f8f74428705b74f9ea5d9323814f650 100644 (file)
@@ -54,8 +54,10 @@ mi_gdb_test "-pycmd ary" \
     "\\^done,result=\\\[\"Hello\",\"42\"\\\]" \
     "-pycmd ary"
 
+set re_order1 "\\^done,result={hello=\"world\",times=\"42\"}"
+set re_order2 "\\^done,result={times=\"42\",hello=\"world\"}"
 mi_gdb_test "-pycmd dct" \
-    "\\^done,result={hello=\"world\",times=\"42\"}" \
+    "($re_order1|$re_order2)" \
     "-pycmd dct"
 
 mi_gdb_test "-pycmd bk1" \