c954021.a

来自「用于进行gcc测试」· A 代码 · 共 525 行 · 第 1/2 页

A
525
字号
         return Number_Complete;      end Count;   end TC_Tasks_Completed;   -- Assemble messages received from an external source   --   Creates a message task for each. The message tasks remain extant   --   for the life of the messages in the system.   --      The Line Driver task would normally be designed to loop continuously   --      creating the messages as input is received.  Simulate this    --      but limit it to the required number of dummy messages needed for   --      this test and allow it to terminate at that point.  Artificially   --      alternate High and Low priority Credit transactions for this test.   --   task body Line_Driver is      Current_ID       : integer := 1;      Current_Priority : Transaction_Priority := High;            -- Artificial: number of messages required for this test      type TC_Trans_Range is range 1..6;      procedure Build_Credit_Record                               ( Next_Transaction : acc_Transaction_Record ) is         Dummy_Account : constant integer := 100;      begin            Next_Transaction.ID := Current_ID;            Next_Transaction.Code := Credit;             Next_Transaction.Priority := Current_Priority;            Next_Transaction.Account_Number := Dummy_Account;            Current_ID := Current_ID + 1;      end Build_Credit_Record;           procedure Build_Debit_Record                               ( Next_Transaction : acc_Transaction_Record ) is         Dummy_Account : constant integer := 200;      begin            Next_Transaction.ID := Current_ID;            Next_Transaction.Code := Debit;             Next_Transaction.Account_Number := Dummy_Account;            Current_ID := Current_ID + 1;      end Build_Debit_Record;        begin            accept Start;   -- Wait for trigger from Main      for Transaction_Numb in TC_Trans_Range loop  -- TC: limit the loop         declare             -- Create a task for the next message            Next_Message_Task : acc_Message_Task := new Message_Task;            -- Create a record for it            Next_Transaction : acc_Transaction_Record :=                                                 new Transaction_Record;         begin            if Transaction_Numb = TC_Trans_Range'first then               -- Send the first Credit message               Build_Credit_Record ( Next_Transaction );               Next_Message_Task.Accept_Transaction ( Next_Transaction );                 -- TC: Wait until the first message has been received by the               -- Credit task and it has set the Overload indicator for the                -- Distributor               while not TC_Handshake.First_Message_Arrived loop                  delay ImpDef.Minimum_Task_Switch;                  end loop;            elsif Transaction_Numb = TC_Trans_Range'last then               -- For this test send the last transaction to the Debit task               -- to improve the mix               Build_Debit_Record( Next_Transaction );               Next_Message_Task.Accept_Transaction ( Next_Transaction );              else               -- TC: Alternate high and low priority transactions               if Current_Priority = High then                  Current_Priority := Low;               else                  Current_Priority := High;               end if;               Build_Credit_Record( Next_Transaction );               Next_Message_Task.Accept_Transaction ( Next_Transaction );              end if;         end;   -- declare      end loop;   exception      when others =>          Report.Failed ("Unexpected exception in Line_Driver");   end Line_Driver;      task body Message_Task is      TC_Original_Transaction_Code : Transaction_Code;        This_Transaction : acc_Transaction_Record := new Transaction_Record;   begin            accept Accept_Transaction (In_Transaction : acc_Transaction_Record) do         This_Transaction.all := In_Transaction.all;      end Accept_Transaction;      -- Note the original code to ensure correct return      TC_Original_Transaction_Code := This_Transaction.Code;       -- Queue up on Distributor's Input queue      Distributor.Input ( This_Transaction );      -- This task will now wait for the requeued rendezvous       -- to complete before proceeding      -- After the required computations have been performed      -- return the Transaction_Record appropriately (probably to an output      -- line driver)      null;            -- stub            -- For the test check that the return values are as expected      if TC_Original_Transaction_Code /= This_Transaction.Code then         -- Incorrect rendezvous         Report.Failed ("Message Task: Incorrect code returned");      end if;      if This_Transaction.Code = Credit then         if This_Transaction.Return_Value  /= Credit_Return   or         not This_Transaction.TC_thru_Dist                    then            Report.Failed ("Expected path not traversed - Credit");         end if;         TC_Tasks_Completed.Increment;      else         if This_Transaction.Return_Value  /= Debit_Return or               This_Transaction.TC_Message_Count /= 1         or            not This_Transaction.TC_thru_Dist               then               Report.Failed ("Expected path not traversed - Debit");         end if;         TC_Debit_Message_Complete.Set_True;      end if;   exception      when others =>          Report.Failed ("Unexpected exception in Message_Task");   end Message_Task;     -- Computation task.  After the computation is performed the rendezvous   -- in the original message task is completed.                                 task body Credit_Computation is      Message_Count   : integer := 0;         begin      loop         select             accept Input ( Transaction : acc_Transaction_Record) do               if Distributor.Credit_is_Overloaded                                    and Transaction.Priority = Low  then                   -- We should not be getting any Low Priority messages. They                  -- should be waiting on the Hold.Wait_for_Underload                   -- queue                  Report.Failed                      ("Credit Task: Low priority transaction during overload");               end if;               -- Perform the computations required for this transaction               null; -- stub               -- For the test:                if not Transaction.TC_thru_Dist then                  Report.Failed                          ("Credit Task: Wrong queue, Distributor bypassed");               end if;               if Transaction.code /= Credit then                  Report.Failed                         ("Credit Task: Requeue delivered to the wrong queue");               end if;               -- The following is all Test Control code:               Transaction.Return_Value := Credit_Return;               Message_Count := Message_Count + 1;               --               -- Now take special action depending on which Message               if Message_Count = 1 then                   -- After the first message :                  Distributor.Set_Credit_Overloaded;                  -- Now flag the Line_Driver that the second and subsequent                  -- messages may now be sent                  TC_Handshake.Set;               end if;               if Message_Count = 3 then                  -- The two high priority transactions created subsequent                  -- to the overload have now been processed                  Distributor.Clear_Credit_Overloaded;               end if;            end Input;                     or            terminate;         end select;      end loop;   exception      when others =>          Report.Failed ("Unexpected exception in Credit_Computation");   end Credit_Computation;   -- Computation task.  After the computation is performed the rendezvous   -- in the original message task is completed.           --                         task body Debit_Computation is      Message_Count   : integer := 0;   begin      loop         select            accept Input (Transaction : acc_Transaction_Record) do               -- Perform the computations required for this message               null;      -- stub               -- For the test:                if not Transaction.TC_thru_Dist then                  Report.Failed                          ("Debit Task: Wrong queue, Distributor bypassed");               end if;               if Transaction.code /= Debit then                  Report.Failed                         ("Debit Task: Requeue delivered to the wrong queue");               end if;               -- for the test plug a known value and count               Transaction.Return_Value := Debit_Return;               -- one, and only one, message should pass through               Message_Count := Message_Count + 1;               Transaction.TC_Message_Count := Message_Count;            end Input;                     or            terminate;         end select;      end loop;   exception      when others =>          Report.Failed ("Unexpected exception in Debit_Computation");   end Debit_Computation;begin    Report.Test ("C954021", "Requeue from one entry body to an entry in" &                                       " another protected object");   Line_Driver.Start;  -- Start the test   -- Ensure that the message tasks have completed before reporting result   while (TC_Tasks_Completed.Count < TC_Credit_Messages_Expected)          and not TC_Debit_Message_Complete.Value loop      delay ImpDef.Minimum_Task_Switch;      end loop;   Report.Result;end C954021;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?