/// <summary> /// update the 'seed' in the XML to track execution progress and keep running in the correct order /// </summary> /// <param name="seedIndex"></param> /// XMLWriter.UpdateSeedXML(seedIndex); /// looks like this needs work again...when there is a large list of drivers it is removing things like the /// 2 from 12 and 20 leaving multiple 1 and 0 in the list and when the EXE gets to those there is no matching inf /// so it just dies internal static void UpdateSeedXML(int seedIndex) { try { string currentSeed = XMLReader.GetSeed(Program.InputTestFilePathBAK); string seedIndexSTR = Convert.ToString(seedIndex); int seedCharCnt = seedIndexSTR.Length; int seedLocIndex = currentSeed.IndexOf(seedIndexSTR); int seedIndexEnd = seedLocIndex + seedCharCnt; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("seedIndexSTR : " + seedIndexSTR); Console.WriteLine("seedCharCnt : " + seedCharCnt); Console.WriteLine("seedLocIndex : " + seedLocIndex); Console.WriteLine("seedIndexEnd : " + seedIndexEnd); currentSeed = currentSeed.Remove(seedLocIndex, seedCharCnt); // Replace(seedIndexSTR, ""); currentSeed = currentSeed.TrimEnd(',').TrimStart(','); currentSeed = currentSeed.Replace(",,", ","); Console.WriteLine("currentSeed : " + currentSeed); Console.ForegroundColor = ConsoleColor.White; //Console.ReadKey(); string StartSeed = XMLReader.GetStartSeed(Program.InputTestFilePathBAK); var testInputData = XDocument.Load(Program.InputTestFilePathBAK); testInputData.XPathSelectElement("/Tests/TestChoices/CurrentSeed").Value = currentSeed; //Thread.Sleep(500); testInputData.Save(Program.InputTestFilePathBAK); //File.WriteAllText(Program.seedFilePath, currentSeed); } catch (Exception ex) { GetData.GetExceptionMessage(ex); } }
/// <summary> /// method to install firmware specifically /// </summary> /// <param name="line"></param> /// <param name="InputTestFilePathBAK"></param> /// <param name="installer"></param> /// <param name="executionCount"></param> /// <param name="dirName"></param> /// <param name="startChoice"></param> /// <param name="rollbackLine"></param> /// <param name="InputTestFilePath"></param> internal static void IfIsCapsule(int seedIndex, string infIndexListString, int?driverPathListCount, string infName, List <string> DriverPathList, string line, string InputTestFilePathBAK, string installer, int executionCount, string dirName, string startChoice, string rollbackLine, string InputTestFilePath) { try { //bool needRollBack = true; bool rebootRequired = true; Logger.FunctionEnter(); string infFileContent = File.ReadAllText(line).ToUpper(); string infDir = Path.GetDirectoryName(line); Logger.Comment("IfIsCapsule isCapsule infName " + infName); string expectedDriverVersion = GetData.GetDriverVersion(line); Logger.Comment("IfIsCapsule From RegCheck before IF : " + expectedDriverVersion); string infNameToTest = Path.GetFileNameWithoutExtension(line); string expectedDriverDate = GetData.GetDriverDate(line); string infPath = Path.GetDirectoryName(line); int infListCount = XMLReader.GetInfsPathListCount(Program.InputTestFilePathBAK); string friendlyDriverName = XMLReader.GetFriendlyDriverName(InputTestFilePath, line); string hardwareID = GetData.FirmwareInstallGetHID(line); bool isInstalled = CheckWhatInstalled.CheckInstalled(line, hardwareID, friendlyDriverName, infNameToTest, expectedDriverVersion, expectedDriverDate); if (isInstalled) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("-------------------------------------------------------------"); Console.WriteLine("THIS FIRMWARE VERSION IS CURRENTLY INSTALLED ROLLBACK NOW...."); Console.WriteLine("-------------------------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; GetData.IfWillNeedRollBack(line); driverPathListCount--; Logger.Comment("this will now begin to ROLLBACK : " + infName); SafeNativeMethods.RollbackInstall(seedIndex, line, infName, infFileContent, hardwareID, rebootRequired = true, InputTestFilePath); RebootAndContinue.RebootCmd(true); } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("-------------------------------------------------------------"); Console.WriteLine("THIS FIRMWARE VERSION WAS NOT INSTALLED YET INSTALLING NOW..."); Console.WriteLine("-------------------------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; hardwareID = GetData.FirmwareInstallGetHID(line); string installArgs = " /C /A /Q /SE /F /PATH " + infDir; Logger.Comment("IfIsCapsule installArgsChoice is FALSE installArgs " + installArgs); driverPathListCount--; Logger.Comment("this will now Install : " + infName); installArgs = " /C /A /Q /SE /F /PATH " + infDir; RegCheck.CreatePolicyRegKeyAndSetValue(hardwareID, rebootRequired); RebootAndContinue.SetStartUpRegistry(Program.reStartBAT); Logger.Comment("installArgs from FirmwareInstall : " + installArgs); SafeNativeMethods.Install_Inf(line, installer, installArgs, seedIndex); } } catch (Exception ex) { GetData.GetExceptionMessage(ex); } Logger.FunctionLeave(); }
/// <summary> /// Where most of the work is done to decide what to do then call the methods to do so /// </summary> /// <param name="installer"></param> /// <param name=""></param> /// <param name="dirName"></param> /// <param name="startChoice"></param> internal static void StartStress(string InputTestFilePath, string installer, string dirName, string startChoice, string rollbackLine, int infListCount = 0) { try { Logger.FunctionEnter(); if (!File.Exists(dirName + @"\debugEnabled.txt")) { Logger.Comment("enabled WinDebugMode we must reboot..."); Thread.Sleep(1000); RebootAndContinue.EnableWinDebugMode(); } if (RegCheck.IsRebootPending()) { Logger.Comment("there is a pending reboot..."); Thread.Sleep(3000); RebootAndContinue.RebootCmd(true); } if (GetData.CheckCrashDumpOccurred()) { Logger.Comment("Looks like we found a crashdump check it out after reboot..."); Thread.Sleep(1000); RebootAndContinue.RebootCmd(true); } GetData.CreateIfMissing(Program.resultsLogDir); int executionCount = XMLReader.GetExecutionCount(InputTestFilePath); string InputTestFilePathBAK = dirName + @"\DriverCapsuleStress.xml.BAK"; if (!File.Exists(InputTestFilePathBAK)) { Utilities.CopyFile(InputTestFilePath, InputTestFilePathBAK); } infListCount = XMLReader.GetInfsPathListCount(Program.InputTestFilePathBAK); string infIndexListString = XMLReader.GetSeed(Program.InputTestFilePathBAK); if (string.IsNullOrEmpty(infIndexListString)) { RewriteXMLContinue(executionCount, infListCount); } Logger.FunctionLeave(); } catch (Exception ex) { GetData.GetExceptionMessage(ex); } }
/// <summary> /// looking for non firmware drivers to install\uninstall /// </summary> /// <param name="line"></param> /// <param name="InputTestFilePathBAK"></param> /// <param name="installer"></param> /// <param name="executionCount"></param> /// <param name="dirName"></param> /// <param name="startChoice"></param> /// <param name="rollbackLine"></param> /// <param name="InputTestFilePath"></param> internal static void IsNotCapsule(int seedIndex, string infIndexListString, int?driverPathListCount, string infName, List <string> DriverPathList, string line, string InputTestFilePathBAK, string installer, int executionCount, string dirName, string startChoice, string rollbackLine, string InputTestFilePath) { try { Logger.FunctionEnter(); bool rebootRequired = false; string infFileContent = File.ReadAllText(line).ToUpper(); string infDir = Path.GetDirectoryName(line); string hardwareID = GetData.FirmwareInstallGetHID(line); Logger.Comment("IfIsCapsule isCapsule infName " + infName); string expectedDriverVersion = GetData.GetDriverVersion(line); Logger.Comment("IfIsCapsule From RegCheck before IF : " + expectedDriverVersion); string infNameToTest = Path.GetFileNameWithoutExtension(line); string expectedDriverDate = GetData.GetDriverDate(line); string infPath = Path.GetDirectoryName(line); string friendlyDriverName = XMLReader.GetFriendlyDriverName(InputTestFilePath, line); bool isInstalled = CheckWhatInstalled.CheckInstalled(line, hardwareID, friendlyDriverName, infNameToTest, expectedDriverVersion, expectedDriverDate); if (isInstalled) { foreach (var testDir in Directory.EnumerateFiles(Program.rollbackLine)) //(Program.rollBackDir.Contains(infName)) { if (testDir.Contains(infName)) { driverPathListCount--; Logger.Comment("this will now begin to ROLLBACK : " + infName); SafeNativeMethods.RollbackInstall(seedIndex, line, infName, infFileContent, hardwareID, rebootRequired = true, InputTestFilePath); } } } driverPathListCount--; Logger.Comment("this will now install infName : " + infName); Logger.Comment("this will now install hardwareID : " + hardwareID); SafeNativeMethods.InstallUninstallCall(seedIndex, rebootRequired, infName, line, installer, InputTestFilePath); Logger.FunctionLeave(); } catch (Exception ex) { GetData.GetExceptionMessage(ex); } }
/// <summary> /// attempt to move the devMgr window over to the left after it opens /// so it is easier to monitor when running locally if need be /// currently not moving though /// </summary> /// <param name="hWnd"></param> /// <param name="X"></param> /// <param name="Y"></param> /// <param name="nWidth"></param> /// <param name="nHeight"></param> /// <param name="bRepaint"></param> /// <returns></returns> internal static void Main(string[] args) { bool show_help = false; List <string> extra = new List <string>(); ShowWindow(ThisConsole, MAXIMIZE); try { // create the .bat file used by the runonce registry entry to start testing again post-reboot if (!File.Exists(reStartBAT)) { File.WriteAllText(reStartBAT, "cd " + dirName + Environment.NewLine + stressAppPath); } string stressLog = "DriverCapsuleStressLog.txt"; Logger.AppendToFile = true; Logger.LogFileName = stressLog; Logger.LogDirName = dirName; if (!File.Exists(stressLog)) { Logger.AddLogFile(stressLog); } //Logger.Verbose(); if (!File.Exists(InputTestFilePath)) { // get user input parameters if there is not already an XML file to run from var p = new OptionSet() { { "r|randomizeList", "True or False - randomize the execution of the INFs", v => randomizeList = v }, { "i|loopCount", "the number of {TIMES} to stress drivers\\capsules. this must be an integer.", v => loopCount = v }, { "s|startChoice", "Choose driver\\capsule to install first(default will be UEFI", v => startChoice = v }, { "e|stopOnErrorSTR", "Stop testing if there is an error or failure and collect logs", v => stopOnErrorSTR = v }, { "g|groupFirmwareSTR", "Install all firmware then reboot rather than install\reboot for each", v => groupFirmwareSTR = v }, { "c|custom", "Install all drivers in a custom order using comma seperated list of INF names (e.g. SurfaceUEFI.inf,IntcAudioBus.inf,IntcOED.inf) or enter 'none'", v => custom = v }, { "h|help", "show this message and exit", v => show_help = v != null }, }; if (show_help) { ShowHelp(p); return; } extra = p.Parse(args); if (extra.Count > 0) { // is the WTT service started. StartStopServices.StopService("wttsvc"); // start testing here if starting fresh CreateListOrder.RandomizeList(args[1], args[3], args[5], args[7], args[9], args[11]); } else { ShowHelp(p); return; } } else { // is the WTT service started. StartStopServices.StopService("wttsvc"); // starts here if there is already an XML file written to run from XDocument xdoc = XDocument.Load(InputTestFilePath); string infIndexListString = XMLReader.GetSeed(InputTestFilePathBAK); int executionCount = XMLReader.GetExecutionCount(InputTestFilePath); supportFolderLOC = xdoc.XPathSelectElement("/Tests/TestChoices/SupportFolder").Value.ToString(); Array infListFromXML = xdoc.XPathSelectElements("/Tests/InfDirectories/InfDir").ToArray(); bool randomize = GetData.GetRandomChoice(InputTestFilePath); ExecuteFromList.ExecuteTheList(randomize, executionCount, startChoice); } } catch (Exception ex) { GetData.GetExceptionMessage(ex); } }
/// <summary> /// executes the stress in the order given by the list that was created /// only changed during execution when it finds firmware or the users choice to start first /// also groups firmware if chosen at runtime to install all firmware and reboot only once rather /// than rebooting for each firmware install seperately /// </summary> /// <param name="randomize"></param> /// <param name="executionCount"></param> /// <param name="dirName"></param> /// <param name="InputTestFilePath"></param> /// <param name="supportFolderLOC"></param> /// <param name="seedFilePath"></param> /// <param name="startChoice"></param> internal static void ExecuteTheList(bool randomize, int executionCount, string startChoice) { Process devMgr = new Process(); devMgr.StartInfo.FileName = @"C:\Windows\System32\mmc.exe"; devMgr.StartInfo.Arguments = "devmgmt.msc"; devMgr.Start(); try { List <string> DriverPathList = GetData.GetInfPathsList(Program.dirName); CheckWhatInstalled.CheckInstalledCSV(); Console.ForegroundColor = ConsoleColor.Magenta; Console.WriteLine("Waiting 3 seconds to be sure device is up and running..."); Console.ForegroundColor = ConsoleColor.White; Thread.Sleep(3000); if (RegCheck.IsRebootPending()) { Logger.Comment("there is a pending reboot..."); RebootAndContinue.RebootCmd(true); } Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Checking for last installed..."); Console.WriteLine("if it exists we'll check that it was successfull then..."); Console.WriteLine("... ExecuteTheList..."); Console.ForegroundColor = ConsoleColor.White; // check if lastInstalled in the XML was successfully installed post-reboot string tmpLine = XMLReader.GetLastInstalled(); if (string.IsNullOrEmpty(tmpLine)) { Console.WriteLine("no previous driver installed to check just yet..."); } else { string installCheck = GetData.IsInstalledAfterReboot(tmpLine); switch (installCheck) { case string unsuccessful when installCheck.Equals("unsuccessful"): DoThisIfFailedPostReboot(); break; case string InsufficientResources when installCheck.Equals("InsufficientResources"): DoThisIfFailedPostReboot(); break; case string IncorrectVersion when installCheck.Equals("IncorrectVersion"): DoThisIfFailedPostReboot(); break; case string invalidImage when installCheck.Equals("invalidImage"): DoThisIfFailedPostReboot(); break; case string authenticationERR when installCheck.Equals("authenticationERR"): DoThisIfFailedPostReboot(); break; case string ACnotConnected when installCheck.Equals("ACnotConnected"): DoThisIfFailedPostReboot(); break; case string insufficientPower when installCheck.Equals("insufficientPower"): DoThisIfFailedPostReboot(); break; default: installCheck.Equals("pass"); break; } } // making sure there is a driver path to test in the XML file // if they have all been removed they are all done and we need to rewrite the XML int infListCount = XMLReader.GetInfsPathListCount(Program.InputTestFilePathBAK); string infIndexListString = XMLReader.GetSeed(Program.InputTestFilePathBAK); if (string.IsNullOrEmpty(infIndexListString)) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("infListCount = " + infListCount); Console.ForegroundColor = ConsoleColor.White; executionCount = XMLReader.GetExecutionCount(Program.InputTestFilePath); DriverStressInit.RewriteXMLContinue(executionCount, infListCount); } // double check the current executin count in the XML to be sure we proceed correctly int TMPexecutionCount = XMLReader.GetExecutionCount(Program.InputTestFilePath); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("executionCount : " + TMPexecutionCount); Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("time to check the executionCount and decide what to do..."); Console.WriteLine("...waiting 10 seconds for Windows to catch up to me......"); Console.WriteLine("----------------------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; Thread.Sleep(10000); // if the execution count is now zero it is time to collect logs etc if (TMPexecutionCount == 0) { Console.WriteLine("waiting before continue to see if this is where it is dying....sometimes..."); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("-----------------------------------------"); Console.WriteLine("at this point...I think I am done...am I?"); Console.WriteLine("-----------------------------------------"); Console.ForegroundColor = ConsoleColor.White; ParseForResults.ParseFromdpinstLog(@"C:\Windows\DPINST.LOG"); File.Create(Program.dirName + @"\DONE.TXT"); CheckWhatInstalled.CheckInstalledCSV(); Logger.Comment("Copy the the driverstress log and DPINST.LOG to our folder..."); Utilities.CopyFile(@"C:\Windows\DPINST.LOG", Program.dpinstLog); Utilities.CopyFile(Program.InputTestFilePathBAK, Program.resultsLogDir + @"\DriverCapsuleStress.xml.BAK"); Utilities.CopyFile(Program.dirName + @"\DriverCapsuleStressLog.txt", Program.resultsLogDir + @"\DriverCapsuleStressLog.txt"); Thread.Sleep(5000); Console.WriteLine("Everything should be completed including copying logs to the Reults folder on the desktop"); // is the WTT service stopped. StartStopServices.StartService("wttsvc"); Logger.FunctionLeave(); } while (TMPexecutionCount >= 1) { string seedStr = XMLReader.GetSeed(Program.InputTestFilePathBAK); XDocument xdoc = XDocument.Load(Program.InputTestFilePath); infIndexListString = XMLReader.GetSeed(Program.InputTestFilePathBAK); Console.WriteLine("infIndexListString = " + infIndexListString); if (randomize) { // if random is set to true this will take the list of index' for each INF // into a list and shuffle the numbers out of order randomly using random seed // then run through the list in that new order // this will be done uniquely each time through the list for the executionCount executionCount = XMLReader.GetExecutionCount(Program.InputTestFilePath); foreach (int seedIndex in infIndexListString.Split(',').Select(Int32.Parse).ToList <int>()) { if (seedIndex == 0) { break; } if (RegCheck.IsRebootPending()) { Logger.Comment("there is a pending reboot..."); Thread.Sleep(3000); RebootAndContinue.RebootCmd(true); } string index = Convert.ToString(seedIndex); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Current infIndex to be tested : " + index); Console.ForegroundColor = ConsoleColor.White; DriverPathList = GetData.GetInfPathsList(Program.dirName); string line = XMLReader.FromINFIndex(infListCount, Program.InputTestFilePath, seedIndex, executionCount).ToLower(); if (string.IsNullOrEmpty(line)) { XMLWriter.UpdateSeedXML(seedIndex); break; } string infName = Path.GetFileName(line); GetData.CreateIfMissing(Program.resultsLogDir); bool isCapsule = GetData.CheckDriverIsFirmware(line, executionCount, infListCount); switch (isCapsule) { case true: Logger.Comment("this is firmware treat it as such and reboot or rollback\reboot..."); infListCount--; CapsuleOrNotInstallCalls.IfIsCapsule(seedIndex, infIndexListString, infListCount, infName, DriverPathList, line, Program.InputTestFilePathBAK, Program.installer, executionCount, Program.dirName, Program.startChoice, Program.rollbackLine, Program.InputTestFilePath); break; default: Logger.Comment("this is NOT firmware check for reboot afer installed"); infListCount--; CapsuleOrNotInstallCalls.IsNotCapsule(seedIndex, infIndexListString, infListCount, infName, DriverPathList, line, Program.InputTestFilePathBAK, Program.installer, executionCount, Program.dirName, Program.startChoice, Program.rollbackLine, Program.InputTestFilePath); break; } } RebootAndContinue.RebootCmd(true); } else { // straight through the list 1-# accounting for other parameters below // groupFirmware or not as well as user choice first string testIsStartChoice = GetData.GetTestFirst(Program.InputTestFilePath); if (testIsStartChoice.Equals("none") & (Directory.EnumerateDirectories(Program.dirName, "uefi")).Equals(true)) { XMLWriter.SetTestFirst("uefi"); } else if (testIsStartChoice.Equals("none") & (Directory.EnumerateDirectories(Program.dirName, "sam")).Equals(true)) { XMLWriter.SetTestFirst("sam"); } else { testIsStartChoice = "none"; } // add ability to group install all firmware together with only one reboot // in this case the firmware would all install individually but have only one reboot // user should see each different color bar during reboot\install of all firmware bool groupFirmware = XMLReader.GetGroupFirmware(Program.InputTestFilePathBAK); int capListCount = 0; if (groupFirmware) { executionCount = XMLReader.GetExecutionCount(Program.InputTestFilePath); foreach (int seedIndex in infIndexListString.Split(',').Select(Int32.Parse).ToList <int>()) { Console.WriteLine("if (groupFirmware) - seedIndex : " + seedIndex); string line = XMLReader.FromINFIndex(infListCount, Program.InputTestFilePath, seedIndex, executionCount).ToLower(); if (string.IsNullOrEmpty(line)) { XMLWriter.UpdateSeedXML(seedIndex); break; } Console.WriteLine("if (groupFirmware) - line : " + line); bool isCapsule = GetData.CheckDriverIsFirmware(line, executionCount, infListCount); if (isCapsule) { capListCount++; capList.Add(line); } else { continue; } } while (capListCount > 1) { // if this is set to true this will get the firmware in the list to install // install each one and reboot at the end rather than rebooting for each install // replicating more of what a user might see at home when getting more than one // firmware update from WU foreach (string groupedFirmware in capList) { { string seedIndexSTR = XMLReader.IndexFromINF(Program.InputTestFilePath, groupedFirmware); int seedIndex = Convert.ToInt32(seedIndexSTR); XMLWriter.RemoveXMLElemnt(Program.InputTestFilePath, groupedFirmware, seedIndex); Console.WriteLine("seedIndex : " + seedIndex); string friendlyDriverName = XMLReader.GetFriendlyDriverName(Program.InputTestFilePath, groupedFirmware); string hardwareID = GetData.FirmwareInstallGetHID(groupedFirmware); string expectedDriverVersion = GetData.GetDriverVersion(groupedFirmware); Logger.Comment("IfIsCapsule From RegCheck before IF : " + expectedDriverVersion); string infNameToTest = Path.GetFileNameWithoutExtension(groupedFirmware); string expectedDriverDate = GetData.GetDriverDate(groupedFirmware); bool isInstalled = CheckWhatInstalled.CheckInstalled(groupedFirmware, hardwareID, friendlyDriverName, infNameToTest, expectedDriverVersion, expectedDriverDate); switch (isInstalled) { case true: string infFileContent = File.ReadAllText(groupedFirmware).ToUpper(); string infName = Path.GetFileNameWithoutExtension(groupedFirmware); SafeNativeMethods.RollbackInstall(seedIndex, groupedFirmware, infName, infFileContent, hardwareID, rebootRequired = true, Program.InputTestFilePath); break; case false: string groupedFirmwareDIR = Path.GetDirectoryName(groupedFirmware); string installArgs = " /C /A /Q /SE /F /PATH " + groupedFirmwareDIR; SafeNativeMethods.Install_Inf(groupedFirmware, Program.installer, installArgs, seedIndex); break; } } capListCount--; } RebootAndContinue.RebootCmd(true); } } executionCount = XMLReader.GetExecutionCount(Program.InputTestFilePath); foreach (int seedIndex in infIndexListString.Split(',').Select(Int32.Parse).ToList <int>()) { if (seedIndex == 0) { break; } string index = Convert.ToString(seedIndex); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Current infIndex to be tested : " + index); Console.ForegroundColor = ConsoleColor.White; if (index.Equals(null)) { continue; } GetData.CreateIfMissing(Program.resultsLogDir); string line = XMLReader.FromINFIndex(infListCount, Program.InputTestFilePath, seedIndex, executionCount).ToLower(); if (string.IsNullOrEmpty(line)) { XMLWriter.UpdateSeedXML(seedIndex); break; } string infName = Path.GetFileNameWithoutExtension(line); testIsStartChoice = GetData.GetTestFirst(Program.InputTestFilePath); string testInfName = infName.ToLower(); infIndexListString = XMLReader.GetSeed(Program.InputTestFilePathBAK); // the tool will skip to here if none of the other above are met // then looking for a choice set to install first from the list // only works when random is set to False if (line.Contains(testIsStartChoice.ToLower())) { Logger.Comment("This is the start first choice : " + line); bool isCapsule = GetData.CheckDriverIsFirmware(line, executionCount, infListCount); switch (isCapsule) { case true: infListCount--; Logger.Comment("re-add the reg key to start post reboot..."); CapsuleOrNotInstallCalls.IfIsCapsule(seedIndex, infIndexListString, infListCount, infName, DriverPathList, line, Program.InputTestFilePathBAK, Program.installer, executionCount, Program.dirName, Program.startChoice, Program.rollbackLine, Program.InputTestFilePath); break; default: Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("NOT MATCHING to the startChoice"); Console.ForegroundColor = ConsoleColor.White; infListCount--; CapsuleOrNotInstallCalls.IsNotCapsule(seedIndex, infIndexListString, infListCount, infName, DriverPathList, line, Program.InputTestFilePathBAK, Program.installer, executionCount, Program.dirName, Program.startChoice, Program.rollbackLine, Program.InputTestFilePath); break; } } } infIndexListString = XMLReader.GetSeed(Program.InputTestFilePathBAK); foreach (int seedIndex in infIndexListString.Split(',').Select(Int32.Parse).ToList <int>()) { if (seedIndex == 0) { break; } string index = Convert.ToString(seedIndex); Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("Current infIndex to be tested : " + index); Console.ForegroundColor = ConsoleColor.White; string indexString = Convert.ToString(index); if (index.Equals(null)) { continue; } string line = XMLReader.FromINFIndex(infListCount, Program.InputTestFilePath, seedIndex, executionCount).ToLower(); if (string.IsNullOrEmpty(line)) { XMLWriter.UpdateSeedXML(seedIndex); break; } bool isCapsule = GetData.CheckDriverIsFirmware(line, executionCount, infListCount); string infName = Path.GetFileName(line); testIsStartChoice = GetData.GetTestFirst(Program.InputTestFilePath); switch (isCapsule) { case true: Logger.Comment("this is firmware and will need to reboot..."); infListCount--; CapsuleOrNotInstallCalls.IfIsCapsule(seedIndex, infIndexListString, infListCount, infName, DriverPathList, line, Program.InputTestFilePathBAK, Program.installer, executionCount, Program.dirName, Program.startChoice, Program.rollbackLine, Program.InputTestFilePath); break; default: Logger.Comment("THIS IS NOT FIRMWARE..."); infListCount--; CapsuleOrNotInstallCalls.IsNotCapsule(seedIndex, infIndexListString, infListCount, infName, DriverPathList, line, Program.InputTestFilePathBAK, Program.installer, executionCount, Program.dirName, Program.startChoice, Program.rollbackLine, Program.InputTestFilePath); break; } } RebootAndContinue.RebootCmd(true); } executionCount--; Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine("executionCount :: " + executionCount); Console.WriteLine("outside of the while loop"); Console.WriteLine("should be getting smaller correctly"); Console.ForegroundColor = ConsoleColor.White; } } catch (Exception ex) { GetData.GetExceptionMessage(ex); } }
/// <summary> /// This does the driver\capsule installation and checks for the exit code to /// decide what to do next /// </summary> /// <param name="line"></param> /// <param name="installer"></param> /// <param name="installArgs"></param> internal static void Install_Inf(string line, string installer, string installArgs, int seedIndex) { Logger.FunctionEnter(); #region STRINGS AND THINGS string failureCause = "None"; string expectedDriverVersion = "N/A"; string beforeDriverStatus = "N/A"; string afterDriverStatus = "N/A"; bool deviceRuning = true; string errorCodeMessage; string installationExitCode; int TimeOut = 120; //string notInstalledExitCode = "0x800"; string couldNotFindInfToDelete = "0x80000000"; string ElementNotFoundCode = "0x490"; string DeviceCanNotStartCode = "0x10"; string InfFileAlteredCode = "0x80010000"; string NoMatchingDevice = "0xB7"; #endregion try { // starts the installation and checks for exit code // Logger.Comment("...trying to install now"); Logger.Comment("========================="); Logger.Comment(line); Logger.Comment(installer + installArgs); string runCommandinstallArgs = installArgs; Process process = Utilities.RunCommand(installer, runCommandinstallArgs, true); string errorMessage = process.StandardError.ReadToEnd(); string stdOutput = process.StandardOutput.ReadToEnd(); int exitCode = process.ExitCode; string exitCodeInHex = ConvertExitCodeToHex(exitCode); string tmpInstExitCode = "0x" + exitCodeInHex; if (tmpInstExitCode.Equals("0x1")) { tmpInstExitCode = "0x11100000"; } else if (tmpInstExitCode.Equals("0x0")) { tmpInstExitCode = "0x00000000"; } if (tmpInstExitCode.Length <= 5) { installationExitCode = tmpInstExitCode; } else { installationExitCode = tmpInstExitCode.Remove(5); } Console.WriteLine("installationExitCode : " + installationExitCode); // sets a timeout period to wait so the program doesn't get stuck waiting endlessly bool notTimeOut = process.WaitForExit(TimeOut); bool stopOnError = XMLReader.GetStopOnError(Program.InputTestFilePathBAK); if (stopOnError) { string lineContains = string.Empty; switch (lineContains) { case string noMatching when stdOutput.Contains(NoMatchingDevice): GetData.GetExitCode(installationExitCode, stdOutput, errorMessage); Logger.Comment("got exit code 0xB7, No Matching Device : " + line); Console.WriteLine("got exit code 0xB7, No Matching Device : " + line); Logger.Comment("Copy the driverstress log and DPINST.LOG to our folder..."); Utilities.CopyFile(@"C:\Windows\DPINST.LOG", Program.dpinstLog); Utilities.CopyFile(Program.dirName + @"\DriverCapsuleStressLog.txt", Program.resultsLogDir + @"\DriverSDriverCapsuleStressLogtressLog.txt"); Console.ReadKey(); Environment.Exit(13); break; case string elementNotFound when installationExitCode.Equals(ElementNotFoundCode): GetData.GetExitCode(installationExitCode, stdOutput, errorMessage); Logger.Comment("got exit code 49, try to re-install : " + line); Logger.Comment("Elemnt not found error, trying to uninstall a device that is not currently installed"); Console.WriteLine("got exit code 49, try to re-install : " + line); Console.WriteLine("Elemnt not found error, trying to uninstall a device that is not currently installed"); Logger.Comment("Copy the driverstress log and DPINST.LOG to our folder..."); Utilities.CopyFile(@"C:\Windows\DPINST.LOG", Program.dpinstLog); Utilities.CopyFile(Program.dirName + @"\DriverCapsuleStressLog.txt", Program.resultsLogDir + @"\DriverCapsuleStressLog.txt"); Console.ReadKey(); Environment.Exit(13); break; case string cannotStart when installationExitCode.Equals(DeviceCanNotStartCode): Logger.Comment("CODE 10 : device cannot start error for " + line); Console.WriteLine("CODE 10 : device cannot start error for " + line); Logger.Comment("Copy the driverstress log and DPINST.LOG to our folder..."); Utilities.CopyFile(@"C:\Windows\DPINST.LOG", Program.dpinstLog); Utilities.CopyFile(Program.dirName + @"\DriverCapsuleStressLog.txt", Program.resultsLogDir + @"\DriverCapsuleStressLog.txt"); Console.ReadKey(); Environment.Exit(13); break; case string couldNotFindInf when installationExitCode.Equals(couldNotFindInfToDelete): Logger.Comment("could Not Find Inf To Delete...what is up...check the logs later..."); Console.WriteLine("could Not Find Inf To Delete...what is up...check the logs later..."); Logger.Comment("Just move the driverstress log and DPINST.LOG to our folder..."); File.Move(@"C:\Windows\DPINST.LOG", Program.dpinstLog + ".ERR"); File.Move(Program.dirName + @"\DriverCapsuleStressLog.txt", Program.resultsLogDir + @"\DriverCapsuleStressLog-ERR.txt"); Environment.Exit(13); break; case string InfFileAltered when installationExitCode.Equals(InfFileAlteredCode): Logger.Comment("this was not installed because the inf file has been altered"); Console.WriteLine("this was not installed because the inf file has been altered"); Logger.Comment("Copy the driverstress log and DPINST.LOG to our folder..."); Utilities.CopyFile(@"C:\Windows\DPINST.LOG", Program.dpinstLog); Utilities.CopyFile(Program.dirName + @"\DriverCapsuleStressLog.txt", Program.resultsLogDir + @"\DriverCapsuleStressLog.txt"); Environment.Exit(13); break; default: if (notTimeOut == false) { failureCause = "Driver installation Timed-Out"; errorCodeMessage = string.Format(line + " Driver installation Timed-Out"); Logger.Comment(line + " Driver installation Failed due to Time-Out::: " + errorCodeMessage, expectedDriverVersion, DateTime.Now.ToString("MM/dd/yyyy H:mm:ss:fff"), beforeDriverStatus, afterDriverStatus, deviceRuning, failureCause); Logger.Comment("Copy the driverstress log and DPINST.LOG to our folder..."); Utilities.CopyFile(@"C:\Windows\DPINST.LOG", Program.dpinstLog); Utilities.CopyFile(Program.dirName + @"\DriverCapsuleStressLog.txt", Program.resultsLogDir + @"\DriverCapsuleStressLog.txt"); Console.ReadKey(); Environment.Exit(13); } break; } } process.Dispose(); } catch (Exception ex) { GetData.GetExceptionMessage(ex); } Logger.FunctionLeave(); }
/// <summary> /// firmware or regular driver will still call this to do the actual installation /// </summary> /// <param name="infName"></param> /// <param name="line"></param> /// <param name="installer"></param> /// <param name="installArgs"></param> /// <param name="InputTestFilePath"></param> /// <param name="rebootRequired"></param> /// <param name="hardwareID"></param> /// SafeNativeMethods.InstallUninstallCall(seedIndex, rebootRequired, infName, line, installer, InputTestFilePath); internal static void InstallUninstallCall(int seedIndex, bool rebootRequired, string infName, string line, string installer, string InputTestFilePath) { try { Logger.FunctionEnter(); string expectedDriverVersion = GetData.GetDriverVersion(line); string infNameToTest = Path.GetFileNameWithoutExtension(line); string expectedDriverDate = GetData.GetDriverDate(line); string infPath = Path.GetDirectoryName(line); string installArgs; string friendlyDriverName = XMLReader.GetFriendlyDriverName(InputTestFilePath, line); Console.WriteLine(line + " and " + seedIndex); Console.WriteLine("RemoveXMLElement now"); XMLWriter.RemoveXMLElemnt(Program.InputTestFilePath, line, seedIndex); Console.WriteLine("check the xml please.."); string hardwareID = GetData.FirmwareInstallGetHID(line); bool isInstalled = CheckWhatInstalled.CheckInstalled(line, hardwareID, friendlyDriverName, infNameToTest, expectedDriverVersion, expectedDriverDate); if (isInstalled) { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("----------------------------------------------------------"); Console.WriteLine("THIS PnP DRIVER VERSION IS INSTALLED UN-INSTALLING NOW...."); Console.WriteLine(infName); Console.WriteLine("----------------------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; Logger.Comment("rebootRequired is showing as : " + rebootRequired); installArgs = " /C /U " + line + " /Q /D"; Install_Inf(line, installer, installArgs, seedIndex); Logger.Comment("Operation should be complete: " + line); string classGUID = GetData.GetClassGUID(line); GetDataFromReg.GetOEMinfNameFromReg(infName, hardwareID, classGUID); if (RegCheck.IsRebootPending()) { Logger.Comment("there is a pending reboot..."); RebootAndContinue.RebootCmd(true); } } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("---------------------------------------------------------------"); Console.WriteLine("THIS PnP DRIVER VERSION WAS NOT INSTALLED YET INSTALLING NOW..."); Console.WriteLine(infName); Console.WriteLine("---------------------------------------------------------------"); Console.ForegroundColor = ConsoleColor.White; Logger.Comment("rebootRequired is showing as : " + rebootRequired); installArgs = " /C /A /Q /SE /F /PATH " + infPath; Install_Inf(line, installer, installArgs, seedIndex); string classGUID = GetData.GetClassGUID(line); XMLWriter.SetLastInstalled(line); //can we check registry simiarly to firmware for PnP drivers? Logger.Comment("Operation should be complete: " + line); if (RegCheck.IsRebootPending()) { Logger.Comment("there is a pending reboot..."); RebootAndContinue.RebootCmd(true); } } Logger.FunctionLeave(); } catch (Exception ex) { GetData.GetExceptionMessage(ex); } }
/// <summary> /// just another check to be sure driver is installed /// this will run after there is a reboot so is mostly for validation of firmware installs /// GetData.IsInstalledAfterReboot(); /// </summary> internal static string IsInstalledAfterReboot(string line) { string result = "pass"; string returnCode = "pass"; try { // get the file attributes for file or directory FileAttributes attr = File.GetAttributes(line); // detect whether its a directory or file if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { foreach (string tmpPath in Directory.EnumerateFiles(line)) { if (tmpPath.EndsWith(".inf")) { line = tmpPath; } else { continue; } } } string TMPexpectedVersion = GetDriverVersion(line); string TMPinfName = Path.GetFileNameWithoutExtension(line); string TMPhardwareID = FirmwareInstallGetHID(line); string classGUID = GetClassGUID(line); int TMPinfListCount = XMLReader.GetInfsPathListCount(Program.InputTestFilePathBAK); int executionCount = XMLReader.GetExecutionCount(Program.InputTestFilePath); bool TMPisCapsule = CheckDriverIsFirmware(line, executionCount, TMPinfListCount); bool stopOnError = XMLReader.GetStopOnError(Program.InputTestFilePathBAK); if (TMPisCapsule) { string CapsuleDidInstall = GetDataFromReg.CheckRegCapsuleIsInstalled(TMPinfName, TMPhardwareID, TMPexpectedVersion, line); if (stopOnError.Equals(true)) { switch (returnCode) { case string failed when CapsuleDidInstall.Equals("unsuccessful"): returnCode = "unsuccessful registry code is 1 "; XMLErrorMessage(returnCode, line); break; case string InsufficientResources when CapsuleDidInstall.Equals("InsufficientResources"): returnCode = "InsufficientResources registry code is 2 "; XMLErrorMessage(returnCode, line); break; case string IncorrectVersion when CapsuleDidInstall.Equals("IncorrectVersion"): returnCode = "IncorrectVersion registry code is 3 "; XMLErrorMessage(returnCode, line); break; case string invalidImage when CapsuleDidInstall.Equals("invalidImage"): returnCode = "invalidImage registry code is 4 "; XMLErrorMessage(returnCode, line); break; case string authenticationERR when CapsuleDidInstall.Equals("authenticationERR"): returnCode = "authenticationERR registry code is 5 "; XMLErrorMessage(returnCode, line); break; case string ACnotConnected when CapsuleDidInstall.Equals("ACnotConnected"): returnCode = "ACnotConnected registry code is 6 "; XMLErrorMessage(returnCode, line); break; case string insufficientPower when CapsuleDidInstall.Equals("insufficientPower"): returnCode = "insufficientBatteryPower registry code is 7 "; XMLErrorMessage(returnCode, line); break; default: returnCode = "pass"; result = returnCode; Logger.Comment("checked the registry after reboot but this firmware installed correctly " + returnCode + " " + line); Console.WriteLine("checked the registry after reboot but this firmware installed correctly " + returnCode + " " + line); break; } } } return(result); } catch (Exception ex) { GetExceptionMessage(ex); return(result); } }