Merge branch 'loaded-branch'
[moon.git] / perf / perf-suite-runner / PerfSuiteRunner.cs
blob966978e6631bdc24927842e5499b36704dd9cfbc
1 /*
2 * Copyright (c) 2008 Novell, Inc. (http://www.novell.com)
4 * Contact:
5 * Moonlight List (moonlight-list@lists.ximian.com)
6 *
7 * Permission is hereby granted, free of charge, to any person
8 * obtaining a copy of this software and associated documentation
9 * files (the "Software"), to deal in the Software without
10 * restriction, including without limitation the rights to use,
11 * copy, modify, merge, publish, distribute, sublicense, and/or sell
12 * copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following
14 * conditions:
16 * The above copyright notice and this permission notice shall be
17 * included in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
21 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
23 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
24 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
26 * OTHER DEALINGS IN THE SOFTWARE.
30 using System;
31 using System.IO;
32 using System.Xml;
33 using PerfSuiteLib;
34 using Mono.GetOptions;
36 namespace PerfSuiteRunner {
38 public static class PerfSuiteRunner {
40 public static int AllTestsMode (Options opts)
42 Console.WriteLine ("*** Pass name is '{0}'...", opts.ShortName);
44 Database.Initialize (opts.DatabaseFile);
45 Database.BeginTransaction ();
47 PassDbEntry passEntry = new PassDbEntry ();
48 passEntry.ShortName = opts.ShortName;
49 passEntry.Author = opts.Author;
50 passEntry.ChangeLog = opts.ChangeLog;
51 passEntry.Date = DateTime.Now;
53 Database.Put (passEntry);
55 DrtStore store = new DrtStore ("perf-suite-set/drtlist.xml");
56 foreach (DrtItem item in store.Items) {
57 Console.WriteLine ("*** Running [{0}]", item);
59 ItemDbEntry itemEntry = Database.GetItemEntryByUniqueId (item.UniqueId);
60 if (itemEntry == null) {
61 Console.WriteLine ("*** [{0}] not yet in the database, adding...", item);
62 itemEntry = new ItemDbEntry ();
63 itemEntry.UniqueId = item.UniqueId;
64 itemEntry.Name = item.Name;
65 itemEntry.InputFile = item.InputFile;
66 Database.Put (itemEntry);
69 DrtResult r = item.Run ();
71 ResultDbEntry resultEntry = new ResultDbEntry ();
72 resultEntry.Pass = passEntry;
73 resultEntry.Item = itemEntry;
75 if (r == null) {
76 resultEntry.Time = 0;
77 Console.WriteLine ("*** Averaged result: 0 (FAILURE)");
78 } else {
79 resultEntry.Time = r.AveragedTime;
80 Console.WriteLine ("*** Averaged result: {0}usec", r.AveragedTime);
83 Database.Put (resultEntry);
86 Database.CommitTransaction ();
88 return 0;
92 public static int SingleTestMode (Options opts)
94 Console.WriteLine ("*** Running single test with id '{0}' not storing results in database...", opts.TestId);
96 DrtStore store = new DrtStore ("perf-suite-set/drtlist.xml");
97 DrtItem item = store.GetDrtItemForId (opts.TestId);
99 if (item == null) {
100 Console.WriteLine ("*** Test '{0}' not found!", opts.TestId);
101 return 128;
104 Console.WriteLine ("*** Running [{0}]", item);
106 DrtResult r = item.Run ();
108 ResultDbEntry resultEntry = new ResultDbEntry ();
110 if (r == null) {
111 resultEntry.Time = 0;
112 Console.WriteLine ("*** Averaged result: 0 (FAILURE)");
113 } else {
114 resultEntry.Time = r.AveragedTime;
115 Console.WriteLine ("*** Averaged result: {0}usec", r.AveragedTime);
118 return 0;
122 public static int Main (string [] args)
124 Options opts = new Options ();
125 opts.ProcessArgs (args);
127 if (opts.TestId != String.Empty)
128 return SingleTestMode (opts);
129 else
130 return AllTestsMode (opts);