# -*- coding: utf-8 -*-
# $Id$
"""
VirtualBox Validation Kit - Python Bindings Test #1
"""
__copyright__ = \
"""
Copyright (C) 2010-2014 Oracle Corporation
This file is part of VirtualBox Open Source Edition (OSE), as
available from http://www.virtualbox.org. This file is free software;
General Public License (GPL) as published by the Free Software
Foundation, in version 2 as it comes in the "COPYING" file of the
VirtualBox OSE distribution. VirtualBox OSE is distributed in the
hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
The contents of this file may alternatively be used under the terms
of the Common Development and Distribution License Version 1.0
(CDDL) only, as it comes in the "COPYING.CDDL" file of the
VirtualBox OSE distribution, in which case the provisions of the
CDDL are applicable instead of those of the GPL.
You may elect to license modified versions of this file under the
terms and conditions of either the GPL or the CDDL or both.
"""
# Standard Python imports.
import os
import sys
import time
import threading
import types
# Only the main script needs to modify the path.
try: __file__
g_ksValidationKitDir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__))));
# Validation Kit imports.
"""
Python Bindings Test #1.
"""
#
# Overridden methods.
#
"""
Import the API.
"""
if not self.importVBoxApi():
return False;
return True;
"""
Execute the testcase.
"""
return self.testEventQueueWaiting() \
and self.testEventQueueInterrupt();
#
# Test execution helpers.
#
""" Thread procedure for checking that waitForEvents fails when not called by the main thread. """
try:
except:
return True;
reporter.error('waitForEvents() returned "%s" when called on a worker thread, expected exception.' % (rc2,));
return False;
"""
Test event queue waiting.
"""
# Check return values and such.
iLoop = 0;
while True:
try:
except:
break;
break;
if rc == 1:
break;
if rc != 0:
break;
iLoop += 1;
if iLoop > 10240:
% (iLoop,));
break;
break;
# Check that we get an exception when trying to call the method from
# a different thread.
""" Thread procedure that's used for waking up the main thread. """
try:
except:
else:
return True;
reporter.error('interruptWaitEvents returned "%s" when called from other thread, expected True' % (rc2,));
return False;
"""
Test interrupting an event queue wait.
"""
# interrupt ourselves first and check the return value.
try:
except:
break;
break
#
# Interrupt a waitForEvents call.
#
# This test ASSUMES that no other events are posted to the thread's
# event queue once we've drained it. Also ASSUMES the box is
# relatively fast and not too busy because we're timing sensitive.
#
# Try quiesce the event queue.
# Create a thread that will interrupt us in 2 seconds.
try:
except:
break;
cMsTimeout = 20000;
if i == 2:
cMsTimeout = -1;
elif i == 3:
cMsTimeout = -999999;
# Do the wait.
try:
except:
else:
# Check the return code and elapsed time.
elif rc != 1:
if msElapsed > 15000:
elif msElapsed < 100:
oThread = None;
break;
if __name__ == '__main__':