1 //===- Tester.cpp ---------------------------------------------------------===// 2 // 3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 // See https://llvm.org/LICENSE.txt for license information. 5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 // 7 //===----------------------------------------------------------------------===// 8 // 9 // This file defines the Tester class used in the MLIR Reduce tool. 10 // 11 // A Tester object is passed as an argument to the reduction passes and it is 12 // used to keep track of the state of the reduction throughout the multiple 13 // passes. 14 // 15 //===----------------------------------------------------------------------===// 16 17 #include "mlir/Reducer/Tester.h" 18 19 using namespace mlir; 20 21 Tester::Tester(StringRef scriptName, ArrayRef<std::string> scriptArgs) 22 : testScript(scriptName), testScriptArgs(scriptArgs) {} 23 24 /// Runs the interestingness testing script on a MLIR test case file. Returns 25 /// true if the interesting behavior is present in the test case or false 26 /// otherwise. 27 bool Tester::isInteresting(StringRef testCase) { 28 29 std::vector<StringRef> testerArgs; 30 testerArgs.push_back(testCase); 31 32 for (const std::string &arg : testScriptArgs) 33 testerArgs.push_back(arg); 34 35 std::string errMsg; 36 int result = llvm::sys::ExecuteAndWait( 37 testScript, testerArgs, /*Env=*/None, /*Redirects=*/None, 38 /*SecondsToWait=*/0, /*MemoryLimit=*/0, &errMsg); 39 40 if (result < 0) 41 llvm::report_fatal_error("Error running interestingness test: " + errMsg, 42 false); 43 44 if (!result) 45 return false; 46 47 return true; 48 } 49