blob: c3662cd40322b5c09589242cb522f3b91e8b71b1 [file] [log] [blame]
Brian Carlstromdb4d5402011-08-09 12:18:28 -07001// Copyright 2011 Google Inc. All Rights Reserved.
2
3#include "common_test.h"
4#include "image_writer.h"
5
6#include "gtest/gtest.h"
7
8namespace art {
9
10class ImageTest : public RuntimeTest {};
11
12TEST_F(ImageTest, WriteRead) {
Brian Carlstromdb4d5402011-08-09 12:18:28 -070013 scoped_ptr<DexFile> libcore_dex_file(GetLibCoreDex());
14 EXPECT_TRUE(libcore_dex_file.get() != NULL);
15
16 // TODO garbage collect before writing
17 const std::vector<Space*>& spaces = Heap::GetSpaces();
18 // can't currently deal with writing a space that might have pointers between spaces
19 CHECK_EQ(1U, spaces.size());
20
21 ImageWriter writer;
22 ScratchFile tmp;
Brian Carlstrom8a436592011-08-15 21:27:23 -070023 const int image_base = 0x5000000;
24 bool success = writer.Write(spaces[0], tmp.GetFilename(), reinterpret_cast<byte*>(image_base));
Brian Carlstromdb4d5402011-08-09 12:18:28 -070025 EXPECT_TRUE(success);
Brian Carlstrom8a436592011-08-15 21:27:23 -070026
27 // tear down old runtime and make a new one
28 delete runtime_.release();
29 java_lang_dex_file_.reset(GetLibCoreDex());
30
31 std::vector<const DexFile*> boot_class_path;
32 boot_class_path.push_back(java_lang_dex_file_.get());
33
34 Runtime::Options options;
35 options.push_back(std::make_pair("bootclasspath", &boot_class_path));
36 std::string boot_image("-Xbootimage:");
37 boot_image.append(tmp.GetFilename());
38 options.push_back(std::make_pair(boot_image.c_str(), reinterpret_cast<void*>(NULL)));
39
40 runtime_.reset(Runtime::Create(options, false));
41 ASSERT_TRUE(runtime_ != NULL);
42 class_linker_ = runtime_->GetClassLinker();
Brian Carlstromdb4d5402011-08-09 12:18:28 -070043}
44
45} // namespace art