Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 1 | // 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 | |
| 8 | namespace art { |
| 9 | |
| 10 | class ImageTest : public RuntimeTest {}; |
| 11 | |
| 12 | TEST_F(ImageTest, WriteRead) { |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 13 | 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 Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame^] | 23 | const int image_base = 0x5000000; |
| 24 | bool success = writer.Write(spaces[0], tmp.GetFilename(), reinterpret_cast<byte*>(image_base)); |
Brian Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 25 | EXPECT_TRUE(success); |
Brian Carlstrom | 8a43659 | 2011-08-15 21:27:23 -0700 | [diff] [blame^] | 26 | |
| 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 Carlstrom | db4d540 | 2011-08-09 12:18:28 -0700 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | } // namespace art |