Move base64 to test code
Change-Id: I0cda5d8a559a2d60250c1d8a8ee6f69509515214
diff --git a/Android.mk b/Android.mk
index e32cc7a..ee8cce7 100644
--- a/Android.mk
+++ b/Android.mk
@@ -18,6 +18,8 @@
include $(CLEAR_VARS)
build_path := $(LOCAL_PATH)/build
+include $(build_path)/Android.common.mk
+
include $(build_path)/Android.libart.mk
include $(build_path)/Android.test.mk
include $(build_path)/Android.aexec.mk
diff --git a/build/Android.aexec.host.mk b/build/Android.aexec.host.mk
index 6efc9e9..25a66a8 100644
--- a/build/Android.aexec.host.mk
+++ b/build/Android.aexec.host.mk
@@ -15,16 +15,10 @@
#
include $(CLEAR_VARS)
-
+LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
LOCAL_MODULE := aexec
LOCAL_MODULE_TAGS := optional
-
-include $(build_path)/Android.common.mk
LOCAL_SRC_FILES := $(AEXEC_SRC_FILES)
-
-LOCAL_C_INCLUDES :=
-
-LOCAL_SHARED_LIBRARIES := \
- libart
-
+LOCAL_CFLAGS := $(ART_CFLAGS)
+LOCAL_SHARED_LIBRARIES := libart
include $(BUILD_HOST_EXECUTABLE)
diff --git a/build/Android.aexec.mk b/build/Android.aexec.mk
index 411128e..216cc2c 100644
--- a/build/Android.aexec.mk
+++ b/build/Android.aexec.mk
@@ -15,18 +15,11 @@
#
include $(CLEAR_VARS)
-
+include external/stlport/libstlport.mk
+LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
LOCAL_MODULE := aexec
LOCAL_MODULE_TAGS := optional
-
-include $(build_path)/Android.common.mk
LOCAL_SRC_FILES := $(AEXEC_SRC_FILES)
-
-include external/stlport/libstlport.mk
-LOCAL_C_INCLUDES +=
-
-LOCAL_SHARED_LIBRARIES := \
- libart \
- libstlport
-
+LOCAL_CFLAGS := $(ART_CFLAGS)
+LOCAL_SHARED_LIBRARIES := libart libstlport
include $(BUILD_EXECUTABLE)
diff --git a/build/Android.common.mk b/build/Android.common.mk
index a351dc7..46fa2a2 100644
--- a/build/Android.common.mk
+++ b/build/Android.common.mk
@@ -14,9 +14,9 @@
# limitations under the License.
#
-LOCAL_CPP_EXTENSION := .cc
+ART_CPP_EXTENSION := .cc
-LOCAL_CFLAGS := \
+ART_CFLAGS := \
-O0 \
-ggdb3 \
-Wall \
@@ -27,20 +27,11 @@
-fno-align-jumps \
-fstrict-aliasing
-ifeq ($(TARGET_ARCH),arm)
-LOCAL_CFLAGS +=
-endif
-
-ifeq ($(TARGET_ARCH),x86)
-LOCAL_CFLAGS +=
-endif
-
AEXEC_SRC_FILES := \
src/main.cc
LIBART_COMMON_SRC_FILES := \
src/assembler.cc \
- src/base64.cc \
src/class_linker.cc \
src/dex_file.cc \
src/dex_instruction.cc \
@@ -65,6 +56,9 @@
src/logging_linux.cc \
src/runtime_linux.cc
+LIBARTTEST_COMMON_SRC_FILES := \
+ src/base64.cc
+
TEST_COMMON_SRC_FILES := \
src/class_linker_test.cc \
src/dex_file_test.cc \
diff --git a/build/Android.libart.host.mk b/build/Android.libart.host.mk
index 1612bf8..4d6f980 100644
--- a/build/Android.libart.host.mk
+++ b/build/Android.libart.host.mk
@@ -15,21 +15,11 @@
#
include $(CLEAR_VARS)
-
+LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
LOCAL_MODULE := libart
LOCAL_MODULE_TAGS := optional
-
-include $(build_path)/Android.common.mk
LOCAL_SRC_FILES := $(LIBART_HOST_SRC_FILES)
-
-LOCAL_WHOLE_STATIC_LIBRARIES := \
- libcutils \
- liblog \
- libz
-
-LOCAL_LDLIBS := \
- -ldl \
- -lpthread \
- -lrt
-
+LOCAL_CFLAGS := $(ART_CFLAGS)
+LOCAL_WHOLE_STATIC_LIBRARIES := libcutils liblog libz
+LOCAL_LDLIBS := -ldl -lpthread -lrt
include $(BUILD_HOST_SHARED_LIBRARY)
diff --git a/build/Android.libart.mk b/build/Android.libart.mk
index e9dcfb6..29a38f5 100644
--- a/build/Android.libart.mk
+++ b/build/Android.libart.mk
@@ -15,21 +15,12 @@
#
include $(CLEAR_VARS)
-
+include external/stlport/libstlport.mk
+LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
LOCAL_MODULE := libart
LOCAL_MODULE_TAGS := optional
-
-include $(build_path)/Android.common.mk
LOCAL_SRC_FILES := $(LIBART_TARGET_SRC_FILES)
-
-include external/stlport/libstlport.mk
-
-LOCAL_STATIC_LIBRARIES := \
- libcutils \
- liblog \
- libz
-
-LOCAL_SHARED_LIBRARIES := \
- libstlport
-
+LOCAL_CFLAGS := $(ART_CFLAGS)
+LOCAL_STATIC_LIBRARIES := libcutils liblog libz
+LOCAL_SHARED_LIBRARIES := libstlport
include $(BUILD_SHARED_LIBRARY)
diff --git a/build/Android.test.host.mk b/build/Android.test.host.mk
index 23346d9..67ce272 100644
--- a/build/Android.test.host.mk
+++ b/build/Android.test.host.mk
@@ -15,32 +15,23 @@
#
include $(CLEAR_VARS)
-
-local_module_tags := tests
-
-include $(build_path)/Android.common.mk
-local_cpp_extension := $(LOCAL_CPP_EXTENSION)
-local_cflags := $(LOCAL_CFLAGS)
-
-local_shared_libraries := \
- libart
-
-local_c_includes := \
- external/gtest/include
-
-local_whole_static_libraries := \
- libgtest_host \
- libgtest_main_host
+LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
+LOCAL_MODULE := libarttest
+LOCAL_MODULE_TAGS := tests
+LOCAL_SRC_FILES := $(LIBARTTEST_COMMON_SRC_FILES)
+LOCAL_CFLAGS := $(ART_CFLAGS)
+LOCAL_LDLIBS := -lrt
+include $(BUILD_HOST_SHARED_LIBRARY)
$(foreach file,$(TEST_HOST_SRC_FILES), \
$(eval include $(CLEAR_VARS)) \
- $(eval LOCAL_CPP_EXTENSION := $(local_cpp_extension)) \
+ $(eval LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)) \
$(eval LOCAL_MODULE := $(notdir $(file:%.cc=%))) \
- $(eval LOCAL_MODULE_TAGS := $(local_module_tags)) \
+ $(eval LOCAL_MODULE_TAGS := tests) \
$(eval LOCAL_SRC_FILES := $(file)) \
- $(eval LOCAL_CFLAGS := $(local_cflags)) \
- $(eval LOCAL_C_INCLUDES := $(local_c_includes)) \
- $(eval LOCAL_WHOLE_STATIC_LIBRARIES := $(local_whole_static_libraries)) \
- $(eval LOCAL_SHARED_LIBRARIES := $(local_shared_libraries)) \
+ $(eval LOCAL_CFLAGS := $(ART_CFLAGS)) \
+ $(eval LOCAL_C_INCLUDES += external/gtest/include) \
+ $(eval LOCAL_WHOLE_STATIC_LIBRARIES := libgtest_host libgtest_main_host) \
+ $(eval LOCAL_SHARED_LIBRARIES := libarttest libart) \
$(eval include $(BUILD_HOST_EXECUTABLE)) \
)
diff --git a/build/Android.test.mk b/build/Android.test.mk
index 7d7b2ce..1c2a718 100644
--- a/build/Android.test.mk
+++ b/build/Android.test.mk
@@ -15,34 +15,25 @@
#
include $(CLEAR_VARS)
-
-local_module_tags := tests
-
-include $(build_path)/Android.common.mk
-local_cpp_extension := $(LOCAL_CPP_EXTENSION)
-local_cflags := $(LOCAL_CFLAGS)
-
-local_shared_libraries := \
- libart \
- libstlport
-
-local_c_includes := \
- external/gtest/include
-
-local_static_libraries := \
- libgtest \
- libgtest_main
+include external/stlport/libstlport.mk
+LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)
+LOCAL_MODULE := libarttest
+LOCAL_MODULE_TAGS := optional
+LOCAL_SRC_FILES := $(LIBARTTEST_COMMON_SRC_FILES)
+LOCAL_CFLAGS := $(ART_CFLAGS)
+LOCAL_SHARED_LIBRARIES := libstlport
+include $(BUILD_SHARED_LIBRARY)
$(foreach file,$(TEST_TARGET_SRC_FILES), \
$(eval include $(CLEAR_VARS)) \
- $(eval LOCAL_CPP_EXTENSION := $(local_cpp_extension)) \
- $(eval LOCAL_MODULE := $(notdir $(file:%.cc=%))) \
- $(eval LOCAL_MODULE_TAGS := $(local_module_tags)) \
- $(eval LOCAL_SRC_FILES := $(file)) \
- $(eval LOCAL_CFLAGS := $(local_cflags)) \
$(eval include external/stlport/libstlport.mk) \
- $(eval LOCAL_C_INCLUDES += $(local_c_includes)) \
- $(eval LOCAL_STATIC_LIBRARIES := $(local_static_libraries)) \
- $(eval LOCAL_SHARED_LIBRARIES := $(local_shared_libraries)) \
+ $(eval LOCAL_CPP_EXTENSION := $(ART_CPP_EXTENSION)) \
+ $(eval LOCAL_MODULE := $(notdir $(file:%.cc=%))) \
+ $(eval LOCAL_MODULE_TAGS := tests) \
+ $(eval LOCAL_SRC_FILES := $(file)) \
+ $(eval LOCAL_CFLAGS := $(ART_CFLAGS)) \
+ $(eval LOCAL_C_INCLUDES += external/gtest/include) \
+ $(eval LOCAL_STATIC_LIBRARIES := libgtest libgtest_main) \
+ $(eval LOCAL_SHARED_LIBRARIES := libarttest libart libstlport) \
$(eval include $(BUILD_EXECUTABLE)) \
)
diff --git a/src/class_linker_test.cc b/src/class_linker_test.cc
index 00fb75c..888ef12 100644
--- a/src/class_linker_test.cc
+++ b/src/class_linker_test.cc
@@ -11,7 +11,7 @@
class ClassLinkerTest : public RuntimeTest {};
TEST_F(ClassLinkerTest, FindClassNonexistent) {
- scoped_ptr<DexFile> dex(DexFile::OpenBase64(kMyClassDex));
+ scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassDex));
ASSERT_TRUE(dex != NULL);
scoped_ptr<ClassLinker> linker(ClassLinker::Create());
@@ -24,9 +24,9 @@
}
TEST_F(ClassLinkerTest, FindClassNested) {
- scoped_ptr<DexFile> objectDex(DexFile::OpenBase64(kJavaLangDex));
+ scoped_ptr<DexFile> objectDex(OpenDexFileBase64(kJavaLangDex));
ASSERT_TRUE(objectDex != NULL);
- scoped_ptr<DexFile> nestedDex(DexFile::OpenBase64(kNestedDex));
+ scoped_ptr<DexFile> nestedDex(OpenDexFileBase64(kNestedDex));
ASSERT_TRUE(nestedDex != NULL);
scoped_ptr<ClassLinker> linker(ClassLinker::Create());
@@ -122,7 +122,7 @@
}
}
- scoped_ptr<DexFile> dex(DexFile::OpenBase64(kMyClassDex));
+ scoped_ptr<DexFile> dex(OpenDexFileBase64(kMyClassDex));
ASSERT_TRUE(dex != NULL);
linker->AppendToClassPath(dex.get());
diff --git a/src/common_test.h b/src/common_test.h
index b9392c8..f341407 100644
--- a/src/common_test.h
+++ b/src/common_test.h
@@ -1,11 +1,27 @@
// Copyright 2011 Google Inc. All Rights Reserved.
+#include "src/base64.h"
#include "src/thread.h"
+#include "src/dex_file.h"
#include "gtest/gtest.h"
namespace art {
+static inline RawDexFile* OpenRawDexFileBase64(const char* base64) {
+ CHECK(base64 != NULL);
+ size_t length;
+ byte* dex_file = DecodeBase64(base64, &length);
+ if (dex_file == NULL) {
+ return NULL;
+ }
+ return RawDexFile::OpenPtr(dex_file, length);
+}
+
+static inline DexFile* OpenDexFileBase64(const char* base64) {
+ return DexFile::Open(OpenRawDexFileBase64(base64));
+}
+
class RuntimeTest : public testing::Test {
protected:
virtual void SetUp() {
diff --git a/src/dex_file.cc b/src/dex_file.cc
index 5b39bfc..6cb8258 100644
--- a/src/dex_file.cc
+++ b/src/dex_file.cc
@@ -14,11 +14,6 @@
return Open(raw);
}
-DexFile* DexFile::OpenBase64(const char* base64) {
- RawDexFile* raw = RawDexFile::OpenBase64(base64);
- return Open(raw);
-}
-
DexFile* DexFile::Open(RawDexFile* raw) {
if (raw == NULL) {
return NULL;
diff --git a/src/dex_file.h b/src/dex_file.h
index 911d3ea..1f4afa3 100644
--- a/src/dex_file.h
+++ b/src/dex_file.h
@@ -20,11 +20,6 @@
// Opens a .dex file from the file system. Returns NULL on failure.
static DexFile* OpenFile(const char* filename);
- // Opens a .dex file from a base64 encoded array. Returns NULL on
- // failure.
- // TODO: move this into the DexFile unit test
- static DexFile* OpenBase64(const char* base64);
-
// Opens a .dex file from a RawDexFile. Takes ownership of the
// RawDexFile.
static DexFile* Open(RawDexFile* raw);
diff --git a/src/dex_file_test.cc b/src/dex_file_test.cc
index 0424cde..561c740 100644
--- a/src/dex_file_test.cc
+++ b/src/dex_file_test.cc
@@ -11,7 +11,7 @@
namespace art {
TEST(DexFileTest, Open) {
- scoped_ptr<DexFile> dex(DexFile::OpenBase64(kNestedDex));
+ scoped_ptr<DexFile> dex(OpenDexFileBase64(kNestedDex));
ASSERT_TRUE(dex != NULL);
}
diff --git a/src/object_test.cc b/src/object_test.cc
index 21aa111..839d61b 100644
--- a/src/object_test.cc
+++ b/src/object_test.cc
@@ -34,9 +34,9 @@
// TODO: test 0 argument methods
// TODO: make this test simpler and shorter
TEST_F(MethodTest, ProtoCompare) {
- scoped_ptr<DexFile> object_dex_file(DexFile::OpenBase64(kJavaLangDex));
+ scoped_ptr<DexFile> object_dex_file(OpenDexFileBase64(kJavaLangDex));
ASSERT_TRUE(object_dex_file != NULL);
- scoped_ptr<DexFile> proto_dex_file(DexFile::OpenBase64(kProtoCompareDex));
+ scoped_ptr<DexFile> proto_dex_file(OpenDexFileBase64(kProtoCompareDex));
ASSERT_TRUE(proto_dex_file != NULL);
scoped_ptr<ClassLinker> linker(ClassLinker::Create());
@@ -92,11 +92,11 @@
}
TEST_F(MethodTest, ProtoCompare2) {
- scoped_ptr<DexFile> object_dex_file(DexFile::OpenBase64(kJavaLangDex));
+ scoped_ptr<DexFile> object_dex_file(OpenDexFileBase64(kJavaLangDex));
ASSERT_TRUE(object_dex_file != NULL);
- scoped_ptr<DexFile> proto1_dex_file(DexFile::OpenBase64(kProtoCompareDex));
+ scoped_ptr<DexFile> proto1_dex_file(OpenDexFileBase64(kProtoCompareDex));
ASSERT_TRUE(proto1_dex_file != NULL);
- scoped_ptr<DexFile> proto2_dex_file(DexFile::OpenBase64(kProtoCompare2Dex));
+ scoped_ptr<DexFile> proto2_dex_file(OpenDexFileBase64(kProtoCompare2Dex));
ASSERT_TRUE(proto2_dex_file != NULL);
scoped_ptr<ClassLinker> linker1(ClassLinker::Create());
linker1->AppendToClassPath(object_dex_file.get());
diff --git a/src/raw_dex_file.cc b/src/raw_dex_file.cc
index 9960aea..d03723d 100644
--- a/src/raw_dex_file.cc
+++ b/src/raw_dex_file.cc
@@ -9,7 +9,6 @@
#include <sys/types.h>
#include <map>
-#include "src/base64.h"
#include "src/globals.h"
#include "src/logging.h"
#include "src/object.h"
@@ -21,33 +20,20 @@
const byte RawDexFile::kDexMagic[] = { 'd', 'e', 'x', '\n' };
const byte RawDexFile::kDexMagicVersion[] = { '0', '3', '5', '\0' };
-// Helper class to deallocate mmap-backed .dex files.
-class MmapCloser : public RawDexFile::Closer {
- public:
- MmapCloser(void* addr, size_t length) : addr_(addr), length_(length) {
- CHECK(addr != NULL);
- };
- virtual ~MmapCloser() {
- if (munmap(addr_, length_) == -1) {
- PLOG(INFO) << "munmap failed";
- }
- }
- private:
- void* addr_;
- size_t length_;
-};
-
-// Helper class for deallocating new/delete-backed .dex files.
-class PtrCloser : public RawDexFile::Closer {
- public:
- PtrCloser(byte* addr) : addr_(addr) {};
- virtual ~PtrCloser() { delete[] addr_; }
- private:
- byte* addr_;
-};
-
RawDexFile::Closer::~Closer() {}
+RawDexFile::MmapCloser::MmapCloser(void* addr, size_t length) : addr_(addr), length_(length) {
+ CHECK(addr != NULL);
+}
+RawDexFile::MmapCloser::~MmapCloser() {
+ if (munmap(addr_, length_) == -1) {
+ PLOG(INFO) << "munmap failed";
+ }
+}
+
+RawDexFile::PtrCloser::PtrCloser(byte* addr) : addr_(addr) {}
+RawDexFile::PtrCloser::~PtrCloser() { delete[] addr_; }
+
RawDexFile* RawDexFile::OpenFile(const char* filename) {
CHECK(filename != NULL);
int fd = open(filename, O_RDONLY); // TODO: scoped_fd
@@ -75,15 +61,10 @@
return Open(dex_file, length, closer);
}
-RawDexFile* RawDexFile::OpenBase64(const char* base64) {
- CHECK(base64 != NULL);
- size_t length;
- byte* dex_file = DecodeBase64(base64, &length);
- if (dex_file == NULL) {
- return NULL;
- }
- RawDexFile::Closer* closer = new PtrCloser(dex_file);
- return Open(dex_file, length, closer);
+RawDexFile* RawDexFile::OpenPtr(byte* ptr, size_t length) {
+ CHECK(ptr != NULL);
+ RawDexFile::Closer* closer = new PtrCloser(ptr);
+ return Open(ptr, length, closer);
}
RawDexFile* RawDexFile::Open(const byte* dex_file, size_t length,
diff --git a/src/raw_dex_file.h b/src/raw_dex_file.h
index f47b982..0bfab12 100644
--- a/src/raw_dex_file.h
+++ b/src/raw_dex_file.h
@@ -203,21 +203,11 @@
uint32_t code_off_;
};
- // Helper class to deallocate underlying storage.
- class Closer {
- public:
- virtual ~Closer();
- };
-
// Opens a .dex file from the file system.
static RawDexFile* OpenFile(const char* filename);
- // Opens a .dex file from a base64 encoded array.
- // TODO: move this into the RawDexFile unit test
- static RawDexFile* OpenBase64(const char* base64);
-
- // Opens a .dex file at a the given address.
- static RawDexFile* Open(const byte* dex_file, size_t length, Closer* closer);
+ // Opens a .dex file from a new allocated pointer
+ static RawDexFile* OpenPtr(byte* ptr, size_t length);
// Closes a .dex file.
virtual ~RawDexFile();
@@ -440,6 +430,34 @@
}
private:
+ // Helper class to deallocate underlying storage.
+ class Closer {
+ public:
+ virtual ~Closer();
+ };
+
+ // Helper class to deallocate mmap-backed .dex files.
+ class MmapCloser : public Closer {
+ public:
+ MmapCloser(void* addr, size_t length);
+ virtual ~MmapCloser();
+ private:
+ void* addr_;
+ size_t length_;
+ };
+
+ // Helper class for deallocating new/delete-backed .dex files.
+ class PtrCloser : public Closer {
+ public:
+ PtrCloser(byte* addr);
+ virtual ~PtrCloser();
+ private:
+ byte* addr_;
+ };
+
+ // Opens a .dex file at a the given address.
+ static RawDexFile* Open(const byte* dex_file, size_t length, Closer* closer);
+
RawDexFile(const byte* addr, size_t length, Closer* closer)
: base_(addr),
length_(length),
diff --git a/src/raw_dex_file_test.cc b/src/raw_dex_file_test.cc
index a67ad77..0395bbd 100644
--- a/src/raw_dex_file_test.cc
+++ b/src/raw_dex_file_test.cc
@@ -11,12 +11,12 @@
namespace art {
TEST(RawDexFileTest, Open) {
- scoped_ptr<RawDexFile> raw(RawDexFile::OpenBase64(kNestedDex));
+ scoped_ptr<RawDexFile> raw(OpenRawDexFileBase64(kNestedDex));
ASSERT_TRUE(raw != NULL);
}
TEST(RawDexFileTest, Header) {
- scoped_ptr<RawDexFile> raw(RawDexFile::OpenBase64(kNestedDex));
+ scoped_ptr<RawDexFile> raw(OpenRawDexFileBase64(kNestedDex));
ASSERT_TRUE(raw != NULL);
const RawDexFile::Header& header = raw->GetHeader();
@@ -44,7 +44,7 @@
}
TEST(RawDexFileTest, ClassDefs) {
- scoped_ptr<RawDexFile> raw(RawDexFile::OpenBase64(kNestedDex));
+ scoped_ptr<RawDexFile> raw(OpenRawDexFileBase64(kNestedDex));
ASSERT_TRUE(raw != NULL);
EXPECT_EQ(2U, raw->NumClassDefs());