3 using System
.Collections
;
4 using System
.Diagnostics
;
6 using System
.Threading
;
13 static class BludgeonMain
{
15 static DirectoryObject
CreateTestRoot ()
19 parent
= Environment
.GetEnvironmentVariable ("BLUDGEON_TEST_DIRECTORY");
23 if (! Directory
.Exists (parent
))
24 Directory
.CreateDirectory (parent
);
30 name
= String
.Format ("test-{0}", ++i
);
31 home
= Path
.GetFullPath (Path
.Combine (parent
, name
));
32 } while (Directory
.Exists (home
));
34 Directory
.CreateDirectory (home
);
35 PathFinder
.HomeDir
= home
;
38 dot
= Path
.Combine (home
, ".bludgeon");
39 Directory
.CreateDirectory (dot
);
42 log
= Path
.Combine (dot
, "Log");
45 Log
.Spew ("Test home directory is '{0}'", home
);
47 return new DirectoryObject (home
);
50 ///////////////////////////////////////////////////////////////////////////
52 // Command-line arguments
54 [Option (LongName
="total-time", Description
="Time to run all tests (in minutes)")]
55 static private double total_time
= -1;
57 [Option (LongName
="total-count", Description
="Number of tests to run")]
58 static private int total_count
= -1;
60 [Option (LongName
="min_pause", Description
="Minimum number of seconds between tests")]
61 static private double min_pause
= 0;
63 [Option (LongName
="max_pause", Description
="Maximum number of seconds between tests")]
64 static private double max_pause
= -1;
66 [Option (LongName
="pause", Description
="Exact number of seconds between tests")]
67 static private double pause
= -1;
69 [Option (LongName
="min-cycles", Description
="Minimum number of cycles to run")]
70 static private int min_cycles
= 1; // Always at least one cycle
72 [Option (LongName
="max-cycles", Description
="Maximum number of cycles to run")]
73 static private int max_cycles
= -1;
75 [Option (LongName
="cycles", Description
="Exact number of cycles to run")]
76 static private int cycles
= -1;
78 [Option (LongName
="test-queries", Description
="Generate random queries and check that they return the correct results")]
79 static private bool test_queries
= false;
81 [Option (LongName
="total-query-time", Description
="Number of minutes to run test queries")]
82 static private double total_query_time
= 1;
84 [Option (LongName
="heap-buddy", Description
="Profile daemon with heap-buddy")]
85 static private bool heap_buddy
= false;
87 [Option (LongName
="list-hammers", Description
="Lists the available hammers and exits")]
88 static private bool list_hammers
= false;
90 /////////////////////////////////////////////////////////////////
92 static private DirectoryObject root
;
93 static private Abuse abuse
;
95 static bool Startup ()
97 Daemon
.UseHeapBuddy
= heap_buddy
;
98 Daemon
.Start (new Daemon
.StartedHandler (OnDaemonStarted
));
102 static void OnDaemonStarted (string version
)
104 if (version
== null) {
105 Log
.Info ("Could not contact daemon -- giving up!");
109 Daemon
.WaitUntilIdle (OnDaemonIdle
);
112 static void OnDaemonIdle ()
114 Log
.Info ("Daemon is idle!");
118 SanityCheck
.TestRandomQueries (total_query_time
, root
);
124 static public void Shutdown ()
127 Log
.Spew ("Test home directory was '{0}'", PathFinder
.HomeDir
);
131 /////////////////////////////////////////////////////////////////
133 private static GLib
.MainLoop main_loop
= null;
135 static void Main (string [] args
)
137 args
= CommandLine
.Process (typeof (BludgeonMain
), args
);
139 // BU.CommandLine.Process returns null if --help was passed
144 foreach (string hammer
in Toolbox
.HammerNames
)
145 Console
.WriteLine (" - {0}", hammer
);
149 ArrayList hammers_to_use
;
150 hammers_to_use
= new ArrayList ();
151 foreach (string name
in args
) {
153 hammer
= Toolbox
.GetHammer (name
);
155 hammers_to_use
.Add (hammer
);
157 Log
.Failure ("Unknown hammer '{0}'", name
);
160 root
= CreateTestRoot ();
161 TreeBuilder
.Build (root
,
162 30, // three directories
165 0.5, // archive decay, which does nothing here
166 false, // build all directories first, not in random order
167 null); // no need to track events
168 if (! root
.VerifyOnDisk ())
169 throw new Exception ("VerifyOnDisk failed for " + root
.FullName
);
171 EventTracker tracker
;
172 tracker
= new EventTracker ();
174 abuse
= new Abuse (root
, tracker
, hammers_to_use
);
176 abuse
.TotalCount
= total_count
;
177 abuse
.TotalTime
= total_time
;
179 abuse
.Cycles
= cycles
;
180 abuse
.MinCycles
= min_cycles
;
181 abuse
.MaxCycles
= max_cycles
;
184 abuse
.MinPause
= min_pause
;
185 abuse
.MaxPause
= max_pause
;
187 GLib
.Idle
.Add (new GLib
.IdleHandler (Startup
));
188 main_loop
= new GLib
.MainLoop ();