VirtualBox

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

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