Testswarm
Adding Jobs to Testswarm
Using a Script to Add jobs
Interesting parts (see full script below)
my $SWARM = "http://localhost";
This is where you specify the URL to where Testswarm will be run from
my $USER = "fluid"; my $AUTH_TOKEN = "some hash code";
The first step is to navigate to the Testswarm URL, which you specified above, and create a new user account.
Once this is done, you can access the users table in the Mysql database. Look up the user you just created. Use the "name" for the $USER value and the "auth" for the $AUTH_TOKEN value. Both these values are necessary in order to have permission to submit jobs.
my $RCS_URL = "https://source.fluidproject.org/svn/fluid/infusion/trunk";
$RCS_URL
is where you specify the url where to checkout the code from, the path to the SVN repository.
my $BASE_DIR = "/var/www/testswarm/infusion-checkout";
The location on the filesystem where you want the code to be checked out. It is relative to the script, or you can use an absolute path.
my $JOB_NAME = "Fluid Infusion Commit <a href=\"https://source.fluidproject.org/svn/!svn/bc/{REV}/fluid/infusion/trunk/\">r{REV}</a>";
The JOB_NAME gets inserted on the page and is used to identify the different jobs. To make it clear which commit is for which job the {REV
} value is expanded to the revision number. The other trick is in the url, where /!svn/bc/{REV} allows you to display a particular revision in the web view of the SVN repository
my $SUITE = "http://localhost/infusion-checkout";
$SUITE
points at where your code is. It should be a URL a web visible instance of your code.
%SUITES = map \{ /(\w+)-test.html$/; $1 => "$SUITE/$_"; \} glob("src/webapp/tests/component-tests/*/html/*.html");
Lastly you will need to determine your testsuites.
The code above basically will find all of the files that match the pattern passed to it. This is called relative to the location you specified for $SUITE. The set of these files is passed to the map function, which performs the regex operation on each of them. Then the $1 variable is replaced by the value of "w" in the regex and used to build up a hash using the $1 value as the name and the key as the full path to the file. Note if you need to, you can create mutltiple hashes in this manner and assign the merged map to $SUITES
%SUITES = (%compTests, %rendererTests, %coreTests);
This will merge the hashes %compTests
, %rendererTests
, and %coreTests
into a single hash.
This code was derived from the testswarm-jqueryui-svn.pl.txt sample Perl script.
#!/usr/bin/perl # CONFIGURE # The location of the TestSwarm that you're going to run against. my $SWARM = "http://localhost"; # Your TestSwarm username. my $USER = "fluid"; ## replace this # Your authorization token. my $AUTH_TOKEN = "some hash code"; # The maximum number of times you want the tests to be run. my $MAX_RUNS = 5; # The URL from which a copy will be checked out. my $RCS_URL = "https://source.fluidproject.org/svn/fluid/infusion/trunk"; # The directory in which the checkouts will occur. my $BASE_DIR = "/var/www/testswarm/infusion-checkout"; # Any build commands that need to happen. my $BUILD = ""; # The name of the job that will be submitted # (pick a descriptive, but short, name to make it easy to search) # Note: The string {REV} will be replaced with the current # commit number/hash. my $JOB_NAME = "Fluid Infusion Commit <a href=\"https://source.fluidproject.org/svn/!svn/bc/{REV}/fluid/infusion/trunk/\">r{REV}</a>"; # The browsers you wish to run against. Options include: # - "all" all available browsers. # - "popular" the most popular browser (99%+ of all browsers in use) # - "current" the current release of all the major browsers # - "gbs" the browsers currently supported in Yahoo's Graded Browser Support # - "beta" upcoming alpha/beta of popular browsers # - "popularbeta" the most popular browser and their upcoming releases my $BROWSERS = "all"; # All the suites that you wish to run within this job # (can be any number of suites) ## insert static suite list here my %SUITES = (); # "inlineEdit" => "http://localhost/infusion-checkout/src/webapp/tests/component-tests/inlineEdit/html/InlineEdit-test.html" #); # Comment these out if you wish to define a custom set of SUITES above my $SUITE = "http://localhost/infusion-checkout"; sub BUILD_SUITES { my %compTests = map { /(\w+)-test.html$/; $1 => "$SUITE/$_"; } glob("src/webapp/tests/component-tests/*/html/*.html"); my %rendererTests = map { /(\w+)-test.html$/; $1 => "$SUITE/$_"; } glob("src/webapp/tests/framework-tests/renderer/html/*.html"); my %coreTests = map { /(\w+)-test.html$/; $1 => "$SUITE/$_"; } glob("src/webapp/tests/framework-tests/core/html/*.html"); %SUITES = (%compTests, %rendererTests, %coreTests); # %SUITES = map { /(\w+)-test.html$/; $1 => "$SUITE/$_?$1"; } glob("src/webapp/tests/component-tests/*/html/*.html"); print "\nstart suites\n"; print "suites: $SUITES"; print "\n"; print %SUITES; print "\nend suites\n"; } ## TODOs # check if c/o exists, if not, svn co non-recursive of trunk # go into, do svn up # parse output, looking for at Revision {REV} # insert that into the suites URLs # submit, along with other parameters, to TestSwarm ########### NO NEED TO CONFIGURE BELOW HERE ############ my $DEBUG = 1; my $fresh; # Check out a specific revision if ( ! -e $BASE_DIR ) { print "svn co $RCS_URL $co_dir\n" if ( $DEBUG ); `svn co $RCS_URL $BASE_DIR`; $fresh = 1; } if ( ! -e $BASE_DIR ) { die "Problem checking out source."; } print "chdir $BASE_DIR\n" if ( $DEBUG ); chdir( $BASE_DIR ); my $previous; my $rev; if (!$fresh) { print "svn info | grep Revision\n" if ( $DEBUG ); $previous = `svn info | grep Revision`; $previous =~ s/Revision: //; $previous =~ s/\s*//g; print "Previous revision: $previous\n" if ( $DEBUG ); if ( ! $previous ) { die "Previous revision information not found."; } print "svn up\n" if ( $DEBUG ); $rev = `svn up | grep Revision`; } print "svn info | grep Revision\n" if ( $DEBUG ); $rev = `svn info | grep Revision`; $rev =~ s/Revision: //; $rev =~ s/\s*//g; print "New revision: $rev\n" if ( $DEBUG ); if ( ! $rev ) { die "New revision information not found."; } if (true || $fresh || $previous != $rev ) { if ( exists &BUILD_SUITES ) { &BUILD_SUITES(); } my %props = ( "state" => "addjob", "output" => "dump", "user" => $USER, "max" => $MAX_RUNS, "job_name" => $JOB_NAME, "browsers" => $BROWSERS, "auth" => $AUTH_TOKEN ); my $query = ""; foreach my $prop ( keys %props ) { $query .= ($query ? "&" : "") . $prop . "=" . clean($props{$prop}); } foreach my $suite ( sort keys %SUITES ) { $query .= "&suites[]=" . clean($suite) . "&urls[]=" . clean($SUITES{$suite}); } print "curl -d \"$query\" $SWARM\n" if ( $DEBUG ); my $results = `curl -d "$query" $SWARM`; print "Results: $results\n" if ( $DEBUG ); if ( $results ) { open( F, ">$rev/results.txt" ); print F "$SWARM$results"; close( F ); } else { die "Job not submitted properly."; } } else { print "No new revision." if ( $DEBUG ); } sub clean { my $str = shift; $str =~ s/{REV}/$rev/g; $str =~ s/([^A-Za-z0-9])/sprintf("%%%02X", ord($1))/seg; $str; }