GfxApiLogger: change codegen scripts to use relative import
... so that we can easily run all unittests by
python -m unittest discover -s scripts -p "*test.py"
Also change how stream error is created.
Test: run the unit test
Change-Id: I882e618c970279d0b3401795d1954c67fd4831db
diff --git a/scripts/gles3translatorgen/__init__.py b/scripts/gles3translatorgen/__init__.py
index 1184512..52d6c75 100644
--- a/scripts/gles3translatorgen/__init__.py
+++ b/scripts/gles3translatorgen/__init__.py
@@ -1,2 +1,17 @@
-import gles30_custom
-import gles31_custom
+#
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+from . import gles30_custom
+from . import gles31_custom
diff --git a/scripts/print_gfx_logs/__init__.py b/scripts/print_gfx_logs/__init__.py
new file mode 100644
index 0000000..04b9604
--- /dev/null
+++ b/scripts/print_gfx_logs/__init__.py
@@ -0,0 +1,14 @@
+#
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
diff --git a/scripts/print_gfx_logs/command_printer.py b/scripts/print_gfx_logs/command_printer.py
index 4c76cb2..f5f7934 100644
--- a/scripts/print_gfx_logs/command_printer.py
+++ b/scripts/print_gfx_logs/command_printer.py
@@ -1,9 +1,24 @@
+#
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import io
import sys
import textwrap
from typing import Dict, Optional
-import vulkan_printer
-import opcodes
+from . import vulkan_printer
+from . import opcodes
import struct
diff --git a/scripts/print_gfx_logs/comand_printer_test.py b/scripts/print_gfx_logs/command_printer_test.py
similarity index 97%
rename from scripts/print_gfx_logs/comand_printer_test.py
rename to scripts/print_gfx_logs/command_printer_test.py
index 70f68e4..106b5f7 100644
--- a/scripts/print_gfx_logs/comand_printer_test.py
+++ b/scripts/print_gfx_logs/command_printer_test.py
@@ -1,10 +1,25 @@
+#
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
import io
import unittest
from typing import Dict
-import opcodes
-from scripts.print_gfx_logs import command_printer
+from . import opcodes
+from . import command_printer
reverse_opcodes: Dict[str, int] = {v: k for k, v in opcodes.opcodes.items()}
diff --git a/scripts/print_gfx_logs/print_gfx_logs.py b/scripts/print_gfx_logs/print_gfx_logs.py
index 76854e6..3f50014 100644
--- a/scripts/print_gfx_logs/print_gfx_logs.py
+++ b/scripts/print_gfx_logs/print_gfx_logs.py
@@ -1,3 +1,18 @@
+#
+# Copyright (C) 2022 The Android Open Source Project
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
"""
Command line tool to process minidump files and print what was logged by GfxApiLogger.
@@ -12,13 +27,13 @@
python3 print_gfx_logs.py <path to minidump file>
"""
-import argparse
+from __future__ import annotations
import ctypes
import sys
from datetime import datetime
import mmap
import textwrap
-import command_printer
+from . import command_printer
from typing import NamedTuple, Optional, List
import traceback
@@ -53,6 +68,12 @@
commands: List[Command]
error_message: Optional[str] # `None` if there were no errors parsing this stream
+ @staticmethod
+ def error(pos_in_file: int, error_message: str) -> Stream:
+ return Stream(
+ pos_in_file=pos_in_file, timestamp=0, thread_id=0, capture_id=0, commands=[],
+ error_message=error_message)
+
def read_uint32(buf: bytes, pos: int) -> int:
"""Reads a single uint32 from buf at a given position"""
@@ -74,11 +95,14 @@
ctypes.memmove(ctypes.addressof(header), header_bytes, ctypes.sizeof(header))
if header.signature != b'GFXAPILOG':
- return Stream(file_pos, error_message="Signature doesn't match")
+ return Stream.error(file_pos, error_message="Signature doesn't match")
if header.version != 2:
- return Stream(file_pos, error_message=("This script can only process version 2 of the graphics API logs, " +
- "but the dump file uses version {} ").format(data.version))
+ return Stream.error(
+ file_pos,
+ error_message=(
+ "This script can only process version 2 of the graphics API logs, but the dump "
+ + "file uses version {} ").format(data.version))
# Convert Windows' GetSystemTimeAsFileTime to Unix timestamp
# https://stackoverflow.com/questions/1695288/getting-the-current-time-in-milliseconds-from-the-system-clock-in-windows
@@ -87,12 +111,16 @@
# Sanity check the size
if header.data_size > 5_000_000:
- return Stream(file_pos,
- error_message="data size is larger than 5MB. This likely indicates garbage/corrupted data")
+ return Stream.error(
+ file_pos,
+ error_message="data size is larger than 5MB. This likely indicates garbage/corrupted " +
+ "data")
if header.committed_index >= header.data_size:
- return Stream(file_pos,
- error_message="index is larger than buffer size. Likely indicates garbage/corrupted data")
+ return Stream.error(
+ file_pos,
+ error_message="index is larger than buffer size. Likely indicates garbage/corrupted " +
+ "data")
file_bytes.seek(file_pos + ctypes.sizeof(header))
data = file_bytes.read(header.data_size)