This is an archive of the discontinued LLVM Phabricator instance.

[TOOL][TEST] A simple string replacing tool for testing purposes
AbandonedPublic

Authored by zinovy.nis on Sep 12 2014, 8:59 AM.

Details

Summary

The strreplace tool helps to eliminate test code duplication. For example the sample below checks 2 operations - add & sub - in the same test code, so you don't need to create 2 separate test files:

; RUN: strreplace '<OPER>' "add" < %s | strreplace "<OPER_ASM>" "addl" > %t.1
; RUN: llc -O0 < %t.1 -mtriple=i686-apple-darwin | FileCheck %t.1

; RUN: strreplace '<OPER>'  "sub" < %s | strreplace "<OPER_ASM>" "subl" > %t.2
; RUN: llc < %t.2 -mtriple=i686-apple-darwin | FileCheck %t.2

; CHECK-LABEL: @foo_<OPER>
; CHECK: <OPER_ASM>

define i32 @foo_<OPER>(i32 %v).
{
  %res = <OPER> i32 1234, %v
  ret i32 %res
}

Diff Detail

Event Timeline

zinovy.nis updated this revision to Diff 13636.Sep 12 2014, 8:59 AM
zinovy.nis retitled this revision from to [TOOL][TEST] A simple string replacing tool for testing purposes.
zinovy.nis updated this object.
zinovy.nis edited the test plan for this revision. (Show Details)
zinovy.nis set the repository for this revision to rL LLVM.
zinovy.nis added a subscriber: Unknown Object (MLST).
zinovy.nis updated this object.Sep 14 2014, 11:53 PM

Please keep the developer policy in mind when you ping a patch.

hfinkel edited edge metadata.Sep 19 2014, 3:34 PM

I don't think this is the right approach because it encourages multiple invocations of the executables, but this adds a lot of overhead to the test-suite run time. We generally encourage placing as many related tests together in the same file as possible to reduce this overhead. Also, it moves logic (like ADD -> some_add_instruction) into the command line and away from the relevant part of the test.

If you're looking for a simple way to capture this, I recommend that we provide a way to repeat a part of the file multiple times, and each time, have the ability to provide alternates. I'm thinking of something like this (obviously the syntax could use some improvement, but I think you'll get the idea):

RUN: repeater %s > %t.all
RUN: llc < %t.all | FileCheck %t.all

; FOREACH ADD SUB
; DEFINE OPER <ADD: add, SUB: sub>
; CHECK-LABEL: @foo_<OPER>
; CHECK: <ADD: addl, SUB: subl>

define i32 @foo_<OPER>(i32 %v).
{
  %res = <OPER> i32 1234, %v
  ret i32 %res
}
; ENDFOREACH

OK, thanks for the review.

zinovy.nis abandoned this revision.Apr 1 2015, 7:42 AM