示例#1
0
 /// <summary>
 /// Adds the elements of another PerfTesterCollection to the end of this PerfTesterCollection.
 /// </summary>
 /// <param name="items">
 /// The PerfTesterCollection whose elements are to be added to the end of this PerfTesterCollection.
 /// </param>
 public virtual void AddRange(PerfTesterCollection items)
 {
     foreach (PerfTester item in items)
     {
         this.List.Add(item);
     }
 }
示例#2
0
 public Enumerator(PerfTesterCollection collection)
 {
     this.wrapped = ((System.Collections.CollectionBase)collection).GetEnumerator();
 }
示例#3
0
 /// <summary>
 /// Initializes a new instance of the PerfTesterCollection class, containing elements
 /// copied from another instance of PerfTesterCollection
 /// </summary>
 /// <param name="items">
 /// The PerfTesterCollection whose elements are to be added to the new PerfTesterCollection.
 /// </param>
 public PerfTesterCollection(PerfTesterCollection items)
 {
     this.AddRange(items);
 }
示例#4
0
        public static void FromAssembly(PerfTesterCollection testers, Assembly a)
        {
            if (testers==null)
                throw new ArgumentNullException("testers");
            if (a==null)
                throw new ArgumentNullException("a");

            foreach(Type t in a.GetExportedTypes())
            {
                if (TypeHelper.HasCustomAttribute(t,typeof(PerfTesterAttribute)))
                {
                    PerfTesterAttribute attr =
                        (PerfTesterAttribute)TypeHelper.GetFirstCustomAttribute(
                        t,
                        typeof(PerfTesterAttribute)
                        );
                    PerfTester tester = new PerfTester(t,attr);

                    testers.Add(tester);
                }
            }
        }
示例#5
0
        public static PerfTesterCollection FromAssembly(Assembly a)
        {
            if (a==null)
                throw new ArgumentNullException("a");
            PerfTesterCollection testers = new PerfTesterCollection();
            FromAssembly(testers,a);

            return testers;
        }
示例#6
0
        public static void FromAssembly(PerfTesterCollection testers, Assembly a)
        {
            Console.WriteLine("FromAssembly enter");
            if (testers==null)
                throw new ArgumentNullException("testers");
            if (a==null)
                throw new ArgumentNullException("a");

            foreach(Type t in a.GetExportedTypes())
            {
                if (TypeHelper.HasCustomAttribute(t, typeof(PerfTesterAttribute)))
                {
                    Console.WriteLine("PerfTesterAttribute {0}", t);
                    PerfTesterAttribute attr =
                        (PerfTesterAttribute)TypeHelper.GetFirstCustomAttribute(
                        t,
                        typeof(PerfTesterAttribute)
                        );
                    Console.WriteLine("PerfTesterAttribute {0}", attr.Description);
                    PerfTester tester = new PerfTester(t, attr);

                    testers.Add(tester);
                }
                else
                    Console.WriteLine("No custom attr");
            }
        }
示例#7
0
        static void Main(string[] args)
        {
            try
            {
                ClArguments cl = new ClArguments();
                cl.AddParameter(new ClParameter("testera","ta","Tester Assembly",false,false));
                cl.AddParameter(new ClParameter("testeda","tdfa","Tested Assembly",false,false));
                cl.AddParameter(new ClParameter("testedapartial","tdfap","Tested Assembly Parital Name",false,false));
                cl.AddParameter(new ClParameter("ignoredtype","it","Ingored types",false,false));
                cl.AddParameter(new ClParameter("verbose","v","Verbose",true,true));
                cl.AddParameter(new ClParameter("outputtype","ot","Output type",true,false));
                cl.AddParameter(new ClParameter("xml","x","Output as XML",true,true));

                cl.Parse(args);
                cl.ProcessHelp();

                // loading testers
                if (!cl.ContainsDuplicate("ta"))
                    throw new Exception("You did not specify a tester assembly");

                // load testers
                PerfTesterCollection testers = new PerfTesterCollection();
                foreach(String name in cl.Duplicates("ta"))
                {
                    Console.WriteLine("Load tester assembly: {0}",name);
                    PerfTester.FromAssembly(
                          testers,
                          Assembly.LoadFrom(name)
                          );
                }
                if (testers.Count == 0)
                    throw new Exception("Could not find any tester class");

                // load tested
                foreach(PerfTester tester in testers)
                {
                    if (tester.IsIgnored)
                        continue;

                    if (cl.ContainsDuplicate("tdfa"))
                    {
                        foreach(String name in cl.Duplicates("tdfa"))
                        {
                            Console.WriteLine("Load tested assembly: {0}",name);
                            tester.LoadTestedTypes(Assembly.LoadFrom(name));
                        }
                    }

                    if (cl.ContainsDuplicate("tdfap"))
                    {
                        foreach(String name in cl.Duplicates("tdfap"))
                        {
                            Console.WriteLine("Load tested assembly: {0}",name);
                            tester.LoadTestedTypes(Assembly.LoadWithPartialName(name));
                        }
                    }

                    Console.WriteLine("Tested types:");
                    foreach(Type t in tester.TestedTypes)
                    {
                        Console.WriteLine("\t{0}",t.Name);
                    }

                    // removing types
                    if (cl.ContainsDuplicate("it"))
                    {
                        foreach(String name in cl.Duplicates("it"))
                        {
                            Console.Write("Ignoring type: <{0}>",name);
                            Type t = Type.GetType(name);
                            if (t==null)
                                Console.WriteLine(" - could not load type.");
                            else
                            {
                                if (tester.TestedTypes.Contains(t))
                                {
                                    Console.WriteLine(" removed");
                                    tester.TestedTypes.Remove(t);
                                }
                                else
                                    Console.WriteLine("-- could not remove {0}",t.Name);
                            }
                        }
                    }
                }

                // run test
                ChartReport chart = new ChartReport(800,400);
                chart.Colors.Map = ColorMap.Jet;
                ImageFormat im = ImageFormat.Png;

                if (cl.ContainsUnique("ot"))
                {
                    switch(cl.Unique("ot").ToLower())
                    {
                    case "png":
                            im = ImageFormat.Png;
                            break;
                    case "gif":
                        im = ImageFormat.Gif;
                        break;
                    case "jpeg":
                        im = ImageFormat.Jpeg;
                        break;
                    case "bmp":
                        im = ImageFormat.Bmp;
                        break;
                    case "emf":
                        im = ImageFormat.Emf;
                        break;
                    }
                }

                foreach(PerfTester tester in testers)
                {
                    if (tester.IsIgnored)
                        continue;

                    TextWriterTracer tracer = new TextWriterTracer();
                    tracer.Attach(tester);

                    PerfTestSuite suite = tester.RunTests();

                    if (cl.ContainsUnique("xml"))
                    {
                        using (FileStream file = File.OpenWrite(tester.TestedType.Name + "." + suite.Name + ".xml"))
                        {
                            StreamWriter writer = new StreamWriter(file);
                            suite.ToXml(writer);
                            writer.Close();
                        }
                    }

                    IDictionary bmps = chart.Render(suite);
                    foreach(DictionaryEntry de in bmps)
                    {
                        PerfTest test = (PerfTest)de.Key;
                        Bitmap bmp = (Bitmap)de.Value;
                        bmp.Save(tester.TestedType.Name + "." + test.Name + "." + im.ToString().ToLower(),im);
                    }
                }
            }
            catch(Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
示例#8
0
 private static void LoadTesters(PerfTesterCollection testers, Assembly testerAssembly)
 {
     Console.WriteLine("Load tester assembly: {0}", testerAssembly.GetName());
     PerfTester.FromAssembly(testers, testerAssembly);
 }
示例#9
0
        private void RunTests(PerfTesterCollection testers, int startValue, int step, int countOfRuns)
        {
            foreach (PerfTester tester in testers)
            {
                tester.IsRunDescriptorValueOveridden = true;
                if (tester.IsIgnored)
                    continue;
                if (startValue > 0)
                    tester.TestStart = startValue;
                if (step > 0)
                    tester.TestStep = step;
                if (countOfRuns > 0)
                    tester.TestCount = countOfRuns;
                tester.ResultsChange += new PerfTester.ResultsChangeHandler(tester_ResultsChange);
                TextWriterTracer tracer = new TextWriterTracer();
                tracer.Attach(tester);

                PerfTestSuite suite = tester.RunTests();
            }
        }
示例#10
0
 private static void LoadTesters(PerfTesterCollection testers, Assembly[] testerAssemblies)
 {
     foreach (Assembly testerAssembly in testerAssemblies)
     {
         LoadTesters(testers, testerAssembly);
     }
 }
示例#11
0
        private static void LoadTestedTypes(Assembly[] testedAssemblies, PerfTesterCollection testers)
        {
            foreach (PerfTester tester in testers)
            {
                tester.IsRunDescriptorValueOveridden = false;
                if (tester.IsIgnored)
                    continue;

                Console.WriteLine("Loading tested types for: {0}", tester.TesterType);

                foreach (Assembly testedAssembly in testedAssemblies)
                {
                    Console.WriteLine("Load tested assembly: {0}", testedAssembly);
                    tester.LoadTestedTypesFromInner(testedAssembly);
                }

                Console.WriteLine("Tested types:");
                Console.WriteLine(tester.TestedTypes.Count + " " + tester.TesterType);
                foreach (Type t in tester.TestedTypes)
                {
                    Console.WriteLine("\t{0}", t.Name);
                }
            }
        }
示例#12
0
        /// <summary>
        /// Gets the report data for test Type.
        /// </summary>
        /// <param name="type">The type of tested object.</param>
        /// <param name="startValue">The start value.</param>
        /// <param name="step">The step.</param>
        /// <param name="countOfRuns">The count of runs.</param>
        /// <returns></returns>
        public void GetReportDataWithType(Type type,int startValue, int step,  int countOfRuns)
        {
            try
            {
                // loading testers
                if (type == null)
                    throw new Exception("You did not specify a tester assembly");

                // load testers from current assembly
                PerfTesterCollection testers = new PerfTesterCollection();
                LoadTesters(testers, Assembly.GetCallingAssembly());

                if (testers.Count == 0)
                    throw new Exception("Could not find any tester class");

                // load tested
                foreach (PerfTester tester in testers)
                {
                    tester.IsRunDescriptorValueOveridden = false;
                    if (tester.IsIgnored)
                        continue;

                    Console.WriteLine("Load tested assembly: {0}", Assembly.GetCallingAssembly().FullName);
                    //Looking inside current
                    tester.LoadTestedTypesFromInner(Assembly.GetCallingAssembly());
                    //Looking inside referenced
                    foreach (var asm in Assembly.GetCallingAssembly().GetReferencedAssemblies())
                    {
                        tester.LoadTestedTypesFromInner(Assembly.Load(asm));
                    }

                    Console.WriteLine("Tested types:");
                    Console.WriteLine(tester.TestedTypes.Count + " " + tester.TesterType);
                    foreach (Type t in tester.TestedTypes)
                    {
                        Console.WriteLine("\t{0}", t.Name);
                    }
                }

                RunTests(testers, startValue, step, countOfRuns);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
示例#13
0
        /// <summary>
        /// Gets the report data for specified assemblies.
        /// </summary>
        /// <param name="testerAssemblies">The assemblies tester types.</param>
        /// <param name="testedAssemblies">The assemblies tested types.</param>
        /// <param name="startValue">The start value.</param>
        /// <param name="step">The step.</param>
        /// <param name="countOfRuns">The count of runs.</param>
        /// <exception cref="System.Exception">You did not specify a tester assembly(s)</exception>
        public void GetReportDataWithAssemblies(Assembly[] testerAssemblies, Assembly[] testedAssemblies, int startValue, int step, int countOfRuns)
        {
            try
            {
                if ((testerAssemblies == null) || (testerAssemblies.Length == 0))
                    throw new Exception("You did not specify a tester assembly(s)");

                if ((testedAssemblies == null) || (testedAssemblies.Length == 0))
                    throw new Exception("You did not specify a tested assembly(s)");

                PerfTesterCollection testers = new PerfTesterCollection();
                LoadTesters(testers, testerAssemblies);

                if (testers.Count == 0)
                    throw new Exception("Could not find any tester class");

                LoadTestedTypes(testedAssemblies, testers);

                RunTests(testers, startValue, step, countOfRuns);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
示例#14
0
        /// <summary>
        /// Generates the report.
        /// </summary>
        /// <param name="args">The arguments to parse. Like in console application before.</param>
        public void GenerateReportWithType(Type type)
        {
            try
            {
                // loading testers
                if (type == null)
                    throw new Exception("You did not specify a tester assembly");

                // load testers from current assembly
                PerfTesterCollection testers = new PerfTesterCollection();
                LoadTesters(testers, Assembly.GetCallingAssembly());

                if (testers.Count == 0)
                    throw new Exception("Could not find any tester class");

                // load tested
                foreach (PerfTester tester in testers)
                {
                    tester.IsRunDescriptorValueOveridden = false;
                    if (tester.IsIgnored)
                        continue;

                    Console.WriteLine("Load tested assembly: {0}", Assembly.GetCallingAssembly().FullName);
                    //Looking inside current
                    tester.LoadTestedTypesFromInner(Assembly.GetCallingAssembly());
                    //Looking inside referenced
                    foreach (var asm in Assembly.GetCallingAssembly().GetReferencedAssemblies())
                    {
                        tester.LoadTestedTypesFromInner(Assembly.Load(asm));
                    }

                    Console.WriteLine("Tested types:");
                    Console.WriteLine(tester.TestedTypes.Count + " " + tester.TesterType);
                    foreach (Type t in tester.TestedTypes)
                    {
                        Console.WriteLine("\t{0}", t.Name);
                    }

                }

                // run test
                ChartReport chart = new ChartReport(800, 400);
                chart.Colors.Map = ColorMap.Jet;
                ImageFormat im = ImageFormat.Png;

                foreach (PerfTester tester in testers)
                {
                    if (tester.IsIgnored)
                        continue;

                    TextWriterTracer tracer = new TextWriterTracer();
                    tracer.Attach(tester);

                    PerfTestSuite suite = tester.RunTests();

                    IDictionary bmps = chart.Render(suite);
                    foreach (DictionaryEntry de in bmps)
                    {
                        PerfTest test = (PerfTest)de.Key;
                        Bitmap bmp = (Bitmap)de.Value;
                        bmp.Save(tester.TestedType.Name + "." + test.Name + "." + im.ToString().ToLower(), im);
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }