unit tests: do identity checks for .srctgt.ll tests
MODIFY
tests/alive-tv/easy-1.srctgt.ll
tests/alive-tv/easy-1.srctgt.ll
-define i32 @src(i32, i32) {
- %x = add nsw i32 %0, %1
- ret i32 %x
+define i8 @src(i8, i8) {
+ %x = add nsw i8 %0, %1
+ ret i8 %x
}
-define i32 @tgt(i32, i32) {
- %x = add i32 %0, %1
- ret i32 %x
+define i8 @tgt(i8, i8) {
+ %x = add i8 %0, %1
+ ret i8 %x
}

MODIFY
tests/alive-tv/easy-3.srctgt.ll
tests/alive-tv/easy-3.srctgt.ll
; ERROR: Target is more poisonous than source
-define i32 @src(i32, i32) {
- %x = add nsw i32 %0, %1
- ret i32 %x
+define i8 @src(i8, i8) {
+ %x = add nsw i8 %0, %1
+ ret i8 %x
}
-define i32 @tgt(i32, i32) {
- %x = add nuw i32 %0, %1
- ret i32 %x
+define i8 @tgt(i8, i8) {
+ %x = add nuw i8 %0, %1
+ ret i8 %x
}

DELETE
tests/alive-tv/inttoptr.src.ll
-define i64* @f(i64 %x, i64 %y) {
- %p = inttoptr i64 %x to i64*
- ret i64* %p
-}
-
-; XFAIL: Invalid expr

DELETE
tests/alive-tv/inttoptr.tgt.ll
-define i64* @f(i64 %x, i64 %y) {
- ret i64* null
-}

DELETE
tests/alive-tv/memory/intptrload.src.ll
-define i64 @f(i64 %x) {
- %p = inttoptr i64 %x to i64*
- %a = load i64, i64* %p
- ret i64 %a
-}
-
-; XFAIL: Invalid expr

DELETE
tests/alive-tv/memory/intptrload.tgt.ll
-define i64 @f(i64 %x) {
- unreachable
-}

MODIFY
tests/lit/lit/formats/alive2test.py
tests/lit/lit/formats/alive2test.py
@@ -6,6 +6,7 @@ import lit.util
from .base import TestFormat
import os, re, signal, string, subprocess
+ok_string = 'Transformation seems to be correct!'
def executeCommand(command):
p = subprocess.Popen(command,
@@ -30,6 +31,12 @@ def executeCommand(command):
return out, err, exitCode
+def id_check(fn, cmd, args):
+ out, err, exitCode = executeCommand(cmd + args)
+ if exitCode != 0 or (out + err).find(ok_string) < 0:
+ raise Exception(fn + ' identity check fail: ' + out + err)
+
+
def readFile(path):
fd = open(path, 'r')
return fd.read()
@@ -58,7 +65,6 @@ class Alive2Test(TestFormat):
def execute(self, test, litConfig):
test = test.getSourcePath()
- ok_string = 'Transformation seems to be correct!'
alive_tv_1 = test.endswith('.srctgt.ll')
if alive_tv_1:
@@ -82,23 +88,21 @@ class Alive2Test(TestFormat):
if m != None:
cmd += m.group(1).split()
- if alive_tv_2:
# Run identity check first
- srcpath = test
- invalid_expr = 'Invalid expr'
- resultchk = lambda msg, exitCode: \
- (exitCode == 0 and msg.find(ok_string) != -1) or \
- (exitCode != 0 and msg.find(invalid_expr) != -1)
-
- out, err, exitCode = executeCommand(cmd + [srcpath, srcpath])
- if not resultchk(out + err, exitCode):
- return lit.Test.FAIL, 'src identity check fail: ' + out + err
+ if alive_tv_1:
+ try:
+ id_check('src', cmd, [test, '-src-fn=src', '-tgt-fn=src'])
+ id_check('tgt', cmd, [test, '-src-fn=tgt', '-tgt-fn=tgt'])
+ except Exception as e:
+ return lit.Test.FAIL, e
+ if alive_tv_2:
+ try:
+ id_check('src', cmd, [test, test])
tgtpath = test.replace('.src.ll', '.tgt.ll')
- out, err, exitCode = executeCommand(cmd + [tgtpath, tgtpath])
- if not resultchk(out + err, exitCode):
- return lit.Test.FAIL, 'tgt identity check fail: ' + out + err
-
+ id_check('tgt', cmd, [tgtpath, tgtpath])
+ except Exception as e:
+ return lit.Test.FAIL, e
cmd.append(test)
if alive_tv_2:

MODIFY
tools/alive-tv.cpp
tools/alive-tv.cpp
@@ -76,6 +76,14 @@ static llvm::cl::list<std::string> opt_funcs(
llvm::cl::ZeroOrMore, llvm::cl::value_desc("function name"),
llvm::cl::cat(opt_alive));
+static llvm::cl::opt<std::string> opt_src_fn(
+ "src-fn", llvm::cl::desc("Name of src function (without @)"),
+ llvm::cl::cat(opt_alive), llvm::cl::init("src"));
+
+static llvm::cl::opt<std::string> opt_tgt_fn(
+ "tgt-fn", llvm::cl::desc("Name of tgt function (without @)"),
+ llvm::cl::cat(opt_alive), llvm::cl::init("tgt"));
+
static llvm::cl::opt<bool> opt_tactic_verbose(
"tactic-verbose", llvm::cl::desc("SMT Tactic verbose mode"),
llvm::cl::cat(opt_alive), llvm::cl::init(false));
@@ -426,8 +434,8 @@ convenient way to demonstrate an existing optimizer bug.
unique_ptr<llvm::Module> M2;
if (opt_file2.empty()) {
- auto SRC = findFunction(*M1, "src");
- auto TGT = findFunction(*M1, "tgt");
+ auto SRC = findFunction(*M1, opt_src_fn);
+ auto TGT = findFunction(*M1, opt_tgt_fn);
if (SRC && TGT) {
auto &DL = M1.get()->getDataLayout();
auto targetTriple = llvm::Triple(M1.get()->getTargetTriple());

unit tests: do identity checks for .srctgt.ll tests