Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 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: |
Roland Levillain | f73caca | 2018-08-24 17:19:07 +0100 | [diff] [blame] | 29 | void SetUp() override; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 30 | |
Yi Kong | 3940254 | 2019-03-24 02:47:16 -0700 | [diff] [blame] | 31 | void PreRuntimeCreate() override; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 32 | |
Roland Levillain | f73caca | 2018-08-24 17:19:07 +0100 | [diff] [blame] | 33 | void PostRuntimeCreate() override; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 34 | |
David Srbecky | cf0c6ef | 2020-02-05 16:25:36 +0000 | [diff] [blame] | 35 | std::string GenerateAlternateImage(const std::string& scratch_dir); |
| 36 | |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 37 | // Generate an oat file for the purposes of test. |
| 38 | // The oat file will be generated for dex_location in the given oat_location |
| 39 | // with the following configuration: |
| 40 | // filter - controls the compilation filter |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 41 | // with_alternate_image - if true, the oat file will be generated with an |
| 42 | // image checksum different than the current image checksum. |
| 43 | void GenerateOatForTest(const std::string& dex_location, |
| 44 | const std::string& oat_location, |
| 45 | CompilerFilter::Filter filter, |
Calin Juravle | 5f9a801 | 2018-02-12 20:27:46 -0800 | [diff] [blame] | 46 | bool with_alternate_image, |
Nicolas Geoffray | 35de14b | 2019-01-10 13:10:36 +0000 | [diff] [blame] | 47 | const char* compilation_reason = nullptr, |
| 48 | const std::vector<std::string>& extra_args = {}); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 49 | |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 50 | // Generate an odex file for the purposes of test. |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 51 | void GenerateOdexForTest(const std::string& dex_location, |
| 52 | const std::string& odex_location, |
Vladimir Marko | e066932 | 2018-09-03 15:44:54 +0100 | [diff] [blame] | 53 | CompilerFilter::Filter filter, |
Nicolas Geoffray | 35de14b | 2019-01-10 13:10:36 +0000 | [diff] [blame] | 54 | const char* compilation_reason = nullptr, |
| 55 | const std::vector<std::string>& extra_args = {}); |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 56 | |
| 57 | // Generate an oat file for the given dex location in its oat location (under |
| 58 | // the dalvik cache). |
| 59 | void GenerateOatForTest(const char* dex_location, |
| 60 | CompilerFilter::Filter filter, |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 61 | bool with_alternate_image); |
| 62 | |
| 63 | // Generate a standard oat file in the oat location. |
| 64 | void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter); |
| 65 | |
Vladimir Marko | b9c29f6 | 2019-03-20 14:22:51 +0000 | [diff] [blame] | 66 | bool Dex2Oat(const std::vector<std::string>& args, std::string* error_msg); |
Nicolas Geoffray | 3d8a78a | 2018-08-29 21:10:16 +0000 | [diff] [blame] | 67 | |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 68 | private: |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 69 | // Reserve memory around where the image will be loaded so other memory |
| 70 | // won't conflict when it comes time to load the image. |
| 71 | // This can be called with an already loaded image to reserve the space |
| 72 | // around it. |
| 73 | void ReserveImageSpace(); |
| 74 | |
| 75 | // Reserve a chunk of memory for the image space in the given range. |
| 76 | // Only has effect for chunks with a positive number of bytes. |
| 77 | void ReserveImageSpaceChunk(uintptr_t start, uintptr_t end); |
| 78 | |
| 79 | // Unreserve any memory reserved by ReserveImageSpace. This should be called |
| 80 | // before the image is loaded. |
| 81 | void UnreserveImageSpace(); |
| 82 | |
Vladimir Marko | c34bebf | 2018-08-16 16:12:49 +0100 | [diff] [blame] | 83 | std::vector<MemMap> image_reservation_; |
Calin Juravle | 36eb313 | 2017-01-13 16:32:38 -0800 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | } // namespace art |
| 87 | |
| 88 | #endif // ART_RUNTIME_DEXOPT_TEST_H_ |