This is an archive of the discontinued LLVM Phabricator instance.

[utils] fixing update_mir_test_checks.py's greediness for `registers:` field
AbandonedPublic

Authored by rtereshin on Feb 21 2018, 5:12 PM.

Details

Reviewers
bogner
Summary

utils/update_mir_test_checks.py may cross machine function boundaries while parsing a *.mir test looking for registers: YAML-field a little too greedily than it actually needs. If there is a MF w/o registers: field followed by a MF with one it will parse both of them with the name of the first one, and registers and body of the second one and eventually crash.

This patch also adds a LIT-test for utils/update_mir_test_checks.py itself to ensure we don't regress on this or, frankly, anything else.

Diff Detail

Repository
rL LLVM

Event Timeline

rtereshin created this revision.Feb 21 2018, 5:12 PM

@bogner

I've also double checked that the test actually fails. On the original tool it fails with

-- Testing: 1 tests, 1 threads --
FAIL: LLVM :: CodeGen/AArch64/actual_test.mir (1 of 1)
******************** TEST 'LLVM :: CodeGen/AArch64/actual_test.mir' FAILED ********************
Script:
--
sed -e 's/^# RUN-NESTED:/# RUN:/' /Volumes/Data/llvm/test/CodeGen/AArch64/actual_test.mir | sed -e 's/^# SOURCE.*$//' > /Volumes/Data/llvm/build/obj/test/CodeGen/AArch64/Output/actual_test.mir.tmp    && /Volumes/Data/llvm/test/CodeGen/AArch64/../../../utils/update_mir_test_checks.py --add-vreg-checks      /Volumes/Data/llvm/build/obj/test/CodeGen/AArch64/Output/actual_test.mir.tmp 2>&1 | /Volumes/Data/llvm/build/obj/bin/FileCheck /Volumes/Data/llvm/test/CodeGen/AArch64/actual_test.mir --check-prefix=STDERR    && cat /Volumes/Data/llvm/build/obj/test/CodeGen/AArch64/Output/actual_test.mir.tmp | /Volumes/Data/llvm/build/obj/bin/FileCheck /Volumes/Data/llvm/test/CodeGen/AArch64/actual_test.mir --check-prefix=SOURCE
--
Exit Code: 1

Command Output (stderr):
--
<stdin>:2:1: error: STDERR-NOT: string occurred!
WARNING: /Volumes/Data/llvm/build/obj/test/CodeGen/AArch64/Output/actual_test.mir.tmp: Error processing file
^
/Volumes/Data/llvm/test/CodeGen/AArch64/actual_test.mir:14:15: note: STDERR-NOT: pattern specified here
# STDERR-NOT: WARNING
              ^

--

********************
Testing Time: 0.21s
********************
Failing Tests (1):
    LLVM :: CodeGen/AArch64/actual_test.mir

  Unexpected Failures: 1

If the issue with registers: field "fixed" by making its regexp non just optional, but non-greedy-optional (??) it will still fail:

-- Testing: 1 tests, 1 threads --
FAIL: LLVM :: CodeGen/AArch64/actual_test.mir (1 of 1)
******************** TEST 'LLVM :: CodeGen/AArch64/actual_test.mir' FAILED ********************
Script:
--
sed -e 's/^# RUN-NESTED:/# RUN:/' /Volumes/Data/llvm/test/CodeGen/AArch64/actual_test.mir | sed -e 's/^# SOURCE.*$//' > /Volumes/Data/llvm/build/obj/test/CodeGen/AArch64/Output/actual_test.mir.tmp    && /Volumes/Data/llvm/test/CodeGen/AArch64/../../../utils/update_mir_test_checks.py --add-vreg-checks      /Volumes/Data/llvm/build/obj/test/CodeGen/AArch64/Output/actual_test.mir.tmp 2>&1 | /Volumes/Data/llvm/build/obj/bin/FileCheck /Volumes/Data/llvm/test/CodeGen/AArch64/actual_test.mir --check-prefix=STDERR    && cat /Volumes/Data/llvm/build/obj/test/CodeGen/AArch64/Output/actual_test.mir.tmp | /Volumes/Data/llvm/build/obj/bin/FileCheck /Volumes/Data/llvm/test/CodeGen/AArch64/actual_test.mir --check-prefix=SOURCE
--
Exit Code: 1

Command Output (stderr):
--
/Volumes/Data/llvm/test/CodeGen/AArch64/actual_test.mir:65:16: error: expected string not found in input
# SOURCE-NEXT: ; CHECK: registers:
               ^
<stdin>:126:2: note: scanning from here
 ; CHECK: liveins: $w0, $w1
 ^

--

********************
Testing Time: 0.21s
********************
Failing Tests (1):
    LLVM :: CodeGen/AArch64/actual_test.mir

  Unexpected Failures: 1

I like the idea of adding tests for update_mir_test_checks itself, but I think we should stick to focused tests rather than just adding one that tries to test everything. I also think this isn't a great place for it, maybe we could add a test/tools/update_checks folder for tests for all of the update_*_tests scripts? We might need to fake out llc to get away with something like that though...

test/CodeGen/AArch64/test-update_mir_test_checks.py-itself.mir
11–14

Is it necessary to check the stderr in this test?

rtereshin abandoned this revision.Feb 28 2018, 1:38 PM

As --add-vreg-checks option support was removed by http://llvm.org/viewvc/llvm-project?view=revision&revision=326284 rendering this largely outdated, closing it.

We should probably revisit testing, though, but for that it's probably enough to have https://reviews.llvm.org/D43604 hanging around anyway.