1 | # -*- coding: utf-8 -*-
|
---|
2 | # $Id: tst-utsgadget.py 82968 2020-02-04 10:35:17Z vboxsync $
|
---|
3 |
|
---|
4 | """
|
---|
5 | Simple testcase for usbgadget2.py.
|
---|
6 | """
|
---|
7 |
|
---|
8 | __copyright__ = \
|
---|
9 | """
|
---|
10 | Copyright (C) 2016-2020 Oracle Corporation
|
---|
11 |
|
---|
12 | This file is part of VirtualBox Open Source Edition (OSE), as
|
---|
13 | available from http://www.virtualbox.org. This file is free software;
|
---|
14 | you can redistribute it and/or modify it under the terms of the GNU
|
---|
15 | General Public License (GPL) as published by the Free Software
|
---|
16 | Foundation, in version 2 as it comes in the "COPYING" file of the
|
---|
17 | VirtualBox OSE distribution. VirtualBox OSE is distributed in the
|
---|
18 | hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
|
---|
19 |
|
---|
20 | The contents of this file may alternatively be used under the terms
|
---|
21 | of the Common Development and Distribution License Version 1.0
|
---|
22 | (CDDL) only, as it comes in the "COPYING.CDDL" file of the
|
---|
23 | VirtualBox OSE distribution, in which case the provisions of the
|
---|
24 | CDDL are applicable instead of those of the GPL.
|
---|
25 |
|
---|
26 | You may elect to license modified versions of this file under the
|
---|
27 | terms and conditions of either the GPL or the CDDL or both.
|
---|
28 | """
|
---|
29 | __version__ = "$Revision: 82968 $"
|
---|
30 |
|
---|
31 | # Standard python imports.
|
---|
32 | import sys
|
---|
33 |
|
---|
34 | # Validation Kit imports.
|
---|
35 | sys.path.insert(0, '.');
|
---|
36 | sys.path.insert(0, '..');
|
---|
37 | sys.path.insert(0, '../..');
|
---|
38 | import usbgadget;
|
---|
39 | import testdriver.reporter as reporter
|
---|
40 | from common import utils;
|
---|
41 |
|
---|
42 |
|
---|
43 | # Python 3 hacks:
|
---|
44 | if sys.version_info[0] >= 3:
|
---|
45 | long = int; # pylint: disable=redefined-builtin,invalid-name
|
---|
46 |
|
---|
47 |
|
---|
48 | g_cTests = 0;
|
---|
49 | g_cFailures = 0
|
---|
50 |
|
---|
51 | def 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 |
|
---|
61 | def 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 |
|
---|
71 | def 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 |
|
---|
138 | if __name__ == '__main__':
|
---|
139 | reporter.incVerbosity();
|
---|
140 | reporter.incVerbosity();
|
---|
141 | reporter.incVerbosity();
|
---|
142 | reporter.incVerbosity();
|
---|
143 | sys.exit(main(sys.argv));
|
---|
144 |
|
---|