cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# -*- coding: utf-8 -*-
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync# $Id$
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncDiff two test sets.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__copyright__ = \
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCopyright (C) 2010-2014 Oracle Corporation
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThis file is part of VirtualBox Open Source Edition (OSE), as
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncavailable from http://www.virtualbox.org. This file is free software;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncyou can redistribute it and/or modify it under the terms of the GNU
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncGeneral Public License (GPL) as published by the Free Software
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncFoundation, in version 2 as it comes in the "COPYING" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution. VirtualBox OSE is distributed in the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsynchope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncThe contents of this file may alternatively be used under the terms
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncof the Common Development and Distribution License Version 1.0
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync(CDDL) only, as it comes in the "COPYING.CDDL" file of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncVirtualBox OSE distribution, in which case the provisions of the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncCDDL are applicable instead of those of the GPL.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncYou may elect to license modified versions of this file under the
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncterms and conditions of either the GPL or the CDDL or both.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync"""
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__version__ = "$Revision$"
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync__all__ = ['BaselineDiff', ];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncdef _findBaselineTest(oBaseline, oTest):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Recursively finds the the test in oBaseline corresponding to oTest. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oTest.oParent is None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oBaseline;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBaseline = _findBaselineTest(oBaseline, oTest.oParent);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oBaseline is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oBaseTest in oBaseline.aoChildren:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oBaseTest.sName == oTest.sName:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oBaseTest;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncdef _findBaselineTestValue(oBaseline, oValue):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """ Finds the baseline value corresponding to oValue. """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBaseTest = _findBaselineTest(oBaseline, oValue.oTest);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oBaseTest is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for oBaseValue in oBaseTest.aoValues:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oBaseValue.sName == oValue.sName:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oBaseValue;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return None;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsyncdef baselineDiff(oTestTree, oBaseline):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Diffs oTestTree against oBaseline, adding diff info to oTestTree.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync Returns oTestTree on success, None on failure (complained already).
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync """
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoStack = [];
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoStack.append((oTestTree, 0));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync while len(aoStack) > 0:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCurTest, iChild = aoStack.pop();
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # depth first
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if iChild < len(oCurTest.aoChildren):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoStack.append((oCurTest, iChild + 1));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync aoStack.append((oCurTest.aoChildren[iChild], 0));
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync continue;
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync # do value diff.
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync for i in range(len(oCurTest.aoValues)):
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oBaseVal = _findBaselineTestValue(oBaseline, oCurTest.aoValues[i]);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oBaseVal is not None:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync lBase = long(oBaseVal.sValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync lTest = long(oCurTest.aoValues[i].sValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync try:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if oBaseVal.sValue == oCurTest.aoValues[i].sValue:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCurTest.aoValues[i].sValue += '|';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCurTest.aoValues[i].sValue += '|%s' % (oBaseVal.sValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync except:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCurTest.aoValues[i].sValue += '|%s' % (oBaseVal.sValue);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync if lTest > lBase:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCurTest.aoValues[i].sValue += '|+%u' % (lTest - lBase);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync elif lTest < lBase:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCurTest.aoValues[i].sValue += '|-%u' % (lBase - lTest);
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCurTest.aoValues[i].sValue += '|0';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync else:
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync oCurTest.aoValues[i].sValue += '|N/A';
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync
cf22150eaeeb72431bf1cf65c309a431454fb22bvboxsync return oTestTree;