Beispiel #1
0
 void Add(Process pnunitTestRunnerProc, PNUnitTestInfo testInfo)
 {
     lock (mRunningTests)
     {
         mRunningTests.Add(new RunningTest(pnunitTestRunnerProc, testInfo));
     }
 }
Beispiel #2
0
        public static PNUnitTestInfo ReadTestInfo(string testInfoPath)
        {
            int            ini    = Environment.TickCount;
            PNUnitTestInfo result = null;

            try
            {
                using (FileStream fs = new FileStream(testInfoPath, FileMode.Open, FileAccess.Read))
                {
                    BinaryFormatter bf = new BinaryFormatter();
                    bf.AssemblyFormat = FormatterAssemblyStyle.Simple;
                    result            = (PNUnitTestInfo)bf.Deserialize(fs);

                    return(result);
                }
            }
            catch (Exception e)
            {
                mLog.ErrorFormat("Something wrong happened when reading the agent info: " + e.Message);
                return(null);
            }
            finally
            {
                TryDelete(testInfoPath);
                mLog.DebugFormat(
                    "Read test info file {0} {1} ms",
                    testInfoPath, Environment.TickCount - ini);
            }
        }
Beispiel #3
0
        internal static void NotifyError(Exception e, PNUnitTestInfo info)
        {
            TestLogInfo testLogInfo = new TestLogInfo();

            testLogInfo.SetOSVersion(Environment.OSVersion.Platform.ToString());

            TestName testName = new TestName();

            testName.Name     = info.TestName;
            testName.FullName = info.TestName;
            testName.TestID   = new TestID();

            PNUnitTestResult result = new PNUnitTestResult(
                testName, info.GetTestOutput(),
                testLogInfo.OSVersion, testLogInfo.BackendType, true);

            string fullMessage = string.Format(
                "TestName: {0}; Error: {1}; EXCEPTION TYPE: {2}; STACK TRACE: {3}",
                testName.Name, e.Message, e.GetType(), e.StackTrace);

            result.Failure(fullMessage, string.Empty);

            info.DeleteTestOutput();

            IPNUnitServices services =
                PNUnitServices.GetPNunitServicesProxy(info.PNUnitServicesServer);

            services.NotifyResult(info.TestName, result);
        }
Beispiel #4
0
        Process LaunchTestRunner(PNUnitTestInfo testInfo, string testInfoPath)
        {
            string testingArgs = string.Format(
                "\"{0}\" \"{1}\"", testInfoPath, mPathToAssemblies);

            // You should customize this section depending on the applications
            // you've got and the platform they run on.
            Process result = null;

            if (testInfo.TestName.StartsWith("windows:"))
            {
                result = ProcessCreator.CreateGuiApplicationRunnerProcess(
                    testInfo, "windows.exe", testingArgs, mPathToAssemblies);
            }

            if (testInfo.TestName.StartsWith("linux:"))
            {
                result = ProcessCreator.CreateGuiApplicationRunnerProcess(
                    testInfo, "linux", testingArgs, mPathToAssemblies);
            }

            if (testInfo.TestName.StartsWith("mac:"))
            {
                result = ProcessCreator.CreateGuiApplicationRunnerProcess(
                    testInfo, "macos.app/Contents/MacOS/macos", testingArgs, mPathToAssemblies);
            }

            if (result == null)
            {
                result = ProcessCreator.CreateTestRunnerProc(testingArgs, mPathToAssemblies);
            }

            result.Start();
            return(result);
        }
Beispiel #5
0
            internal static PNUnitTestInfo ReadTestInfo(string testInfoPath)
            {
                int init = Environment.TickCount;

                try
                {
                    using (FileStream fs = new FileStream(testInfoPath, FileMode.Open, FileAccess.Read))
                    {
                        BinaryFormatter bf = new BinaryFormatter();
                        bf.AssemblyFormat = FormatterAssemblyStyle.Simple;
                        PNUnitTestInfo result = (PNUnitTestInfo)bf.Deserialize(fs);

                        result.TestToRun = CleanTestName(result.TestToRun);
                        return(result);
                    }
                }
                catch (Exception ex)
                {
                    mLog.ErrorFormat(
                        "Something went wrong while reading the agent info: {0}",
                        ex.Message);
                    return(null);
                }
                finally
                {
                    TryDelete(testInfoPath);
                    mLog.DebugFormat(
                        "Read test info file {0} in {1} ms.",
                        testInfoPath, Environment.TickCount - init);
                }
            }
Beispiel #6
0
        public void RunTest(PNUnitTestInfo testInfo)
        {
            try
            {
                int ini = Environment.TickCount;

                mLog.InfoFormat(
                    ">>RunTest called for Test {0}, AssemblyName {1}, TestToRun {2}",
                    testInfo.TestName, testInfo.AssemblyName, testInfo.TestToRun);

                mTestCounter.Increment();

                CreateTestOutputFile(testInfo);

                // spawn the test in a new process
                string testInfoPath = WriteTestInfo(testInfo);

                mProcessPool.RunProcess(testInfo, testInfoPath);

                mLog.InfoFormat(
                    "<<RunTest {0} - {1} launched in {2} ms.",
                    testInfo.TestName, testInfo.TestToRun, Environment.TickCount - ini);
            }
            catch (Exception e)
            {
                mLog.ErrorFormat("<<RunTest {0} - {1} failed {2}",
                                 testInfo.TestName, testInfo.TestToRun, e.Message);

                NotifyError(e, testInfo);
            }
        }
 public NUnitTestRunner(
     PNUnitTestInfo info,
     string pathToAssemblies)
 {
     mNUnitAssemblyPath = Path.Combine(pathToAssemblies, info.AssemblyName);
     mPNUnitTestInfo    = info;
 }
Beispiel #8
0
        internal static PNUnitTestResult BuildError(
            PNUnitTestInfo pnunitTestInfo,
            Exception e,
            TestConsoleAccess consoleAccess,
            TestLogInfo testLogInfo)
        {
            TestName testName = new TestName();

            testName.Name     = pnunitTestInfo.TestName;
            testName.FullName = pnunitTestInfo.TestName;
            testName.TestID   = new TestID();

            PNUnitTestResult result = new PNUnitTestResult(
                testName,
                pnunitTestInfo.GetTestOutput(),
                testLogInfo.OSVersion,
                testLogInfo.BackendType);

            string fullMessage = string.Format(
                "{0}; EXCEPTION TYPE: {1}; STACK TRACE: {2}",
                e.Message, e.GetType(), e.StackTrace);

            result.Failure(fullMessage, string.Empty);

            pnunitTestInfo.DeleteTestOutput();
            return(result);
        }
Beispiel #9
0
        public void RunTest(PNUnitTestInfo info)
        {
            log.InfoFormat("RunTest called for Test {0}, AssemblyName {1}, TestToRun {2}",
                           info.TestName, info.AssemblyName, info.TestToRun);

            new PNUnitTestRunner(info, mConfig).Run();
        }
Beispiel #10
0
        private TestResult BuildResult(
            TestResult result,
            TestConsoleAccess consoleAccess,
            PNUnitTestInfo testInfo)
        {
            //the test namespace contains errors
            if (result == null)
            {
                TestName testName = new TestName();
                testName.Name     = testInfo.TestName;

                string errormsg = "The test {0} couldn't be found in the assembly {1}";

                result = new PNUnitTestResult(testName, string.Empty);
                result.Failure(
                    string.Format(errormsg, testInfo.TestToRun, testInfo.AssemblyName),
                    string.Empty);

                return(result);
            }

            if (!result.IsSuccess /*|| ReturnTestOutput()*/)
            {
                return(new PNUnitTestResult(result, consoleAccess.GetTestOutput()));
            }
            else
            {
                return(result);
            }
        }
Beispiel #11
0
        internal void RunProcess(
            PNUnitTestInfo testInfo,
            string testInfoPath)
        {
            Process pnunitTestRunnerProc = Run(testInfo, testInfoPath);

            Add(pnunitTestRunnerProc, testInfo);
        }
Beispiel #12
0
 public PNUnitTestRunner(
     PNUnitTestInfo info,
     AgentConfig config)
 {
     mConfig         = config;
     mPNUnitTestInfo = info;
     mbUseDomainPool = config.UseDomainPool;
 }
 static void InitPNUnitServices(
     PNUnitTestInfo testInfo,
     TestRunner testRunner,
     IPNUnitServices services,
     TestConsoleAccess consoleAccess,
     TestLogInfo testLogInfo)
 {
     // Intialize the singleton
     new PNUnitServices(testInfo, services, consoleAccess, testLogInfo);
 }
Beispiel #14
0
        void CreateTestOutputFile(PNUnitTestInfo info)
        {
            string outputTestFilePath = Path.GetTempFileName();

            using (StreamWriter sw = new StreamWriter(outputTestFilePath, false))
            {
                sw.WriteLine("");
            }

            info.OutputFile = outputTestFilePath;
        }
Beispiel #15
0
        static void RunPreload(string pathToAssemblies)
        {
            mLog.Debug("Preload started. Path To assemblies:" + pathToAssemblies);
            InitServices.InitNUnitServices();

            PNUnitTestRunner runner = new PNUnitTestRunner(pathToAssemblies);

            runner.Preload();

            int pidOfThisExpectedByAgent = Codice.Test.PlatformIdentifier.IsWindows() ?
                                           System.Diagnostics.Process.GetCurrentProcess().Id :
                                           Mono.Unix.UnixEnvironment.GetParentProcessId();

            string testInfoFile = Path.Combine(
                Path.GetTempPath(),
                PNUnit.Agent.AssemblyPreload.PRELOADED_PROCESS_FILE_PREFIX + pidOfThisExpectedByAgent.ToString());

            int count = 0;

            while (!File.Exists(testInfoFile))
            {
                System.Threading.Thread.Sleep(150);
                mLog.DebugFormat("Waiting for testinfo file to be created...: {0}", testInfoFile);

                count++;

                if (count >= 6000) //wait 1,5 minutes for test arrival
                {
                    mLog.Fatal("Tired of waiting: Cannot execute tests without information; exiting ...");
                    Environment.Exit(1);
                }
            }

            mLog.DebugFormat("Preload read {0} from file", testInfoFile);

            PNUnitTestInfo info = TestInfoReader.ReadTestInfo(testInfoFile);

            if (info == null)
            {
                mLog.Fatal("Cannot execute tests without information; exiting ...");
                Environment.Exit(1);
            }

            ProcessNameSetter.SetProcessName(info.TestName);

            IPNUnitServices services =
                PNUnitServices.GetPNunitServicesProxy(info.PNUnitServicesServer);

            runner.Run(info, services, null);
        }
Beispiel #16
0
        string WriteTestInfo(PNUnitTestInfo info)
        {
            string infoConfigPath = Path.GetTempFileName();

            using (FileStream fs = new FileStream(infoConfigPath, FileMode.OpenOrCreate))
            {
                BinaryFormatter bf = new BinaryFormatter(new RemotingSurrogateSelector(),
                                                         new StreamingContext(StreamingContextStates.CrossAppDomain));
                bf.AssemblyFormat = FormatterAssemblyStyle.Simple;
                bf.Serialize(fs, info);
            }

            return(infoConfigPath);
        }
Beispiel #17
0
        static void CreatePNUnitServices(
            PNUnitTestInfo testInfo,
            TestRunner testRunner,
            IPNUnitServices services,
            TestConsoleAccess consoleAccess,
            TestLogInfo testLogInfo,
            ITestConsoleAccess extraConsoleAccess)
        {
            // Intialize the singleton
            new PNUnitServices(testInfo, services, consoleAccess, testLogInfo);

            if (extraConsoleAccess != null)
            {
                PNUnitServices.Get().RegisterConsole(extraConsoleAccess);
            }
        }
Beispiel #18
0
        Process Run(PNUnitTestInfo testInfo, string testInfoPath)
        {
            if (!mbUsePreload || !AssemblyPreload.CanUsePreload(testInfo.AssemblyName))
            {
                return(LaunchTestRunner(testInfo, testInfoPath));
            }

            Process result = LaunchPreloaded(testInfoPath);

            if (result != null)
            {
                return(result);
            }

            return(LaunchTestRunner(testInfo, testInfoPath));
        }
Beispiel #19
0
        TestResult RunTest(
            PNUnitTestInfo testInfo,
            ConsoleWriter outStream,
            TestRunner testRunner)
        {
            EventListener collector = new EventCollector(outStream);

            ITestFilter filter = new NUnit.Core.Filters.SimpleNameFilter(
                testInfo.TestToRun);

            TestResult result = testRunner.Run(
                collector, filter, true, LoggingThreshold.All);

            result = FindResult(testInfo.TestToRun, result);

            return(result);
        }
Beispiel #20
0
        internal static PNUnitTestResult BuildResult(
            PNUnitTestInfo pnunittestinfo,
            TestResult result,
            TestConsoleAccess consoleAccess,
            TestLogInfo testLogInfo)
        {
            string output = pnunittestinfo.GetTestOutput();

            pnunittestinfo.DeleteTestOutput();

            mLog.Debug("Going to build the result ...");

            if (result == null)
            {
                mLog.Debug("Going to build an error result ...");
                TestName testName = new TestName();
                testName.Name     = pnunittestinfo.TestName;
                testName.FullName = pnunittestinfo.TestName;
                testName.TestID   = new TestID();

                string errorMsg = string.Format(
                    "The test {0} couldn't be found in the assembly {1}",
                    pnunittestinfo.TestToRun,
                    pnunittestinfo.AssemblyName);

                PNUnitTestResult testResult = new PNUnitTestResult(
                    testName,
                    output,
                    testLogInfo.OSVersion,
                    testLogInfo.BackendType);

                testResult.Failure(errorMsg, string.Empty);
                return(testResult);
            }

            PNUnitTestResult myResult = new PNUnitTestResult(result, output,
                                                             testLogInfo.OSVersion, testLogInfo.BackendType);

            return(myResult);
        }
Beispiel #21
0
        public void Run(object state)
        {
            InitServices.InitNUnitServices();

            PNUnitTestInfo testInfo = TestInfoReader.ReadTestInfo(mTestInfoFile);

            if (testInfo == null)
            {
                Console.Error.WriteLine("Cannot execute tests without information. Exiting...");
                mGuiFinalizer.Finalize(1);
            }

            IPNUnitServices services = GetPNUnitServices(testInfo.PNUnitServicesServer);

            PNUnitTestRunner.PNUnitTestRunner runner =
                new PNUnitTestRunner.PNUnitTestRunner(mPathToAssemblies);

            runner.Run(testInfo, services, mGuiConsole);

            GuiTestAssemblyResolver.UninstallAssemblyResolver();

            mGuiFinalizer.Finalize(1);
        }
Beispiel #22
0
        static void RunOnce(string testInfoFile, string pathToAssemblies)
        {
            PNUnitTestInfo info = TestInfoReader.ReadTestInfo(testInfoFile);

            if (info == null)
            {
                Console.WriteLine("Cannot execute tests without information; exiting ...");
                Environment.Exit(1);
            }

            ProcessNameSetter.SetProcessName(info.TestName);

            IPNUnitServices services =
                PNUnitServices.GetPNunitServicesProxy(info.PNUnitServicesServer);

            if (info.TestName.StartsWith("run-nunit"))
            {
                new NUnitTestRunner(info, pathToAssemblies).Run(services);
                return;
            }

            new PNUnitTestRunner(pathToAssemblies).Run(info, services, null);
        }
Beispiel #23
0
            internal static Process CreateGuiApplicationRunnerProcess(
                PNUnitTestInfo testInfo,
                string executableName,
                string testingArgs,
                string pathToAssemblies)
            {
                if (testInfo.TestParams.Length == 0)
                {
                    throw new Exception("The test is wrongly defined!");
                }

                string executablePath = Path.Combine(
                    pathToAssemblies, testInfo.TestParams[0]);

                executablePath = Path.GetFullPath(executablePath);

                string processName = Path.Combine(executablePath, executableName);

                string arguments = string.Concat(testInfo.TestParams[1], " ", testingArgs);

                mLog.DebugFormat(
                    "Running process [{0} {1}]", processName, arguments);

                Console.WriteLine(processName);
                Console.WriteLine(arguments);

                Process testRunnerProc = new Process();

                testRunnerProc.StartInfo.UseShellExecute  = false;
                testRunnerProc.StartInfo.FileName         = processName;
                testRunnerProc.StartInfo.CreateNoWindow   = false;
                testRunnerProc.StartInfo.WorkingDirectory = pathToAssemblies;
                testRunnerProc.StartInfo.Arguments        = arguments;

                return(testRunnerProc);
            }
Beispiel #24
0
        TestRunner SetupTest(
            PNUnitTestInfo testInfo,
            IPNUnitServices services,
            TestConsoleAccess consoleAccess,
            TestLogInfo testLogInfo,
            ITestConsoleAccess extraConsoleAccess)
        {
            TestRunner result;
            bool       testAssemblyLoaded;

            if (mPreloader == null)
            {
                result = new SimpleTestRunner();

                int ini = Environment.TickCount;

                string fullAssemblyPath = Path.GetFullPath(
                    Path.Combine(mPathToAssemblies, testInfo.AssemblyName));

                mLog.DebugFormat("Loading test assembly from {0}", fullAssemblyPath);

                testAssemblyLoaded = MakeTest(result, fullAssemblyPath);

                mLog.DebugFormat("Load test assembly {0} ms", Environment.TickCount - ini);
            }
            else
            {
                //if (!AssemblyPreload.CanUsePreload(testInfo.AssemblyName))
                //{
                //    throw new Exception(
                //        "The preloaded and the target assembly don't match!!");
                //}

                result             = mPreloader.TestRunner;
                testAssemblyLoaded = mPreloader.TestAssemblyLoaded;
            }

            if (!testAssemblyLoaded)
            {
                mLog.InfoFormat("Unable to load test assembly {0} for test {1}",
                                testInfo.AssemblyName,
                                testInfo.TestName);

                PNUnitTestResult testResult = BuildError(
                    testInfo, new Exception("Unable to locate tests"),
                    consoleAccess, testLogInfo);

                services.NotifyResult(
                    testInfo.TestName, testResult);

                return(null);
            }

            mLog.Debug("Test loaded, going to set CurrentDirectory");

            Directory.SetCurrentDirectory(mPathToAssemblies);

            mLog.Debug("Creating PNUnit services");

            CreatePNUnitServices(testInfo, result, services, consoleAccess,
                                 testLogInfo, extraConsoleAccess);

            return(result);
        }
Beispiel #25
0
        private void ThreadProc()
        {
            log.DebugFormat(
                "Thread created for TestGroup {0} with {1} tests",
                mTestGroup.Name, mTestGroup.Tests.Length);

            mFinish          = new ManualResetEvent(false);
            mBarriers        = new Hashtable();
            mBarriersOfTests = new Hashtable();
            init             = false;
            RemotingServices.Marshal(this, mTestGroup.Name);

            mLaunchedTests = 0;
            foreach (TestConf test in mTestGroup.Tests)
            {
                if (test.Machine.StartsWith(agentkey))
                {
                    test.Machine = mTestGroup.Agents[int.Parse(test.Machine.Substring(agentkey.Length))];
                }

                Launcher.Log(string.Format("Starting {0} test {1} on {2}",
                                           mTestGroup.Name, test.Name, test.Machine));
                // contact the machine
                try
                {
                    IPNUnitAgent agent = (IPNUnitAgent)
                                         Activator.GetObject(
                        typeof(IPNUnitAgent),
                        string.Format(
                            "tcp://{0}/{1}",
                            test.Machine,
                            PNUnit.Framework.Names.PNUnitAgentServiceName));

                    lock ( mResultLock )
                    {
                        ++mLaunchedTests;
                    }

                    PNUnitTestInfo testToRun = new PNUnitTestInfo(
                        test.Name, test.Assembly, test.TestToRun,
                        test.TestParams, this, test.StartBarrier,
                        test.EndBarrier, test.WaitBarriers);

                    testToRun.UserValues = mUserValues;

                    agent.RunTest(testToRun);
                }
                catch (Exception e)
                {
                    Launcher.LogError(string.Format(
                                          "An error occurred trying to contact {0} [{1}]",
                                          test.Machine, e.Message));

                    lock ( mResultLock )
                    {
                        --mLaunchedTests;
                    }
                }
            }

            log.DebugFormat("Thread going to wait for results for TestGroup {0}", mTestGroup.Name);
            if (HasToWait())
            {
                // wait for all tests to end
                mFinish.WaitOne();
            }

            log.DebugFormat("Thread going to wait for NotifyResult to finish for TestGroup {0}", mTestGroup.Name);
            Thread.Sleep(500); // wait for the NotifyResult call to finish
            RemotingServices.Disconnect(this);
            log.DebugFormat("Thread going to finish for TestGroup {0}", mTestGroup.Name);
        }
Beispiel #26
0
        public void Run(
            PNUnitTestInfo testInfo,
            IPNUnitServices services,
            ITestConsoleAccess extraConsoleAccess)
        {
            try
            {
                TestResult result = null;

                TestRunner testRunner = null;

                TestConsoleAccess consoleAccess = new TestConsoleAccess(testInfo.OutputFile);

                TestLogInfo testLogInfo = new TestLogInfo();

                try
                {
                    mLog.DebugFormat("Running test {0}:{1} Assembly {2}",
                                     testInfo.TestName,
                                     testInfo.TestToRun,
                                     testInfo.AssemblyName);

                    ConsoleWriter outStream   = new ConsoleWriter(Console.Out);
                    ConsoleWriter errorStream = new ConsoleWriter(Console.Error);

                    testRunner = SetupTest(testInfo, services, consoleAccess,
                                           testLogInfo, extraConsoleAccess);

                    if (testRunner == null)
                    {
                        return;
                    }

                    mLog.DebugFormat("RunTest {0}", testInfo.TestName);

                    PrintSeparator();

                    try
                    {
                        result = RunTest(testInfo, outStream, testRunner);
                    }
                    catch (Exception e)
                    {
                        mLog.ErrorFormat("Error running test {0}. {1}", testInfo.TestName, e.Message);
                        mLog.Debug(e.StackTrace);

                        result = BuildError(testInfo, e, consoleAccess, testLogInfo);
                    }
                }
                catch (Exception e)
                {
                    mLog.ErrorFormat("Error launching tests: {0}", e.Message);
                    mLog.Debug(e.StackTrace);

                    result = BuildError(testInfo,
                                        e, consoleAccess, testLogInfo);
                }
                finally
                {
                    mLog.InfoFormat("Notifying the results {0}",
                                    testInfo.TestName);

                    PNUnitTestResult pnunitResult = BuildResult(
                        testInfo,
                        result, consoleAccess, testLogInfo);

                    mLog.DebugFormat("Result built!! Now, notify the launcher ... {0}",
                                     testInfo.TestName);

                    try
                    {
                        services.NotifyResult(
                            testInfo.TestName, pnunitResult);
                        mLog.DebugFormat("<-Results NOTIFIED - {0}",
                                         testInfo.TestName);
                    }
                    catch (Exception e)
                    {
                        mLog.ErrorFormat(
                            "Error notifying back the result of test {0}. {1}",
                            testInfo.TestName, e.Message);
                        mLog.Error(
                            "If you're using a custom launcher.remoting.conf" +
                            " check that you've defined the binaryFormatter");
                    }

                    result = null;

                    UnloadTests(testRunner);
                }
            }
            catch (Exception ex)
            {
                mLog.ErrorFormat("Error running test {0} {1}",
                                 testInfo.TestName, ex.Message);
                mLog.Debug(ex.StackTrace);
            }
        }
 public PNUnitTestRunner(PNUnitTestInfo info, AgentConfig config)
 {
     mConfig         = config;
     mPNUnitTestInfo = info;
 }
Beispiel #28
0
 internal RunningTest(Process p, PNUnitTestInfo info)
 {
     TestProcess = p;
     TestInfo    = info;
 }