示例#1
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);
            }
        }
示例#2
0
        private void CreatePNUnitServices(
            TestDomain testDomain,
            TestConsoleAccess consoleAccess)
        {
            log.Info("Creating PNUnitServices in the AppDomain of the test");

            object[] param = { mPNUnitTestInfo, consoleAccess };

            try
            {
                System.Runtime.Remoting.ObjectHandle obj
#if NET_2_0
                    = Activator.CreateInstance(
                          testDomain.AppDomain,
#else
                    = testDomain.AppDomain.CreateInstance(
#endif
                          typeof(PNUnitServices).Assembly.FullName,
                          typeof(PNUnitServices).FullName,
                          false, BindingFlags.Default, null, param, null, null, null);
                obj.Unwrap();
            }
            catch (Exception e)
            {
                BuildError(e, consoleAccess);
                log.ErrorFormat("Error running test {0}", e.Message);
                return;
            }
        }
示例#3
0
        private TestDomain SetupTest(TestConsoleAccess consoleAccess)
        {
            try
            {
                TestDomain result;

                lock (mFreeDomains.SyncRoot)
                {
                    log.Debug(">Locking mFreeDomains.SyncRoot");

                    if (mbUseDomainPool && mFreeDomains.Count > 0)
                    {
                        log.Debug("Reusing a previously created TestDomain");
                        result = mFreeDomains.Dequeue() as TestDomain;
                        CreatePNUnitServices(result, consoleAccess);
                        return(result);
                    }

                    log.Debug("Creating a new TestDomain");
                    result = new TestDomain();

                    bool testLoaded = MakeTest(
                        result,
                        Path.Combine(mConfig.PathToAssemblies, mPNUnitTestInfo.AssemblyName),
                        GetShadowCopyCacheConfig());

                    log.Debug("MakeTest executed");

                    if (!testLoaded)
                    {
                        log.InfoFormat("Unable to locate test {0}", mPNUnitTestInfo.TestName);
                        TestResult testResult = BuildError("Unable to locate tests", consoleAccess);

                        mPNUnitTestInfo.Services.NotifyResult(
                            mPNUnitTestInfo.TestName, testResult);

                        return(null);
                    }

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

                    Directory.SetCurrentDirectory(mConfig.PathToAssemblies); // test directory ?

                    log.Debug("Creating PNUnit services");

                    CreatePNUnitServices(result, consoleAccess);

                    return(result);
                }
            }
            finally
            {
                log.Debug("<Unlocking mFreeDomains.SyncRoot");
            }
        }
 private TestResult BuildResult(TestResult result, TestConsoleAccess consoleAccess)
 {
     if (!result.IsSuccess)
     {
         return(new PNUnitTestResult(result, consoleAccess.GetTestOutput()));
     }
     else
     {
         return(result);
     }
 }
示例#5
0
        private TestResult BuildError(Exception e, TestConsoleAccess consoleAccess)
        {
            TestName testName = new TestName();
            testName.Name = mPNUnitTestInfo.TestName;
            testName.FullName = mPNUnitTestInfo.TestName;
            testName.TestID = new TestID();

            TestResult result = new PNUnitTestResult(testName, consoleAccess.GetTestOutput());
            result.Error(e);
            return result;
        }
示例#6
0
        private TestResult BuildError(Exception e, TestConsoleAccess consoleAccess)
        {
            TestName testName = new TestName();

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

            TestResult result = new PNUnitTestResult(testName, consoleAccess.GetTestOutput());

            result.Error(e);
            return(result);
        }
示例#7
0
        private TestResult BuildError(string message, TestConsoleAccess consoleAccess)
        {
            TestName testName = new TestName();

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

            TestResult result = new PNUnitTestResult(testName, consoleAccess.GetTestOutput());

            result.Failure(message, string.Empty);
            return(result);
        }
        private void ThreadProc()
        {
            TestResult result = null;
            TestDomain testDomain = new TestDomain();

            TestConsoleAccess consoleAccess = new TestConsoleAccess();

            try
            {
                log.InfoFormat("Thread entered for Test {0}:{1} Assembly {2}",
                    mPNUnitTestInfo.TestName, mPNUnitTestInfo.TestToRun, mPNUnitTestInfo.AssemblyName);

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

                bool testLoaded = MakeTest(testDomain, Path.Combine(mConfig.PathToAssemblies, mPNUnitTestInfo.AssemblyName), GetShadowCopyCacheConfig());

                if (!testLoaded)
                {
                    log.InfoFormat("Unable to locate test {0}", mPNUnitTestInfo.TestName);
                    result = BuildError("Unable to locate tests", consoleAccess);

                    mPNUnitTestInfo.Services.NotifyResult(
                        mPNUnitTestInfo.TestName, result);

                    return;
                }

                Directory.SetCurrentDirectory(mConfig.PathToAssemblies); // test directory ?
                EventListener collector = new EventCollector( outStream );

                string savedDirectory = Environment.CurrentDirectory;

                log.Info("Creating PNUnitServices in the AppDomain of the test");

                object[] param = { mPNUnitTestInfo, (ITestConsoleAccess) consoleAccess };

                try
                {
                    System.Runtime.Remoting.ObjectHandle obj
            #if NET_2_0
                        = Activator.CreateInstance(
                            testDomain.AppDomain,
            #else

                        = testDomain.AppDomain.CreateInstance(
            #endif
                        typeof(PNUnitServices).Assembly.FullName,
                        typeof(PNUnitServices).FullName,
                        false, BindingFlags.Default, null, param, null, null, null);
                    obj.Unwrap();
                }
                catch( Exception e )
                {
                    result = BuildError(e, consoleAccess);
                    log.ErrorFormat("Error running test {0}", e.Message);
                    return;
                }

                log.Info("Running tests");

                try
                {
                    ITestFilter filter = new NUnit.Core.Filters.SimpleNameFilter(mPNUnitTestInfo.TestToRun);
                    result =
                        FindResult(
                            mPNUnitTestInfo.TestToRun,
                            testDomain.Run(collector, filter) );
                    filter = null;
                }
                catch( Exception e )
                {
                    result = BuildError(e, consoleAccess);
                    log.ErrorFormat("Error running test {0}", e.Message);
                }

            }
            finally
            {
                log.Info("Notifying the results");

                mPNUnitTestInfo.Services.NotifyResult(
                    mPNUnitTestInfo.TestName, BuildResult(result, consoleAccess));

                result = null;

                //Bug with framework
                if( IsWindows() )
                {
            #if !NET_2_0
                    lock(obj)
            #endif
                    {
                        testDomain.Unload();
                    }
                }
            }
        }
 private TestResult BuildResult(TestResult result, TestConsoleAccess consoleAccess)
 {
     if (!result.IsSuccess)
     {
         return new PNUnitTestResult(result, consoleAccess.GetTestOutput());
     }
     else
         return result;
 }
示例#10
0
        private TestDomain SetupTest(TestConsoleAccess consoleAccess)
        {
            try
            {
                TestDomain result;

                lock( mFreeDomains.SyncRoot )
                {
                    log.Debug(">Locking mFreeDomains.SyncRoot");

                    if( mbUseDomainPool && mFreeDomains.Count > 0 )
                    {
                        log.Debug("Reusing a previously created TestDomain");
                        result = mFreeDomains.Dequeue() as TestDomain;
                        CreatePNUnitServices(result, consoleAccess);
                        return result;
                    }

                    log.Debug("Creating a new TestDomain");
                    result = new TestDomain();

                    bool testLoaded = MakeTest(
                        result,
                        Path.Combine(mConfig.PathToAssemblies, mPNUnitTestInfo.AssemblyName),
                        GetShadowCopyCacheConfig());

                    log.Debug("MakeTest executed");

                    if( !testLoaded )
                    {
                        log.InfoFormat("Unable to locate test {0}", mPNUnitTestInfo.TestName);
                        TestResult testResult = BuildError("Unable to locate tests", consoleAccess);

                        mPNUnitTestInfo.Services.NotifyResult(
                            mPNUnitTestInfo.TestName, testResult);

                        return null;
                    }

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

                    Directory.SetCurrentDirectory(mConfig.PathToAssemblies); // test directory ?

                    log.Debug("Creating PNUnit services");

                    CreatePNUnitServices(result, consoleAccess);

                    return result;
                }
            }
            finally
            {
                log.Debug("<Unlocking mFreeDomains.SyncRoot");
            }
        }
示例#11
0
        internal void Run(PNUnitAgent.TestCounter testCounter)
        {
            string line;

            while ((line = Console.ReadLine()) != "")
            {
                switch (line)
                {
                case "help":
                    Console.WriteLine("Available commands:");
                    Console.WriteLine("\tgc: run the garbage collector");
                    Console.WriteLine("\tcollect: run a collect");
                    Console.WriteLine("\ttestcount: shows the number of tests launched");
                    Console.WriteLine("\tgcinfo: info about the garbage collector");
                    Console.WriteLine("\tprocinfo: info about the process");
                    Console.WriteLine("\tdisableconsole: turns off test output" +
                                      " on the console (tests continues executing)");
                    Console.WriteLine("\tenableconsole: turns on test" +
                                      " output on the console (default)");
                    Console.WriteLine("\tdisableoutput: turns off saving " +
                                      "test output to a buffer to be sent back to the" +
                                      " launcher (saves memory)");
                    Console.WriteLine("\tenableoutput: turns on saving" +
                                      " output to a buffer to be returned to the launcher" +
                                      " (default)");
                    break;

                case "gc":
                    Console.WriteLine("Cleaning up memory {0} Mb",
                                      GC.GetTotalMemory(true) / 1024 / 1024);
                    break;

                case "collect":
                    Console.WriteLine("Collecting memory {0} Mb",
                                      GC.GetTotalMemory(false) / 1024 / 1024);
                    GC.Collect();
                    Console.WriteLine("Memory collected {0} Mb",
                                      GC.GetTotalMemory(false) / 1024 / 1024);
                    break;

                case "testcount":
                    Console.WriteLine("{0} tests launched", testCounter.Get());
                    break;

                case "gcinfo":
                        #if NET_2_0
                    Console.WriteLine("{0, -10}\t{1,16}", "Generation", "Collection count");
                    Console.WriteLine("==========\t================");
                    Console.WriteLine("{0, -10}\t{1,16}", 0, GC.CollectionCount(0));
                    Console.WriteLine("{0, -10}\t{1,16}", 1, GC.CollectionCount(1));
                    Console.WriteLine("{0, -10}\t{1,16}", 2, GC.CollectionCount(2));
                        #endif
                    Console.WriteLine("\nTotal memory {0:0,0.00} Mb",
                                      (float)GC.GetTotalMemory(false) / 1024f / 1024f);
                    break;

                case "procinfo":
                    System.Diagnostics.Process p = System.Diagnostics.Process.GetCurrentProcess();

                    Console.WriteLine("{0, -25}\t{1,20}", "Entry", "Value");
                    Console.WriteLine("========================\t=======================");
                    Console.WriteLine("{0, -25}\t{1,20}", "Proc Id", p.Id);
                    Console.WriteLine("{0, -25}\t{1,20}", "Handle count", p.HandleCount);
                    Console.WriteLine("{0, -25}\t{1,20}", "Thread count", p.Threads.Count);
                        #if NET_2_0
                    Console.WriteLine("{0, -25}\t{1,20:0,0.00} Mb", "Non paged system mem",
                                      GetMb(p.NonpagedSystemMemorySize64));
                    Console.WriteLine("{0, -25}\t{1,20:0,0.00} Mb", "Paged mem size",
                                      GetMb(p.PagedMemorySize64));
                    Console.WriteLine("{0, -25}\t{1,20:0,0.00} Mb", "Paged system mem size",
                                      GetMb(p.PagedSystemMemorySize64));
                    Console.WriteLine("{0, -25}\t{1,20:0,0.00} Mb", "Peak paged mem size",
                                      GetMb(p.PeakPagedMemorySize64));
                    Console.WriteLine("{0, -25}\t{1,20:0,0.00} Mb", "Peak virtual mem size",
                                      GetMb(p.PeakVirtualMemorySize64));
                    Console.WriteLine("{0, -25}\t{1,20:0,0.00} Mb", "Peak working set",
                                      GetMb(p.PeakWorkingSet64));
                    Console.WriteLine("{0, -25}\t{1,20:0,0.00} Mb", "Private mem size",
                                      GetMb(p.PrivateMemorySize64));
                    Console.WriteLine("{0, -25}\t{1,20:0,0.00} Mb", "Virtual mem size",
                                      GetMb(p.VirtualMemorySize64));
                    Console.WriteLine("{0, -25}\t{1,20:0,0.00} Mb", "Working set",
                                      GetMb(p.WorkingSet64));
                        #endif
                    Console.WriteLine("{0, -25}\t{1,20}", "Start time", p.StartTime);
                    Console.WriteLine("{0, -25}\t{1,20}", "Privileged proc time", p.PrivilegedProcessorTime);
                    Console.WriteLine("{0, -25}\t{1,20}", "User proc time", p.UserProcessorTime);
                    Console.WriteLine("{0, -25}\t{1,20}", "Total proc time", p.TotalProcessorTime);
                    p.Close();
                    break;

                case "disableconsole":
                    TestConsoleAccess.DisableConsole();
                    break;

                case "enableconsole":
                    TestConsoleAccess.EnableConsole();
                    break;

                case "disableoutput":
                    TestConsoleAccess.DisableStoreOutput();
                    break;

                case "enableoutput":
                    TestConsoleAccess.EnableStoreOutput();
                    break;
                }
            }
        }
        private void ThreadProc()
        {
            TestResult result     = null;
            TestDomain testDomain = new TestDomain();

            TestConsoleAccess consoleAccess = new TestConsoleAccess();

            try
            {
                log.InfoFormat("Thread entered for Test {0}:{1} Assembly {2}",
                               mPNUnitTestInfo.TestName, mPNUnitTestInfo.TestToRun, mPNUnitTestInfo.AssemblyName);

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

                bool testLoaded = MakeTest(testDomain, Path.Combine(mConfig.PathToAssemblies, mPNUnitTestInfo.AssemblyName), GetShadowCopyCacheConfig());

                if (!testLoaded)
                {
                    log.InfoFormat("Unable to locate test {0}", mPNUnitTestInfo.TestName);
                    result = BuildError("Unable to locate tests", consoleAccess);

                    mPNUnitTestInfo.Services.NotifyResult(
                        mPNUnitTestInfo.TestName, result);

                    return;
                }

                Directory.SetCurrentDirectory(mConfig.PathToAssemblies); // test directory ?
                EventListener collector = new EventCollector(outStream);

                string savedDirectory = Environment.CurrentDirectory;

                log.Info("Creating PNUnitServices in the AppDomain of the test");

                object[] param = { mPNUnitTestInfo, (ITestConsoleAccess)consoleAccess };

                try
                {
                    System.Runtime.Remoting.ObjectHandle obj
#if NET_2_0
                        = Activator.CreateInstance(
                              testDomain.AppDomain,
#else
                        = testDomain.AppDomain.CreateInstance(
#endif
                              typeof(PNUnitServices).Assembly.FullName,
                              typeof(PNUnitServices).FullName,
                              false, BindingFlags.Default, null, param, null, null, null);
                    obj.Unwrap();
                }
                catch (Exception e)
                {
                    result = BuildError(e, consoleAccess);
                    log.ErrorFormat("Error running test {0}", e.Message);
                    return;
                }

                log.Info("Running tests");

                try
                {
                    ITestFilter filter = new NUnit.Core.Filters.SimpleNameFilter(mPNUnitTestInfo.TestToRun);
                    result             =
                        FindResult(
                            mPNUnitTestInfo.TestToRun,
                            testDomain.Run(collector, filter));
                    filter = null;
                }
                catch (Exception e)
                {
                    result = BuildError(e, consoleAccess);
                    log.ErrorFormat("Error running test {0}", e.Message);
                }
            }
            finally
            {
                log.Info("Notifying the results");

                mPNUnitTestInfo.Services.NotifyResult(
                    mPNUnitTestInfo.TestName, BuildResult(result, consoleAccess));

                result = null;

                //Bug with framework
                if (IsWindows())
                {
#if !NET_2_0
                    lock (obj)
#endif
                    {
                        testDomain.Unload();
                    }
                }
            }
        }
示例#13
0
        private void ThreadProc()
        {
            TestResult result = null;

            TestDomain testDomain = null;

            TestConsoleAccess consoleAccess = new TestConsoleAccess();

            try
            {
                log.DebugFormat("Thread entered for Test {0}:{1} Assembly {2}",
                    mPNUnitTestInfo.TestName,
                    mPNUnitTestInfo.TestToRun,
                    mPNUnitTestInfo.AssemblyName);

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

                testDomain = SetupTest(consoleAccess);

                if( testDomain == null )
                    return;

                log.Debug("Running tests");

                try
                {
                    if(mConfig.NoTimeout)
                    {
                        result = RunTest(outStream, testDomain);
                    }
                    else
                    {
                        RunTestWithTimeoutDelegate deleg = new RunTestWithTimeoutDelegate(
                            RunTest);
                        IAsyncResult ar = deleg.BeginInvoke(outStream, testDomain, null, new object());
                        if (!ar.AsyncWaitHandle.WaitOne(TEST_TIMEOUT, false))
                        {
                            testDomain.CancelRun();
                            throw new Exception("Test timeout exception");
                        }
                        else  
                        {
                            result = deleg.EndInvoke(ar);
                        }
                    }
                }
                catch( Exception e )
                {
                    result = BuildError(e, consoleAccess);
                    log.ErrorFormat("Error running test {0}", e.Message);
                }

            }
            finally
            {
                log.Info("Notifying the results");

                log.Debug("////////////////////////////////////////Notifying the results/////////////////////////");

                mPNUnitTestInfo.Services.NotifyResult(
                    mPNUnitTestInfo.TestName, BuildResult(result, consoleAccess, mPNUnitTestInfo));

                log.Debug("////////////////////////////////////////Results NOTIFIED/////////////////////////");
                result = null;

                ReleaseDomain(testDomain);
            }
        }
示例#14
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;
        }
示例#15
0
        private void CreatePNUnitServices(
            TestDomain testDomain,
            TestConsoleAccess consoleAccess)
        {
            log.Info("Creating PNUnitServices in the AppDomain of the test");

            object[] param = { mPNUnitTestInfo, consoleAccess };

            try
            {
                System.Runtime.Remoting.ObjectHandle obj
#if NET_2_0
                        = Activator.CreateInstance(
                            testDomain.AppDomain,
#else
                    = testDomain.AppDomain.CreateInstance(
#endif
                    typeof(PNUnitServices).Assembly.FullName,
                    typeof(PNUnitServices).FullName,
                    false, BindingFlags.Default, null, param, null, null, null);
                obj.Unwrap();
            }
            catch( Exception e )
            {
                BuildError(e, consoleAccess);
                log.ErrorFormat("Error running test {0}", e.Message);
                return;
            }
        }
示例#16
0
        private void ThreadProc()
        {
            TestResult result = null;

            TestDomain testDomain = null;

            TestConsoleAccess consoleAccess = new TestConsoleAccess();

            try
            {
                log.DebugFormat("Thread entered for Test {0}:{1} Assembly {2}",
                                mPNUnitTestInfo.TestName,
                                mPNUnitTestInfo.TestToRun,
                                mPNUnitTestInfo.AssemblyName);

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

                testDomain = SetupTest(consoleAccess);

                if (testDomain == null)
                {
                    return;
                }

                log.Debug("Running tests");

                try
                {
                    if (mConfig.NoTimeout)
                    {
                        result = RunTest(outStream, testDomain);
                    }
                    else
                    {
                        RunTestWithTimeoutDelegate deleg = new RunTestWithTimeoutDelegate(
                            RunTest);
                        IAsyncResult ar = deleg.BeginInvoke(outStream, testDomain, null, new object());
                        if (!ar.AsyncWaitHandle.WaitOne(TEST_TIMEOUT, false))
                        {
                            testDomain.CancelRun();
                            throw new Exception("Test timeout exception");
                        }
                        else
                        {
                            result = deleg.EndInvoke(ar);
                        }
                    }
                }
                catch (Exception e)
                {
                    result = BuildError(e, consoleAccess);
                    log.ErrorFormat("Error running test {0}", e.Message);
                }
            }
            finally
            {
                log.Info("Notifying the results");

                log.Debug("////////////////////////////////////////Notifying the results/////////////////////////");

                mPNUnitTestInfo.Services.NotifyResult(
                    mPNUnitTestInfo.TestName, BuildResult(result, consoleAccess, mPNUnitTestInfo));

                log.Debug("////////////////////////////////////////Results NOTIFIED/////////////////////////");
                result = null;

                ReleaseDomain(testDomain);
            }
        }
示例#17
0
        private TestResult BuildError(string message, TestConsoleAccess consoleAccess)
        {
            TestName testName = new TestName();
            testName.Name = mPNUnitTestInfo.TestName;
            testName.FullName = mPNUnitTestInfo.TestName;
            testName.TestID = new TestID();

            TestResult result = new PNUnitTestResult(testName, consoleAccess.GetTestOutput());
            result.Failure(message, string.Empty);
            return result;
        }