Skip to content

Commit

Permalink
Add validation unit tests to Parameters component
Browse files Browse the repository at this point in the history
  • Loading branch information
Jbsco committed Aug 13, 2024
1 parent bba0b9b commit 3071231
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/components/parameters/test/parameters.tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ tests:
description: This unit test tests the nominal updating of the parameter table by command.
- name: Test_Nominal_Table_Upload
description: This unit test tests the nominal updating of the parameter table by memory region upload.
- name: Test_Nominal_Table_Validate
description: This unit test tests the nominal validation of the parameter table by memory region upload.
- name: Test_Nominal_Table_Fetch
description: This unit test tests the nominal fetching of the parameter table by into a provided memory region.
- name: Test_Dump_Parameters_Error
Expand All @@ -17,6 +19,8 @@ tests:
description: This unit test tests the behavior when updating of the parameter table fails.
- name: Test_Table_Upload_Error
description: This unit test tests the behavior when updating of the parameter table by memory region upload fails.
- name: Test_Table_Validate_Error
description: This unit test tests the behavior when validation of the parameter table by memory region upload fails.
- name: Test_Table_Fetch_Error
description: This unit test tests the behavior when fetching of the parameter table into a memory region fails.
- name: Test_No_Dump_On_Change
Expand Down
89 changes: 89 additions & 0 deletions src/components/parameters/test/parameters_tests-implementation.adb
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,37 @@ package body Parameters_Tests.Implementation is
Parameters_Memory_Region_Release_Assert.Eq (T.Parameters_Memory_Region_Release_T_Recv_Sync_History.Get (1), (Region, Success));
end Test_Nominal_Table_Upload;

overriding procedure Test_Nominal_Table_Validate (Self : in out Instance) is
use Parameter_Enums.Parameter_Table_Update_Status;
use Parameter_Enums.Parameter_Table_Operation_Type;
T : Component.Parameters.Implementation.Tester.Instance_Access renames Self.Tester;
-- Create a memory region that holds the parameter table data.
Table : aliased Test_Parameter_Table_Record.Serialization.Byte_Array :=
Test_Parameter_Table_Record.Serialization.To_Byte_Array
((Crc_Calculated => [0, 0], Header => (Crc_Table => [0, 0], Version => 1.0), Component_A_Parameter_I32 => (Value => 99), Component_C_The_Tick => ((3, 2), 8), Component_A_Parameter_U16 => (Value => 19), Component_B_Parameter_U16 => (Value => 12),
Component_B_Parameter_I32 => (Value => -22)));
Crc : constant Crc_16.Crc_16_Type := Crc_16.Compute_Crc_16 (Table (Table'First + Crc_16.Crc_16_Type'Length + Parameter_Table_Header.Crc_Section_Length .. Table'Last));
Region : constant Memory_Region.T := (Address => Table'Address + Crc_16.Crc_16_Type'Length, Length => Test_Parameter_Table_Record.Serialization.Serialized_Length - Crc_16.Crc_16_Type'Length);
begin
-- Set the CRC:
Table (Table'First + Crc_16.Crc_16_Type'Length .. Table'First + Crc_16.Crc_16_Type'Length + Parameter_Table_Header.Size_In_Bytes - 1) := Parameter_Table_Header.Serialization.To_Byte_Array ((Crc_Table => Crc, Version => 1.0));
Table (Table'First .. Table'First + Crc_16.Crc_16_Type'Length - 1) := Crc;

-- Send the memory region to the component:
T.Parameters_Memory_Region_T_Send ((Region => Region, Operation => Validate));
Natural_Assert.Eq (T.Dispatch_All, 1);

-- Check no failure event was received:
Natural_Assert.Eq (T.Parameter_Validation_Failed_History.Get_Count, 0);

-- A packet should not have been automatically dumped.
Natural_Assert.Eq (T.Packet_T_Recv_Sync_History.Get_Count, 0);

-- Make sure the memory location was released with the proper status:
Natural_Assert.Eq (T.Parameters_Memory_Region_Release_T_Recv_Sync_History.Get_Count, 1);
Parameters_Memory_Region_Release_Assert.Eq (T.Parameters_Memory_Region_Release_T_Recv_Sync_History.Get (1), (Region, Success));
end Test_Nominal_Table_Validate;

overriding procedure Test_Nominal_Table_Fetch (Self : in out Instance) is
use Parameter_Enums.Parameter_Table_Update_Status;
use Parameter_Enums.Parameter_Table_Operation_Type;
Expand Down Expand Up @@ -648,6 +679,64 @@ package body Parameters_Tests.Implementation is
Parameters_Memory_Region_Release_Assert.Eq (T.Parameters_Memory_Region_Release_T_Recv_Sync_History.Get (2), ((Address => Table'Address, Length => Table'Length), Crc_Error));
end Test_Table_Upload_Error;

overriding procedure Test_Table_Validate_Error (Self : in out Instance) is
use Parameter_Enums.Parameter_Update_Status;
use Parameter_Enums.Parameter_Table_Update_Status;
use Parameter_Enums.Parameter_Table_Operation_Type;
use Parameter_Enums.Parameter_Operation_Type;
T : Component.Parameters.Implementation.Tester.Instance_Access renames Self.Tester;
-- Create a memory region that holds the parameter table data.
Dump : constant Test_Parameter_Table_Record.Serialization.Byte_Array :=
Test_Parameter_Table_Record.Serialization.To_Byte_Array
((Crc_Calculated => [0, 0], Header => (Crc_Table => [0, 0], Version => 1.0), Component_A_Parameter_I32 => (Value => 99), Component_C_The_Tick => ((3, 2), 8), Component_A_Parameter_U16 => (Value => 19), Component_B_Parameter_U16 => (Value => 12),
Component_B_Parameter_I32 => (Value => -22)));
Table : aliased Basic_Types.Byte_Array (0 .. Test_Parameter_Table_Record.Size_In_Bytes - Crc_16.Crc_16_Type'Length - 1) := Dump (Dump'First + Crc_16.Crc_16_Type'Length .. Dump'Last);
Crc : constant Crc_16.Crc_16_Type := Crc_16.Compute_Crc_16 (Table (Table'First + Parameter_Table_Header.Crc_Section_Length .. Table'Last));
Region : constant Memory_Region.T := (Address => Table'Address, Length => Table'Length);
begin
-- Set the CRC:
Table (Table'First .. Table'First + Parameter_Table_Header.Size_In_Bytes - 1) := Parameter_Table_Header.Serialization.To_Byte_Array ((Crc_Table => Crc, Version => 1.0));

-- Set A to return a bad status:
T.Component_A.Override_Parameter_Return (Status => Validation_Error, Length => 0);

-- Send the memory region to the component:
T.Parameters_Memory_Region_T_Send ((Region => Region, Operation => Validate));
Natural_Assert.Eq (T.Dispatch_All, 1);

-- Check events:
Natural_Assert.Eq (T.Event_T_Recv_Sync_History.Get_Count, 3);
Natural_Assert.Eq (T.Parameter_Stage_Failed_History.Get_Count, 2);
Parameter_Operation_Status_Assert.Eq (T.Parameter_Stage_Failed_History.Get (1), (Operation => Stage, Status => Validation_Error, Id => 2));
Parameter_Operation_Status_Assert.Eq (T.Parameter_Stage_Failed_History.Get (2), (Operation => Stage, Status => Validation_Error, Id => 1));
Natural_Assert.Eq (T.Parameter_Validation_Failed_History.Get_Count, 1);
Parameter_Operation_Status_Assert.Eq (T.Parameter_Validation_Failed_History.Get (1), (Operation => Validate, Status => Validation_Error, Id => 0));

-- Make sure the memory location was released with the proper status:
Natural_Assert.Eq (T.Parameters_Memory_Region_Release_T_Recv_Sync_History.Get_Count, 1);
Parameters_Memory_Region_Release_Assert.Eq (T.Parameters_Memory_Region_Release_T_Recv_Sync_History.Get (1), (Region, Parameter_Error));

--
-- Send the memory region to the component with a get request, but with bad CRC:
--
Table (Table'First .. Table'First + Parameter_Table_Header.Size_In_Bytes - 1) := Parameter_Table_Header.Serialization.To_Byte_Array ((Crc_Table => [6, 7], Version => 1.0));
T.Parameters_Memory_Region_T_Send ((Region => (Address => Table'Address, Length => Table'Length), Operation => Validate));
Natural_Assert.Eq (T.Dispatch_All, 1);

-- Check events:
Natural_Assert.Eq (T.Event_T_Recv_Sync_History.Get_Count, 4);
Natural_Assert.Eq (T.Memory_Region_Crc_Invalid_History.Get_Count, 1);
Invalid_Parameters_Memory_Region_Crc_Assert.Eq
(T.Memory_Region_Crc_Invalid_History.Get (1), (Parameters_Region => (Region => (Address => Table'Address, Length => Table'Length), Operation => Validate), Header => (Crc_Table => [6, 7], Version => 1.0), Computed_Crc => Crc));

-- A packet should not have been automatically dumped.
Natural_Assert.Eq (T.Packet_T_Recv_Sync_History.Get_Count, 0);

-- Make sure the memory location was released with the proper status:
Natural_Assert.Eq (T.Parameters_Memory_Region_Release_T_Recv_Sync_History.Get_Count, 2);
Parameters_Memory_Region_Release_Assert.Eq (T.Parameters_Memory_Region_Release_T_Recv_Sync_History.Get (2), ((Address => Table'Address, Length => Table'Length), Crc_Error));
end Test_Table_Validate_Error;

overriding procedure Test_Table_Fetch_Error (Self : in out Instance) is
use Parameter_Enums.Parameter_Update_Status;
use Parameter_Enums.Parameter_Table_Update_Status;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ private
overriding procedure Test_Nominal_Update_Parameters (Self : in out Instance);
-- This unit test tests the nominal updating of the parameter table by memory region upload.
overriding procedure Test_Nominal_Table_Upload (Self : in out Instance);
-- This unit test tests the nominal validation of the parameter table by memory region upload.
overriding procedure Test_Nominal_Table_Validate (Self : in out Instance);
-- This unit test tests the nominal fetching of the parameter table by into a provided memory region.
overriding procedure Test_Nominal_Table_Fetch (Self : in out Instance);
-- This unit test tests the behavior when dumping the parameter table fails.
Expand All @@ -27,6 +29,8 @@ private
overriding procedure Test_Update_Parameters_Error (Self : in out Instance);
-- This unit test tests the behavior when updating of the parameter table by memory region upload fails.
overriding procedure Test_Table_Upload_Error (Self : in out Instance);
-- This unit test tests the behavior when validation of the parameter table by memory region upload fails.
overriding procedure Test_Table_Validate_Error (Self : in out Instance);
-- This unit test tests the behavior when fetching of the parameter table into a memory region fails.
overriding procedure Test_Table_Fetch_Error (Self : in out Instance);
-- This unit test tests the no-dump-on-change configuration for the Init function and makes sure the component behaves as expected.
Expand Down

0 comments on commit 3071231

Please sign in to comment.