Skip to content

Commit 790d752

Browse files
committed
fix: use runner-shared for deserialization tests
1 parent bcc85db commit 790d752

File tree

3 files changed

+219
-20
lines changed

3 files changed

+219
-20
lines changed

src/tests/deserialize_rust/create_serialized.rs

Lines changed: 52 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,11 @@
1212
//! [dependencies]
1313
//! bincode = "1.3.3"
1414
//! serde = { version = "1.0.192", features = ["derive"] }
15+
//! runner-shared = { git = "https://github.com/CodSpeedHQ/runner" }
1516
//! ```
1617
17-
// WARNING: Has to be in sync with `runner`.
18-
mod shared {
19-
#[derive(serde::Serialize, serde::Deserialize, Debug, PartialEq)]
20-
pub enum Command {
21-
ExecutedBenchmark { pid: u32, uri: String },
22-
StartBenchmark,
23-
StopBenchmark,
24-
Ack,
25-
PingPerf,
26-
SetIntegration { name: String, version: String },
27-
Err,
28-
}
29-
}
18+
// Import from runner-shared to ensure we use the same types
19+
use runner_shared::fifo::{Command, MarkerType, RunnerMode};
3020

3121
fn dump(name: &str, result: &Vec<u8>) {
3222
print!("pub const {}: []const u8 = &.{{ ", name);
@@ -47,21 +37,63 @@ fn main() {
4737

4838
example(
4939
"cmd_cur_bench",
50-
&shared::Command::ExecutedBenchmark {
40+
&Command::CurrentBenchmark {
5141
pid: 12345,
5242
uri: "http://example.com/benchmark".to_string(),
5343
},
5444
);
55-
example("cmd_start_bench", &shared::Command::StartBenchmark);
56-
example("cmd_stop_bench", &shared::Command::StopBenchmark);
57-
example("cmd_ack", &shared::Command::Ack);
58-
example("cmd_ping_perf", &shared::Command::PingPerf);
45+
example("cmd_start_bench", &Command::StartBenchmark);
46+
example("cmd_stop_bench", &Command::StopBenchmark);
47+
example("cmd_ack", &Command::Ack);
48+
example("cmd_ping_perf", &Command::PingPerf);
5949
example(
6050
"cmd_set_integration",
61-
&shared::Command::SetIntegration {
51+
&Command::SetIntegration {
6252
name: "test-integration".to_string(),
6353
version: "1.0.0".to_string(),
6454
},
6555
);
66-
example("cmd_err", &shared::Command::Err);
56+
example("cmd_err", &Command::Err);
57+
example(
58+
"cmd_add_marker_sample_start",
59+
&Command::AddMarker {
60+
pid: 12345,
61+
marker: MarkerType::SampleStart(1000),
62+
},
63+
);
64+
example(
65+
"cmd_add_marker_sample_end",
66+
&Command::AddMarker {
67+
pid: 12345,
68+
marker: MarkerType::SampleEnd(2000),
69+
},
70+
);
71+
example(
72+
"cmd_add_marker_benchmark_start",
73+
&Command::AddMarker {
74+
pid: 12345,
75+
marker: MarkerType::BenchmarkStart(3000),
76+
},
77+
);
78+
example(
79+
"cmd_add_marker_benchmark_end",
80+
&Command::AddMarker {
81+
pid: 12345,
82+
marker: MarkerType::BenchmarkEnd(4000),
83+
},
84+
);
85+
example("cmd_set_version", &Command::SetVersion(1));
86+
example("cmd_get_runner_mode", &Command::GetRunnerMode);
87+
example(
88+
"cmd_runner_mode_perf",
89+
&Command::RunnerModeResponse(RunnerMode::Perf),
90+
);
91+
example(
92+
"cmd_runner_mode_simulation",
93+
&Command::RunnerModeResponse(RunnerMode::Simulation),
94+
);
95+
example(
96+
"cmd_runner_mode_analysis",
97+
&Command::RunnerModeResponse(RunnerMode::Analysis),
98+
);
6799
}

src/tests/deserialize_rust/rust_deser.zig

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,33 @@ test "rust deserialization" {
2828
.version = "1.0.0",
2929
} });
3030
try assert_eq(rust.cmd_err, Command{ .Err = {} });
31+
32+
// AddMarker commands
33+
try assert_eq(rust.cmd_add_marker_sample_start, Command{ .AddMarker = .{
34+
.pid = 12345,
35+
.marker = shared.MarkerType{ .SampleStart = 1000 },
36+
} });
37+
try assert_eq(rust.cmd_add_marker_sample_end, Command{ .AddMarker = .{
38+
.pid = 12345,
39+
.marker = shared.MarkerType{ .SampleEnd = 2000 },
40+
} });
41+
try assert_eq(rust.cmd_add_marker_benchmark_start, Command{ .AddMarker = .{
42+
.pid = 12345,
43+
.marker = shared.MarkerType{ .BenchmarkStart = 3000 },
44+
} });
45+
try assert_eq(rust.cmd_add_marker_benchmark_end, Command{ .AddMarker = .{
46+
.pid = 12345,
47+
.marker = shared.MarkerType{ .BenchmarkEnd = 4000 },
48+
} });
49+
50+
// SetVersion command
51+
try assert_eq(rust.cmd_set_version, Command{ .SetVersion = 1 });
52+
53+
// GetIntegrationMode command
54+
try assert_eq(rust.cmd_get_runner_mode, Command{ .GetIntegrationMode = {} });
55+
56+
// IntegrationModeResponse commands
57+
try assert_eq(rust.cmd_runner_mode_perf, Command{ .IntegrationModeResponse = .Perf });
58+
try assert_eq(rust.cmd_runner_mode_simulation, Command{ .IntegrationModeResponse = .Simulation });
59+
try assert_eq(rust.cmd_runner_mode_analysis, Command{ .IntegrationModeResponse = .Analysis });
3160
}

src/tests/deserialize_rust/serialized.zig

Lines changed: 138 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,141 @@ pub const cmd_err: []const u8 = &.{
119119
0x0,
120120
0x0,
121121
};
122+
pub const cmd_add_marker_sample_start: []const u8 = &.{
123+
0x7,
124+
0x0,
125+
0x0,
126+
0x0,
127+
0x39,
128+
0x30,
129+
0x0,
130+
0x0,
131+
0x0,
132+
0x0,
133+
0x0,
134+
0x0,
135+
0xE8,
136+
0x3,
137+
0x0,
138+
0x0,
139+
0x0,
140+
0x0,
141+
0x0,
142+
0x0,
143+
};
144+
pub const cmd_add_marker_sample_end: []const u8 = &.{
145+
0x7,
146+
0x0,
147+
0x0,
148+
0x0,
149+
0x39,
150+
0x30,
151+
0x0,
152+
0x0,
153+
0x1,
154+
0x0,
155+
0x0,
156+
0x0,
157+
0xD0,
158+
0x7,
159+
0x0,
160+
0x0,
161+
0x0,
162+
0x0,
163+
0x0,
164+
0x0,
165+
};
166+
pub const cmd_add_marker_benchmark_start: []const u8 = &.{
167+
0x7,
168+
0x0,
169+
0x0,
170+
0x0,
171+
0x39,
172+
0x30,
173+
0x0,
174+
0x0,
175+
0x2,
176+
0x0,
177+
0x0,
178+
0x0,
179+
0xB8,
180+
0xB,
181+
0x0,
182+
0x0,
183+
0x0,
184+
0x0,
185+
0x0,
186+
0x0,
187+
};
188+
pub const cmd_add_marker_benchmark_end: []const u8 = &.{
189+
0x7,
190+
0x0,
191+
0x0,
192+
0x0,
193+
0x39,
194+
0x30,
195+
0x0,
196+
0x0,
197+
0x3,
198+
0x0,
199+
0x0,
200+
0x0,
201+
0xA0,
202+
0xF,
203+
0x0,
204+
0x0,
205+
0x0,
206+
0x0,
207+
0x0,
208+
0x0,
209+
};
210+
pub const cmd_set_version: []const u8 = &.{
211+
0x8,
212+
0x0,
213+
0x0,
214+
0x0,
215+
0x1,
216+
0x0,
217+
0x0,
218+
0x0,
219+
0x0,
220+
0x0,
221+
0x0,
222+
0x0,
223+
};
224+
pub const cmd_get_runner_mode: []const u8 = &.{
225+
0x9,
226+
0x0,
227+
0x0,
228+
0x0,
229+
};
230+
pub const cmd_runner_mode_perf: []const u8 = &.{
231+
0xA,
232+
0x0,
233+
0x0,
234+
0x0,
235+
0x1,
236+
0x0,
237+
0x0,
238+
0x0,
239+
};
240+
pub const cmd_runner_mode_simulation: []const u8 = &.{
241+
0xA,
242+
0x0,
243+
0x0,
244+
0x0,
245+
0x2,
246+
0x0,
247+
0x0,
248+
0x0,
249+
};
250+
pub const cmd_runner_mode_analysis: []const u8 = &.{
251+
0xA,
252+
0x0,
253+
0x0,
254+
0x0,
255+
0x0,
256+
0x0,
257+
0x0,
258+
0x0,
259+
};

0 commit comments

Comments
 (0)