• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!/usr/bin/env python
2#
3# Copyright (C) 2016 The Android Open Source Project
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# You may obtain a copy of 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,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#
17
18import os
19import unittest
20
21from vts.utils.python.coverage import arc_summary
22from vts.utils.python.coverage import block_summary
23from vts.utils.python.coverage import function_summary
24
25
26class FunctionSummaryTest(unittest.TestCase):
27    """Tests for FunctionSummary of vts.utils.python.coverage.
28    """
29
30    def setUp(self):
31        """Creates a function summary and a chain of blocks.
32
33        Creates an arc between adjacent blocks. All arcs are left with default
34        values (unresolved, count of 0).
35        """
36        self.n = 10
37        self.count = 5
38        self.function_summary = function_summary.FunctionSummary(0, 'test',
39                                                                 'test.c', 0)
40        self.function_summary.blocks = [block_summary.BlockSummary(i, 0)
41                                        for i in range(self.n)]
42        self.arcs = []
43        for i in range(1, self.n):
44            arc = arc_summary.ArcSummary(self.function_summary.blocks[i - 1],
45                                         self.function_summary.blocks[i], 0)
46            self.function_summary.blocks[i - 1].exit_arcs.append(arc)
47            self.function_summary.blocks[i].entry_arcs.append(arc)
48            self.arcs.append(arc)
49
50    def testResolveChainStart(self):
51        """Tests for correct resolution in a long chain.
52
53        Test resolution for the case when there is a chain of unresolved arcs
54        after a resolved arc.
55        """
56        self.arcs[0].resolved = True
57        self.arcs[0].count = self.count
58
59        self.function_summary.Resolve()
60        for arc in self.arcs:
61            self.assertTrue(arc.resolved)
62            self.assertEqual(self.count, arc.count)
63            self.assertEqual(self.count, arc.src_block.count)
64            self.assertEqual(self.count, arc.dst_block.count)
65
66    def testResolveChainEnd(self):
67        """Tests for correct resolution in a long chain.
68
69        Test resolution for the case when there is a chain of unresolved arcs
70        before a resolved arc.
71        """
72        self.arcs[-1].resolved = True
73        self.arcs[-1].count = self.count
74
75        self.function_summary.Resolve()
76        for arc in self.arcs:
77            self.assertTrue(arc.resolved)
78            self.assertEqual(self.count, arc.count)
79            self.assertEqual(self.count, arc.src_block.count)
80            self.assertEqual(self.count, arc.dst_block.count)
81
82    def testResolveFailure(self):
83        """Tests for failure when no progress can be made.
84
85        Test that Resolve() returns False when there is not enough information
86        to resolve any arcs.
87        """
88        self.assertFalse(self.function_summary.Resolve())
89
90
91if __name__ == "__main__":
92    unittest.main()
93