Пример #1
0
        public void GetDumpFileWillThrowExceptionIfNoDumpfile()
        {
            var process              = "process";
            var processId            = 12345;
            var testResultsDirectory = "D:\\TestResults";

            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { });
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);

            this.mockHangDumperFactory.Setup(x => x.Create(It.IsAny <string>()))
            .Returns(new Mock <IHangDumper>().Object);

            this.mockCrashDumperFactory.Setup(x => x.Create(It.IsAny <string>()))
            .Returns(new Mock <ICrashDumper>().Object);

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockHangDumperFactory.Object,
                this.mockCrashDumperFactory.Object);

            processDumpUtility.StartTriggerBasedProcessDump(processId, testResultsDirectory, false, ".NETCoreApp,Version=v5.0");

            var ex = Assert.ThrowsException <FileNotFoundException>(() => processDumpUtility.GetDumpFiles());

            Assert.AreEqual(ex.Message, Resources.Resources.DumpFileNotGeneratedErrorMessage);
        }
Пример #2
0
        public void StartProcessDumpForHangWillStartProcDumpExeWithCorrectParams()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var filename             = $"{process}_{processId}_{guid}_hangdump.dmp";
            var args                 = $"-accepteula -n 1 -ma {processId} {filename}";
            var testResultsDirectory = "D:\\TestResults";

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()))
            .Returns(this.mockProcDumpProcess.Object);
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);
            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { Path.Combine(testResultsDirectory, filename) });

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartHangBasedProcessDump(processId, guid, testResultsDirectory, isFullDump: true);

            this.mockProcessHelper.Verify(x => x.LaunchProcess(It.IsAny <string>(), args, It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()), Times.Once);
            Assert.AreEqual(Path.Combine(testResultsDirectory, filename), processDumpUtility.GetDumpFile());
        }
Пример #3
0
        public void GetDumpFileWillThrowExceptionIfNoDumpfile()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var testResultsDirectory = "D:\\TestResults";

            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { });
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);
            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()))
            .Returns(this.mockProcDumpProcess.Object);

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartTriggerBasedProcessDump(processId, guid, testResultsDirectory);

            var ex = Assert.ThrowsException <FileNotFoundException>(() => processDumpUtility.GetDumpFile());

            Assert.AreEqual(ex.Message, Resources.Resources.DumpFileNotGeneratedErrorMessage);
        }
Пример #4
0
        public void GetDumpFileWillWaitForProcessToExitAndGetDumpFile()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var testResultsDirectory = "D:\\TestResults";

            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { "dump.dmp" });
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);
            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()))
            .Returns(this.mockProcDumpProcess.Object);

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartTriggerBasedProcessDump(processId, guid, testResultsDirectory);
            processDumpUtility.GetDumpFile();

            this.mockProcessHelper.Verify(x => x.WaitForProcessExit(It.IsAny <Process>()), Times.Once);
        }
Пример #5
0
        public void StartProcessDumpWillStartProcDumpExeWithCorrectParamsAndGetDumpFileReturnsFullPath()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var filename             = $"{process}_{processId}_{guid}.dmp";
            var args                 = $"-accepteula -e 1 -g -t -f STACK_OVERFLOW -f ACCESS_VIOLATION {processId} {filename}";
            var testResultsDirectory = "D:\\TestResults";

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null))
            .Returns(this.mockProcDumpProcess.Object);
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);

            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { Path.Combine(testResultsDirectory, filename) });

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartProcessDump(processId, guid, testResultsDirectory);

            this.mockProcessHelper.Verify(x => x.LaunchProcess(It.IsAny <string>(), args, It.IsAny <string>(), null, null, null), Times.Once);
            Assert.AreEqual(Path.Combine(testResultsDirectory, filename), processDumpUtility.GetDumpFile());
        }
Пример #6
0
        public void GetDumpFileWillReturnEmptyIfProcDumpDidntStart()
        {
            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null))
            .Throws(new Exception());

            var processDumpUtility = new ProcessDumpUtility(this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockPlatformEnvironment.Object);

            Assert.ThrowsException <Exception>(() => processDumpUtility.StartProcessDump(12345, "guid", "D:\\TestResults"));
            Assert.AreEqual(string.Empty, processDumpUtility.GetDumpFile());
        }
Пример #7
0
        public void StartProcessDumpWillThrowErrorIfProcdumpEnvVarNotSet()
        {
            Environment.SetEnvironmentVariable("PROCDUMP_PATH", null);

            var processDumpUtility = new ProcessDumpUtility(this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockPlatformEnvironment.Object);

            var ex = Assert.ThrowsException <TestPlatformException>(() => processDumpUtility.StartProcessDump(1234, "guid", "D:\\"));

            Assert.AreEqual(ex.Message, Resources.Resources.ProcDumpEnvVarEmpty);
        }
Пример #8
0
        public void GetDumpFileWillWaitForProcessToExitAndGetDumpFile()
        {
            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { "dump.dmp" });

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null))
            .Returns(this.mockProcDumpProcess.Object);

            var processDumpUtility = new ProcessDumpUtility(this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockPlatformEnvironment.Object);

            processDumpUtility.StartProcessDump(12345, "guid", "D:\\TestResults");
            processDumpUtility.GetDumpFile();

            this.mockProcessHelper.Verify(x => x.WaitForProcessExit(It.IsAny <Process>()), Times.Once);
        }
Пример #9
0
        public void GetDumpFileWillThrowExceptionIfNoDumpfile()
        {
            this.mockFileHelper.Setup(x => x.GetFiles(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <SearchOption>()))
            .Returns(new string[] { });

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null))
            .Returns(this.mockProcDumpProcess.Object);

            var processDumpUtility = new ProcessDumpUtility(this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockPlatformEnvironment.Object);

            processDumpUtility.StartProcessDump(12345, "guid", "D:\\TestResults");

            var ex = Assert.ThrowsException <FileNotFoundException>(() => processDumpUtility.GetDumpFile());

            Assert.AreEqual(ex.Message, Resources.Resources.DumpFileNotGeneratedErrorMessage);
        }
Пример #10
0
        public void TerminateProcessDumpShouldCallTerminateOnProcDumpProcess()
        {
            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            // Mock process helper
            this.mockProcessHelper.Setup(x => x.TerminateProcess(It.IsAny <object>()));

            // Raise
            processDumpUtility.TerminateProcess();

            // Verify
            this.mockProcessHelper.Verify(x => x.TerminateProcess(It.IsAny <object>()), Times.Once);
        }
Пример #11
0
        public void StartProcessDumpWillStartExeCorrespondingToPlatformArchitecture()
        {
            PlatformArchitecture[] platformArchitecture = { PlatformArchitecture.X64, PlatformArchitecture.X86 };

            Dictionary <PlatformArchitecture, string> architectureExeMap = new Dictionary <PlatformArchitecture, string>()
            {
                { PlatformArchitecture.X86, "procdump.exe" },
                { PlatformArchitecture.X64, "procdump64.exe" }
            };

            foreach (var architecture in architectureExeMap)
            {
                this.mockPlatformEnvironment.Setup(x => x.Architecture).Returns(architecture.Key);

                var processDumpUtility = new ProcessDumpUtility(this.mockProcessHelper.Object, this.mockFileHelper.Object, this.mockPlatformEnvironment.Object);
                processDumpUtility.StartProcessDump(1234, "guid", "D:\\");

                this.mockProcessHelper.Verify(x => x.LaunchProcess(Path.Combine("D:\\procdump", architecture.Value), It.IsAny <string>(), It.IsAny <string>(), null, null, null));
            }
        }
Пример #12
0
        public void GetDumpFileWillReturnEmptyIfProcDumpDidntStart()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var testResultsDirectory = "D:\\TestResults";

            this.mockProcessHelper.Setup(x => x.LaunchProcess(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()))
            .Throws(new Exception());
            this.mockProcessHelper.Setup(x => x.GetProcessName(processId))
            .Returns(process);

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            Assert.ThrowsException <Exception>(() => processDumpUtility.StartTriggerBasedProcessDump(processId, guid, testResultsDirectory));
            Assert.AreEqual(string.Empty, processDumpUtility.GetDumpFile());
        }
Пример #13
0
        public void StartProcessDumpWillStartExeCorrespondingTo32BitTestHostProcessIn64BitOS()
        {
            IntPtr x86ProcessHandle = new IntPtr(0);
            int    processId        = 12345;

            this.mockPlatformEnvironment.Setup(x => x.Architecture).Returns(PlatformArchitecture.X64);

            this.mockProcessHelper.Setup(x => x.GetProcessHandle(processId))
            .Returns(x86ProcessHandle);
            this.mockNativeMethodsHelper.Setup(x => x.Is64Bit(x86ProcessHandle))
            .Returns(false);

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartTriggerBasedProcessDump(processId, "guid", "D:\\");

            this.mockProcessHelper.Verify(x => x.LaunchProcess(Path.Combine("D:\\procdump", "procdump.exe"), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()));
        }
Пример #14
0
        public void StartProcessDumpWillStartExeCorrespondingToTestHostProcessIn32BitOS()
        {
            var guid = "guid";

            // var process = "process";
            var processId            = 12345;
            var testResultsDirectory = "D:\\TestResults";

            this.mockPlatformEnvironment.Setup(x => x.Architecture).Returns(PlatformArchitecture.X86);
            this.mockProcessHelper.Setup(x => x.GetProcessHandle(processId))
            .Returns(new IntPtr(0));

            var processDumpUtility = new ProcessDumpUtility(
                this.mockProcessHelper.Object,
                this.mockFileHelper.Object,
                this.mockPlatformEnvironment.Object,
                this.mockNativeMethodsHelper.Object);

            processDumpUtility.StartTriggerBasedProcessDump(processId, guid, testResultsDirectory);

            this.mockProcessHelper.Verify(x => x.LaunchProcess(Path.Combine("D:\\procdump", "procdump.exe"), It.IsAny <string>(), It.IsAny <string>(), null, null, null, It.IsAny <Action <object, string> >()));
        }