1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#[cfg(test)]
pub mod tests {
use std::process::Command;
// cargo run -p test-mutex-std --example basic_mutex_std --features hotpath
#[test]
fn test_basic_output() {
let output = Command::new("cargo")
.args([
"run",
"-p",
"test-mutex-std",
"--example",
"basic_mutex_std",
"--features",
"hotpath",
])
.output()
.expect("Failed to execute command");
assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
let stdout = String::from_utf8_lossy(&output.stdout);
let all_expected = [
"Std Mutex example completed!",
"mutexes",
"counter",
"Locks",
"Wait avg",
"Acq avg",
];
for expected in all_expected {
assert!(
stdout.contains(expected),
"Expected:\n{expected}\n\nGot:\n{stdout}",
);
}
}
// cargo run -p test-mutex-std --example basic_mutex_std --features hotpath (json)
#[test]
fn test_json_output() {
let output = Command::new("cargo")
.args([
"run",
"-p",
"test-mutex-std",
"--example",
"basic_mutex_std",
"--features",
"hotpath",
])
.env("HOTPATH_OUTPUT_FORMAT", "json")
.output()
.expect("Failed to execute command");
assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
let stdout = String::from_utf8_lossy(&output.stdout);
let all_expected = [
"\"mutexes\"",
"\"label\":\"counter\"",
"\"count\":6",
"\"wait_avg\"",
"\"acquire_avg\"",
"\"wait_percentiles\"",
"\"acquire_percentiles\"",
];
for expected in all_expected {
assert!(
stdout.contains(expected),
"Expected:\n{expected}\n\nGot:\n{stdout}",
);
}
}
// Locks recorded on a thread whose event queue drains ahead of the queue
// carrying `Created` must still be counted (placeholder backfill).
// cargo run -p test-mutex-std --example created_ordering --features hotpath (json)
#[test]
fn test_created_ordering_output() {
let output = Command::new("cargo")
.args([
"run",
"-p",
"test-mutex-std",
"--example",
"created_ordering",
"--features",
"hotpath",
])
.env("HOTPATH_OUTPUT_FORMAT", "json")
.output()
.expect("Failed to execute command");
assert!(
output.status.success(),
"Command failed with status: {}",
output.status
);
let stdout = String::from_utf8_lossy(&output.stdout);
let all_expected = ["\"label\":\"target\"", "\"count\":100"];
for expected in all_expected {
assert!(
stdout.contains(expected),
"Expected:\n{expected}\n\nGot:\n{stdout}",
);
}
}
}