Index: /trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py
===================================================================
--- /trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py	(revision 56687)
+++ /trunk/src/VBox/ValidationKit/tests/additions/tdAddGuestCtrl.py	(revision 56688)
@@ -91,8 +91,24 @@
     Provides credentials to pass to the guest.
     """
-    def __init__(self, sUser, sPassword, sDomain):
-        self.sUser = sUser;
-        self.sPassword = sPassword;
-        self.sDomain = sDomain;
+    def __init__(self, sUser = None, sPassword = None, sDomain = None, oTestVm = None):
+        # If no user is specified, select the default user and
+        # password for the given test VM.
+        if sUser is None:
+            assert sPassword is None;
+            assert sDomain is None;
+            assert oTestVm is not None;
+
+            ## @todo fix this so all VMs have several usable test users with the same passwords (or none).
+            sUser     = 'test';
+            sPassword = 'password';
+            if oTestVm.isWindows():
+                #sPassword = ''; # stupid config mistake.
+                sPassword = 'password';
+                sUser     = 'Administrator';
+            sDomain   = '';
+
+        self.sUser     = sUser;
+        self.sPassword = sPassword if sPassword is not None else '';
+        self.sDomain   = sDomain if sDomain is not None else '';
 
 class tdTestGuestCtrlBase(object):
@@ -137,5 +153,5 @@
 
             try:
-                reporter.log('Waiting for session "%s" to start within %ldms...' % (sName, self.timeoutMS));
+                reporter.log('Waiting for session "%s" to start within %dms...' % (sName, self.timeoutMS));
                 fWaitFor = [ vboxcon.GuestSessionWaitForFlag_Start ];
                 waitResult = self.oGuestSession.waitForArray(fWaitFor, self.timeoutMS);
@@ -147,11 +163,12 @@
                     and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
                     # Just log, don't assume an error here (will be done in the main loop then).
-                    reporter.log('Session did not start successfully, returned wait result: %ld' \
-                                  % (waitResult));
+                    reporter.log('Session did not start successfully, returned wait result: %d' \
+                                  % (waitResult,));
                     return (False, None);
                 reporter.log('Session "%s" successfully started' % (sName,));
             except:
                 # Just log, don't assume an error here (will be done in the main loop then).
-                reporter.logXcpt('Waiting for guest session "%s" to start failed:' % (sName));
+                reporter.logXcpt('Waiting for guest session "%s" (usr=%s;pw=%s;dom=%s) to start failed:'
+                                 % (sName, self.oCreds.sUser, self.oCreds.sPassword, self.oCreds.sDomain,));
                 return (False, None);
         else:
@@ -382,12 +399,237 @@
         return len(aoSession);
 
-class tdTestSessionEnv(tdTestGuestCtrlBase):
-    """
-    Test the guest session environment.
-    """
-    def __init__(self, sUser = "", sPassword = "", aEnv = None):
+class tdTestSessionEx(tdTestGuestCtrlBase):
+    """
+    Test the guest session.
+    """
+    def __init__(self, aoSteps = None, enmUser = None):
         tdTestGuestCtrlBase.__init__(self);
-        self.oCreds = tdCtxCreds(sUser, sPassword, sDomain = "");
-        self.aEnv = aEnv or [];
+        assert enmUser == None; # For later.
+        self.enmUser = enmUser;
+        self.aoSteps = aoSteps if aoSteps is not None else [];
+
+    def execute(self, oTstDrv, oVmSession, oTxsSession, oTestVm, sMsgPrefix):
+        """
+        Executes the test.
+        """
+        #
+        # Create a session.
+        #
+        assert self.enmUser == None; # For later.
+        self.oCreds = tdCtxCreds(oTestVm = oTestVm);
+        self.setEnvironment(oVmSession, oTxsSession, oTestVm);
+        reporter.log2('%s: %s steps' % (sMsgPrefix, len(self.aoSteps),));
+        fRc, oCurSession = self.createSession(sMsgPrefix);
+        if fRc is True:
+            #
+            # Execute the tests.
+            #
+            try:
+                fRc = self.executeSteps(oTstDrv, oCurSession, sMsgPrefix);
+            except:
+                reporter.errorXcpt('%s: Unexpected exception executing test steps' % (sMsgPrefix,));
+                fRc = False;
+
+            fRc2 = self.closeSession();
+            if fRc2 is False:
+                reporter.error('%s: Session could not be closed' % (sMsgPrefix,));
+                fRc = False;
+        else:
+            reporter.error('%s: Session creation failed' % (sMsgPrefix,));
+            fRc = False;
+        return fRc;
+
+    def executeSteps(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
+        """
+        Executes just the steps.
+        Returns True on success, False on test failure.
+        """
+        fRc = True;
+        for (i, oStep) in enumerate(self.aoSteps):
+            fRc2 = oStep.execute(oTstDrv, oGstCtrlSession, sMsgPrefix + ', step #%d' % i);
+            if fRc2 is False:
+                fRc = False;
+        return fRc;
+
+
+#
+# Scheduling Environment Changes with the Guest Control Session.
+#
+
+class tdStepSessionSetEnv(object):
+    """
+    Guest session environment: schedule putenv
+    """
+    def __init__(self, sVar, sValue, hrcExpected = 0):
+        self.sVar        = sVar;
+        self.sValue      = sValue;
+        self.hrcExpected = hrcExpected;
+
+    def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
+        """
+        Executes the step.
+        Returns True on success, False on test failure.
+        """
+        reporter.log2('tdStepSessionSetEnv: sVar=%s sValue=%s hrcExpected=%#x' % (self.sVar, self.sValue, self.hrcExpected,));
+        try:
+            if oTstDrv.fpApiVer >= 5.0:
+                oGstCtrlSession.environmentScheduleSet(self.sVar, self.sValue);
+            else:
+                oGstCtrlSession.environmentSet(self.sVar, self.sValue);
+        except vbox.ComException, oXcpt:
+            # Is this an expected failure?
+            if vbox.ComError.equal(oXcpt, self.hrcExpected):
+                return True;
+            reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (setenv %s=%s)'
+                               % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected),
+                                  vbox.ComError.getXcptResult(oXcpt),
+                                  vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)),
+                                  self.sVar, self.sValue,));
+            return False;
+        except:
+            reporter.errorXcpt('%s: Unexpected exception in tdStepSessionSetEnv::execute (%s=%s)'
+                               % (sMsgPrefix, self.sVar, self.sValue,));
+            return False;
+
+        # Should we succeed?
+        if self.hrcExpected != 0:
+            reporter.error('%s: Expected hrcExpected=%#x, got S_OK (putenv %s=%s)'
+                           % (sMsgPrefix, self.hrcExpected, self.sVar, self.sValue,));
+            return False;
+        return True;
+
+class tdStepSessionUnsetEnv(object):
+    """
+    Guest session environment: schedule unset.
+    """
+    def __init__(self, sVar, hrcExpected = 0):
+        self.sVar        = sVar;
+        self.hrcExpected = hrcExpected;
+
+    def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
+        """
+        Executes the step.
+        Returns True on success, False on test failure.
+        """
+        reporter.log2('tdStepSessionUnsetEnv: sVar=%s hrcExpected=%#x' % (self.sVar, self.hrcExpected,));
+        try:
+            if oTstDrv.fpApiVer >= 5.0:
+                oGstCtrlSession.environmentScheduleUnset(self.sVar);
+            else:
+                oGstCtrlSession.environmentUnset(self.sVar);
+        except vbox.ComException, oXcpt:
+            # Is this an expected failure?
+            if vbox.ComError.equal(oXcpt, self.hrcExpected):
+                return True;
+            reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (unsetenv %s)'
+                               % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected),
+                                  vbox.ComError.getXcptResult(oXcpt),
+                                  vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)),
+                                  self.sVar,));
+            return False;
+        except:
+            reporter.errorXcpt('%s: Unexpected exception in tdStepSessionUnsetEnv::execute (%s)'
+                               % (sMsgPrefix, self.sVar,));
+            return False;
+
+        # Should we succeed?
+        if self.hrcExpected != 0:
+            reporter.error('%s: Expected hrcExpected=%#x, got S_OK (unsetenv %s)'
+                           % (sMsgPrefix, self.hrcExpected, self.sVar,));
+            return False;
+        return True;
+
+class tdStepSessionBulkEnv(object):
+    """
+    Guest session environment: Bulk environment changes.
+    """
+    def __init__(self, asEnv = None, hrcExpected = 0):
+        self.asEnv = asEnv if asEnv is not None else [];
+        self.hrcExpected = hrcExpected;
+
+    def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
+        """
+        Executes the step.
+        Returns True on success, False on test failure.
+        """
+        reporter.log2('tdStepSessionBulkEnv: asEnv=%s hrcExpected=%#x' % (self.asEnv, self.hrcExpected,));
+        try:
+            if oTstDrv.fpApiVer >= 5.0:
+                oTstDrv.oVBoxMgr.setArray(oGstCtrlSession, 'environmentChanges', self.asEnv);
+            else:
+                oTstDrv.oVBoxMgr.setArray(oGstCtrlSession, 'environment', self.asEnv);
+        except vbox.ComException, oXcpt:
+            # Is this an expected failure?
+            if vbox.ComError.equal(oXcpt, self.hrcExpected):
+                return True;
+            reporter.errorXcpt('%s: Expected hrc=%#x (%s) got %#x (%s) instead (asEnv=%s)'
+                               % (sMsgPrefix, self.hrcExpected, vbox.ComError.toString(self.hrcExpected),
+                                  vbox.ComError.getXcptResult(oXcpt),
+                                  vbox.ComError.toString(vbox.ComError.getXcptResult(oXcpt)),
+                                  self.asEnv,));
+            return False;
+        except:
+            reporter.errorXcpt('%s: Unexpected exception writing the environmentChanges property (asEnv=%s).'
+                               % (sMsgPrefix, self.asEnv));
+            return False;
+        return True;
+
+class tdStepSessionClearEnv(tdStepSessionBulkEnv):
+    """
+    Guest session environment: clears the scheduled environment changes.
+    """
+    def __init__(self):
+        tdStepSessionBulkEnv.__init__(self);
+
+
+class tdStepSessionCheckEnv(object):
+    """
+    Check the currently scheduled environment changes of a guest control session.
+    """
+    def __init__(self, asEnv = None):
+        self.asEnv = asEnv if asEnv is not None else [];
+
+    def execute(self, oTstDrv, oGstCtrlSession, sMsgPrefix):
+        """
+        Executes the step.
+        Returns True on success, False on test failure.
+        """
+        reporter.log2('tdStepSessionCheckEnv: asEnv=%s' % (self.asEnv,));
+
+        #
+        # Get the environment change list.
+        #
+        try:
+            if oTstDrv.fpApiVer >= 5.0:
+                asCurEnv = oTstDrv.oVBoxMgr.getArray(oGstCtrlSession, 'environmentChanges');
+            else:
+                asCurEnv = oTstDrv.oVBoxMgr.getArray(oGstCtrlSession, 'environment');
+        except:
+            reporter.errorXcpt('%s: Unexpected exception reading the environmentChanges property.' % (sMsgPrefix,));
+            return False;
+
+        #
+        # Compare it with the expected one by trying to remove each expected value
+        # and the list anything unexpected.
+        #
+        fRc = True;
+        asCopy = list(asCurEnv); # just in case asCurEnv is immutable
+        for sExpected in self.asEnv:
+            try:
+                asCopy.remove(sExpected);
+            except:
+                reporter.error('%s: Expected "%s" to be in the resulting environment' % (sMsgPrefix, sExpected,));
+                fRc = False;
+        for sUnexpected in asCopy:
+            reporter.error('%d: Unexpected "%s" in the resulting environment' % (sMsgPrefix, sUnexpected,));
+            fRc = False;
+
+        if fRc is not True:
+            reporter.log2('%s: Current environment: %s' % (sMsgPrefix, asCurEnv));
+        return fRc;
+
+#
+#
+#
 
 class tdTestSessionFileRefs(tdTestGuestCtrlBase):
@@ -496,13 +738,4 @@
         tdTestResult.__init__(self, fRc = fRc);
         self.cNumSessions = cNumSessions;
-
-class tdTestResultSessionEnv(tdTestResult):
-    """
-    Test result for guest session environment tests.
-    """
-    def __init__(self, fRc = False, cNumVars = 0):
-        tdTestResult.__init__(self, fRc = fRc);
-        self.cNumVars = cNumVars;
-
 
 class SubTstDrvAddGuestCtrl(base.SubTestDriverBase):
@@ -982,7 +1215,6 @@
                 if     oTest.uExitStatus != oRes.uExitStatus \
                     or oTest.iExitCode   != oRes.iExitCode:
-                    reporter.error('Test #%d failed: Got exit status + code %d,%d, expected %d,%d' % \
-                                   (i, oTest.uExitStatus, oTest.iExitCode, \
-                                       oRes.uExitStatus,  oRes.iExitCode));
+                    reporter.error('Test #%d failed: Got exit status + code %d,%d, expected %d,%d'
+                                   % (i, oTest.uExitStatus, oTest.iExitCode, oRes.uExitStatus,  oRes.iExitCode));
                     return False;
             if fRc is True:
@@ -991,10 +1223,10 @@
                     and oRes.sBuf is not None:
                     if bytes(oTest.sBuf) != bytes(oRes.sBuf):
-                        reporter.error('Test #%d failed: Got buffer\n%s (%ld bytes), expected\n%s (%ld bytes)' %
-                                       (i, map(hex, map(ord, oTest.sBuf)), len(oTest.sBuf), \
-                                           map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf)));
+                        reporter.error('Test #%d failed: Got buffer\n%s (%d bytes), expected\n%s (%d bytes)'
+                                       % (i, map(hex, map(ord, oTest.sBuf)), len(oTest.sBuf), \
+                                          map(hex, map(ord, oRes.sBuf)), len(oRes.sBuf)));
                         return False;
                     else:
-                        reporter.log2('Test #%d passed: Buffers match (%ld bytes)' % (i, len(oRes.sBuf)));
+                        reporter.log2('Test #%d passed: Buffers match (%d bytes)' % (i, len(oRes.sBuf)));
                 elif     oRes.sBuf is not None \
                      and len(oRes.sBuf):
@@ -1004,5 +1236,5 @@
                 elif     oRes.cbStdOut > 0 \
                      and oRes.cbStdOut != oTest.cbStdOut:
-                    reporter.error('Test #%d failed: Got %ld stdout data, expected %ld'
+                    reporter.error('Test #%d failed: Got %d stdout data, expected %d'
                                    % (i, oTest.cbStdOut, oRes.cbStdOut));
                     return False;
@@ -1022,8 +1254,8 @@
         #tsStart = base.timestampMilli();
 
-        reporter.log2('Using session user=%s, sDomain=%s, session name=%s, session timeout=%ld' \
+        reporter.log2('Using session user=%s, sDomain=%s, session name=%s, session timeout=%d' \
                       % (oGuestSession.user, oGuestSession.domain, \
                          oGuestSession.name, oGuestSession.timeout));
-        reporter.log2('Executing cmd=%s, aFlags=%s, timeout=%ld, args=%s, env=%s' \
+        reporter.log2('Executing cmd=%s, aFlags=%s, timeout=%d, args=%s, env=%s' \
                       % (oTest.sCmd, oTest.aFlags, oTest.timeoutMS, \
                          oTest.aArgs, oTest.aEnv));
@@ -1033,8 +1265,8 @@
                                                   oTest.aEnv, oTest.aFlags, oTest.timeoutMS);
             if curProc is not None:
-                reporter.log2('Process start requested, waiting for start (%ldms) ...' % (oTest.timeoutMS,));
+                reporter.log2('Process start requested, waiting for start (%dms) ...' % (oTest.timeoutMS,));
                 fWaitFor = [ vboxcon.ProcessWaitForFlag_Start ];
                 waitResult = curProc.waitForArray(fWaitFor, oTest.timeoutMS);
-                reporter.log2('Wait result returned: %d, current process status is: %ld' % (waitResult, curProc.status));
+                reporter.log2('Wait result returned: %d, current process status is: %d' % (waitResult, curProc.status));
 
                 if curProc.status == vboxcon.ProcessStatus_Started:
@@ -1045,5 +1277,5 @@
                         fWaitFor.append(vboxcon.ProcessWaitForFlag_StdErr);
                     ## @todo Add vboxcon.ProcessWaitForFlag_StdIn.
-                    reporter.log2('Process (PID %ld) started, waiting for termination (%dms), waitFlags=%s ...' \
+                    reporter.log2('Process (PID %d) started, waiting for termination (%dms), waitFlags=%s ...' \
                                   % (curProc.PID, oTest.timeoutMS, fWaitFor));
                     while True:
@@ -1057,5 +1289,5 @@
                                 buf = curProc.Read(1, 64 * 1024, oTest.timeoutMS);
                                 if len(buf):
-                                    reporter.log2('Process (PID %ld) got %ld bytes of stdout data' % (curProc.PID, len(buf)));
+                                    reporter.log2('Process (PID %d) got %d bytes of stdout data' % (curProc.PID, len(buf)));
                                     oTest.cbStdOut += len(buf);
                                     oTest.sBuf = buf; # Appending does *not* work atm, so just assign it. No time now.
@@ -1066,5 +1298,5 @@
                                 buf = curProc.Read(2, 64 * 1024, oTest.timeoutMS);
                                 if len(buf):
-                                    reporter.log2('Process (PID %ld) got %ld bytes of stderr data' % (curProc.PID, len(buf)));
+                                    reporter.log2('Process (PID %d) got %d bytes of stderr data' % (curProc.PID, len(buf)));
                                     oTest.cbStdErr += len(buf);
                                     oTest.sBuf = buf; # Appending does *not* work atm, so just assign it. No time now.
@@ -1072,10 +1304,10 @@
                             if     waitResult == vboxcon.ProcessWaitResult_StdIn \
                                 or waitResult == vboxcon.ProcessWaitResult_WaitFlagNotSupported:
-                                pass; #reporter.log2('Process (PID %ld) needs stdin data' % (curProc.pid,));
+                                pass; #reporter.log2('Process (PID %d) needs stdin data' % (curProc.pid,));
                             # Termination or error?
                             if     waitResult == vboxcon.ProcessWaitResult_Terminate \
                                 or waitResult == vboxcon.ProcessWaitResult_Error \
                                 or waitResult == vboxcon.ProcessWaitResult_Timeout:
-                                reporter.log2('Process (PID %ld) reported terminate/error/timeout: %ld, status: %ld' \
+                                reporter.log2('Process (PID %d) reported terminate/error/timeout: %d, status: %d' \
                                               % (curProc.PID, waitResult, curProc.status));
                                 break;
@@ -1083,11 +1315,11 @@
                             # Just skip reads which returned nothing.
                             pass;
-                    reporter.log2('Final process status (PID %ld) is: %ld' % (curProc.PID, curProc.status));
-                    reporter.log2('Process (PID %ld) %ld stdout, %ld stderr' % (curProc.PID, oTest.cbStdOut, oTest.cbStdErr));
+                    reporter.log2('Final process status (PID %d) is: %d' % (curProc.PID, curProc.status));
+                    reporter.log2('Process (PID %d) %d stdout, %d stderr' % (curProc.PID, oTest.cbStdOut, oTest.cbStdErr));
             oTest.uExitStatus = curProc.status;
             oTest.iExitCode = curProc.exitCode;
-            reporter.log2('Process (PID %ld) has exit code: %ld' % (curProc.PID, oTest.iExitCode));
+            reporter.log2('Process (PID %d) has exit code: %d' % (curProc.PID, oTest.iExitCode));
         except KeyboardInterrupt:
-            reporter.error('Process (PID %ld) execution interrupted' % (curProc.PID,));
+            reporter.error('Process (PID %d) execution interrupted' % (curProc.PID,));
             if curProc is not None:
                 curProc.close();
@@ -1104,166 +1336,102 @@
         """
 
-        if oTestVm.isWindows():
-            sUser = "Administrator";
-        else:
-            sUser = "vbox";
-        sPassword = "password";
-
         aaTests = [
-            # No environment set.
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword),
-              tdTestResultSessionEnv(fRc = False) ],
-            # Invalid stuff.
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ '=FOO' ]),
-              tdTestResultSessionEnv(fRc = False) ],
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ '====' ]),
-              tdTestResultSessionEnv(fRc = False) ],
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ '=BAR' ]),
-              tdTestResultSessionEnv(fRc = False) ],
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ u'ß$%ß&' ]),
-              tdTestResultSessionEnv(fRc = False) ],
-            # Key only.
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ 'FOO=' ]),
-              tdTestResultSessionEnv(fRc = True, cNumVars = 1) ],
-            # Values.
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ 'FOO' ]),
-              tdTestResultSessionEnv(fRc = True, cNumVars = 1) ],
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ 'FOO=BAR' ]),
-              tdTestResultSessionEnv(fRc = True, cNumVars = 1) ],
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ 'FOO=BAR', 'BAR=BAZ' ]),
-              tdTestResultSessionEnv(fRc = True, cNumVars = 2) ],
+            # Check basic operations.
+            tdTestSessionEx([ # Initial environment is empty.
+                              tdStepSessionCheckEnv(),
+                              # Check clearing empty env.
+                              tdStepSessionClearEnv(),
+                              tdStepSessionCheckEnv(),
+                              # Check set.
+                              tdStepSessionSetEnv('FOO', 'BAR'),
+                              tdStepSessionCheckEnv(['FOO=BAR',]),
+                              tdStepSessionClearEnv(),
+                              tdStepSessionCheckEnv(),
+                              # Check unset.
+                              tdStepSessionUnsetEnv('BAR'),
+                              tdStepSessionCheckEnv(['BAR']),
+                              tdStepSessionClearEnv(),
+                              tdStepSessionCheckEnv(),
+                              # Set + unset.
+                              tdStepSessionSetEnv('FOO', 'BAR'),
+                              tdStepSessionCheckEnv(['FOO=BAR',]),
+                              tdStepSessionUnsetEnv('FOO'),
+                              tdStepSessionCheckEnv(['FOO']),
+                              # Bulk environment changes (via attrib) (shall replace existing 'FOO').
+                              tdStepSessionBulkEnv( ['PATH=/bin:/usr/bin', 'TMPDIR=/var/tmp', 'USER=root']),
+                              tdStepSessionCheckEnv(['PATH=/bin:/usr/bin', 'TMPDIR=/var/tmp', 'USER=root']),
+                              ]),
+            tdTestSessionEx([ # Check that setting the same value several times works.
+                              tdStepSessionSetEnv('FOO','BAR'),
+                              tdStepSessionCheckEnv([ 'FOO=BAR',]),
+                              tdStepSessionSetEnv('FOO','BAR2'),
+                              tdStepSessionCheckEnv([ 'FOO=BAR2',]),
+                              tdStepSessionSetEnv('FOO','BAR3'),
+                              tdStepSessionCheckEnv([ 'FOO=BAR3',]),
+                              # Add a little unsetting to the mix.
+                              tdStepSessionSetEnv('BAR', 'BEAR'),
+                              tdStepSessionCheckEnv([ 'FOO=BAR3', 'BAR=BEAR',]),
+                              tdStepSessionUnsetEnv('FOO'),
+                              tdStepSessionCheckEnv([ 'FOO', 'BAR=BEAR',]),
+                              tdStepSessionSetEnv('FOO','BAR4'),
+                              tdStepSessionCheckEnv([ 'FOO=BAR4', 'BAR=BEAR',]),
+                              # The environment is case sensitive.
+                              tdStepSessionSetEnv('foo','BAR5'),
+                              tdStepSessionCheckEnv([ 'FOO=BAR4', 'BAR=BEAR', 'foo=BAR5']),
+                              tdStepSessionUnsetEnv('foo'),
+                              tdStepSessionCheckEnv([ 'FOO=BAR4', 'BAR=BEAR', 'foo']),
+                              ]),
+            tdTestSessionEx([ # Bulk settings merges stuff, last entry standing.
+                              tdStepSessionBulkEnv(['FOO=bar', 'foo=bar', 'FOO=doofus', 'TMPDIR=/tmp', 'foo=bar2']),
+                              tdStepSessionCheckEnv(['FOO=doofus', 'TMPDIR=/tmp', 'foo=bar2']),
+                              ]),
+            # Invalid variable names.
+            tdTestSessionEx([ tdStepSessionSetEnv('', 'FOO', vbox.ComError.E_INVALIDARG),
+                              tdStepSessionCheckEnv(),
+                              tdStepSessionSetEnv('=', '===', vbox.ComError.E_INVALIDARG),
+                              tdStepSessionCheckEnv(),
+                              tdStepSessionSetEnv('FOO=', 'BAR', vbox.ComError.E_INVALIDARG),
+                              tdStepSessionCheckEnv(),
+                              tdStepSessionSetEnv('=FOO', 'BAR', vbox.ComError.E_INVALIDARG),
+                              tdStepSessionCheckEnv(),
+                              tdStepSessionBulkEnv(['=', 'foo=bar'], vbox.ComError.E_INVALIDARG),
+                              tdStepSessionCheckEnv(),
+                              tdStepSessionBulkEnv(['=FOO', 'foo=bar'], vbox.ComError.E_INVALIDARG),
+                              tdStepSessionCheckEnv(),
+                              ]),
             # A bit more weird keys/values.
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ '$$$=' ]),
-              tdTestResultSessionEnv(fRc = True, cNumVars = 1) ],
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ '$$$=%%%' ]),
-              tdTestResultSessionEnv(fRc = True, cNumVars = 1) ],
-            # Same stuff.
-            [ tdTestSessionEnv(sUser = sUser, sPassword = sPassword, aEnv = [ 'FOO=BAR', 'FOO=BAR' ]),
-              tdTestResultSessionEnv(fRc = True, cNumVars = 1) ]
+            tdTestSessionEx([ tdStepSessionSetEnv('$$$', ''),
+                              tdStepSessionCheckEnv([ '$$$=',]), ]),
+            tdTestSessionEx([ tdStepSessionSetEnv('$$$', '%%%'),
+                              tdStepSessionCheckEnv([ '$$$=%%%',]),
+                              ]),
+            tdTestSessionEx([ tdStepSessionSetEnv(u'ß$%ß&', ''),
+                              tdStepSessionCheckEnv([ u'ß$%ß&=',]),
+                              ]),
+            # Misc stuff.
+            tdTestSessionEx([ tdStepSessionSetEnv('FOO', ''),
+                              tdStepSessionCheckEnv(['FOO=',]),
+                              ]),
+            tdTestSessionEx([ tdStepSessionSetEnv('FOO', 'BAR'),
+                              tdStepSessionCheckEnv(['FOO=BAR',])
+                              ],),
+            tdTestSessionEx([ tdStepSessionSetEnv('FOO', 'BAR'),
+                              tdStepSessionSetEnv('BAR', 'BAZ'),
+                              tdStepSessionCheckEnv([ 'FOO=BAR', 'BAR=BAZ',]),
+                              ]),
         ];
 
-        # The IGuestSession::environment attribute changed late in 5.0 development.
-        sEnvironmentChangesAttr = 'environmentChanges' if self.oTstDrv.fpApiVer >= 5.0 else 'environment';
-
-        # Parameters.
+        #
+        # Work through the tests.
+        #
         fRc = True;
-        for (i, aTest) in enumerate(aaTests):
-            curTest = aTest[0]; # tdTestExec, use an index, later.
-            curRes  = aTest[1]; # tdTestResult
-            curTest.setEnvironment(oSession, oTxsSession, oTestVm);
-            reporter.log('Testing #%d, user="%s", sPassword="%s", env="%s" (%d)...' \
-                         % (i, curTest.oCreds.sUser, curTest.oCreds.sPassword, curTest.aEnv, len(curTest.aEnv)));
-            curGuestSessionName = 'testGuestCtrlSessionEnvironment: Test #%d' % (i,);
-            fRc2, curGuestSession = curTest.createSession(curGuestSessionName);
-            if fRc2 is not True:
-                reporter.error('Test #%d failed: Session creation failed: Got %s, expected True' % (i, fRc2));
+        for (i, oCurTest) in enumerate(aaTests):
+            try:
+                fRc2 = oCurTest.execute(self.oTstDrv, oSession, oTxsSession, oTestVm, 'test %#d' % (i,));
+                if fRc2 is not True:
+                    fRc = False;
+            except:
+                reporter.errorXcpt('Unexpected exception executing test #%d' % (i,));
                 fRc = False;
-                break;
-            # Make sure environment is empty.
-            curEnv = self.oTstDrv.oVBoxMgr.getArray(curGuestSession, sEnvironmentChangesAttr);
-            reporter.log2('Test #%d: Environment initially has %d elements' % (i, len(curEnv)));
-            if len(curEnv) != 0:
-                reporter.error('Test #%d failed: Initial session environment has %d vars, expected 0' % (i, len(curEnv)));
-                fRc = False;
-                break;
-            try:
-                for (_, aEnv) in enumerate(curTest.aEnv):
-                    aElems = aEnv.split('=');
-                    strKey = '';  ## @todo s/Key/Var/g
-                    strValue = '';
-                    if len(aElems) > 0:
-                        strKey = aElems[0];
-                    if len(aElems) == 2:
-                        strValue = aElems[1];
-                    reporter.log2('Test #%d: Single var="%s", value="%s" (%d) ...' \
-                                  % (i, strKey, strValue, len(aElems)));
-                    try:
-                        if self.oTstDrv.fpApiVer >= 5.0:
-                            curGuestSession.environmentScheduleSet(strKey, strValue);
-                        else:
-                            curGuestSession.environmentSet(strKey, strValue);
-                    except:
-                        # Setting environment variables might fail (e.g. if empty name specified). Check.
-                        reporter.logXcpt('Test #%d failed: Setting environment variable failed:' % (i,));
-                        curEnv = self.oTstDrv.oVBoxMgr.getArray(curGuestSession, sEnvironmentChangesAttr);
-                        if len(curEnv) is not curRes.cNumVars:
-                            reporter.error('Test #%d failed: Session environment has %d vars, expected %d' \
-                                           % (i, len(curEnv), curRes.cNumVars));
-                            fRc = False;
-                            break;
-                        else:
-                            reporter.log('Test #%d: API reported an error (single), good' % (i,));
-                    ## @todo environmentGet() has been removed in 5.0 because it's not up to the task of returning all the
-                    ## putenv strings forms and gives the impression that the environment is something it isn't. This test
-                    ## should be rewritten using the attribute.  What's more, there should be an Unset test here, shouldn't
-                    ## there?
-                    #
-                    #reporter.log2('Getting key="%s" ...' % (strKey,));
-                    #try:
-                    #    strValue2 = curGuestSession.environmentGet(strKey);
-                    #    if      strKey.isalnum() \
-                    #        and strValue != strValue2:
-                    #        reporter.error('Test #%d failed: Got environment value "%s", expected "%s" (var: "%s")' \
-                    #                       % (i, strValue2, strValue, strKey));
-                    #        fRc = False;
-                    #        break;
-                    #    # Getting back an empty value when specifying an invalid key is fine.
-                    #    reporter.log2('Got key "%s=%s"' % (strKey, strValue2));
-                    #except UnicodeDecodeError: # Might happen on unusal values, fine.
-                    #    if strValue != strValue2:
-                    #        reporter.error('Test #%d failed: Got (undecoded) environment variable "%s", ' \
-                    #                       'expected "%s" (var: "%s")' \
-                    #                       % (i, strValue2, strValue, strKey));
-                    #        fRc = False;
-                    #        break;
-                    #except:
-                    #    if     strKey == "" \
-                    #        or not strKey.isalnum():
-                    #        reporter.log('Test #%d: API reported an error (invalid key "%s"), good' % (i, strKey));
-                    #    else:
-                    #        reporter.errorXcpt('Test #%d failed: Getting environment variable:' % (i));
-                if fRc is False:
-                    continue;
-                # Set the same stuff again, this time all at once using the array.
-                if len(curTest.aEnv):
-                    reporter.log('Test #%d: Array %s (%d)' % (i, curTest.aEnv, len(curTest.aEnv)));
-                    try:
-                        ## @todo No return (e.g. boolean) value available thru wrapper.
-                        #curGuestSession.environmentSetArray(curTest.aEnv);
-                        pass;
-                    except:
-                        # Setting environment variables might fail (e.g. if empty name specified). Check.
-                        curEnv = self.oTstDrv.oVBoxMgr.getArray(curGuestSession, sEnvironmentChangesAttr);
-                        if len(curEnv) is not curRes.cNumVars:
-                            reporter.error('Test #%d failed: Session environment has %d vars, expected %d (array)' \
-                                           % (i, len(curEnv), curRes.cNumVars));
-                            fRc = False;
-                            break;
-                        else:
-                            reporter.log('Test #%d: API reported an error (array), good' % (i,));
-                ## @todo Get current system environment and add it to curRes.cNumVars before comparing!
-                reporter.log('Test #%d: Environment size' % (i,));
-                curEnv = self.oTstDrv.oVBoxMgr.getArray(curGuestSession, sEnvironmentChangesAttr);
-                reporter.log2('Test #%d: Environment (%d) -> %s' % (i, len(curEnv), curEnv));
-                if len(curEnv) != curRes.cNumVars:
-                    reporter.error('Test #%d failed: Session environment has %d vars (%s), expected %d' \
-                                   % (i, len(curEnv), curEnv, curRes.cNumVars));
-                    fRc = False;
-                    break;
-
-                self.oTstDrv.oVBoxMgr.setArray(curGuestSession, sEnvironmentChangesAttr, []);
-                curEnv = self.oTstDrv.oVBoxMgr.getArray(curGuestSession, sEnvironmentChangesAttr);
-                if len(curEnv) is not 0:
-                    reporter.error('Test #%d failed: Session environment has %d vars, expected 0');
-                    fRc = False;
-                    break;
-            except:
-                reporter.errorXcpt('Test #%d failed:' % (i,));
-
-            fRc2 = curTest.closeSession();
-            if fRc2 is False:
-                reporter.error('Test #%d failed: Session could not be closed' % (i,));
-                fRc = False;
-                break;
 
         return (fRc, oTxsSession);
@@ -1392,4 +1560,7 @@
 
         try:
+            # r=bird: multiSession[0].oGuestSession is None! Why don't you just use 'assert' or 'if' to check
+            #         the functioning of the __testcase__?
+
             # Make sure that accessing the first opened guest session does not work anymore because we just removed (closed) it.
             curSessionName = multiSession[0].oGuestSession.name;
@@ -1444,5 +1615,5 @@
                 and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
                 # Just log, don't assume an error here (will be done in the main loop then).
-                reporter.log('Session did not start successfully, returned wait result: %ld' \
+                reporter.log('Session did not start successfully, returned wait result: %d' \
                               % (waitResult));
                 return (False, oTxsSession);
@@ -1464,5 +1635,5 @@
                     #       do not support terminating guest processes.
                 except:
-                    reporter.errorXcpt('Opening stale file #%ld failed:' % (i,));
+                    reporter.errorXcpt('Opening stale file #%d failed:' % (i,));
                     fRc = False;
                     break;
@@ -1471,5 +1642,5 @@
                 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
                 if cFiles != cStaleFiles:
-                    reporter.error('Test failed: Got %ld stale files, expected %ld' % (cFiles, cStaleFiles));
+                    reporter.error('Test failed: Got %d stale files, expected %d' % (cFiles, cStaleFiles));
                     fRc = False;
 
@@ -1489,5 +1660,5 @@
                         aaFiles.append(oCurFile);
                     except:
-                        reporter.errorXcpt('Opening non-stale file #%ld failed:' % (i,));
+                        reporter.errorXcpt('Opening non-stale file #%d failed:' % (i,));
                         fRc = False;
                         break;
@@ -1495,5 +1666,5 @@
                 cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
                 if cFiles != cStaleFiles * 2:
-                    reporter.error('Test failed: Got %ld total files, expected %ld' % (cFiles, cStaleFiles * 2));
+                    reporter.error('Test failed: Got %d total files, expected %d' % (cFiles, cStaleFiles * 2));
                     fRc = False;
             if fRc:
@@ -1503,5 +1674,5 @@
                         aaFiles[i].close();
                     except:
-                        reporter.errorXcpt('Waiting for non-stale file #%ld failed:' % (i,));
+                        reporter.errorXcpt('Waiting for non-stale file #%d failed:' % (i,));
                         fRc = False;
                         break;
@@ -1511,5 +1682,5 @@
                 # a reference in aaFiles[] for).
                 if cFiles != cStaleFiles:
-                    reporter.error('Test failed: Got %ld total files, expected %ld' \
+                    reporter.error('Test failed: Got %d total files, expected %d' \
                                    % (cFiles, cStaleFiles));
                     fRc = False;
@@ -1523,9 +1694,9 @@
                             curFilesStatus = aaFiles[i].status;
                             if curFilesStatus != vboxcon.FileStatus_Closed:
-                                reporter.error('Test failed: Non-stale file #%ld has status %ld, expected %ld' \
+                                reporter.error('Test failed: Non-stale file #%d has status %d, expected %d' \
                                        % (i, curFilesStatus, vboxcon.FileStatus_Closed));
                                 fRc = False;
                         except:
-                            reporter.errorXcpt('Checking status of file #%ld failed:' % (i,));
+                            reporter.errorXcpt('Checking status of file #%d failed:' % (i,));
                             fRc = False;
                             break;
@@ -1533,5 +1704,5 @@
                 reporter.log2('All non-stale files closed');
             cFiles = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'files'));
-            reporter.log2('Final guest session file count: %ld' % (cFiles,));
+            reporter.log2('Final guest session file count: %d' % (cFiles,));
             # Now try to close the session and see what happens.
             reporter.log2('Closing guest session ...');
@@ -1580,5 +1751,5 @@
                 and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
                 # Just log, don't assume an error here (will be done in the main loop then).
-                reporter.log('Session did not start successfully, returned wait result: %ld' \
+                reporter.log('Session did not start successfully, returned wait result: %d' \
                               % (waitResult));
                 return (False, oTxsSession);
@@ -1600,5 +1771,5 @@
                     #       do not support terminating guest processes.
                 except:
-                    reporter.logXcpt('Creating stale process #%ld failed:' % (i,));
+                    reporter.logXcpt('Creating stale process #%d failed:' % (i,));
                     fRc = False;
                     break;
@@ -1607,5 +1778,5 @@
                 cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
                 if cProcs != cStaleProcs:
-                    reporter.error('Test failed: Got %ld stale processes, expected %ld' % (cProcs, cStaleProcs));
+                    reporter.error('Test failed: Got %d stale processes, expected %d' % (cProcs, cStaleProcs));
                     fRc = False;
 
@@ -1624,5 +1795,5 @@
                         aaProcs.append(oCurProc);
                     except:
-                        reporter.logXcpt('Creating non-stale process #%ld failed:' % (i,));
+                        reporter.logXcpt('Creating non-stale process #%d failed:' % (i,));
                         fRc = False;
                         break;
@@ -1634,10 +1805,10 @@
                         curProcStatus = aaProcs[i].status;
                         if aaProcs[i].status != vboxcon.ProcessStatus_TerminatedNormally:
-                            reporter.error('Test failed: Waiting for non-stale processes #%ld'
-                                           ' resulted in status %ld, expected %ld' \
+                            reporter.error('Test failed: Waiting for non-stale processes #%d'
+                                           ' resulted in status %d, expected %d' \
                                    % (i, curProcStatus, vboxcon.ProcessStatus_TerminatedNormally));
                             fRc = False;
                     except:
-                        reporter.logXcpt('Waiting for non-stale process #%ld failed:' % (i,));
+                        reporter.logXcpt('Waiting for non-stale process #%d failed:' % (i,));
                         fRc = False;
                         break;
@@ -1647,5 +1818,5 @@
                 # a reference in aaProcs[] for).
                 if cProcs != (cStaleProcs * 2):
-                    reporter.error('Test failed: Got %ld total processes, expected %ld' \
+                    reporter.error('Test failed: Got %d total processes, expected %d' \
                                    % (cProcs, cStaleProcs));
                     fRc = False;
@@ -1657,5 +1828,5 @@
                         curProcStatus = aaProcs[i].status;
                         if aaProcs[i].status != vboxcon.ProcessStatus_TerminatedNormally:
-                            reporter.error('Test failed: Non-stale processes #%ld has status %ld, expected %ld' \
+                            reporter.error('Test failed: Non-stale processes #%d has status %d, expected %d' \
                                    % (i, curProcStatus, vboxcon.ProcessStatus_TerminatedNormally));
                             fRc = False;
@@ -1689,8 +1860,8 @@
                 cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
                 if cProcs != (cStaleProcs * 2): # Still should be 20 processes because we terminated the 10 newest ones.
-                    reporter.error('Test failed: Got %ld total processes, expected %ld' % (cProcs, cStaleProcs * 2));
+                    reporter.error('Test failed: Got %d total processes, expected %d' % (cProcs, cStaleProcs * 2));
                     fRc = False;
             cProcs = len(self.oTstDrv.oVBoxMgr.getArray(oGuestSession, 'processes'));
-            reporter.log2('Final guest session processes count: %ld' % (cProcs,));
+            reporter.log2('Final guest session processes count: %d' % (cProcs,));
             # Now try to close the session and see what happens.
             reporter.log2('Closing guest session ...');
@@ -1909,5 +2080,5 @@
                 if      waitResult != vboxcon.GuestSessionWaitResult_Start \
                     and waitResult != vboxcon.GuestSessionWaitResult_WaitFlagNotSupported:
-                    reporter.error('Session did not start successfully, returned wait result: %ld' \
+                    reporter.error('Session did not start successfully, returned wait result: %d' \
                                    % (waitResult));
                     return (False, oTxsSession);
@@ -2083,5 +2254,5 @@
                 waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Start ], 30 * 1000);
                 if waitRes != vboxcon.ProcessWaitResult_Start:
-                    reporter.error('Waiting for process 1 to start failed, got status %ld');
+                    reporter.error('Waiting for process 1 to start failed, got status %d');
                     fRc = False;
                 if fRc:
@@ -2097,5 +2268,5 @@
                     waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 5000);
                     if waitRes != vboxcon.ProcessWaitResult_Timeout:
-                        reporter.error('Waiting for process 1 did not time out when it should, got wait result %ld' % (waitRes,));
+                        reporter.error('Waiting for process 1 did not time out when it should, got wait result %d' % (waitRes,));
                         fRc = False;
                     else:
@@ -2114,5 +2285,5 @@
                     waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Start ], 30 * 1000);
                     if waitRes != vboxcon.ProcessWaitResult_Start:
-                        reporter.error('Waiting for process 1 to start failed, got status %ld');
+                        reporter.error('Waiting for process 1 to start failed, got status %d');
                         fRc = False;
                     if fRc:
@@ -2120,5 +2291,5 @@
                         waitRes = curProc.waitForArray([ vboxcon.ProcessWaitForFlag_Terminate ], 30 * 1000);
                         if waitRes != vboxcon.ProcessWaitResult_Timeout:
-                            reporter.error('Waiting for process 2 did not time out when it should, got wait result %ld' \
+                            reporter.error('Waiting for process 2 did not time out when it should, got wait result %d' \
                                            % (waitRes,));
                             fRc = False;
@@ -2126,9 +2297,9 @@
                         reporter.log('Waiting for process 2 indicated an error, good');
                         if curProc.status != vboxcon.ProcessStatus_TimedOutKilled:
-                            reporter.error('Status of process 2 wrong; excepted %ld, got %ld' \
+                            reporter.error('Status of process 2 wrong; excepted %d, got %d' \
                                            % (vboxcon.ProcessStatus_TimedOutKilled, curProc.status));
                             fRc = False;
                         else:
-                            reporter.log('Status of process 2 correct (%ld)' % (vboxcon.ProcessStatus_TimedOutKilled,));
+                            reporter.log('Status of process 2 correct (%d)' % (vboxcon.ProcessStatus_TimedOutKilled,));
                     ## @todo Add curProc.terminate() as soon as it's implemented.
                 except:
@@ -2441,13 +2612,13 @@
             (fRc2, cDirs, cFiles) = self.gctrlReadDir(curTest, curRes, curGuestSession);
             curTest.closeSession();
-            reporter.log2('Test #%d: Returned %ld directories, %ld files total' % (i, cDirs, cFiles));
+            reporter.log2('Test #%d: Returned %d directories, %d files total' % (i, cDirs, cFiles));
             if fRc2 is curRes.fRc:
                 if fRc2 is True:
                     if curRes.numFiles != cFiles:
-                        reporter.error('Test #%d failed: Got %ld files, expected %ld' % (i, cFiles, curRes.numFiles));
+                        reporter.error('Test #%d failed: Got %d files, expected %d' % (i, cFiles, curRes.numFiles));
                         fRc = False;
                         break;
                     if curRes.numDirs != cDirs:
-                        reporter.error('Test #%d failed: Got %ld directories, expected %ld' % (i, cDirs, curRes.numDirs));
+                        reporter.error('Test #%d failed: Got %d directories, expected %d' % (i, cDirs, curRes.numDirs));
                         fRc = False;
                         break;
@@ -2610,10 +2781,10 @@
                 eFileType = fileObjInfo.type;
                 if curRes.eFileType != eFileType:
-                    reporter.error('Test #%d failed: Got file type %ld, expected %ld' % (i, eFileType, curRes.eFileType));
+                    reporter.error('Test #%d failed: Got file type %d, expected %d' % (i, eFileType, curRes.eFileType));
                     fRc = False;
                     break;
                 cbFile = long(fileObjInfo.objectSize);
                 if curRes.cbSize != cbFile:
-                    reporter.error('Test #%d failed: Got %ld bytes size, expected %ld bytes' % (i, cbFile, curRes.cbSize));
+                    reporter.error('Test #%d failed: Got %d bytes size, expected %d bytes' % (i, cbFile, curRes.cbSize));
                     fRc = False;
                     break;
@@ -2712,5 +2883,5 @@
             curTest = aTest[0]; # tdTestFileReadWrite, use an index, later.
             curRes  = aTest[1]; # tdTestResult
-            reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%ld ...' % \
+            reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%d ...' % \
                          (i, curTest.sFile, curTest.cbToReadWrite, curTest.sOpenMode, curTest.sDisposition, curTest.cbOffset));
             curTest.setEnvironment(oSession, oTxsSession, oTestVm);
@@ -2731,5 +2902,5 @@
                     resOffset = long(curTest.cbOffset);
                     if curOffset != resOffset:
-                        reporter.error('Test #%d failed: Initial offset on open does not match: Got %ld, expected %ld' \
+                        reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d' \
                                        % (i, curOffset, resOffset));
                         fRc = False;
@@ -2748,5 +2919,5 @@
                     if  curRes.cbProcessed > 0 \
                     and curRes.cbProcessed is not len(aBufRead):
-                        reporter.error('Test #%d failed: Read buffer length does not match: Got %ld, expected %ld' \
+                        reporter.error('Test #%d failed: Read buffer length does not match: Got %d, expected %d' \
                                        % (i, len(aBufRead), curRes.cbProcessed));
                         fRc = False;
@@ -2754,5 +2925,5 @@
                         if  curRes.aBuf is not None \
                         and bytes(curRes.aBuf) != bytes(aBufRead):
-                            reporter.error('Test #%d failed: Got buffer\n%s (%ld bytes), expected\n%s (%ld bytes)' \
+                            reporter.error('Test #%d failed: Got buffer\n%s (%d bytes), expected\n%s (%d bytes)' \
                                            % (i, map(hex, map(ord, aBufRead)), len(aBufRead), \
                                               map(hex, map(ord, curRes.aBuf)), len(curRes.aBuf)));
@@ -2764,5 +2935,5 @@
                 resOffset = long(curRes.cbOffset);
                 if curOffset != resOffset:
-                    reporter.error('Test #%d failed: Final offset does not match: Got %ld, expected %ld' \
+                    reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d' \
                                    % (i, curOffset, resOffset));
                     fRc = False;
@@ -2826,5 +2997,5 @@
             curTest = aTest[0]; # tdTestFileReadWrite, use an index, later.
             curRes  = aTest[1]; # tdTestResult
-            reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%ld ...' % \
+            reporter.log('Testing #%d, sFile="%s", cbToReadWrite=%d, sOpenMode="%s", sDisposition="%s", cbOffset=%d ...' % \
                          (i, curTest.sFile, curTest.cbToReadWrite, curTest.sOpenMode, curTest.sDisposition, curTest.cbOffset));
             curTest.setEnvironment(oSession, oTxsSession, oTestVm);
@@ -2845,5 +3016,5 @@
                     resOffset = long(curTest.cbOffset);
                     if curOffset != resOffset:
-                        reporter.error('Test #%d failed: Initial offset on open does not match: Got %ld, expected %ld' \
+                        reporter.error('Test #%d failed: Initial offset on open does not match: Got %d, expected %d' \
                                        % (i, curOffset, resOffset));
                         fRc = False;
@@ -2862,5 +3033,5 @@
                     if  curRes.cbProcessed > 0 \
                     and curRes.cbProcessed != cBytesWritten:
-                        reporter.error('Test #%d failed: Written buffer length does not match: Got %ld, expected %ld' \
+                        reporter.error('Test #%d failed: Written buffer length does not match: Got %d, expected %d' \
                                        % (i, cBytesWritten, curRes.cbProcessed));
                         fRc = False;
@@ -2879,5 +3050,5 @@
                         and long(curFile.offset) != curTest.cbOffset:
                             reporter.error('Test #%d failed: Initial write position does not match current position, \
-                                           got %ld, expected %ld' \
+                                           got %d, expected %d' \
                                            % (i, long(curFile.offset), curTest.cbOffset));
                             fRc = False;
@@ -2885,5 +3056,5 @@
                         aBufRead = curFile.read(curTest.cbToReadWrite, 30 * 1000);
                         if len(aBufRead) != curTest.cbToReadWrite:
-                            reporter.error('Test #%d failed: Got buffer length %ld, expected %ld' \
+                            reporter.error('Test #%d failed: Got buffer length %d, expected %d' \
                                            % (i, len(aBufRead), curTest.cbToReadWrite));
                             fRc = False;
@@ -2898,5 +3069,5 @@
                 resOffset = long(curRes.cbOffset);
                 if curOffset != resOffset:
-                    reporter.error('Test #%d failed: Final offset does not match: Got %ld, expected %ld' \
+                    reporter.error('Test #%d failed: Final offset does not match: Got %d, expected %d' \
                                    % (i, curOffset, resOffset));
                     fRc = False;
