예제 #1
0
		static public void GetAllSubdirectories (DirectoryObject dir, ArrayList target)
		{
			target.Add (dir);
			foreach (FileSystemObject child in dir.Children)
				if (child is DirectoryObject)
					GetAllSubdirectories ((DirectoryObject) child, target);
		}
예제 #2
0
		public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
		{
			FileObject target;
			target = dir.PickChildFile ();
			if (target == null)
				return false;

			Log.Info ("Deleted file '{0}'", target.ShortName);			
			target.Parent.RemoveChild (target, tracker);
			
			return true;
		}
예제 #3
0
		public TarFileObject (DirectoryObject tar_root)
		{
			AllowChildren ();
			
			ArrayList to_be_tarred;
			to_be_tarred = new ArrayList (tar_root.Children);

			foreach (FileSystemObject fso in to_be_tarred) {
				tar_root.RemoveChild (fso, null);
				this.AddChild (fso, null);
			}
		}
예제 #4
0
		public ZipFileObject (DirectoryObject zip_root)
		{
			AllowChildren ();
			
			ArrayList to_be_zipped;
			to_be_zipped = new ArrayList (zip_root.Children);

			foreach (FileSystemObject fso in to_be_zipped) {
				zip_root.RemoveChild (fso, null);
				this.AddChild (fso, null);
			}
		}
예제 #5
0
		public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
		{
			DirectoryObject created;
			created = new DirectoryObject ();

			DirectoryObject parent;
			parent = dir.PickDirectory ();
			parent.AddChild (created, tracker);
			
			Log.Info ("Created directory {0}", created.ShortName);

			return true;
		}
예제 #6
0
		public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
		{
			FileObject created;
			created = new TextFileObject (); // FIXME: or an archive

			DirectoryObject parent;
			parent = dir.PickDirectory ();
			parent.AddChild (created, tracker);
			
			Log.Info ("Created file '{0}'", created.ShortName);

			return true;
		}
예제 #7
0
		public Abuse (DirectoryObject root,
			      EventTracker    tracker,
			      ICollection     hammers)
		{
			this.root = root;
			this.tracker = tracker;

			this.hammers = new IHammer [hammers.Count];
			int i = 0;
			foreach (IHammer hammer in hammers)
				this.hammers [i++] = hammer;

			idle_handler = new GLib.IdleHandler (AbuseWorker);
			timeout_handler = new GLib.TimeoutHandler (RescheduleAbuse);
			verified_handler = new Daemon.VerifiedHandler (VerifiedWorker);
		}
예제 #8
0
		static public FileObject NewFile (int    n_directories,
						  int    n_files,
						  string extension,
						  double p_archive,
						  double archive_decay,
						  Random random)
		{
			if (random == null)
				random = new Random ();

			n_directories = (int) Math.Floor (n_directories * archive_decay);
			n_files = (int) Math.Floor (n_files * archive_decay);

			if (n_files == 0 || extension == ".txt" || (extension == null && random.NextDouble () > p_archive))
				return new TextFileObject ();

			if (extension == null)
				extension = possible_extensions [random.Next (possible_extensions.Length)];

			switch (extension) {
			case ".gz":
				FileObject gzipped_file;
				gzipped_file = NewFile (n_directories, n_files, null, p_archive, archive_decay, random);
				return new GzipFileObject (gzipped_file);

			case ".bz2":
				FileObject bzip2ed_file;
				bzip2ed_file = NewFile (n_directories, n_files, null, p_archive, archive_decay, random);
				return new Bzip2FileObject (bzip2ed_file);

			case ".tar":
				DirectoryObject tar_root;
				tar_root = new DirectoryObject ();
				Build (tar_root, n_directories, n_files, p_archive, archive_decay, false, null);
				return new TarFileObject (tar_root);

			case ".zip":
				DirectoryObject zip_root;
				zip_root = new DirectoryObject ();
				Build (zip_root, n_directories, n_files, p_archive, archive_decay, false, null);
				return new ZipFileObject (zip_root);

			}

			throw new Exception ("Something terrible happened!");
		}
예제 #9
0
			public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
			{
				// We randomly pick an IHammer, and call HammerOnce on it.
				// If it returns false, we try the next IHammer until we
				// find one that returns true or until we've exhausted
				// all possibilities.
				int i;
				i = random.Next (hammers.Count);

				for (int j = 0; j < hammers.Count; ++j) {
					int k = (i + j) % hammers.Count;
					IHammer hammer;
					hammer = hammers [k] as IHammer;
					if (hammer.HammerOnce (dir, tracker))
						return true;
				}

				return false;
			}
예제 #10
0
		public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
		{
			FileObject victim;

			do {
				victim = dir.PickChildFile ();
			} while (victim != null && victim.IsWritable);

			if (victim == null)
				return false;

			// Create an object w/ the right type
			FileObject created;
			created = TreeBuilder.NewFile (5, 10, victim.Extension, 0.1, 0.5, null); // FIXME: stupid magic numbers

			Log.Info ("Clobbered file '{0}'", victim.ShortName);
			victim.Parent.ClobberingAddChild (created, victim, tracker);

			return true;
		}
예제 #11
0
		static void Main (string [] args)
		{
			args = CommandLine.Process (typeof (BludgeonMain), args);

			// BU.CommandLine.Process returns null if --help was passed
			if (args == null)
				return;

			if (list_hammers) {
				foreach (string hammer in Toolbox.HammerNames)
					Console.WriteLine ("  - {0}", hammer);
				return;
			}

			ArrayList hammers_to_use;
			hammers_to_use = new ArrayList ();
			foreach (string name in args) {
				IHammer hammer;
				hammer = Toolbox.GetHammer (name);
				if (hammer != null)
					hammers_to_use.Add (hammer);
				else
					Log.Failure ("Unknown hammer '{0}'", name);
			}

			root = CreateTestRoot ();
			TreeBuilder.Build (root,
					   30,    // number of directories
					   100,   // number of files
					   0, //0.1,   // no archives
					   0, //0.5,   // archive decay, which does nothing here
					   false, // build all directories first, not in random order
					   null); // no need to track events
			if (! root.VerifyOnDisk ())
				throw new Exception ("VerifyOnDisk failed for " + root.FullName);
			
			EventTracker tracker;
			tracker = new EventTracker ();

			abuse = new Abuse (root, tracker, hammers_to_use);

			abuse.TotalCount = total_count;
			abuse.TotalTime = total_time;

			abuse.Cycles = cycles;
			abuse.MinCycles = min_cycles;
			abuse.MaxCycles = max_cycles;

			abuse.Pause = pause;
			abuse.MinPause = min_pause;
			abuse.MaxPause = max_pause;

			GLib.Idle.Add (new GLib.IdleHandler (Startup));
			main_loop = new GLib.MainLoop ();
			main_loop.Run ();
		}
예제 #12
0
		static public void Build (DirectoryObject root,
					  int             n_directories,
					  int             n_files,
					  double          p_archive,
					  double          archive_decay,
					  bool            build_in_random_order,
					  EventTracker    tracker)
		{
			//Log.Info ("BUILD {0} {1} {2}", n_directories, n_files, p_archive);
			Random random;
			random = new Random ();

			// First, create the list of all of the directories we could
			// put things in.
			ArrayList all_dirs;
			all_dirs = new ArrayList ();
			GetAllSubdirectories (root, all_dirs);

			int nd = n_directories, nf = n_files;

			// Next, we construct the directories and files.
			while (nd > 0 || nf > 0) {
				
				// If we are not building in a random order,
				// we create all of the directories first.
				bool create_dir;
				if (build_in_random_order)
					create_dir = (random.Next (nd + nf) < nd);
				else
					create_dir = (nd > 0);

				if (create_dir) {
					
					DirectoryObject dir;
					dir = new DirectoryObject ();

					FileSystemObject parent;
					parent = (FileSystemObject) all_dirs [random.Next (all_dirs.Count)];
					parent.AddChild (dir, tracker);
					all_dirs.Add (dir);

					//Log.Spew ("dir {0}: {1}", n_directories - nd, dir.FullName);
					--nd;
					
				} else {

					
					FileObject file;
					file = NewFile (n_directories, n_files, null, p_archive, archive_decay, random);

					FileSystemObject parent;
					parent = (FileSystemObject) all_dirs [random.Next (all_dirs.Count)];
					parent.AddChild (file, tracker);

#if false
					// Commented out because it breaks queries
	
					// 20% of the time make the file unwritable, which prevents us from
					// being able to set extended attributes and makes us fall back to
					// our sqlite store.
					if (random.Next (5) == 0)
						Syscall.chmod (file.FullName, (FilePermissions) 292); // 0444
#endif

					//Log.Spew ("file {0}: {1}", n_files - nf, file.FullName);
					--nf;
				}
			}
		}
예제 #13
0
		abstract protected FileSystemObject PickTarget (DirectoryObject dir);
예제 #14
0
		public bool HammerOnce (DirectoryObject dir, EventTracker tracker)
		{
			DirectoryObject new_parent;
			new_parent = dir.PickDirectory ();

			// 10 is a stupid magic number here.
			FileSystemObject target = null;
			for (int i = 0; i < 10 && target == null; ++i) {
				target = PickTarget (dir);
				if (target == null)
					return false;
				if (target.IsAncestorOf (new_parent))
					target = null;
			}
			if (target == null)
				return false;

			Log.Spew ("Moved {0} to {1}", target.ShortName, new_parent.ShortName);
			target.Parent.MoveChild (target, new_parent, tracker);
			return true;
		}
예제 #15
0
        static void Main(string [] args)
        {
            args = CommandLine.Process(typeof(BludgeonMain), args);

            // BU.CommandLine.Process returns null if --help was passed
            if (args == null)
            {
                return;
            }

            if (list_hammers)
            {
                foreach (string hammer in Toolbox.HammerNames)
                {
                    Console.WriteLine("  - {0}", hammer);
                }
                return;
            }

            ArrayList hammers_to_use;

            hammers_to_use = new ArrayList();
            foreach (string name in args)
            {
                IHammer hammer;
                hammer = Toolbox.GetHammer(name);
                if (hammer != null)
                {
                    hammers_to_use.Add(hammer);
                }
                else
                {
                    Log.Failure("Unknown hammer '{0}'", name);
                }
            }

            root = CreateTestRoot();
            TreeBuilder.Build(root,
                              30,             // number of directories
                              100,            // number of files
                              0,              //0.1,   // no archives
                              0,              //0.5,   // archive decay, which does nothing here
                              false,          // build all directories first, not in random order
                              null);          // no need to track events
            if (!root.VerifyOnDisk())
            {
                throw new Exception("VerifyOnDisk failed for " + root.FullName);
            }

            EventTracker tracker;

            tracker = new EventTracker();

            abuse = new Abuse(root, tracker, hammers_to_use);

            abuse.TotalCount = total_count;
            abuse.TotalTime  = total_time;

            abuse.Cycles    = cycles;
            abuse.MinCycles = min_cycles;
            abuse.MaxCycles = max_cycles;

            abuse.Pause    = pause;
            abuse.MinPause = min_pause;
            abuse.MaxPause = max_pause;

            GLib.Idle.Add(new GLib.IdleHandler(Startup));
            main_loop = new GLib.MainLoop();
            main_loop.Run();
        }
예제 #16
0
		override protected FileSystemObject PickTarget (DirectoryObject dir)
		{
			return dir.PickChildDirectory ();
		}
예제 #17
0
        static public void Build(DirectoryObject root,
                                 int n_directories,
                                 int n_files,
                                 double p_archive,
                                 double archive_decay,
                                 bool build_in_random_order,
                                 EventTracker tracker)
        {
            //Log.Info ("BUILD {0} {1} {2}", n_directories, n_files, p_archive);
            Random random;

            random = new Random();

            // First, create the list of all of the directories we could
            // put things in.
            ArrayList all_dirs;

            all_dirs = new ArrayList();
            GetAllSubdirectories(root, all_dirs);

            int nd = n_directories, nf = n_files;

            // Next, we construct the directories and files.
            while (nd > 0 || nf > 0)
            {
                // If we are not building in a random order,
                // we create all of the directories first.
                bool create_dir;
                if (build_in_random_order)
                {
                    create_dir = (random.Next(nd + nf) < nd);
                }
                else
                {
                    create_dir = (nd > 0);
                }

                if (create_dir)
                {
                    DirectoryObject dir;
                    dir = new DirectoryObject();

                    FileSystemObject parent;
                    parent = (FileSystemObject)all_dirs [random.Next(all_dirs.Count)];
                    parent.AddChild(dir, tracker);
                    all_dirs.Add(dir);

                    //Log.Spew ("dir {0}: {1}", n_directories - nd, dir.FullName);
                    --nd;
                }
                else
                {
                    FileObject file;
                    file = NewFile(n_directories, n_files, null, p_archive, archive_decay, random);

                    FileSystemObject parent;
                    parent = (FileSystemObject)all_dirs [random.Next(all_dirs.Count)];
                    parent.AddChild(file, tracker);

#if false
                    // Commented out because it breaks queries

                    // 20% of the time make the file unwritable, which prevents us from
                    // being able to set extended attributes and makes us fall back to
                    // our sqlite store.
                    if (random.Next(5) == 0)
                    {
                        Syscall.chmod(file.FullName, (FilePermissions)292);                           // 0444
                    }
#endif

                    //Log.Spew ("file {0}: {1}", n_files - nf, file.FullName);
                    --nf;
                }
            }
        }