Skip to content

Commit

Permalink
Added test for proper scheduling after delay expiry
Browse files Browse the repository at this point in the history
It's not obvious from the FreeRTOS source code (in tasks.c) what
happens if a task's delay ends while another task of the same priority
is running.
This test demonstrates that the running task continues.

  * test-stm32f4/action_after_delay-main.adb,
    test-stm32f4/action_after_delay.adb,
    test-stm32f4/action_after_delay.ads: new test.
  * test-stm32f4/testbed.gpr: include action_after_delay.
  • Loading branch information
simonjwright committed Oct 13, 2020
1 parent ed88765 commit 48d06b8
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test-stm32f4/action_after_delay-main.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
-- Copyright (C) 2020 Free Software Foundation, Inc.

-- This file is part of the Cortex GNAT RTS package.
--
-- Copying and distribution of this file, with or without
-- modification, are permitted in any medium without royalty provided
-- the copyright notice and this notice are preserved. This file is
-- offered as-is, without any warranty.

with Ada.Real_Time;
procedure Action_After_Delay.Main is
begin
delay until Ada.Real_Time.Time_Last;
end Action_After_Delay.Main;
38 changes: 38 additions & 0 deletions test-stm32f4/action_after_delay.adb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
-- Copyright (C) 2020 Free Software Foundation, Inc.

-- This file is part of the Cortex GNAT RTS package.
--
-- Copying and distribution of this file, with or without
-- modification, are permitted in any medium without royalty provided
-- the copyright notice and this notice are preserved. This file is
-- offered as-is, without any warranty.

with Ada.Real_Time;

package body Action_After_Delay is

task T1;
task T2;

T2_Has_Run : Boolean := False with Volatile;

task body T1 is
begin
loop
exit when T2_Has_Run;
end loop;
-- PE here (because it's illegal in Ravenscar to exit a task)
-- if T2 has run
end T1;

task body T2 is
use type Ada.Real_Time.Time;
begin
delay until Ada.Real_Time.Clock + Ada.Real_Time.Seconds (1);
-- Shouldn't get here, since T1 hasn't reached a dispatching
-- point.
T2_Has_Run := True;
delay until Ada.Real_Time.Time_Last;
end T2;

end Action_After_Delay;
15 changes: 15 additions & 0 deletions test-stm32f4/action_after_delay.ads
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-- Copyright (C) 2020 Free Software Foundation, Inc.

-- This file is part of the Cortex GNAT RTS package.
--
-- Copying and distribution of this file, with or without
-- modification, are permitted in any medium without royalty provided
-- the copyright notice and this notice are preserved. This file is
-- offered as-is, without any warranty.

-- The purpose of this little suite is to determine what happens when
-- one task is running and another, at the same priority, exits a
-- delay; will it run or be blocked?

package Action_After_Delay with Elaborate_Body is
end Action_After_Delay;
2 changes: 2 additions & 0 deletions test-stm32f4/testbed.gpr
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
project Testbed is

for Main use ("testbed.adb",
"action_after_delay-main.adb",
"delay_in_po-main.adb",
"generate_hard_fault.adb");
for Languages use ("Ada", "C");
Expand All @@ -29,6 +30,7 @@ project Testbed is
for Runtime ("ada") use project'Project_Dir & "../local/stm32f4";

package Builder is
for Executable ("action_after_delay-main.adb") use "action_after_delay";
for Executable ("delay_in_po-main.adb") use "delay_in_po";
for Global_Configuration_Pragmas use "gnat.adc";
for Global_Compilation_Switches ("ada") use
Expand Down

0 comments on commit 48d06b8

Please sign in to comment.