aboutsummaryrefslogtreecommitdiff
path: root/core/test
diff options
context:
space:
mode:
authorStewart Smith <stewart@linux.vnet.ibm.com>2015-10-08 09:06:36 +1100
committerStewart Smith <stewart@linux.vnet.ibm.com>2015-10-08 14:15:45 +1100
commitdc3d17ac940fe1e0b2723a31d171ab47fd68fd47 (patch)
tree08e758f7ff8006366389a1c992ff360d033d48dd /core/test
parentc09aef0ad259e4232490f62424699298e82aaa18 (diff)
downloadskiboot-dc3d17ac940fe1e0b2723a31d171ab47fd68fd47.zip
skiboot-dc3d17ac940fe1e0b2723a31d171ab47fd68fd47.tar.gz
skiboot-dc3d17ac940fe1e0b2723a31d171ab47fd68fd47.tar.bz2
Add unit test for timebase functions
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
Diffstat (limited to 'core/test')
-rw-r--r--core/test/Makefile.check1
-rw-r--r--core/test/run-timebase.c56
2 files changed, 57 insertions, 0 deletions
diff --git a/core/test/Makefile.check b/core/test/Makefile.check
index c1af4b3..2724aab 100644
--- a/core/test/Makefile.check
+++ b/core/test/Makefile.check
@@ -14,6 +14,7 @@ CORE_TEST := core/test/run-device \
core/test/run-pel \
core/test/run-pool \
core/test/run-time-utils \
+ core/test/run-timebase \
core/test/run-timer
CORE_TEST_NOSTUB := core/test/run-console-log
diff --git a/core/test/run-timebase.c b/core/test/run-timebase.c
new file mode 100644
index 0000000..2d4c83d
--- /dev/null
+++ b/core/test/run-timebase.c
@@ -0,0 +1,56 @@
+/* Copyright 2013-2015 IBM Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+ * implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <assert.h>
+
+#define __TEST__
+#include <timebase.h>
+
+int main(void)
+{
+ /* This is a fairly solid assumption that the math we're doing
+ * is based on tb_hz of exactly 512mhz.
+ * If we do start doing the math on different tb_hz, you probably
+ * want to go and audit every bit of code that touches tb to
+ * count/delay things.
+ */
+ assert(tb_hz == 512000000);
+ assert(secs_to_tb(1) == tb_hz);
+ assert(secs_to_tb(2) == 1024000000);
+ assert(secs_to_tb(10) == 5120000000);
+ assert(tb_to_secs(512000000) == 1);
+ assert(tb_to_secs(5120000000) == 10);
+ assert(tb_to_secs(1024000000) == 2);
+
+ assert(msecs_to_tb(1) == 512000);
+ assert(msecs_to_tb(100) == 51200000);
+ assert(msecs_to_tb(5) == 2560000);
+ assert(tb_to_msecs(512000) == 1);
+
+ assert(usecs_to_tb(5) == 2560);
+ assert(tb_to_usecs(2560) == 5);
+ assert(usecs_to_tb(5)*1000 == msecs_to_tb(5));
+ assert(tb_to_usecs(512000) == 1000);
+
+ assert(tb_compare(msecs_to_tb(5), usecs_to_tb(5)) == TB_AAFTERB);
+ assert(tb_compare(msecs_to_tb(5), usecs_to_tb(50000)) == TB_ABEFOREB);
+ assert(tb_compare(msecs_to_tb(5), usecs_to_tb(5)*1000) == TB_AEQUALB);
+
+ return 0;
+}