Exemplo n.º 1
0
        public void ScriptNullScript()
        {
            String testScriptName = "Name";

            // Create a script.
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Removes the specified script.
        /// </summary>
        /// <param name="scriptName">Name of script to remove.</param>
        public void RemoveScript(String scriptName)
        {
            // Cannot create an autoscript from the client.
            if (isAutoScript(scriptName))
            {
                throw new StackHashException("Cannot remove system scripts", StackHashServiceErrorCode.CannotRemoveSystemScripts);
            }

            String fileName = getScriptFileName(scriptName);

            // Load it to see if it is read only.
            if (File.Exists(fileName))
            {
                StackHashScriptSettings script = StackHashScriptSettings.Load(fileName);

                if (!script.IsReadOnly)
                {
                    File.Delete(fileName);
                }
                else
                {
                    throw new StackHashException("Cannot remove Read Only script", StackHashServiceErrorCode.CannotRemoveSystemScripts);
                }
            }
        }
Exemplo n.º 3
0
        public void ScriptGenerateNoLines()
        {
            String testScriptName = "Name";

            // Create a script - empty.
            StackHashScript         script         = new StackHashScript();
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script);

            String tempFileName   = m_TempPath + "\\GeneratedScript.wds";
            String outputFileName = "c:\\test\\results.log";


            String symPath = null;
            String exePath = null;
            String srcPath = null;

            scriptSettings.GenerateScriptFile(tempFileName, outputFileName, ref symPath, ref exePath, ref srcPath);

            Assert.AreEqual(null, symPath);
            Assert.AreEqual(null, exePath);
            Assert.AreEqual(null, srcPath);

            // Read all of the data in.
            String[] allLines = File.ReadAllLines(tempFileName);

            Assert.AreEqual(true, File.Exists(tempFileName));

            // Should just contain a comment line.
            Assert.AreEqual(4, allLines.Length);
            Assert.AreEqual(true, allLines[0].Contains(outputFileName));
            Assert.AreEqual(true, allLines[1].Contains(testScriptName));
            Assert.AreEqual(true, allLines[1].Contains(scriptSettings.LastModifiedDate.ToString(CultureInfo.InvariantCulture)));
            Assert.AreEqual(true, allLines[2].Contains("Script Complete"));
            Assert.AreEqual(true, allLines[3].Contains(".logclose"));
        }
Exemplo n.º 4
0
        public void GetUnquotedPathFromCommandLineParamOriginalNullConcat()
        {
            String path         = "c:\\testpath";
            String command      = ".sympath +";
            String commandLine  = command + " " + path;
            String originalPath = null;

            String outPath = StackHashScriptSettings.GetUnquotedPathFromCommandLine(originalPath, commandLine, ".sympath");

            Assert.AreEqual(path, outPath);
        }
Exemplo n.º 5
0
        public void GetUnquotedPathFromCommandCommandMismatch()
        {
            String path         = "\"c:\\testpath;z:\\stuff\"";
            String command      = "     .SymPath    +    ";
            String commandLine  = command + " " + path;
            String originalPath = "c:\\original";

            String outPath = StackHashScriptSettings.GetUnquotedPathFromCommandLine(originalPath, commandLine, ".srcpath");

            Assert.AreEqual(originalPath, outPath);
        }
Exemplo n.º 6
0
        public void GetUnquotedPathFromCommandLineNoParameterOriginalNull()
        {
            String path         = "";
            String command      = ".sympath";
            String commandLine  = command + " " + path;
            String originalPath = null;

            String outPath = StackHashScriptSettings.GetUnquotedPathFromCommandLine(originalPath, commandLine, ".sympath");

            Assert.AreEqual(null, outPath);
        }
Exemplo n.º 7
0
        public void UpdateScriptFile()
        {
            bool saveAutoScript = false;
            bool fileExists     = File.Exists(m_ScriptFileName);

            if (fileExists)
            {
                // Load in the script and check the version number. If there is an error during load
                // then just create a new copy of the file.
                try
                {
                    StackHashScriptSettings thisScript = StackHashScriptSettings.Load(m_ScriptFileName);
                    saveAutoScript = !IsScriptCurrent(thisScript);
                }
                catch (System.Exception ex)
                {
                    String message = String.Format(CultureInfo.InvariantCulture, "Failed to load script {0} - Reconstructing", ScriptName);
                    DiagnosticsHelper.LogException(DiagSeverity.Warning, message, ex);
                    saveAutoScript = true;
                }
            }
            else
            {
                saveAutoScript = true;
            }

            FileAttributes currentAttributes;

            if (saveAutoScript)
            {
                if (fileExists)
                {
                    currentAttributes = File.GetAttributes(m_ScriptFileName);

                    // Turn off the readonly permission so the file can be updated.
                    if ((currentAttributes & FileAttributes.ReadOnly) != 0)
                    {
                        // Clear the read only flag.
                        File.SetAttributes(m_ScriptFileName, currentAttributes & ~FileAttributes.ReadOnly);
                    }
                }
                StackHashScriptSettings autoScript = GenerateScript();
                autoScript.Save(m_ScriptFileName);
            }

            // Make sure the file is marked read only so the client can't delete it.
            currentAttributes = File.GetAttributes(m_ScriptFileName);
            if ((currentAttributes & FileAttributes.ReadOnly) == 0)
            {
                // Set the read only flag.
                File.SetAttributes(m_ScriptFileName, currentAttributes | FileAttributes.ReadOnly);
            }
        }
Exemplo n.º 8
0
 public void GetUnquotedPathFromCommandLineNullCommand()
 {
     try
     {
         StackHashScriptSettings.GetUnquotedPathFromCommandLine(null, ".sympath", null);
     }
     catch (System.ArgumentNullException ex)
     {
         Assert.AreEqual("command", ex.ParamName);
         throw;
     }
 }
Exemplo n.º 9
0
        public void GetUnquotedPathFromCommandLineQuotesNoConcat()
        {
            String path         = "\"c:\\testpath\"";
            String command      = ".sympath   ";
            String commandLine  = command + " " + path;
            String originalPath = "c:\\original";

            String outPath = StackHashScriptSettings.GetUnquotedPathFromCommandLine(originalPath, commandLine, ".sympath");

            String expectedResult = "c:\\testpath";

            Assert.AreEqual(expectedResult, outPath);
        }
Exemplo n.º 10
0
        public void GetUnquotedPathFromCommandCalledTwiceNoConcat()
        {
            String path         = "c:\\path";
            String command      = "     .SymPath        ";
            String commandLine  = command + " " + path;
            String originalPath = "c:\\original";

            String outPath = StackHashScriptSettings.GetUnquotedPathFromCommandLine(originalPath, commandLine, ".sympath");

            outPath = StackHashScriptSettings.GetUnquotedPathFromCommandLine(outPath, commandLine, ".sympath");

            Assert.AreEqual(path, outPath);
        }
Exemplo n.º 11
0
        public void GetUnquotedPathFromCommandLineQuotesAndSpaceAndCase()
        {
            String path         = "\"c:\\testpath;z:\\stuff\"";
            String command      = "     .SymPath    +    ";
            String commandLine  = command + " " + path;
            String originalPath = "c:\\original";

            String outPath = StackHashScriptSettings.GetUnquotedPathFromCommandLine(originalPath, commandLine, ".sympath");

            String expectedResult = originalPath + ";" + "c:\\testpath;z:\\stuff";

            Assert.AreEqual(expectedResult, outPath);
        }
Exemplo n.º 12
0
        /// <summary>
        /// Determines if the specified version of the auto script file is up to date.
        /// </summary>
        /// <param name="script"></param>
        /// <returns></returns>
        public bool IsScriptCurrent(StackHashScriptSettings script)
        {
            if (script == null)
            {
                throw new ArgumentNullException("script");
            }

            if (script.Name != m_ScriptName)
            {
                throw new ArgumentException("Script file not specified", "script");
            }

            return(script.Version == CurrentVersion);
        }
Exemplo n.º 13
0
        public void RunAllAutoScripts()
        {
            String dumpFileName = m_TempPath + "Cucku.exe.mdmp";

            // First make a copy of the test cab file.
            File.Copy(TestSettings.TestDataFolder + @"Dumps\Cucku.exe.mdmp",
                      dumpFileName, true);
            FileAttributes attributes = File.GetAttributes(dumpFileName);

            File.SetAttributes(dumpFileName, attributes & ~FileAttributes.ReadOnly);

            ScriptManager scriptManager = new ScriptManager(m_TempPath);

            // Now execute the script.
            StackHashDebug.Windbg winDbg = new Windbg();

            try
            {
                Collection <AutoScriptBase> autoScripts = scriptManager.AutoScripts;

                foreach (AutoScriptBase autoScript in autoScripts)
                {
                    // Generate the script settings structure in memory.
                    StackHashScriptSettings scriptSettings = autoScript.GenerateScript();

                    // Those settings are now used to create a WinDbg script file (wds). This file has a command
                    // to create a log file (the resultsFileName).
                    String resultsFileName = String.Format("{0}.log", Path.Combine(m_TempPath, autoScript.ScriptName));
                    String scriptFileName  = String.Format("{0}.wds", Path.Combine(m_TempPath, autoScript.ScriptName));
                    String symPath         = null;
                    String exePath         = null;
                    String srcPath         = null;
                    scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref symPath, ref exePath, ref srcPath);

                    // Run the wds file through the debugger to produce the results.log file.
                    winDbg.RunScript(m_DebuggerSettings, false, scriptFileName, dumpFileName, m_TempPath, symPath, exePath, srcPath);

                    // Load the results.log file.
                    StackHashScriptResult scriptResults = new StackHashScriptResult(resultsFileName);

                    // Analyse the results.
                    StackHashDumpAnalysis analysis = new StackHashDumpAnalysis();
                    analysis = autoScript.AnalyzeScriptResults(analysis, scriptResults);
                }
            }
            finally
            {
                scriptManager.RemoveAutoScripts();
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Gets all script contexts.
        /// </summary>
        /// <returns>Full list of all the script settings.</returns>
        private StackHashScriptCollection GetAllScripts()
        {
            StackHashScriptCollection allScripts = new StackHashScriptCollection();

            String [] allScriptFiles = Directory.GetFiles(m_ScriptFolder, s_ScriptWildcard);

            foreach (String fileName in allScriptFiles)
            {
                StackHashScriptSettings thisScript = StackHashScriptSettings.Load(fileName);

                allScripts.Add(thisScript);
            }

            return(allScripts);
        }
Exemplo n.º 15
0
        public void ScriptContainsPssCorIa64Clr4()
        {
            String testScriptName = "Name";
            String testCommand    = @".load psscor.dll";
            String testComment    = @"loads psscor from correct location";

            StackHashScript script = new StackHashScript();

            script.Add(new StackHashScriptLine(testCommand, testComment));

            StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script);

            scriptSettings.FixUp(StackHashScriptDumpArchitecture.IA64, "4.0.2355.2233", "C:\\test");

            Assert.AreEqual(0, String.Compare(".load C:\\test\\psscor4\\ia64\\psscor4.dll", scriptSettings.Script[0].Command, StringComparison.OrdinalIgnoreCase));
        }
Exemplo n.º 16
0
        /// <summary>
        /// Adds or edits a debugger script
        /// </summary>
        /// <param name="clientLogic">Client Logic</param>
        /// <param name="scriptSettings">Script to edit (new blank script if add)</param>
        /// <param name="add">True if this is a new script, false if an existing script is being edited</param>
        public ScriptAddEdit(ClientLogic clientLogic, StackHashScriptSettings scriptSettings, bool add)
        {
            Debug.Assert(clientLogic != null);
            Debug.Assert(scriptSettings != null);

            _clientLogic    = clientLogic;
            _scriptSettings = scriptSettings;
            _add            = add;

            InitializeComponent();

            if (UserSettings.Settings.HaveWindow(WindowKey))
            {
                UserSettings.Settings.RestoreWindow(WindowKey, this);
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// Generates the auto script file in memory.
        /// </summary>
        /// <returns>Full script settings.</returns>
        public override StackHashScriptSettings GenerateScript()
        {
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings();

            scriptSettings.CreationDate     = DateTime.Now.ToUniversalTime();
            scriptSettings.LastModifiedDate = scriptSettings.CreationDate;
            scriptSettings.Name             = base.ScriptName;
            scriptSettings.Owner            = StackHashScriptOwner.System;
            scriptSettings.RunAutomatically = true;
            scriptSettings.Version          = base.CurrentVersion;
            scriptSettings.IsReadOnly       = true;
            scriptSettings.DumpType         = StackHashScriptDumpType.UnmanagedAndManaged; // Run script on all types of dump.
            scriptSettings.Script           = new StackHashScript();
            scriptSettings.Script.Add(new StackHashScriptLine(s_VerTargetCommand, s_VerTargetComment));

            return(scriptSettings);
        }
Exemplo n.º 18
0
        public void ScriptGenerate2LinesOtherWayAround()
        {
            String testScriptName = "Name";
            String testCommand2   = @"$$ Command 1";
            String testComment2   = @"Demo Comment 1";
            String testCommand1   = @"$$ Command 2";
            String testComment1   = @"Another comment";

            // Create a script - empty.
            StackHashScript script = new StackHashScript();

            script.Add(new StackHashScriptLine(testCommand1, testComment1));
            script.Add(new StackHashScriptLine(testCommand2, testComment2));
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script);

            String tempFileName   = m_TempPath + "\\GeneratedScript.wds";
            String outputFileName = "c:\\test\\results.log";
            String symPath        = null;
            String exePath        = null;
            String srcPath        = null;

            scriptSettings.GenerateScriptFile(tempFileName, outputFileName, ref symPath, ref exePath, ref srcPath);

            Assert.AreEqual(null, symPath);
            Assert.AreEqual(null, exePath);
            Assert.AreEqual(null, srcPath);

            // Read all of the data in.
            String[] allLines = File.ReadAllLines(tempFileName);

            Assert.AreEqual(true, File.Exists(tempFileName));

            // Should contain the script header comment plus one command and one comment line for each command.
            Assert.AreEqual(10, allLines.Length);
            Assert.AreEqual(true, allLines[0].Contains(outputFileName));
            Assert.AreEqual(true, allLines[1].Contains(testScriptName));
            Assert.AreEqual(true, allLines[1].Contains(scriptSettings.LastModifiedDate.ToString(CultureInfo.InvariantCulture)));
            Assert.AreEqual(true, allLines[2].Contains(scriptSettings.Script[0].Comment));
            Assert.AreEqual(true, allLines[3].StartsWith(scriptSettings.Script[0].Command));
            Assert.AreEqual(true, allLines[4].Contains(scriptSettings.Script[0].Comment));
            Assert.AreEqual(true, allLines[5].Contains(scriptSettings.Script[1].Comment));
            Assert.AreEqual(true, allLines[6].StartsWith(scriptSettings.Script[1].Command));
            Assert.AreEqual(true, allLines[7].Contains(scriptSettings.Script[1].Comment));
            Assert.AreEqual(true, allLines[8].Contains("Script Complete"));
            Assert.AreEqual(true, allLines[9].Contains(".logclose"));
        }
Exemplo n.º 19
0
        /// <summary>
        /// Gets the results files for the specified cab.
        /// </summary>
        /// <param name="product">Product to which the cab belongs</param>
        /// <param name="file">File to which the cab belongs</param>
        /// <param name="theEvent">Event to which the cab belongs</param>
        /// <param name="cab">Cab to get results for.</param>
        /// <returns>All script results for specified cab.</returns>
        public StackHashScriptResultFiles GetResultFiles(StackHashProduct product,
                                                         StackHashFile file, StackHashEvent theEvent, StackHashCab cab)
        {
            // Unwrap the cab if necessary.
            String cabFileFolder = m_ErrorIndex.GetCabFolder(product, file, theEvent, cab);

            cabFileFolder += "\\Analysis";

            // Get a list of the results log files.
            String[] files;
            if (Directory.Exists(cabFileFolder))
            {
                files = Directory.GetFiles(cabFileFolder, "*.log");
            }
            else
            {
                files = new String[0];
            }

            StackHashScriptResultFiles resultFiles = new StackHashScriptResultFiles();

            foreach (String fileName in files)
            {
                // Need to get whether it is an auto or user script.
                String fileNameNoExtension             = Path.GetFileNameWithoutExtension(fileName);
                StackHashScriptSettings scriptSettings = m_ScriptManager.LoadScript(fileNameNoExtension, true);

                StackHashScriptResultFile resultFile = new StackHashScriptResultFile();
                resultFile.RunDate    = File.GetLastWriteTimeUtc(fileName);
                resultFile.ScriptName = Path.GetFileNameWithoutExtension(fileName);

                if ((scriptSettings == null) || (scriptSettings.Owner == StackHashScriptOwner.System))
                {
                    resultFile.UserName = "******";
                }
                else
                {
                    resultFile.UserName = "******";
                }

                resultFiles.Add(resultFile);
            }

            return(resultFiles);
        }
Exemplo n.º 20
0
        private void scriptSaveLoadNCommands(int numCommands, bool addComment)
        {
            StackHashScript script = new StackHashScript();

            for (int i = 0; i < numCommands; i++)
            {
                String command = "command" + i.ToString();
                String comment = null;
                if (addComment)
                {
                    comment = "comment" + i.ToString();
                }
                script.Add(new StackHashScriptLine(command, comment));
            }
            String testScriptName = m_TempPath + "\\scriptsettings.wds";
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script);

            scriptSettings.Name             = "TestName";
            scriptSettings.CreationDate     = DateTime.Now.ToUniversalTime();
            scriptSettings.LastModifiedDate = DateTime.Now.ToUniversalTime();
            scriptSettings.Owner            = StackHashScriptOwner.System;
            scriptSettings.RunAutomatically = true;
            scriptSettings.Version          = 2;
            scriptSettings.Save(testScriptName);

            // And load in again and compare.
            StackHashScriptSettings loadedSettings = StackHashScriptSettings.Load(testScriptName);


            Assert.AreEqual(scriptSettings.CreationDate, loadedSettings.CreationDate);
            Assert.AreEqual(scriptSettings.LastModifiedDate, loadedSettings.LastModifiedDate);
            Assert.AreEqual(scriptSettings.Name, loadedSettings.Name);
            Assert.AreEqual(scriptSettings.Script.Count, loadedSettings.Script.Count);
            Assert.AreEqual(scriptSettings.RunAutomatically, loadedSettings.RunAutomatically);
            Assert.AreEqual(scriptSettings.Version, loadedSettings.Version);
            Assert.AreEqual(scriptSettings.Owner, loadedSettings.Owner);

            for (int i = 0; i < scriptSettings.Script.Count; i++)
            {
                Assert.AreEqual(scriptSettings.Script[i].Command, loadedSettings.Script[i].Command);
                Assert.AreEqual(scriptSettings.Script[i].Comment, loadedSettings.Script[i].Comment);
            }
        }
Exemplo n.º 21
0
        public void RunAutoScript()
        {
            String dumpFileName    = m_TempPath + "Cucku.exe.mdmp";
            String scriptFileName  = m_TempPath + "AutoScript.wds";
            String resultsFileName = m_TempPath + "AutoScript.log";

            // First make a copy of the test cab file.
            File.Copy(TestSettings.TestDataFolder + @"Dumps\Cucku.exe.mdmp",
                      dumpFileName, true);
            FileAttributes attributes = File.GetAttributes(dumpFileName);

            File.SetAttributes(dumpFileName, attributes & ~FileAttributes.ReadOnly);

            AutoScript autoScript = new AutoScript(m_TempPath);
            StackHashScriptSettings scriptSettings = autoScript.GenerateScript();
            String symPath = null;
            String exePath = null;
            String srcPath = null;

            scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref symPath, ref exePath, ref srcPath);

            Assert.AreEqual(null, symPath);
            Assert.AreEqual(null, exePath);
            Assert.AreEqual(null, srcPath);

            // Now execute the script.
            StackHashDebug.Windbg winDbg = new Windbg();
            winDbg.RunScript(m_DebuggerSettings, false, scriptFileName, dumpFileName, m_TempPath, symPath, exePath, srcPath);

            // Load the results file.
            StackHashScriptResult scriptResults = new StackHashScriptResult(resultsFileName);

            // Analyse the results.
            StackHashDumpAnalysis analysis = new StackHashDumpAnalysis();

            analysis = autoScript.AnalyzeScriptResults(analysis, scriptResults);

            Assert.AreEqual("not available", analysis.SystemUpTime);
            Assert.AreEqual("0 days 0:02:20.000", analysis.ProcessUpTime);

            Assert.AreEqual("2.0.50727.3603", analysis.DotNetVersion);
        }
Exemplo n.º 22
0
        public void ScriptConstructor()
        {
            String testCommand    = @"$$ This is a simple command";
            String testComment    = @"Just a demo";
            String testScriptName = "Name";

            // Create a script.
            StackHashScript script = new StackHashScript();

            script.Add(new StackHashScriptLine(testCommand, testComment));
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script);

            Assert.AreEqual(testCommand, script[0].Command);
            Assert.AreEqual(testComment, script[0].Comment);
            Assert.AreEqual(StackHashScriptDumpType.UnmanagedAndManaged, scriptSettings.DumpType);

            Assert.AreEqual(testScriptName, scriptSettings.Name);
            Assert.AreEqual(scriptSettings.LastModifiedDate, scriptSettings.CreationDate);
            Assert.AreEqual(true, DateTime.Now.ToUniversalTime().Second - scriptSettings.CreationDate.Second <= 2);
        }
Exemplo n.º 23
0
        /// <summary>
        /// Generates the auto script file in memory.
        /// </summary>
        /// <returns>Full script settings.</returns>
        public override StackHashScriptSettings GenerateScript()
        {
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings();

            scriptSettings.CreationDate     = DateTime.Now.ToUniversalTime();
            scriptSettings.LastModifiedDate = scriptSettings.CreationDate;
            scriptSettings.Name             = s_ScriptName;
            scriptSettings.Owner            = StackHashScriptOwner.System;
            scriptSettings.Version          = s_CurrentVersion;
            scriptSettings.IsReadOnly       = true;
            scriptSettings.RunAutomatically = true;                                        // This is automatic but not defined by the user.
            scriptSettings.DumpType         = StackHashScriptDumpType.UnmanagedAndManaged; // Run script on all types of dump.
            scriptSettings.Script           = new StackHashScript();
            scriptSettings.Script.Add(new StackHashScriptLine(s_DebuggerVersionCommand, s_DebuggerVersionComment));
            scriptSettings.Script.Add(new StackHashScriptLine(s_VerTargetCommand, s_VerTargetComment));
            scriptSettings.Script.Add(new StackHashScriptLine(s_MscoreModuleCommand, s_MscoreModuleComment));
            scriptSettings.Script.Add(new StackHashScriptLine(s_MscoreModuleCommand2, s_MscoreModuleComment2));

            return(scriptSettings);
        }
Exemplo n.º 24
0
        /// <summary>
        /// Loads the specified script file.
        /// </summary>
        /// <param name="scriptName">Script to load.</param>
        /// <returns>The script settings.</returns>
        public StackHashScriptSettings LoadScript(string scriptName, bool noException)
        {
            String fileName = getScriptFileName(scriptName);

            if (!File.Exists(fileName))
            {
                if (noException)
                {
                    return(null);
                }
                else
                {
                    throw new StackHashException("Script file does not exist when loading script.", StackHashServiceErrorCode.ScriptDoesNotExist);
                }
            }

            StackHashScriptSettings newScriptSettings = StackHashScriptSettings.Load(fileName);

            return(newScriptSettings);
        }
Exemplo n.º 25
0
        private void DoAdd()
        {
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings();

            scriptSettings.Script           = new StackHashScript();
            scriptSettings.IsReadOnly       = false;
            scriptSettings.RunAutomatically = false;
            scriptSettings.Version          = 1;
            scriptSettings.Owner            = StackHashScriptOwner.User;

            ScriptAddEdit scriptAdd = new ScriptAddEdit(_clientLogic, scriptSettings, true);

            scriptAdd.Owner = this;

            if (scriptAdd.ShowDialog() == true)
            {
                _reselectScriptName = scriptSettings.Name;
                _clientLogic.AdminAddScript(scriptSettings, scriptSettings.Name, false);
            }
        }
Exemplo n.º 26
0
        public void ScriptGenerate1Line()
        {
            String testScriptName = "Name";
            String testCommand    = @"$$ This is a simple command";
            String testComment    = @"Just a demo";

            // Create a script - empty.
            StackHashScript script = new StackHashScript();

            script.Add(new StackHashScriptLine(testCommand, testComment));
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script);

            String m_TempFileName = m_TempPath + "\\GeneratedScript.wds";
            String outputFileName = "c:\\test\\results.log";
            String symPath        = null;
            String exePath        = null;
            String srcPath        = null;

            scriptSettings.GenerateScriptFile(m_TempFileName, outputFileName, ref symPath, ref exePath, ref srcPath);

            Assert.AreEqual(null, symPath);
            Assert.AreEqual(null, exePath);
            Assert.AreEqual(null, srcPath);


            // Read all of the data in.
            String[] allLines = File.ReadAllLines(m_TempFileName);

            Assert.AreEqual(true, File.Exists(m_TempFileName));

            // Should contain the script header comment, and one command comment and one command.
            Assert.AreEqual(7, allLines.Length);
            Assert.AreEqual(true, allLines[0].Contains(outputFileName));
            Assert.AreEqual(true, allLines[1].Contains(testScriptName));
            Assert.AreEqual(true, allLines[1].Contains(scriptSettings.LastModifiedDate.ToString(CultureInfo.InvariantCulture)));
            Assert.AreEqual(true, allLines[2].Contains(scriptSettings.Script[0].Comment));
            Assert.AreEqual(true, allLines[3].StartsWith(scriptSettings.Script[0].Command));
            Assert.AreEqual(true, allLines[4].Contains(scriptSettings.Script[0].Comment));
            Assert.AreEqual(true, allLines[5].Contains("Script Complete"));
            Assert.AreEqual(true, allLines[6].Contains(".logclose"));
        }
Exemplo n.º 27
0
        public void RunSimpleScript()
        {
            // Create a test script.
            String testScriptName = "ScriptName";
            String testCommand    = @"r";
            String testComment    = @"Just a demo";

            StackHashScript script = new StackHashScript();

            script.Add(new StackHashScriptLine(testCommand, testComment));
            StackHashScriptSettings scriptSettings = new StackHashScriptSettings(testScriptName, script);

            String scriptFileName  = m_TempPath + @"\GeneratedScript.wds";
            String resultsFileName = m_TempPath + @"\Results.log";
            String symPath         = null;
            String exePath         = null;
            String srcPath         = null;

            scriptSettings.GenerateScriptFile(scriptFileName, resultsFileName, ref symPath, ref exePath, ref srcPath);

            Assert.AreEqual(null, symPath);
            Assert.AreEqual(null, exePath);
            Assert.AreEqual(null, srcPath);

            // Run the script with the debugger.
            Windbg debugger     = new Windbg();
            String dumpFileName = TestSettings.TestDataFolder + @"Dumps\Cucku.exe.mdmp";

            StackHashDebuggerSettings debuggerSettings = new StackHashDebuggerSettings();

            debuggerSettings.DebuggerPathAndFileName = StackHashDebuggerSettings.Default32BitDebuggerPathAndFileName;
            debuggerSettings.SymbolPath = StackHashSearchPath.DefaultSymbolPath;
            debugger.RunScript(debuggerSettings, true, scriptFileName, dumpFileName, resultsFileName, symPath, exePath, srcPath);

            Assert.AreEqual(true, File.Exists(resultsFileName));
            String[] allResults = File.ReadAllLines(resultsFileName, Encoding.Unicode);

            Assert.AreEqual(true, allResults.Length > 0);
        }
Exemplo n.º 28
0
        /// <summary>
        /// Renames the specified script.
        /// </summary>
        /// <param name="oldScriptName">Current name of the script.</param>
        /// <param name="newScriptName">New name of the script.</param>
        public void RenameScript(String oldScriptName, String newScriptName)
        {
            if (string.IsNullOrEmpty(oldScriptName))
            {
                throw new ArgumentNullException("oldScriptName");
            }
            if (string.IsNullOrEmpty(newScriptName))
            {
                throw new ArgumentNullException("newScriptName");
            }

            // Don't do anything if the name hasn't changed.
            if (oldScriptName == newScriptName)
            {
                return;
            }

            String fileName = getScriptFileName(oldScriptName);

            if (!File.Exists(fileName))
            {
                throw new StackHashException("Script name does not exist during rename", StackHashServiceErrorCode.ScriptDoesNotExist);
            }

            // Load in the script and save it to the new name.
            StackHashScriptSettings thisScript = StackHashScriptSettings.Load(fileName);

            thisScript.Name             = newScriptName;
            thisScript.LastModifiedDate = DateTime.Now.ToUniversalTime();

            String newFileName = getScriptFileName(newScriptName);

            thisScript.Save(newFileName);

            // Delete the old script as the renamed version is now available.
            File.Delete(fileName);
        }
Exemplo n.º 29
0
        /// <summary>
        /// Add a new script.
        /// </summary>
        /// <param name="script">Full script settings.</param>
        /// <param name="overwrite">true - Overwrite any old script of the same name.</param>
        /// <param name="allowReadOnlyScriptOverwrite">true - allow read only script to be overwritten.</param>
        public void AddScript(StackHashScriptSettings script, bool overwrite, bool allowReadOnlyScriptOverwrite)
        {
            if (script == null)
            {
                throw new ArgumentNullException("script");
            }

            String fileName = getScriptFileName(script.Name);

            if (File.Exists(fileName))
            {
                if (!overwrite)
                {
                    throw new StackHashException("Script file already exists and overWrite not set", StackHashServiceErrorCode.CannotOverwriteScriptFile);
                }
                else
                {
                    // File already exists. The Created time should remain the same. The update time should change.
                    StackHashScriptSettings oldScript = StackHashScriptSettings.Load(fileName);

                    if (oldScript.IsReadOnly && !allowReadOnlyScriptOverwrite)
                    {
                        throw new InvalidOperationException("Cannot overwrite Read Only script");
                    }

                    script.CreationDate     = oldScript.CreationDate;
                    script.LastModifiedDate = DateTime.Now.ToUniversalTime();
                }
            }
            else
            {
                script.CreationDate     = DateTime.Now.ToUniversalTime();
                script.LastModifiedDate = script.CreationDate;
            }

            script.Save(fileName);
        }
Exemplo n.º 30
0
        public void runAnalyzeJustAutoScripts(ErrorIndexType indexType, int numberOfProducts, int numberOfFiles, int numberOfEvents, int numberOfCabs,
                                              int numberOfAutoUnmanagedAndManagedScripts, int numberOfManualUnmanagedAndManagedScripts,
                                              bool useUnmanagedCabs, int numberOfAutoManagedScripts, int numberOfManualManagedScripts,
                                              int numberOfAutoUnmanagedScripts, int numberOfManualUnmanagedScripts)
        {
            int numberOfEventInfos = 1;

            // Use the dummy winqual.

            StackHashTestData testData = new StackHashTestData();

            testData.DummyWinQualSettings = new StackHashTestDummyWinQualSettings();
            testData.DummyWinQualSettings.UseDummyWinQual                    = true;
            testData.DummyWinQualSettings.ObjectsToCreate                    = new StackHashTestIndexData();
            testData.DummyWinQualSettings.ObjectsToCreate.UseLargeCab        = false;
            testData.DummyWinQualSettings.ObjectsToCreate.NumberOfProducts   = numberOfProducts;
            testData.DummyWinQualSettings.ObjectsToCreate.NumberOfFiles      = numberOfFiles;
            testData.DummyWinQualSettings.ObjectsToCreate.NumberOfEvents     = numberOfEvents;
            testData.DummyWinQualSettings.ObjectsToCreate.NumberOfEventInfos = numberOfEventInfos;
            testData.DummyWinQualSettings.ObjectsToCreate.NumberOfCabs       = numberOfCabs;
            testData.DummyWinQualSettings.ObjectsToCreate.UseUnmanagedCab    = useUnmanagedCabs;

            m_Utils.SetTestData(testData);

            m_Utils.RegisterForNotifications(true, m_Utils.ApplicationGuid);
            m_Utils.CreateNewContext(indexType);

            // Set the username and password to something valid.
            GetStackHashPropertiesResponse settings = m_Utils.GetContextSettings();

            String testPath = "c:\\stackhashunittest\\testindex\\";

            settings.Settings.ContextCollection[0].ErrorIndexSettings.Folder = testPath;
            settings.Settings.ContextCollection[0].ErrorIndexSettings.Name   = "TestIndex";
            settings.Settings.ContextCollection[0].WinQualSettings.UserName  = m_UserName;
            settings.Settings.ContextCollection[0].WinQualSettings.Password  = m_Password;
            m_Utils.SetContextSettings(settings.Settings.ContextCollection[0]);

            // Make sure the index starts off empty.
            m_Utils.DeleteIndex(0);

            m_Utils.ActivateContext(0);

            for (int i = 0; i < numberOfAutoUnmanagedAndManagedScripts; i++)
            {
                StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i, true, StackHashScriptDumpType.UnmanagedAndManaged, true);
                m_Utils.AddDebuggerScript(scriptSettings, false);
            }

            for (int i = 0; i < numberOfManualUnmanagedAndManagedScripts; i++)
            {
                StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 100, true, StackHashScriptDumpType.UnmanagedAndManaged, false);
                m_Utils.AddDebuggerScript(scriptSettings, false);
            }

            for (int i = 0; i < numberOfAutoManagedScripts; i++)
            {
                StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 200, true, StackHashScriptDumpType.ManagedOnly, true);
                m_Utils.AddDebuggerScript(scriptSettings, false);
            }

            for (int i = 0; i < numberOfManualManagedScripts; i++)
            {
                StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 300, true, StackHashScriptDumpType.ManagedOnly, false);
                m_Utils.AddDebuggerScript(scriptSettings, false);
            }

            for (int i = 0; i < numberOfAutoUnmanagedScripts; i++)
            {
                StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 400, true, StackHashScriptDumpType.UnmanagedOnly, true);
                m_Utils.AddDebuggerScript(scriptSettings, false);
            }

            for (int i = 0; i < numberOfManualUnmanagedScripts; i++)
            {
                StackHashScriptSettings scriptSettings = m_Utils.MakeScriptSettings(i + 500, true, StackHashScriptDumpType.UnmanagedOnly, false);
                m_Utils.AddDebuggerScript(scriptSettings, false);
            }

            try
            {
                // Synchronize so we have a copy of just the product list.
                StartSynchronizationResponse resp = m_Utils.StartSynchronization(0, 60000);

                StackHashClientData clientData = m_Utils.LastClientData;

                StackHashWinQualSyncCompleteAdminReport adminReport = m_Utils.WinQualSyncAdminReport as StackHashWinQualSyncCompleteAdminReport;
                Assert.AreNotEqual(null, adminReport);
                Assert.AreEqual(clientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid);
                Assert.AreEqual(clientData.ClientId, adminReport.ClientData.ClientId);
                Assert.AreEqual(clientData.ClientName, adminReport.ClientData.ClientName);
                Assert.AreEqual(clientData.ClientRequestId, adminReport.ClientData.ClientRequestId);
                Assert.AreEqual(0, adminReport.ContextId);
                Assert.AreEqual(null, adminReport.LastException);
                Assert.AreEqual(StackHashAdminOperation.WinQualSyncCompleted, adminReport.Operation);
                Assert.AreEqual(StackHashAsyncOperationResult.Success, adminReport.ResultData);
                Assert.AreEqual(numberOfProducts, adminReport.ErrorIndexStatistics.Products);
                Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Files);
                Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Events);
                Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Cabs);
                Assert.AreEqual(0, adminReport.ErrorIndexStatistics.EventInfos);


                // Enable sync for all the products.
                GetProductsResponse getProducts = m_Utils.GetProducts(0);


                foreach (StackHashProductInfo productInfo in getProducts.Products)
                {
                    Assert.AreEqual(false, productInfo.SynchronizeEnabled);
                    m_Utils.SetProductSynchronizationState(0, productInfo.Product.Id, true);

                    // Make sure there are no files for this product yet.
                    GetFilesResponse getFiles = m_Utils.GetFiles(0, productInfo.Product);

                    Assert.AreEqual(0, getFiles.Files.Count);
                }

                // Start the sync and wait for the sync and analyze to complete.
                resp = m_Utils.StartSynchronization(0, 120000, false, false, null);

                clientData = m_Utils.LastClientData;

                adminReport = m_Utils.WinQualSyncAdminReport as StackHashWinQualSyncCompleteAdminReport;
                Assert.AreNotEqual(null, adminReport);
                Assert.AreEqual(clientData.ApplicationGuid, adminReport.ClientData.ApplicationGuid);
                Assert.AreEqual(clientData.ClientId, adminReport.ClientData.ClientId);
                Assert.AreEqual(clientData.ClientName, adminReport.ClientData.ClientName);
                Assert.AreEqual(clientData.ClientRequestId, adminReport.ClientData.ClientRequestId);
                Assert.AreEqual(0, adminReport.ContextId);
                Assert.AreEqual(null, adminReport.LastException);
                Assert.AreEqual(StackHashAdminOperation.WinQualSyncCompleted, adminReport.Operation);
                Assert.AreEqual(StackHashAsyncOperationResult.Success, adminReport.ResultData);
                Assert.AreEqual(0, adminReport.ErrorIndexStatistics.Products); // Should have already added the product.
                Assert.AreEqual(numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Files);
                Assert.AreEqual(numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Events);
                Assert.AreEqual(numberOfCabs * numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.Cabs);
                Assert.AreEqual(numberOfEventInfos * numberOfEvents * numberOfFiles * numberOfProducts, adminReport.ErrorIndexStatistics.EventInfos);

                // Make sure the task is no longer running.
                GetStackHashServiceStatusResponse statusResp = m_Utils.GetServiceStatus();

                Assert.AreEqual(false, m_Utils.IsTaskRunning(statusResp.Status.ContextStatusCollection[0].TaskStatusCollection, StackHashTaskType.WinQualSynchronizeTask));
                Assert.AreEqual(false, m_Utils.IsTaskRunning(statusResp.Status.ContextStatusCollection[0].TaskStatusCollection, StackHashTaskType.AnalyzeTask));


                // Check that the scripts have been run ok. Both auto scripts should be run.
                StackHashProductInfoCollection products = m_Utils.GetProducts(0).Products;
                foreach (StackHashProductInfo product in products)
                {
                    StackHashFileCollection files = m_Utils.GetFiles(0, product.Product).Files;

                    foreach (StackHashFile file in files)
                    {
                        StackHashEventCollection events = m_Utils.GetEvents(0, product.Product, file).Events;

                        foreach (StackHashEvent currentEvent in events)
                        {
                            StackHashEventPackage eventPackage = m_Utils.GetEventPackage(0, product.Product, file, currentEvent).EventPackage;

                            foreach (StackHashCabPackage cab in eventPackage.Cabs)
                            {
                                StackHashScriptResultFiles scriptResults = m_Utils.GetDebugResultFiles(0, product.Product, file, currentEvent, cab.Cab).ResultFiles;

                                int numberOfAutoScripts = 2;
                                int expectedResults     = numberOfAutoScripts + numberOfAutoUnmanagedAndManagedScripts;

                                if (!useUnmanagedCabs)
                                {
                                    expectedResults += numberOfAutoManagedScripts;
                                }
                                else
                                {
                                    expectedResults += numberOfAutoUnmanagedScripts;
                                }

                                Assert.AreEqual(expectedResults, scriptResults.Count);
                            }
                        }
                    }
                }
            }
            finally
            {
                m_Utils.DeactivateContext(0);
                m_Utils.DeleteIndex(0);
            }
        }