Skip to content

Commit c80179a

Browse files
committed
High-level tests into /dev/(null|stdout)
1 parent b6c3086 commit c80179a

File tree

1 file changed

+118
-0
lines changed

1 file changed

+118
-0
lines changed

tests/system.rs

Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,8 @@ const INPUT_FOR_HIP_A: &str = "test_a.hip";
195195
const INPUT_FOR_HIP_B: &str = "test_b.hip";
196196
const INPUT_FOR_HIP_C: &str = "test_c.hip";
197197
const OUTPUT: &str = "test.o";
198+
const DEV_NULL: &str = "/dev/null";
199+
const DEV_STDOUT: &str = "/dev/stdout";
198200

199201
// Copy the source files into the tempdir so we can compile with relative paths, since the commandline winds up in the hash key.
200202
fn copy_to_tempdir(inputs: &[&str], tempdir: &Path) {
@@ -265,6 +267,120 @@ fn test_basic_compile(compiler: Compiler, tempdir: &Path) {
265267
});
266268
}
267269

270+
#[cfg(unix)]
271+
fn test_basic_compile_into_dev_null(compiler: Compiler, tempdir: &Path) {
272+
let Compiler {
273+
name,
274+
exe,
275+
env_vars,
276+
} = compiler;
277+
println!("test_basic_compile: {}", name);
278+
// Compile a source file.
279+
copy_to_tempdir(&[INPUT, INPUT_ERR], tempdir);
280+
281+
let out_file = tempdir.join(OUTPUT);
282+
trace!("compile");
283+
sccache_command()
284+
.args(compile_cmdline(name, &exe, INPUT, DEV_NULL, Vec::new()))
285+
.current_dir(tempdir)
286+
.envs(env_vars.clone())
287+
.assert()
288+
.success();
289+
trace!("request stats");
290+
get_stats(|info| {
291+
assert_eq!(1, info.stats.compile_requests);
292+
assert_eq!(1, info.stats.requests_executed);
293+
assert_eq!(0, info.stats.cache_hits.all());
294+
assert_eq!(1, info.stats.cache_misses.all());
295+
assert_eq!(&1, info.stats.cache_misses.get("C/C++").unwrap());
296+
let adv_key = adv_key_kind("c", compiler.name);
297+
assert_eq!(&1, info.stats.cache_misses.get_adv(&adv_key).unwrap());
298+
});
299+
trace!("compile");
300+
fs::remove_file(&out_file).unwrap();
301+
sccache_command()
302+
.args(compile_cmdline(name, &exe, INPUT, DEV_NULL, Vec::new()))
303+
.current_dir(tempdir)
304+
.envs(env_vars)
305+
.assert()
306+
.success();
307+
assert!(fs::metadata(&out_file).map(|m| m.len() > 0).unwrap());
308+
trace!("request stats");
309+
get_stats(|info| {
310+
assert_eq!(2, info.stats.compile_requests);
311+
assert_eq!(2, info.stats.requests_executed);
312+
assert_eq!(1, info.stats.cache_hits.all());
313+
assert_eq!(1, info.stats.cache_misses.all());
314+
assert_eq!(&1, info.stats.cache_hits.get("C/C++").unwrap());
315+
assert_eq!(&1, info.stats.cache_misses.get("C/C++").unwrap());
316+
let adv_key = adv_key_kind("c", compiler.name);
317+
assert_eq!(&1, info.stats.cache_hits.get_adv(&adv_key).unwrap());
318+
assert_eq!(&1, info.stats.cache_misses.get_adv(&adv_key).unwrap());
319+
});
320+
}
321+
322+
#[cfg(not(unix))]
323+
fn test_basic_compile_into_dev_null(_: Compiler, _: &Path) {
324+
warn!("Not unix, skipping /dev tests");
325+
}
326+
327+
#[cfg(unix)]
328+
fn test_basic_compile_into_dev_stdout(compiler: Compiler, tempdir: &Path) {
329+
let Compiler {
330+
name,
331+
exe,
332+
env_vars,
333+
} = compiler;
334+
println!("test_basic_compile: {}", name);
335+
// Compile a source file.
336+
copy_to_tempdir(&[INPUT, INPUT_ERR], tempdir);
337+
338+
let out_file = tempdir.join(OUTPUT);
339+
trace!("compile");
340+
sccache_command()
341+
.args(compile_cmdline(name, &exe, INPUT, DEV_STDOUT, Vec::new()))
342+
.current_dir(tempdir)
343+
.envs(env_vars.clone())
344+
.assert()
345+
.success();
346+
trace!("request stats");
347+
get_stats(|info| {
348+
assert_eq!(1, info.stats.compile_requests);
349+
assert_eq!(1, info.stats.requests_executed);
350+
assert_eq!(0, info.stats.cache_hits.all());
351+
assert_eq!(1, info.stats.cache_misses.all());
352+
assert_eq!(&1, info.stats.cache_misses.get("C/C++").unwrap());
353+
let adv_key = adv_key_kind("c", compiler.name);
354+
assert_eq!(&1, info.stats.cache_misses.get_adv(&adv_key).unwrap());
355+
});
356+
trace!("compile");
357+
fs::remove_file(&out_file).unwrap();
358+
sccache_command()
359+
.args(compile_cmdline(name, &exe, INPUT, DEV_STDOUT, Vec::new()))
360+
.current_dir(tempdir)
361+
.envs(env_vars)
362+
.assert()
363+
.success();
364+
assert!(fs::metadata(&out_file).map(|m| m.len() > 0).unwrap());
365+
trace!("request stats");
366+
get_stats(|info| {
367+
assert_eq!(2, info.stats.compile_requests);
368+
assert_eq!(2, info.stats.requests_executed);
369+
assert_eq!(1, info.stats.cache_hits.all());
370+
assert_eq!(1, info.stats.cache_misses.all());
371+
assert_eq!(&1, info.stats.cache_hits.get("C/C++").unwrap());
372+
assert_eq!(&1, info.stats.cache_misses.get("C/C++").unwrap());
373+
let adv_key = adv_key_kind("c", compiler.name);
374+
assert_eq!(&1, info.stats.cache_hits.get_adv(&adv_key).unwrap());
375+
assert_eq!(&1, info.stats.cache_misses.get_adv(&adv_key).unwrap());
376+
});
377+
}
378+
379+
#[cfg(not(unix))]
380+
fn test_basic_compile_into_dev_stdout(_: Compiler, _: &Path) {
381+
warn!("Not unix, skipping /dev tests");
382+
}
383+
268384
fn test_noncacheable_stats(compiler: Compiler, tempdir: &Path) {
269385
let Compiler {
270386
name,
@@ -631,6 +747,8 @@ fn run_sccache_command_tests(compiler: Compiler, tempdir: &Path, preprocessor_ca
631747
test_basic_compile(compiler.clone(), tempdir);
632748
}
633749
test_compile_with_define(compiler.clone(), tempdir);
750+
test_basic_compile_into_dev_null(compiler.clone(), tempdir);
751+
test_basic_compile_into_dev_stdout(compiler.clone(), tempdir);
634752
if compiler.name == "cl.exe" {
635753
test_msvc_deps(compiler.clone(), tempdir);
636754
test_msvc_responsefile(compiler.clone(), tempdir);

0 commit comments

Comments
 (0)