VirtualBox

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

Last change on this file since 60522 was 60522, checked in by vboxsync, 9 years ago

ValidationKit/usb: Fixes, basic compliance testing works finally

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