Ejemplo n.º 1
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))
            .Returns(this.mockProcDumpProcess.Object);

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

            processDumpUtility.StartProcessDump(processId, guid, testResultsDirectory);

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

            Assert.AreEqual(ex.Message, Resources.Resources.DumpFileNotGeneratedErrorMessage);
        }
Ejemplo n.º 2
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))
            .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, isFullDump: true);

            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());
        }
Ejemplo n.º 3
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))
            .Returns(this.mockProcDumpProcess.Object);

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

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

            this.mockProcessHelper.Verify(x => x.WaitForProcessExit(It.IsAny <Process>()), Times.Once);
        }
Ejemplo n.º 4
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());
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
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));
            }
        }
Ejemplo n.º 8
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))
            .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.StartProcessDump(processId, guid, testResultsDirectory));
            Assert.AreEqual(string.Empty, processDumpUtility.GetDumpFile());
        }
Ejemplo n.º 9
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.StartProcessDump(processId, "guid", "D:\\");

            this.mockProcessHelper.Verify(x => x.LaunchProcess(Path.Combine("D:\\procdump", "procdump.exe"), It.IsAny <string>(), It.IsAny <string>(), null, null, null));
        }
Ejemplo n.º 10
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.StartProcessDump(processId, guid, testResultsDirectory);

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