]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
New functional test for sleep function.
authorVladimir Serbinenko <phcoder@gmail.com>
Sun, 15 Dec 2013 16:57:58 +0000 (17:57 +0100)
committerVladimir Serbinenko <phcoder@gmail.com>
Sun, 15 Dec 2013 16:57:58 +0000 (17:57 +0100)
This test allows to check sleep without qemu. Keep qemu version as
well as functional test won't notice if all clocks are going too fast
or too slow.

ChangeLog
grub-core/Makefile.core.def
grub-core/tests/lib/functional_test.c
grub-core/tests/sleep_test.c [new file with mode: 0644]

index 63e63f9ad768a85faa3376fb56b853e3f2df6144..6cbf04a70ace160e81cf01143f81101aae2c14ff 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-12-15  Vladimir Serbinenko  <phcoder@gmail.com>
+
+       New functional test for sleep function.
+
+       This test allows to check sleep without qemu. Keep qemu version as
+       well as functional test won't notice if all clocks are going too fast
+       or too slow.
+
 2013-12-15  Vladimir Serbinenko  <phcoder@gmail.com>
 
        Add explicit sysv_abi on amd64 asm routines.
index a550032a3fdb2db2363c87434024274abf402897..4102e73baf04e1491f7542208d61ded09fdf2794 100644 (file)
@@ -1932,6 +1932,11 @@ module = {
   common = tests/signatures.h;
 };
 
+module = {
+  name = sleep_test;
+  common = tests/sleep_test.c;
+};
+
 module = {
   name = xnu_uuid_test;
   common = tests/xnu_uuid_test.c;
index b99cb5f68769ff43b23f9e2c753a227670e8fcdc..5be7a58e5d42c74da1edfb7d6a4bde3da7ecafbb 100644 (file)
@@ -64,6 +64,7 @@ grub_functional_all_tests (grub_extcmd_context_t ctxt __attribute__ ((unused)),
   grub_dl_load ("xnu_uuid_test");
   grub_dl_load ("pbkdf2_test");
   grub_dl_load ("signature_test");
+  grub_dl_load ("sleep_test");
 
   FOR_LIST_ELEMENTS (test, grub_test_list)
     ok = !grub_test_run (test) && ok;
diff --git a/grub-core/tests/sleep_test.c b/grub-core/tests/sleep_test.c
new file mode 100644 (file)
index 0000000..98ea572
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ *  GRUB  --  GRand Unified Bootloader
+ *  Copyright (C) 2013  Free Software Foundation, Inc.
+ *
+ *  GRUB is free software: you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation, either version 3 of the License, or
+ *  (at your option) any later version.
+ *
+ *  GRUB is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with GRUB.  If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <grub/time.h>
+#include <grub/misc.h>
+#include <grub/dl.h>
+#include <grub/command.h>
+#include <grub/env.h>
+#include <grub/test.h>
+#include <grub/mm.h>
+#include <grub/datetime.h>
+#include <grub/time.h>
+
+GRUB_MOD_LICENSE ("GPLv3+");
+
+static void
+sleep_test (void)
+{
+  struct grub_datetime st, en;
+  grub_int32_t stu, enu;
+  grub_test_assert (!grub_get_datetime (&st), "Couldn't retrieve start time");
+  grub_millisleep (10000);
+  grub_test_assert (!grub_get_datetime (&en), "Couldn't retrieve end time");
+  grub_test_assert (grub_datetime2unixtime (&st, &stu), "Invalid date");
+  grub_test_assert (grub_datetime2unixtime (&en, &enu), "Invalid date");
+  grub_test_assert (enu - stu >= 9 && enu - stu <= 11, "Interval out of range: %d", enu-stu);
+
+}
+
+GRUB_FUNCTIONAL_TEST (sleep_test, sleep_test);