Ejemplo n.º 1
0
        public static List <Process> Test(string path, string name)
        {
            var processes = new List <Process>();
            var outdir    = Path.Combine(OutputDir, name);

            if (Directory.Exists(outdir))
            {
                //Directory.Delete(outdir, true);
                foreach (var file in new DirectoryInfo(outdir).EnumerateFiles("*.out"))
                {
                    try
                    {
                        file.Delete();
                    }
                    catch
                    {
                        Console.WriteLine("FUU");
                    }
                }
            }
            else
            {
                Directory.CreateDirectory(outdir);
            }
            for (var i = 0; i < Executables.Count; i++)
            {
                var _in  = new Win32.FILE(path);
                var _out = new Win32.FILE(Path.Combine(outdir, $"{name}_{Executables[i].Name}.out"));
                var io   = new ProcessIO(_in, _out);
                var psi  = new ProcessStartInfo
                {
                    StartSuspended = false,
                    StdIO          = io,
                    Executable     = Executables[i].FullName
                }; // TotalTimeLimit = MaxTime
                var p = new Process(psi);
                processes.Add(p);
                p.Start();
            }

            return(processes);
        }
Ejemplo n.º 2
0
        public static bool SingleTest(TestInfo test)
        {
            var anything        = false;
            var ok              = true;
            var currentTestName = $"{JobName}{test.ID}";
            var testPath        = test.File;
            var input           = new Win32.FILE(testPath);
            var processes       = Test(testPath, currentTestName);
            var testOutputDir   = Path.Combine(OutputDir, currentTestName);
            var MasterMD5       = "";
            // Console.WriteLine($"-----------BEGIN TEST {currentTestName}----------");
            var OutputMd5s = new Dictionary <string, List <FileInfo> >();

            Console.Title = $"Running test {JobName}_{test.ID} | {GetTitle()}";

            for (var i = 0; i < Executables.Count; i++)
            {
                var p = processes[i];
                var e = Executables[i];
                p.WaitForExit();
                Thread.Sleep(5);
                processes[i].StartInfo.StdIO.StandardOutput.Close();
                processes[i].StartInfo.StdIO.StandardInput.Close();

                var maxMem     = (uint)p.GetMemoryCounters().Value.PeakWorkingSetSize;
                var outputPath = Path.Combine(testOutputDir, $"{currentTestName}_{Executables[i].Name}.out");
                var outputmd5  = md5(outputPath);
                if (Executables[i].Name == MasterExecutable)
                {
                    MasterMD5 = outputmd5;
                }
                if (!OutputMd5s.ContainsKey(outputmd5))
                {
                    OutputMd5s.Add(outputmd5, new List <FileInfo>());
                    File.Move(outputPath, Path.Combine(testOutputDir, outputmd5 + ".out"));
                }
                OutputMd5s[outputmd5].Add(Executables[i]);
                //File.Delete(outputPath);

                //if (outputmd5 != "NIE")
                //{
                //    _Ile_Razy_bylo_cokolwiek_innego_niz_NIE++;
                //}

                var error = p.OutOfMemory || p.OutOfTime || p.ExitCode.GetValueOrDefault(0xBAD) != 0;
                //if (error || outputmd5 != MasterMD5)
                {
                    anything = true;
                    TotalWall[Executables[i].Name] += (ulong)p.Clock.TotalMilliseconds;
                    Console.WriteLine($"-----------BEGIN TEST {currentTestName}----------");
                    Console.ForegroundColor = error ? ConsoleColor.Red : ConsoleColor.Green;
                    var prefix = Executables[i].Name == MasterExecutable ? " [MASTER] " : " ";
                    Console.WriteLine($"--{prefix}{e.Name}");
                    Console.ForegroundColor = p.OutOfMemory || p.OutOfTime ? ConsoleColor.Red : ConsoleColor.Green;
                    Console.WriteLine($"\t OutOfMemory: {p.OutOfMemory} OutOfTime: {p.OutOfTime}");
                    Console.ForegroundColor = maxMem > MaxMem ? ConsoleColor.Red : ConsoleColor.Green;
                    Console.WriteLine($"\t Memory: {maxMem / 1024}/{MaxMem / 1024}");
                    Console.ForegroundColor = (int)p.Clock.TotalMilliseconds > MaxTime || (int)p.FixedProcessTime > MaxTime
                        ? ConsoleColor.Red
                        : ConsoleColor.Green;
                    Console.WriteLine(
                        $"\t Wall time: {(int) p.Clock.TotalMilliseconds}ms/{MaxTime}ms FIXED time: {(int) p.FixedProcessTime}ms/{MaxTime}ms");
                    Console.ForegroundColor = p.ExitCode != 0 ? ConsoleColor.Red : ConsoleColor.Green;
                    Console.WriteLine($"\t ExitCode: {p.ExitCode} " + (p.ExitCode == 0 ? "OK" : "ERROR"));
                    Console.ResetColor();
                    Console.WriteLine($"\t Output: {outputmd5}");
                }


                if (error || outputmd5 != MasterMD5)
                {
                    if (!Errors.ContainsKey(Executables[i].Name))
                    {
                        Errors.Add(Executables[i].Name, new List <string>());
                    }
                    Errors[Executables[i].Name].Add(currentTestName);
                }
                //Console.ForegroundColor = (!outputOK) ? ConsoleColor.Red : ConsoleColor.Green;
                //Console.WriteLine($"\t Output: OK");
            }

            if (OutputMd5s.Count == 1)
            {
                //Console.ForegroundColor = ConsoleColor.Green;
                //Console.WriteLine("\t\t------ALL OUTPUTS MATCH------");
                ok = true;
                var targetTest = Path.Combine(OutputDir, $"{currentTestName}.out");
                if (File.Exists(targetTest))
                {
                    File.Delete(targetTest);
                }
                File.Delete(Path.Combine(testOutputDir, $"{MasterMD5}.out"));
                //File.Move(Path.Combine(testOutputDir, $"{MasterMD5}.out"), targetTest);
                Directory.Delete(testOutputDir, true);
            }
            else
            {
                ok = false;
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("\t\t------OUTPUTS DO NOT MATCH!------");
                ++Mismatches;
                Console.ResetColor();
                var md5s = OutputMd5s.Keys.OrderBy(t => OutputMd5s[t].Count);
                File.Copy(testPath, Path.Combine(testOutputDir, $"{currentTestName}.in"), true);
                foreach (var key in md5s)
                {
                    var list = OutputMd5s[key];
                    var str  = string.Join(", ", list);
                    var file = string.Join("_", list.Select(t => t.Name.Replace(".exe", ""))) + ".out";
                    Console.ForegroundColor = key == MasterMD5 ? ConsoleColor.Green : ConsoleColor.DarkYellow;
                    File.Move(Path.Combine(testOutputDir, $"{key}.out"), Path.Combine(testOutputDir, file));
                    if (key == MasterMD5)
                    {
                        File.Copy(Path.Combine(testOutputDir, file), Path.Combine(OutputDir, $"{currentTestName}.out"), true);
                    }
                    Console.WriteLine($"{key}: {str}");
                }
                Console.ResetColor();
            }
            if (anything)
            {
                Console.WriteLine($"-----------END TEST {currentTestName}----------");
            }
            return(ok);
            //Console.ResetColor();
        }