ART: Use references in assembler tests
Move parameters to const references.
Bug: 32619234
Test: m
Change-Id: Ib68bdc313b91fee1e9e4e1e794eeca630837b005
diff --git a/compiler/utils/assembler_test_base.h b/compiler/utils/assembler_test_base.h
index 8c71292..ac24ee9 100644
--- a/compiler/utils/assembler_test_base.h
+++ b/compiler/utils/assembler_test_base.h
@@ -106,7 +106,9 @@
// Driver() assembles and compares the results. If the results are not equal and we have a
// disassembler, disassemble both and check whether they have the same mnemonics (in which case
// we just warn).
- void Driver(const std::vector<uint8_t>& data, std::string assembly_text, std::string test_name) {
+ void Driver(const std::vector<uint8_t>& data,
+ const std::string& assembly_text,
+ const std::string& test_name) {
EXPECT_NE(assembly_text.length(), 0U) << "Empty assembly";
NativeAssemblerResult res;
@@ -229,7 +231,7 @@
bool success = Exec(args, error_msg);
if (!success) {
LOG(ERROR) << "Assembler command line:";
- for (std::string arg : args) {
+ for (const std::string& arg : args) {
LOG(ERROR) << arg;
}
}
@@ -238,7 +240,7 @@
// Runs objdump -h on the binary file and extracts the first line with .text.
// Returns "" on failure.
- std::string Objdump(std::string file) {
+ std::string Objdump(const std::string& file) {
bool have_objdump = FileExists(FindTool(objdump_cmd_name_));
EXPECT_TRUE(have_objdump) << "Cannot find objdump: " << GetObjdumpCommand();
if (!have_objdump) {
@@ -287,8 +289,9 @@
}
// Disassemble both binaries and compare the text.
- bool DisassembleBinaries(const std::vector<uint8_t>& data, const std::vector<uint8_t>& as,
- std::string test_name) {
+ bool DisassembleBinaries(const std::vector<uint8_t>& data,
+ const std::vector<uint8_t>& as,
+ const std::string& test_name) {
std::string disassembler = GetDisassembleCommand();
if (disassembler.length() == 0) {
LOG(WARNING) << "No dissassembler command.";
@@ -324,7 +327,7 @@
return result;
}
- bool DisassembleBinary(std::string file, std::string* error_msg) {
+ bool DisassembleBinary(const std::string& file, std::string* error_msg) {
std::vector<std::string> args;
// Encaspulate the whole command line in a single string passed to
@@ -345,7 +348,7 @@
return Exec(args, error_msg);
}
- std::string WriteToFile(const std::vector<uint8_t>& buffer, std::string test_name) {
+ std::string WriteToFile(const std::vector<uint8_t>& buffer, const std::string& test_name) {
std::string file_name = GetTmpnam() + std::string("---") + test_name;
const char* data = reinterpret_cast<const char*>(buffer.data());
std::ofstream s_out(file_name + ".o");
@@ -354,7 +357,7 @@
return file_name + ".o";
}
- bool CompareFiles(std::string f1, std::string f2) {
+ bool CompareFiles(const std::string& f1, const std::string& f2) {
std::ifstream f1_in(f1);
std::ifstream f2_in(f2);
@@ -369,7 +372,9 @@
}
// Compile the given assembly code and extract the binary, if possible. Put result into res.
- bool Compile(std::string assembly_code, NativeAssemblerResult* res, std::string test_name) {
+ bool Compile(const std::string& assembly_code,
+ NativeAssemblerResult* res,
+ const std::string& test_name) {
res->ok = false;
res->code.reset(nullptr);
@@ -438,7 +443,7 @@
// Check whether file exists. Is used for commands, so strips off any parameters: anything after
// the first space. We skip to the last slash for this, so it should work with directories with
// spaces.
- static bool FileExists(std::string file) {
+ static bool FileExists(const std::string& file) {
if (file.length() == 0) {
return false;
}
@@ -478,7 +483,7 @@
return getcwd(temp, 1024) ? std::string(temp) + "/" : std::string("");
}
- std::string FindTool(std::string tool_name) {
+ std::string FindTool(const std::string& tool_name) {
// Find the current tool. Wild-card pattern is "arch-string*tool-name".
std::string gcc_path = GetRootPath() + GetGCCRootPath();
std::vector<std::string> args;
@@ -522,7 +527,8 @@
// Helper for below. If name_predicate is empty, search for all files, otherwise use it for the
// "-name" option.
- static void FindToolDumpPrintout(std::string name_predicate, std::string tmp_file) {
+ static void FindToolDumpPrintout(const std::string& name_predicate,
+ const std::string& tmp_file) {
std::string gcc_path = GetRootPath() + GetGCCRootPath();
std::vector<std::string> args;
args.push_back("find");
@@ -562,7 +568,7 @@
}
// For debug purposes.
- void FindToolDump(std::string tool_name) {
+ void FindToolDump(const std::string& tool_name) {
// Check with the tool name.
FindToolDumpPrintout(architecture_string_ + "*" + tool_name, GetTmpnam());
FindToolDumpPrintout("", GetTmpnam());