source: rtems/c/src/ada-tests/samples/nsecs/sptest.adb @ c499856

4.115
Last change on this file since c499856 was c499856, checked in by Chris Johns <chrisj@…>, on 03/20/14 at 21:10:47

Change all references of rtems.com to rtems.org.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1--
2--  SPTEST / BODY
3--
4--  DESCRIPTION:
5--
6--  This package is the implementation of the Nanosecond test of the
7--  Sample Test Suite.
8--
9--  DEPENDENCIES:
10--
11-- 
12--
13--  COPYRIGHT (c) 1989-2011.
14--  On-Line Applications Research Corporation (OAR).
15--
16--  The license and distribution terms for this file may in
17--  the file LICENSE in this distribution or at
18--  http://www.rtems.org/license/LICENSE.
19--
20
21with Ada.Integer_Text_IO;
22with Interfaces.C;
23with RTEMS;
24with RTEMS.Clock;
25with Text_IO;
26use type Interfaces.C.Long;
27use type RTEMS.Time_T;
28
29package body SPTEST is
30
31   Dummy_Variable : Natural := 0;
32
33   procedure Simple_Procedure is
34   begin
35      Dummy_Variable := Dummy_Variable + 1;
36   end Simple_Procedure;
37
38   procedure Subtract_Em (
39      Start  : in     RTEMS.Timespec;
40      Stop   : in     RTEMS.Timespec;
41      Result :    out RTEMS.Timespec
42   ) is
43      Nanoseconds_Per_Second : constant := 1000000000;
44   begin
45      if (Stop.TV_Nsec < Start.TV_Nsec) then
46         Result.TV_Sec  := Stop.TV_Sec - Start.TV_Sec - 1;
47         Result.TV_Nsec :=
48           (Nanoseconds_Per_Second - Start.TV_Nsec) + Stop.TV_Nsec;
49      else
50         Result.TV_Sec  := Stop.TV_Sec - Start.TV_Sec;
51         Result.TV_Nsec := Stop.TV_Nsec - Start.TV_Nsec;
52      end if;
53   end Subtract_Em;
54
55
56--
57--  INIT
58--
59
60   procedure INIT (
61      ARGUMENT : in     RTEMS.TASKS.ARGUMENT
62   ) is
63      pragma Unreferenced(ARGUMENT);
64      Status : RTEMS.Status_Codes;
65      Start  : RTEMS.Timespec;
66      Stop   : RTEMS.Timespec;
67      Diff   : RTEMS.Timespec;
68      Max    : Integer;
69   begin
70
71      TEXT_IO.NEW_LINE( 2 );
72      TEXT_IO.PUT_LINE( "*** NANOSECOND CLOCK TEST ***" );
73
74      --
75      --  Iterate 10 times showing difference in TOD
76      --
77
78      TEXT_IO.PUT_LINE( "10 iterations of getting TOD NOT tested in Ada" );
79
80      --
81      --  Iterate 10 times showing difference in Uptime
82      --
83
84      TEXT_IO.NEW_LINE;
85      TEXT_IO.PUT_LINE( "10 iterations of getting Uptime" );
86
87      for Index in 1 .. 10 loop
88
89         RTEMS.Clock.Get_Uptime( Start, Status );
90         RTEMS.Clock.Get_Uptime( Stop, Status );
91
92         Subtract_Em( Start, Stop, Diff );
93
94         Ada.Integer_Text_IO.Put( Integer( Start.TV_Sec ), 1 );
95         Text_IO.Put( ":" );
96         Ada.Integer_Text_IO.Put( Integer( Start.TV_Nsec ), 9 );
97         Text_IO.Put( " " );
98         Ada.Integer_Text_IO.Put( Integer( Stop.TV_Sec ), 1 );
99         Text_IO.Put( ":" );
100         Ada.Integer_Text_IO.Put( Integer( Stop.TV_Nsec ), 9 );
101         Text_IO.Put( " --> " );
102         Ada.Integer_Text_IO.Put( Integer( Diff.TV_Sec ), 1 );
103         Text_IO.Put( ":" );
104         Ada.Integer_Text_IO.Put( Integer( Diff.TV_Nsec ), 9 );
105         Text_IO.New_Line;
106      end loop;
107
108      --
109      --  Iterate 10 times showing difference in Uptime with different counts
110      --
111
112      TEXT_IO.NEW_LINE;
113      TEXT_IO.PUT_LINE(
114         "10 iterations of getting Uptime with different loop values"
115      );
116
117      for Index in 1 .. 10 loop
118         Max := (Index * 10000);
119         RTEMS.Clock.Get_Uptime( Start, Status );
120         for j in 1 .. Max loop
121            Simple_Procedure;
122         end loop;
123         RTEMS.Clock.Get_Uptime( Stop, Status );
124
125         Subtract_Em( Start, Stop, Diff );
126
127         Text_IO.Put( "loop of " );
128         Ada.Integer_Text_IO.Put( Max, 6 );
129         Text_IO.Put( " " );
130         Ada.Integer_Text_IO.Put( Integer( Start.TV_Sec ), 1 );
131         Text_IO.Put( ":" );
132         Ada.Integer_Text_IO.Put( Integer( Start.TV_Nsec ), 9 );
133         Text_IO.Put( " " );
134         Ada.Integer_Text_IO.Put( Integer( Stop.TV_Sec ), 1 );
135         Text_IO.Put( ":" );
136         Ada.Integer_Text_IO.Put( Integer( Stop.TV_Nsec ), 9 );
137         Text_IO.Put( " --> " );
138         Ada.Integer_Text_IO.Put( Integer( Diff.TV_Sec ), 1 );
139         Text_IO.Put( ":" );
140         Ada.Integer_Text_IO.Put( Integer( Diff.TV_Nsec ), 9 );
141         Text_IO.New_Line;
142
143      end loop;
144
145      delay( 1.0 );
146
147      TEXT_IO.PUT_LINE( "*** END OF NANOSECOND CLOCK TEST ***" );
148
149      RTEMS.SHUTDOWN_EXECUTIVE( 0 );
150
151   end INIT;
152
153end SPTEST;
Note: See TracBrowser for help on using the repository browser.