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 | |
---|
21 | with Ada.Integer_Text_IO; |
---|
22 | with Interfaces.C; |
---|
23 | with RTEMS; |
---|
24 | with RTEMS.Clock; |
---|
25 | with Text_IO; |
---|
26 | with TEST_SUPPORT; |
---|
27 | use type Interfaces.C.Long; |
---|
28 | use type RTEMS.Time_T; |
---|
29 | |
---|
30 | package body SPTEST is |
---|
31 | |
---|
32 | Dummy_Variable : Natural := 0; |
---|
33 | |
---|
34 | procedure Simple_Procedure is |
---|
35 | begin |
---|
36 | Dummy_Variable := Dummy_Variable + 1; |
---|
37 | end Simple_Procedure; |
---|
38 | |
---|
39 | procedure Subtract_Em ( |
---|
40 | Start : in RTEMS.Timespec; |
---|
41 | Stop : in RTEMS.Timespec; |
---|
42 | Result : out RTEMS.Timespec |
---|
43 | ) is |
---|
44 | Nanoseconds_Per_Second : constant := 1000000000; |
---|
45 | begin |
---|
46 | if (Stop.TV_Nsec < Start.TV_Nsec) then |
---|
47 | Result.TV_Sec := Stop.TV_Sec - Start.TV_Sec - 1; |
---|
48 | Result.TV_Nsec := |
---|
49 | (Nanoseconds_Per_Second - Start.TV_Nsec) + Stop.TV_Nsec; |
---|
50 | else |
---|
51 | Result.TV_Sec := Stop.TV_Sec - Start.TV_Sec; |
---|
52 | Result.TV_Nsec := Stop.TV_Nsec - Start.TV_Nsec; |
---|
53 | end if; |
---|
54 | end Subtract_Em; |
---|
55 | |
---|
56 | |
---|
57 | -- |
---|
58 | -- INIT |
---|
59 | -- |
---|
60 | |
---|
61 | procedure INIT ( |
---|
62 | ARGUMENT : in RTEMS.TASKS.ARGUMENT |
---|
63 | ) is |
---|
64 | pragma Unreferenced(ARGUMENT); |
---|
65 | Status : RTEMS.Status_Codes; |
---|
66 | Start : RTEMS.Timespec; |
---|
67 | Stop : RTEMS.Timespec; |
---|
68 | Diff : RTEMS.Timespec; |
---|
69 | Max : Integer; |
---|
70 | begin |
---|
71 | |
---|
72 | TEXT_IO.NEW_LINE( 2 ); |
---|
73 | TEST_SUPPORT.ADA_TEST_BEGIN; |
---|
74 | |
---|
75 | -- |
---|
76 | -- Iterate 10 times showing difference in TOD |
---|
77 | -- |
---|
78 | |
---|
79 | TEXT_IO.PUT_LINE( "10 iterations of getting TOD NOT tested in Ada" ); |
---|
80 | |
---|
81 | -- |
---|
82 | -- Iterate 10 times showing difference in Uptime |
---|
83 | -- |
---|
84 | |
---|
85 | TEXT_IO.NEW_LINE; |
---|
86 | TEXT_IO.PUT_LINE( "10 iterations of getting Uptime" ); |
---|
87 | |
---|
88 | for Index in 1 .. 10 loop |
---|
89 | |
---|
90 | RTEMS.Clock.Get_Uptime( Start, Status ); |
---|
91 | RTEMS.Clock.Get_Uptime( Stop, Status ); |
---|
92 | |
---|
93 | Subtract_Em( Start, Stop, Diff ); |
---|
94 | |
---|
95 | Ada.Integer_Text_IO.Put( Integer( Start.TV_Sec ), 1 ); |
---|
96 | Text_IO.Put( ":" ); |
---|
97 | Ada.Integer_Text_IO.Put( Integer( Start.TV_Nsec ), 9 ); |
---|
98 | Text_IO.Put( " " ); |
---|
99 | Ada.Integer_Text_IO.Put( Integer( Stop.TV_Sec ), 1 ); |
---|
100 | Text_IO.Put( ":" ); |
---|
101 | Ada.Integer_Text_IO.Put( Integer( Stop.TV_Nsec ), 9 ); |
---|
102 | Text_IO.Put( " --> " ); |
---|
103 | Ada.Integer_Text_IO.Put( Integer( Diff.TV_Sec ), 1 ); |
---|
104 | Text_IO.Put( ":" ); |
---|
105 | Ada.Integer_Text_IO.Put( Integer( Diff.TV_Nsec ), 9 ); |
---|
106 | Text_IO.New_Line; |
---|
107 | end loop; |
---|
108 | |
---|
109 | -- |
---|
110 | -- Iterate 10 times showing difference in Uptime with different counts |
---|
111 | -- |
---|
112 | |
---|
113 | TEXT_IO.NEW_LINE; |
---|
114 | TEXT_IO.PUT_LINE( |
---|
115 | "10 iterations of getting Uptime with different loop values" |
---|
116 | ); |
---|
117 | |
---|
118 | for Index in 1 .. 10 loop |
---|
119 | Max := (Index * 10000); |
---|
120 | RTEMS.Clock.Get_Uptime( Start, Status ); |
---|
121 | for j in 1 .. Max loop |
---|
122 | Simple_Procedure; |
---|
123 | end loop; |
---|
124 | RTEMS.Clock.Get_Uptime( Stop, Status ); |
---|
125 | |
---|
126 | Subtract_Em( Start, Stop, Diff ); |
---|
127 | |
---|
128 | Text_IO.Put( "loop of " ); |
---|
129 | Ada.Integer_Text_IO.Put( Max, 6 ); |
---|
130 | Text_IO.Put( " " ); |
---|
131 | Ada.Integer_Text_IO.Put( Integer( Start.TV_Sec ), 1 ); |
---|
132 | Text_IO.Put( ":" ); |
---|
133 | Ada.Integer_Text_IO.Put( Integer( Start.TV_Nsec ), 9 ); |
---|
134 | Text_IO.Put( " " ); |
---|
135 | Ada.Integer_Text_IO.Put( Integer( Stop.TV_Sec ), 1 ); |
---|
136 | Text_IO.Put( ":" ); |
---|
137 | Ada.Integer_Text_IO.Put( Integer( Stop.TV_Nsec ), 9 ); |
---|
138 | Text_IO.Put( " --> " ); |
---|
139 | Ada.Integer_Text_IO.Put( Integer( Diff.TV_Sec ), 1 ); |
---|
140 | Text_IO.Put( ":" ); |
---|
141 | Ada.Integer_Text_IO.Put( Integer( Diff.TV_Nsec ), 9 ); |
---|
142 | Text_IO.New_Line; |
---|
143 | |
---|
144 | end loop; |
---|
145 | |
---|
146 | delay( 1.0 ); |
---|
147 | |
---|
148 | TEST_SUPPORT.ADA_TEST_END; |
---|
149 | |
---|
150 | RTEMS.SHUTDOWN_EXECUTIVE( 0 ); |
---|
151 | |
---|
152 | end INIT; |
---|
153 | |
---|
154 | end SPTEST; |
---|