diff options
Diffstat (limited to 'tools/checker/file_format/c1visualizer/test.py')
-rw-r--r-- | tools/checker/file_format/c1visualizer/test.py | 114 |
1 files changed, 93 insertions, 21 deletions
diff --git a/tools/checker/file_format/c1visualizer/test.py b/tools/checker/file_format/c1visualizer/test.py index 812a4cf9ce..8c3cce4a4c 100644 --- a/tools/checker/file_format/c1visualizer/test.py +++ b/tools/checker/file_format/c1visualizer/test.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # # Copyright (C) 2014 The Android Open Source Project # @@ -14,34 +14,38 @@ # See the License for the specific language governing permissions and # limitations under the License. -from common.testing import ToUnicode -from file_format.c1visualizer.parser import ParseC1visualizerStream +from common.immutables import ImmutableDict +from file_format.c1visualizer.parser import parse_c1_visualizer_stream from file_format.c1visualizer.struct import C1visualizerFile, C1visualizerPass import io import unittest + class C1visualizerParser_Test(unittest.TestCase): - def createFile(self, passList): + def create_file(self, data): """ Creates an instance of CheckerFile from provided info. - Data format: [ ( <case-name>, [ ( <text>, <assert-variant> ), ... ] ), ... ] + Data format: ( [ <isa-feature>, ... ], + [ ( <case-name>, [ ( <text>, <assert-variant> ), ... ] ), ... ] + ) """ - c1File = C1visualizerFile("<c1_file>") - for passEntry in passList: - passName = passEntry[0] - passBody = passEntry[1] - c1Pass = C1visualizerPass(c1File, passName, passBody, 0) - return c1File + c1_file = C1visualizerFile("<c1_file>") + c1_file.instruction_set_features = data[0] + for pass_entry in data[1]: + pass_name = pass_entry[0] + pass_body = pass_entry[1] + c1_pass = C1visualizerPass(c1_file, pass_name, pass_body, 0) + return c1_file - def assertParsesTo(self, c1Text, expectedData): - expectedFile = self.createFile(expectedData) - actualFile = ParseC1visualizerStream("<c1_file>", io.StringIO(ToUnicode(c1Text))) - return self.assertEqual(expectedFile, actualFile) + def assertParsesTo(self, c1_text, expected_data): + expected_file = self.create_file(expected_data) + actual_file = parse_c1_visualizer_stream("<c1_file>", io.StringIO(c1_text)) + return self.assertEqual(expected_file, actual_file) def test_EmptyFile(self): - self.assertParsesTo("", []) + self.assertParsesTo("", (ImmutableDict(), [])) def test_SingleGroup(self): self.assertParsesTo( @@ -55,7 +59,9 @@ class C1visualizerParser_Test(unittest.TestCase): bar end_cfg """, - [ ( "MyMethod pass1", [ "foo", "bar" ] ) ]) + (ImmutableDict(), [ + ("MyMethod pass1", ["foo", "bar"]) + ])) def test_MultipleGroups(self): self.assertParsesTo( @@ -76,8 +82,10 @@ class C1visualizerParser_Test(unittest.TestCase): def end_cfg """, - [ ( "MyMethod1 pass1", [ "foo", "bar" ] ), - ( "MyMethod1 pass2", [ "abc", "def" ] ) ]) + (ImmutableDict(), [ + ("MyMethod1 pass1", ["foo", "bar"]), + ("MyMethod1 pass2", ["abc", "def"]) + ])) self.assertParsesTo( """ begin_compilation @@ -101,5 +109,69 @@ class C1visualizerParser_Test(unittest.TestCase): def end_cfg """, - [ ( "MyMethod1 pass1", [ "foo", "bar" ] ), - ( "MyMethod2 pass2", [ "abc", "def" ] ) ]) + (ImmutableDict(), [ + ("MyMethod1 pass1", ["foo", "bar"]), + ("MyMethod2 pass2", ["abc", "def"]) + ])) + + def test_InstructionSetFeatures(self): + self.assertParsesTo( + """ + begin_compilation + name "isa_features:feature1,-feature2" + method "isa_features:feature1,-feature2" + date 1234 + end_compilation + """, + (ImmutableDict({"feature1": True, "feature2": False}), [])) + self.assertParsesTo( + """ + begin_compilation + name "isa_features:feature1,-feature2" + method "isa_features:feature1,-feature2" + date 1234 + end_compilation + begin_compilation + name "xyz1" + method "MyMethod1" + date 1234 + end_compilation + begin_cfg + name "pass1" + foo + bar + end_cfg + """, + (ImmutableDict({"feature1": True, "feature2": False}), [ + ("MyMethod1 pass1", ["foo", "bar"]) + ])) + self.assertParsesTo( + """ + begin_compilation + name "isa:some_isa isa_features:feature1,-feature2" + method "isa:some_isa isa_features:feature1,-feature2" + date 1234 + end_compilation + """, + (ImmutableDict({"feature1": True, "feature2": False}), [])) + self.assertParsesTo( + """ + begin_compilation + name "isa:some_isa isa_features:feature1,-feature2" + method "isa:some_isa isa_features:feature1,-feature2" + date 1234 + end_compilation + begin_compilation + name "xyz1" + method "MyMethod1" + date 1234 + end_compilation + begin_cfg + name "pass1" + foo + bar + end_cfg + """, + (ImmutableDict({"feature1": True, "feature2": False}), [ + ("MyMethod1 pass1", ["foo", "bar"]) + ])) |