vaseboot/VasEBoot-core/tests/sleep_test.c

52 lines
1.8 KiB
C

/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2013 Free Software Foundation, Inc.
*
* VAS_EBOOT 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.
*
* VAS_EBOOT 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 VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
*/
#include <VasEBoot/time.h>
#include <VasEBoot/misc.h>
#include <VasEBoot/dl.h>
#include <VasEBoot/command.h>
#include <VasEBoot/env.h>
#include <VasEBoot/test.h>
#include <VasEBoot/mm.h>
#include <VasEBoot/datetime.h>
#include <VasEBoot/time.h>
VAS_EBOOT_MOD_LICENSE ("GPLv3+");
static void
sleep_test (void)
{
struct VasEBoot_datetime st, en;
VasEBoot_int64_t stu = 0, enu = 0;
int is_delayok;
VasEBoot_test_assert (!VasEBoot_get_datetime (&st), "Couldn't retrieve start time");
VasEBoot_millisleep (10000);
VasEBoot_test_assert (!VasEBoot_get_datetime (&en), "Couldn't retrieve end time");
VasEBoot_test_assert (VasEBoot_datetime2unixtime (&st, &stu), "Invalid date");
VasEBoot_test_assert (VasEBoot_datetime2unixtime (&en, &enu), "Invalid date");
is_delayok = (enu - stu >= 9 && enu - stu <= 11);
#ifdef __arm__
/* Ignore QEMU bug */
if (enu - stu >= 15 && enu - stu <= 17)
is_delayok = 1;
#endif
VasEBoot_test_assert (is_delayok, "Interval out of range: %" PRIdVAS_EBOOT_INT64_T, enu - stu);
}
VAS_EBOOT_FUNCTIONAL_TEST (sleep_test, sleep_test);