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 | |
Andreas Gampe | 8cf9cb3 | 2017-07-19 09:28:38 -0700 | [diff] [blame] | 17 | #include <sstream> |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 18 | #include <string> |
| 19 | #include <vector> |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 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 | } |
Andreas Gampe | 5555dd1 | 2017-08-24 13:50:21 -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; |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 337 | std::set<DexCacheResolvedClasses> classes; |
| 338 | for (const std::unique_ptr<const DexFile>& dex_file : dex_files) { |
| 339 | for (uint32_t i = 0; i < dex_file->NumMethodIds(); i += 2) { |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 340 | uint8_t flags = 0u; |
| 341 | |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 342 | if ((i & 3) != 0) { |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 343 | flags |= ProfileCompilationInfo::MethodHotness::kFlagHot; |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 344 | ++profile_methods; |
| 345 | } else if ((i & 2) != 0) { |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 346 | flags |= ProfileCompilationInfo::MethodHotness::kFlagStartup; |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 347 | ++profile_methods; |
| 348 | } |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 349 | pfi.AddMethodIndex(static_cast<ProfileCompilationInfo::MethodHotness::Flag>(flags), |
| 350 | dex_location, |
| 351 | dex_file->GetLocationChecksum(), |
| 352 | /*dex_method_idx*/i, |
| 353 | dex_file->NumMethodIds()); |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 354 | } |
| 355 | DexCacheResolvedClasses cur_classes(dex_location, |
| 356 | dex_location, |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 357 | dex_file->GetLocationChecksum(), |
| 358 | dex_file->NumMethodIds()); |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 359 | // Add every even class too. |
| 360 | for (uint32_t i = 0; i < dex_file->NumClassDefs(); i += 1) { |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 361 | if ((i & 2) == 0) { |
| 362 | cur_classes.AddClass(dex_file->GetClassDef(i).class_idx_); |
| 363 | ++profile_classes; |
| 364 | } |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 365 | } |
Mathieu Chartier | ea650f3 | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 366 | classes.insert(cur_classes); |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 367 | } |
Mathieu Chartier | bbe3a5e | 2017-06-13 16:36:17 -0700 | [diff] [blame] | 368 | pfi.AddClasses(classes); |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 369 | // Write to provided file. |
| 370 | std::unique_ptr<File> file(OS::CreateEmptyFile(out_profile.c_str())); |
| 371 | ASSERT_TRUE(file != nullptr); |
| 372 | pfi.Save(file->Fd()); |
| 373 | if (file->FlushCloseOrErase() != 0) { |
| 374 | PLOG(FATAL) << "Could not flush and close test file."; |
| 375 | } |
| 376 | EXPECT_GE(profile_methods, 0u); |
| 377 | EXPECT_GE(profile_classes, 0u); |
| 378 | } |
| 379 | |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 380 | // Runs DexFileLayout test. |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 381 | bool DexFileLayoutExec(std::string* error_msg) { |
| 382 | ScratchFile tmp_file; |
Andreas Gampe | 641a473 | 2017-08-24 13:21:35 -0700 | [diff] [blame] | 383 | const std::string& tmp_name = tmp_file.GetFilename(); |
Andreas Gampe | 5555dd1 | 2017-08-24 13:50:21 -0700 | [diff] [blame] | 384 | size_t tmp_last_slash = tmp_name.rfind('/'); |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 385 | std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1); |
| 386 | |
| 387 | // Write inputs and expected outputs. |
| 388 | std::string dex_file = tmp_dir + "classes.dex"; |
| 389 | WriteFileBase64(kDexFileLayoutInputDex, dex_file.c_str()); |
| 390 | std::string profile_file = tmp_dir + "primary.prof"; |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 391 | CreateProfile(dex_file, profile_file, dex_file); |
| 392 | // WriteFileBase64(kDexFileLayoutInputProfile, profile_file.c_str()); |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 393 | std::string output_dex = tmp_dir + "classes.dex.new"; |
| 394 | |
| 395 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 396 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 397 | |
| 398 | std::vector<std::string> dexlayout_exec_argv = |
Mathieu Chartier | fa0aa09 | 2017-03-27 15:43:54 -0700 | [diff] [blame] | 399 | { 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] | 400 | if (!::art::Exec(dexlayout_exec_argv, error_msg)) { |
| 401 | return false; |
| 402 | } |
Mathieu Chartier | fa0aa09 | 2017-03-27 15:43:54 -0700 | [diff] [blame] | 403 | |
| 404 | // -v makes sure that the layout did not corrupt the dex file. |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 405 | |
| 406 | std::vector<std::string> rm_exec_argv = |
Mathieu Chartier | fa0aa09 | 2017-03-27 15:43:54 -0700 | [diff] [blame] | 407 | { "/bin/rm", dex_file, profile_file, output_dex }; |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 408 | if (!::art::Exec(rm_exec_argv, error_msg)) { |
| 409 | return false; |
| 410 | } |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 411 | return true; |
| 412 | } |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 413 | |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 414 | // Runs DexFileLayout test twice (second time is run on output of first time) |
| 415 | // for behavior consistency. |
| 416 | bool DexFileLayoutFixedPointExec(std::string* error_msg) { |
| 417 | ScratchFile tmp_file; |
Andreas Gampe | 641a473 | 2017-08-24 13:21:35 -0700 | [diff] [blame] | 418 | const std::string& tmp_name = tmp_file.GetFilename(); |
Andreas Gampe | 5555dd1 | 2017-08-24 13:50:21 -0700 | [diff] [blame] | 419 | size_t tmp_last_slash = tmp_name.rfind('/'); |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 420 | std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1); |
| 421 | |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 422 | // Unzip the test dex file to the classes.dex destination. It is required to unzip since |
| 423 | // opening from jar recalculates the dex location checksum. |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 424 | std::string dex_file = tmp_dir + "classes.dex"; |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 425 | |
| 426 | std::vector<std::string> unzip_args = { |
| 427 | "/usr/bin/unzip", |
| 428 | GetTestDexFileName("ManyMethods"), |
| 429 | "classes.dex", |
| 430 | "-d", |
| 431 | tmp_dir, |
| 432 | }; |
| 433 | if (!art::Exec(unzip_args, error_msg)) { |
| 434 | LOG(ERROR) << "Failed to unzip dex"; |
| 435 | return false; |
| 436 | } |
| 437 | |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 438 | std::string profile_file = tmp_dir + "primary.prof"; |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 439 | CreateProfile(dex_file, profile_file, dex_file); |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 440 | std::string output_dex = tmp_dir + "classes.dex.new"; |
| 441 | std::string second_output_dex = tmp_dir + "classes.dex.new.new"; |
| 442 | |
| 443 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 444 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 445 | |
| 446 | // -v makes sure that the layout did not corrupt the dex file. |
| 447 | std::vector<std::string> dexlayout_exec_argv = |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 448 | { 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] | 449 | if (!::art::Exec(dexlayout_exec_argv, error_msg)) { |
| 450 | return false; |
| 451 | } |
| 452 | |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 453 | // Recreate the profile with the new dex location. This is required so that the profile dex |
| 454 | // location matches. |
| 455 | CreateProfile(dex_file, profile_file, output_dex); |
| 456 | |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 457 | // -v makes sure that the layout did not corrupt the dex file. |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 458 | // -i since the checksum won't match from the first layout. |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 459 | std::vector<std::string> second_dexlayout_exec_argv = |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 460 | { 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] | 461 | if (!::art::Exec(second_dexlayout_exec_argv, error_msg)) { |
| 462 | return false; |
| 463 | } |
| 464 | |
| 465 | bool diff_result = true; |
| 466 | std::vector<std::string> diff_exec_argv = |
| 467 | { "/usr/bin/diff", output_dex, second_output_dex }; |
| 468 | if (!::art::Exec(diff_exec_argv, error_msg)) { |
| 469 | diff_result = false; |
| 470 | } |
| 471 | |
| 472 | std::vector<std::string> rm_exec_argv = |
| 473 | { "/bin/rm", dex_file, profile_file, output_dex, second_output_dex }; |
| 474 | if (!::art::Exec(rm_exec_argv, error_msg)) { |
| 475 | return false; |
| 476 | } |
| 477 | |
| 478 | return diff_result; |
| 479 | } |
| 480 | |
Jeff Hao | ac46271 | 2017-03-02 10:59:43 -0800 | [diff] [blame] | 481 | // Runs UnreferencedCatchHandlerTest & Unreferenced0SizeCatchHandlerTest. |
| 482 | bool UnreferencedCatchHandlerExec(std::string* error_msg, const char* filename) { |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 483 | ScratchFile tmp_file; |
Andreas Gampe | 641a473 | 2017-08-24 13:21:35 -0700 | [diff] [blame] | 484 | const std::string& tmp_name = tmp_file.GetFilename(); |
Andreas Gampe | 5555dd1 | 2017-08-24 13:50:21 -0700 | [diff] [blame] | 485 | size_t tmp_last_slash = tmp_name.rfind('/'); |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 486 | std::string tmp_dir = tmp_name.substr(0, tmp_last_slash + 1); |
| 487 | |
| 488 | // Write inputs and expected outputs. |
| 489 | std::string input_dex = tmp_dir + "classes.dex"; |
Jeff Hao | ac46271 | 2017-03-02 10:59:43 -0800 | [diff] [blame] | 490 | WriteFileBase64(filename, input_dex.c_str()); |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 491 | std::string output_dex = tmp_dir + "classes.dex.new"; |
| 492 | |
| 493 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 494 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 495 | |
| 496 | std::vector<std::string> dexlayout_exec_argv = |
| 497 | { dexlayout, "-w", tmp_dir, "-o", "/dev/null", input_dex }; |
| 498 | if (!::art::Exec(dexlayout_exec_argv, error_msg)) { |
| 499 | return false; |
| 500 | } |
| 501 | |
| 502 | // Diff input and output. They should be the same. |
| 503 | std::vector<std::string> diff_exec_argv = { "/usr/bin/diff", input_dex, output_dex }; |
| 504 | if (!::art::Exec(diff_exec_argv, error_msg)) { |
| 505 | return false; |
| 506 | } |
| 507 | |
| 508 | std::vector<std::string> rm_exec_argv = { "/bin/rm", input_dex, output_dex }; |
| 509 | if (!::art::Exec(rm_exec_argv, error_msg)) { |
| 510 | return false; |
| 511 | } |
| 512 | return true; |
| 513 | } |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 514 | |
| 515 | bool DexLayoutExec(ScratchFile* dex_file, |
| 516 | const char* dex_filename, |
| 517 | ScratchFile* profile_file, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 518 | std::vector<std::string>& dexlayout_exec_argv) { |
| 519 | WriteBase64ToFile(dex_filename, dex_file->GetFile()); |
| 520 | EXPECT_EQ(dex_file->GetFile()->Flush(), 0); |
| 521 | if (profile_file != nullptr) { |
Mathieu Chartier | d00e02b | 2017-05-24 12:04:13 -0700 | [diff] [blame] | 522 | CreateProfile(dex_file->GetFilename(), profile_file->GetFilename(), dex_file->GetFilename()); |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 523 | } |
| 524 | std::string error_msg; |
| 525 | const bool result = ::art::Exec(dexlayout_exec_argv, &error_msg); |
| 526 | if (!result) { |
| 527 | LOG(ERROR) << "Error: " << error_msg; |
| 528 | return false; |
| 529 | } |
| 530 | return true; |
| 531 | } |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 532 | }; |
| 533 | |
| 534 | |
| 535 | TEST_F(DexLayoutTest, FullPlainOutput) { |
Jeff Hao | 0f7eaeb | 2016-08-31 17:56:13 -0700 | [diff] [blame] | 536 | // Disable test on target. |
| 537 | TEST_DISABLED_FOR_TARGET(); |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 538 | std::string error_msg; |
Jeff Hao | a862100 | 2016-10-04 18:13:44 +0000 | [diff] [blame] | 539 | ASSERT_TRUE(FullPlainOutputExec(&error_msg)) << error_msg; |
| 540 | } |
| 541 | |
| 542 | TEST_F(DexLayoutTest, DexFileOutput) { |
| 543 | // Disable test on target. |
| 544 | TEST_DISABLED_FOR_TARGET(); |
| 545 | std::string error_msg; |
| 546 | ASSERT_TRUE(DexFileOutputExec(&error_msg)) << error_msg; |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 547 | } |
| 548 | |
Jeff Hao | 042e898 | 2016-10-19 11:17:11 -0700 | [diff] [blame] | 549 | TEST_F(DexLayoutTest, DexFileLayout) { |
| 550 | // Disable test on target. |
| 551 | TEST_DISABLED_FOR_TARGET(); |
| 552 | std::string error_msg; |
| 553 | ASSERT_TRUE(DexFileLayoutExec(&error_msg)) << error_msg; |
| 554 | } |
| 555 | |
Bharadwaj Kalandhabhatta | 02ef640 | 2017-05-17 17:13:39 -0700 | [diff] [blame] | 556 | TEST_F(DexLayoutTest, DexFileLayoutFixedPoint) { |
| 557 | // Disable test on target. |
| 558 | TEST_DISABLED_FOR_TARGET(); |
| 559 | std::string error_msg; |
| 560 | ASSERT_TRUE(DexFileLayoutFixedPointExec(&error_msg)) << error_msg; |
| 561 | } |
| 562 | |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 563 | TEST_F(DexLayoutTest, UnreferencedCatchHandler) { |
| 564 | // Disable test on target. |
| 565 | TEST_DISABLED_FOR_TARGET(); |
| 566 | std::string error_msg; |
Jeff Hao | ac46271 | 2017-03-02 10:59:43 -0800 | [diff] [blame] | 567 | ASSERT_TRUE(UnreferencedCatchHandlerExec(&error_msg, |
| 568 | kUnreferencedCatchHandlerInputDex)) << error_msg; |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 569 | } |
Jeff Hao | ac46271 | 2017-03-02 10:59:43 -0800 | [diff] [blame] | 570 | |
| 571 | TEST_F(DexLayoutTest, Unreferenced0SizeCatchHandler) { |
| 572 | // Disable test on target. |
| 573 | TEST_DISABLED_FOR_TARGET(); |
| 574 | std::string error_msg; |
| 575 | ASSERT_TRUE(UnreferencedCatchHandlerExec(&error_msg, |
| 576 | kUnreferenced0SizeCatchHandlerInputDex)) << error_msg; |
| 577 | } |
| 578 | |
Jeff Hao | a64a64c | 2017-03-06 15:05:38 -0800 | [diff] [blame] | 579 | TEST_F(DexLayoutTest, UnreferencedEndingCatchHandler) { |
| 580 | // Disable test on target. |
| 581 | TEST_DISABLED_FOR_TARGET(); |
| 582 | std::string error_msg; |
| 583 | ASSERT_TRUE(UnreferencedCatchHandlerExec(&error_msg, |
| 584 | kUnreferencedEndingCatchHandlerInputDex)) << error_msg; |
| 585 | } |
| 586 | |
Mathieu Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 587 | TEST_F(DexLayoutTest, DuplicateOffset) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 588 | ScratchFile temp_dex; |
Mathieu Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 589 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 590 | 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] | 591 | std::vector<std::string> dexlayout_exec_argv = |
| 592 | { dexlayout, "-a", "-i", "-o", "/dev/null", temp_dex.GetFilename() }; |
| 593 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 594 | kDexFileDuplicateOffset, |
| 595 | nullptr /* profile_file */, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 596 | dexlayout_exec_argv)); |
Mathieu Chartier | 6b0dbef | 2017-02-21 12:45:30 -0800 | [diff] [blame] | 597 | } |
| 598 | |
Jeff Hao | f914f8e | 2017-02-21 16:14:23 -0800 | [diff] [blame] | 599 | TEST_F(DexLayoutTest, NullSetRefListElement) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 600 | ScratchFile temp_dex; |
Jeff Hao | f914f8e | 2017-02-21 16:14:23 -0800 | [diff] [blame] | 601 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 602 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 603 | std::vector<std::string> dexlayout_exec_argv = |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 604 | { dexlayout, "-o", "/dev/null", temp_dex.GetFilename() }; |
| 605 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 606 | kNullSetRefListElementInputDex, |
| 607 | nullptr /* profile_file */, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 608 | dexlayout_exec_argv)); |
Jeff Hao | f914f8e | 2017-02-21 16:14:23 -0800 | [diff] [blame] | 609 | } |
| 610 | |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 611 | TEST_F(DexLayoutTest, MultiClassData) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 612 | ScratchFile temp_dex; |
| 613 | ScratchFile temp_profile; |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 614 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 615 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 616 | std::vector<std::string> dexlayout_exec_argv = |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 617 | { dexlayout, "-p", temp_profile.GetFilename(), "-o", "/dev/null", temp_dex.GetFilename() }; |
| 618 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 619 | kMultiClassDataInputDex, |
| 620 | &temp_profile, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 621 | dexlayout_exec_argv)); |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 622 | } |
| 623 | |
| 624 | TEST_F(DexLayoutTest, UnalignedCodeInfo) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 625 | ScratchFile temp_dex; |
| 626 | ScratchFile temp_profile; |
Jeff Hao | e17f589 | 2017-02-23 16:14:04 -0800 | [diff] [blame] | 627 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 628 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 629 | std::vector<std::string> dexlayout_exec_argv = |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 630 | { dexlayout, "-p", temp_profile.GetFilename(), "-o", "/dev/null", temp_dex.GetFilename() }; |
| 631 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 632 | kUnalignedCodeInfoInputDex, |
| 633 | &temp_profile, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 634 | dexlayout_exec_argv)); |
Jeff Hao | 44652a3 | 2017-02-22 14:20:41 -0800 | [diff] [blame] | 635 | } |
| 636 | |
Jeff Hao | 32a60ab | 2017-03-01 16:44:50 -0800 | [diff] [blame] | 637 | TEST_F(DexLayoutTest, ClassDataBeforeCode) { |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 638 | ScratchFile temp_dex; |
| 639 | ScratchFile temp_profile; |
Jeff Hao | 32a60ab | 2017-03-01 16:44:50 -0800 | [diff] [blame] | 640 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 641 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 642 | std::vector<std::string> dexlayout_exec_argv = |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 643 | { dexlayout, "-p", temp_profile.GetFilename(), "-o", "/dev/null", temp_dex.GetFilename() }; |
| 644 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 645 | kClassDataBeforeCodeInputDex, |
| 646 | &temp_profile, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 647 | dexlayout_exec_argv)); |
| 648 | } |
| 649 | |
| 650 | TEST_F(DexLayoutTest, UnknownTypeDebugInfo) { |
| 651 | ScratchFile temp_dex; |
| 652 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 653 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 654 | std::vector<std::string> dexlayout_exec_argv = |
| 655 | { dexlayout, "-o", "/dev/null", temp_dex.GetFilename() }; |
| 656 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 657 | kUnknownTypeDebugInfoInputDex, |
| 658 | nullptr /* profile_file */, |
Jeff Hao | d9be768 | 2017-04-05 09:29:43 -0700 | [diff] [blame] | 659 | dexlayout_exec_argv)); |
Jeff Hao | 32a60ab | 2017-03-01 16:44:50 -0800 | [diff] [blame] | 660 | } |
| 661 | |
Jeff Hao | d212d5b | 2017-04-26 12:09:06 -0700 | [diff] [blame] | 662 | TEST_F(DexLayoutTest, DuplicateCodeItem) { |
| 663 | ScratchFile temp_dex; |
| 664 | std::string dexlayout = GetTestAndroidRoot() + "/bin/dexlayout"; |
| 665 | EXPECT_TRUE(OS::FileExists(dexlayout.c_str())) << dexlayout << " should be a valid file path"; |
| 666 | std::vector<std::string> dexlayout_exec_argv = |
| 667 | { dexlayout, "-o", "/dev/null", temp_dex.GetFilename() }; |
| 668 | ASSERT_TRUE(DexLayoutExec(&temp_dex, |
| 669 | kDuplicateCodeItemInputDex, |
| 670 | nullptr /* profile_file */, |
Jeff Hao | d212d5b | 2017-04-26 12:09:06 -0700 | [diff] [blame] | 671 | dexlayout_exec_argv)); |
| 672 | } |
| 673 | |
Jeff Hao | c3acfc5 | 2016-08-29 14:18:26 -0700 | [diff] [blame] | 674 | } // namespace art |