From: Joe Hershberger Date: Tue, 21 Apr 2015 18:57:18 +0000 (-0500) Subject: sandbox: Add test function to advance time X-Git-Tag: v2015.07-rc2~285^2~47 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=909bd6d9729cb0c6ba6b80cdc283bbd3e1e12770;p=u-boot sandbox: Add test function to advance time 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 Acked-by: Simon Glass --- diff --git a/arch/sandbox/cpu/cpu.c b/arch/sandbox/cpu/cpu.c index 168f2efa33..b6aae3718a 100644 --- a/arch/sandbox/cpu/cpu.c +++ b/arch/sandbox/cpu/cpu.c @@ -45,11 +45,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 cleanup_before_linux(void) { return 0; diff --git a/arch/sandbox/include/asm/test.h b/arch/sandbox/include/asm/test.h index 8e490e96d7..296589c282 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 2227f1c121..80eaa6334c 100644 --- a/board/sandbox/sandbox.c +++ b/board/sandbox/sandbox.c @@ -7,6 +7,7 @@ #include #include #include +#include #include /* @@ -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)