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