Example #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);
        }
Example #2
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);
        }
Example #3
0
        public void StartProcessDumpWillStartProcDumpExeWithCorrectParamsForFullDump()
        {
            var guid                 = "guid";
            var process              = "process";
            var processId            = 12345;
            var filename             = $"{process}_{processId}_{guid}.dmp";
            var args                 = $"-accepteula -e 1 -g -t -ma -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, 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.StartTriggerBasedProcessDump(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());
        }
Example #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);
        }
Example #5
0
        public void StartProcessDumpWillThrowErrorIfProcdumpEnvVarNotSet()
        {
            Environment.SetEnvironmentVariable("PROCDUMP_PATH", null);

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

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

            Assert.AreEqual(ex.Message, Resources.Resources.ProcDumpEnvVarEmpty);
        }
Example #6
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());
        }
Example #7
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> >()));
        }
Example #8
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> >()));
        }