Skip to content

Commit b15b55b

Browse files
committed
Divide test run between multiple travis builds.
1 parent 4379e2f commit b15b55b

File tree

3 files changed

+46
-5
lines changed

3 files changed

+46
-5
lines changed

.travis.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ matrix:
1212
fast_finish: true
1313
include:
1414
# Linux builders, all docker images
15+
- env: IMAGE=x86_64-gnu-llvm-3.7 ALLOW_PR=1 RUST_BACKTRACE=1 BOOTSTRAP_ARGS="--slice 0 --number-slices 4"
16+
- env: IMAGE=x86_64-gnu-llvm-3.7 ALLOW_PR=1 RUST_BACKTRACE=1 BOOTSTRAP_ARGS="--slice 1 --number-slices 4"
17+
- env: IMAGE=x86_64-gnu-llvm-3.7 ALLOW_PR=1 RUST_BACKTRACE=1 BOOTSTRAP_ARGS="--slice 2 --number-slices 4"
18+
- env: IMAGE=x86_64-gnu-llvm-3.7 ALLOW_PR=1 RUST_BACKTRACE=1 BOOTSTRAP_ARGS="--slice 3 --number-slices 4"
1519
- env: IMAGE=android DEPLOY=1
1620
- env: IMAGE=armhf-gnu
1721
- env: IMAGE=cross DEPLOY=1
@@ -33,7 +37,6 @@ matrix:
3337
- env: IMAGE=x86_64-gnu-aux
3438
- env: IMAGE=x86_64-gnu-debug
3539
- env: IMAGE=x86_64-gnu-nopt
36-
- env: IMAGE=x86_64-gnu-llvm-3.7 ALLOW_PR=1 RUST_BACKTRACE=1
3740
- env: IMAGE=x86_64-gnu-distcheck
3841
- env: IMAGE=x86_64-gnu-incremental
3942

src/bootstrap/flags.rs

+18
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ pub enum Subcommand {
6060
Test {
6161
paths: Vec<PathBuf>,
6262
test_args: Vec<String>,
63+
split: Option<(usize, usize)>,
6364
},
6465
Bench {
6566
paths: Vec<PathBuf>,
@@ -224,10 +225,27 @@ To learn more about a subcommand, run `./x.py <command> -h`
224225
}
225226
"test" => {
226227
opts.optmulti("", "test-args", "extra arguments", "ARGS");
228+
opts.optopt("",
229+
"number-slices",
230+
"divide the test run in N segments",
231+
"N");
232+
opts.optopt("",
233+
"slice",
234+
"run ith segment",
235+
"i");
227236
m = parse(&opts);
237+
let split = match (m.opt_str("slice"), m.opt_str("number-slices")) {
238+
(Some(raw_slice), Some(raw_nb_slices)) => {
239+
Some((raw_slice.parse().unwrap(),
240+
raw_nb_slices.parse().unwrap()))
241+
}
242+
(None, None) => None,
243+
_ => panic!("You must provide --slice and --number-slices"),
244+
};
228245
Subcommand::Test {
229246
paths: remaining_as_path(&m),
230247
test_args: m.opt_strs("test-args"),
248+
split: split,
231249
}
232250
}
233251
"bench" => {

src/bootstrap/step.rs

+24-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
2929
use std::collections::{HashMap, HashSet};
3030
use std::mem;
31+
use std::cmp::min;
3132

3233
use check::{self, TestKind};
3334
use compile;
@@ -982,10 +983,14 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
982983
// product of the two and then create a step based off them. Note that
983984
// the stage each step is associated was specified with the `--step`
984985
// flag on the command line.
986+
let mut split = None;
985987
let (kind, paths) = match self.build.flags.cmd {
986988
Subcommand::Build { ref paths } => (Kind::Build, &paths[..]),
987989
Subcommand::Doc { ref paths } => (Kind::Doc, &paths[..]),
988-
Subcommand::Test { ref paths, test_args: _ } => (Kind::Test, &paths[..]),
990+
Subcommand::Test { ref paths, test_args: _, split: new_split } => {
991+
split = new_split;
992+
(Kind::Test, &paths[..])
993+
}
989994
Subcommand::Bench { ref paths, test_args: _ } => (Kind::Bench, &paths[..]),
990995
Subcommand::Dist { ref paths, install } => {
991996
if install {
@@ -996,8 +1001,7 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
9961001
}
9971002
Subcommand::Clean => panic!(),
9981003
};
999-
1000-
self.rules.values().filter(|rule| rule.kind == kind).filter(|rule| {
1004+
let steps = self.rules.values().filter(|rule| rule.kind == kind).filter(|rule| {
10011005
(paths.len() == 0 && rule.default) || paths.iter().any(|path| {
10021006
path.ends_with(rule.path)
10031007
})
@@ -1041,7 +1045,23 @@ invalid rule dependency graph detected, was a rule added and maybe typo'd?
10411045
self.sbuild.name(rule.name).target(target).host(host)
10421046
})
10431047
})
1044-
}).collect()
1048+
}).collect::<Vec<_>>();
1049+
1050+
if let Some((offset, nb_split)) = split {
1051+
assert!(nb_split <= steps.len(),
1052+
"you asked for {} slices but there are only {} tasks",
1053+
nb_split,
1054+
steps.len());
1055+
let index = |i| {
1056+
i * (steps.len() / nb_split) + min(steps.len() % nb_split, i)
1057+
};
1058+
let from = index(offset);
1059+
let to = index(offset + 1);
1060+
steps[from..to].into()
1061+
} else {
1062+
steps
1063+
}
1064+
10451065
}
10461066

10471067
/// Execute all top-level targets indicated by `steps`.

0 commit comments

Comments
 (0)