1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: diff.py 96407 2022-08-22 17:43:14Z vboxsync $
|
---|
3 |
|
---|
4 | """
|
---|
5 | Diff two test sets.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2010-2022 Oracle and/or its affiliates.
|
---|
11 |
|
---|
12 | This file is part of VirtualBox base platform packages, as
|
---|
13 | available from https://www.virtualbox.org.
|
---|
14 |
|
---|
15 | This program is free software; you can redistribute it and/or
|
---|
16 | modify it under the terms of the GNU General Public License
|
---|
17 | as published by the Free Software Foundation, in version 3 of the
|
---|
18 | License.
|
---|
19 |
|
---|
20 | This program is distributed in the hope that it will be useful, but
|
---|
21 | WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
22 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
23 | General Public License for more details.
|
---|
24 |
|
---|
25 | You should have received a copy of the GNU General Public License
|
---|
26 | along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
27 |
|
---|
28 | The contents of this file may alternatively be used under the terms
|
---|
29 | of the Common Development and Distribution License Version 1.0
|
---|
30 | (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
31 | in the VirtualBox distribution, in which case the provisions of the
|
---|
32 | CDDL are applicable instead of those of the GPL.
|
---|
33 |
|
---|
34 | You may elect to license modified versions of this file under the
|
---|
35 | terms and conditions of either the GPL or the CDDL or both.
|
---|
36 |
|
---|
37 | SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
38 | """
|
---|
39 | __version__ = "$Revision: 96407 $"
|
---|
40 | __all__ = ['BaselineDiff', ];
|
---|
41 |
|
---|
42 |
|
---|
43 | def _findBaselineTest(oBaseline, oTest):
|
---|
44 | """ Recursively finds the test in oBaseline corresponding to oTest. """
|
---|
45 | if oTest.oParent is None:
|
---|
46 | return oBaseline;
|
---|
47 | oBaseline = _findBaselineTest(oBaseline, oTest.oParent);
|
---|
48 | if oBaseline is not None:
|
---|
49 | for oBaseTest in oBaseline.aoChildren:
|
---|
50 | if oBaseTest.sName == oTest.sName:
|
---|
51 | return oBaseTest;
|
---|
52 | return None;
|
---|
53 |
|
---|
54 | def _findBaselineTestValue(oBaseline, oValue):
|
---|
55 | """ Finds the baseline value corresponding to oValue. """
|
---|
56 | oBaseTest = _findBaselineTest(oBaseline, oValue.oTest);
|
---|
57 | if oBaseTest is not None:
|
---|
58 | for oBaseValue in oBaseTest.aoValues:
|
---|
59 | if oBaseValue.sName == oValue.sName:
|
---|
60 | return oBaseValue;
|
---|
61 | return None;
|
---|
62 |
|
---|
63 | def baselineDiff(oTestTree, oBaseline):
|
---|
64 | """
|
---|
65 | Diffs oTestTree against oBaseline, adding diff info to oTestTree.
|
---|
66 | Returns oTestTree on success, None on failure (complained already).
|
---|
67 | """
|
---|
68 |
|
---|
69 | aoStack = [];
|
---|
70 | aoStack.append((oTestTree, 0));
|
---|
71 | while len(aoStack) > 0:
|
---|
72 | oCurTest, iChild = aoStack.pop();
|
---|
73 |
|
---|
74 | # depth first
|
---|
75 | if iChild < len(oCurTest.aoChildren):
|
---|
76 | aoStack.append((oCurTest, iChild + 1));
|
---|
77 | aoStack.append((oCurTest.aoChildren[iChild], 0));
|
---|
78 | continue;
|
---|
79 |
|
---|
80 | # do value diff.
|
---|
81 | for i in range(len(oCurTest.aoValues)):
|
---|
82 | oBaseVal = _findBaselineTestValue(oBaseline, oCurTest.aoValues[i]);
|
---|
83 | if oBaseVal is not None:
|
---|
84 | try:
|
---|
85 | lBase = long(oBaseVal.sValue);
|
---|
86 | lTest = long(oCurTest.aoValues[i].sValue);
|
---|
87 | except:
|
---|
88 | try:
|
---|
89 | if oBaseVal.sValue == oCurTest.aoValues[i].sValue:
|
---|
90 | oCurTest.aoValues[i].sValue += '|';
|
---|
91 | else:
|
---|
92 | oCurTest.aoValues[i].sValue += '|%s' % (oBaseVal.sValue);
|
---|
93 | except:
|
---|
94 | oCurTest.aoValues[i].sValue += '|%s' % (oBaseVal.sValue);
|
---|
95 | else:
|
---|
96 | if lTest > lBase:
|
---|
97 | oCurTest.aoValues[i].sValue += '|+%u' % (lTest - lBase);
|
---|
98 | elif lTest < lBase:
|
---|
99 | oCurTest.aoValues[i].sValue += '|-%u' % (lBase - lTest);
|
---|
100 | else:
|
---|
101 | oCurTest.aoValues[i].sValue += '|0';
|
---|
102 | else:
|
---|
103 | oCurTest.aoValues[i].sValue += '|N/A';
|
---|
104 |
|
---|
105 | return oTestTree;
|
---|