source: ada-examples/delay_until/delay_until.adb @ 3fe7728

ada-examples-4-10-branch ada-examples-4-10-1
Last change on this file since 3fe7728 was 789d0e8, checked in by Joel Sherrill <joel.sherrill@…>, on Sep 17, 2009 at 6:13:32 PM

2009-09-17 Joel Sherrill <joel.sherrill@…>

  • Makefile, delay_until.adb: Make follow standard RTEMS test output format. Add output screens where appropriate.
  • delay_until.scn: New file.
  • Property mode set to 100644
File size: 1.9 KB
Line 
1--
2--  $Id$
3--
4
5with Ada.Real_Time;
6with Ada.Text_Io;
7
8use type Ada.Real_Time.Time;
9use type Ada.Real_Time.Time_Span;
10
11
12procedure Delay_Until is
13   Next_Wakeup : Ada.Real_Time.Time;
14   Period      : constant Ada.Real_Time.Time_Span :=
15                    Ada.Real_Time.Nanoseconds (16666667);
16                    --   Ada.Real_Time.Nanoseconds (20000);
17
18   Iterations : constant := 1000;
19   Actual_Span : array (1..Iterations) of Ada.Real_Time.Time_Span;
20   Average_Span : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Zero;
21   Max_Span     : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_First;
22   Min_Span     : Ada.Real_Time.Time_Span := Ada.Real_Time.Time_Span_Last;
23
24begin
25   Ada.Text_Io.Put_Line ("*** Delay Until Variation Test ***");
26   Ada.Text_Io.Put_Line (
27      Integer'Image (Iterations) & " iterations with " &
28      Duration'Image (Ada.Real_Time.To_Duration(Period)) &
29      "s period"
30   );
31   Next_Wakeup := Ada.Real_Time.Clock + Period;
32   for Count in 1..Iterations loop
33      delay until Next_Wakeup;
34
35      Actual_Span (Count) := Ada.Real_Time.Clock - (Next_Wakeup - Period);
36      Average_Span := Average_Span + (Actual_Span (Count) / Iterations);
37      if Actual_Span (Count) > Max_Span then
38         Max_Span := Actual_Span (Count);
39      end if;
40      if Actual_Span (Count) < Min_Span then
41         Min_Span := Actual_Span (Count);
42      end if;
43
44      Next_Wakeup := Next_Wakeup + Period;
45   end loop;
46
47   Ada.Text_Io.Put_Line (
48      "Average delay is" &
49      Duration'Image (Ada.Real_Time.To_Duration (Average_Span)) &
50      "s"
51   );
52   Ada.Text_Io.Put_Line (
53      "Maximum delay is" &
54      Duration'Image (Ada.Real_Time.To_Duration (Max_Span)) &
55      "s"
56   );
57   Ada.Text_Io.Put_Line (
58      "Minimum delay is" &
59       Duration'Image (Ada.Real_Time.To_Duration (Min_Span)) &
60       "s"
61   );
62   Ada.Text_Io.Put_Line ("*** END OF Delay Until Variation Test ***");
63end Delay_Until;
Note: See TracBrowser for help on using the repository browser.