commence breakage
[inav.git] / src / test / unit / time_unittest.cc
blob8048601ac6e2826ea4b4ecc9c9bba1f3fc65eae2
1 /*
2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 #include <stdint.h>
19 #include <stdbool.h>
21 #include <limits.h>
23 extern "C" {
24 #include "common/time.h"
25 #include "drivers/time.h"
26 extern timeUs_t usTicks;
27 extern volatile timeMs_t sysTickUptime;
28 extern volatile timeMs_t sysTickValStamp;
31 #include "unittest_macros.h"
32 #include "gtest/gtest.h"
34 SysTick_Type SysTickValue;
35 SysTick_Type *SysTick = &SysTickValue;
37 TEST(TimeUnittest, TestMillis)
39 sysTickUptime = 0;
40 EXPECT_EQ(0, millis());
41 sysTickUptime = 1;
42 EXPECT_EQ(1, millis());
45 TEST(TimeUnittest, TestMicros)
47 usTicks = 168;
48 sysTickValStamp = SysTick->VAL = 1000 * usTicks;
49 sysTickUptime = 0;
50 EXPECT_EQ(0, micros());
51 sysTickUptime = 1;
52 EXPECT_EQ(1000, micros());
53 // ULONG_MAX = 4294967295
54 sysTickUptime = 429496; // ULONG_MAX / 1000;
55 EXPECT_EQ(429496000, micros());
56 sysTickUptime = 429497;
57 EXPECT_EQ(429497000, micros());
58 sysTickUptime = 500000;
59 EXPECT_EQ(500000000, micros());
61 sysTickUptime = 0;
62 sysTickValStamp = SysTick->VAL = 0;
63 EXPECT_EQ(1000, micros());
64 sysTickUptime = 1;
65 EXPECT_EQ(2000, micros());
66 // ULONG_MAX = 4294967295
67 sysTickUptime = 429496; // ULONG_MAX / 1000;
68 EXPECT_EQ(429497000, micros());
69 sysTickUptime = 429497;
70 EXPECT_EQ(429498000, micros());
71 sysTickUptime = 500000;
72 EXPECT_EQ(500001000, micros());