summaryrefslogtreecommitdiff
path: root/compiler/utils/assembler_thumb_test.cc
diff options
context:
space:
mode:
author David Srbecky <dsrbecky@google.com> 2015-04-12 07:45:18 +0100
committer David Srbecky <dsrbecky@google.com> 2015-04-21 12:37:13 +0100
commit3e52aa4d406fe802dabee2a2e7ba8764cc13aaaa (patch)
tree81b2d22b3fae45a0c92e688a3502335c02397934 /compiler/utils/assembler_thumb_test.cc
parentf458ba7d9c04bc8d499532b5470af28db18e4149 (diff)
Move GetAndroidToolsDir to common location.
Move the code which looks for the prebuilts directory to CommonRuntimeTest and add test for it. Change-Id: Id804de31c466656957fdd4b6a470f80a00477aed
Diffstat (limited to 'compiler/utils/assembler_thumb_test.cc')
-rw-r--r--compiler/utils/assembler_thumb_test.cc94
1 files changed, 5 insertions, 89 deletions
diff --git a/compiler/utils/assembler_thumb_test.cc b/compiler/utils/assembler_thumb_test.cc
index a171e59d98..772fa9aa4b 100644
--- a/compiler/utils/assembler_thumb_test.cc
+++ b/compiler/utils/assembler_thumb_test.cc
@@ -43,8 +43,6 @@ namespace arm {
static constexpr bool kPrintResults = false;
#endif
-static const char* TOOL_PREFIX = "arm-linux-androideabi-";
-
void SetAndroidData() {
const char* data = getenv("ANDROID_DATA");
if (data == nullptr) {
@@ -65,87 +63,6 @@ int CompareIgnoringSpace(const char* s1, const char* s2) {
return *s1 - *s2;
}
-std::string GetAndroidToolsDir() {
- std::string root;
- const char* android_build_top = getenv("ANDROID_BUILD_TOP");
- if (android_build_top != nullptr) {
- root += android_build_top;
- } else {
- // Not set by build server, so default to current directory
- char* cwd = getcwd(nullptr, 0);
- setenv("ANDROID_BUILD_TOP", cwd, 1);
- root += cwd;
- free(cwd);
- }
-
- // Look for "prebuilts"
- std::string toolsdir = root;
- struct stat st;
- while (toolsdir != "") {
- std::string prebuilts = toolsdir + "/prebuilts";
- if (stat(prebuilts.c_str(), &st) == 0) {
- // Found prebuilts.
- toolsdir += "/prebuilts/gcc/linux-x86/arm";
- break;
- }
- // Not present, move up one dir.
- size_t slash = toolsdir.rfind('/');
- if (slash == std::string::npos) {
- toolsdir = "";
- } else {
- toolsdir = toolsdir.substr(0, slash-1);
- }
- }
- bool statok = stat(toolsdir.c_str(), &st) == 0;
- if (!statok) {
- return ""; // Use path.
- }
-
- DIR* dir = opendir(toolsdir.c_str());
- if (dir == nullptr) {
- return ""; // Use path.
- }
-
- struct dirent* entry;
- std::string founddir;
- double maxversion = 0;
-
- // Find the latest version of the arm-eabi tools (biggest version number).
- // Suffix on toolsdir will be something like "arm-eabi-4.8"
- while ((entry = readdir(dir)) != nullptr) {
- std::string subdir = toolsdir + std::string("/") + std::string(entry->d_name);
- size_t eabi = subdir.find(TOOL_PREFIX);
- if (eabi != std::string::npos) {
- // Check if "bin/{as,objcopy,objdump}" exist under this folder.
- struct stat exec_st;
- std::string exec_path;
- exec_path = subdir + "/bin/" + TOOL_PREFIX + "as";
- if (stat(exec_path.c_str(), &exec_st) != 0)
- continue;
- exec_path = subdir + "/bin/" + TOOL_PREFIX + "objcopy";
- if (stat(exec_path.c_str(), &exec_st) != 0)
- continue;
- exec_path = subdir + "/bin/" + TOOL_PREFIX + "objdump";
- if (stat(exec_path.c_str(), &exec_st) != 0)
- continue;
-
- std::string suffix = subdir.substr(eabi + strlen(TOOL_PREFIX));
- double version = strtod(suffix.c_str(), nullptr);
- if (version > maxversion) {
- maxversion = version;
- founddir = subdir;
- }
- }
- }
- closedir(dir);
- bool found = founddir != "";
- if (!found) {
- return ""; // Use path.
- }
-
- return founddir + "/bin/";
-}
-
void dump(std::vector<uint8_t>& code, const char* testname) {
// This will only work on the host. There is no as, objcopy or objdump on the
// device.
@@ -155,7 +72,7 @@ void dump(std::vector<uint8_t>& code, const char* testname) {
if (!results_ok) {
setup_results();
- toolsdir = GetAndroidToolsDir();
+ toolsdir = CommonRuntimeTest::GetAndroidTargetToolsDir(kThumb2);
SetAndroidData();
results_ok = true;
}
@@ -187,19 +104,18 @@ void dump(std::vector<uint8_t>& code, const char* testname) {
char cmd[1024];
// Assemble the .S
- snprintf(cmd, sizeof(cmd), "%s%sas %s -o %s.o", toolsdir.c_str(), TOOL_PREFIX, filename, filename);
+ snprintf(cmd, sizeof(cmd), "%sas %s -o %s.o", toolsdir.c_str(), filename, filename);
system(cmd);
// Remove the $d symbols to prevent the disassembler dumping the instructions
// as .word
- snprintf(cmd, sizeof(cmd), "%s%sobjcopy -N '$d' %s.o %s.oo", toolsdir.c_str(), TOOL_PREFIX,
- filename, filename);
+ snprintf(cmd, sizeof(cmd), "%sobjcopy -N '$d' %s.o %s.oo", toolsdir.c_str(), filename, filename);
system(cmd);
// Disassemble.
- snprintf(cmd, sizeof(cmd), "%s%sobjdump -d %s.oo | grep '^ *[0-9a-f][0-9a-f]*:'",
- toolsdir.c_str(), TOOL_PREFIX, filename);
+ snprintf(cmd, sizeof(cmd), "%sobjdump -d %s.oo | grep '^ *[0-9a-f][0-9a-f]*:'",
+ toolsdir.c_str(), filename);
if (kPrintResults) {
// Print the results only, don't check. This is used to generate new output for inserting
// into the .inc file.