| 1 |
/* |
| 2 |
* Copyright (C) 2019 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 |
package com.android.protolog.tool |
| 18 |
|
| 19 |
import org.junit.Assert.assertEquals |
| 20 |
import org.junit.Test |
| 21 |
|
| 22 |
class CommandOptionsTest { |
| 23 |
companion object { |
| 24 |
val TEST_JAVA_SRC = listOf( |
| 25 |
"frameworks/base/services/core/java/com/android/server/wm/" + |
| 26 |
"AccessibilityController.java", |
| 27 |
"frameworks/base/services/core/java/com/android/server/wm/ActivityDisplay.java", |
| 28 |
"frameworks/base/services/core/java/com/android/server/wm/" + |
| 29 |
"ActivityMetricsLaunchObserver.java" |
| 30 |
) |
| 31 |
private const val TEST_PROTOLOG_CLASS = "com.android.server.wm.ProtoLog" |
| 32 |
private const val TEST_PROTOLOGIMPL_CLASS = "com.android.server.wm.ProtoLogImpl" |
| 33 |
private const val TEST_PROTOLOGCACHE_CLASS = "com.android.server.wm.ProtoLog\$Cache" |
| 34 |
private const val TEST_PROTOLOGGROUP_CLASS = "com.android.internal.protolog.ProtoLogGroup" |
| 35 |
private const val TEST_PROTOLOGGROUP_JAR = "out/soong/.intermediates/frameworks/base/" + |
| 36 |
"services/core/services.core.wm.protologgroups/android_common/javac/" + |
| 37 |
"services.core.wm.protologgroups.jar" |
| 38 |
private const val TEST_SRC_JAR = "out/soong/.temp/sbox175955373/" + |
| 39 |
"services.core.wm.protolog.srcjar" |
| 40 |
private const val TEST_VIEWER_JSON = "out/soong/.temp/sbox175955373/" + |
| 41 |
"services.core.wm.protolog.json" |
| 42 |
private const val TEST_LOG = "./test_log.pb" |
| 43 |
} |
| 44 |
|
| 45 |
@Test(expected = InvalidCommandException::class) |
| 46 |
fun noCommand() { |
| 47 |
CommandOptions(arrayOf()) |
| 48 |
} |
| 49 |
|
| 50 |
@Test(expected = InvalidCommandException::class) |
| 51 |
fun invalidCommand() { |
| 52 |
val testLine = "invalid" |
| 53 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 54 |
} |
| 55 |
|
| 56 |
@Test |
| 57 |
fun transformClasses() { |
| 58 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 59 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 60 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 61 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 62 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 63 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 64 |
val cmd = CommandOptions(testLine.split(' ').toTypedArray()) |
| 65 |
assertEquals(CommandOptions.TRANSFORM_CALLS_CMD, cmd.command) |
| 66 |
assertEquals(TEST_PROTOLOG_CLASS, cmd.protoLogClassNameArg) |
| 67 |
assertEquals(TEST_PROTOLOGIMPL_CLASS, cmd.protoLogImplClassNameArg) |
| 68 |
assertEquals(TEST_PROTOLOGGROUP_CLASS, cmd.protoLogGroupsClassNameArg) |
| 69 |
assertEquals(TEST_PROTOLOGGROUP_JAR, cmd.protoLogGroupsJarArg) |
| 70 |
assertEquals(TEST_SRC_JAR, cmd.outputSourceJarArg) |
| 71 |
assertEquals(TEST_JAVA_SRC, cmd.javaSourceArgs) |
| 72 |
} |
| 73 |
|
| 74 |
@Test(expected = InvalidCommandException::class) |
| 75 |
fun transformClasses_noProtoLogClass() { |
| 76 |
val testLine = "transform-protolog-calls " + |
| 77 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 78 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 79 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 80 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 81 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 82 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 83 |
} |
| 84 |
|
| 85 |
@Test(expected = InvalidCommandException::class) |
| 86 |
fun transformClasses_noProtoLogImplClass() { |
| 87 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 88 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 89 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 90 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 91 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 92 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 93 |
} |
| 94 |
|
| 95 |
@Test(expected = InvalidCommandException::class) |
| 96 |
fun transformClasses_noProtoLogCacheClass() { |
| 97 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 98 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 99 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 100 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 101 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 102 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 103 |
} |
| 104 |
|
| 105 |
@Test(expected = InvalidCommandException::class) |
| 106 |
fun transformClasses_noProtoLogGroupClass() { |
| 107 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 108 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 109 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 110 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 111 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 112 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 113 |
} |
| 114 |
|
| 115 |
@Test(expected = InvalidCommandException::class) |
| 116 |
fun transformClasses_noProtoLogGroupJar() { |
| 117 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 118 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 119 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 120 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 121 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 122 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 123 |
} |
| 124 |
|
| 125 |
@Test(expected = InvalidCommandException::class) |
| 126 |
fun transformClasses_noOutJar() { |
| 127 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 128 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 129 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 130 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 131 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 132 |
TEST_JAVA_SRC.joinToString(" ") |
| 133 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 134 |
} |
| 135 |
|
| 136 |
@Test(expected = InvalidCommandException::class) |
| 137 |
fun transformClasses_noJavaInput() { |
| 138 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 139 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 140 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 141 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 142 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 143 |
"--output-srcjar $TEST_SRC_JAR" |
| 144 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 145 |
} |
| 146 |
|
| 147 |
@Test(expected = InvalidCommandException::class) |
| 148 |
fun transformClasses_invalidProtoLogClass() { |
| 149 |
val testLine = "transform-protolog-calls --protolog-class invalid " + |
| 150 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 151 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 152 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 153 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 154 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 155 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 156 |
} |
| 157 |
|
| 158 |
@Test(expected = InvalidCommandException::class) |
| 159 |
fun transformClasses_invalidProtoLogImplClass() { |
| 160 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 161 |
"--protolog-impl-class invalid " + |
| 162 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 163 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 164 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 165 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 166 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 167 |
} |
| 168 |
|
| 169 |
@Test(expected = InvalidCommandException::class) |
| 170 |
fun transformClasses_invalidProtoLogCacheClass() { |
| 171 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 172 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 173 |
"--protolog-cache-class invalid " + |
| 174 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 175 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 176 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 177 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 178 |
} |
| 179 |
|
| 180 |
@Test(expected = InvalidCommandException::class) |
| 181 |
fun transformClasses_invalidProtoLogGroupClass() { |
| 182 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 183 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 184 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 185 |
"--loggroups-class invalid " + |
| 186 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 187 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 188 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 189 |
} |
| 190 |
|
| 191 |
@Test(expected = InvalidCommandException::class) |
| 192 |
fun transformClasses_invalidProtoLogGroupJar() { |
| 193 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 194 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 195 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 196 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 197 |
"--loggroups-jar invalid.txt " + |
| 198 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 199 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 200 |
} |
| 201 |
|
| 202 |
@Test(expected = InvalidCommandException::class) |
| 203 |
fun transformClasses_invalidOutJar() { |
| 204 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 205 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 206 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 207 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 208 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 209 |
"--output-srcjar invalid.db ${TEST_JAVA_SRC.joinToString(" ")}" |
| 210 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 211 |
} |
| 212 |
|
| 213 |
@Test(expected = InvalidCommandException::class) |
| 214 |
fun transformClasses_invalidJavaInput() { |
| 215 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 216 |
"--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 217 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 218 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 219 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 220 |
"--output-srcjar $TEST_SRC_JAR invalid.py" |
| 221 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 222 |
} |
| 223 |
|
| 224 |
@Test(expected = InvalidCommandException::class) |
| 225 |
fun transformClasses_unknownParam() { |
| 226 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 227 |
"--unknown test --protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " + |
| 228 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 229 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 230 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 231 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 232 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 233 |
} |
| 234 |
|
| 235 |
@Test(expected = InvalidCommandException::class) |
| 236 |
fun transformClasses_noValue() { |
| 237 |
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " + |
| 238 |
"--protolog-impl-class " + |
| 239 |
"--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " + |
| 240 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 241 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 242 |
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}" |
| 243 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 244 |
} |
| 245 |
|
| 246 |
@Test |
| 247 |
fun generateConfig() { |
| 248 |
val testLine = "generate-viewer-config --protolog-class $TEST_PROTOLOG_CLASS " + |
| 249 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 250 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 251 |
"--viewer-conf $TEST_VIEWER_JSON ${TEST_JAVA_SRC.joinToString(" ")}" |
| 252 |
val cmd = CommandOptions(testLine.split(' ').toTypedArray()) |
| 253 |
assertEquals(CommandOptions.GENERATE_CONFIG_CMD, cmd.command) |
| 254 |
assertEquals(TEST_PROTOLOG_CLASS, cmd.protoLogClassNameArg) |
| 255 |
assertEquals(TEST_PROTOLOGGROUP_CLASS, cmd.protoLogGroupsClassNameArg) |
| 256 |
assertEquals(TEST_PROTOLOGGROUP_JAR, cmd.protoLogGroupsJarArg) |
| 257 |
assertEquals(TEST_VIEWER_JSON, cmd.viewerConfigJsonArg) |
| 258 |
assertEquals(TEST_JAVA_SRC, cmd.javaSourceArgs) |
| 259 |
} |
| 260 |
|
| 261 |
@Test(expected = InvalidCommandException::class) |
| 262 |
fun generateConfig_noViewerConfig() { |
| 263 |
val testLine = "generate-viewer-config --protolog-class $TEST_PROTOLOG_CLASS " + |
| 264 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 265 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 266 |
TEST_JAVA_SRC.joinToString(" ") |
| 267 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 268 |
} |
| 269 |
|
| 270 |
@Test(expected = InvalidCommandException::class) |
| 271 |
fun generateConfig_invalidViewerConfig() { |
| 272 |
val testLine = "generate-viewer-config --protolog-class $TEST_PROTOLOG_CLASS " + |
| 273 |
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " + |
| 274 |
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " + |
| 275 |
"--viewer-conf invalid.yaml ${TEST_JAVA_SRC.joinToString(" ")}" |
| 276 |
CommandOptions(testLine.split(' ').toTypedArray()) |
| 277 |
} |
| 278 |
|
| 279 |
@Test |
| 280 |
fun readLog() { |
| 281 |
val testLine = "read-log --viewer-conf $TEST_VIEWER_JSON $TEST_LOG" |
| 282 |
val cmd = CommandOptions(testLine.split(' ').toTypedArray()) |
| 283 |
assertEquals(CommandOptions.READ_LOG_CMD, cmd.command) |
| 284 |
assertEquals(TEST_VIEWER_JSON, cmd.viewerConfigJsonArg) |
| 285 |
assertEquals(TEST_LOG, cmd.logProtofileArg) |
| 286 |
} |
| 287 |
} |