VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/tests/usb/tst-utsgadget.py@ 70522

Last change on this file since 70522 was 70522, checked in by vboxsync, 7 years ago

ValidationKit: More python 3 adjustments. [fixes]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.3 KB
Line 
1# -*- coding: utf-8 -*-
2# $Id: tst-utsgadget.py 70522 2018-01-10 15:55:16Z vboxsync $
3
4"""
5Simple testcase for usbgadget2.py.
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2016-2017 Oracle Corporation
11
12This file is part of VirtualBox Open Source Edition (OSE), as
13available from http://www.virtualbox.org. This file is free software;
14you can redistribute it and/or modify it under the terms of the GNU
15General Public License (GPL) as published by the Free Software
16Foundation, in version 2 as it comes in the "COPYING" file of the
17VirtualBox OSE distribution. VirtualBox OSE is distributed in the
18hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
19
20The contents of this file may alternatively be used under the terms
21of the Common Development and Distribution License Version 1.0
22(CDDL) only, as it comes in the "COPYING.CDDL" file of the
23VirtualBox OSE distribution, in which case the provisions of the
24CDDL are applicable instead of those of the GPL.
25
26You may elect to license modified versions of this file under the
27terms and conditions of either the GPL or the CDDL or both.
28"""
29__version__ = "$Revision: 70522 $"
30
31# Standard python imports.
32import sys
33import types
34
35# Validation Kit imports.
36sys.path.insert(0, '.');
37sys.path.insert(0, '..');
38sys.path.insert(0, '../..');
39import usbgadget;
40import testdriver.reporter as reporter
41from common import utils;
42
43
44# Python 3 hacks:
45if sys.version_info[0] >= 3:
46 long = int; # pylint: disable=redefined-builtin,invalid-name
47
48
49g_cTests = 0;
50g_cFailures = 0
51
52def boolRes(rc, fExpect = True):
53 """Checks a boolean result."""
54 global g_cTests, g_cFailures;
55 g_cTests = g_cTests + 1;
56 if isinstance(rc, types.BooleanType):
57 if rc == fExpect:
58 return 'PASSED';
59 g_cFailures = g_cFailures + 1;
60 return 'FAILED';
61
62def stringRes(rc, sExpect):
63 """Checks a string result."""
64 global g_cTests, g_cFailures;
65 g_cTests = g_cTests + 1;
66 if utils.isString(rc):
67 if rc == sExpect:
68 return 'PASSED';
69 g_cFailures = g_cFailures + 1;
70 return 'FAILED';
71
72def main(asArgs): # pylint: disable=C0111,R0914,R0915
73 cMsTimeout = long(30*1000);
74 sAddress = 'localhost';
75 uPort = None;
76 fStdTests = True;
77
78 i = 1;
79 while i < len(asArgs):
80 if asArgs[i] == '--hostname':
81 sAddress = asArgs[i + 1];
82 i = i + 2;
83 elif asArgs[i] == '--port':
84 uPort = int(asArgs[i + 1]);
85 i = i + 2;
86 elif asArgs[i] == '--timeout':
87 cMsTimeout = long(asArgs[i + 1]);
88 i = i + 2;
89 elif asArgs[i] == '--help':
90 print 'tst-utsgadget.py [--hostname <addr|name>] [--port <num>] [--timeout <cMS>]'
91 return 0;
92 else:
93 print 'Unknown argument: %s' % (asArgs[i]);
94 return 2;
95
96 oGadget = usbgadget.UsbGadget();
97 if uPort is None:
98 rc = oGadget.connectTo(cMsTimeout, sAddress);
99 else:
100 rc = oGadget.connectTo(cMsTimeout, sAddress, uPort = uPort);
101 if rc is False:
102 print 'connectTo failed';
103 return 1;
104
105 if fStdTests:
106 rc = oGadget.getUsbIpPort() is not None;
107 print '%s: getUsbIpPort() -> %s' % (boolRes(rc), oGadget.getUsbIpPort());
108
109 rc = oGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest);
110 print '%s: impersonate()' % (boolRes(rc));
111
112 rc = oGadget.disconnectUsb();
113 print '%s: disconnectUsb()' % (boolRes(rc));
114
115 rc = oGadget.connectUsb();
116 print '%s: connectUsb()' % (boolRes(rc));
117
118 rc = oGadget.clearImpersonation();
119 print '%s: clearImpersonation()' % (boolRes(rc));
120
121 # Test super speed (and therefore passing configuration items)
122 rc = oGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, True);
123 print '%s: impersonate(, True)' % (boolRes(rc));
124
125 rc = oGadget.clearImpersonation();
126 print '%s: clearImpersonation()' % (boolRes(rc));
127
128 # Done
129 rc = oGadget.disconnectFrom();
130 print '%s: disconnectFrom() -> %s' % (boolRes(rc), rc);
131
132 if g_cFailures != 0:
133 print 'tst-utsgadget.py: %u out of %u test failed' % (g_cFailures, g_cTests);
134 return 1;
135 print 'tst-utsgadget.py: all %u tests passed!' % (g_cTests);
136 return 0;
137
138
139if __name__ == '__main__':
140 reporter.incVerbosity();
141 reporter.incVerbosity();
142 reporter.incVerbosity();
143 reporter.incVerbosity();
144 sys.exit(main(sys.argv));
145
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