OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [gcc/] [testsuite/] [ada/] [acats/] [tests/] [c9/] [c940001.a] - Diff between revs 154 and 816

Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
-- C940001.A
-- C940001.A
--
--
--
--
--                             Grant of Unlimited Rights
--                             Grant of Unlimited Rights
--
--
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     Under contracts F33600-87-D-0337, F33600-84-D-0280, MDA903-79-C-0687,
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
--     F08630-91-C-0015, and DCA100-97-D-0025, the U.S. Government obtained
--     unlimited rights in the software and documentation contained herein.
--     unlimited rights in the software and documentation contained herein.
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making
--     Unlimited rights are defined in DFAR 252.227-7013(a)(19).  By making
--     this public release, the Government intends to confer upon all
--     this public release, the Government intends to confer upon all
--     recipients unlimited rights  equal to those held by the Government.
--     recipients unlimited rights  equal to those held by the Government.
--     These rights include rights to use, duplicate, release or disclose the
--     These rights include rights to use, duplicate, release or disclose the
--     released technical data and computer software in whole or in part, in
--     released technical data and computer software in whole or in part, in
--     any manner and for any purpose whatsoever, and to have or permit others
--     any manner and for any purpose whatsoever, and to have or permit others
--     to do so.
--     to do so.
--
--
--                                    DISCLAIMER
--                                    DISCLAIMER
--
--
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     ALL MATERIALS OR INFORMATION HEREIN RELEASED, MADE AVAILABLE OR
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
--     DISCLOSED ARE AS IS.  THE GOVERNMENT MAKES NO EXPRESS OR IMPLIED
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     WARRANTY AS TO ANY MATTER WHATSOEVER, INCLUDING THE CONDITIONS OF THE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
--     SOFTWARE, DOCUMENTATION OR OTHER INFORMATION RELEASED, MADE AVAILABLE
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     OR DISCLOSED, OR THE OWNERSHIP, MERCHANTABILITY, OR FITNESS FOR A
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--     PARTICULAR PURPOSE OF SAID MATERIAL.
--*
--*
--
--
-- OBJECTIVE:
-- OBJECTIVE:
--      Check that a protected object provides coordinated access to
--      Check that a protected object provides coordinated access to
--      shared data.  Check that it can be used to sequence a number of tasks.
--      shared data.  Check that it can be used to sequence a number of tasks.
--      Use the protected object to control a single token for which three
--      Use the protected object to control a single token for which three
--      tasks compete.  Check that only one task is running at a time and that
--      tasks compete.  Check that only one task is running at a time and that
--      all tasks get a chance to run sometime.
--      all tasks get a chance to run sometime.
--
--
-- TEST DESCRIPTION:
-- TEST DESCRIPTION:
--      Declare a protected type with two entries.  A task may call the Take
--      Declare a protected type with two entries.  A task may call the Take
--      entry to get a token which allows it to continue processing.  If it
--      entry to get a token which allows it to continue processing.  If it
--      has the token, it may call the Give entry to return it.  The tasks
--      has the token, it may call the Give entry to return it.  The tasks
--      implement a discipline whereby only the task with the token may be
--      implement a discipline whereby only the task with the token may be
--      active.  The test does not require any specific order for the tasks
--      active.  The test does not require any specific order for the tasks
--      to run.
--      to run.
--
--
--
--
-- CHANGE HISTORY:
-- CHANGE HISTORY:
--      06 Dec 94   SAIC    ACVC 2.0
--      06 Dec 94   SAIC    ACVC 2.0
--      07 Jul 96   SAIC    Fixed spelling nits.
--      07 Jul 96   SAIC    Fixed spelling nits.
--
--
--!
--!
package C940001_0 is
package C940001_0 is
  type Token_Type is private;
  type Token_Type is private;
  True_Token : constant Token_Type;   -- Create a deferred constant in order
  True_Token : constant Token_Type;   -- Create a deferred constant in order
                                      -- to provide a component init for the
                                      -- to provide a component init for the
                                      -- protected object
                                      -- protected object
  protected type Token_Mgr_Prot_Unit is
  protected type Token_Mgr_Prot_Unit is
    entry Take (T : out Token_Type);
    entry Take (T : out Token_Type);
    entry Give (T : in out  Token_Type);
    entry Give (T : in out  Token_Type);
  private
  private
    Token : Token_Type := True_Token;
    Token : Token_Type := True_Token;
  end Token_Mgr_Prot_Unit;
  end Token_Mgr_Prot_Unit;
  function Init_Token return Token_Type;   -- call to initialize an
  function Init_Token return Token_Type;   -- call to initialize an
                                           -- object of Token_Type
                                           -- object of Token_Type
  function Token_Value (T : Token_Type) return Boolean;
  function Token_Value (T : Token_Type) return Boolean;
                                           -- call to inspect the value of an
                                           -- call to inspect the value of an
                                           -- object of Token_Type
                                           -- object of Token_Type
private
private
  type Token_Type is new boolean;
  type Token_Type is new boolean;
  True_Token : constant Token_Type := true;
  True_Token : constant Token_Type := true;
end C940001_0;
end C940001_0;
--=================================================================--
--=================================================================--
package body C940001_0 is
package body C940001_0 is
  protected body  Token_Mgr_Prot_Unit is
  protected body  Token_Mgr_Prot_Unit is
    entry Take (T : out Token_Type) when Token = true is
    entry Take (T : out Token_Type) when Token = true is
      begin                   -- Calling task will Take the token, so
      begin                   -- Calling task will Take the token, so
        T := Token;           -- check first that token_mgr owns the
        T := Token;           -- check first that token_mgr owns the
        Token := false;       -- token to give, then give it to caller
        Token := false;       -- token to give, then give it to caller
      end Take;
      end Take;
    entry Give (T : in out Token_Type)  when Token = false is
    entry Give (T : in out Token_Type)  when Token = false is
      begin                   -- Calling task will Give the token back,
      begin                   -- Calling task will Give the token back,
        if T = true then      -- so first check that token_mgr does not
        if T = true then      -- so first check that token_mgr does not
          Token := T;         -- own the token, then check that the task has
          Token := T;         -- own the token, then check that the task has
          T := false;         -- the token to give, then take it from the
          T := false;         -- the token to give, then take it from the
        end if;               -- task
        end if;               -- task
                              -- if caller does not own the token, then
                              -- if caller does not own the token, then
      end Give;               -- it falls out of the entry body with no
      end Give;               -- it falls out of the entry body with no
  end Token_Mgr_Prot_Unit;    -- action
  end Token_Mgr_Prot_Unit;    -- action
  function Init_Token return Token_Type is
  function Init_Token return Token_Type is
    begin
    begin
      return false;
      return false;
    end Init_Token;
    end Init_Token;
  function Token_Value (T : Token_Type) return Boolean is
  function Token_Value (T : Token_Type) return Boolean is
    begin
    begin
      return Boolean (T);
      return Boolean (T);
    end Token_Value;
    end Token_Value;
end C940001_0;
end C940001_0;
--===============================================================--
--===============================================================--
with Report;
with Report;
with ImpDef;
with ImpDef;
with C940001_0;
with C940001_0;
procedure C940001 is
procedure C940001 is
  type TC_Int_Type is range 0..2;
  type TC_Int_Type is range 0..2;
              -- range is very narrow so that erroneous execution may
              -- range is very narrow so that erroneous execution may
              -- raise Constraint_Error
              -- raise Constraint_Error
  type TC_Artifact_Type is record
  type TC_Artifact_Type is record
     TC_Int : TC_Int_Type := 1;
     TC_Int : TC_Int_Type := 1;
     Number_of_Accesses : integer := 0;
     Number_of_Accesses : integer := 0;
  end record;
  end record;
  TC_Artifact : TC_Artifact_Type;
  TC_Artifact : TC_Artifact_Type;
  Sequence_Mgr : C940001_0.Token_Mgr_Prot_Unit;
  Sequence_Mgr : C940001_0.Token_Mgr_Prot_Unit;
  procedure Bump (Item : in out TC_Int_Type) is
  procedure Bump (Item : in out TC_Int_Type) is
    begin
    begin
      Item := Item + 1;
      Item := Item + 1;
    exception
    exception
      when Constraint_Error =>
      when Constraint_Error =>
        Report.Failed ("Incremented without corresponding decrement");
        Report.Failed ("Incremented without corresponding decrement");
      when others =>
      when others =>
        Report.Failed ("Bump raised Unexpected Exception");
        Report.Failed ("Bump raised Unexpected Exception");
   end Bump;
   end Bump;
  procedure Decrement (Item : in out TC_Int_Type) is
  procedure Decrement (Item : in out TC_Int_Type) is
    begin
    begin
      Item := Item - 1;
      Item := Item - 1;
    exception
    exception
      when Constraint_Error =>
      when Constraint_Error =>
        Report.Failed ("Decremented without corresponding increment");
        Report.Failed ("Decremented without corresponding increment");
      when others =>
      when others =>
        Report.Failed ("Decrement raised Unexpected Exception");
        Report.Failed ("Decrement raised Unexpected Exception");
    end Decrement;
    end Decrement;
    --==============--
    --==============--
  task type Network_Node_Type;
  task type Network_Node_Type;
  task body Network_Node_Type is
  task body Network_Node_Type is
    Slot_for_Token : C940001_0.Token_Type := C940001_0.Init_Token;
    Slot_for_Token : C940001_0.Token_Type := C940001_0.Init_Token;
    begin
    begin
      -- Ask for token - if request is not granted, task will be queued
      -- Ask for token - if request is not granted, task will be queued
      Sequence_Mgr.Take (Slot_for_Token);
      Sequence_Mgr.Take (Slot_for_Token);
      -- Task now has token and may perform its work
      -- Task now has token and may perform its work
      --==========================--
      --==========================--
      -- in this case, the work is to ensure that the test results
      -- in this case, the work is to ensure that the test results
      -- are the expected ones!
      -- are the expected ones!
      --==========================--
      --==========================--
      Bump (TC_Artifact.TC_Int);   -- increment when request is granted
      Bump (TC_Artifact.TC_Int);   -- increment when request is granted
      TC_Artifact.Number_Of_Accesses :=
      TC_Artifact.Number_Of_Accesses :=
        TC_Artifact.Number_Of_Accesses + 1;
        TC_Artifact.Number_Of_Accesses + 1;
      if not C940001_0.Token_Value ( Slot_for_Token) then
      if not C940001_0.Token_Value ( Slot_for_Token) then
        Report.Failed ("Incorrect results from entry Take");
        Report.Failed ("Incorrect results from entry Take");
      end if;
      end if;
      -- give a chance for other tasks to (incorrectly) run
      -- give a chance for other tasks to (incorrectly) run
      delay ImpDef.Minimum_Task_Switch;
      delay ImpDef.Minimum_Task_Switch;
      Decrement (TC_Artifact.TC_Int); -- prepare to return token
      Decrement (TC_Artifact.TC_Int); -- prepare to return token
      -- Task has completed its work and will return token
      -- Task has completed its work and will return token
      Sequence_Mgr.Give (Slot_for_Token);   -- return token to sequence manager
      Sequence_Mgr.Give (Slot_for_Token);   -- return token to sequence manager
      if c940001_0.Token_Value (Slot_for_Token) then
      if c940001_0.Token_Value (Slot_for_Token) then
        Report.Failed ("Incorrect results from entry Give");
        Report.Failed ("Incorrect results from entry Give");
      end if;
      end if;
    exception
    exception
      when others => Report.Failed ("Unexpected exception raised in task");
      when others => Report.Failed ("Unexpected exception raised in task");
    end Network_Node_Type;
    end Network_Node_Type;
    --==============--
    --==============--
begin
begin
  Report.Test ("C940001", "Check that a protected object can control " &
  Report.Test ("C940001", "Check that a protected object can control " &
                          "tasks by coordinating access to shared data");
                          "tasks by coordinating access to shared data");
  declare
  declare
     Node_1, Node_2, Node_3 : Network_Node_Type;
     Node_1, Node_2, Node_3 : Network_Node_Type;
                           -- declare three tasks which will compete for
                           -- declare three tasks which will compete for
                           -- a single token, managed by Sequence Manager
                           -- a single token, managed by Sequence Manager
  begin                    -- tasks start
  begin                    -- tasks start
    null;
    null;
  end; -- wait for all tasks to terminate before reporting result
  end; -- wait for all tasks to terminate before reporting result
  if TC_Artifact.Number_of_Accesses /= 3 then
  if TC_Artifact.Number_of_Accesses /= 3 then
    Report.Failed ("Not all tasks got through");
    Report.Failed ("Not all tasks got through");
  end if;
  end if;
  Report.Result;
  Report.Result;
end C940001;
end C940001;
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.