Ejemplo n.º 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();
        }
Ejemplo n.º 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);
        }
Ejemplo n.º 3
0
        public DolphiimoteDll(string path)
        {
            nativeDll = new NativeDll(path);

            if (Marshal.SizeOf(typeof(DolphiimoteCallbacks)) != 24)
            {
                throw new InvalidOperationException("DolphiimoteCallbacks wrong size. Expected: 24, got:" + Marshal.SizeOf(typeof(DolphiimoteCallbacks)));
            }

            if (Marshal.SizeOf(typeof(DolphiimoteData)) != 128)
            {
                throw new InvalidOperationException("DolphiimoteData wrong size. Expected: 128, got:" + Marshal.SizeOf(typeof(DolphiimoteData)));
            }

            if (Marshal.SizeOf(typeof(DolphiimoteCapabilities)) != 16)
            {
                throw new InvalidOperationException("DolphiimoteCapabilities wrong size.");
            }

            dolphiimoteInit               = nativeDll.GetDelegateFromFunction <DolphiimoteInit>("dolphiimote_init");
            dolphiimoteUpdate             = nativeDll.GetDelegateFromFunction <DolphiimoteUpdate>("dolphiimote_update");
            dolphiimoteSetReportingMode   = nativeDll.GetDelegateFromFunction <DolphiimoteSetReportingMode>("dolphiimote_set_reporting_mode");
            dolphiimoteShutdown           = nativeDll.GetDelegateFromFunction <DolphiimoteShutdown>("dolphiimote_shutdown");
            dolphiimoteEnableCapabilities = nativeDll.GetDelegateFromFunction <DolphiimoteEnableCapabilities>("dolphiimote_enable_capabilities");
            dolphiimoteSetRumble          = nativeDll.GetDelegateFromFunction <DolphiimoteSetRumble>("dolphiimote_set_rumble");
            dolphiimoteRequestStatus      = nativeDll.GetDelegateFromFunction <DolphiimoteRequestStatus>("dolphiimote_request_status");
            dolphiimoteSetLedState        = nativeDll.GetDelegateFromFunction <DolphiimoteSetLedState>("dolphiimote_set_leds");
        }
Ejemplo n.º 4
0
        public DolphiimoteDll(string path)
        {
            nativeDll = new NativeDll(path);

            if (Marshal.SizeOf(typeof(DolphiimoteCallbacks)) != 20)
            {
                throw new InvalidOperationException("DolphiimoteCallbacks wrong size.");
            }

            if (Marshal.SizeOf(typeof(DolphiimoteData)) != 32)
            {
                throw new InvalidOperationException("DolphiimoteData wrong size.");
            }

            if (Marshal.SizeOf(typeof(DolphiimoteCapabilities)) != 16)
            {
                throw new InvalidOperationException("DolphiimoteCapabilities wrong size.");
            }

            dolphiimoteInit = nativeDll.GetDelegateFromFunction <DolphiimoteInit>("dolphiimote_init");
            dolphiimoteDetermineCapabilities = nativeDll.GetDelegateFromFunction <DolphiimoteDetermineCapabilities>("dolphiimote_determine_capabilities");
            dolphiimoteUpdate             = nativeDll.GetDelegateFromFunction <DolphiimoteUpdate>("dolphiimote_update");
            dolphiimoteSetReportingMode   = nativeDll.GetDelegateFromFunction <DolphiimoteSetReportingMode>("dolphiimote_set_reporting_mode");
            dolphiimoteShutdown           = nativeDll.GetDelegateFromFunction <DolphiimoteShutdown>("dolphiimote_shutdown");
            dolphiimoteEnableCapabilities = nativeDll.GetDelegateFromFunction <DolphiimoteEnableCapabilities>("dolphiimote_enable_capabilities");
        }
Ejemplo n.º 5
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);
        }
        public void AllocManyType()
        {
            var ptr = NativeDll.AllocateArrayOfInt(200);

            ptr = NativeDll.AllocateArrayOfInt(150);
            ptr = NativeDll.AllocateArrayOfPoint(200);
        }
Ejemplo n.º 7
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));
        }
Ejemplo n.º 8
0
        public TrackIRDll(string path, Action<string> logger = null)
        {
            this.logger = logger ?? (str => {});

            dll = new NativeDll(path);
            getSignature = dll.GetDelegateFromFunction<NpGetSignature>(GetSignatureName);
            getPosition = dll.GetDelegateFromFunction<GetHeadposePosition>(GetDataName);
            queryVersion = dll.GetDelegateFromFunction<NpQueryVersion>(QueryVersionName);
            registerWindowHandle = dll.GetDelegateFromFunction<NpRegisterWindowHandle>(RegisterWindowHandleName);
            unregisterWindowHandle = dll.GetDelegateFromFunction<NpUnregisterWindowHandle>(UnregisterWindowHandleName);
            registerProgramProfileId = dll.GetDelegateFromFunction<NpRegisterProgramProfileId>(RegisterProgramProfileIdName);
            requestData = dll.GetDelegateFromFunction<NpRequestData>(RequestDataName);
            startDataTransmission = dll.GetDelegateFromFunction<NpStartDataTransmission>(StartDataTransmissionName);
            stopDataTransmission = dll.GetDelegateFromFunction<NpStopDataTransmission>(StopDataTransmissionName);
            startCursor = dll.GetDelegateFromFunction<NpStartCursor>(StartCursorName);
            stopCursor = dll.GetDelegateFromFunction<NpStopCursor>(StopCursorName);
            reCenter = dll.GetDelegateFromFunction<NpReCenter>(ReCenterName);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
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!");
        }
Ejemplo n.º 11
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);
        }
 public void AllocNativeStruct()
 {
     var ptr = NativeDll.AllocateArrayOfPoint(200);
 }
        public void AllocAndFreeNativeStruct()
        {
            var ptr = NativeDll.AllocateArrayOfPoint(200);

            NativeDll.DeallocateArrayOfPoint(ptr);
        }
 public void AllocNativeInt()
 {
     var ptr = NativeDll.AllocateArrayOfInt(200);
 }
 public void AllocReallocAndFreeUsingVector()
 {
     // This example uses std::vector<int>.
     NativeDll.AllocReallocAndFreeUsingVector();
 }
 public void AllocReallocAndFree()
 {
     // This example uses standard malloc, realloc and free.
     NativeDll.AllocReallocAndFree();
 }