#!/usr/local/bin/perl -w use List::Util 'shuffle'; use File::Basename; use strict; my $DOC = <<"EOF"; Usage: $0 [ ...] Args: - , the number of mutants to pick - , the dir containing all mutants generated by MuJava for the app - , the dir in which to place links to the picked mutants - , dirs of previously-picked mutants. Mutants picked this time around are distinct from these, and their numbering starts where numbering leaves off. Constants: - IGNORE_CLS, the classes from which no mutants should be picked - IGNORE_MUT_TYPE, the types of mutants that should not be picked - IGNORE_SPEC_MUT, the mutants that should not be picked Affects: - Randomly picks mutants from , skipping mutants from classes in the list . Places numbered links to them and an index file in . Numbering starts at 1 unless are specified. EOF ; my %IGNORE_CLS = ('crosswordsage.CrosswordPage'=>1, 'crosswordsage.LetterPanel'=>1, 'crosswordsage.MainScreen4Rip'=>1, 'crosswordsage.PrintUtilities'=>1, 'crosswordsage.SimpleAuthenticator'=>1, 'crosswordsage.VersionChecker'=>1, 'freemind.controller.actions.PrintActionHandler'=>1, 'freemind.modes.browsemode.BrowseArrowLinkModel'=>1, 'freemind.modes.browsemode.BrowseCloudModel'=>1, 'freemind.modes.browsemode.BrowseController'=>1, 'freemind.modes.browsemode.BrowseEdgeModel'=>1, 'freemind.modes.browsemode.BrowseMapModel'=>1, 'freemind.modes.browsemode.BrowseMode'=>1, 'freemind.modes.browsemode.BrowseNodeModel'=>1, 'freemind.modes.browsemode.BrowsePopupMenu'=>1, 'freemind.modes.browsemode.BrowseToolBar'=>1, 'freemind.modes.browsemode.BrowseXMLElement'=>1, 'freemind.modes.schememode.SchemeController'=>1, 'freemind.modes.schememode.SchemeEdgeModel'=>1, 'freemind.modes.schememode.SchemeMapModel'=>1, 'freemind.modes.schememode.SchemeMode'=>1, 'freemind.modes.schememode.SchemeNodeModel'=>1, 'freemind.modes.schememode.SchemePopupMenu'=>1, 'freemind.modes.schememode.SchemeToolBar'=>1, 'freemind.modes.filemode.FileController'=>1, 'freemind.modes.filemode.FileEdgeModel'=>1, 'freemind.modes.filemode.FileMapModel'=>1, 'freemind.modes.filemode.FileMode'=>1, 'freemind.modes.filemode.FileNodeModel'=>1, 'freemind.modes.filemode.FilePopupMenu'=>1, 'freemind.modes.filemode.FileToolBar'=>1); my @IGNORE_MUT_TYPE = ('IOP', 'IOD', 'JDC', 'OMR', 'IHI'); my @IGNORE_SPEC_MUT = ('/fs/guitar/MuJava_mutants/freemind-0.8.0/freemind.modes.actions.ApplyPatternAction/traditional_mutants/void_applyPattern(freemind.modes.MindMapNode,freemind.modes.StylePattern)/ROR_4', '/fs/guitar/MuJava_mutants/freemind-0.8.0/freemind.modes.actions.ApplyPatternAction/traditional_mutants/void_applyPattern(freemind.modes.MindMapNode,freemind.modes.StylePattern)/ROR_5', '/fs/guitar/MuJava_mutants/freemind-0.8.0/freemind.modes.actions.ApplyPatternAction/traditional_mutants/void_applyPattern(freemind.modes.MindMapNode,freemind.modes.StylePattern)/ROR_6', '/fs/guitar/MuJava_mutants/freemind-0.8.0/freemind.modes.actions.ApplyPatternAction/traditional_mutants/void_applyPattern(freemind.modes.MindMapNode,freemind.modes.StylePattern)/ROR_7', '/fs/guitar/MuJava_mutants/freemind-0.8.0/freemind.modes.actions.ApplyPatternAction/traditional_mutants/void_applyPattern(freemind.modes.MindMapNode,freemind.modes.StylePattern)/ROR_8', '/fs/guitar/MuJava_mutants/freemind-0.8.0/freemind.modes.actions.ApplyPatternAction/traditional_mutants/void_applyPattern(freemind.modes.MindMapNode,freemind.modes.StylePattern)/COI_4'); if (@ARGV < 3) { print $DOC; exit 1; } my $num = shift @ARGV; my $mujava_dir = shift @ARGV; my $mut_dir = shift @ARGV; my @prev_mut_dirs = @ARGV; $mujava_dir =~ s|/$||; $mut_dir =~ s|/$||; my %prev_mut_paths; my $num_prev_muts = 0; foreach my $prev_mut_dir (@prev_mut_dirs) { $prev_mut_dir =~ s|/$||; open(INDEX, "$prev_mut_dir/index") or die "Couldn't read $prev_mut_dir/index\n"; while () { chomp; my ($mut_num, $mut_path) = split; $prev_mut_paths{$mut_path} = 1; $num_prev_muts++; } close(INDEX); } ### BEGIN cloned from Jaymie_ExptOSS/scripts/pick_mutants ### if (! -e $mujava_dir || ! -d $mujava_dir) { die "Directory $mujava_dir does not exist\n"; } my @mutdirs; my @clsdirs = <$mujava_dir/*>; foreach my $clsdir (@clsdirs) { next if ($IGNORE_CLS{basename($clsdir)}); my @cmdirs = <$clsdir/class_mutants/*>; foreach my $cmdir (@cmdirs) { my $ignore = 0; foreach my $imt (@IGNORE_MUT_TYPE) { $ignore = 1 if ($cmdir =~ m/${imt}_\d+$/); } foreach my $ism (@IGNORE_SPEC_MUT) { $ignore = 1 if ($cmdir =~ m/$ism$/); } push @mutdirs, $cmdir if (-d $cmdir && <$cmdir/*> && !$ignore && !$prev_mut_paths{$cmdir}); } my @tmdirs = <$clsdir/traditional_mutants/*/*>; foreach my $tmdir (@tmdirs) { my $ignore = 0; foreach my $imt (@IGNORE_MUT_TYPE) { $ignore = 1 if ($tmdir =~ m/${imt}_\d+$/); } foreach my $ism (@IGNORE_SPEC_MUT) { $ignore = 1 if ($tmdir =~ m/$ism$/); } push @mutdirs, $tmdir if (-d $tmdir && <$tmdir/*> && !$ignore && !$prev_mut_paths{$tmdir}); } } if (-e $mut_dir) { die "Directory $mut_dir already exists\n"; } else { `mkdir $mut_dir`; die "Couldn't do mkdir $mut_dir\n" if ($?); } open(INDEX, ">$mut_dir/index") or die "Couldn't write to $mut_dir/index\n"; my @indices = shuffle( (0..$#mutdirs) ); my $i; for ($i = 0; $i < $num && $i <= $#indices; $i++) { my $name = $i + 1 + $num_prev_muts; my $j = $indices[$i]; `cp -r '$mutdirs[$j]' $mut_dir/$name`; die "Couldn't do cp -r '$mutdirs[$j]' $mut_dir/$name\n" if ($?); print INDEX "$name $mutdirs[$j]\n"; } close(INDEX); print "Picked $i mutants of " . scalar(@mutdirs) . " possible\n"; ### END cloned from Jaymie_ExptOSS/scripts/pick_mutants ###