blob: 6fe8eeb66eafdd921996c6e1918ac48fe1f82853 [file] [log] [blame]
Jeff Haoc3acfc52016-08-29 14:18:26 -07001/*
2 * Copyright (C) 2016 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#include <string>
18#include <vector>
19#include <sstream>
20
21#include <sys/types.h>
22#include <unistd.h>
23
Jeff Hao042e8982016-10-19 11:17:11 -070024#include "base/unix_file/fd_file.h"
Jeff Haoc3acfc52016-08-29 14:18:26 -070025#include "common_runtime_test.h"
Mathieu Chartierd00e02b2017-05-24 12:04:13 -070026#include "dex_file-inl.h"
David Sehr97c381e2017-02-01 15:09:58 -080027#include "exec_utils.h"
Mathieu Chartierd00e02b2017-05-24 12:04:13 -070028#include "jit/profile_compilation_info.h"
Jeff Haoc3acfc52016-08-29 14:18:26 -070029#include "utils.h"
30
31namespace art {
32
Jeff Hao042e8982016-10-19 11:17:11 -070033static const char kDexFileLayoutInputDex[] =
34 "ZGV4CjAzNQD1KW3+B8NAB0f2A/ZVIBJ0aHrGIqcpVTAUAgAAcAAAAHhWNBIAAAAAAAAAAIwBAAAH"
35 "AAAAcAAAAAQAAACMAAAAAQAAAJwAAAAAAAAAAAAAAAMAAACoAAAAAgAAAMAAAAAUAQAAAAEAADAB"
36 "AAA4AQAAQAEAAEgBAABNAQAAUgEAAGYBAAADAAAABAAAAAUAAAAGAAAABgAAAAMAAAAAAAAAAAAA"
37 "AAAAAAABAAAAAAAAAAIAAAAAAAAAAAAAAAAAAAACAAAAAAAAAAEAAAAAAAAAdQEAAAAAAAABAAAA"
38 "AAAAAAIAAAAAAAAAAgAAAAAAAAB/AQAAAAAAAAEAAQABAAAAaQEAAAQAAABwEAIAAAAOAAEAAQAB"
39 "AAAAbwEAAAQAAABwEAIAAAAOAAY8aW5pdD4ABkEuamF2YQAGQi5qYXZhAANMQTsAA0xCOwASTGph"
40 "dmEvbGFuZy9PYmplY3Q7AAFWAAQABw48AAQABw48AAAAAQAAgIAEgAIAAAEAAYCABJgCAAAACwAA"
41 "AAAAAAABAAAAAAAAAAEAAAAHAAAAcAAAAAIAAAAEAAAAjAAAAAMAAAABAAAAnAAAAAUAAAADAAAA"
42 "qAAAAAYAAAACAAAAwAAAAAEgAAACAAAAAAEAAAIgAAAHAAAAMAEAAAMgAAACAAAAaQEAAAAgAAAC"
43 "AAAAdQEAAAAQAAABAAAAjAEAAA==";
44
Jeff Haoe17f5892017-02-23 16:14:04 -080045// Dex file with catch handler unreferenced by try blocks.
46// Constructed by building a dex file with try/catch blocks and hex editing.
47static const char kUnreferencedCatchHandlerInputDex[] =
48 "ZGV4CjAzNQD+exd52Y0f9nY5x5GmInXq5nXrO6Kl2RV4AwAAcAAAAHhWNBIAAAAAAAAAANgCAAAS"
49 "AAAAcAAAAAgAAAC4AAAAAwAAANgAAAABAAAA/AAAAAQAAAAEAQAAAQAAACQBAAA0AgAARAEAANYB"
50 "AADeAQAA5gEAAO4BAAAAAgAADwIAACYCAAA9AgAAUQIAAGUCAAB5AgAAfwIAAIUCAACIAgAAjAIA"
51 "AKECAACnAgAArAIAAAQAAAAFAAAABgAAAAcAAAAIAAAACQAAAAwAAAAOAAAADAAAAAYAAAAAAAAA"
52 "DQAAAAYAAADIAQAADQAAAAYAAADQAQAABQABABAAAAAAAAAAAAAAAAAAAgAPAAAAAQABABEAAAAD"
53 "AAAAAAAAAAAAAAABAAAAAwAAAAAAAAADAAAAAAAAAMgCAAAAAAAAAQABAAEAAAC1AgAABAAAAHAQ"
54 "AwAAAA4AAwABAAIAAgC6AgAAIQAAAGIAAAAaAQoAbiACABAAYgAAABoBCwBuIAIAEAAOAA0AYgAA"
55 "ABoBAQBuIAIAEAAo8A0AYgAAABoBAgBuIAIAEAAo7gAAAAAAAAcAAQAHAAAABwABAAIBAg8BAhgA"
56 "AQAAAAQAAAABAAAABwAGPGluaXQ+AAZDYXRjaDEABkNhdGNoMgAQSGFuZGxlclRlc3QuamF2YQAN"
57 "TEhhbmRsZXJUZXN0OwAVTGphdmEvaW8vUHJpbnRTdHJlYW07ABVMamF2YS9sYW5nL0V4Y2VwdGlv"
58 "bjsAEkxqYXZhL2xhbmcvT2JqZWN0OwASTGphdmEvbGFuZy9TdHJpbmc7ABJMamF2YS9sYW5nL1N5"
59 "c3RlbTsABFRyeTEABFRyeTIAAVYAAlZMABNbTGphdmEvbGFuZy9TdHJpbmc7AARtYWluAANvdXQA"
60 "B3ByaW50bG4AAQAHDgAEAQAHDn17AncdHoseAAAAAgAAgYAExAIBCdwCAAANAAAAAAAAAAEAAAAA"
61 "AAAAAQAAABIAAABwAAAAAgAAAAgAAAC4AAAAAwAAAAMAAADYAAAABAAAAAEAAAD8AAAABQAAAAQA"
62 "AAAEAQAABgAAAAEAAAAkAQAAASAAAAIAAABEAQAAARAAAAIAAADIAQAAAiAAABIAAADWAQAAAyAA"
63 "AAIAAAC1AgAAACAAAAEAAADIAgAAABAAAAEAAADYAgAA";
64
Jeff Haoac462712017-03-02 10:59:43 -080065// Dex file with 0-size (catch all only) catch handler unreferenced by try blocks.
66// Constructed by building a dex file with try/catch blocks and hex editing.
67static const char kUnreferenced0SizeCatchHandlerInputDex[] =
68 "ZGV4CjAzNQCEbEEvMstSNpQpjPdfMEfUBS48cis2QRJoAwAAcAAAAHhWNBIAAAAAAAAAAMgCAAAR"
69 "AAAAcAAAAAcAAAC0AAAAAwAAANAAAAABAAAA9AAAAAQAAAD8AAAAAQAAABwBAAAsAgAAPAEAAOoB"
70 "AADyAQAABAIAABMCAAAqAgAAPgIAAFICAABmAgAAaQIAAG0CAACCAgAAhgIAAIoCAACQAgAAlQIA"
71 "AJ4CAACiAgAAAgAAAAMAAAAEAAAABQAAAAYAAAAHAAAACQAAAAcAAAAFAAAAAAAAAAgAAAAFAAAA"
72 "3AEAAAgAAAAFAAAA5AEAAAQAAQANAAAAAAAAAAAAAAAAAAIADAAAAAEAAQAOAAAAAgAAAAAAAAAA"
73 "AAAAAQAAAAIAAAAAAAAAAQAAAAAAAAC5AgAAAAAAAAEAAQABAAAApgIAAAQAAABwEAMAAAAOAAQA"
74 "AQACAAIAqwIAAC8AAABiAAAAGgEPAG4gAgAQAGIAAAAaAQoAbiACABAAYgAAABoBEABuIAIAEABi"
75 "AAAAGgELAG4gAgAQAA4ADQBiAQAAGgIKAG4gAgAhACcADQBiAQAAGgILAG4gAgAhACcAAAAAAAAA"
76 "BwABAA4AAAAHAAEAAgAdACYAAAABAAAAAwAAAAEAAAAGAAY8aW5pdD4AEEhhbmRsZXJUZXN0Lmph"
77 "dmEADUxIYW5kbGVyVGVzdDsAFUxqYXZhL2lvL1ByaW50U3RyZWFtOwASTGphdmEvbGFuZy9PYmpl"
78 "Y3Q7ABJMamF2YS9sYW5nL1N0cmluZzsAEkxqYXZhL2xhbmcvU3lzdGVtOwABVgACVkwAE1tMamF2"
79 "YS9sYW5nL1N0cmluZzsAAmYxAAJmMgAEbWFpbgADb3V0AAdwcmludGxuAAJ0MQACdDIAAQAHDgAE"
80 "AQAHDnl7eXkCeB2bAAAAAgAAgYAEvAIBCdQCAA0AAAAAAAAAAQAAAAAAAAABAAAAEQAAAHAAAAAC"
81 "AAAABwAAALQAAAADAAAAAwAAANAAAAAEAAAAAQAAAPQAAAAFAAAABAAAAPwAAAAGAAAAAQAAABwB"
82 "AAABIAAAAgAAADwBAAABEAAAAgAAANwBAAACIAAAEQAAAOoBAAADIAAAAgAAAKYCAAAAIAAAAQAA"
83 "ALkCAAAAEAAAAQAAAMgCAAA=";
84
Jeff Haoa64a64c2017-03-06 15:05:38 -080085// Dex file with an unreferenced catch handler at end of code item.
86// Constructed by building a dex file with try/catch blocks and hex editing.
87static const char kUnreferencedEndingCatchHandlerInputDex[] =
88 "ZGV4CjAzNQCEflufI6xGTDDRmLpbfYi6ujPrDLIwvYcEBAAAcAAAAHhWNBIAAAAAAAAAAGQDAAAT"
89 "AAAAcAAAAAgAAAC8AAAAAwAAANwAAAABAAAAAAEAAAUAAAAIAQAAAQAAADABAAC0AgAAUAEAAE4C"
90 "AABWAgAAXgIAAGYCAAB4AgAAhwIAAJ4CAAC1AgAAyQIAAN0CAADxAgAA9wIAAP0CAAAAAwAABAMA"
91 "ABkDAAAcAwAAIgMAACcDAAAEAAAABQAAAAYAAAAHAAAACAAAAAkAAAAMAAAADgAAAAwAAAAGAAAA"
92 "AAAAAA0AAAAGAAAAQAIAAA0AAAAGAAAASAIAAAUAAQARAAAAAAAAAAAAAAAAAAAADwAAAAAAAgAQ"
93 "AAAAAQABABIAAAADAAAAAAAAAAAAAAABAAAAAwAAAAAAAAADAAAAAAAAAFADAAAAAAAAAQABAAEA"
94 "AAAwAwAABAAAAHAQBAAAAA4AAgAAAAIAAgA1AwAAIQAAAGIAAAAaAQoAbiADABAAYgAAABoBCwBu"
95 "IAMAEAAOAA0AYgAAABoBAQBuIAMAEAAo8A0AYgAAABoBAgBuIAMAEAAo7gAAAAAAAAcAAQAHAAAA"
96 "BwABAAIBAg8BAhgAAwABAAIAAgBCAwAAIQAAAGIAAAAaAQoAbiADABAAYgAAABoBCwBuIAMAEAAO"
97 "AA0AYgAAABoBAQBuIAMAEAAo8A0AYgAAABoBAgBuIAMAEAAo7gAAAAAAAAcAAQAHAAAABwABAAIB"
98 "Ag8BAhgAAQAAAAQAAAABAAAABwAGPGluaXQ+AAZDYXRjaDEABkNhdGNoMgAQSGFuZGxlclRlc3Qu"
99 "amF2YQANTEhhbmRsZXJUZXN0OwAVTGphdmEvaW8vUHJpbnRTdHJlYW07ABVMamF2YS9sYW5nL0V4"
100 "Y2VwdGlvbjsAEkxqYXZhL2xhbmcvT2JqZWN0OwASTGphdmEvbGFuZy9TdHJpbmc7ABJMamF2YS9s"
101 "YW5nL1N5c3RlbTsABFRyeTEABFRyeTIAAVYAAlZMABNbTGphdmEvbGFuZy9TdHJpbmc7AAFhAARt"
102 "YWluAANvdXQAB3ByaW50bG4AAQAHDgAEAAcOfHsCeB0eih4AEQEABw59ewJ3HR6LHgAAAAMAAIGA"
103 "BNACAQnoAgEJ1AMAAA0AAAAAAAAAAQAAAAAAAAABAAAAEwAAAHAAAAACAAAACAAAALwAAAADAAAA"
104 "AwAAANwAAAAEAAAAAQAAAAABAAAFAAAABQAAAAgBAAAGAAAAAQAAADABAAABIAAAAwAAAFABAAAB"
105 "EAAAAgAAAEACAAACIAAAEwAAAE4CAAADIAAAAwAAADADAAAAIAAAAQAAAFADAAAAEAAAAQAAAGQD"
106 "AAA=";
107
Mathieu Chartier6b0dbef2017-02-21 12:45:30 -0800108// Dex file with multiple code items that have the same debug_info_off_. Constructed by a modified
109// dexlayout on XandY.
110static const char kDexFileDuplicateOffset[] =
111 "ZGV4CjAzNwAQfXfPCB8qCxo7MqdFhmHZQwCv8+udHD8MBAAAcAAAAHhWNBIAAAAAAAAAAFQDAAAT"
112 "AAAAcAAAAAgAAAC8AAAAAQAAANwAAAABAAAA6AAAAAUAAADwAAAAAwAAABgBAACUAgAAeAEAABQC"
113 "AAAeAgAAJgIAACsCAAAyAgAANwIAAFsCAAB7AgAAngIAALICAAC1AgAAvQIAAMUCAADIAgAA1QIA"
114 "AOkCAADvAgAA9QIAAPwCAAACAAAAAwAAAAQAAAAFAAAABgAAAAcAAAAIAAAACQAAAAkAAAAHAAAA"
115 "AAAAAAIAAQASAAAAAAAAAAEAAAABAAAAAQAAAAIAAAAAAAAAAgAAAAEAAAAGAAAAAQAAAAAAAAAA"
116 "AAAABgAAAAAAAAAKAAAAAAAAACsDAAAAAAAAAQAAAAAAAAAGAAAAAAAAAAsAAAD0AQAANQMAAAAA"
117 "AAACAAAAAAAAAAAAAAAAAAAACwAAAAQCAAA/AwAAAAAAAAIAAAAUAwAAGgMAAAEAAAAjAwAAAQAB"
118 "AAEAAAAFAAAABAAAAHAQBAAAAA4AAQABAAEAAAAFAAAABAAAAHAQBAAAAA4AAQAAAAEAAAAFAAAA"
119 "CAAAACIAAQBwEAEAAABpAAAADgABAAEAAQAAAAUAAAAEAAAAcBAAAAAADgB4AQAAAAAAAAAAAAAA"
120 "AAAAhAEAAAAAAAAAAAAAAAAAAAg8Y2xpbml0PgAGPGluaXQ+AANMWDsABUxZJFo7AANMWTsAIkxk"
121 "YWx2aWsvYW5ub3RhdGlvbi9FbmNsb3NpbmdDbGFzczsAHkxkYWx2aWsvYW5ub3RhdGlvbi9Jbm5l"
122 "ckNsYXNzOwAhTGRhbHZpay9hbm5vdGF0aW9uL01lbWJlckNsYXNzZXM7ABJMamF2YS9sYW5nL09i"
123 "amVjdDsAAVYABlguamF2YQAGWS5qYXZhAAFaAAthY2Nlc3NGbGFncwASZW1pdHRlcjogamFjay00"
124 "LjI1AARuYW1lAAR0aGlzAAV2YWx1ZQABegARAAcOABMABw4AEgAHDnYAEQAHDgACAwERGAICBAIN"
125 "BAgPFwwCBQERHAEYAQAAAQAAgIAEjAMAAAEAAYCABKQDAQACAAAIAoiABLwDAYCABNwDAAAADwAA"
126 "AAAAAAABAAAAAAAAAAEAAAATAAAAcAAAAAIAAAAIAAAAvAAAAAMAAAABAAAA3AAAAAQAAAABAAAA"
127 "6AAAAAUAAAAFAAAA8AAAAAYAAAADAAAAGAEAAAMQAAACAAAAeAEAAAEgAAAEAAAAjAEAAAYgAAAC"
128 "AAAA9AEAAAIgAAATAAAAFAIAAAMgAAAEAAAA/wIAAAQgAAADAAAAFAMAAAAgAAADAAAAKwMAAAAQ"
129 "AAABAAAAVAMAAA==";
130
Jeff Haof914f8e2017-02-21 16:14:23 -0800131// Dex file with null value for annotations_off in the annotation_set_ref_list.
132// Constructed by building a dex file with annotations and hex editing.
133static const char kNullSetRefListElementInputDex[] =
134 "ZGV4CjAzNQB1iA+7ZwgkF+7E6ZesYFc2lRAR3qnRAanwAwAAcAAAAHhWNBIAAAAAAAAAACADAAAS"
135 "AAAAcAAAAAgAAAC4AAAAAwAAANgAAAABAAAA/AAAAAQAAAAEAQAAAgAAACQBAACMAgAAZAEAAOgB"
136 "AADwAQAAAAIAAAMCAAAQAgAAIAIAADQCAABIAgAAawIAAI0CAAC1AgAAyAIAANECAADUAgAA2QIA"
137 "ANwCAADjAgAA6QIAAAMAAAAEAAAABQAAAAYAAAAHAAAACAAAAAkAAAAMAAAAAgAAAAMAAAAAAAAA"
138 "DAAAAAcAAAAAAAAADQAAAAcAAADgAQAABgAGAAsAAAAAAAEAAAAAAAAAAgAOAAAAAQAAABAAAAAC"
139 "AAEAAAAAAAAAAAAAAAAAAgAAAAAAAAABAAAAsAEAAAgDAAAAAAAAAQAAAAEmAAACAAAA2AEAAAoA"
140 "AADIAQAAFgMAAAAAAAACAAAAAAAAAHwBAAABAAAA/AIAAAAAAAABAAAAAgMAAAEAAQABAAAA8AIA"
141 "AAQAAABwEAMAAAAOAAIAAgAAAAAA9QIAAAEAAAAOAAAAAAAAAAAAAAAAAAAAAQAAAAEAAABkAQAA"
142 "cAEAAAAAAAAAAAAAAAAAAAEAAAAEAAAAAgAAAAMAAwAGPGluaXQ+AA5Bbm5vQ2xhc3MuamF2YQAB"
143 "TAALTEFubm9DbGFzczsADkxNeUFubm90YXRpb247ABJMamF2YS9sYW5nL09iamVjdDsAEkxqYXZh"
144 "L2xhbmcvU3RyaW5nOwAhTGphdmEvbGFuZy9hbm5vdGF0aW9uL0Fubm90YXRpb247ACBMamF2YS9s"
145 "YW5nL2Fubm90YXRpb24vUmV0ZW50aW9uOwAmTGphdmEvbGFuZy9hbm5vdGF0aW9uL1JldGVudGlv"
146 "blBvbGljeTsAEU15QW5ub3RhdGlvbi5qYXZhAAdSVU5USU1FAAFWAANWTEwAAWEABWFOYW1lAARu"
147 "YW1lAAV2YWx1ZQABAAcOAAICAAAHDgABBQERGwABAQEQFw8AAAIAAICABIQDAQmcAwAAAAECgQgA"
148 "AAARAAAAAAAAAAEAAAAAAAAAAQAAABIAAABwAAAAAgAAAAgAAAC4AAAAAwAAAAMAAADYAAAABAAA"
149 "AAEAAAD8AAAABQAAAAQAAAAEAQAABgAAAAIAAAAkAQAAAhAAAAEAAABkAQAAAxAAAAMAAABwAQAA"
150 "ASAAAAIAAACEAQAABiAAAAIAAACwAQAAARAAAAIAAADYAQAAAiAAABIAAADoAQAAAyAAAAIAAADw"
151 "AgAABCAAAAIAAAD8AgAAACAAAAIAAAAIAwAAABAAAAEAAAAgAwAA";
152
Jeff Haoe17f5892017-02-23 16:14:04 -0800153// Dex file with shared empty class data item for multiple class defs.
154// Constructing by building a dex file with multiple classes and hex editing.
155static const char kMultiClassDataInputDex[] =
156 "ZGV4CjAzNQALJgF9TtnLq748xVe/+wyxETrT9lTEiW6YAQAAcAAAAHhWNBIAAAAAAAAAADQBAAAI"
157 "AAAAcAAAAAQAAACQAAAAAAAAAAAAAAACAAAAoAAAAAAAAAAAAAAAAgAAALAAAACoAAAA8AAAAPAA"
158 "AAD4AAAAAAEAAAMBAAAIAQAADQEAACEBAAAkAQAAAgAAAAMAAAAEAAAABQAAAAEAAAAGAAAAAgAA"
159 "AAcAAAABAAAAAQYAAAMAAAAAAAAAAAAAAAAAAAAnAQAAAAAAAAIAAAABBgAAAwAAAAAAAAABAAAA"
160 "AAAAACcBAAAAAAAABkEuamF2YQAGQi5qYXZhAAFJAANMQTsAA0xCOwASTGphdmEvbGFuZy9PYmpl"
161 "Y3Q7AAFhAAFiAAAAAAABAAAAARkAAAAIAAAAAAAAAAEAAAAAAAAAAQAAAAgAAABwAAAAAgAAAAQA"
162 "AACQAAAABAAAAAIAAACgAAAABgAAAAIAAACwAAAAAiAAAAgAAADwAAAAACAAAAIAAAAnAQAAABAA"
163 "AAEAAAA0AQAA";
164
165// Dex file with code info followed by non 4-byte aligned section.
166// Constructed a dex file with code info followed by string data and hex edited.
167static const char kUnalignedCodeInfoInputDex[] =
168 "ZGV4CjAzNQDXJzXNb4iWn2SLhmLydW/8h1K9moERIw7UAQAAcAAAAHhWNBIAAAAAAAAAAEwBAAAG"
169 "AAAAcAAAAAMAAACIAAAAAQAAAJQAAAAAAAAAAAAAAAMAAACgAAAAAQAAALgAAAD8AAAA2AAAAAIB"
170 "AAAKAQAAEgEAABcBAAArAQAALgEAAAIAAAADAAAABAAAAAQAAAACAAAAAAAAAAAAAAAAAAAAAAAA"
171 "AAUAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAABAAAAAAAAADsBAAAAAAAAAQABAAEAAAAxAQAA"
172 "BAAAAHAQAgAAAA4AAQABAAAAAAA2AQAAAQAAAA4ABjxpbml0PgAGQS5qYXZhAANMQTsAEkxqYXZh"
173 "L2xhbmcvT2JqZWN0OwABVgABYQABAAcOAAMABw4AAAABAQCBgATYAQEB8AEAAAALAAAAAAAAAAEA"
174 "AAAAAAAAAQAAAAYAAABwAAAAAgAAAAMAAACIAAAAAwAAAAEAAACUAAAABQAAAAMAAACgAAAABgAA"
175 "AAEAAAC4AAAAASAAAAIAAADYAAAAAiAAAAYAAAACAQAAAyAAAAIAAAAxAQAAACAAAAEAAAA7AQAA"
176 "ABAAAAEAAABMAQAA";
Jeff Hao44652a32017-02-22 14:20:41 -0800177
Jeff Hao32a60ab2017-03-01 16:44:50 -0800178// Dex file with class data section preceding code items.
179// Constructed by passing dex file through dexmerger tool and hex editing.
180static const char kClassDataBeforeCodeInputDex[] =
181 "ZGV4CjAzNQCZKmCu3XXn4zvxCh5VH0gZNNobEAcsc49EAgAAcAAAAHhWNBIAAAAAAAAAAAQBAAAJ"
182 "AAAAcAAAAAQAAACUAAAAAgAAAKQAAAAAAAAAAAAAAAUAAAC8AAAAAQAAAOQAAABAAQAABAEAAPgB"
183 "AAAAAgAACAIAAAsCAAAQAgAAJAIAACcCAAAqAgAALQIAAAIAAAADAAAABAAAAAUAAAACAAAAAAAA"
184 "AAAAAAAFAAAAAwAAAAAAAAABAAEAAAAAAAEAAAAGAAAAAQAAAAcAAAABAAAACAAAAAIAAQAAAAAA"
185 "AQAAAAEAAAACAAAAAAAAAAEAAAAAAAAAjAEAAAAAAAALAAAAAAAAAAEAAAAAAAAAAQAAAAkAAABw"
186 "AAAAAgAAAAQAAACUAAAAAwAAAAIAAACkAAAABQAAAAUAAAC8AAAABgAAAAEAAADkAAAAABAAAAEA"
187 "AAAEAQAAACAAAAEAAACMAQAAASAAAAQAAACkAQAAAiAAAAkAAAD4AQAAAyAAAAQAAAAwAgAAAAAB"
188 "AwCBgASkAwEBvAMBAdADAQHkAwAAAQABAAEAAAAwAgAABAAAAHAQBAAAAA4AAgABAAAAAAA1AgAA"
189 "AgAAABIQDwACAAEAAAAAADoCAAACAAAAEiAPAAIAAQAAAAAAPwIAAAIAAAASMA8ABjxpbml0PgAG"
190 "QS5qYXZhAAFJAANMQTsAEkxqYXZhL2xhbmcvT2JqZWN0OwABVgABYQABYgABYwABAAcOAAMABw4A"
191 "BgAHDgAJAAcOAA==";
192
Jeff Haod9be7682017-04-05 09:29:43 -0700193// Dex file with local info containing a null type descriptor.
194// Constructed a dex file with debug info sequence containing DBG_RESTART_LOCAL without any
195// DBG_START_LOCAL to give it a declared type.
196static const char kUnknownTypeDebugInfoInputDex[] =
197 "ZGV4CjAzNQBtKqZfzjHLNSNwW2A6Bz9FuCEX0sL+FF38AQAAcAAAAHhWNBIAAAAAAAAAAHQBAAAI"
198 "AAAAcAAAAAQAAACQAAAAAgAAAKAAAAAAAAAAAAAAAAMAAAC4AAAAAQAAANAAAAAMAQAA8AAAABwB"
199 "AAAkAQAALAEAAC8BAAA0AQAASAEAAEsBAABOAQAAAgAAAAMAAAAEAAAABQAAAAIAAAAAAAAAAAAA"
200 "AAUAAAADAAAAAAAAAAEAAQAAAAAAAQAAAAYAAAACAAEAAAAAAAEAAAABAAAAAgAAAAAAAAABAAAA"
201 "AAAAAGMBAAAAAAAAAQABAAEAAABUAQAABAAAAHAQAgAAAA4AAgABAAAAAABZAQAAAgAAABIQDwAG"
202 "PGluaXQ+AAZBLmphdmEAAUkAA0xBOwASTGphdmEvbGFuZy9PYmplY3Q7AAFWAAFhAAR0aGlzAAEA"
203 "Bw4AAwAHDh4GAAYAAAAAAQEAgYAE8AEBAYgCAAAACwAAAAAAAAABAAAAAAAAAAEAAAAIAAAAcAAA"
204 "AAIAAAAEAAAAkAAAAAMAAAACAAAAoAAAAAUAAAADAAAAuAAAAAYAAAABAAAA0AAAAAEgAAACAAAA"
205 "8AAAAAIgAAAIAAAAHAEAAAMgAAACAAAAVAEAAAAgAAABAAAAYwEAAAAQAAABAAAAdAEAAA==";
206
Jeff Haod212d5b2017-04-26 12:09:06 -0700207// Dex file with multiple class data items pointing to the same code item.
208// Constructed by hex editing.
209static const char kDuplicateCodeItemInputDex[] =
210 "ZGV4CjAzNQCwKtVglQOmLWuHwldN5jkBOInC7mTMhJMAAgAAcAAAAHhWNBIAAAAAAAAAAHgBAAAH"
211 "AAAAcAAAAAMAAACMAAAAAQAAAJgAAAAAAAAAAAAAAAQAAACkAAAAAQAAAMQAAAAcAQAA5AAAACQB"
212 "AAAsAQAANAEAADkBAABNAQAAUAEAAFMBAAACAAAAAwAAAAQAAAAEAAAAAgAAAAAAAAAAAAAAAAAA"
213 "AAAAAAAFAAAAAAAAAAYAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAABAAAAAAAAAGUBAAAAAAAA"
214 "AQABAAEAAABWAQAABAAAAHAQAwAAAA4AAQABAAAAAABbAQAAAQAAAA4AAAABAAEAAAAAAGABAAAB"
215 "AAAADgAAAAY8aW5pdD4ABkEuamF2YQADTEE7ABJMamF2YS9sYW5nL09iamVjdDsAAVYAAWEAAWIA"
216 "AQAHDgADAAcOAAUABw4AAAABAgCBgATkAQEA/AEBAPwBAAsAAAAAAAAAAQAAAAAAAAABAAAABwAA"
217 "AHAAAAACAAAAAwAAAIwAAAADAAAAAQAAAJgAAAAFAAAABAAAAKQAAAAGAAAAAQAAAMQAAAABIAAA"
218 "AwAAAOQAAAACIAAABwAAACQBAAADIAAAAwAAAFYBAAAAIAAAAQAAAGUBAAAAEAAAAQAAAHgBAAA=";
219
Mathieu Chartier6b0dbef2017-02-21 12:45:30 -0800220static void WriteBase64ToFile(const char* base64, File* file) {
Jeff Hao042e8982016-10-19 11:17:11 -0700221 // Decode base64.
222 CHECK(base64 != nullptr);
223 size_t length;
224 std::unique_ptr<uint8_t[]> bytes(DecodeBase64(base64, &length));
Mathieu Chartier6b0dbef2017-02-21 12:45:30 -0800225 CHECK(bytes != nullptr);
Jeff Hao042e8982016-10-19 11:17:11 -0700226 if (!file->WriteFully(bytes.get(), length)) {
227 PLOG(FATAL) << "Failed to write base64 as file";
228 }
Mathieu Chartier6b0dbef2017-02-21 12:45:30 -0800229}
230
231static void WriteFileBase64(const char* base64, const char* location) {
232 // Write to provided file.
233 std::unique_ptr<File> file(OS::CreateEmptyFile(location));
234 CHECK(file != nullptr);
235 WriteBase64ToFile(base64, file.get());
Jeff Hao042e8982016-10-19 11:17:11 -0700236 if (file->FlushCloseOrErase() != 0) {
237 PLOG(FATAL) << "Could not flush and close test file.";
238 }
239}
240
Jeff Haoc3acfc52016-08-29 14:18:26 -0700241class DexLayoutTest : public CommonRuntimeTest {
242 protected:
243 virtual void SetUp() {
244 CommonRuntimeTest::SetUp();
Jeff Haoc3acfc52016-08-29 14:18:26 -0700245 }
246
Jeff Haoa8621002016-10-04 18:13:44 +0000247 // Runs FullPlainOutput test.
248 bool FullPlainOutputExec(std::string* error_msg) {
Jeff Haoc3acfc52016-08-29 14:18:26 -0700249 // TODO: dexdump2 -> dexdump ?
250 ScratchFile dexdump_output;
Andreas Gampeca620d72016-11-08 08:09:33 -0800251 const std::string& dexdump_filename = dexdump_output.GetFilename();
Jeff Haoc3acfc52016-08-29 14:18:26 -0700252 std::string dexdump = GetTestAndroidRoot() + "/bin/dexdump2";
253 EXPECT_TRUE(OS::FileExists(dexdump.c_str())) << dexdump << " should be a valid file path";
Jeff Haoc3acfc52016-08-29 14:18:26 -0700254
255 ScratchFile dexlayout_output;
Andreas Gampeca620d72016-11-08 08:09:33 -0800256 const std::string& dexlayout_filename = dexlayout_output.GetFilename();
Jeff Haoc3acfc52016-08-29 14:18:26 -0700257 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
258 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
Jeff Haoc3acfc52016-08-29 14:18:26 -0700259
Jeff Haoa8621002016-10-04 18:13:44 +0000260 for (const std::string &dex_file : GetLibCoreDexFileNames()) {
261 std::vector<std::string> dexdump_exec_argv =
262 { dexdump, "-d", "-f", "-h", "-l", "plain", "-o", dexdump_filename, dex_file };
263 std::vector<std::string> dexlayout_exec_argv =
264 { dexlayout, "-d", "-f", "-h", "-l", "plain", "-o", dexlayout_filename, dex_file };
Jeff Haoa8621002016-10-04 18:13:44 +0000265 if (!::art::Exec(dexdump_exec_argv, error_msg)) {
266 return false;
267 }
268 if (!::art::Exec(dexlayout_exec_argv, error_msg)) {
269 return false;
270 }
271 std::vector<std::string> diff_exec_argv =
272 { "/usr/bin/diff", dexdump_filename, dexlayout_filename };
273 if (!::art::Exec(diff_exec_argv, error_msg)) {
274 return false;
275 }
Jeff Haoc3acfc52016-08-29 14:18:26 -0700276 }
277 return true;
278 }
279
Jeff Haoa8621002016-10-04 18:13:44 +0000280 // Runs DexFileOutput test.
281 bool DexFileOutputExec(std::string* error_msg) {
282 ScratchFile tmp_file;
Andreas Gampeca620d72016-11-08 08:09:33 -0800283 const std::string& tmp_name = tmp_file.GetFilename();
284 size_t tmp_last_slash = tmp_name.rfind('/');
Jeff Haoa8621002016-10-04 18:13:44 +0000285 std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1);
286 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
287 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
288
289 for (const std::string &dex_file : GetLibCoreDexFileNames()) {
290 std::vector<std::string> dexlayout_exec_argv =
Jeff Hao042e8982016-10-19 11:17:11 -0700291 { dexlayout, "-w", tmp_dir, "-o", tmp_name, dex_file };
Jeff Haoa8621002016-10-04 18:13:44 +0000292 if (!::art::Exec(dexlayout_exec_argv, error_msg)) {
293 return false;
294 }
Jeff Hao042e8982016-10-19 11:17:11 -0700295 size_t dex_file_last_slash = dex_file.rfind("/");
Jeff Haoa8621002016-10-04 18:13:44 +0000296 std::string dex_file_name = dex_file.substr(dex_file_last_slash + 1);
297 std::vector<std::string> unzip_exec_argv =
298 { "/usr/bin/unzip", dex_file, "classes.dex", "-d", tmp_dir};
299 if (!::art::Exec(unzip_exec_argv, error_msg)) {
300 return false;
301 }
302 std::vector<std::string> diff_exec_argv =
303 { "/usr/bin/diff", tmp_dir + "classes.dex" , tmp_dir + dex_file_name };
304 if (!::art::Exec(diff_exec_argv, error_msg)) {
305 return false;
306 }
307 std::vector<std::string> rm_zip_exec_argv = { "/bin/rm", tmp_dir + "classes.dex" };
308 if (!::art::Exec(rm_zip_exec_argv, error_msg)) {
309 return false;
310 }
311 std::vector<std::string> rm_out_exec_argv = { "/bin/rm", tmp_dir + dex_file_name };
312 if (!::art::Exec(rm_out_exec_argv, error_msg)) {
313 return false;
314 }
315 }
Jeff Hao042e8982016-10-19 11:17:11 -0700316 return true;
317 }
Jeff Haoa8621002016-10-04 18:13:44 +0000318
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700319 // Create a profile with some subset of methods and classes.
320 void CreateProfile(const std::string& input_dex,
321 const std::string& out_profile,
322 const std::string& dex_location) {
323 std::vector<std::unique_ptr<const DexFile>> dex_files;
324 std::string error_msg;
325 bool result = DexFile::Open(input_dex.c_str(),
326 input_dex,
327 false,
328 &error_msg,
329 &dex_files);
330
331 ASSERT_TRUE(result) << error_msg;
332 ASSERT_GE(dex_files.size(), 1u);
333
334 size_t profile_methods = 0;
335 size_t profile_classes = 0;
336 ProfileCompilationInfo pfi;
337 std::vector<ProfileMethodInfo> pmis;
338 std::set<DexCacheResolvedClasses> classes;
339 for (const std::unique_ptr<const DexFile>& dex_file : dex_files) {
340 for (uint32_t i = 0; i < dex_file->NumMethodIds(); i += 2) {
341 if ((i & 3) != 0) {
342 pfi.AddMethodIndex(dex_location,
343 dex_file->GetLocationChecksum(),
Mathieu Chartierea650f32017-05-24 12:04:13 -0700344 i,
345 dex_file->NumMethodIds());
346 ++profile_methods;
347 } else if ((i & 2) != 0) {
348 pfi.AddSampledMethod(/*startup*/true,
349 dex_location,
350 dex_file->GetLocationChecksum(),
351 i,
352 dex_file->NumMethodIds());
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700353 ++profile_methods;
354 }
355 }
356 DexCacheResolvedClasses cur_classes(dex_location,
357 dex_location,
Mathieu Chartierea650f32017-05-24 12:04:13 -0700358 dex_file->GetLocationChecksum(),
359 dex_file->NumMethodIds());
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700360 // Add every even class too.
361 for (uint32_t i = 0; i < dex_file->NumClassDefs(); i += 1) {
Mathieu Chartierea650f32017-05-24 12:04:13 -0700362 if ((i & 2) == 0) {
363 cur_classes.AddClass(dex_file->GetClassDef(i).class_idx_);
364 ++profile_classes;
365 }
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700366 }
Mathieu Chartierea650f32017-05-24 12:04:13 -0700367 classes.insert(cur_classes);
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700368 }
369 pfi.AddMethodsAndClasses(pmis, classes);
370 // Write to provided file.
371 std::unique_ptr<File> file(OS::CreateEmptyFile(out_profile.c_str()));
372 ASSERT_TRUE(file != nullptr);
373 pfi.Save(file->Fd());
374 if (file->FlushCloseOrErase() != 0) {
375 PLOG(FATAL) << "Could not flush and close test file.";
376 }
377 EXPECT_GE(profile_methods, 0u);
378 EXPECT_GE(profile_classes, 0u);
379 }
380
Jeff Haod9be7682017-04-05 09:29:43 -0700381 // Runs DexFileLayout test.
Jeff Hao042e8982016-10-19 11:17:11 -0700382 bool DexFileLayoutExec(std::string* error_msg) {
383 ScratchFile tmp_file;
384 std::string tmp_name = tmp_file.GetFilename();
385 size_t tmp_last_slash = tmp_name.rfind("/");
386 std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1);
387
388 // Write inputs and expected outputs.
389 std::string dex_file = tmp_dir + "classes.dex";
390 WriteFileBase64(kDexFileLayoutInputDex, dex_file.c_str());
391 std::string profile_file = tmp_dir + "primary.prof";
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700392 CreateProfile(dex_file, profile_file, dex_file);
393 // WriteFileBase64(kDexFileLayoutInputProfile, profile_file.c_str());
Jeff Hao042e8982016-10-19 11:17:11 -0700394 std::string output_dex = tmp_dir + "classes.dex.new";
395
396 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
397 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
398
399 std::vector<std::string> dexlayout_exec_argv =
Mathieu Chartierfa0aa092017-03-27 15:43:54 -0700400 { dexlayout, "-v", "-w", tmp_dir, "-o", tmp_name, "-p", profile_file, dex_file };
Jeff Hao042e8982016-10-19 11:17:11 -0700401 if (!::art::Exec(dexlayout_exec_argv, error_msg)) {
402 return false;
403 }
Mathieu Chartierfa0aa092017-03-27 15:43:54 -0700404
405 // -v makes sure that the layout did not corrupt the dex file.
Jeff Hao042e8982016-10-19 11:17:11 -0700406
407 std::vector<std::string> rm_exec_argv =
Mathieu Chartierfa0aa092017-03-27 15:43:54 -0700408 { "/bin/rm", dex_file, profile_file, output_dex };
Jeff Hao042e8982016-10-19 11:17:11 -0700409 if (!::art::Exec(rm_exec_argv, error_msg)) {
410 return false;
411 }
Jeff Haoa8621002016-10-04 18:13:44 +0000412 return true;
413 }
Jeff Hao44652a32017-02-22 14:20:41 -0800414
Bharadwaj Kalandhabhatta02ef6402017-05-17 17:13:39 -0700415 // Runs DexFileLayout test twice (second time is run on output of first time)
416 // for behavior consistency.
417 bool DexFileLayoutFixedPointExec(std::string* error_msg) {
418 ScratchFile tmp_file;
419 std::string tmp_name = tmp_file.GetFilename();
420 size_t tmp_last_slash = tmp_name.rfind("/");
421 std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1);
422
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700423 // Unzip the test dex file to the classes.dex destination. It is required to unzip since
424 // opening from jar recalculates the dex location checksum.
Bharadwaj Kalandhabhatta02ef6402017-05-17 17:13:39 -0700425 std::string dex_file = tmp_dir + "classes.dex";
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700426
427 std::vector<std::string> unzip_args = {
428 "/usr/bin/unzip",
429 GetTestDexFileName("ManyMethods"),
430 "classes.dex",
431 "-d",
432 tmp_dir,
433 };
434 if (!art::Exec(unzip_args, error_msg)) {
435 LOG(ERROR) << "Failed to unzip dex";
436 return false;
437 }
438
Bharadwaj Kalandhabhatta02ef6402017-05-17 17:13:39 -0700439 std::string profile_file = tmp_dir + "primary.prof";
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700440 CreateProfile(dex_file, profile_file, dex_file);
Bharadwaj Kalandhabhatta02ef6402017-05-17 17:13:39 -0700441 std::string output_dex = tmp_dir + "classes.dex.new";
442 std::string second_output_dex = tmp_dir + "classes.dex.new.new";
443
444 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
445 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
446
447 // -v makes sure that the layout did not corrupt the dex file.
448 std::vector<std::string> dexlayout_exec_argv =
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700449 { dexlayout, "-i", "-v", "-w", tmp_dir, "-o", tmp_name, "-p", profile_file, dex_file };
Bharadwaj Kalandhabhatta02ef6402017-05-17 17:13:39 -0700450 if (!::art::Exec(dexlayout_exec_argv, error_msg)) {
451 return false;
452 }
453
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700454 // Recreate the profile with the new dex location. This is required so that the profile dex
455 // location matches.
456 CreateProfile(dex_file, profile_file, output_dex);
457
Bharadwaj Kalandhabhatta02ef6402017-05-17 17:13:39 -0700458 // -v makes sure that the layout did not corrupt the dex file.
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700459 // -i since the checksum won't match from the first layout.
Bharadwaj Kalandhabhatta02ef6402017-05-17 17:13:39 -0700460 std::vector<std::string> second_dexlayout_exec_argv =
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700461 { dexlayout, "-i", "-v", "-w", tmp_dir, "-o", tmp_name, "-p", profile_file, output_dex };
Bharadwaj Kalandhabhatta02ef6402017-05-17 17:13:39 -0700462 if (!::art::Exec(second_dexlayout_exec_argv, error_msg)) {
463 return false;
464 }
465
466 bool diff_result = true;
467 std::vector<std::string> diff_exec_argv =
468 { "/usr/bin/diff", output_dex, second_output_dex };
469 if (!::art::Exec(diff_exec_argv, error_msg)) {
470 diff_result = false;
471 }
472
473 std::vector<std::string> rm_exec_argv =
474 { "/bin/rm", dex_file, profile_file, output_dex, second_output_dex };
475 if (!::art::Exec(rm_exec_argv, error_msg)) {
476 return false;
477 }
478
479 return diff_result;
480 }
481
Jeff Haoac462712017-03-02 10:59:43 -0800482 // Runs UnreferencedCatchHandlerTest & Unreferenced0SizeCatchHandlerTest.
483 bool UnreferencedCatchHandlerExec(std::string* error_msg, const char* filename) {
Jeff Hao44652a32017-02-22 14:20:41 -0800484 ScratchFile tmp_file;
485 std::string tmp_name = tmp_file.GetFilename();
486 size_t tmp_last_slash = tmp_name.rfind("/");
487 std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1);
488
489 // Write inputs and expected outputs.
490 std::string input_dex = tmp_dir + "classes.dex";
Jeff Haoac462712017-03-02 10:59:43 -0800491 WriteFileBase64(filename, input_dex.c_str());
Jeff Hao44652a32017-02-22 14:20:41 -0800492 std::string output_dex = tmp_dir + "classes.dex.new";
493
494 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
495 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
496
497 std::vector<std::string> dexlayout_exec_argv =
498 { dexlayout, "-w", tmp_dir, "-o", "/dev/null", input_dex };
499 if (!::art::Exec(dexlayout_exec_argv, error_msg)) {
500 return false;
501 }
502
503 // Diff input and output. They should be the same.
504 std::vector<std::string> diff_exec_argv = { "/usr/bin/diff", input_dex, output_dex };
505 if (!::art::Exec(diff_exec_argv, error_msg)) {
506 return false;
507 }
508
509 std::vector<std::string> rm_exec_argv = { "/bin/rm", input_dex, output_dex };
510 if (!::art::Exec(rm_exec_argv, error_msg)) {
511 return false;
512 }
513 return true;
514 }
Jeff Haod9be7682017-04-05 09:29:43 -0700515
516 bool DexLayoutExec(ScratchFile* dex_file,
517 const char* dex_filename,
518 ScratchFile* profile_file,
Jeff Haod9be7682017-04-05 09:29:43 -0700519 std::vector<std::string>& dexlayout_exec_argv) {
520 WriteBase64ToFile(dex_filename, dex_file->GetFile());
521 EXPECT_EQ(dex_file->GetFile()->Flush(), 0);
522 if (profile_file != nullptr) {
Mathieu Chartierd00e02b2017-05-24 12:04:13 -0700523 CreateProfile(dex_file->GetFilename(), profile_file->GetFilename(), dex_file->GetFilename());
Jeff Haod9be7682017-04-05 09:29:43 -0700524 }
525 std::string error_msg;
526 const bool result = ::art::Exec(dexlayout_exec_argv, &error_msg);
527 if (!result) {
528 LOG(ERROR) << "Error: " << error_msg;
529 return false;
530 }
531 return true;
532 }
Jeff Haoc3acfc52016-08-29 14:18:26 -0700533};
534
535
536TEST_F(DexLayoutTest, FullPlainOutput) {
Jeff Hao0f7eaeb2016-08-31 17:56:13 -0700537 // Disable test on target.
538 TEST_DISABLED_FOR_TARGET();
Jeff Haoc3acfc52016-08-29 14:18:26 -0700539 std::string error_msg;
Jeff Haoa8621002016-10-04 18:13:44 +0000540 ASSERT_TRUE(FullPlainOutputExec(&error_msg)) << error_msg;
541}
542
543TEST_F(DexLayoutTest, DexFileOutput) {
544 // Disable test on target.
545 TEST_DISABLED_FOR_TARGET();
546 std::string error_msg;
547 ASSERT_TRUE(DexFileOutputExec(&error_msg)) << error_msg;
Jeff Haoc3acfc52016-08-29 14:18:26 -0700548}
549
Jeff Hao042e8982016-10-19 11:17:11 -0700550TEST_F(DexLayoutTest, DexFileLayout) {
551 // Disable test on target.
552 TEST_DISABLED_FOR_TARGET();
553 std::string error_msg;
554 ASSERT_TRUE(DexFileLayoutExec(&error_msg)) << error_msg;
555}
556
Bharadwaj Kalandhabhatta02ef6402017-05-17 17:13:39 -0700557TEST_F(DexLayoutTest, DexFileLayoutFixedPoint) {
558 // Disable test on target.
559 TEST_DISABLED_FOR_TARGET();
560 std::string error_msg;
561 ASSERT_TRUE(DexFileLayoutFixedPointExec(&error_msg)) << error_msg;
562}
563
Jeff Haoe17f5892017-02-23 16:14:04 -0800564TEST_F(DexLayoutTest, UnreferencedCatchHandler) {
565 // Disable test on target.
566 TEST_DISABLED_FOR_TARGET();
567 std::string error_msg;
Jeff Haoac462712017-03-02 10:59:43 -0800568 ASSERT_TRUE(UnreferencedCatchHandlerExec(&error_msg,
569 kUnreferencedCatchHandlerInputDex)) << error_msg;
Jeff Haoe17f5892017-02-23 16:14:04 -0800570}
Jeff Haoac462712017-03-02 10:59:43 -0800571
572TEST_F(DexLayoutTest, Unreferenced0SizeCatchHandler) {
573 // Disable test on target.
574 TEST_DISABLED_FOR_TARGET();
575 std::string error_msg;
576 ASSERT_TRUE(UnreferencedCatchHandlerExec(&error_msg,
577 kUnreferenced0SizeCatchHandlerInputDex)) << error_msg;
578}
579
Jeff Haoa64a64c2017-03-06 15:05:38 -0800580TEST_F(DexLayoutTest, UnreferencedEndingCatchHandler) {
581 // Disable test on target.
582 TEST_DISABLED_FOR_TARGET();
583 std::string error_msg;
584 ASSERT_TRUE(UnreferencedCatchHandlerExec(&error_msg,
585 kUnreferencedEndingCatchHandlerInputDex)) << error_msg;
586}
587
Mathieu Chartier6b0dbef2017-02-21 12:45:30 -0800588TEST_F(DexLayoutTest, DuplicateOffset) {
Jeff Haod9be7682017-04-05 09:29:43 -0700589 ScratchFile temp_dex;
Mathieu Chartier6b0dbef2017-02-21 12:45:30 -0800590 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
591 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
Jeff Haod9be7682017-04-05 09:29:43 -0700592 std::vector<std::string> dexlayout_exec_argv =
593 { dexlayout, "-a", "-i", "-o", "/dev/null", temp_dex.GetFilename() };
594 ASSERT_TRUE(DexLayoutExec(&temp_dex,
595 kDexFileDuplicateOffset,
596 nullptr /* profile_file */,
Jeff Haod9be7682017-04-05 09:29:43 -0700597 dexlayout_exec_argv));
Mathieu Chartier6b0dbef2017-02-21 12:45:30 -0800598}
599
Jeff Haof914f8e2017-02-21 16:14:23 -0800600TEST_F(DexLayoutTest, NullSetRefListElement) {
Jeff Haod9be7682017-04-05 09:29:43 -0700601 ScratchFile temp_dex;
Jeff Haof914f8e2017-02-21 16:14:23 -0800602 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
603 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
604 std::vector<std::string> dexlayout_exec_argv =
Jeff Haod9be7682017-04-05 09:29:43 -0700605 { dexlayout, "-o", "/dev/null", temp_dex.GetFilename() };
606 ASSERT_TRUE(DexLayoutExec(&temp_dex,
607 kNullSetRefListElementInputDex,
608 nullptr /* profile_file */,
Jeff Haod9be7682017-04-05 09:29:43 -0700609 dexlayout_exec_argv));
Jeff Haof914f8e2017-02-21 16:14:23 -0800610}
611
Jeff Haoe17f5892017-02-23 16:14:04 -0800612TEST_F(DexLayoutTest, MultiClassData) {
Jeff Haod9be7682017-04-05 09:29:43 -0700613 ScratchFile temp_dex;
614 ScratchFile temp_profile;
Jeff Haoe17f5892017-02-23 16:14:04 -0800615 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
616 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
617 std::vector<std::string> dexlayout_exec_argv =
Jeff Haod9be7682017-04-05 09:29:43 -0700618 { dexlayout, "-p", temp_profile.GetFilename(), "-o", "/dev/null", temp_dex.GetFilename() };
619 ASSERT_TRUE(DexLayoutExec(&temp_dex,
620 kMultiClassDataInputDex,
621 &temp_profile,
Jeff Haod9be7682017-04-05 09:29:43 -0700622 dexlayout_exec_argv));
Jeff Haoe17f5892017-02-23 16:14:04 -0800623}
624
625TEST_F(DexLayoutTest, UnalignedCodeInfo) {
Jeff Haod9be7682017-04-05 09:29:43 -0700626 ScratchFile temp_dex;
627 ScratchFile temp_profile;
Jeff Haoe17f5892017-02-23 16:14:04 -0800628 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
629 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
630 std::vector<std::string> dexlayout_exec_argv =
Jeff Haod9be7682017-04-05 09:29:43 -0700631 { dexlayout, "-p", temp_profile.GetFilename(), "-o", "/dev/null", temp_dex.GetFilename() };
632 ASSERT_TRUE(DexLayoutExec(&temp_dex,
633 kUnalignedCodeInfoInputDex,
634 &temp_profile,
Jeff Haod9be7682017-04-05 09:29:43 -0700635 dexlayout_exec_argv));
Jeff Hao44652a32017-02-22 14:20:41 -0800636}
637
Jeff Hao32a60ab2017-03-01 16:44:50 -0800638TEST_F(DexLayoutTest, ClassDataBeforeCode) {
Jeff Haod9be7682017-04-05 09:29:43 -0700639 ScratchFile temp_dex;
640 ScratchFile temp_profile;
Jeff Hao32a60ab2017-03-01 16:44:50 -0800641 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
642 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
643 std::vector<std::string> dexlayout_exec_argv =
Jeff Haod9be7682017-04-05 09:29:43 -0700644 { dexlayout, "-p", temp_profile.GetFilename(), "-o", "/dev/null", temp_dex.GetFilename() };
645 ASSERT_TRUE(DexLayoutExec(&temp_dex,
646 kClassDataBeforeCodeInputDex,
647 &temp_profile,
Jeff Haod9be7682017-04-05 09:29:43 -0700648 dexlayout_exec_argv));
649}
650
651TEST_F(DexLayoutTest, UnknownTypeDebugInfo) {
652 ScratchFile temp_dex;
653 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
654 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
655 std::vector<std::string> dexlayout_exec_argv =
656 { dexlayout, "-o", "/dev/null", temp_dex.GetFilename() };
657 ASSERT_TRUE(DexLayoutExec(&temp_dex,
658 kUnknownTypeDebugInfoInputDex,
659 nullptr /* profile_file */,
Jeff Haod9be7682017-04-05 09:29:43 -0700660 dexlayout_exec_argv));
Jeff Hao32a60ab2017-03-01 16:44:50 -0800661}
662
Jeff Haod212d5b2017-04-26 12:09:06 -0700663TEST_F(DexLayoutTest, DuplicateCodeItem) {
664 ScratchFile temp_dex;
665 std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout";
666 EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path";
667 std::vector<std::string> dexlayout_exec_argv =
668 { dexlayout, "-o", "/dev/null", temp_dex.GetFilename() };
669 ASSERT_TRUE(DexLayoutExec(&temp_dex,
670 kDuplicateCodeItemInputDex,
671 nullptr /* profile_file */,
Jeff Haod212d5b2017-04-26 12:09:06 -0700672 dexlayout_exec_argv));
673}
674
Jeff Haoc3acfc52016-08-29 14:18:26 -0700675} // namespace art