
Add a function that maintains an offset to include in the system timer values returned from the lib/time.c APIs.
This will allow timeouts to be skipped instantly in tests
Signed-off-by: Joe Hershberger joe.hershberger@ni.com ---
arch/sandbox/cpu/cpu.c | 5 ----- arch/sandbox/include/asm/test.h | 8 ++++++++ board/sandbox/sandbox.c | 11 ++++++++++- 3 files changed, 18 insertions(+), 6 deletions(-)
diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index 007ae86..6c3f4b4 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -44,11 +44,6 @@ void __udelay(unsigned long usec) os_usleep(usec); }
-unsigned long __attribute__((no_instrument_function)) timer_get_us(void) -{ - return os_get_nsec() / 1000; -} - int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images) { if (flag & (BOOTM_STATE_OS_GO | BOOTM_STATE_OS_FAKE_GO)) { diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 8e490e9..296589c 100644 --- a/arch/sandbox/include/asm/test.h +++ b/arch/sandbox/include/asm/test.h @@ -28,4 +28,12 @@ void sandbox_i2c_eeprom_set_test_mode(struct udevice *dev,
void sandbox_i2c_eeprom_set_offset_len(struct udevice *dev, int offset_len);
+/* + * sandbox_timer_add_offset() + * + * Allow tests to add to the time reported through lib/time.c functions + * offset: number of milliseconds to advance the system time + */ +void sandbox_timer_add_offset(unsigned long offset); + #endif diff --git a/board/sandbox/sandbox.c b/board/sandbox/sandbox.c index 2227f1c..80eaa63 100644 --- a/board/sandbox/sandbox.c +++ b/board/sandbox/sandbox.c @@ -7,6 +7,7 @@ #include <cros_ec.h> #include <dm.h> #include <os.h> +#include <asm/test.h> #include <asm/u-boot-sandbox.h>
/* @@ -25,9 +26,17 @@ void flush_cache(unsigned long start, unsigned long size) { }
+/* system timer offset in ms */ +static unsigned long sandbox_timer_offset; + +void sandbox_timer_add_offset(unsigned long offset) +{ + sandbox_timer_offset += offset; +} + unsigned long timer_read_counter(void) { - return os_get_nsec() / 1000; + return os_get_nsec() / 1000 + sandbox_timer_offset * 1000; }
int dram_init(void)