示例#1
0
        public void Process_should_not_terminate_other_process()
        {
            // Arrange
            var compiler = new CSharpCodeProvider();
            var options  = new CompilerParameters
            {
                GenerateExecutable = true
            };

            options.ReferencedAssemblies.Add("System.dll");
            var asm = compiler.CompileAssemblyFromSource(options, TerminateProcessByIdSource);

            asm.Errors.HasErrors.Should().BeFalse();

            var ps   = Process.Start("calc");
            var info = new JudgeInfo
            {
                Input         = ps.Id.ToString(CultureInfo.InvariantCulture),
                MemoryLimitMb = 10.0f,
                Path          = asm.PathToAssembly,
                TimeLimitMs   = 100
            };

            // Act
            var result = NativeDll.Judge(info);
            var that   = Process.GetProcessById(ps.Id);

            // Assert
            result.ExitCode.Should().NotBe(0);
            that.Should().NotBeNull();

            // Clean up
            ps.Kill();
        }
示例#2
0
        public void Judge_run_InfinateLoop_should_exit()
        {
            // Arrange
            var compiler = new CSharpCodeProvider();
            var options  = new CompilerParameters
            {
                GenerateExecutable = true
            };
            var asm = compiler.CompileAssemblyFromSource(options, InfinateLoopSource);
            var ji  = new JudgeInfo
            {
                Input         = null,
                MemoryLimitMb = 10.0f,
                Path          = asm.PathToAssembly,
                TimeLimitMs   = 100
            };

            // Act
            var result = NativeDll.Judge(ji);

            // Assert
            result.Succeed.Should().BeTrue();
            result.ExitCode.Should().NotBe(0);
            result.TimeMs.Should().BeGreaterOrEqualTo(100);
        }
示例#3
0
        public void Judge_run_MemoryLimitTest_should_be_limited()
        {
            // Arrange
            var compiler = new CSharpCodeProvider();
            var options  = new CompilerParameters
            {
                GenerateExecutable = true
            };
            var asm  = compiler.CompileAssemblyFromSource(options, MemoryLimitTestSource);
            var info = new JudgeInfo
            {
                Input         = null,
                MemoryLimitMb = 10.0f,
                Path          = asm.PathToAssembly,
                TimeLimitMs   = 200
            };

            // Act
            var result = NativeDll.Judge(info);

            // Assert
            result.Succeed.Should().BeTrue();
            result.ExitCode.Should().NotBe(0);
            result.MemoryMb.Should().BeGreaterOrEqualTo(20.0f);
        }
示例#4
0
        public void Judge_run_many_times_should_not_leak_memory(int times)
        {
            // Arrange
            var compiler = new CSharpCodeProvider();
            var options  = new CompilerParameters
            {
                GenerateExecutable = true
            };
            var asm = compiler.CompileAssemblyFromSource(options, Code);

            asm.Errors.HasErrors.Should().BeFalse();
            var info = new JudgeInfo
            {
                Input         = "Flash",
                MemoryLimitMb = 10.0f,
                Path          = asm.PathToAssembly,
                TimeLimitMs   = 150
            };
            var parallelOption = new ParallelOptions {
                MaxDegreeOfParallelism = 4
            };

            // Act & Assert
            Console.WriteLine(GC.GetTotalMemory(true));
            //for (int i = 0; i < times; ++i) NativeDll.Judge(info);
            Parallel.For(0, times, parallelOption, (i) => NativeDll.Judge(info));

            Console.WriteLine(GC.GetTotalMemory(true));
            Parallel.For(0, times, parallelOption, (i) => NativeDll.Judge(info));

            Console.WriteLine(GC.GetTotalMemory(true));
            Parallel.For(0, times, parallelOption, (i) => NativeDll.Judge(info));

            Console.WriteLine(GC.GetTotalMemory(true));
        }
示例#5
0
文件: ProcessRun.cs 项目: sdcb/sdoj
        public void Create_calc_should_return_success()
        {
            // arrange
            var calc = new JudgeInfo
            {
                Path          = "calc.exe",
                MemoryLimitMb = 10.0f,
                TimeLimitMs   = 100,
                Input         = null
            };

            // act
            var result = NativeDll.Judge(calc);

            // assert
            result.Succeed.Should().BeTrue();
            result.ErrorCode.Should().Be(0);
            result.MemoryMb.Should().BeGreaterThan(0);
        }
示例#6
0
        public void Process_should_return_expected_output()
        {
            // Arrange
            var compiler = new CSharpCodeProvider();
            var options  = new CompilerParameters {
                GenerateExecutable = true
            };
            var res  = compiler.CompileAssemblyFromSource(options, Code);
            var info = new JudgeInfo
            {
                Input         = "Flash",
                MemoryLimitMb = 10,
                Path          = res.PathToAssembly,
                TimeLimitMs   = 1000
            };

            // Act
            var result = NativeDll.Judge(info);

            // Assert
            result.Succeed.Should().BeTrue();
            result.Output.Should().Be("Hey Flash!");
        }
示例#7
0
        public void Ten_kb_input_should_work_well()
        {
            // Arrange
            var compiler = new CSharpCodeProvider();
            var options  = new CompilerParameters {
                GenerateExecutable = true
            };
            var res  = compiler.CompileAssemblyFromSource(options, Code);
            var info = new JudgeInfo
            {
                Input         = new string('F', 10 * 1024),
                MemoryLimitMb = 10,
                Path          = res.PathToAssembly,
                TimeLimitMs   = 1000
            };
            var expectedOutput = string.Format("Hey {0}!", info.Input);

            // Act
            var result = NativeDll.Judge(info);

            // Assert
            result.Succeed.Should().BeTrue();
            result.Output.Should().Be(expectedOutput);
        }