wasefire_board_api/debug.rs
1// Copyright 2023 Google LLC
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Debugging and testing interface.
16
17use wasefire_logger as log;
18
19/// Debugging and testing interface.
20pub trait Api: Send {
21 /// Maximum value returned by [`Self::time()`] before wrapping.
22 const MAX_TIME: u64;
23
24 /// Prints a line with timestamp.
25 fn println(line: &str) {
26 let time = Self::time();
27 log::println!("{}.{:06}: {}", time / 1000000, time % 1000000, line);
28 }
29
30 /// Returns the time in micro-seconds since some initial event.
31 ///
32 /// This wraps once [`Self::MAX_TIME`] is reached. In particular, a maximum value of zero
33 /// equivalent to not supporting this API.
34 fn time() -> u64;
35}
36
37/// Default implementation.
38pub enum Impl {}
39
40impl Api for Impl {
41 const MAX_TIME: u64 = 0;
42
43 fn time() -> u64 {
44 0
45 }
46}