Skip to content

Commit 7231bfd

Browse files
fix tests and scheduler (off by one error)
1 parent 5418b89 commit 7231bfd

2 files changed

Lines changed: 3 additions & 12 deletions

File tree

Src/HALAL/Services/Time/Scheduler.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,12 +288,12 @@ void Scheduler::schedule_next_interval() {
288288
SET_BIT(Scheduler_global_timer->EGR, TIM_EGR_UG); // This should cause an interrupt
289289
} else {
290290
if (diff < -1) [[unlikely]] {
291-
current_interval_us_ = static_cast<uint32_t>(0 - diff) - 1u;
291+
current_interval_us_ = static_cast<uint32_t>(0 - diff);
292292
} else {
293-
current_interval_us_ = static_cast<uint32_t>(diff) - 1u;
293+
current_interval_us_ = static_cast<uint32_t>(diff);
294294
}
295295

296-
Scheduler_global_timer->ARR = current_interval_us_;
296+
Scheduler_global_timer->ARR = current_interval_us_ - 1u;
297297
if (Scheduler_global_timer->CNT > current_interval_us_) [[unlikely]] {
298298
uint32_t offset = Scheduler_global_timer->CNT - current_interval_us_;
299299
Scheduler_global_timer->CNT = 0;

Tests/Time/scheduler_test.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ TEST_F(SchedulerTests, TaskRegistration) {
4444

4545
TEST_F(SchedulerTests, TaskExecutionShort) {
4646
Scheduler::register_task(10, &fake_workload);
47-
Scheduler::start();
4847
TIM2_BASE->PSC = 2; // quicker test
4948

5049
constexpr int NUM_TICKS = 1'000;
@@ -59,7 +58,6 @@ TEST_F(SchedulerTests, TaskExecutionShort) {
5958

6059
TEST_F(SchedulerTests, TaskExecutionLong) {
6160
Scheduler::register_task(10, &fake_workload);
62-
Scheduler::start();
6361
// TIM2_BASE->ARR = 500;
6462
TIM2_BASE->generate_update();
6563
TIM2_BASE->PSC = 2; // quicker test
@@ -75,7 +73,6 @@ TEST_F(SchedulerTests, TaskExecutionLong) {
7573

7674
TEST_F(SchedulerTests, SetTimeout) {
7775
Scheduler::set_timeout(10, &fake_workload);
78-
Scheduler::start();
7976
TIM2_BASE->PSC = 2; // quicker test
8077

8178
constexpr int NUM_TICKS = 100;
@@ -90,7 +87,6 @@ TEST_F(SchedulerTests, SetTimeout) {
9087
TEST_F(SchedulerTests, GlobalTickOverflow) {
9188
Scheduler::global_tick_us_ = 0xFFFFFFF0ULL; // Near 32-bit max
9289
Scheduler::register_task(20, &fake_workload);
93-
Scheduler::start();
9490
TIM2_BASE->PSC = 2; // quicker test
9591

9692
constexpr int NUM_TICKS = 100;
@@ -133,7 +129,6 @@ TEST_F(SchedulerTests, GlobalTickOverflowManyTasks) {
133129
Scheduler::register_task(10, &multiple_task_1);
134130
Scheduler::register_task(20, &multiple_task_2);
135131
Scheduler::register_task(30, &multiple_task_3);
136-
Scheduler::start();
137132
TIM2_BASE->PSC = 2; // quicker test
138133

139134
constexpr int NUM_TICKS = 100;
@@ -151,7 +146,6 @@ TEST_F(SchedulerTests, GlobalTickOverflowManyTasks) {
151146

152147
TEST_F(SchedulerTests, TimeoutClearAddTask) {
153148
uint8_t timeout_id = Scheduler::set_timeout(10, &fake_workload);
154-
Scheduler::start();
155149
TIM2_BASE->PSC = 2; // quicker test
156150

157151
constexpr int NUM_TICKS = 100;
@@ -190,7 +184,6 @@ TEST_F(SchedulerTests, TaskDe_ReRegistration) {
190184
uint8_t connecting_task = Scheduler::register_task(10, &connecting_cyclic);
191185
uint8_t operational_task = 0;
192186
uint8_t fault_task = 0;
193-
Scheduler::start();
194187
TIM2_BASE->PSC = 2; // quicker test
195188

196189
constexpr int NUM_TICKS = 100;
@@ -231,7 +224,6 @@ TEST_F(SchedulerTests, MultipleTasks) {
231224
Scheduler::register_task(5, &multiple_task_5);
232225
Scheduler::register_task(6, &multiple_task_6);
233226

234-
Scheduler::start();
235227
TIM2_BASE->PSC = 2; // quicker test
236228
constexpr int NUM_TICKS = 300;
237229
for (int i = 0; i < NUM_TICKS; i++) {
@@ -258,7 +250,6 @@ TEST_F(SchedulerTests, SameTaskMultipleTimes) {
258250
Scheduler::register_task(6, &multiple_task_1);
259251

260252
multiple_task1count = 0;
261-
Scheduler::start();
262253
TIM2_BASE->PSC = 2; // quicker test
263254
constexpr int NUM_TICKS = 300;
264255
for (int i = 0; i < NUM_TICKS; i++) {

0 commit comments

Comments
 (0)