0

SuperSize: Added test file for dex_disassembly.py.

Bug: 1302759
Change-Id: Ie6a444589155c0c5b462915ad2dbbd24fdf9e706
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3517727
Reviewed-by: Andrew Grieve <agrieve@chromium.org>
Commit-Queue: Vigaash Sivasothy <vigaash@google.com>
Cr-Commit-Position: refs/heads/main@{#980225}
This commit is contained in:
Vigaash Sivasothy
2022-03-11 19:51:30 +00:00
committed by Chromium LUCI CQ
parent 612f1efd4e
commit 351cc6830b
2 changed files with 256 additions and 0 deletions
tools/binary_size/libsupersize

@@ -0,0 +1,118 @@
#!/usr/bin/env python3
# Copyright 2022 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import os
import unittest
import dex_disassembly
import test_util
_TEST_DATA_DIR = test_util.TEST_DATA_DIR
class DexDisassemblyTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
with open(os.path.join(_TEST_DATA_DIR, 'R8_Disassembler_Output.txt'),
'r') as f:
cls.classes_map = dex_disassembly._ParseDisassembly(f.read())
def testParseClassName(self):
"""Test parsing the class names."""
expected_info_list = [
'org.chromium.chrome.browser.customtabs.' +
'CustomTabDelegateFactory$$Lambda$5',
'org.chromium.chrome.browser.app.appmenu.IncognitoMenuItemViewBinder$1',
'com.youtube.elements.fbs.AnimatedVectorType'
]
self.assertEqual(expected_info_list, list(self.classes_map))
def testParseMethodList(self):
"""Test parsing the method names for a class."""
expected_info_list_class1 = ['<init>', 'get']
expected_info_list_class2 = []
expected_info_list_class3 = [
'<init>', 'animation', 'frameState', 'progressState'
]
self.assertEqual(expected_info_list_class1, [
method.name for method in
self.classes_map['org.chromium.chrome.browser.customtabs.' +
'CustomTabDelegateFactory$$Lambda$5'].methods
])
self.assertEqual(expected_info_list_class2, [
method.name for method in
self.classes_map['org.chromium.chrome.browser.app.appmenu.' +
'IncognitoMenuItemViewBinder$1'].methods
])
self.assertEqual(expected_info_list_class3, [
method.name for method in
self.classes_map['com.youtube.elements.fbs.AnimatedVectorType'].methods
])
def testParseMethodReturnType(self):
"""Test parsing the return type for each method."""
# Note the return types are obfuscated.
expected_info_list_class1 = ['void', 'java.lang.Object']
expected_info_list_class2 = []
expected_info_list_class3 = ['void', 'bb', 'Va', 'Wa']
self.assertEqual(expected_info_list_class1, [
method.return_type for method in self.classes_map[
'org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory' +
'$$Lambda$5'].methods
])
self.assertEqual(expected_info_list_class2, [
method.return_type
for method in self.classes_map['org.chromium.chrome.browser.app.appmenu'
+
'.IncognitoMenuItemViewBinder$1'].methods
])
self.assertEqual(expected_info_list_class3, [
method.return_type for method in
self.classes_map['com.youtube.elements.fbs.AnimatedVectorType'].methods
])
def testParseMethodParamType(self):
"""Test parsing the parameters type for each method."""
# Note the return types are obfuscated.
expected_info_list_class1 = [[], []]
expected_info_list_class2 = []
expected_info_list_class3 = [[], [], ['java.lang.Object', 'int', 'byte[]'],
['java.lang.Object']]
self.assertEqual(expected_info_list_class1, [
method.param_types for method in self.classes_map[
'org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory' +
'$$Lambda$5'].methods
])
self.assertEqual(expected_info_list_class2, [
method.param_types for method in
self.classes_map['org.chromium.chrome.browser.app.appmenu.' +
'IncognitoMenuItemViewBinder$1'].methods
])
self.assertEqual(expected_info_list_class3, [
method.param_types for method in
self.classes_map['com.youtube.elements.fbs.AnimatedVectorType'].methods
])
def testParseMethodBytecode(self):
"""Test parsing a stand alone class."""
# Note the return types are obfuscated.
expected_info = [
'registers: 1, inputs: 1, outputs: 1\n',
'------------------------------------------------------------\n',
'inst# offset instruction arguments\n',
'------------------------------------------------------------\n',
' 0: 0x00: InvokeDirect { v0 } org.chromium.base.' +
'supplier.Supplier$$CC void <init>()\n', ' 1: 0x03: ReturnVoid\n'
]
self.assertEqual(
expected_info, self.classes_map[
'org.chromium.chrome.browser.customtabs.' +
'CustomTabDelegateFactory$$Lambda$5']._FindMethodByteCode(
'org.chromium.chrome.browser.customtabs.' +
'CustomTabDelegateFactory$$Lambda$5', '<init>', [], 'void'))
if __name__ == '__main__':
unittest.main()

@@ -0,0 +1,138 @@
# Bytecode for
# Class: 'org.chromium.chrome.browser.customtabs.CustomTabDelegateFactory$$Lambda$5'
#
# Method: '<init>':
# public
#
void Xa0.<init>()
registers: 1, inputs: 1, outputs: 1
------------------------------------------------------------
inst# offset instruction arguments
------------------------------------------------------------
0: 0x00: InvokeDirect { v0 } org.chromium.base.supplier.Supplier$$CC void <init>()
1: 0x03: ReturnVoid
#
# Method: 'get':
# public
#
java.lang.Object Xa0.get()
registers: 2, inputs: 1, outputs: 0
------------------------------------------------------------
inst# offset instruction arguments
------------------------------------------------------------
0: 0x00: Const4 v0, 0x0 (0)
1: 0x01: ReturnObject v0
# Bytecode for
# Class: 'org.chromium.chrome.browser.app.appmenu.IncognitoMenuItemViewBinder$1'
# Bytecode for
# Class: 'com.youtube.elements.fbs.AnimatedVectorType'
#
# Method: '<init>':
# public
#
void Xa.<init>()
registers: 1, inputs: 1, outputs: 1
------------------------------------------------------------
inst# offset instruction arguments
------------------------------------------------------------
0x00, line 1, locals: [0 -> this]
0: 0x00: InvokeDirect { v0 } com.google.flatbuffers.Table void <init>()
1: 0x03: ReturnVoid
#
# Method: 'animation':
# public
#
bb Xa.h()
registers: 4, inputs: 1, outputs: 3
------------------------------------------------------------
inst# offset instruction arguments
------------------------------------------------------------
0x00, line 1, locals: [3 -> this]
0: 0x00: NewInstance v0, com.youtube.elements.fbs.AnimatedVectorTypeSource
1: 0x02: InvokeDirect { v0 } com.youtube.elements.fbs.AnimatedVectorTypeSource void <init>()
2: 0x05: Const4 v1, 0x4 (4)
0x06, line 2, locals: [3 -> this]
3: 0x06: InvokeVirtual { v3 v1 } com.google.flatbuffers.Table int __offset(int)
4: 0x09: MoveResult v1
5: 0x0a: IfEqz v1, 0x19 (+15)
6: 0x0c: Iget v2, v3, com.google.flatbuffers.Table int bb_pos
7: 0x0e: AddInt2Addr v1, v2
8: 0x0f: InvokeVirtual { v3 v1 } com.google.flatbuffers.Table int __indirect(int)
9: 0x12: MoveResult v1
10: 0x13: IgetObject v2, v3, com.google.flatbuffers.Table java.nio.ByteBuffer bb
0x15, line 3, locals: [3 -> this]
11: 0x15: InvokeVirtual { v0 v1 v2 } com.google.flatbuffers.Table void __reset(int,java.nio.ByteBuffer)
12: 0x18: Goto 0x1a (+2)
13: 0x19: Const4 v0, 0x0 (0)
14: 0x1a: ReturnObject v0
#
# Method: 'frameState':
# public
#
Va Xa.i(java.lang.Object, int, byte[])
registers: 4, inputs: 1, outputs: 3
------------------------------------------------------------
inst# offset instruction arguments
------------------------------------------------------------
0x00, line 1, locals: [3 -> this]
0: 0x00: NewInstance v0, com.youtube.elements.fbs.AnimatedVectorFrameState
1: 0x02: InvokeDirect { v0 } com.youtube.elements.fbs.AnimatedVectorFrameState void <init>()
2: 0x05: Const16 v1, 0x0014 (20)
0x07, line 2, locals: [3 -> this]
3: 0x07: InvokeVirtual { v3 v1 } com.google.flatbuffers.Table int __offset(int)
4: 0x0a: MoveResult v1
5: 0x0b: IfEqz v1, 0x1a (+15)
6: 0x0d: Iget v2, v3, com.google.flatbuffers.Table int bb_pos
7: 0x0f: AddInt2Addr v1, v2
8: 0x10: InvokeVirtual { v3 v1 } com.google.flatbuffers.Table int __indirect(int)
9: 0x13: MoveResult v1
10: 0x14: IgetObject v2, v3, com.google.flatbuffers.Table java.nio.ByteBuffer bb
0x16, line 3, locals: [3 -> this]
11: 0x16: InvokeVirtual { v0 v1 v2 } com.google.flatbuffers.Table void __reset(int,java.nio.ByteBuffer)
12: 0x19: Goto 0x1b (+2)
13: 0x1a: Const4 v0, 0x0 (0)
14: 0x1b: ReturnObject v0
#
# Method: 'progressState':
# public
#
Wa Xa.j(java.lang.Object)
registers: 4, inputs: 1, outputs: 3
------------------------------------------------------------
inst# offset instruction arguments
------------------------------------------------------------
0x00, line 1, locals: [3 -> this]
0: 0x00: NewInstance v0, com.youtube.elements.fbs.AnimatedVectorProgressState
1: 0x02: InvokeDirect { v0 } com.youtube.elements.fbs.AnimatedVectorProgressState void <init>()
2: 0x05: Const16 v1, 0x0012 (18)
0x07, line 2, locals: [3 -> this]
3: 0x07: InvokeVirtual { v3 v1 } com.google.flatbuffers.Table int __offset(int)
4: 0x0a: MoveResult v1
5: 0x0b: IfEqz v1, 0x1a (+15)
6: 0x0d: Iget v2, v3, com.google.flatbuffers.Table int bb_pos
7: 0x0f: AddInt2Addr v1, v2
8: 0x10: InvokeVirtual { v3 v1 } com.google.flatbuffers.Table int __indirect(int)
9: 0x13: MoveResult v1
10: 0x14: IgetObject v2, v3, com.google.flatbuffers.Table java.nio.ByteBuffer bb
0x16, line 3, locals: [3 -> this]
11: 0x16: InvokeVirtual { v0 v1 v2 } com.google.flatbuffers.Table void __reset(int,java.nio.ByteBuffer)
12: 0x19: Goto 0x1b (+2)
13: 0x1a: Const4 v0, 0x0 (0)
14: 0x1b: ReturnObject v0