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 "base/macros.h" 24 #include "dex2oat_environment_test.h" 25 26 namespace art HIDDEN { 27 28 class DexoptTest : public Dex2oatEnvironmentTest { 29 public: 30 void SetUp() override; 31 32 void PreRuntimeCreate() override; 33 34 void PostRuntimeCreate() override; 35 36 std::string GenerateAlternateImage(const std::string& scratch_dir); 37 38 // Generate an oat file for the purposes of test. 39 // The oat file will be generated for dex_location in the given oat_location 40 // with the following configuration: 41 // filter - controls the compilation filter 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 with_alternate_image, 48 const char* compilation_reason = nullptr, 49 const std::vector<std::string>& extra_args = {}); 50 51 // Generate an odex file for the purposes of test. 52 void GenerateOdexForTest(const std::string& dex_location, 53 const std::string& odex_location, 54 CompilerFilter::Filter filter, 55 const char* compilation_reason = nullptr, 56 const std::vector<std::string>& extra_args = {}); 57 58 // Generate an oat file for the given dex location in its oat location (under 59 // the dalvik cache). 60 void GenerateOatForTest(const char* dex_location, 61 CompilerFilter::Filter filter, 62 bool with_alternate_image); 63 64 // Generate a standard oat file in the oat location. 65 void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter); 66 67 // Generate sdm and dm files for the purposes of test. 68 // If `include_app_image` is true, generates an app image and includes it in the sdm file. 69 void GenerateSdmDmForTest(const std::string& dex_location, 70 const std::string& sdm_location, 71 const std::string& dm_location, 72 CompilerFilter::Filter filter, 73 bool include_app_image, 74 const char* compilation_reason = nullptr, 75 const std::vector<std::string>& extra_args = {}); 76 77 bool Dex2Oat(const std::vector<std::string>& args, std::string* error_msg); 78 79 private: 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<MemMap> image_reservation_; 95 }; 96 97 } // namespace art 98 99 #endif // ART_RUNTIME_DEXOPT_TEST_H_ 100