1 /* 2 * Copyright (C) 2017 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef ART_RUNTIME_DEXOPT_TEST_H_ 18 #define ART_RUNTIME_DEXOPT_TEST_H_ 19 20 #include <string> 21 #include <vector> 22 23 #include "dex2oat_environment_test.h" 24 25 namespace art { 26 27 class DexoptTest : public Dex2oatEnvironmentTest { 28 public: 29 virtual void SetUp() OVERRIDE; 30 31 virtual void PreRuntimeCreate(); 32 33 virtual void PostRuntimeCreate() OVERRIDE; 34 35 // Generate an oat file for the purposes of test. 36 // The oat file will be generated for dex_location in the given oat_location 37 // with the following configuration: 38 // filter - controls the compilation filter 39 // pic - whether or not the code will be PIC 40 // relocate - if true, the oat file will be relocated with respect to the 41 // boot image. Otherwise the oat file will not be relocated. 42 // with_alternate_image - if true, the oat file will be generated with an 43 // image checksum different than the current image checksum. 44 void GenerateOatForTest(const std::string& dex_location, 45 const std::string& oat_location, 46 CompilerFilter::Filter filter, 47 bool relocate, 48 bool pic, 49 bool with_alternate_image, 50 const char* compilation_reason = nullptr); 51 52 // Generate a non-PIC odex file for the purposes of test. 53 // The generated odex file will be un-relocated. 54 void GenerateOdexForTest(const std::string& dex_location, 55 const std::string& odex_location, 56 CompilerFilter::Filter filter); 57 58 void GeneratePicOdexForTest(const std::string& dex_location, 59 const std::string& odex_location, 60 CompilerFilter::Filter filter, 61 const char* compilation_reason = nullptr); 62 63 // Generate an oat file for the given dex location in its oat location (under 64 // the dalvik cache). 65 void GenerateOatForTest(const char* dex_location, 66 CompilerFilter::Filter filter, 67 bool relocate, 68 bool pic, 69 bool with_alternate_image); 70 71 // Generate a standard oat file in the oat location. 72 void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter); 73 74 private: 75 // Pre-Relocate the image to a known non-zero offset so we don't have to 76 // deal with the runtime randomly relocating the image by 0 and messing up 77 // the expected results of the tests. 78 bool PreRelocateImage(const std::string& image_location, std::string* error_msg); 79 80 // Reserve memory around where the image will be loaded so other memory 81 // won't conflict when it comes time to load the image. 82 // This can be called with an already loaded image to reserve the space 83 // around it. 84 void ReserveImageSpace(); 85 86 // Reserve a chunk of memory for the image space in the given range. 87 // Only has effect for chunks with a positive number of bytes. 88 void ReserveImageSpaceChunk(uintptr_t start, uintptr_t end); 89 90 // Unreserve any memory reserved by ReserveImageSpace. This should be called 91 // before the image is loaded. 92 void UnreserveImageSpace(); 93 94 std::vector<std::unique_ptr<MemMap>> image_reservation_; 95 }; 96 97 } // namespace art 98 99 #endif // ART_RUNTIME_DEXOPT_TEST_H_ 100