VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/analysis/diff.py@ 96407

Last change on this file since 96407 was 96407, checked in by vboxsync, 2 years ago

scm copyright and license note update

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 3.8 KB
Line 
1# -*- coding: utf-8 -*-
2# $Id: diff.py 96407 2022-08-22 17:43:14Z vboxsync $
3
4"""
5Diff two test sets.
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2010-2022 Oracle and/or its affiliates.
11
12This file is part of VirtualBox base platform packages, as
13available from https://www.virtualbox.org.
14
15This program is free software; you can redistribute it and/or
16modify it under the terms of the GNU General Public License
17as published by the Free Software Foundation, in version 3 of the
18License.
19
20This program is distributed in the hope that it will be useful, but
21WITHOUT ANY WARRANTY; without even the implied warranty of
22MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23General Public License for more details.
24
25You should have received a copy of the GNU General Public License
26along with this program; if not, see <https://www.gnu.org/licenses>.
27
28The contents of this file may alternatively be used under the terms
29of the Common Development and Distribution License Version 1.0
30(CDDL), a copy of it is provided in the "COPYING.CDDL" file included
31in the VirtualBox distribution, in which case the provisions of the
32CDDL are applicable instead of those of the GPL.
33
34You may elect to license modified versions of this file under the
35terms and conditions of either the GPL or the CDDL or both.
36
37SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
38"""
39__version__ = "$Revision: 96407 $"
40__all__ = ['BaselineDiff', ];
41
42
43def _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
54def _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
63def 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;
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette