1#!/usr/bin/python3
2#
3# Copyright (C) 2023 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License"); you may not
6# use this file except in compliance with the License. You may obtain a copy of
7# the License at
8#
9#      http://www.apache.org/licenses/LICENSE-2.0
10#
11# Unless required by applicable law or agreed to in writing, software
12# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14# License for the specific language governing permissions and limitations under
15# the License.
16#
17import unittest
18import aggregate_cts_reports
19
20
21class TestParse(unittest.TestCase):
22
23  def test_aggregate(self):
24    report_files = ['testdata/test_result_1.xml', 'testdata/test_result_2.xml']
25    report = aggregate_cts_reports.aggregate_cts_reports(report_files)
26
27    self.check_ctsreport(report)
28
29  def check_ctsreport(self, report):
30    self.assertEqual(
31        report.get_test_status('module_1', 'arm64-v8a', 'testcase_1', 'test_1'),
32        'pass',
33    )
34    self.assertEqual(
35        report.get_test_status('module_1', 'arm64-v8a', 'testcase_1', 'test_2'),
36        'fail',
37    )
38    self.assertEqual(
39        report.get_test_status('module_2', 'arm64-v8a', 'testcase_2', 'test_3'),
40        'pass',
41    )
42    self.assertEqual(
43        report.get_test_status('module_2', 'arm64-v8a', 'testcase_3', 'test_4'),
44        'ASSUMPTION_FAILURE',
45    )
46    self.assertEqual(
47        report.get_test_status('module_2', 'arm64-v8a', 'testcase_3', 'test_5'),
48        'fail',
49    )
50    self.assertEqual(
51        report.get_test_status('module_2', 'arm64-v8a', 'testcase_4', 'test_6'),
52        'pass',
53    )
54    self.assertEqual(
55        report.get_test_status('module_2', 'arm64-v8a', 'testcase_4', 'test_7'),
56        'pass',
57    )
58    self.assertEqual(
59        report.get_test_status('module_2', 'arm64-v8a', 'testcase_4', 'test_8'),
60        'fail',
61    )
62    self.assertEqual(
63        report.get_test_status('module_3', 'arm64-v8a', 'testcase_5', 'test_9'),
64        'pass',
65    )
66    self.assertEqual(
67        report.get_test_status(
68            'module_3', 'arm64-v8a', 'testcase_5', 'test_10'
69        ),
70        'TEST_ERROR',
71    )
72    self.assertEqual(
73        report.get_test_status(
74            'module_3', 'arm64-v8a', 'testcase_5', 'test_11'
75        ),
76        'pass',
77    )
78    self.assertEqual(
79        report.get_test_status(
80            'module_4', 'arm64-v8a', 'testcase_6', 'test_12'
81        ),
82        'fail',
83    )
84
85    self.assertEqual(report.info['build_model'], 'this_model')
86    self.assertEqual(report.info['build_id'], '1412')
87    self.assertEqual(report.info['build_fingerprint'], 'this_build_fingerprint')
88    self.assertEqual(report.info['build_device'], 'this_device')
89    self.assertEqual(report.info['build_version_sdk'], '34')
90    self.assertEqual(report.info['build_version_security_patch'], '2023-06-05')
91    self.assertEqual(report.info['build_board'], 'this_board')
92    self.assertEqual(report.info['build_type'], 'userdebug')
93    self.assertEqual(report.info['build_version_release'], '14')
94    self.assertEqual(report.info['suite_name'], 'CTS')
95    self.assertEqual(report.info['suite_version'], '14_r1')
96    self.assertEqual(report.info['suite_plan'], 'cts')
97    self.assertEqual(report.info['suite_build_number'], '1234567')
98
99    module_summaries = report.module_summaries
100    summary = module_summaries['module_1']['arm64-v8a']
101    self.assertEqual(summary.counter['pass'], 1)
102    self.assertEqual(summary.counter['fail'], 1)
103
104    summary = module_summaries['module_2']['arm64-v8a']
105    self.assertEqual(summary.counter['pass'], 3)
106    self.assertEqual(
107        summary.counter['ASSUMPTION_FAILURE'],
108        1,
109    )
110    self.assertEqual(summary.counter['fail'], 2)
111
112    summary = module_summaries['module_3']['arm64-v8a']
113    self.assertEqual(summary.counter['pass'], 2)
114    self.assertEqual(summary.counter['TEST_ERROR'], 1)
115
116    summary = module_summaries['module_4']['arm64-v8a']
117    self.assertEqual(summary.counter['fail'], 1)
118
119
120if __name__ == '__main__':
121  unittest.main()
122