http://www.mediawiki.org/wiki/Special:Code/MediaWiki/88439
Revision: 88439 Author: krinkle Date: 2011-05-19 23:56:30 +0000 (Thu, 19 May 2011) Log Message: ----------- Adding custom configuration for MediaWiki's TestSwarm to SVN. Based on https://github.com/jquery/testswarm/blob/master/scripts/testswarm-jqueryui-svn.pl.txt Added Paths: ----------- trunk/tools/testswarm/ trunk/tools/testswarm/config/ trunk/tools/testswarm/config/crontab.txt trunk/tools/testswarm/scripts/ trunk/tools/testswarm/scripts/testswarm-mediawiki-svn (pre-r88431).php trunk/tools/testswarm/scripts/testswarm-mediawiki-svn.php Added: trunk/tools/testswarm/config/crontab.txt =================================================================== --- trunk/tools/testswarm/config/crontab.txt (rev 0) +++ trunk/tools/testswarm/config/crontab.txt 2011-05-19 23:56:30 UTC (rev 88439) @@ -0,0 +1 @@ +* * * * * php $HOME/testswarm/scripts/testswarm-mediawiki-svn.php > $HOME/testswarm/scripts/testswarm-mediawiki-svn.run.log 2>&1 Property changes on: trunk/tools/testswarm/config/crontab.txt ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/tools/testswarm/scripts/testswarm-mediawiki-svn (pre-r88431).php =================================================================== --- trunk/tools/testswarm/scripts/testswarm-mediawiki-svn (pre-r88431).php (rev 0) +++ trunk/tools/testswarm/scripts/testswarm-mediawiki-svn (pre-r88431).php 2011-05-19 23:56:30 UTC (rev 88439) @@ -0,0 +1,198 @@ +<?php + + die( 'Deprecated' ); + // This is an old file from before MediaWiki + // moved the test suite outside the resources + // directory which required us to modify the script + // to allow sparse checkouts. + // Bellow is the script as it was before then. + // This may be useful for others using TestSwarm + // and needing a PHP script to automaticlaly populate + // tests from SVN. + // -- Krinkle (2011-05-20) + +/** + * INIT + * ---------- + */ +// We like debug messages to be outputted to wherever the cronjob is set to +error_reporting(E_ALL); ini_set('display_errors', 1); + +// Toggle this to hide debug info (commands executed and their output etc.) +$GLOBALS['debugMode'] = true; + +// Make sure we're in the directory where the script is located if not already +chdir( dirname ( __FILE__ ) ); + +/** + * FUNCTIONS + * ---------- + */ + +function logger( $msg ) { + if ( $GLOBALS['debugMode'] ) { + echo "$msg\n"; + } +} + +function stopper( $msg ) { + die( "$msg\n" ); +} + +function getTestUrl( $rev, $suite ) { + $url = $GLOBALS['testUrlPattern']; + $url = str_replace( '$1', rawurlencode( $rev ), $url ); + $url = str_replace( '$2', rawurlencode( $suite ), $url ); + return $url; +} + + +/** + * CONFIGURE + * ---------- + */ + +# The location of the TestSwarm that you're going to run against. Ending in slash! +$swarmUrl = "http://toolserver.org/~krinkle/testswarm/"; + +# Your TestSwarm username. +$userName = "MediaWiki"; + +## replace this +# Your authorization token. +$userAuthToken = "*******"; + +# The maximum number of times you want the tests to be run. +$testMaxRuns = 2; + +# The URL from which a copy will be checked out. Without trailing slash! +$svnCoRepoDir = "http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3/resources"; + +# The directory in which the checkouts will occur. Without trailing slash! +$svnCoTargetDir = "/home/krinkle/testswarm-mediawiki/tmp-checkout"; +$svnCoTargetUrl = "http://toolserver.org/~krinkle/testswarm-tmp-checkouts"; + +# URL where tests can be executed +# $1 = revision id +# $2 = module name +$testUrlPattern = $svnCoTargetUrl . '/r$1/test/?filter=$2'; + +# The name of the job that will be submitted +# (pick a descriptive, but short, name to make it easy to search) + +# Note: The string $1 will be replaced with the current revision id. +$jobNamePattern = 'MediaWiki Commit <a href="http://www.mediawiki.org/wiki/Special:Code/MediaWiki/$1">r$1</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 +# - "popularbetamobile" +$browsers = "popularbeta"; + +# All the suites that you wish to run within this job +# (can be any number of suites) + +## Comment out to insert static suite list here (ie. QUnit modules) +#$suites = array( +# 'foo.js', +# 'bar.util.js', +# 'jquery.baz.js', +#); + +########### NO NEED TO CONFIGURE BELOW HERE ############ + +/** + * DOING STUFF + * ---------- + */ + +# Get latest revision number of HEAD + +$svnInfoCMD = array(); +$svnHeadRev = null; +exec( "svn info $svnCoRepoDir", $svnInfoCMD['output'], $svnInfoCMD['return'] ); + +if ( is_array( $svnInfoCMD['output'] ) && count( $svnInfoCMD['output'] ) ) { + foreach( $svnInfoCMD['output'] as $line ) { + $lineParts = explode( ':', $line, 2 ); + if ( trim( $lineParts[0] ) == 'Last Changed Rev' ) { + $svnHeadRev = trim( $lineParts[1] ); + break; + } + } + unset( $line, $lineParts ); +} + +if ( empty( $svnHeadRev ) ) { + die("Problem getting svn info."); +} + +# Check out a specific revision + +if ( is_dir( $svnCoTargetDir ) ) { + // Already checked out ? + if ( is_dir( "$svnCoTargetDir/r$svnHeadRev" ) ) { + stopper("Last revision has been done already. Skipping this loop."); + } + $svnCheckoutCMD = array(); + logger( "> $ svn checkout -r $svnHeadRev $svnCoRepoDir $svnCoTargetDir/r$svnHeadRev" ); + exec( "svn checkout -r $svnHeadRev $svnCoRepoDir $svnCoTargetDir/r$svnHeadRev", $svnCheckoutCMD['output'], $svnCheckoutCMD['return'] ); + logger( print_r( $svnCheckoutCMD['output'], true ) ); + unset( $svnCheckoutCMD ); + +} else { + stopper( "Problem locating temporary checkout directory." ); +} + +# Get array of test modules + +$unitDir = glob( "$svnCoTargetDir/r$svnHeadRev/test/unit/*/*.js" ); +$suites = array_map( 'basename', $unitDir ); + + +# Add jobs + +if ( true ) { + + $params = array( + "state" => "addjob", + "output" => "dump", + "user" => $userName, + "max" => $testMaxRuns, + "job_name" => str_replace( '$1', $svnHeadRev, $jobNamePattern ), + "browsers" => $browsers, + "auth" => $userAuthToken + ); + + $query = http_build_query( $params ); + + foreach ( $suites as $suite ) { + $query .= "&suites[]=" . rawurlencode( $suite ) . + "&urls[]=" . getTestUrl( $svnHeadRev, $suite ); + } + + logger( "curl -d \"$query\" $swarmUrl" ); + + $curlPostCMD = array(); + exec( "curl -d \"$query\" $swarmUrl", $curlPostCMD['output'], $curlPostCMD['return'] ); + + logger( "Results: {$curlPostCMD['output']}" ); + + if ( $curlPostCMD['output'] ) { + file_put_contents( + __DIR__ . '/testswarm-mediawiki-svn.log', + '[' . date('r') . '] ' . implode( ' \\', $curlPostCMD['output'] ) . "\n", + FILE_APPEND + ); + + } else { + stopper( "Job not submitted properly." ); + } + +} else { + stopper( "No new revision." ); +} \ No newline at end of file Property changes on: trunk/tools/testswarm/scripts/testswarm-mediawiki-svn (pre-r88431).php ___________________________________________________________________ Added: svn:eol-style + native Added: trunk/tools/testswarm/scripts/testswarm-mediawiki-svn.php =================================================================== --- trunk/tools/testswarm/scripts/testswarm-mediawiki-svn.php (rev 0) +++ trunk/tools/testswarm/scripts/testswarm-mediawiki-svn.php 2011-05-19 23:56:30 UTC (rev 88439) @@ -0,0 +1,242 @@ +<?php + +/** + * INIT + * ---------- + */ +// We like debug messages to be outputted to wherever the cronjob is set to +error_reporting(E_ALL); ini_set('display_errors', 1); + +// Toggle this to hide debug info (commands executed and their output etc.) +$GLOBALS['debugMode'] = true; + +// Make sure we're in the directory where the script is located if not already +chdir( dirname ( __FILE__ ) ); + +/** + * FUNCTIONS + * ---------- + */ + +function logger( $msg ) { + if ( $GLOBALS['debugMode'] ) { + echo "$msg\n"; + } +} + +function stopper( $msg ) { + die( "$msg\n" ); +} + +function getTestUrl( $rev, $suite ) { + $url = $GLOBALS['testUrlPattern']; + $url = str_replace( '$1', rawurlencode( $rev ), $url ); + $url = str_replace( '$2', rawurlencode( $suite ), $url ); + return $url; +} + + +/** + * CONFIGURE + * ---------- + */ + +# The location of the TestSwarm that you're going to run against. Ending in slash. +$swarmUrl = "http://toolserver.org/~krinkle/testswarm/"; + +# Your TestSwarm username. +$userName = "MediaWiki"; + +## replace this +# Your authorization token. +$userAuthToken = "*******"; + +# The maximum number of times you want the tests to be run. +# If a client reports a test as broken, the test swarm will send +# that revision/testmodule combination up to this many times to the +# same browser/version combination before giving up and continueing +# with other testmodules and revisions. +$testMaxRuns = 2; + +# Stuff for the multi-directory sparse checkout +# Because we don't want the entire MediaWiki install, but do need data from multiple dirs +# > Without leading or trailing slashes! +$svnCoRepoInfo = array( + // To be checked out with "--depth empty" + 'rootBase' => 'http://svn.wikimedia.org/svnroot/mediawiki/trunk/phase3', + + // Updated with "--set-depth infinity", also used to get svn revision + 'resourcesDir' => 'resources', + + // Updated with "--set-depth empty" + 'qunitBase' => 'tests', + + // Updated with "--set-depth infinity", also used to get svn revision + 'qunitDir' => 'tests/qunit', +); + +# The directory in which the checkouts will occur. Without trailing slash! +$svnCoTargetDir = "/home/krinkle/testswarm-mediawiki/tmp-checkout"; +$svnCoTargetUrl = "http://toolserver.org/~krinkle/testswarm-tmp-checkouts"; + +# URL where tests can be executed +# $1 = revision id +# $2 = module name +$testUrlPattern = $svnCoTargetUrl . '/r$1/tests/qunit/?filter=$2'; + +# The name of the job that will be submitted +# (pick a descriptive, but short, name to make it easy to search) + +# Note: The string $1 will be replaced with the current revision id. +$jobNamePattern = 'MediaWiki Commit <a href="http://www.mediawiki.org/wiki/Special:Code/MediaWiki/$1">r$1</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 +# - "popularbetamobile" +$browsers = "popularbeta"; + +# All the suites that you wish to run within this job +# (can be any number of suites) + +## Comment out to insert static suite list here (ie. QUnit modules) +#$suites = array( +# 'foo.js', +# 'bar.util.js', +# 'jquery.baz.js', +#); + +########### NO NEED TO CONFIGURE BELOW HERE ############ + +/** + * DOING STUFF + * ---------- + */ + +# Get latest revision number of HEAD for QUnit tests dir and Resources dir +$tmpCmd = array(); +$svnHeadRevs = array( + 'tests' => null, + 'resources' => null, +); +$svnHeadRevTop = null; + +foreach ( array( + 'tests' => $svnCoRepoInfo['rootBase'] . '/' . $svnCoRepoInfo['qunitDir'], + 'resources' => $svnCoRepoInfo['rootBase'] . '/' . $svnCoRepoInfo['resourcesDir'], +) as $key => $url ) { + + exec( "svn info $url", $tmpCmd['output'], $tmpCmd['return'] ); + + if ( is_array( $tmpCmd['output'] ) && count( $tmpCmd['output'] ) ) { + foreach( $tmpCmd['output'] as $line ) { + $lineParts = explode( ':', $line, 2 ); + if ( trim( $lineParts[0] ) == 'Last Changed Rev' ) { + $svnHeadRevs[$key] = trim( $lineParts[1] ); + break; + } + } + unset( $line, $lineParts ); + } + +} +unset( $tmpCmd, $key, $url ); + +if ( empty( $svnHeadRevs['tests'] ) || empty( $svnHeadRevs['resources'] ) ) { + die("Problem getting svn info."); +} + +# Determine the highest of each +$svnHeadRevTop = max( intval( $svnHeadRevs['tests'] ), intval( $svnHeadRevs['resources'] ) ); + +# Check out a specific revision +# We're doing a sparse checkout of phase3 +# and get /resources and /tests/qunit + +$revTargetTmpDir = "$svnCoTargetDir/r$svnHeadRevTop"; + +if ( is_dir( $svnCoTargetDir ) ) { + // Already checked out ? + if ( is_dir( "$revTargetTmpDir" ) ) { + stopper("Last revision (r$svnHeadRevTop) has been done already. Skipping this loop."); + } + $cmdExc = array(); + $cmd = null; + + // Checkout empty root of mediawiki + $cmd = "svn checkout -r $svnHeadRevTop {$svnCoRepoInfo['rootBase']} $revTargetTmpDir --depth empty"; + logger( $cmd ); exec( $cmd, $cmdExc['output'], $cmdExc['return'] ); + logger( print_r( $cmdExc['output'], true ) ); + + // Checkout full depth of the resources directory + $cmd = "svn update -r $svnHeadRevTop --set-depth infinity $revTargetTmpDir/{$svnCoRepoInfo['resourcesDir']}"; + logger( $cmd ); exec( $cmd, $cmdExc['output'], $cmdExc['return'] ); + logger( print_r( $cmdExc['output'], true ) ); + + // Checkout empty qunit's parent directory + $cmd = "svn update -r $svnHeadRevTop --set-depth empty $revTargetTmpDir/{$svnCoRepoInfo['qunitBase']}"; + logger( $cmd ); exec( $cmd, $cmdExc['output'], $cmdExc['return'] ); + logger( print_r( $cmdExc['output'], true ) ); + + // Checkout full depth of qunit directory + $cmd = "svn update -r $svnHeadRevTop --set-depth infinity $revTargetTmpDir/{$svnCoRepoInfo['qunitDir']}"; + logger( $cmd ); exec( $cmd, $cmdExc['output'], $cmdExc['return'] ); + logger( print_r( $cmdExc['output'], true ) ); + + unset( $cmd, $cmdExc ); + +} else { + stopper("Problem locating temporary checkout directory."); +} + +# Get array of modules + +$unitDir = glob( "$revTargetTmpDir/{$svnCoRepoInfo['qunitDir']}/suites/resources/*/*.js" ); +$suites = array_map( 'basename', $unitDir ); + +# Add jobs + +if ( true ) { + + $params = array( + "state" => "addjob", + "output" => "dump", + "user" => $userName, + "max" => $testMaxRuns, + "job_name" => str_replace( '$1', $svnHeadRevTop, $jobNamePattern ), + "browsers" => $browsers, + "auth" => $userAuthToken + ); + + $query = http_build_query( $params ); + + foreach ( $suites as $suite ) { + $query .= "&suites[]=" . rawurlencode( $suite ) . + "&urls[]=" . getTestUrl( $svnHeadRevTop, $suite ); + } + + logger( "curl -d \"$query\" $swarmUrl" ); + + $curlPostCMD = array(); + exec( "curl -d \"$query\" $swarmUrl", $curlPostCMD['output'], $curlPostCMD['return'] ); + + logger( "Results: {$curlPostCMD['output']}" ); + + if ( $curlPostCMD['output'] ) { + file_put_contents( + __DIR__ . '/testswarm-mediawiki-svn.log', + '[' . date('r') . '] ' . implode( ' \\', $curlPostCMD['output'] ) . "\n", + FILE_APPEND + ); + + } else { + stopper( "Job not submitted properly." ); + } + +} else { + stopper( "No new revision." ); +} Property changes on: trunk/tools/testswarm/scripts/testswarm-mediawiki-svn.php ___________________________________________________________________ Added: svn:eol-style + native _______________________________________________ MediaWiki-CVS mailing list [email protected] https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
