- Timestamp:
- Jan 9, 2017 11:57:35 AM (8 years ago)
- Location:
- trunk/src/VBox/ValidationKit
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/ValidationKit/testdriver/base.py
r62795 r65199 1139 1139 """ 1140 1140 Worker that reads the PID file. 1141 Returns list of PID, empty if no file.1142 """ 1143 aiPids = [];1141 Returns dictionary of PID with value (sName, fSudo), empty if no file. 1142 """ 1143 dPids = {}; 1144 1144 if os.path.isfile(self.sPidFile): 1145 1145 try: … … 1149 1149 except: 1150 1150 reporter.errorXcpt(); 1151 return aiPids;1151 return dPids; 1152 1152 1153 1153 sContent = str(sContent).strip().replace('\n', ' ').replace('\r', ' ').replace('\t', ' '); 1154 for sPid in sContent.split(' '): 1155 if sPid.isdigit(): 1154 for sProcess in sContent.split(' '): 1155 asFields = sProcess.split(':'); 1156 if len(asFields) == 3 and asFields[0].isdigit(): 1156 1157 try: 1157 aiPids.append(int(sPid));1158 dPids[int(asFields[0])] = (asFields[2], asFields[1] == 'sudo'); 1158 1159 except: 1159 reporter.logXcpt('sP id=%s' % (sPid,));1160 reporter.logXcpt('sProcess=%s' % (sProcess,)); 1160 1161 else: 1161 reporter.log('%s: "%s"' % (self.sPidFile, sP id));1162 1163 return aiPids;1164 1165 def pidFileAdd(self, iPid, fSudo = False):1162 reporter.log('%s: "%s"' % (self.sPidFile, sProcess)); 1163 1164 return dPids; 1165 1166 def pidFileAdd(self, iPid, sName, fSudo = False): 1166 1167 """ 1167 1168 Adds a PID to the PID file, creating the file if necessary. … … 1170 1171 try: 1171 1172 oFile = utils.openNoInherit(self.sPidFile, 'a'); 1172 oFile.write(str(iPid) + '\n'); 1173 oFile.write('%s:%s:%s\n' 1174 % ( iPid, 1175 'sudo' if fSudo else 'normal', 1176 sName.replace(' ', '_').replace(':','_').replace('\n','_').replace('\r','_').replace('\t','_'),)); 1173 1177 oFile.close(); 1174 1178 except: … … 1182 1186 Removes a PID from the PID file. 1183 1187 """ 1184 aiPids = self.pidFileRead();1185 if iPid not in aiPids:1188 dPids = self.pidFileRead(); 1189 if iPid not in dPids: 1186 1190 if not fQuiet: 1187 reporter.log('pidFileRemove could not find %s in the PID file (content: %s)' % (iPid, aiPids));1191 reporter.log('pidFileRemove could not find %s in the PID file (content: %s)' % (iPid, dPids)); 1188 1192 return False; 1189 1193 1190 aiPids.remove(iPid); 1194 sName = dPids[iPid][0]; 1195 del dPids[iPid]; 1196 1191 1197 sPid = ''; 1192 for iPid2 in aiPids:1193 sPid += '%s \n' % (iPid2,);1198 for iPid2 in dPids: 1199 sPid += '%s:%s:%s\n' % (iPid2, 'sudo' if dPids[iPid2][1] else 'normal', dPids[iPid2][0]); 1194 1200 1195 1201 try: … … 1201 1207 return False; 1202 1208 1203 reporter.log2('pidFileRemove: removed PID %d (new content: %s)' % (iPid, self.pidFileRead(),));1209 reporter.log2('pidFileRemove: removed PID %d [%s] (new content: %s)' % (iPid, sName, self.pidFileRead(),)); 1204 1210 return True; 1205 1211 … … 1516 1522 """ 1517 1523 1518 aiPids = self.pidFileRead();1519 reporter.log('The pid file contained: %s' % ( aiPids,));1524 dPids = self.pidFileRead(); 1525 reporter.log('The pid file contained: %s' % (dPids,)); 1520 1526 1521 1527 # … … 1527 1533 afnMethods = [ sendUserSignal1, processInterrupt, processTerminate, processKill ]; 1528 1534 for fnMethod in afnMethods: 1529 for iPid in aiPids: 1535 ## @todo Handle SUDO processes. 1536 for iPid in dPids: 1530 1537 fnMethod(iPid); 1531 1538 … … 1534 1541 time.sleep(1); 1535 1542 1536 for j in range(len(aiPids) - 1, -1, -1): 1537 iPid = aiPids[j]; 1543 for iPid in dPids.keys(): 1538 1544 if not processExists(iPid): 1539 reporter.log('%s terminated' % (iPid,));1545 reporter.log('%s (%s) terminated' % (dPids[iPid][0], iPid,)); 1540 1546 self.pidFileRemove(iPid, fQuiet = True); 1541 aiPids.pop(j);1542 1543 if len( aiPids) == 0:1547 del dPids[iPid]; 1548 1549 if len(dPids) == 0: 1544 1550 reporter.log('All done.'); 1545 1551 return True; 1546 1552 1547 1553 if i in [4, 8]: 1548 reporter.log('Still waiting for: %s (method=%s)' % ( aiPids, fnMethod,));1549 1550 reporter.log('Failed to terminate the following processes: %s' % ( aiPids,));1554 reporter.log('Still waiting for: %s (method=%s)' % (dPids, fnMethod,)); 1555 1556 reporter.log('Failed to terminate the following processes: %s' % (dPids,)); 1551 1557 return False; 1552 1558 … … 1661 1667 reporter.log('*** cleanup-before action completed (fRc2=%s, fRc=%s) ***' % (fRc2, fRc,)); 1662 1668 1663 self.pidFileAdd(os.getpid() );1669 self.pidFileAdd(os.getpid(), os.path.basename(sys.argv[0])); 1664 1670 1665 1671 if 'config' in asActions and fRc is True: … … 1730 1736 1731 1737 def testPidFile(self): 1732 aiPids = [os.getpid() + 1, os.getpid() + 2]; 1733 self.assertTrue(self.oTstDrv.pidFileAdd(aiPids[0])); 1734 self.assertEqual(self.oTstDrv.pidFileRead(), aiPids[0:1]); 1735 self.assertTrue(self.oTstDrv.pidFileAdd(aiPids[1])); 1736 self.assertEqual(self.oTstDrv.pidFileRead(), aiPids[0:2]); 1738 1739 iPid1 = os.getpid() + 1; 1740 iPid2 = os.getpid() + 2; 1741 1742 self.assertTrue(self.oTstDrv.pidFileAdd(iPid1, 'test1')); 1743 self.assertEqual(self.oTstDrv.pidFileRead(), {iPid1:('test1',False)}); 1744 1745 self.assertTrue(self.oTstDrv.pidFileAdd(iPid2, 'test2', fSudo = True)); 1746 self.assertEqual(self.oTstDrv.pidFileRead(), {iPid1:('test1',False), iPid2:('test2',True)}); 1747 1748 self.assertTrue(self.oTstDrv.pidFileRemove(iPid1)); 1749 self.assertEqual(self.oTstDrv.pidFileRead(), {iPid2:('test2',True)}); 1750 1751 self.assertTrue(self.oTstDrv.pidFileRemove(iPid2)); 1752 self.assertEqual(self.oTstDrv.pidFileRead(), {}); 1753 1737 1754 self.assertTrue(self.oTstDrv.pidFileDelete()); 1738 1755 -
trunk/src/VBox/ValidationKit/testdriver/vboxwrappers.py
r64332 r65199 2618 2618 if self.uPid is not None: 2619 2619 reporter.log2('getPid: %u' % (self.uPid,)); 2620 self.oTstDrv.pidFileAdd(self.uPid );2620 self.oTstDrv.pidFileAdd(self.uPid, 'vm_%s' % (self.sName,), fSudo = True); # Set-uid-to-root is similar to SUDO. 2621 2621 return self.uPid; 2622 2622 -
trunk/src/VBox/ValidationKit/tests/unittests/tdUnitTest1.py
r65196 r65199 645 645 646 646 if oChild is not None: 647 self.pidFileAdd(oChild.pid, fSudo = fHardened);647 self.pidFileAdd(oChild.pid, sName, fSudo = fHardened); 648 648 iRc = oChild.wait(); 649 649 self.pidFileRemove(oChild.pid);
Note:
See TracChangeset
for help on using the changeset viewer.