VirtualBox

source: vbox/trunk/src/VBox/ValidationKit/testdriver/vboxtestfileset.py@ 90780

Last change on this file since 90780 was 83308, checked in by vboxsync, 5 years ago

Validation Kit/tests + Guest Control: Added (optional) parameter for passing "compatible with" specs to the TestFileSet object and use this in Guest Control testing.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.6 KB
Line 
1# -*- coding: utf-8 -*-
2# $Id: vboxtestfileset.py 83308 2020-03-17 13:50:19Z vboxsync $
3# pylint: disable=too-many-lines
4
5"""
6Test File Set
7"""
8
9__copyright__ = \
10"""
11Copyright (C) 2010-2020 Oracle Corporation
12
13This file is part of VirtualBox Open Source Edition (OSE), as
14available from http://www.virtualbox.org. This file is free software;
15you can redistribute it and/or modify it under the terms of the GNU
16General Public License (GPL) as published by the Free Software
17Foundation, in version 2 as it comes in the "COPYING" file of the
18VirtualBox OSE distribution. VirtualBox OSE is distributed in the
19hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
20
21The contents of this file may alternatively be used under the terms
22of the Common Development and Distribution License Version 1.0
23(CDDL) only, as it comes in the "COPYING.CDDL" file of the
24VirtualBox OSE distribution, in which case the provisions of the
25CDDL are applicable instead of those of the GPL.
26
27You may elect to license modified versions of this file under the
28terms and conditions of either the GPL or the CDDL or both.
29"""
30__version__ = "$Revision: 83308 $"
31
32
33# Standard Python imports.
34import os;
35import sys;
36
37# Validation Kit imports.
38from common import utils;
39from testdriver import reporter;
40from testdriver import testfileset;
41
42# Python 3 hacks:
43if sys.version_info[0] >= 3:
44 xrange = range; # pylint: disable=redefined-builtin,invalid-name
45
46
47class TestFileSet(testfileset.TestFileSet):
48 """
49 A generated set of files and directories for uploading to a VM.
50
51 The file and directory names are compatible with the host, so it is
52 possible to copy them to the host without changing any names.
53
54 Uploaded as a tarball and expanded via TXS (if new enough) or uploaded vts_tar
55 utility from the validation kit.
56 """
57
58 def __init__(self, oTestVm, sBasePath, sSubDir, # pylint: disable=too-many-arguments
59 oRngFileSizes = xrange(0, 16384),
60 oRngManyFiles = xrange(128, 512),
61 oRngTreeFiles = xrange(128, 384),
62 oRngTreeDepth = xrange(92, 256),
63 oRngTreeDirs = xrange(2, 16),
64 cchMaxPath = 230,
65 cchMaxName = 230,
66 asCompatibleWith = None,
67 uSeed = None):
68
69 asCompOses = [oTestVm.getGuestOs(), ];
70 sHostOs = utils.getHostOs();
71 if sHostOs not in asCompOses:
72 asCompOses.append(sHostOs);
73
74 testfileset.TestFileSet.__init__(self,
75 fDosStyle = oTestVm.isWindows() or oTestVm.isOS2(),
76 asCompatibleWith = asCompOses,
77 sBasePath = sBasePath,
78 sSubDir = sSubDir,
79 oRngFileSizes = oRngFileSizes,
80 oRngManyFiles = oRngManyFiles,
81 oRngTreeFiles = oRngTreeFiles,
82 oRngTreeDepth = oRngTreeDepth,
83 oRngTreeDirs = oRngTreeDirs,
84 cchMaxPath = cchMaxPath,
85 cchMaxName = cchMaxName,
86 uSeed = uSeed);
87 self.oTestVm = oTestVm;
88
89 def __uploadFallback(self, oTxsSession, sTarFileGst, oTstDrv):
90 """
91 Fallback upload method.
92 """
93 sVtsTarExe = 'vts_tar' + self.oTestVm.getGuestExeSuff();
94 sVtsTarHst = os.path.join(oTstDrv.sVBoxValidationKit, self.oTestVm.getGuestOs(),
95 self.oTestVm.getGuestArch(), sVtsTarExe);
96 sVtsTarGst = self.oTestVm.pathJoin(self.sBasePath, sVtsTarExe);
97
98 if oTxsSession.syncUploadFile(sVtsTarHst, sVtsTarGst) is not True:
99 return reporter.error('Failed to upload "%s" to the guest as "%s"!' % (sVtsTarHst, sVtsTarGst,));
100
101 fRc = oTxsSession.syncExec(sVtsTarGst, [sVtsTarGst, '-xzf', sTarFileGst, '-C', self.sBasePath,], fWithTestPipe = False);
102 if fRc is not True:
103 return reporter.error('vts_tar failed!');
104 return True;
105
106 def upload(self, oTxsSession, oTstDrv):
107 """
108 Uploads the files into the guest via the given TXS session.
109
110 Returns True / False.
111 """
112
113 #
114 # Create a tarball.
115 #
116 sTarFileHst = os.path.join(oTstDrv.sScratchPath, 'tdAddGuestCtrl-1-Stuff.tar.gz');
117 sTarFileGst = self.oTestVm.pathJoin(self.sBasePath, 'tdAddGuestCtrl-1-Stuff.tar.gz');
118 if self.createTarball(sTarFileHst) is not True:
119 return False;
120
121 #
122 # Upload it.
123 #
124 reporter.log('Uploading tarball "%s" to the guest as "%s"...' % (sTarFileHst, sTarFileGst));
125 if oTxsSession.syncUploadFile(sTarFileHst, sTarFileGst) is not True:
126 return reporter.error('Failed upload tarball "%s" as "%s"!' % (sTarFileHst, sTarFileGst,));
127
128 #
129 # Try unpack it.
130 #
131 reporter.log('Unpacking "%s" into "%s"...' % (sTarFileGst, self.sBasePath));
132 if oTxsSession.syncUnpackFile(sTarFileGst, self.sBasePath, fIgnoreErrors = True) is not True:
133 reporter.log('Failed to expand tarball "%s" into "%s", falling back on individual directory and file creation...'
134 % (sTarFileGst, self.sBasePath,));
135 if self.__uploadFallback(oTxsSession, sTarFileGst, oTstDrv) is not True:
136 return False;
137 reporter.log('Successfully placed test files and directories in the VM.');
138 return True;
139
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