1-- C974014.A
2--
3--                             Grant of Unlimited Rights
4--
5--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
6--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
7--     unlimited rights in the software and documentation contained herein.
8--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making
9--     this public release, the Government intends to confer upon all
10--     recipients unlimited rights  equal to those held by the Government.
11--     These rights include rights to use, duplicate, release or disclose the
12--     released technical data and computer software in whole or in part, in
13--     any manner and for any purpose whatsoever, and to have or permit others
14--     to do so.
15--
16--                                    DISCLAIMER
17--
18--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
19--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
20--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
21--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
22--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
23--     PARTICULAR PURPOSE OF SAID MATERIAL.
24--*
25--
26-- OBJECTIVE:
27--      Check that if the triggering alternative of an asynchronous select
28--      statement is a delay and the abortable part completes before the delay
29--      expires then the delay is cancelled and the optional statements in the
30--      triggering part are not performed.  In particular, check the case of
31--      the ATC in non-tasking code.
32--
33-- TEST DESCRIPTION:
34--      A fraction of in-line code is simulated.  An asynchronous select
35--      is used with a triggering delay of several minutes.  The abortable
36--      part, which is simulating a very lengthy, time consuming procedure
37--      actually returns almost immediately thus ensuring that it completes
38--      first.  At the conclusion, if a substantial amount of time has passed
39--      the delay is assumed not to have been cancelled.
40--      (based on example in LRM 9.7.4)
41--
42--
43-- CHANGE HISTORY:
44--      06 Dec 94   SAIC    ACVC 2.0
45--
46--!
47
48
49with Report;
50with Ada.Calendar;
51
52procedure C974014 is
53
54   function "-" (Left, Right : Ada.Calendar.Time)
55                              return Duration      renames Ada.Calendar."-";
56
57   TC_Start_Time      : Ada.Calendar.Time := Ada.Calendar.Clock;
58   TC_Elapsed_Time    : duration;
59
60   Maximum_Allowable_Time : duration := 300.0; -- for Calculate_Gamma_Function
61
62begin
63
64   Report.Test ("C974014", "ATC: When abortable part completes before " &
65                             "a triggering delay, check that the delay " &
66                             "is cancelled & optional statements " &
67                             "are not performed");
68
69   declare  -- encapsulate test code
70
71      type Gamma_Index is digits 5;   -- float precision
72
73      -- (These two fields are assumed filled elsewhere)
74      Input_Field, Result_of_Beta : Gamma_Index;
75
76      -- Notify and take corrective action in the event that
77      -- the procedure Calculate_Gamma_Function does not converge.
78      --
79      procedure Non_Convergent is
80      begin
81         null;  -- stub
82
83         Report.Failed ("Optional statements in triggering part" &
84                                    " were performed");
85      end Non_Convergent;
86
87
88      --  This is a very time consuming calculation.  It is possible,
89      --  that, with certain parameters, it will not converge.  If it
90      --  runs for more than Maximum_Allowable_Time it is considered
91      --  not to be convergent and should be aborted.
92      --
93      Procedure Calculate_Gamma_Function (X, Y : Gamma_Index) is
94      begin
95         null;  -- Stub
96         --
97      end Calculate_Gamma_Function;
98
99   begin  -- declare
100
101      -- .....  Isolated segment of inline code
102
103      -- Now Print Gamma Function (abort and display if not convergent)
104      --
105      select
106         delay Maximum_Allowable_Time;  -- for Calculate_Gamma_Function
107         Non_Convergent;   -- Display error and flag result as failed
108
109      then abort
110         Calculate_Gamma_Function (Input_Field, Result_of_Beta);
111      end select;
112
113      -- .....  End of Isolated segment of inline code
114
115   end; -- declare
116
117   TC_Elapsed_Time := Ada.Calendar.Clock - TC_Start_Time;
118
119   -- Note: We are not checking for "cancellation within a reasonable time",
120   -- we are checking for cancellation/non-cancellation of the delay.  We
121   -- use a number which, if exceeded, means that the delay was not
122   -- cancelled and has proceeded to  full term.
123   --
124   if ( TC_Elapsed_Time > Maximum_Allowable_Time/2 ) then
125      -- Test time exceeds a reasonable value.
126      Report.Failed ("Triggering delay statement was not cancelled");
127   end if;
128
129
130   Report.Result;
131
132end C974014;
133