Skip to content

Commit e7507d6

Browse files
committed
Auto merge of rust-lang#2207 - RalfJung:ui_test_parallelism, r=oli-obk
ui_test: ensure all worker threads stay around Also organize files such that the by far slowest test (weak_memory/consistency) always starts first. It still finishes last on my system... even after I halved the iteration count. Fixes rust-lang/miri#2204
2 parents 4c1f50b + c16c453 commit e7507d6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+36
-17
lines changed

tests/pass/weak_memory/consistency.rs renamed to tests/pass/0weak_memory_consistency.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn test_single_thread() {
214214
}
215215

216216
pub fn main() {
217-
for _ in 0..100 {
217+
for _ in 0..50 {
218218
test_single_thread();
219219
test_mixed_access();
220220
test_load_buffering_acq_rel();
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

ui_test/README.md

+5

ui_test/src/lib.rs

+30-16
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::collections::VecDeque;
12
use std::fmt::Write;
23
use std::path::{Path, PathBuf};
34
use std::process::{Command, ExitStatus};
@@ -6,7 +7,6 @@ use std::sync::Mutex;
67

78
use colored::*;
89
use comments::ErrorMatch;
9-
use crossbeam::queue::SegQueue;
1010
use regex::Regex;
1111
use rustc_stderr::{Level, Message};
1212

@@ -55,9 +55,8 @@ pub fn run_tests(config: Config) {
5555
// Get the triple with which to run the tests
5656
let target = config.target.clone().unwrap_or_else(|| config.get_host());
5757

58-
// A queue for files or folders to process
59-
let todo = SegQueue::new();
60-
todo.push(config.root_dir.clone());
58+
// A channel for files to process
59+
let (submit, receive) = crossbeam::channel::unbounded();
6160

6261
// Some statistics and failure reports.
6362
let failures = Mutex::new(vec![]);
@@ -66,20 +65,35 @@ pub fn run_tests(config: Config) {
6665
let filtered = AtomicUsize::default();
6766

6867
crossbeam::scope(|s| {
68+
// Create a thread that is in charge of walking the directory and submitting jobs.
69+
// It closes the channel when it is done.
70+
s.spawn(|_| {
71+
let mut todo = VecDeque::new();
72+
todo.push_back(config.root_dir.clone());
73+
while let Some(path) = todo.pop_front() {
74+
if path.is_dir() {
75+
// Enqueue everything inside this directory.
76+
// We want it sorted, to have some control over scheduling of slow tests.
77+
let mut entries =
78+
std::fs::read_dir(path).unwrap().collect::<Result<Vec<_>, _>>().unwrap();
79+
entries.sort_by_key(|e| e.file_name());
80+
for entry in entries {
81+
todo.push_back(entry.path());
82+
}
83+
} else if path.extension().map(|ext| ext == "rs").unwrap_or(false) {
84+
// Forward .rs files to the test workers.
85+
submit.send(path).unwrap();
86+
}
87+
}
88+
// There will be no more jobs. This signals the workers to quit.
89+
// (This also ensures `submit` is moved into this closure.)
90+
drop(submit);
91+
});
92+
93+
// Create N worker threads that receive files to test.
6994
for _ in 0..std::thread::available_parallelism().unwrap().get() {
7095
s.spawn(|_| {
71-
while let Some(path) = todo.pop() {
72-
// Collect everything inside directories
73-
if path.is_dir() {
74-
for entry in std::fs::read_dir(path).unwrap() {
75-
todo.push(entry.unwrap().path());
76-
}
77-
continue;
78-
}
79-
// Only look at .rs files
80-
if !path.extension().map(|ext| ext == "rs").unwrap_or(false) {
81-
continue;
82-
}
96+
for path in &receive {
8397
if !config.path_filter.is_empty() {
8498
let path_display = path.display().to_string();
8599
if !config.path_filter.iter().any(|filter| path_display.contains(filter)) {

0 commit comments

Comments
 (0)