Add unit tests for proto timestamp parser
Bug: None
Test: unit tests
Change-Id: I231ed3a383649632e8f9808839ffdbd470413359
diff --git a/acts/framework/tests/test_utils/instrumentation/data/sample_timestamp.instrumentation_data_proto b/acts/framework/tests/test_utils/instrumentation/data/sample_timestamp.instrumentation_data_proto
new file mode 100644
index 0000000..ecc75a5
--- /dev/null
+++ b/acts/framework/tests/test_utils/instrumentation/data/sample_timestamp.instrumentation_data_proto
Binary files differ
diff --git a/acts/framework/tests/test_utils/instrumentation/data/sample_timestamp_proto.txt b/acts/framework/tests/test_utils/instrumentation/data/sample_timestamp_proto.txt
new file mode 100644
index 0000000..5ac75cd
--- /dev/null
+++ b/acts/framework/tests/test_utils/instrumentation/data/sample_timestamp_proto.txt
@@ -0,0 +1,110 @@
+test_status {
+ result_code: 1
+ results {
+ entries {
+ key: "class"
+ value_string: "com.google.android.powertests.PartialWakelock"
+ }
+ entries {
+ key: "current"
+ value_int: 1
+ }
+ entries {
+ key: "id"
+ value_string: "AndroidJUnitRunner"
+ }
+ entries {
+ key: "numtests"
+ value_int: 1
+ }
+ entries {
+ key: "stream"
+ value_string: "\ncom.google.android.powertests.PartialWakelock:"
+ }
+ entries {
+ key: "test"
+ value_string: "partialWakelock"
+ }
+ }
+}
+test_status {
+ results {
+ entries {
+ key: "class"
+ value_string: "com.google.android.powertests.PartialWakelock"
+ }
+ entries {
+ key: "start-timestamp"
+ }
+ entries {
+ key: "test"
+ value_string: "partialWakelock"
+ }
+ entries {
+ key: "timestamp"
+ value_long: 1567029917802
+ }
+ entries {
+ key: "timestamps-message"
+ }
+ }
+}
+test_status {
+ results {
+ entries {
+ key: "class"
+ value_string: "com.google.android.powertests.PartialWakelock"
+ }
+ entries {
+ key: "end-timestamp"
+ }
+ entries {
+ key: "test"
+ value_string: "partialWakelock"
+ }
+ entries {
+ key: "timestamp"
+ value_long: 1567029932879
+ }
+ entries {
+ key: "timestamps-message"
+ }
+ }
+}
+test_status {
+ results {
+ entries {
+ key: "class"
+ value_string: "com.google.android.powertests.PartialWakelock"
+ }
+ entries {
+ key: "current"
+ value_int: 1
+ }
+ entries {
+ key: "id"
+ value_string: "AndroidJUnitRunner"
+ }
+ entries {
+ key: "numtests"
+ value_int: 1
+ }
+ entries {
+ key: "stream"
+ value_string: "."
+ }
+ entries {
+ key: "test"
+ value_string: "partialWakelock"
+ }
+ }
+}
+session_status {
+ result_code: -1
+ results {
+ entries {
+ key: "stream"
+ value_string: "\n\nTime: 16.333\n\nOK (1 test)\n\n"
+ }
+ }
+}
diff --git a/acts/framework/tests/test_utils/instrumentation/instrumentation_proto_parser_test.py b/acts/framework/tests/test_utils/instrumentation/instrumentation_proto_parser_test.py
index c8c9c87..a9d48a4 100644
--- a/acts/framework/tests/test_utils/instrumentation/instrumentation_proto_parser_test.py
+++ b/acts/framework/tests/test_utils/instrumentation/instrumentation_proto_parser_test.py
@@ -26,6 +26,7 @@
DEST_DIR = 'dest/proto_dir'
SOURCE_PATH = 'source/proto/protofile'
SAMPLE_PROTO = 'data/sample.instrumentation_data_proto'
+SAMPLE_TIMESTAMP_PROTO = 'data/sample_timestamp.instrumentation_data_proto'
class InstrumentationProtoParserTest(unittest.TestCase):
@@ -63,6 +64,17 @@
self.assertIsInstance(parser.get_session_from_local_file(proto_file),
instrumentation_data_pb2.Session)
+ def test_get_test_timestamps(self):
+ proto_file = os.path.join(os.path.dirname(__file__),
+ SAMPLE_TIMESTAMP_PROTO)
+ session = parser.get_session_from_local_file(proto_file)
+ timestamps = parser.get_test_timestamps(session)
+ self.assertEqual(
+ timestamps['partialWakelock'][parser.START_TIMESTAMP],
+ 1567029917802)
+ self.assertEqual(
+ timestamps['partialWakelock'][parser.END_TIMESTAMP], 1567029932879)
+
if __name__ == '__main__':
unittest.main()