blob: 5f0eafd8eb974dfb0d20930bd8885f8db54219d0 [file] [log] [blame]
Calin Juravle36eb3132017-01-13 16:32:38 -08001/*
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
25namespace art {
26
27class 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
51 // Generate a non-PIC odex file for the purposes of test.
52 // The generated odex file will be un-relocated.
53 void GenerateOdexForTest(const std::string& dex_location,
54 const std::string& odex_location,
55 CompilerFilter::Filter filter);
56
57 void GeneratePicOdexForTest(const std::string& dex_location,
58 const std::string& odex_location,
59 CompilerFilter::Filter filter);
60
61 // Generate an oat file for the given dex location in its oat location (under
62 // the dalvik cache).
63 void GenerateOatForTest(const char* dex_location,
64 CompilerFilter::Filter filter,
65 bool relocate,
66 bool pic,
67 bool with_alternate_image);
68
69 // Generate a standard oat file in the oat location.
70 void GenerateOatForTest(const char* dex_location, CompilerFilter::Filter filter);
71
72 private:
73 // Pre-Relocate the image to a known non-zero offset so we don't have to
74 // deal with the runtime randomly relocating the image by 0 and messing up
75 // the expected results of the tests.
76 bool PreRelocateImage(const std::string& image_location, std::string* error_msg);
77
78 // Reserve memory around where the image will be loaded so other memory
79 // won't conflict when it comes time to load the image.
80 // This can be called with an already loaded image to reserve the space
81 // around it.
82 void ReserveImageSpace();
83
84 // Reserve a chunk of memory for the image space in the given range.
85 // Only has effect for chunks with a positive number of bytes.
86 void ReserveImageSpaceChunk(uintptr_t start, uintptr_t end);
87
88 // Unreserve any memory reserved by ReserveImageSpace. This should be called
89 // before the image is loaded.
90 void UnreserveImageSpace();
91
92 std::vector<std::unique_ptr<MemMap>> image_reservation_;
93};
94
95} // namespace art
96
97#endif // ART_RUNTIME_DEXOPT_TEST_H_