VirtualBox

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

Last change on this file since 88839 was 82968, checked in by vboxsync, 5 years ago

Copyright year updates by scm.

  • 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 82968 2020-02-04 10:35:17Z vboxsync $
3
4"""
5Simple testcase for usbgadget2.py.
6"""
7
8__copyright__ = \
9"""
10Copyright (C) 2016-2020 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: 82968 $"
30
31# Standard python imports.
32import sys
33
34# Validation Kit imports.
35sys.path.insert(0, '.');
36sys.path.insert(0, '..');
37sys.path.insert(0, '../..');
38import usbgadget;
39import testdriver.reporter as reporter
40from common import utils;
41
42
43# Python 3 hacks:
44if sys.version_info[0] >= 3:
45 long = int; # pylint: disable=redefined-builtin,invalid-name
46
47
48g_cTests = 0;
49g_cFailures = 0
50
51def boolRes(rc, fExpect = True):
52 """Checks a boolean result."""
53 global g_cTests, g_cFailures;
54 g_cTests = g_cTests + 1;
55 if isinstance(rc, bool):
56 if rc == fExpect:
57 return 'PASSED';
58 g_cFailures = g_cFailures + 1;
59 return 'FAILED';
60
61def stringRes(rc, sExpect):
62 """Checks a string result."""
63 global g_cTests, g_cFailures;
64 g_cTests = g_cTests + 1;
65 if utils.isString(rc):
66 if rc == sExpect:
67 return 'PASSED';
68 g_cFailures = g_cFailures + 1;
69 return 'FAILED';
70
71def main(asArgs): # pylint: disable=missing-docstring,too-many-locals,too-many-statements
72 cMsTimeout = long(30*1000);
73 sAddress = 'localhost';
74 uPort = None;
75 fStdTests = True;
76
77 i = 1;
78 while i < len(asArgs):
79 if asArgs[i] == '--hostname':
80 sAddress = asArgs[i + 1];
81 i = i + 2;
82 elif asArgs[i] == '--port':
83 uPort = int(asArgs[i + 1]);
84 i = i + 2;
85 elif asArgs[i] == '--timeout':
86 cMsTimeout = long(asArgs[i + 1]);
87 i = i + 2;
88 elif asArgs[i] == '--help':
89 print('tst-utsgadget.py [--hostname <addr|name>] [--port <num>] [--timeout <cMS>]');
90 return 0;
91 else:
92 print('Unknown argument: %s' % (asArgs[i],));
93 return 2;
94
95 oGadget = usbgadget.UsbGadget();
96 if uPort is None:
97 rc = oGadget.connectTo(cMsTimeout, sAddress);
98 else:
99 rc = oGadget.connectTo(cMsTimeout, sAddress, uPort = uPort);
100 if rc is False:
101 print('connectTo failed');
102 return 1;
103
104 if fStdTests:
105 rc = oGadget.getUsbIpPort() is not None;
106 print('%s: getUsbIpPort() -> %s' % (boolRes(rc), oGadget.getUsbIpPort(),));
107
108 rc = oGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest);
109 print('%s: impersonate()' % (boolRes(rc),));
110
111 rc = oGadget.disconnectUsb();
112 print('%s: disconnectUsb()' % (boolRes(rc),));
113
114 rc = oGadget.connectUsb();
115 print('%s: connectUsb()' % (boolRes(rc),));
116
117 rc = oGadget.clearImpersonation();
118 print('%s: clearImpersonation()' % (boolRes(rc),));
119
120 # Test super speed (and therefore passing configuration items)
121 rc = oGadget.impersonate(usbgadget.g_ksGadgetImpersonationTest, True);
122 print('%s: impersonate(, True)' % (boolRes(rc),));
123
124 rc = oGadget.clearImpersonation();
125 print('%s: clearImpersonation()' % (boolRes(rc),));
126
127 # Done
128 rc = oGadget.disconnectFrom();
129 print('%s: disconnectFrom() -> %s' % (boolRes(rc), rc,));
130
131 if g_cFailures != 0:
132 print('tst-utsgadget.py: %u out of %u test failed' % (g_cFailures, g_cTests,));
133 return 1;
134 print('tst-utsgadget.py: all %u tests passed!' % (g_cTests,));
135 return 0;
136
137
138if __name__ == '__main__':
139 reporter.incVerbosity();
140 reporter.incVerbosity();
141 reporter.incVerbosity();
142 reporter.incVerbosity();
143 sys.exit(main(sys.argv));
144
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