|
| 1 | +//! This test checks if unstable feature usage metric dump files `unstable-feature-usage*.json` work |
| 2 | +//! as expected. |
| 3 | +//! |
| 4 | +//! - Basic sanity checks on a default ICE dump. |
| 5 | +//! |
| 6 | +//! See <https://github.com./rust-lang/rust/issues/129485>. |
| 7 | +//! |
| 8 | +//! # Test history |
| 9 | +//! |
| 10 | +//! - forked from dump-ice-to-disk test, which has flakeyness issues on i686-mingw, I'm assuming |
| 11 | +//! those will be present in this test as well on the same platform |
| 12 | +
|
| 13 | +//@ ignore-windows |
| 14 | +//FIXME(#128911): still flakey on i686-mingw. |
| 15 | + |
| 16 | +use std::path::{Path, PathBuf}; |
| 17 | + |
| 18 | +use run_make_support::rfs::create_dir_all; |
| 19 | +use run_make_support::{ |
| 20 | + cwd, filename_contains, has_extension, rfs, run_in_tmpdir, rustc, serde_json, |
| 21 | + shallow_find_files, |
| 22 | +}; |
| 23 | + |
| 24 | +fn find_feature_usage_metrics<P: AsRef<Path>>(dir: P) -> Vec<PathBuf> { |
| 25 | + shallow_find_files(dir, |path| { |
| 26 | + if filename_contains(path, "unstable_feature_usage") && has_extension(path, "json") { |
| 27 | + true |
| 28 | + } else { |
| 29 | + dbg!(path); |
| 30 | + false |
| 31 | + } |
| 32 | + }) |
| 33 | +} |
| 34 | + |
| 35 | +fn main() { |
| 36 | + test_metrics_dump(); |
| 37 | + test_metrics_errors(); |
| 38 | +} |
| 39 | + |
| 40 | +#[track_caller] |
| 41 | +fn test_metrics_dump() { |
| 42 | + run_in_tmpdir(|| { |
| 43 | + let metrics_dir = cwd().join("metrics"); |
| 44 | + create_dir_all(&metrics_dir); |
| 45 | + rustc() |
| 46 | + .input("lib.rs") |
| 47 | + .incremental("incremental") |
| 48 | + .env("RUST_BACKTRACE", "short") |
| 49 | + .arg(format!("-Zmetrics-dir={}", metrics_dir.display())) |
| 50 | + .run(); |
| 51 | + let mut metrics = find_feature_usage_metrics(&metrics_dir); |
| 52 | + let json_path = |
| 53 | + metrics.pop().expect("there should be one metrics file in the output directory"); |
| 54 | + |
| 55 | + // After the `pop` above, there should be no files left. |
| 56 | + assert!( |
| 57 | + metrics.is_empty(), |
| 58 | + "there should be no more than one metrics file in the output directory" |
| 59 | + ); |
| 60 | + |
| 61 | + let message = rfs::read_to_string(json_path); |
| 62 | + let mut parsed: serde_json::Value = |
| 63 | + serde_json::from_str(&message).expect("metrics should be dumped as json"); |
| 64 | + // remove timestamps |
| 65 | + assert!(parsed["lib_features"][0]["timestamp"].is_number()); |
| 66 | + assert!(parsed["lang_features"][0]["timestamp"].is_number()); |
| 67 | + parsed["lib_features"][0]["timestamp"] = serde_json::json!(null); |
| 68 | + parsed["lang_features"][0]["timestamp"] = serde_json::json!(null); |
| 69 | + let expected = serde_json::json!( |
| 70 | + { |
| 71 | + "lib_features":[{"symbol":"ascii_char", "timestamp":null}], |
| 72 | + "lang_features":[{"symbol":"box_patterns","since":null, "timestamp":null}] |
| 73 | + } |
| 74 | + ); |
| 75 | + |
| 76 | + assert_eq!(expected, parsed); |
| 77 | + }); |
| 78 | +} |
| 79 | + |
| 80 | +#[track_caller] |
| 81 | +fn test_metrics_errors() { |
| 82 | + run_in_tmpdir(|| { |
| 83 | + rustc() |
| 84 | + .input("lib.rs") |
| 85 | + .incremental("incremental") |
| 86 | + .env("RUST_BACKTRACE", "short") |
| 87 | + .arg("-Zmetrics-dir=invaliddirectorythatdefinitelydoesntexist") |
| 88 | + .run_fail() |
| 89 | + .assert_stderr_contains( |
| 90 | + "error: cannot dump feature usage metrics: No such file or directory", |
| 91 | + ) |
| 92 | + .assert_stdout_not_contains("internal compiler error"); |
| 93 | + }); |
| 94 | +} |
0 commit comments