Skip to content

Commit c923b6c

Browse files
committed
minicrater: test network access and memory limit
1 parent ff6e899 commit c923b6c

File tree

11 files changed

+153
-1
lines changed

11 files changed

+153
-1
lines changed

local-crates/memory-hungry/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "memory-hungry"
3+
version = "0.1.0"
4+
authors = ["Pietro Albini <[email protected]>"]
5+
6+
[dependencies]
7+
8+
[build-dependencies]
9+
rustc_version = "0.2.3"

local-crates/memory-hungry/build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extern crate rustc_version;
2+
3+
#[path = "src/allocate.rs"]
4+
mod allocate;
5+
6+
use rustc_version::{version_meta, Channel};
7+
8+
fn main() {
9+
if let Channel::Beta = version_meta().unwrap().channel {
10+
// On the beta channel allocate in tests
11+
println!("cargo:rustc-cfg=channel_beta");
12+
} else {
13+
// On the stable channel allocate in build.rs
14+
allocate::allocate();
15+
}
16+
17+
// Rebuild the crate only if the build.rs file changes
18+
println!("cargo:rebuild-if-changed=build.rs");
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
const MAX_ALLOCATE: usize = 1_073_741_824;
2+
3+
pub fn allocate() {
4+
let data = [0u8; 4096];
5+
let mut allocated = 0;
6+
7+
while allocated < MAX_ALLOCATE {
8+
Box::leak(Box::new(data));
9+
allocated += data.len();
10+
}
11+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[cfg(channel_beta)]
2+
mod allocate;
3+
4+
fn main() {
5+
println!("Hello world");
6+
}
7+
8+
#[test]
9+
#[cfg(channel_beta)]
10+
fn test_allocate() {
11+
allocate::allocate();
12+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[package]
2+
name = "network-access"
3+
version = "0.1.0"
4+
authors = ["Pietro Albini <[email protected]>"]
5+
6+
[dependencies]
7+
8+
[build-dependencies]
9+
rustc_version = "0.2.3"

local-crates/network-access/build.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
extern crate rustc_version;
2+
3+
#[path = "src/network.rs"]
4+
mod network;
5+
6+
use rustc_version::{version_meta, Channel};
7+
8+
fn main() {
9+
if let Channel::Beta = version_meta().unwrap().channel {
10+
// On the beta channel connect to the network in tests
11+
println!("cargo:rustc-cfg=channel_beta");
12+
} else {
13+
// On the stable channel connect to the network in build.rs
14+
network::call();
15+
}
16+
17+
// Rebuild the crate only if the build.rs file changes
18+
println!("cargo:rebuild-if-changed=build.rs");
19+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#[cfg(channel_beta)]
2+
mod network;
3+
4+
fn main() {
5+
println!("Hello, world!");
6+
}
7+
8+
#[cfg(channel_beta)]
9+
#[test]
10+
fn test_network_access() {
11+
network::call();
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
use std::net::TcpStream;
2+
3+
pub fn call() {
4+
// Try to connect to www.rust-lang.org:80
5+
// If network access is disabled even this should fail
6+
let _ = TcpStream::connect("www.rust-lang.org:80").unwrap();
7+
}

tests/minicrater/config.toml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
[server]
2+
bot-acl = [
3+
"pietroalbini",
4+
]
5+
6+
[server.labels]
7+
remove = "^S-"
8+
experiment-queued = "S-waiting-on-crater"
9+
experiment-completed = "S-waiting-on-review"
10+
11+
[demo-crates]
12+
crates = ["lazy_static"]
13+
github-repos = ["brson/hello-rs"]
14+
15+
[sandbox]
16+
memory-limit = "512M"
17+
18+
[crates]
19+
20+
[github-repos]

tests/minicrater/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn run() {
2222
// Create local list in the temp work dir
2323
Command::crater()
2424
.args(&["create-lists", "local"])
25+
.env("CRATER_CONFIG", "tests/minicrater/config.toml")
2526
.assert()
2627
.success();
2728

@@ -33,18 +34,21 @@ fn run() {
3334
"stable",
3435
"beta",
3536
"--crate-select=local",
36-
]).assert()
37+
]).env("CRATER_CONFIG", "tests/minicrater/config.toml")
38+
.assert()
3739
.success();
3840

3941
// Execute the experiment
4042
Command::crater()
4143
.args(&["run-graph", &ex_arg])
44+
.env("CRATER_CONFIG", "tests/minicrater/config.toml")
4245
.assert()
4346
.success();
4447

4548
// Generate the report
4649
Command::crater()
4750
.args(&["gen-report", &ex_arg])
51+
.env("CRATER_CONFIG", "tests/minicrater/config.toml")
4852
.arg(report_dir.path())
4953
.assert()
5054
.success();

tests/minicrater/results.expected.json

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,36 @@
6060
],
6161
"url": "https://github.com/rust-lang-nursery/crater/tree/master/local-crates/build-pass"
6262
},
63+
{
64+
"name": "memory-hungry (local)",
65+
"res": "Fixed",
66+
"runs": [
67+
{
68+
"log": "stable/local/memory-hungry",
69+
"res": "BuildFail"
70+
},
71+
{
72+
"log": "beta/local/memory-hungry",
73+
"res": "TestFail"
74+
}
75+
],
76+
"url": "https://github.com/rust-lang-nursery/crater/tree/master/local-crates/memory-hungry"
77+
},
78+
{
79+
"name": "network-access (local)",
80+
"res": "Fixed",
81+
"runs": [
82+
{
83+
"log": "stable/local/network-access",
84+
"res": "BuildFail"
85+
},
86+
{
87+
"log": "beta/local/network-access",
88+
"res": "TestFail"
89+
}
90+
],
91+
"url": "https://github.com/rust-lang-nursery/crater/tree/master/local-crates/network-access"
92+
},
6393
{
6494
"name": "test-fail (local)",
6595
"res": "SameTestFail",

0 commit comments

Comments
 (0)