public void AddRun(TestCase testCase, Benchmark benchmark, string text) {
            if (string.IsNullOrEmpty(text)) return;
            var runEntry = new RunEntry() { TestCase = testCase, Benchmark = benchmark, RawLog = text };
            RunEntries.Add(runEntry);

            ParseInfolog(text, runEntry);
            if (testCase.BenchmarkArg > 0) ParseBenchmarkData(runEntry);
        }
Пример #2
0
 void TestedBatchOnRunCompleted(TestCase run, Benchmark benchmark, string arg3) {
     var stringToAppend = string.Format("== RUN {0} {1} ==\n", run, benchmark) + arg3;
                 InvokeIfNeeded(() => tbResults.AppendText(stringToAppend));
 }
Пример #3
0
 void btnAddTest_Click(object sender, EventArgs e) {
     var testCase = new TestCase(tbEngine.Text,
                                 tbGame.Text,
                                 tbMap.Text,
                                 cbConfigs.SelectedItem as Config,
                                 cmbScripts.SelectedItem as StartScript);
     int arg;
     int.TryParse(tbBenchmarkArg.Text, out arg);
     testCase.BenchmarkArg = arg;
     var ret = testCase.Validate(springDownloader);
     if (ret != null) MessageBox.Show(ret);
     else lbTestCases.Items.Add(testCase);
 }
Пример #4
0
        /// <summary>
        /// Modify modinfo to add or change dependencies. If mod already depends on game which starts with same word as testcase game, replace it, otherwise append it
        /// </summary>
        public void ModifyModInfo(TestCase testCase) {
            var orgFile = Path.Combine(BenchmarkPath, "modinfo.lua.org");
            var modFile = Path.Combine(BenchmarkPath, "modinfo.lua");
            File.Copy(modFile, orgFile, true);


            var deps = GetDependencies();

            if (!string.IsNullOrEmpty(testCase.Game)) {
                var firstWord = testCase.Game.Split(' ').First();
                var toReplace = deps.FirstOrDefault(x => x.StartsWith(firstWord + " "));
                if (toReplace != null) deps.Remove(toReplace);
                deps.Add(testCase.Game);
            }

            File.WriteAllText(Path.Combine(BenchmarkPath, "modinfo.lua"),
                              Regex.Replace(GetOrgModInfo(),
                                            "(depend[ ]*=[ ]*{)([^}]*)(})",
                                            m => m.Groups[1].Value + string.Join(",", deps.Select(x => string.Format("'{0}'", x))) + m.Groups[3],RegexOptions.IgnoreCase));
        }
Пример #5
0
        public string Start(SpringPaths paths, TestCase test, Benchmark benchmark) {
            LogLines = new StringBuilder();

            //paths.SetEnginePath(paths.GetEngineFolderByVersion(test.Engine));

            var optirun = Environment.GetEnvironmentVariable("OPTIRUN");
            
            process = new Process();
            process.StartInfo.CreateNoWindow = true;
            List<string> arg = new List<string>();

            if (string.IsNullOrEmpty(optirun)) {
                process.StartInfo.FileName = paths.GetSpringExecutablePath(test.Engine);
            }
            else {
                Trace.TraceInformation("Using optirun {0} to start the game (OPTIRUN env var defined)", optirun);
                process.StartInfo.FileName = optirun;
                arg.Add(string.Format("\"{0}\"", ( paths.GetSpringExecutablePath(test.Engine))));
            }



            process.StartInfo.WorkingDirectory = Path.GetDirectoryName(paths.GetSpringExecutablePath(test.Engine));

            arg.Add(string.Format("--config \"{0}\"", Path.Combine(test.Config.ConfigPath, "springsettings.cfg")));
            if (test.BenchmarkArg > 0) arg.Add("--benchmark " + test.BenchmarkArg);


            var dataDirList = new List<string>()
            {
                test.Config.ConfigPath,
                Directory.GetParent(benchmark.BenchmarkPath).Parent.FullName,
                paths.WritableDirectory,
            };
            dataDirList.AddRange(paths.DataDirectories);
            dataDirList.Add(Path.GetDirectoryName(paths.GetSpringExecutablePath(test.Engine)));

            if (Environment.OSVersion.Platform == PlatformID.Unix) dataDirList = dataDirList.Distinct().Select(x => x.Replace(" ", "\\ ")).ToList();
            else dataDirList = dataDirList.Distinct().ToList();

            var datadirs = string.Join(Environment.OSVersion.Platform == PlatformID.Unix ? ":" : ";", dataDirList);

            process.StartInfo.EnvironmentVariables["SPRING_DATADIR"] = datadirs;
            process.StartInfo.EnvironmentVariables["SPRING_ISOLATED"] = test.Config.ConfigPath;
            process.StartInfo.EnvironmentVariables["SPRING_WRITEDIR"] = test.Config.ConfigPath;

            var scriptPath = Path.GetTempFileName();
            File.WriteAllText(scriptPath, test.StartScript.GetScriptForTestCase(test, benchmark));
            arg.Add(string.Format("\"{0}\"", scriptPath));

            
            process.StartInfo.Arguments = string.Join(" ", arg);
            process.StartInfo.UseShellExecute = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError = true;

            process.ErrorDataReceived += (sender, args) =>
                {
                    LogLines.AppendLine(args.Data);
                    LineAdded(args.Data);
                };
            process.OutputDataReceived += (sender, args) =>
                {
                    LogLines.AppendLine(args.Data);
                    LineAdded(args.Data);
                };
            process.EnableRaisingEvents = true;

            try {
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();

                process.WaitForExit();
            } catch (Exception ex) {
                Trace.TraceError("Error waiting for process: {0}", ex);
            }
            var lines = LogLines.ToString();

            File.Delete(scriptPath);

            return lines;
        }
 /// <summary>
 /// Gets modified startscript for starting the game
 /// </summary>
 public string GetScriptForTestCase(TestCase test, Benchmark benchmark) {
     var script = GetScript();
     script = Regex.Replace(script, "(gametype=)([^;]*)", m => m.Groups[1] + benchmark.Name, RegexOptions.IgnoreCase);
     if (!string.IsNullOrEmpty(test.Map)) script = Regex.Replace(script, "(mapname=)([^;]*)", m => m.Groups[1] + test.Map, RegexOptions.IgnoreCase);
     return script;
 }
Пример #7
0
        public string Start(SpringPaths paths, TestCase test, Benchmark benchmark)
        {
            LogLines = new StringBuilder();

            paths.SetEnginePath(paths.GetEngineFolderByVersion(test.Engine));

            var optirun = Environment.GetEnvironmentVariable("OPTIRUN");

            process = new Process();
            process.StartInfo.CreateNoWindow = true;
            List <string> arg = new List <string>();

            if (string.IsNullOrEmpty(optirun))
            {
                process.StartInfo.FileName = test.UseMultithreaded ? paths.MtExecutable : paths.Executable;
            }
            else
            {
                Trace.TraceInformation("Using optirun {0} to start the game (OPTIRUN env var defined)", optirun);
                process.StartInfo.FileName = optirun;
                arg.Add(string.Format("\"{0}\"", (test.UseMultithreaded ? paths.MtExecutable : paths.Executable)));
            }



            process.StartInfo.WorkingDirectory = Path.GetDirectoryName(paths.Executable);

            arg.Add(string.Format("--config \"{0}\"", Path.Combine(test.Config.ConfigPath, "springsettings.cfg")));
            if (test.BenchmarkArg > 0)
            {
                arg.Add("--benchmark " + test.BenchmarkArg);
            }


            var dataDirList = new List <string>()
            {
                test.Config.ConfigPath,
                Directory.GetParent(benchmark.BenchmarkPath).Parent.FullName,
                paths.WritableDirectory,
            };

            dataDirList.AddRange(paths.DataDirectories);
            dataDirList.Add(Path.GetDirectoryName(paths.Executable));

            if (Environment.OSVersion.Platform == PlatformID.Unix)
            {
                dataDirList = dataDirList.Distinct().Select(x => x.Replace(" ", "\\ ")).ToList();
            }
            else
            {
                dataDirList = dataDirList.Distinct().ToList();
            }

            var datadirs = string.Join(Environment.OSVersion.Platform == PlatformID.Unix ? ":" : ";", dataDirList);

            process.StartInfo.EnvironmentVariables["SPRING_DATADIR"]  = datadirs;
            process.StartInfo.EnvironmentVariables["SPRING_ISOLATED"] = test.Config.ConfigPath;
            process.StartInfo.EnvironmentVariables["SPRING_WRITEDIR"] = test.Config.ConfigPath;

            var scriptPath = Path.GetTempFileName();

            File.WriteAllText(scriptPath, test.StartScript.GetScriptForTestCase(test, benchmark));
            arg.Add(string.Format("\"{0}\"", scriptPath));


            process.StartInfo.Arguments              = string.Join(" ", arg);
            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = true;
            process.StartInfo.RedirectStandardError  = true;

            process.ErrorDataReceived += (sender, args) =>
            {
                LogLines.AppendLine(args.Data);
                LineAdded(args.Data);
            };
            process.OutputDataReceived += (sender, args) =>
            {
                LogLines.AppendLine(args.Data);
                LineAdded(args.Data);
            };
            process.EnableRaisingEvents = true;

            try {
                process.Start();
                process.BeginOutputReadLine();
                process.BeginErrorReadLine();

                process.WaitForExit();
            } catch (Exception ex) {
                Trace.TraceError("Error waiting for process: {0}", ex);
            }
            var lines = LogLines.ToString();

            File.Delete(scriptPath);

            return(lines);
        }