Update ProtoLogTool commands args
We need these new parameters to inject those values into the generated classes so we don't have to manually create an impl of these class and passing those values manually.
Flag: ACONFIG android.tracing.Flags.perfettoProtolog DEVELOPMENT
Bug: 276432490
Test: atest FrameworksServicesTests
Change-Id: I32906cbe37c7c3899d7c487d5ed341381a05fdf1
diff --git a/tools/protologtool/Android.bp b/tools/protologtool/Android.bp
index 46745e9..61e4b35 100644
--- a/tools/protologtool/Android.bp
+++ b/tools/protologtool/Android.bp
@@ -42,5 +42,6 @@
"junit",
"mockito",
"objenesis",
+ "truth",
],
}
diff --git a/tools/protologtool/README.md b/tools/protologtool/README.md
index ba63957..24a4861 100644
--- a/tools/protologtool/README.md
+++ b/tools/protologtool/README.md
@@ -8,11 +8,13 @@
### Code transformation
-Command: `protologtool transform-protolog-calls
- --protolog-class <protolog class name>
- --protolog-impl-class <protolog implementation class name>
+Command: `protologtool transform-protolog-calls
+ --protolog-class <protolog class name>
--loggroups-class <protolog groups class name>
--loggroups-jar <config jar path>
+ --viewer-config-file-path <protobuf viewer config file path>
+ --legacy-viewer-config-file-path <legacy json.gz viewer config file path>
+ --legacy-output-file-path <.winscope file path to write the legacy trace to>
--output-srcjar <output.srcjar>
[<input.java>]`
@@ -44,10 +46,11 @@
### Viewer config generation
Command: `generate-viewer-config
- --protolog-class <protolog class name>
+ --protolog-class <protolog class name>
--loggroups-class <protolog groups class name>
--loggroups-jar <config jar path>
- --viewer-conf <viewer.json>
+ --viewer-config-type <proto|json>
+ --viewer-config <viewer.json>
[<input.java>]`
This command is similar in it's syntax to the previous one, only instead of creating a processed source jar
@@ -74,7 +77,7 @@
### Binary log viewing
-Command: `read-log --viewer-conf <viewer.json> <wm_log.pb>`
+Command: `read-log --viewer-config <viewer.json> <wm_log.pb>`
Reads the binary ProtoLog log file and outputs a human-readable LogCat-like text log.
diff --git a/tools/protologtool/src/com/android/protolog/tool/CommandOptions.kt b/tools/protologtool/src/com/android/protolog/tool/CommandOptions.kt
index bfbbf7a..a359155 100644
--- a/tools/protologtool/src/com/android/protolog/tool/CommandOptions.kt
+++ b/tools/protologtool/src/com/android/protolog/tool/CommandOptions.kt
@@ -26,32 +26,35 @@
private val commands = setOf(TRANSFORM_CALLS_CMD, GENERATE_CONFIG_CMD, READ_LOG_CMD)
private const val PROTOLOG_CLASS_PARAM = "--protolog-class"
- private const val PROTOLOGIMPL_CLASS_PARAM = "--protolog-impl-class"
- private const val PROTOLOGCACHE_CLASS_PARAM = "--protolog-cache-class"
private const val PROTOLOGGROUP_CLASS_PARAM = "--loggroups-class"
private const val PROTOLOGGROUP_JAR_PARAM = "--loggroups-jar"
- private const val VIEWER_CONFIG_JSON_PARAM = "--viewer-conf"
+ private const val VIEWER_CONFIG_PARAM = "--viewer-config"
+ private const val VIEWER_CONFIG_TYPE_PARAM = "--viewer-config-type"
private const val OUTPUT_SOURCE_JAR_PARAM = "--output-srcjar"
- private val parameters = setOf(PROTOLOG_CLASS_PARAM, PROTOLOGIMPL_CLASS_PARAM,
- PROTOLOGCACHE_CLASS_PARAM, PROTOLOGGROUP_CLASS_PARAM, PROTOLOGGROUP_JAR_PARAM,
- VIEWER_CONFIG_JSON_PARAM, OUTPUT_SOURCE_JAR_PARAM)
+ private const val VIEWER_CONFIG_FILE_PATH_PARAM = "--viewer-config-file-path"
+ // TODO(b/324128613): Remove these legacy options once we fully flip the Perfetto protolog flag
+ private const val LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM = "--legacy-viewer-config-file-path"
+ private const val LEGACY_OUTPUT_FILE_PATH = "--legacy-output-file-path"
+ private val parameters = setOf(PROTOLOG_CLASS_PARAM, PROTOLOGGROUP_CLASS_PARAM,
+ PROTOLOGGROUP_JAR_PARAM, VIEWER_CONFIG_PARAM, VIEWER_CONFIG_TYPE_PARAM,
+ OUTPUT_SOURCE_JAR_PARAM, VIEWER_CONFIG_FILE_PATH_PARAM,
+ LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM, LEGACY_OUTPUT_FILE_PATH)
val USAGE = """
Usage: ${Constants.NAME} <command> [<args>]
Available commands:
- $TRANSFORM_CALLS_CMD $PROTOLOG_CLASS_PARAM <class name> $PROTOLOGIMPL_CLASS_PARAM
- <class name> $PROTOLOGCACHE_CLASS_PARAM
- <class name> $PROTOLOGGROUP_CLASS_PARAM <class name> $PROTOLOGGROUP_JAR_PARAM
- <config.jar> $OUTPUT_SOURCE_JAR_PARAM <output.srcjar> [<input.java>]
+ $TRANSFORM_CALLS_CMD $PROTOLOG_CLASS_PARAM <class name>
+ $PROTOLOGGROUP_CLASS_PARAM <class name> $PROTOLOGGROUP_JAR_PARAM <config.jar>
+ $OUTPUT_SOURCE_JAR_PARAM <output.srcjar> [<input.java>]
- processes java files replacing stub calls with logging code.
- $GENERATE_CONFIG_CMD $PROTOLOG_CLASS_PARAM <class name> $PROTOLOGGROUP_CLASS_PARAM
- <class name> $PROTOLOGGROUP_JAR_PARAM <config.jar> $VIEWER_CONFIG_JSON_PARAM
- <viewer.json> [<input.java>]
+ $GENERATE_CONFIG_CMD $PROTOLOG_CLASS_PARAM <class name>
+ $PROTOLOGGROUP_CLASS_PARAM <class name> $PROTOLOGGROUP_JAR_PARAM <config.jar>
+ $VIEWER_CONFIG_PARAM <viewer.json|viewer.pb> [<input.java>]
- creates viewer config file from given java files.
- $READ_LOG_CMD $VIEWER_CONFIG_JSON_PARAM <viewer.json> <wm_log.pb>
+ $READ_LOG_CMD $VIEWER_CONFIG_PARAM <viewer.json|viewer.pb> <wm_log.pb>
- translates a binary log to a readable format.
""".trimIndent()
@@ -69,6 +72,13 @@
return params.getValue(paramName)
}
+ private fun getOptionalParam(paramName: String, params: Map<String, String>): String? {
+ if (!params.containsKey(paramName)) {
+ return null
+ }
+ return params.getValue(paramName)
+ }
+
private fun validateNotSpecified(paramName: String, params: Map<String, String>): String {
if (params.containsKey(paramName)) {
throw InvalidCommandException("Unsupported param $paramName")
@@ -90,9 +100,43 @@
return name
}
- private fun validateJSONName(name: String): String {
- if (!name.endsWith(".json")) {
- throw InvalidCommandException("Json file required, got $name instead")
+ private fun validateViewerConfigFilePath(name: String): String {
+ if (!name.endsWith(".pb")) {
+ throw InvalidCommandException("Proto file (ending with .pb) required, " +
+ "got $name instead")
+ }
+ return name
+ }
+
+ private fun validateLegacyViewerConfigFilePath(name: String): String {
+ if (!name.endsWith(".json.gz")) {
+ throw InvalidCommandException("GZiped Json file (ending with .json.gz) required, " +
+ "got $name instead")
+ }
+ return name
+ }
+
+ private fun validateOutputFilePath(name: String): String {
+ if (!name.endsWith(".winscope")) {
+ throw InvalidCommandException("Winscope file (ending with .winscope) required, " +
+ "got $name instead")
+ }
+ return name
+ }
+
+ private fun validateConfigFileName(name: String): String {
+ if (!name.endsWith(".json") && !name.endsWith(".pb")) {
+ throw InvalidCommandException("Json file (ending with .json) or proto file " +
+ "(ending with .pb) required, got $name instead")
+ }
+ return name
+ }
+
+ private fun validateConfigType(name: String): String {
+ val validType = listOf("json", "proto")
+ if (!validType.contains(name)) {
+ throw InvalidCommandException("Unexpected config file type. " +
+ "Expected on of [${validType.joinToString()}], but got $name")
}
return name
}
@@ -102,8 +146,8 @@
throw InvalidCommandException("No java source input files")
}
list.forEach { name ->
- if (!name.endsWith(".java")) {
- throw InvalidCommandException("Not a java source file $name")
+ if (!name.endsWith(".java") && !name.endsWith(".kt")) {
+ throw InvalidCommandException("Not a java or kotlin source file $name")
}
}
return list
@@ -122,12 +166,14 @@
val protoLogClassNameArg: String
val protoLogGroupsClassNameArg: String
- val protoLogImplClassNameArg: String
- val protoLogCacheClassNameArg: String
val protoLogGroupsJarArg: String
- val viewerConfigJsonArg: String
+ val viewerConfigFileNameArg: String
+ val viewerConfigTypeArg: String
val outputSourceJarArg: String
val logProtofileArg: String
+ val viewerConfigFilePathArg: String
+ val legacyViewerConfigFilePathArg: String?
+ val legacyOutputFilePath: String?
val javaSourceArgs: List<String>
val command: String
@@ -169,38 +215,55 @@
when (command) {
TRANSFORM_CALLS_CMD -> {
protoLogClassNameArg = validateClassName(getParam(PROTOLOG_CLASS_PARAM, params))
- protoLogGroupsClassNameArg = validateClassName(getParam(PROTOLOGGROUP_CLASS_PARAM,
- params))
- protoLogImplClassNameArg = validateClassName(getParam(PROTOLOGIMPL_CLASS_PARAM,
- params))
- protoLogCacheClassNameArg = validateClassName(getParam(PROTOLOGCACHE_CLASS_PARAM,
- params))
+ protoLogGroupsClassNameArg =
+ validateClassName(getParam(PROTOLOGGROUP_CLASS_PARAM, params))
protoLogGroupsJarArg = validateJarName(getParam(PROTOLOGGROUP_JAR_PARAM, params))
- viewerConfigJsonArg = validateNotSpecified(VIEWER_CONFIG_JSON_PARAM, params)
+ viewerConfigFileNameArg = validateNotSpecified(VIEWER_CONFIG_PARAM, params)
+ viewerConfigTypeArg = validateNotSpecified(VIEWER_CONFIG_TYPE_PARAM, params)
outputSourceJarArg = validateSrcJarName(getParam(OUTPUT_SOURCE_JAR_PARAM, params))
+ viewerConfigFilePathArg = validateViewerConfigFilePath(
+ getParam(VIEWER_CONFIG_FILE_PATH_PARAM, params))
+ legacyViewerConfigFilePathArg =
+ getOptionalParam(LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM, params)?.let {
+ validateLegacyViewerConfigFilePath(it)
+ }
+ legacyOutputFilePath =
+ getOptionalParam(LEGACY_OUTPUT_FILE_PATH, params)?.let {
+ validateOutputFilePath(it)
+ }
javaSourceArgs = validateJavaInputList(inputFiles)
logProtofileArg = ""
}
GENERATE_CONFIG_CMD -> {
protoLogClassNameArg = validateClassName(getParam(PROTOLOG_CLASS_PARAM, params))
- protoLogGroupsClassNameArg = validateClassName(getParam(PROTOLOGGROUP_CLASS_PARAM,
- params))
- protoLogImplClassNameArg = validateNotSpecified(PROTOLOGIMPL_CLASS_PARAM, params)
- protoLogCacheClassNameArg = validateNotSpecified(PROTOLOGCACHE_CLASS_PARAM, params)
+ protoLogGroupsClassNameArg =
+ validateClassName(getParam(PROTOLOGGROUP_CLASS_PARAM, params))
protoLogGroupsJarArg = validateJarName(getParam(PROTOLOGGROUP_JAR_PARAM, params))
- viewerConfigJsonArg = validateJSONName(getParam(VIEWER_CONFIG_JSON_PARAM, params))
+ viewerConfigFileNameArg =
+ validateConfigFileName(getParam(VIEWER_CONFIG_PARAM, params))
+ viewerConfigTypeArg = validateConfigType(getParam(VIEWER_CONFIG_TYPE_PARAM, params))
outputSourceJarArg = validateNotSpecified(OUTPUT_SOURCE_JAR_PARAM, params)
+ viewerConfigFilePathArg =
+ validateNotSpecified(VIEWER_CONFIG_FILE_PATH_PARAM, params)
+ legacyViewerConfigFilePathArg =
+ validateNotSpecified(LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM, params)
+ legacyOutputFilePath = validateNotSpecified(LEGACY_OUTPUT_FILE_PATH, params)
javaSourceArgs = validateJavaInputList(inputFiles)
logProtofileArg = ""
}
READ_LOG_CMD -> {
protoLogClassNameArg = validateNotSpecified(PROTOLOG_CLASS_PARAM, params)
protoLogGroupsClassNameArg = validateNotSpecified(PROTOLOGGROUP_CLASS_PARAM, params)
- protoLogImplClassNameArg = validateNotSpecified(PROTOLOGIMPL_CLASS_PARAM, params)
- protoLogCacheClassNameArg = validateNotSpecified(PROTOLOGCACHE_CLASS_PARAM, params)
protoLogGroupsJarArg = validateNotSpecified(PROTOLOGGROUP_JAR_PARAM, params)
- viewerConfigJsonArg = validateJSONName(getParam(VIEWER_CONFIG_JSON_PARAM, params))
+ viewerConfigFileNameArg =
+ validateConfigFileName(getParam(VIEWER_CONFIG_PARAM, params))
+ viewerConfigTypeArg = validateNotSpecified(VIEWER_CONFIG_TYPE_PARAM, params)
outputSourceJarArg = validateNotSpecified(OUTPUT_SOURCE_JAR_PARAM, params)
+ viewerConfigFilePathArg =
+ validateNotSpecified(VIEWER_CONFIG_FILE_PATH_PARAM, params)
+ legacyViewerConfigFilePathArg =
+ validateNotSpecified(LEGACY_VIEWER_CONFIG_FILE_PATH_PARAM, params)
+ legacyOutputFilePath = validateNotSpecified(LEGACY_OUTPUT_FILE_PATH, params)
javaSourceArgs = listOf()
logProtofileArg = validateLogInputList(inputFiles)
}
diff --git a/tools/protologtool/tests/com/android/protolog/tool/CommandOptionsTest.kt b/tools/protologtool/tests/com/android/protolog/tool/CommandOptionsTest.kt
index 3cfbb43..5ef2833 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/CommandOptionsTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/CommandOptionsTest.kt
@@ -16,7 +16,9 @@
package com.android.protolog.tool
+import com.google.common.truth.Truth.assertThat
import org.junit.Assert.assertEquals
+import org.junit.Assert.assertThrows
import org.junit.Test
class CommandOptionsTest {
@@ -35,6 +37,10 @@
private const val TEST_PROTOLOGGROUP_JAR = "out/soong/.intermediates/frameworks/base/" +
"services/core/services.core.wm.protologgroups/android_common/javac/" +
"services.core.wm.protologgroups.jar"
+ private const val TEST_VIEWER_CONFIG_FILE_PATH = "/some/viewer/config/file/path.pb"
+ private const val TEST_LEGACY_VIEWER_CONFIG_FILE_PATH =
+ "/some/viewer/config/file/path.json.gz"
+ private const val TEST_LEGACY_OUTPUT_FILE_PATH = "/some/output/file/path.winscope"
private const val TEST_SRC_JAR = "out/soong/.temp/sbox175955373/" +
"services.core.wm.protolog.srcjar"
private const val TEST_VIEWER_JSON = "out/soong/.temp/sbox175955373/" +
@@ -42,186 +48,263 @@
private const val TEST_LOG = "./test_log.pb"
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun noCommand() {
- CommandOptions(arrayOf())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(arrayOf())
+ }
+ assertThat(exception).hasMessageThat().contains("No command specified")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun invalidCommand() {
val testLine = "invalid"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("Unknown command")
}
@Test
fun transformClasses() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
val cmd = CommandOptions(testLine.split(' ').toTypedArray())
assertEquals(CommandOptions.TRANSFORM_CALLS_CMD, cmd.command)
assertEquals(TEST_PROTOLOG_CLASS, cmd.protoLogClassNameArg)
- assertEquals(TEST_PROTOLOGIMPL_CLASS, cmd.protoLogImplClassNameArg)
assertEquals(TEST_PROTOLOGGROUP_CLASS, cmd.protoLogGroupsClassNameArg)
assertEquals(TEST_PROTOLOGGROUP_JAR, cmd.protoLogGroupsJarArg)
+ assertEquals(TEST_VIEWER_CONFIG_FILE_PATH, cmd.viewerConfigFilePathArg)
+ assertEquals(TEST_LEGACY_VIEWER_CONFIG_FILE_PATH, cmd.legacyViewerConfigFilePathArg)
+ assertEquals(TEST_LEGACY_OUTPUT_FILE_PATH, cmd.legacyOutputFilePath)
assertEquals(TEST_SRC_JAR, cmd.outputSourceJarArg)
assertEquals(TEST_JAVA_SRC, cmd.javaSourceArgs)
}
- @Test(expected = InvalidCommandException::class)
+ @Test
+ fun transformClasses_noViewerConfigFile() {
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
+ "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
+ "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
+ "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("--viewer-config-file-path")
+ }
+
+ @Test
+ fun transformClasses_noLegacyViewerConfigFile() {
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
+ "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
+ "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
+ "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
+ val cmd = CommandOptions(testLine.split(' ').toTypedArray())
+ assertEquals(CommandOptions.TRANSFORM_CALLS_CMD, cmd.command)
+ assertEquals(TEST_PROTOLOG_CLASS, cmd.protoLogClassNameArg)
+ assertEquals(TEST_PROTOLOGGROUP_CLASS, cmd.protoLogGroupsClassNameArg)
+ assertEquals(TEST_PROTOLOGGROUP_JAR, cmd.protoLogGroupsJarArg)
+ assertEquals(TEST_VIEWER_CONFIG_FILE_PATH, cmd.viewerConfigFilePathArg)
+ assertEquals(null, cmd.legacyViewerConfigFilePathArg)
+ assertEquals(TEST_LEGACY_OUTPUT_FILE_PATH, cmd.legacyOutputFilePath)
+ assertEquals(TEST_SRC_JAR, cmd.outputSourceJarArg)
+ assertEquals(TEST_JAVA_SRC, cmd.javaSourceArgs)
+ }
+
+ @Test
+ fun transformClasses_noLegacyOutputFile() {
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
+ "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
+ "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
+ val cmd = CommandOptions(testLine.split(' ').toTypedArray())
+ assertEquals(CommandOptions.TRANSFORM_CALLS_CMD, cmd.command)
+ assertEquals(TEST_PROTOLOG_CLASS, cmd.protoLogClassNameArg)
+ assertEquals(TEST_PROTOLOGGROUP_CLASS, cmd.protoLogGroupsClassNameArg)
+ assertEquals(TEST_PROTOLOGGROUP_JAR, cmd.protoLogGroupsJarArg)
+ assertEquals(TEST_VIEWER_CONFIG_FILE_PATH, cmd.viewerConfigFilePathArg)
+ assertEquals(TEST_LEGACY_VIEWER_CONFIG_FILE_PATH, cmd.legacyViewerConfigFilePathArg)
+ assertEquals(null, cmd.legacyOutputFilePath)
+ assertEquals(TEST_SRC_JAR, cmd.outputSourceJarArg)
+ assertEquals(TEST_JAVA_SRC, cmd.javaSourceArgs)
+ }
+
+ @Test
fun transformClasses_noProtoLogClass() {
val testLine = "transform-protolog-calls " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("--protolog-class")
}
- @Test(expected = InvalidCommandException::class)
- fun transformClasses_noProtoLogImplClass() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
- "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
- "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
- }
-
- @Test(expected = InvalidCommandException::class)
- fun transformClasses_noProtoLogCacheClass() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
- "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
- }
-
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_noProtoLogGroupClass() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("--loggroups-class")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_noProtoLogGroupJar() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("--loggroups-jar")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_noOutJar() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- TEST_JAVA_SRC.joinToString(" ")
- CommandOptions(testLine.split(' ').toTypedArray())
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
+ "${TEST_JAVA_SRC.joinToString(" ")}"
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("--output-srcjar")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_noJavaInput() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
"--output-srcjar $TEST_SRC_JAR"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("No java source input files")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_invalidProtoLogClass() {
- val testLine = "transform-protolog-calls --protolog-class invalid " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class invalid " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("class name invalid")
}
- @Test(expected = InvalidCommandException::class)
- fun transformClasses_invalidProtoLogImplClass() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class invalid " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
- "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
- "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
- }
-
- @Test(expected = InvalidCommandException::class)
- fun transformClasses_invalidProtoLogCacheClass() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class invalid " +
- "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
- "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
- }
-
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_invalidProtoLogGroupClass() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class invalid " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("class name invalid")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_invalidProtoLogGroupJar() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar invalid.txt " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat()
+ .contains("Jar file required, got invalid.txt instead")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_invalidOutJar() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- "--output-srcjar invalid.db ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
+ "--output-srcjar invalid.pb ${TEST_JAVA_SRC.joinToString(" ")}"
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat()
+ .contains("Source jar file required, got invalid.pb instead")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_invalidJavaInput() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
- "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
- "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- "--output-srcjar $TEST_SRC_JAR invalid.py"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val testLine = "transform-protolog-calls " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
+ "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
+ "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-file-path $TEST_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-viewer-config-file-path $TEST_LEGACY_VIEWER_CONFIG_FILE_PATH " +
+ "--legacy-output-file-path $TEST_LEGACY_OUTPUT_FILE_PATH " +
+ "--output-srcjar $TEST_SRC_JAR invalid.py"
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat()
+ .contains("Not a java or kotlin source file invalid.py")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun transformClasses_unknownParam() {
val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
"--unknown test --protolog-impl-class $TEST_PROTOLOGIMPL_CLASS " +
@@ -229,59 +312,88 @@
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
"--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
- }
-
- @Test(expected = InvalidCommandException::class)
- fun transformClasses_noValue() {
- val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
- "--protolog-impl-class " +
- "--protolog-cache-class $TEST_PROTOLOGCACHE_CLASS " +
- "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
- "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("--unknown")
}
@Test
- fun generateConfig() {
- val testLine = "generate-viewer-config --protolog-class $TEST_PROTOLOG_CLASS " +
+ fun transformClasses_noValue() {
+ val testLine = "transform-protolog-calls --protolog-class $TEST_PROTOLOG_CLASS " +
+ "--loggroups-class " +
+ "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--output-srcjar $TEST_SRC_JAR ${TEST_JAVA_SRC.joinToString(" ")}"
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("No value for --loggroups-class")
+ }
+
+ @Test
+ fun generateConfig_json() {
+ val testLine = "generate-viewer-config " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- "--viewer-conf $TEST_VIEWER_JSON ${TEST_JAVA_SRC.joinToString(" ")}"
+ "--viewer-config-type json " +
+ "--viewer-config $TEST_VIEWER_JSON ${TEST_JAVA_SRC.joinToString(" ")}"
val cmd = CommandOptions(testLine.split(' ').toTypedArray())
assertEquals(CommandOptions.GENERATE_CONFIG_CMD, cmd.command)
assertEquals(TEST_PROTOLOG_CLASS, cmd.protoLogClassNameArg)
assertEquals(TEST_PROTOLOGGROUP_CLASS, cmd.protoLogGroupsClassNameArg)
assertEquals(TEST_PROTOLOGGROUP_JAR, cmd.protoLogGroupsJarArg)
- assertEquals(TEST_VIEWER_JSON, cmd.viewerConfigJsonArg)
+ assertEquals(TEST_VIEWER_JSON, cmd.viewerConfigFileNameArg)
assertEquals(TEST_JAVA_SRC, cmd.javaSourceArgs)
}
- @Test(expected = InvalidCommandException::class)
+ @Test
+ fun generateConfig_proto() {
+ val testLine = "generate-viewer-config " +
+ "--protolog-class $TEST_PROTOLOG_CLASS " +
+ "--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
+ "--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
+ "--viewer-config-type proto " +
+ "--viewer-config $TEST_VIEWER_JSON ${TEST_JAVA_SRC.joinToString(" ")}"
+ val cmd = CommandOptions(testLine.split(' ').toTypedArray())
+ assertEquals(CommandOptions.GENERATE_CONFIG_CMD, cmd.command)
+ assertEquals(TEST_PROTOLOG_CLASS, cmd.protoLogClassNameArg)
+ assertEquals(TEST_PROTOLOGGROUP_CLASS, cmd.protoLogGroupsClassNameArg)
+ assertEquals(TEST_PROTOLOGGROUP_JAR, cmd.protoLogGroupsJarArg)
+ assertEquals(TEST_VIEWER_JSON, cmd.viewerConfigFileNameArg)
+ assertEquals(TEST_JAVA_SRC, cmd.javaSourceArgs)
+ }
+
+ @Test
fun generateConfig_noViewerConfig() {
val testLine = "generate-viewer-config --protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
TEST_JAVA_SRC.joinToString(" ")
- CommandOptions(testLine.split(' ').toTypedArray())
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("--viewer-config required")
}
- @Test(expected = InvalidCommandException::class)
+ @Test
fun generateConfig_invalidViewerConfig() {
val testLine = "generate-viewer-config --protolog-class $TEST_PROTOLOG_CLASS " +
"--loggroups-class $TEST_PROTOLOGGROUP_CLASS " +
"--loggroups-jar $TEST_PROTOLOGGROUP_JAR " +
- "--viewer-conf invalid.yaml ${TEST_JAVA_SRC.joinToString(" ")}"
- CommandOptions(testLine.split(' ').toTypedArray())
+ "--viewer-config invalid.yaml ${TEST_JAVA_SRC.joinToString(" ")}"
+ val exception = assertThrows<InvalidCommandException>(InvalidCommandException::class.java) {
+ CommandOptions(testLine.split(' ').toTypedArray())
+ }
+ assertThat(exception).hasMessageThat().contains("required, got invalid.yaml instead")
}
@Test
fun readLog() {
- val testLine = "read-log --viewer-conf $TEST_VIEWER_JSON $TEST_LOG"
+ val testLine = "read-log --viewer-config $TEST_VIEWER_JSON $TEST_LOG"
val cmd = CommandOptions(testLine.split(' ').toTypedArray())
assertEquals(CommandOptions.READ_LOG_CMD, cmd.command)
- assertEquals(TEST_VIEWER_JSON, cmd.viewerConfigJsonArg)
+ assertEquals(TEST_VIEWER_JSON, cmd.viewerConfigFileNameArg)
assertEquals(TEST_LOG, cmd.logProtofileArg)
}
}
diff --git a/tools/protologtool/tests/com/android/protolog/tool/EndToEndTest.kt b/tools/protologtool/tests/com/android/protolog/tool/EndToEndTest.kt
index 0d2b91d..c9bcbe5 100644
--- a/tools/protologtool/tests/com/android/protolog/tool/EndToEndTest.kt
+++ b/tools/protologtool/tests/com/android/protolog/tool/EndToEndTest.kt
@@ -16,15 +16,15 @@
package com.android.protolog.tool
-import org.junit.Assert
-import org.junit.Assert.assertTrue
-import org.junit.Test
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.File
import java.io.FileNotFoundException
import java.io.OutputStream
import java.util.jar.JarInputStream
+import org.junit.Assert
+import org.junit.Assert.assertTrue
+import org.junit.Test
class EndToEndTest {
@@ -47,11 +47,9 @@
logGroup = LogGroup("GROUP", true, false, "TAG_GROUP"),
commandOptions = CommandOptions(arrayOf("transform-protolog-calls",
"--protolog-class", "com.android.internal.protolog.common.ProtoLog",
- "--protolog-impl-class", "com.android.internal.protolog.ProtoLogImpl",
- "--protolog-cache-class",
- "com.android.server.wm.ProtoLogCache",
"--loggroups-class", "com.android.internal.protolog.ProtoLogGroup",
"--loggroups-jar", "not_required.jar",
+ "--viewer-config-file-path", "not_required.pb",
"--output-srcjar", "out.srcjar",
"frameworks/base/org/example/Example.java"))
)
@@ -80,7 +78,8 @@
"--protolog-class", "com.android.internal.protolog.common.ProtoLog",
"--loggroups-class", "com.android.internal.protolog.ProtoLogGroup",
"--loggroups-jar", "not_required.jar",
- "--viewer-conf", "out.json",
+ "--viewer-config-type", "json",
+ "--viewer-config", "out.json",
"frameworks/base/org/example/Example.java"))
)
val viewerConfigJson = assertLoadText(output, "out.json")