Fixed #374055:Only the first "tag" is detected in digikam.
[beagle.git] / bludgeon / Bludgeon.cs
blobb9253fcb8ac2742dbe8a4fd764317936d7a1b1f4
2 using System;
3 using System.Collections;
4 using System.Diagnostics;
5 using System.IO;
6 using System.Threading;
8 using Beagle.Util;
9 using CommandLineFu;
11 namespace Bludgeon {
13 static class BludgeonMain {
15 static DirectoryObject CreateTestRoot ()
18 string parent;
19 parent = Environment.GetEnvironmentVariable ("BLUDGEON_TEST_DIRECTORY");
20 if (parent == null)
21 parent = ".";
23 if (! Directory.Exists (parent))
24 Directory.CreateDirectory (parent);
26 int i = 0;
27 string home;
28 do {
29 string name;
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;
37 string dot;
38 dot = Path.Combine (home, ".bludgeon");
39 Directory.CreateDirectory (dot);
41 string log;
42 log = Path.Combine (dot, "Log");
43 Log.Create (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));
99 return false;
102 static void OnDaemonStarted (string version)
104 if (version == null) {
105 Log.Info ("Could not contact daemon -- giving up!");
106 main_loop.Quit ();
109 Daemon.WaitUntilIdle (OnDaemonIdle);
112 static void OnDaemonIdle ()
114 Log.Info ("Daemon is idle!");
115 abuse.Run ();
117 if (test_queries) {
118 SanityCheck.TestRandomQueries (total_query_time, root);
119 Shutdown ();
124 static public void Shutdown ()
126 Daemon.Shutdown ();
127 Log.Spew ("Test home directory was '{0}'", PathFinder.HomeDir);
128 main_loop.Quit ();
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
140 if (args == null)
141 return;
143 if (list_hammers) {
144 foreach (string hammer in Toolbox.HammerNames)
145 Console.WriteLine (" - {0}", hammer);
146 return;
149 ArrayList hammers_to_use;
150 hammers_to_use = new ArrayList ();
151 foreach (string name in args) {
152 IHammer hammer;
153 hammer = Toolbox.GetHammer (name);
154 if (hammer != null)
155 hammers_to_use.Add (hammer);
156 else
157 Log.Failure ("Unknown hammer '{0}'", name);
160 root = CreateTestRoot ();
161 TreeBuilder.Build (root,
162 30, // three directories
163 100, // ten files
164 0.1, // no archives
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;
183 abuse.Pause = pause;
184 abuse.MinPause = min_pause;
185 abuse.MaxPause = max_pause;
187 GLib.Idle.Add (new GLib.IdleHandler (Startup));
188 main_loop = new GLib.MainLoop ();
189 main_loop.Run ();