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