コード例 #1
0
 /// <summary>
 /// In case we are re-running a build process the output file may already exist and we need to make sure it doesn't contaminate the new test run.
 /// This function deletes the output file if it exists.
 /// </summary>
 protected bool DeleteOutputFile(string absOutputPath, ref ezTest.TestTargetResult res)
 {
     if (System.IO.File.Exists(absOutputPath))
     {
         try
         {
             System.IO.File.Delete(absOutputPath);
         }
         catch (System.Exception ex)
         {
             res.Error("Error deleting test output file ({0}): {1}", absOutputPath, ex.Message);
             return(false);
         }
     }
     return(true);
 }
コード例 #2
0
ファイル: Test.cs プロジェクト: eltld/ezEngine
        ezTest.TestTargetResult RunTest(ezCMake.TestTarget target)
        {
            ezTest.TestTargetResult res = new ezTest.TestTargetResult();
            res.Name = target.Name;
            res.NeedsHardwareAccess = target.NeedsHardwareAccess;
            res.Experimental        = target.Experimental;

            string sAbsBinDir      = System.IO.Path.Combine(_Settings.AbsBinPath, _Settings.Configuration);
            string sAbsBinFilename = System.IO.Path.Combine(sAbsBinDir, target.Name);
            string sAbsOutputPath  = System.IO.Path.Combine(_Settings.AbsOutputFolder, string.Format("{0}_{1}_{2}.json", _Settings.Configuration, _Settings.Revision, target.Name));

            // In case we are re-running a build process the output file may already exist and we need to make sure it doesn't
            // contaminate the new test run.
            if (System.IO.File.Exists(sAbsOutputPath))
            {
                try
                {
                    System.IO.File.Delete(sAbsOutputPath);
                }
                catch (Exception ex)
                {
                    res.Error("Error deleting test output file ({0}): {1}", sAbsOutputPath, ex.Message);
                    return(res);
                }
            }

            res.ProcessRes = ezProcessHelper.RunExternalExe(sAbsBinFilename, string.Format("-json \"{0}\" -rev {1} -nogui -all", sAbsOutputPath, _Settings.Revision), sAbsBinDir, res);
            res.Success    = (res.ProcessRes.ExitCode == 0);
            res.Duration   = res.ProcessRes.Duration;

            if (System.IO.File.Exists(sAbsOutputPath))
            {
                res.TestResultJSON = System.IO.File.ReadAllText(sAbsOutputPath, Encoding.UTF8);
            }
            else
            {
                res.Error("No output file present!");
            }

            if (!res.Success && !res.Experimental)
            {
                res.Error("Testing '{0}' failed!", res.Name);
            }
            return(res);
        }
コード例 #3
0
        public override ezTest.TestTargetResult BuildTarget(ezCMake.TestTarget target, BuildShared.BuildMachineSettings settings)
        {
            ezTest.TestTargetResult res = new ezTest.TestTargetResult();
            res.Name = target.Name;
            res.NeedsHardwareAccess = target.NeedsHardwareAccess;
            res.Experimental        = target.Experimental;

            string absBinDir      = System.IO.Path.Combine(settings.AbsBinPath, settings.Configuration);
            string absBinFilename = System.IO.Path.Combine(absBinDir, target.Name);
            string outputFilename = GetOutputFileName(target, settings);
            string absOutputPath  = System.IO.Path.Combine(settings.AbsOutputFolder, outputFilename);

            if (!DeleteOutputFile(absOutputPath, ref res))
            {
                return(res);
            }

            res.ProcessRes = ezProcessHelper.RunExternalExe(absBinFilename, GetDefaultTestArgs(absOutputPath, settings), absBinDir, res);
            res.Success    = (res.ProcessRes.ExitCode == 0);
            res.Duration   = res.ProcessRes.Duration;

            if (System.IO.File.Exists(absOutputPath))
            {
                res.TestResultJSON = System.IO.File.ReadAllText(absOutputPath, Encoding.UTF8);
            }
            else
            {
                res.Error("No output file present!");
            }

            if (!res.Success && !res.Experimental)
            {
                res.Error("Testing '{0}' failed!", res.Name);
            }
            return(res);
        }
コード例 #4
0
        public override ezTest.TestTargetResult BuildTarget(ezCMake.TestTarget target, BuildMachineSettings settings)
        {
            ezTest.TestTargetResult res = new ezTest.TestTargetResult();
            res.Name = target.Name;
            res.NeedsHardwareAccess = target.NeedsHardwareAccess;
            res.Experimental        = target.Experimental;


            // Prepare output path (may fail, and we don't want to go through the rest if it does)
            string outputFilename = GetOutputFileName(target, settings);
            string absOutputPath  = System.IO.Path.Combine(settings.AbsOutputFolder, outputFilename);

            if (!DeleteOutputFile(absOutputPath, ref res))
            {
                return(res);
            }

            // Deploy app.
            string fullPackageName;
            var    deployResult = DeployAppX(target, settings, out fullPackageName);

            res.MergeIn(deployResult);
            if (!deployResult.Success)
            {
                return(res);
            }

            // Start AppX
            uint appXPid;
            var  startResult = StartAppX(fullPackageName, GetDefaultTestArgs(outputFilename, settings), out appXPid);

            res.MergeIn(startResult);
            if (!startResult.Success)
            {
                return(res);
            }
            Process appXProcess;

            try
            {
                appXProcess = Process.GetProcessById((int)appXPid);
            }
            catch (Exception e)
            {
                res.Error("Failed to get process handle to test app: {0}", e);
                return(res);
            }

            // Start fileserver.
            string absFilerserveFilename = GetFileserverPath(settings);

            if (!File.Exists(absFilerserveFilename))
            {
                res.Error("No fileserver found. File '{0}' does not exist.", absFilerserveFilename);
            }
            else
            {
                string absBinDir       = Path.Combine(settings.AbsBinPath, settings.Configuration);
                string absTestDataPath = Path.Combine(settings.AbsCodePath, relativeTestDataPath);
                // 20s timeout for connect, 2s timeout for closing after connection loss.
                string args = string.Format("-specialdirs project \"{0}\" eztest \"{1}\" -fs_start -fs_wait_timeout 20 -fs_close_timeout 2", absTestDataPath, settings.AbsOutputFolder);
                res.ProcessRes = ezProcessHelper.RunExternalExe(absFilerserveFilename, args, absBinDir, res);
                res.Duration  += res.ProcessRes.Duration;
                res.Success    = (res.ProcessRes.ExitCode == 0);
            }

            // Top watch.

            // Check whether the AppX is dead by now.
            if (!appXProcess.HasExited)
            {
                res.Error("Fileserve is no longer running but the AppX is.");
                res.Success = false;
                appXProcess.Kill();
            }
            // Can't read exit code: "Process was not started by this object, so requested information cannot be determined"

            /*else
             * {
             * if (appXProcess.ExitCode != 0)
             * {
             *  res.Error("Test AppX exited with {0}", appXProcess.ExitCode);
             *  res.Success = false;
             * }
             * }*/
            appXProcess.Dispose();
            appXProcess = null;

            // Read test output.
            if (File.Exists(absOutputPath))
            {
                res.TestResultJSON = File.ReadAllText(absOutputPath, Encoding.UTF8);
                //TODO: use test json output as stdout substitute until pipes are implemented.
                res.ProcessRes.StdOut = res.TestResultJSON;
                try
                {
                    // Parse test output to figure out what the result is as we can't use the exit code.
                    var values = Newtonsoft.Json.JsonConvert.DeserializeObject <System.Collections.Generic.Dictionary <string, dynamic> >(res.TestResultJSON);
                    var errors = values["errors"] as Newtonsoft.Json.Linq.JArray;
                    res.Success = errors.Count == 0;
                }
                catch (Exception e)
                {
                    res.Success = false;
                    res.Error("Failed to parse test output: '{0}'", e.ToString());
                }
            }
            else
            {
                res.Error("No output file present!");
                res.Success = false;
            }

            if (!res.Success && !res.Experimental)
            {
                res.Error("Testing '{0}' failed!", res.Name);
            }
            return(res);
        }