예제 #1
0
#pragma warning restore SYSLIB0012

    /// <summary>
    /// Attempts to load an assembly w/ a simple name, looking in the given paths if a normal load fails
    /// </summary>
    /// <param name="assemblyName">The assembly name to load</param>
    /// <param name="paths">paths to look in if the initial load fails</param>
    public void Load(string assemblyName, string[] paths
#if !PROJECTK_BUILD
                     , ReliabilityFramework rf
#endif
                     )
    {
#if !PROJECTK_BUILD
        myRf = rf;

        AssemblyName an = new AssemblyName(assemblyName);
        assembly = assemblyName;
#endif
        try
        {
#if !PROJECTK_BUILD
            assem = Assembly.Load(an);
#else
            LoadFrom(assemblyName + ".dll", paths);
#endif
        }
        catch
        {
            Console.WriteLine("Load failed for: {0}", assemblyName);

#if !PROJECTK_BUILD
            LoadFrom(assemblyName, paths, rf);  // couldn't load the assembly, try doing a LoadFrom with paths.
#endif
        }
    }
예제 #2
0
    /// <summary>
    /// Executes a LoadFrom in the app domain LoaderClass has been loaded into.  Attempts to load a given assembly, looking in the
    /// given paths & the current directory.
    /// </summary>
    /// <param name="path">The assembly to load</param>
    /// <param name="paths">Paths to search for the given assembly</param>
    public void LoadFrom(string path, string[] paths, ReliabilityFramework rf)
    {
        myRf = rf;

        AssemblyName an = new AssemblyName();

        an.CodeBase = assembly = path;

        //register AssemblyLoad and DomainUnload events
        AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(this.UnloadOnAssemblyLoad);
        AppDomain.CurrentDomain.DomainUnload += new EventHandler(this.UnloadOnDomainUnload);

        try
        {
            assem = Assembly.Load(an);
        }
        catch
        {
            try
            {
                FileInfo fi = new FileInfo(path);

                an          = new AssemblyName();
                an.CodeBase = assembly = fi.FullName;

                assem = Assembly.Load(an);
            }
            catch
            {
                if (paths != null)
                {
                    foreach (string basePath in paths)
                    {
                        try
                        {
                            an          = new AssemblyName();
                            an.CodeBase = assembly = ReliabilityConfig.ConvertPotentiallyRelativeFilenameToFullPath(basePath, path);

                            assem = Assembly.Load(an);
                        }
                        catch
                        {
                            continue;
                        }
                        break;
                    }
                }
            }
        }
    }
예제 #3
0
    /// <summary>
    /// Executes a LoadFrom in the app domain LoaderClass has been loaded into.  Attempts to load a given assembly, looking in the
    /// given paths & the current directory.
    /// </summary>
    /// <param name="path">The assembly to load</param>
    /// <param name="paths">Paths to search for the given assembly</param>
    public void LoadFrom(string path, string[] paths, ReliabilityFramework rf)
    {
        myRf = rf;

        AssemblyName an = new AssemblyName();
        an.CodeBase = assembly = path;

        //register AssemblyLoad and DomainUnload events
        AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(this.UnloadOnAssemblyLoad);
        AppDomain.CurrentDomain.DomainUnload += new EventHandler(this.UnloadOnDomainUnload);

        try
        {
            assem = Assembly.Load(an);
        }
        catch
        {
            try
            {
                FileInfo fi = new FileInfo(path);

                an = new AssemblyName();
                an.CodeBase = assembly = fi.FullName;

                assem = Assembly.Load(an);
            }
            catch
            {
                if (paths != null)
                {
                    foreach (string basePath in paths)
                    {
                        try
                        {
                            an = new AssemblyName();
                            an.CodeBase = assembly = ReliabilityConfig.ConvertPotentiallyRelativeFilenameToFullPath(basePath, path);

                            assem = Assembly.Load(an);
                        }
                        catch
                        {
                            continue;
                        }
                        break;
                    }
                }
            }
        }
    }
예제 #4
0
    /// <summary>
    /// Attempts to load an assembly w/ a simple name, looking in the given paths if a normal load fails
    /// </summary>
    /// <param name="assemblyName">The assembly name to load</param>
    /// <param name="paths">paths to look in if the initial load fails</param>
    public void Load(string assemblyName, string[] paths, ReliabilityFramework rf)
    {
        myRf = rf;

        AssemblyName an = new AssemblyName(assemblyName);

        assembly = assemblyName;

        try
        {
            assem = Assembly.Load(an);
        }
        catch
        {
            Console.WriteLine("Load failed for: {0}", assemblyName);
            LoadFrom(assemblyName, paths, rf);  // couldn't load the assembly, try doing a LoadFrom with paths.
        }
    }
예제 #5
0
#pragma warning disable SYSLIB0012 // Assembly.CodeBase is obsolete

    /// <summary>
    /// Executes a LoadFrom in the app domain LoaderClass has been loaded into.  Attempts to load a given assembly, looking in the
    /// given paths & the current directory.
    /// </summary>
    /// <param name="path">The assembly to load</param>
    /// <param name="paths">Paths to search for the given assembly</param>
    public void LoadFrom(string path, string[] paths
#if !PROJECTK_BUILD
                         , ReliabilityFramework rf
#endif
                         )
    {
#if !PROJECTK_BUILD
        myRf = rf;

        AssemblyName an = new AssemblyName();
        an.CodeBase = assembly = path;

        //register AssemblyLoad and DomainUnload events
        AppDomain.CurrentDomain.AssemblyLoad += new AssemblyLoadEventHandler(this.UnloadOnAssemblyLoad);
        AppDomain.CurrentDomain.DomainUnload += new EventHandler(this.UnloadOnDomainUnload);
#else
        AssemblyLoadContext alc = AssemblyLoadContext.GetLoadContext(Assembly.GetExecutingAssembly());
#endif
        try
        {
#if !PROJECTK_BUILD
            assem = Assembly.Load(an);
#else
            assembly = path;
            assem    = alc.LoadFromAssemblyPath(assembly);
#endif
        }
        catch
        {
            try
            {
                FileInfo fi = new FileInfo(path);
                assembly = fi.FullName;
#if !PROJECTK_BUILD
                an          = new AssemblyName();
                an.CodeBase = assembly;

                assem = Assembly.Load(an);
#else
                assem = alc.LoadFromAssemblyPath(assembly);
#endif
            }
            catch
            {
                if (paths != null)
                {
                    foreach (string basePath in paths)
                    {
                        try
                        {
                            assembly = ReliabilityConfig.ConvertPotentiallyRelativeFilenameToFullPath(basePath, path);
#if !PROJECTK_BUILD
                            an          = new AssemblyName();
                            an.CodeBase = assembly;

                            assem = Assembly.Load(an);
#else
                            assem = alc.LoadFromAssemblyPath(assembly);
#endif
                            break;
                        }
                        catch
                        {
                        }
                    }
                }
            }
        }
    }
예제 #6
0
    private void LogWorker()
    {
        while (true)
        {
            bool cachedCloseLogFile = _closeLogFile; // The CloseLog method will set closeLogFile to true indicating we should close the log file
                                                     // This value is cached here so we can write all of the remaining messages to log before closing it
            int messageQueueCount         = _messageQueue.Count;
            int instrumentationQueueCount = _instrumentationMessageQueue.Count;

            if (_logFile != null && messageQueueCount > 0)
            {
                try
                {
                    string text;
                    for (int i = messageQueueCount; i > 0; i--)
                    {
                        try
                        {
                            lock (_messageQueue)
                            {
                                text = _messageQueue.Dequeue();
                            }
                        }
                        catch (InvalidOperationException) { text = null; }

                        if (!String.IsNullOrEmpty(text))
                        {
                            _logFile.Write(_encoding.GetBytes(text), 0, text.Length);
                            text = null;
                        }
                    }
                    _logFile.Flush();
                }
                catch (IOException e)
                {
                    ReliabilityFramework.MyDebugBreak(String.Format("LogWorker IOException:{0}", e.ToString()));
                    //Disk may be full so simply stop logging
                }
            }


            if (cachedCloseLogFile)
            {
                if (null != _logFile)
                {
#if !PROJECTK_BUILD
                    logFile.Close();
#endif
                    _logFile = null;
                }
                _closeLogFile = false;
            }

            if (_instrumentationLogFile != null && instrumentationQueueCount > 0)
            {
                try
                {
                    string text;
                    for (int i = instrumentationQueueCount; i > 0; i--)
                    {
                        try
                        {
                            lock (_instrumentationMessageQueue)
                            {
                                text = _instrumentationMessageQueue.Dequeue();
                            }
                        }
                        catch (InvalidOperationException) { text = null; }

                        if (!String.IsNullOrEmpty(text))
                        {
                            _instrumentationLogFile.Write(_encoding.GetBytes(text), 0, text.Length);
                            text = null;
                        }
                    }
                    _instrumentationLogFile.Flush();
                }
                catch (IOException e)
                {
                    ReliabilityFramework.MyDebugBreak(String.Format("LogWorker IOException:{0}", e.ToString()));
                }
            }
        }
    }
예제 #7
0
    /// <summary>
    /// Our main execution routine for the reliability framework.  Here we create an instance of the framework & run the reliability tests
    /// in it.  All code in here will execute in our starting app domain.
    /// </summary>
    /// <param name="args">command line arguments.  First argument should be the config file we use for this run</param>
    /// <returns>Returns 100 on success, something else on failure</returns>
    public static int Main(string[] args)
    {
        string configFile = null;
        bool okToContinue = true, doReplay = false;
        string sTests = "tests", sSeed = "seed";

        ReliabilityFramework rf = new ReliabilityFramework();
        rf._logger.WriteToInstrumentationLog(null, LoggingLevels.StartupShutdown, "Started");
#if !PROJECTK_BUILD
        Thread.CurrentThread.Priority = ThreadPriority.Highest;
#endif 
        foreach (string arg in args)
        {
            rf._logger.WriteToInstrumentationLog(null, LoggingLevels.StartupShutdown, String.Format("Argument: {0}", arg));
            if (arg[0] == '/' || arg[0] == '-')
            {
                if (String.Compare(arg.Substring(1), "replay", true) == 0)
                {
                    doReplay = true;
                }
                else if (String.Compare(arg.Substring(1, arg.IndexOf(':') - 1), sTests, true) == 0)
                {
                    String testlist = arg.Substring(sTests.Length + 2);
                    String[] tests;
                    tests = testlist.Split(',');
                }
                else if (String.Compare(arg.Substring(1, arg.IndexOf(':') - 1), sSeed, true) == 0)
                {
                    s_seed = Convert.ToInt32(arg.Substring(sSeed.Length + 2));
                    s_randNum = new Random(s_seed);
                }
                else
                {
                    Console.WriteLine("Unknown option: {0}", arg);
                    okToContinue = false;
                }
            }
            else if (configFile == null)
            {
                configFile = arg;
            }
        }
        if (configFile == null)
        {
            okToContinue = false;
            Console.WriteLine("You must specify a config file!");
            rf._logger.WriteToInstrumentationLog(null, LoggingLevels.StartupShutdown, "No configuration file specified.");
        }
        if (!okToContinue)
        {
            Console.WriteLine("\r\nWhidbey Host Interface Reliability Harness\r\n");
            Console.WriteLine("Usage: ReliabiltityFramework [options] <test config file>");
            Console.WriteLine("");
            Console.WriteLine("Available options: ");
            Console.WriteLine("");
            Console.WriteLine(" /replay     -   Replay from log file");
            Console.WriteLine(" /{0}:<tests>	-	Comma delimited list of tests to run (no spaces)", sTests);
            Console.WriteLine(" /{0}:<seed>	-	Random Number seed for replays", sSeed);
            rf._logger.WriteToInstrumentationLog(null, LoggingLevels.StartupShutdown, "Not ok to continue.");

#if PROJECTK_BUILD
            return 0;
#else
            Environment.Exit(0);
#endif 
        }

        int retVal = -1;
        try
        {
            try
            {
                rf._logger.WriteToInstrumentationLog(null, LoggingLevels.Tests, "Running tests...");
                retVal = rf.RunReliabilityTests(configFile, doReplay);
                rf._logger.WriteToInstrumentationLog(null, LoggingLevels.Tests, String.Format("Successfully executed tests, return val: {0}", retVal));
            }
            catch (OutOfMemoryException e)
            {
                rf.HandleOom(e, "Running tests");
            }
            catch (Exception e)
            {
                Exception eTemp = e.InnerException;
                while (eTemp != null)
                {
                    if (eTemp is OutOfMemoryException)
                    {
                        rf.HandleOom(e, "Running tests (inner)");
                        break;
                    }

                    eTemp = e.InnerException;
                }
                if (eTemp == null)
                {
                    rf._logger.WriteToInstrumentationLog(null, LoggingLevels.Tests, String.Format("Exception while running tests: {0}", e));
                    Console.WriteLine("There was an exception while attempting to run the tests: See Instrumentation Log for details");
                }
            }
        }
        finally
        {
            rf._logger.WriteToInstrumentationLog(null, LoggingLevels.StartupShutdown, "Reliability framework is shutting down...");
        }

        NoExitPoll();

        rf._logger.WriteToInstrumentationLog(null, LoggingLevels.StartupShutdown, String.Format("Shutdown w/ ret val of  {0}", retVal));


        GC.Collect(2);
        GC.WaitForPendingFinalizers();
        return (retVal);
    }
예제 #8
0
    /// <summary>
    /// Attempts to load an assembly w/ a simple name, looking in the given paths if a normal load fails
    /// </summary>
    /// <param name="assemblyName">The assembly name to load</param>
    /// <param name="paths">paths to look in if the initial load fails</param>
    public void Load(string assemblyName, string[] paths, ReliabilityFramework rf)
    {
        myRf = rf;

        AssemblyName an = new AssemblyName(assemblyName);
        assembly = assemblyName;

        try
        {
            assem = Assembly.Load(an);
        }
        catch
        {
            Console.WriteLine("Load failed for: {0}", assemblyName);
            LoadFrom(assemblyName, paths, rf);	// couldn't load the assembly, try doing a LoadFrom with paths.

        }
    }