Esempio n. 1
0
        public bool Compile()
        {
            string reportFile = Path.Combine(workDir, NeTesterConfiguration.REPORT_FILE);
            string script     = Path.Combine(workDir, NeTesterConfiguration.COMPILE_SCRIPT);

            using (StreamWriter sw = new StreamWriter(script))
                sw.Write(lang.CompileScript);

            DfyzProc prc = new DfyzProc(NeTesterConfiguration.SHELL_COMMAND,
                                        workDir, null);

            prc.AddArgument(NeTesterConfiguration.SHELL_SCRIPT_PARAM);
            prc.AddArgument(script + " " + source + " " + exe);

            prc.SetCommonParams();

            prc.StdinRedirection        = DfyzProc.NULL_DEVICE;
            prc.StdoutRedirection       = reportFile;
            prc.DuplicateStdoutToStderr = true;

            RunResult rr = prc.Run();

            if (rr.Status != RunStatus.Ok)
            {
                throw new NeTesterException("Compilation failed");
            }

            using (StreamReader sr = new StreamReader(reportFile))
                compReport = sr.ReadToEnd();

            return(rr.ExitCode == 0);
        }
Esempio n. 2
0
        public void TestExitCode()
        {
            DfyzProc  dp = new DfyzProc(Path.Combine(TESTS_DIR, "ExitCode.exe"), TESTS_DIR, null);
            RunResult rr = dp.Run();

            Assert.AreEqual(RunStatus.Ok, rr.Status);
            Assert.AreEqual(31337, rr.ExitCode);
        }
Esempio n. 3
0
        public void TestOk()
        {
            DfyzProc  dp  = new DfyzProc(Path.Combine(TESTS_DIR, "Ok.exe"), TESTS_DIR, null);
            RunResult res = dp.Run();

            Assert.AreEqual(RunStatus.Ok, res.Status);
            Assert.AreEqual(0, res.ExitCode);
        }
Esempio n. 4
0
        public void TestMemoryLimit()
        {
            DfyzProc dp = new DfyzProc(Path.Combine(TESTS_DIR, "MemoryLimit"), TESTS_DIR, null);

            dp.MemoryLimit = 6 * 1048576;
            RunResult rr = dp.Run();

            Assert.AreEqual(RunStatus.MemoryLimit, rr.Status);
        }
Esempio n. 5
0
        public void TestTimeLimit()
        {
            DfyzProc dp = new DfyzProc(Path.Combine(TESTS_DIR, "TimeLimit.exe"), TESTS_DIR, null);

            dp.TimeLimit = 1000;
            RunResult rr = dp.Run();

            Assert.AreEqual(RunStatus.TimeLimit, rr.Status);
        }
Esempio n. 6
0
        public void TestSecurityViolation()
        {
            DfyzProc dp = new DfyzProc(Path.Combine(TESTS_DIR, "Spawn.exe"), TESTS_DIR, null);

            dp.AllowProcessCreation = false;
            RunResult rr = dp.Run();

            Assert.AreEqual(RunStatus.SecurityViolation, rr.Status);
        }
Esempio n. 7
0
        public void TestIdlenessLimit()
        {
            DfyzProc dp = new DfyzProc(Path.Combine(TESTS_DIR, "IdlenessLimit.exe"), TESTS_DIR, null);

            dp.IdlenessLimit = 2500;
            RunResult rr = dp.Run();

            Assert.AreEqual(RunStatus.SecurityViolation, rr.Status);
        }
Esempio n. 8
0
        public void TestCrashes()
        {
            DfyzProc  avDp = new DfyzProc(Path.Combine(TESTS_DIR, "AV.exe"), TESTS_DIR, null);
            DfyzProc  zdDp = new DfyzProc(Path.Combine(TESTS_DIR, "Zerodiv.exe"), TESTS_DIR, null);
            RunResult rr   = avDp.Run();

            Assert.AreEqual(RunStatus.RuntimeError, rr.Status);
            rr = zdDp.Run();
            Assert.AreEqual(RunStatus.RuntimeError, rr.Status);
        }
Esempio n. 9
0
        public void TestArguments()
        {
            string argsFile = Path.Combine(TESTS_DIR, "args.txt");

            if (File.Exists(argsFile))
            {
                File.Delete(argsFile);
            }
            string[] trickyArgs = new string[] { "\"\"\"\"\"", "\\\"\"\\", "\\\\" };

            List <string> argList = new List <string>();

            for (int i = 1; i <= 1000; i++)
            {
                argList.Add(i.ToString());
            }
            foreach (string s in trickyArgs)
            {
                argList.Add(s);
            }

            DfyzProc  dp  = new DfyzProc(Path.Combine(TESTS_DIR, "Args.exe"), TESTS_DIR, argList);
            RunResult res = dp.Run();

            Assert.AreEqual(RunStatus.Ok, res.Status);
            Assert.AreEqual(0, res.ExitCode);

            StreamReader sr = new StreamReader(argsFile);
            string       nLine;

            for (int i = 1; i <= 1000; i++)
            {
                nLine = sr.ReadLine();
                Assert.AreNotEqual(null, nLine);
                Assert.AreEqual(i, int.Parse(nLine, NumberStyles.Integer));
            }

            for (int i = 0; i < trickyArgs.Length; i++)
            {
                nLine = sr.ReadLine();
                Assert.AreNotEqual(null, nLine);
                Assert.AreEqual(trickyArgs[i], nLine);
            }

            sr.Close();

            if (File.Exists(argsFile))
            {
                File.Delete(argsFile);
            }
        }
Esempio n. 10
0
        public void TestOutputLimit()
        {
            string outputFile = Path.Combine(TESTS_DIR, "big-file.txt");

            if (File.Exists(outputFile))
            {
                File.Delete(outputFile);
            }
            DfyzProc dp = new DfyzProc(Path.Combine(TESTS_DIR, "OutputLimit.exe"), TESTS_DIR, null);

            dp.OutputLimit = 10000;
            RunResult rr = dp.Run();

            Assert.AreEqual(RunStatus.OutputLimit, rr.Status);
            if (File.Exists(outputFile))
            {
                File.Delete(outputFile);
            }
        }
Esempio n. 11
0
        public bool Compile()
        {
            string reportFile = Path.Combine(workDir, NeTesterConfiguration.ReportFile);
            string script     = Path.Combine(workDir, NeTesterConfiguration.CompileScript);


            using (StreamWriter sw = new StreamWriter(script))
            {
                throw new NotImplementedException();
                //sw.Write(lang.CompileScript);
            }

            RunResult rr = new RunResult();

            using (DfyzProc prc = new DfyzProc(NeTesterConfiguration.ShellCommand, workDir, null))
            {
                prc.AddArgument(NeTesterConfiguration.ShellScriptParam);
                prc.AddArgument(script + " " + source + " " + exe);

                prc.SetCommonParams();

                prc.StdinRedirection        = DfyzProc.NULL_DEVICE;
                prc.StdoutRedirection       = reportFile;
                prc.DuplicateStdoutToStderr = true;

                rr = prc.Run();
            }
            if (rr.Status != RunStatus.Ok)
            {
                throw new NeTesterException("Compilation failed");
            }

            using (StreamReader sr = new StreamReader(reportFile))
                compReport = sr.ReadToEnd();

            return(rr.ExitCode == 0);
        }
Esempio n. 12
0
        public void TestRedirections()
        {
            string inputFile  = Path.Combine(TESTS_DIR, "input.txt");
            string outputFile = Path.Combine(TESTS_DIR, "output.txt");
            string errorFile  = Path.Combine(TESTS_DIR, "error.txt");

            if (File.Exists(inputFile))
            {
                File.Delete(inputFile);
            }
            if (File.Exists(errorFile))
            {
                File.Delete(errorFile);
            }
            if (File.Exists(outputFile))
            {
                File.Delete(outputFile);
            }

            List <int>   randoms = new List <int>();
            StreamWriter sw      = new StreamWriter(inputFile);
            Random       r       = new Random(Environment.TickCount);

            for (int i = 0; i < 1000; i++)
            {
                int nextR = r.Next();
                randoms.Add(nextR);
                sw.WriteLine(nextR.ToString());
            }

            sw.Close();

            DfyzProc dp = new DfyzProc(Path.Combine(TESTS_DIR, "StdStreams.exe"), TESTS_DIR, null);

            dp.StdinRedirection  = inputFile;
            dp.StdoutRedirection = outputFile;
            dp.StderrRedirection = errorFile;

            RunResult rr = dp.Run();

            if (rr.Status == RunStatus.Failure)
            {
                Console.Error.WriteLine(dp.Comment);
            }
            Assert.AreEqual(RunStatus.Ok, rr.Status);

            StreamReader rOut = new StreamReader(outputFile);
            StreamReader rErr = new StreamReader(errorFile);

            for (int i = 0; i < randoms.Count; i++)
            {
                Assert.AreEqual(randoms[i] + 1, int.Parse(rOut.ReadLine(), NumberStyles.Integer));
                Assert.AreEqual(randoms[i] + 2, int.Parse(rErr.ReadLine(), NumberStyles.Integer));
            }

            rOut.Close();
            rErr.Close();

            if (File.Exists(inputFile))
            {
                File.Delete(inputFile);
            }
            if (File.Exists(errorFile))
            {
                File.Delete(errorFile);
            }
            if (File.Exists(outputFile))
            {
                File.Delete(outputFile);
            }
        }
Esempio n. 13
0
        public CheckStatus Check(string[] files)
        {
            bool okParams = true;

            foreach (string s in files)
            {
                if (string.IsNullOrEmpty(s))
                {
                    okParams = false;
                }
            }

            if (files.Length != 3 || !okParams)
            {
                throw new NeTesterException("Invalid checker parameters");
            }

            string resultXml = Path.Combine(wDir, "result.xml");

            if (!File.Exists(exe))
            {
                throw new NeTesterException("Checker file doesn't exist");
            }

            RunResult rr;

            using (DfyzProc prc = new DfyzProc(exe, wDir, null))
            {
                foreach (string s in files)
                {
                    prc.AddArgument(s);
                }

                prc.AddArgument(resultXml);
                prc.AddArgument("-appes");

                prc.SetCommonParams();
                prc.StdinRedirection = prc.StdoutRedirection = prc.StderrRedirection = DfyzProc.NULL_DEVICE;

                rr = prc.Run();
                if (rr.Status != RunStatus.Ok)
                {
                    string message = "Running checker failed";
                    if (rr.Status == RunStatus.Failure)
                    {
                        message += String.Format(": {0}", prc.Comment);
                    }
                    throw new NeTesterException(message);
                }
            }

            XmlDocument doc = new XmlDocument();

            try
            {
                doc.Load(resultXml);
            }
            catch (XmlException ex)
            {
                throw new NeTesterException(String.Format("Cannot load checker's result file: {0}", ex.Message));
            }
            if (doc.DocumentElement.Name != "result" || !doc.DocumentElement.HasAttribute("outcome"))
            {
                throw new NeTesterException("Checker's result file has invalid format");
            }
            comment = doc.DocumentElement.InnerText;
            return(MapOutcomeToCheckStatus(doc.DocumentElement.Attributes["outcome"].Value));
        }