VirtualBox

Changeset 61553 in vbox for trunk


Ignore:
Timestamp:
Jun 7, 2016 9:05:29 PM (9 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
107892
Message:

vsheriff: Expiermenting with screenshot hashing.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/ValidationKit/testmanager/batch/virtual_test_sheriff.py

    r61551 r61553  
    4040import sys;
    4141import os;
     42import hashlib;
     43import StringIO;
    4244from optparse import OptionParser;
     45from PIL import Image;
    4346
    4447# Add Test Manager's modules path
     
    182185            self.oSheriff.vprint('Error opening the "%s" log file: %s' % (oFile.sFile, oSizeOrError,));
    183186        return sContent;
     187
     188    def getScreenshotSha256(self, oFile):
     189        """
     190        Tries to read the given screenshot file, uncompress it, and do SHA-2
     191        on the raw pixels.
     192        Returns SHA-2 digest string on success, None on failure.
     193        """
     194        (oFile, _, _) = self.oTestSet.openFile(oFile.sFile, 'rb');
     195        try:
     196            abImageFile = oFile.read();
     197        except Exception as oXcpt:
     198            self.oSheriff.vprint('Error reading the "%s" image file: %s' % (oFile.sFile, oXcpt,))
     199        else:
     200            try:
     201                oImage = Image.open(StringIO.StringIO(abImageFile));
     202            except Exception as oXcpt:
     203                self.oSheriff.vprint('Error opening the "%s" image bytes using PIL.Image.open: %s' % (oFile.sFile, oXcpt,))
     204            else:
     205                try:
     206                    oHash = hashlib.sha256();
     207                    oHash.update(oImage.tostring());
     208                except Exception as oXcpt:
     209                    self.oSheriff.vprint('Error hashing the uncompressed image bytes for "%s": %s' % (oFile.sFile, oXcpt,))
     210                else:
     211                    return oHash.hexdigest();
     212        return None;
     213
    184214
    185215
     
    377407    ## @name Failure reasons we know.
    378408    ## @{
     409    ktReason_BSOD_Recovery                             = ( 'BSOD',              'Recovery' );
    379410    ktReason_Guru_Generic                              = ( 'Guru Meditations',  'Generic Guru Meditation' );
    380411    ktReason_Guru_VERR_IEM_INSTR_NOT_IMPLEMENTED       = ( 'Guru Meditations',  'VERR_IEM_INSTR_NOT_IMPLEMENTED' );
     
    630661    ];
    631662
     663    ## Mapping screenshot/failure SHA-256 hashes to failure reasons.
     664    katSimpleScreenshotHashReasons = [
     665        # ( Whether to stop on hit, reason tuple, lowercased sha-256 of PIL.Image.tostring output )
     666        ( True,  ktReason_BSOD_Recovery,                    '576f8e38d62b311cac7e3dc3436a0d0b9bd8cfd7fa9c43aafa95631520a45eac' ),
     667    ];
     668
    632669    def investigateVMResult(self, oCaseFile, oFailedResult, sResultLog):
    633670        """
     
    699736            _ = sInfoText;
    700737
     738            # Continue with screen hashes.
     739            if sScreenHash is not None:
     740                for fStopOnHit, tReason, sHash in self.katSimpleScreenshotHashReasons:
     741                    if sScreenHash == sHash:
     742                        oCaseFile.noteReasonForId(tReason, oFailedResult.idTestResult);
     743                        if fStopOnHit:
     744                            return True;
     745                        fFoundSomething = True;
     746
    701747            #
    702748            # Check for repeated reboots...
     
    714760        # appear in the order that terminateVmBySession uploads them).
    715761        #
    716         sVMLog    = None;
    717         sKrnlLog  = None;
    718         sVgaText  = None;
    719         sInfoText = None;
     762        sVMLog      = None;
     763        sScreenHash = None;
     764        sKrnlLog    = None;
     765        sVgaText    = None;
     766        sInfoText   = None;
    720767        for oFile in oFailedResult.aoFiles:
    721768            if oFile.sKind == TestResultFileData.ksKind_LogReleaseVm:
     
    723770                    if investigateLogSet() is True:
    724771                        return True;
    725                 sKrnlLog  = None;
    726                 sVgaText  = None;
    727                 sInfoText = None;
    728                 sVMLog    = oCaseFile.getLogFile(oFile);
     772                sKrnlLog    = None;
     773                sScreenHash = None;
     774                sVgaText    = None;
     775                sInfoText   = None;
     776                sVMLog      = oCaseFile.getLogFile(oFile);
    729777            elif oFile.sKind == TestResultFileData.ksKind_LogGuestKernel:
    730778                sKrnlLog  = oCaseFile.getLogFile(oFile);
     
    733781            elif oFile.sKind == TestResultFileData.ksKind_InfoCollection:
    734782                sInfoText = oCaseFile.getLogFile(oFile);
     783            elif oFile.sKind == TestResultFileData.ksKind_ScreenshotFailure:
     784                sScreenHash = oCaseFile.getScreenshotSha256(oFile);
     785                if sScreenHash is not None:
     786                    sScreenHash = sScreenHash.tolower();
     787                    self.vprint('%s  %s' % ( sScreenHash, oFile.sFile,));
    735788        if sVMLog is not None and investigateLogSet() is True:
    736789            return True;
Note: See TracChangeset for help on using the changeset viewer.

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