Skip to content

Run the tests of popular crates in the CI #426

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
"--extended-regex-tests",
"--test-successful-rustc --nb-parts 2 --current-part 0",
"--test-successful-rustc --nb-parts 2 --current-part 1",
"--projects",
]

steps:
Expand Down
2 changes: 1 addition & 1 deletion build_system/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ fn clone_and_setup<F>(repo_url: &str, checkout_commit: &str, extra: Option<F>) -
where
F: Fn(&Path) -> Result<(), String>,
{
let clone_result = git_clone(repo_url, None)?;
let clone_result = git_clone(repo_url, None, false)?;
if !clone_result.ran_clone {
println!("`{}` has already been cloned", clone_result.repo_name);
}
Expand Down
56 changes: 54 additions & 2 deletions build_system/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::build;
use crate::config::{Channel, ConfigInfo};
use crate::utils::{
get_gcc_path, get_toolchain, remove_file, run_command, run_command_with_env,
get_gcc_path, get_toolchain, git_clone, remove_file, run_command, run_command_with_env,
run_command_with_output_and_env, rustc_version_info, split_args, walk_dir,
};

use std::collections::{BTreeSet, HashMap};
use std::ffi::OsStr;
use std::fs::{remove_dir_all, File};
use std::fs::{create_dir_all, remove_dir_all, File};
use std::io::{BufRead, BufReader};
use std::path::{Path, PathBuf};
use std::str::FromStr;
Expand All @@ -31,6 +31,7 @@ fn get_runners() -> Runners {
"--test-failing-rustc",
("Run failing rustc tests", test_failing_rustc),
);
runners.insert("--projects", ("Run the tests of popular crates", test_projects));
runners.insert("--test-libcore", ("Run libcore tests", test_libcore));
runners.insert("--clean", ("Empty cargo target directory", clean));
runners.insert("--build-sysroot", ("Build sysroot", build_sysroot));
Expand Down Expand Up @@ -679,6 +680,57 @@ where
// echo "[BUILD] sysroot in release mode"
// ./build_sysroot/build_sysroot.sh --release

fn test_projects(env: &Env, args: &TestArg) -> Result<(), String> {
let projects = [
//"https://gitlab.gnome.org/GNOME/librsvg", // FIXME: doesn't compile in the CI since the
// version of cairo and other libraries is too old.
"https://github.com/rust-random/getrandom",
"https://github.com/BurntSushi/memchr",
"https://github.com/dtolnay/itoa",
"https://github.com/rust-lang/cfg-if",
"https://github.com/rust-lang-nursery/lazy-static.rs",
//"https://github.com/marshallpierce/rust-base64", // FIXME: one test is OOM-killed.
// TODO: ignore the base64 test that is OOM-killed.
"https://github.com/time-rs/time",
"https://github.com/rust-lang/log",
"https://github.com/bitflags/bitflags",
//"https://github.com/serde-rs/serde", // FIXME: one test fails.
//"https://github.com/rayon-rs/rayon", // TODO: very slow, only run on master?
//"https://github.com/rust-lang/cargo", // TODO: very slow, only run on master?
];

let run_tests = |projects_path, iter: &mut dyn Iterator<Item=&&str>| -> Result<(), String> {
for project in iter {
let clone_result = git_clone(project, Some(projects_path), true)?;
let repo_path = Path::new(&clone_result.repo_dir);
run_cargo_command(&[&"build", &"--release"], Some(repo_path), env, args)?;
run_cargo_command(&[&"test"], Some(repo_path), env, args)?;
}

Ok(())
};

let projects_path = Path::new("projects");
create_dir_all(projects_path)
.map_err(|err| format!("Failed to create directory `projects`: {}", err))?;

let nb_parts = args.nb_parts.unwrap_or(0);
if nb_parts > 0 {
// We increment the number of tests by one because if this is an odd number, we would skip
// one test.
let count = projects.len() / nb_parts + 1;
let current_part = args.current_part.unwrap();
let start = current_part * count;
// We remove the projects we don't want to test.
run_tests(projects_path, &mut projects.iter().skip(start).take(count))?;
}
else {
run_tests(projects_path, &mut projects.iter())?;
}

Ok(())
}

fn test_libcore(env: &Env, args: &TestArg) -> Result<(), String> {
// FIXME: create a function "display_if_not_quiet" or something along the line.
println!("[TEST] libcore");
Expand Down
12 changes: 10 additions & 2 deletions build_system/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ pub fn get_gcc_path() -> Result<String, String> {
pub struct CloneResult {
pub ran_clone: bool,
pub repo_name: String,
pub repo_dir: String,
}

pub fn git_clone(to_clone: &str, dest: Option<&Path>) -> Result<CloneResult, String> {
pub fn git_clone(to_clone: &str, dest: Option<&Path>, shallow_clone: bool) -> Result<CloneResult, String> {
let repo_name = to_clone.split('/').last().unwrap();
let repo_name = match repo_name.strip_suffix(".git") {
Some(n) => n.to_string(),
Expand All @@ -299,13 +300,20 @@ pub fn git_clone(to_clone: &str, dest: Option<&Path>) -> Result<CloneResult, Str
return Ok(CloneResult {
ran_clone: false,
repo_name,
repo_dir: dest.display().to_string(),
});
}

run_command_with_output(&[&"git", &"clone", &to_clone, &dest], None)?;
let mut command: Vec<&dyn AsRef<OsStr>> = vec![&"git", &"clone", &to_clone, &dest];
if shallow_clone {
command.push(&"--depth");
command.push(&"1");
}
run_command_with_output(&command, None)?;
Ok(CloneResult {
ran_clone: true,
repo_name,
repo_dir: dest.display().to_string(),
})
}

Expand Down