]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
sandbox: Add test function to advance time
authorJoe Hershberger <joe.hershberger@ni.com>
Tue, 21 Apr 2015 18:57:18 +0000 (13:57 -0500)
committerSimon Glass <sjg@chromium.org>
Wed, 6 May 2015 02:58:18 +0000 (20:58 -0600)
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>
Acked-by: Simon Glass <sjg@chromium.org>
arch/sandbox/cpu/cpu.c
arch/sandbox/include/asm/test.h
board/sandbox/sandbox.c

index 168f2efa33e5fe4f5eaab52503dbb724fd2f5528..b6aae3718a19f81baaa4a7616ec1231d67c3e80e 100644 (file)
@@ -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;
index 8e490e96d7ae6cf9fb6f055ad30437862f872fb1..296589c28261f3f0153db37896704c94f7406e70 100644 (file)
@@ -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
index 2227f1c1214a97ae078fe18dac950dfe1a835b90..80eaa6334cb56cccbeadaee9e0a3bf68c9a07c40 100644 (file)
@@ -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)