diff --git a/run_unit_tests.py b/run_unit_tests.py new file mode 100644 index 0000000..8da5741 --- /dev/null +++ b/run_unit_tests.py @@ -0,0 +1,78 @@ +''' +This helper script for Seattle testbed, https://seattle.poly.edu/, + * downloads Seattle testbed's sources from GitHub, + * builds them using Seattle's build scripts, and finally + * runs Seattle's unit tests. + + Find documentation for Seattle's build scripts and unit test framework at + https://seattle.poly.edu/wiki/BuildInstructions + https://seattle.poly.edu/wiki/UnitTestFramework + + The list of components (i.e. source repositories) for which the + tests are run is configurable via the repolist variable, see below. + + Since other testbeds use the Seattle codebase, we make the testbed + name (and thus repo address) configurable too: +''' +import os +import sys +import subprocess +import time +import string + +def main(): + testbed = 'Seattletestbed' + # If you like to test the complete set of repos, get the list of + # $testbed repositories via the GitHub API, grab entries like + # "full_name": "Seattletestbed/foo", + # cut out the repo names, and create a space-separated list: + # + # repolist=`curl https://api.github.com/orgs/$testbed/repos | awk '/full_name/ {gsub("\"", ""); gsub(",", ""); split($2, a, "/"); printf a[2] " "}'` + + + # Otherwise, just supply the list yourself. + # + # Here's a mostly complete one, omitting but a few backup/outdated repos: + # repolist="advertiseserver affix buildscripts common demokit experimentmanager geoip_server nodemanager overlord portability repy_v1 repy_v2 seash seattlelib_v1 seattlelib_v2 softwareupdater timeserver utf zenodotus" + + # This is the "bare minimum" list. Whatever changes you make to the + # Seattle codebase, do make sure these tests pass (in addition to the + # repo you changed, of course!) + repolist = ["common", "nodemanager", "repy_v2", "seattlelib_v2", "seash", "softwareupdater", "utf"] + for repo in repolist: + print "Running tests for this list of "+ testbed +"\'s repositories: " + repo + + # We will also measure the time elapsed for all tests + test_suite_started_at = time.time() + + # For every repo name, ... + for repo in repolist: + print "Testing " + testbed + '/' + repo + " now..." + print "https://github.com/" + testbed + "/" + repo + ".git" + # Clone the repo + subprocess.call(["git", "clone","https://github.com/" + testbed + "/" + repo + ".git"]) + + # If $repo has a "tests" subdir, then prepare the + # test files and run the tests + if os.path.isdir(repo +os.path.sep +"tests"): + # Measure the time for this single repo's tests + repo_test_started_at = time.time() + os.chdir(repo + os.path.sep +"scripts") + subprocess.call([sys.executable, "initialize.py"]) + subprocess.call([sys.executable, "build.py", "-t"]) + os.chdir(".." + os.path.sep +"RUNNABLE") + subprocess.call([sys.executable, "utf.py", "-a"]) + repo_test_finished_at = time.time() + repo_test_time = str(repo_test_finished_at - repo_test_started_at) + print "Tests for " + testbed + "/" + repo + " took " + repo_test_time + " seconds, excluding download and build" + os.chdir(".." + os.path.sep + "..") + else: + print testbed + "/" + repo + "has no \"tests\" directory. Skipping." + + test_suite_finished_at = time.time() + test_suite_time = str(test_suite_finished_at - test_suite_started_at) + print "Done running tests for " + testbed + ", which took me " + test_suite_time + " seconds overall." + +if __name__ == '__main__': + main() +