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/>.
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
)
40 EXPECT_EQ(0, millis());
42 EXPECT_EQ(1, millis());
45 TEST(TimeUnittest
, TestMicros
)
48 sysTickValStamp
= SysTick
->VAL
= 1000 * usTicks
;
50 EXPECT_EQ(0, micros());
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());
62 sysTickValStamp
= SysTick
->VAL
= 0;
63 EXPECT_EQ(1000, micros());
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());