Warning, /testsuites/ada/samples/nsecs/sptest.adb is written in an unsupported language. File is not indexed.
0001 -- SPDX-License-Identifier: BSD-2-Clause
0002
0003 --
0004 -- SPTEST / BODY
0005 --
0006 -- DESCRIPTION:
0007 --
0008 -- This package is the implementation of the Nanosecond test of the
0009 -- Sample Test Suite.
0010 --
0011 -- DEPENDENCIES:
0012 --
0013 --
0014 --
0015 -- COPYRIGHT (c) 1989-2011.
0016 -- On-Line Applications Research Corporation (OAR).
0017 --
0018 -- Redistribution and use in source and binary forms, with or without
0019 -- modification, are permitted provided that the following conditions
0020 -- are met:
0021 -- 1. Redistributions of source code must retain the above copyright
0022 -- notice, this list of conditions and the following disclaimer.
0023 -- 2. Redistributions in binary form must reproduce the above copyright
0024 -- notice, this list of conditions and the following disclaimer in the
0025 -- documentation and/or other materials provided with the distribution.
0026 --
0027 -- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0028 -- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0029 -- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0030 -- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0031 -- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0032 -- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0033 -- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0034 -- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0035 -- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0036 -- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0037 -- POSSIBILITY OF SUCH DAMAGE.
0038 --
0039
0040 with Ada.Integer_Text_IO;
0041 with Interfaces.C;
0042 with RTEMS;
0043 with RTEMS.Clock;
0044 with Text_IO;
0045 with TEST_SUPPORT;
0046 use type Interfaces.C.Long;
0047 use type RTEMS.Time_T;
0048
0049 package body SPTEST is
0050
0051 Dummy_Variable : Natural := 0;
0052
0053 procedure Simple_Procedure is
0054 begin
0055 Dummy_Variable := Dummy_Variable + 1;
0056 end Simple_Procedure;
0057
0058 procedure Subtract_Em (
0059 Start : in RTEMS.Timespec;
0060 Stop : in RTEMS.Timespec;
0061 Result : out RTEMS.Timespec
0062 ) is
0063 Nanoseconds_Per_Second : constant := 1000000000;
0064 begin
0065 if (Stop.TV_Nsec < Start.TV_Nsec) then
0066 Result.TV_Sec := Stop.TV_Sec - Start.TV_Sec - 1;
0067 Result.TV_Nsec :=
0068 (Nanoseconds_Per_Second - Start.TV_Nsec) + Stop.TV_Nsec;
0069 else
0070 Result.TV_Sec := Stop.TV_Sec - Start.TV_Sec;
0071 Result.TV_Nsec := Stop.TV_Nsec - Start.TV_Nsec;
0072 end if;
0073 end Subtract_Em;
0074
0075
0076 --
0077 -- INIT
0078 --
0079
0080 procedure INIT (
0081 ARGUMENT : in RTEMS.TASKS.ARGUMENT
0082 ) is
0083 pragma Unreferenced(ARGUMENT);
0084 Status : RTEMS.Status_Codes;
0085 Start : RTEMS.Timespec;
0086 Stop : RTEMS.Timespec;
0087 Diff : RTEMS.Timespec;
0088 Max : Integer;
0089 begin
0090
0091 TEXT_IO.NEW_LINE( 2 );
0092 TEST_SUPPORT.ADA_TEST_BEGIN;
0093
0094 --
0095 -- Iterate 10 times showing difference in TOD
0096 --
0097
0098 TEXT_IO.PUT_LINE( "10 iterations of getting TOD NOT tested in Ada" );
0099
0100 --
0101 -- Iterate 10 times showing difference in Uptime
0102 --
0103
0104 TEXT_IO.NEW_LINE;
0105 TEXT_IO.PUT_LINE( "10 iterations of getting Uptime" );
0106
0107 for Index in 1 .. 10 loop
0108
0109 RTEMS.Clock.Get_Uptime( Start, Status );
0110 RTEMS.Clock.Get_Uptime( Stop, Status );
0111
0112 Subtract_Em( Start, Stop, Diff );
0113
0114 Ada.Integer_Text_IO.Put( Integer( Start.TV_Sec ), 1 );
0115 Text_IO.Put( ":" );
0116 Ada.Integer_Text_IO.Put( Integer( Start.TV_Nsec ), 9 );
0117 Text_IO.Put( " " );
0118 Ada.Integer_Text_IO.Put( Integer( Stop.TV_Sec ), 1 );
0119 Text_IO.Put( ":" );
0120 Ada.Integer_Text_IO.Put( Integer( Stop.TV_Nsec ), 9 );
0121 Text_IO.Put( " --> " );
0122 Ada.Integer_Text_IO.Put( Integer( Diff.TV_Sec ), 1 );
0123 Text_IO.Put( ":" );
0124 Ada.Integer_Text_IO.Put( Integer( Diff.TV_Nsec ), 9 );
0125 Text_IO.New_Line;
0126 end loop;
0127
0128 --
0129 -- Iterate 10 times showing difference in Uptime with different counts
0130 --
0131
0132 TEXT_IO.NEW_LINE;
0133 TEXT_IO.PUT_LINE(
0134 "10 iterations of getting Uptime with different loop values"
0135 );
0136
0137 for Index in 1 .. 10 loop
0138 Max := (Index * 10000);
0139 RTEMS.Clock.Get_Uptime( Start, Status );
0140 for j in 1 .. Max loop
0141 Simple_Procedure;
0142 end loop;
0143 RTEMS.Clock.Get_Uptime( Stop, Status );
0144
0145 Subtract_Em( Start, Stop, Diff );
0146
0147 Text_IO.Put( "loop of " );
0148 Ada.Integer_Text_IO.Put( Max, 6 );
0149 Text_IO.Put( " " );
0150 Ada.Integer_Text_IO.Put( Integer( Start.TV_Sec ), 1 );
0151 Text_IO.Put( ":" );
0152 Ada.Integer_Text_IO.Put( Integer( Start.TV_Nsec ), 9 );
0153 Text_IO.Put( " " );
0154 Ada.Integer_Text_IO.Put( Integer( Stop.TV_Sec ), 1 );
0155 Text_IO.Put( ":" );
0156 Ada.Integer_Text_IO.Put( Integer( Stop.TV_Nsec ), 9 );
0157 Text_IO.Put( " --> " );
0158 Ada.Integer_Text_IO.Put( Integer( Diff.TV_Sec ), 1 );
0159 Text_IO.Put( ":" );
0160 Ada.Integer_Text_IO.Put( Integer( Diff.TV_Nsec ), 9 );
0161 Text_IO.New_Line;
0162
0163 end loop;
0164
0165 delay( 1.0 );
0166
0167 TEST_SUPPORT.ADA_TEST_END;
0168
0169 RTEMS.SHUTDOWN_EXECUTIVE( 0 );
0170
0171 end INIT;
0172
0173 end SPTEST;