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