use super::registry::*;
pub(crate) fn register(registry: &mut CommandRegistry) {
registry.register(cmd_clock_time_report());
}
fn cmd_clock_time_report() -> CommandDef {
CommandDef::new(
"ClockTime_Report",
vec![ArgDesc {
name: "interest_level",
arg_type: ArgType::Int,
}],
"ClockTime_Report <interest_level> — Report the IOC's OS clock \
synchronization status.",
|args: &[ArgValue], ctx: &CommandContext| {
let level = match args.first() {
Some(ArgValue::Int(n)) => *n as i32,
_ => 0,
};
let report = crate::runtime::general_time::clock_time_report(level);
let body = report.strip_suffix('\n').unwrap_or(&report);
ctx.print_fmt(format_args!("{body}"));
Ok(CommandOutcome::Continue)
},
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn the_command_is_registered_with_c_s_name_and_arity() {
let mut reg = CommandRegistry::new();
register(&mut reg);
let cmd = reg.get("ClockTime_Report").expect("C registers this");
assert_eq!(cmd.args.len(), 1, "C `ReportFuncDef` declares 1 arg");
assert_eq!(cmd.args[0].name, "interest_level");
assert!(matches!(cmd.args[0].arg_type, ArgType::Int));
}
#[test]
fn the_report_is_c_s_unsynchronized_branch() {
let out = crate::runtime::general_time::clock_time_report(0);
let mut lines = out.lines();
let first = lines.next().expect("one line at least");
assert!(
first.starts_with("Program started at "),
"C prints this verbatim: {first:?}"
);
assert_eq!(
first.len(),
"Program started at ".len() + 26,
"C's epicsTimeToStrftime width: {first:?}"
);
let rest: Vec<&str> = lines.collect();
if cfg!(any(target_os = "vxworks", target_os = "rtems")) {
assert_eq!(
rest,
["IOC's OS Clock synchronization thread is not running."]
);
} else {
assert!(rest.is_empty(), "C guards that line out here: {rest:?}");
}
assert_eq!(
crate::runtime::general_time::clock_time_report(1)
.lines()
.count(),
out.lines().count()
);
}
}