Christian Duvivier | 3a82bf4 | 2011-12-22 16:04:15 -0800 | [diff] [blame] | 1 | #!/usr/bin/python |
| 2 | |
John Koleszar | 778393c | 2012-08-21 11:18:38 -0700 | [diff] [blame] | 3 | import getopt |
Christian Duvivier | 3a82bf4 | 2011-12-22 16:04:15 -0800 | [diff] [blame] | 4 | import subprocess |
| 5 | import sys |
| 6 | |
John Koleszar | 778393c | 2012-08-21 11:18:38 -0700 | [diff] [blame] | 7 | LONG_OPTIONS = ["shard=", "shards="] |
John Koleszar | a9c7597 | 2012-11-08 17:09:30 -0800 | [diff] [blame] | 8 | BASE_COMMAND = "./configure --enable-internal-stats --enable-experimental" |
John Koleszar | 778393c | 2012-08-21 11:18:38 -0700 | [diff] [blame] | 9 | |
Christian Duvivier | 3a82bf4 | 2011-12-22 16:04:15 -0800 | [diff] [blame] | 10 | def RunCommand(command): |
| 11 | run = subprocess.Popen(command, shell=True) |
| 12 | output = run.communicate() |
| 13 | if run.returncode: |
| 14 | print "Non-zero return code: " + str(run.returncode) + " => exiting!" |
| 15 | sys.exit(1) |
| 16 | |
| 17 | def list_of_experiments(): |
| 18 | experiments = [] |
| 19 | configure_file = open("configure") |
| 20 | list_start = False |
| 21 | for line in configure_file.read().split("\n"): |
| 22 | if line == 'EXPERIMENT_LIST="': |
| 23 | list_start = True |
| 24 | elif line == '"': |
| 25 | list_start = False |
| 26 | elif list_start: |
| 27 | currently_broken = ["csm"] |
| 28 | experiment = line[4:] |
| 29 | if experiment not in currently_broken: |
| 30 | experiments.append(experiment) |
| 31 | return experiments |
| 32 | |
John Koleszar | 778393c | 2012-08-21 11:18:38 -0700 | [diff] [blame] | 33 | def main(argv): |
| 34 | # Parse arguments |
| 35 | options = {"--shard": 0, "--shards": 1} |
John Koleszar | 307541d | 2012-08-22 10:48:20 -0700 | [diff] [blame] | 36 | if "--" in argv: |
| 37 | opt_end_index = argv.index("--") |
| 38 | else: |
| 39 | opt_end_index = len(argv) |
| 40 | try: |
| 41 | o, _ = getopt.getopt(argv[1:opt_end_index], None, LONG_OPTIONS) |
| 42 | except getopt.GetoptError, err: |
| 43 | print str(err) |
| 44 | print "Usage: %s [--shard=<n> --shards=<n>] -- [configure flag ...]"%argv[0] |
| 45 | sys.exit(2) |
| 46 | |
John Koleszar | 778393c | 2012-08-21 11:18:38 -0700 | [diff] [blame] | 47 | options.update(o) |
John Koleszar | 307541d | 2012-08-22 10:48:20 -0700 | [diff] [blame] | 48 | extra_args = argv[opt_end_index + 1:] |
John Koleszar | 778393c | 2012-08-21 11:18:38 -0700 | [diff] [blame] | 49 | |
| 50 | # Shard experiment list |
| 51 | shard = int(options["--shard"]) |
| 52 | shards = int(options["--shards"]) |
| 53 | experiments = list_of_experiments() |
John Koleszar | 307541d | 2012-08-22 10:48:20 -0700 | [diff] [blame] | 54 | base_command = " ".join([BASE_COMMAND] + extra_args) |
| 55 | configs = [base_command] |
| 56 | configs += ["%s --enable-%s" % (base_command, e) for e in experiments] |
John Koleszar | 778393c | 2012-08-21 11:18:38 -0700 | [diff] [blame] | 57 | my_configs = zip(configs, range(len(configs))) |
| 58 | my_configs = filter(lambda x: x[1] % shards == shard, my_configs) |
| 59 | my_configs = [e[0] for e in my_configs] |
| 60 | |
| 61 | # Run configs for this shard |
| 62 | for config in my_configs: |
| 63 | test_build(config) |
Christian Duvivier | 3a82bf4 | 2011-12-22 16:04:15 -0800 | [diff] [blame] | 64 | |
| 65 | def test_build(configure_command): |
| 66 | print "\033[34m\033[47mTesting %s\033[0m" % (configure_command) |
| 67 | RunCommand(configure_command) |
| 68 | RunCommand("make clean") |
| 69 | RunCommand("make") |
| 70 | |
| 71 | if __name__ == "__main__": |
John Koleszar | 778393c | 2012-08-21 11:18:38 -0700 | [diff] [blame] | 72 | main(sys.argv) |