Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 1 | /* |
| 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 Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 24 | #include "base/unix_file/fd_file.h" |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 25 | #include "common_runtime_test.h" |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 26 | #include "dex_file-inl.h" |
David Sehr | 97c381e | 2017-02-01 15:09:58 -0800 | [diff] [blame] | 27 | #include "exec_utils.h" |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 28 | #include "jit/profile_compilation_info.h" |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 29 | #include "utils.h" |
| 30 | |
| 31 | namespace art { |
| 32 | |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 33 | static 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 Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 45 | // Dex file with catch handler unreferenced by try blocks. |
| 46 | // Constructed by building a dex file with try/catch blocks and hex editing. |
| 47 | static 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 Hao | ac46271 | 2017-03-02 10:59:43 -0800 | [diff] [blame] | 65 | // 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. |
| 67 | static 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 Hao | a64a64c | 2017-03-06 15:05:38 -0800 | [diff] [blame] | 85 | // 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. |
| 87 | static 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 Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 108 | // Dex file with multiple code items that have the same debug_info_off_. Constructed by a modified |
| 109 | // dexlayout on XandY. |
| 110 | static 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 Hao | f914f8e | 2017-02-21 16:14:23 -0800 | [diff] [blame] | 131 | // 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. |
| 133 | static 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 Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 153 | // 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. |
| 155 | static 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. |
| 167 | static const char kUnalignedCodeInfoInputDex[] = |
| 168 | "ZGV4CjAzNQDXJzXNb4iWn2SLhmLydW/8h1K9moERIw7UAQAAcAAAAHhWNBIAAAAAAAAAAEwBAAAG" |
| 169 | "AAAAcAAAAAMAAACIAAAAAQAAAJQAAAAAAAAAAAAAAAMAAACgAAAAAQAAALgAAAD8AAAA2AAAAAIB" |
| 170 | "AAAKAQAAEgEAABcBAAArAQAALgEAAAIAAAADAAAABAAAAAQAAAACAAAAAAAAAAAAAAAAAAAAAAAA" |
| 171 | "AAUAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAABAAAAAAAAADsBAAAAAAAAAQABAAEAAAAxAQAA" |
| 172 | "BAAAAHAQAgAAAA4AAQABAAAAAAA2AQAAAQAAAA4ABjxpbml0PgAGQS5qYXZhAANMQTsAEkxqYXZh" |
| 173 | "L2xhbmcvT2JqZWN0OwABVgABYQABAAcOAAMABw4AAAABAQCBgATYAQEB8AEAAAALAAAAAAAAAAEA" |
| 174 | "AAAAAAAAAQAAAAYAAABwAAAAAgAAAAMAAACIAAAAAwAAAAEAAACUAAAABQAAAAMAAACgAAAABgAA" |
| 175 | "AAEAAAC4AAAAASAAAAIAAADYAAAAAiAAAAYAAAACAQAAAyAAAAIAAAAxAQAAACAAAAEAAAA7AQAA" |
| 176 | "ABAAAAEAAABMAQAA"; |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 177 | |
Jeff Hao | 32a60ab | 2017-03-01 16:44:50 -0800 | [diff] [blame] | 178 | // Dex file with class data section preceding code items. |
| 179 | // Constructed by passing dex file through dexmerger tool and hex editing. |
| 180 | static 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 Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 193 | // 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. |
| 196 | static 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 Hao | d212d5b | 2017-04-26 12:09:06 -0700 | [diff] [blame] | 207 | // Dex file with multiple class data items pointing to the same code item. |
| 208 | // Constructed by hex editing. |
| 209 | static const char kDuplicateCodeItemInputDex[] = |
| 210 | "ZGV4CjAzNQCwKtVglQOmLWuHwldN5jkBOInC7mTMhJMAAgAAcAAAAHhWNBIAAAAAAAAAAHgBAAAH" |
| 211 | "AAAAcAAAAAMAAACMAAAAAQAAAJgAAAAAAAAAAAAAAAQAAACkAAAAAQAAAMQAAAAcAQAA5AAAACQB" |
| 212 | "AAAsAQAANAEAADkBAABNAQAAUAEAAFMBAAACAAAAAwAAAAQAAAAEAAAAAgAAAAAAAAAAAAAAAAAA" |
| 213 | "AAAAAAAFAAAAAAAAAAYAAAABAAAAAAAAAAAAAAABAAAAAQAAAAAAAAABAAAAAAAAAGUBAAAAAAAA" |
| 214 | "AQABAAEAAABWAQAABAAAAHAQAwAAAA4AAQABAAAAAABbAQAAAQAAAA4AAAABAAEAAAAAAGABAAAB" |
| 215 | "AAAADgAAAAY8aW5pdD4ABkEuamF2YQADTEE7ABJMamF2YS9sYW5nL09iamVjdDsAAVYAAWEAAWIA" |
| 216 | "AQAHDgADAAcOAAUABw4AAAABAgCBgATkAQEA/AEBAPwBAAsAAAAAAAAAAQAAAAAAAAABAAAABwAA" |
| 217 | "AHAAAAACAAAAAwAAAIwAAAADAAAAAQAAAJgAAAAFAAAABAAAAKQAAAAGAAAAAQAAAMQAAAABIAAA" |
| 218 | "AwAAAOQAAAACIAAABwAAACQBAAADIAAAAwAAAFYBAAAAIAAAAQAAAGUBAAAAEAAAAQAAAHgBAAA="; |
| 219 | |
Mathieu Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 220 | static void WriteBase64ToFile(const char* base64, File* file) { |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 221 | // Decode base64. |
| 222 | CHECK(base64 != nullptr); |
| 223 | size_t length; |
| 224 | std::unique_ptr<uint8_t[]> bytes(DecodeBase64(base64, &length)); |
Mathieu Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 225 | CHECK(bytes != nullptr); |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 226 | if (!file->WriteFully(bytes.get(), length)) { |
| 227 | PLOG(FATAL) << "Failed to write base64 as file"; |
| 228 | } |
Mathieu Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 229 | } |
| 230 | |
| 231 | static 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 Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 236 | if (file->FlushCloseOrErase() != 0) { |
| 237 | PLOG(FATAL) << "Could not flush and close test file."; |
| 238 | } |
| 239 | } |
| 240 | |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 241 | class DexLayoutTest : public CommonRuntimeTest { |
| 242 | protected: |
| 243 | virtual void SetUp() { |
| 244 | CommonRuntimeTest::SetUp(); |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 247 | // Runs FullPlainOutput test. |
| 248 | bool FullPlainOutputExec(std::string* error_msg) { |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 249 | // TODO: dexdump2 -> dexdump ? |
| 250 | ScratchFile dexdump_output; |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 251 | const std::string& dexdump_filename = dexdump_output.GetFilename(); |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 252 | std::string dexdump = GetTestAndroidRoot() + "/bin/dexdump2"; |
| 253 | EXPECT_TRUE(OS::FileExists(dexdump.c_str())) << dexdump << " should be a valid file path"; |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 254 | |
| 255 | ScratchFile dexlayout_output; |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 256 | const std::string& dexlayout_filename = dexlayout_output.GetFilename(); |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 257 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 258 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 259 | |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 260 | 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 Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 265 | 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 Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 276 | } |
| 277 | return true; |
| 278 | } |
| 279 | |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 280 | // Runs DexFileOutput test. |
| 281 | bool DexFileOutputExec(std::string* error_msg) { |
| 282 | ScratchFile tmp_file; |
Andreas Gampe | ca620d7 | 2016-11-08 08:09:33 -0800 | [diff] [blame] | 283 | const std::string& tmp_name = tmp_file.GetFilename(); |
| 284 | size_t tmp_last_slash = tmp_name.rfind('/'); |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 285 | 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 Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 291 | { dexlayout, "-w", tmp_dir, "-o", tmp_name, dex_file }; |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 292 | if (!::art::Exec(dexlayout_exec_argv, error_msg)) { |
| 293 | return false; |
| 294 | } |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 295 | size_t dex_file_last_slash = dex_file.rfind("/"); |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 296 | 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 Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 316 | return true; |
| 317 | } |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 318 | |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 319 | // 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 Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame^] | 344 | 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 Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 353 | ++profile_methods; |
| 354 | } |
| 355 | } |
| 356 | DexCacheResolvedClasses cur_classes(dex_location, |
| 357 | dex_location, |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame^] | 358 | dex_file->GetLocationChecksum(), |
| 359 | dex_file->NumMethodIds()); |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 360 | // Add every even class too. |
| 361 | for (uint32_t i = 0; i < dex_file->NumClassDefs(); i += 1) { |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame^] | 362 | if ((i & 2) == 0) { |
| 363 | cur_classes.AddClass(dex_file->GetClassDef(i).class_idx_); |
| 364 | ++profile_classes; |
| 365 | } |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 366 | } |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame^] | 367 | classes.insert(cur_classes); |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 368 | } |
| 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 Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 381 | // Runs DexFileLayout test. |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 382 | 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 Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 392 | CreateProfile(dex_file, profile_file, dex_file); |
| 393 | // WriteFileBase64(kDexFileLayoutInputProfile, profile_file.c_str()); |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 394 | 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 Chartier | fa0aa09 | 2017-03-27 15:43:54 -0700 | [diff] [blame] | 400 | { dexlayout, "-v", "-w", tmp_dir, "-o", tmp_name, "-p", profile_file, dex_file }; |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 401 | if (!::art::Exec(dexlayout_exec_argv, error_msg)) { |
| 402 | return false; |
| 403 | } |
Mathieu Chartier | fa0aa09 | 2017-03-27 15:43:54 -0700 | [diff] [blame] | 404 | |
| 405 | // -v makes sure that the layout did not corrupt the dex file. |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 406 | |
| 407 | std::vector<std::string> rm_exec_argv = |
Mathieu Chartier | fa0aa09 | 2017-03-27 15:43:54 -0700 | [diff] [blame] | 408 | { "/bin/rm", dex_file, profile_file, output_dex }; |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 409 | if (!::art::Exec(rm_exec_argv, error_msg)) { |
| 410 | return false; |
| 411 | } |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 412 | return true; |
| 413 | } |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 414 | |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 415 | // 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 Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 423 | // 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 Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 425 | std::string dex_file = tmp_dir + "classes.dex"; |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 426 | |
| 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 Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 439 | std::string profile_file = tmp_dir + "primary.prof"; |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 440 | CreateProfile(dex_file, profile_file, dex_file); |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 441 | 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 Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 449 | { dexlayout, "-i", "-v", "-w", tmp_dir, "-o", tmp_name, "-p", profile_file, dex_file }; |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 450 | if (!::art::Exec(dexlayout_exec_argv, error_msg)) { |
| 451 | return false; |
| 452 | } |
| 453 | |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 454 | // 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 Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 458 | // -v makes sure that the layout did not corrupt the dex file. |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 459 | // -i since the checksum won't match from the first layout. |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 460 | std::vector<std::string> second_dexlayout_exec_argv = |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 461 | { dexlayout, "-i", "-v", "-w", tmp_dir, "-o", tmp_name, "-p", profile_file, output_dex }; |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 462 | 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 Hao | ac46271 | 2017-03-02 10:59:43 -0800 | [diff] [blame] | 482 | // Runs UnreferencedCatchHandlerTest & Unreferenced0SizeCatchHandlerTest. |
| 483 | bool UnreferencedCatchHandlerExec(std::string* error_msg, const char* filename) { |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 484 | 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 Hao | ac46271 | 2017-03-02 10:59:43 -0800 | [diff] [blame] | 491 | WriteFileBase64(filename, input_dex.c_str()); |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 492 | 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 Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 515 | |
| 516 | bool DexLayoutExec(ScratchFile* dex_file, |
| 517 | const char* dex_filename, |
| 518 | ScratchFile* profile_file, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 519 | 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 Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 523 | CreateProfile(dex_file->GetFilename(), profile_file->GetFilename(), dex_file->GetFilename()); |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 524 | } |
| 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 Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 533 | }; |
| 534 | |
| 535 | |
| 536 | TEST_F(DexLayoutTest, FullPlainOutput) { |
Jeff Hao | 0f7eaeb | 2016-08-31 17:56:13 -0700 | [diff] [blame] | 537 | // Disable test on target. |
| 538 | TEST_DISABLED_FOR_TARGET(); |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 539 | std::string error_msg; |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 540 | ASSERT_TRUE(FullPlainOutputExec(&error_msg)) << error_msg; |
| 541 | } |
| 542 | |
| 543 | TEST_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 Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 548 | } |
| 549 | |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 550 | TEST_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 Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 557 | TEST_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 Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 564 | TEST_F(DexLayoutTest, UnreferencedCatchHandler) { |
| 565 | // Disable test on target. |
| 566 | TEST_DISABLED_FOR_TARGET(); |
| 567 | std::string error_msg; |
Jeff Hao | ac46271 | 2017-03-02 10:59:43 -0800 | [diff] [blame] | 568 | ASSERT_TRUE(UnreferencedCatchHandlerExec(&error_msg, |
| 569 | kUnreferencedCatchHandlerInputDex)) << error_msg; |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 570 | } |
Jeff Hao | ac46271 | 2017-03-02 10:59:43 -0800 | [diff] [blame] | 571 | |
| 572 | TEST_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 Hao | a64a64c | 2017-03-06 15:05:38 -0800 | [diff] [blame] | 580 | TEST_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 Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 588 | TEST_F(DexLayoutTest, DuplicateOffset) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 589 | ScratchFile temp_dex; |
Mathieu Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 590 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 591 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 592 | 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 Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 597 | dexlayout_exec_argv)); |
Mathieu Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 598 | } |
| 599 | |
Jeff Hao | f914f8e | 2017-02-21 16:14:23 -0800 | [diff] [blame] | 600 | TEST_F(DexLayoutTest, NullSetRefListElement) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 601 | ScratchFile temp_dex; |
Jeff Hao | f914f8e | 2017-02-21 16:14:23 -0800 | [diff] [blame] | 602 | 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 Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 605 | { dexlayout, "-o", "/dev/null", temp_dex.GetFilename() }; |
| 606 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 607 | kNullSetRefListElementInputDex, |
| 608 | nullptr /* profile_file */, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 609 | dexlayout_exec_argv)); |
Jeff Hao | f914f8e | 2017-02-21 16:14:23 -0800 | [diff] [blame] | 610 | } |
| 611 | |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 612 | TEST_F(DexLayoutTest, MultiClassData) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 613 | ScratchFile temp_dex; |
| 614 | ScratchFile temp_profile; |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 615 | 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 Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 618 | { dexlayout, "-p", temp_profile.GetFilename(), "-o", "/dev/null", temp_dex.GetFilename() }; |
| 619 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 620 | kMultiClassDataInputDex, |
| 621 | &temp_profile, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 622 | dexlayout_exec_argv)); |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 623 | } |
| 624 | |
| 625 | TEST_F(DexLayoutTest, UnalignedCodeInfo) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 626 | ScratchFile temp_dex; |
| 627 | ScratchFile temp_profile; |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 628 | 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 Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 631 | { dexlayout, "-p", temp_profile.GetFilename(), "-o", "/dev/null", temp_dex.GetFilename() }; |
| 632 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 633 | kUnalignedCodeInfoInputDex, |
| 634 | &temp_profile, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 635 | dexlayout_exec_argv)); |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 636 | } |
| 637 | |
Jeff Hao | 32a60ab | 2017-03-01 16:44:50 -0800 | [diff] [blame] | 638 | TEST_F(DexLayoutTest, ClassDataBeforeCode) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 639 | ScratchFile temp_dex; |
| 640 | ScratchFile temp_profile; |
Jeff Hao | 32a60ab | 2017-03-01 16:44:50 -0800 | [diff] [blame] | 641 | 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 Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 644 | { dexlayout, "-p", temp_profile.GetFilename(), "-o", "/dev/null", temp_dex.GetFilename() }; |
| 645 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 646 | kClassDataBeforeCodeInputDex, |
| 647 | &temp_profile, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 648 | dexlayout_exec_argv)); |
| 649 | } |
| 650 | |
| 651 | TEST_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 Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 660 | dexlayout_exec_argv)); |
Jeff Hao | 32a60ab | 2017-03-01 16:44:50 -0800 | [diff] [blame] | 661 | } |
| 662 | |
Jeff Hao | d212d5b | 2017-04-26 12:09:06 -0700 | [diff] [blame] | 663 | TEST_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 Hao | d212d5b | 2017-04-26 12:09:06 -0700 | [diff] [blame] | 672 | dexlayout_exec_argv)); |
| 673 | } |
| 674 | |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 675 | } // namespace art |