Skip to content

Commit 733d272

Browse files
committed
Implement unit tests for sunlineSRuKF
1 parent 414b0e5 commit 733d272

8 files changed

+414
-0
lines changed

src/components/sunline_srukf/.all_path

Whitespace-only changes.
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
--------------------------------------------------------------------------------
2+
-- Sunline_Srukf Component Tester Body
3+
--------------------------------------------------------------------------------
4+
5+
package body Component.Sunline_Srukf.Implementation.Tester is
6+
7+
---------------------------------------
8+
-- Initialize heap variables:
9+
---------------------------------------
10+
procedure Init_Base (Self : in out Instance) is
11+
begin
12+
-- Initialize tester heap:
13+
-- Connector histories:
14+
Self.Data_Product_Fetch_T_Service_History.Init (Depth => 100);
15+
Self.Data_Product_T_Recv_Sync_History.Init (Depth => 100);
16+
-- Data product histories:
17+
Self.Sunline_Srukf_State_History.Init (Depth => 100);
18+
end Init_Base;
19+
20+
procedure Final_Base (Self : in out Instance) is
21+
begin
22+
-- Destroy tester heap:
23+
-- Connector histories:
24+
Self.Data_Product_Fetch_T_Service_History.Destroy;
25+
Self.Data_Product_T_Recv_Sync_History.Destroy;
26+
-- Data product histories:
27+
Self.Sunline_Srukf_State_History.Destroy;
28+
end Final_Base;
29+
30+
---------------------------------------
31+
-- Test initialization functions:
32+
---------------------------------------
33+
procedure Connect (Self : in out Instance) is
34+
begin
35+
Self.Component_Instance.Attach_Data_Product_Fetch_T_Request (To_Component => Self'Unchecked_Access, Hook => Self.Data_Product_Fetch_T_Service_Access);
36+
Self.Component_Instance.Attach_Data_Product_T_Send (To_Component => Self'Unchecked_Access, Hook => Self.Data_Product_T_Recv_Sync_Access);
37+
Self.Attach_Tick_T_Send (To_Component => Self.Component_Instance'Unchecked_Access, Hook => Self.Component_Instance.Tick_T_Recv_Sync_Access);
38+
end Connect;
39+
40+
-- Helper function for returning data dependencies:
41+
function Return_Data_Dependency (Self : in out Instance; Arg : in Data_Product_Fetch.T) return Data_Product_Return.T is
42+
use Data_Product_Types;
43+
use Data_Product_Enums.Fetch_Status;
44+
use Sys_Time;
45+
-- Set default return values. These will be overridden below based on test configuration and
46+
-- the ID requested.
47+
Id_To_Return : Data_Product_Types.Data_Product_Id := Self.Data_Dependency_Return_Id_Override;
48+
Length_To_Return : Data_Product_Types.Data_Product_Buffer_Length_Type := Self.Data_Dependency_Return_Length_Override;
49+
Return_Status : Data_Product_Enums.Fetch_Status.E := Self.Data_Dependency_Return_Status_Override;
50+
Buffer_To_Return : Data_Product_Types.Data_Product_Buffer_Type;
51+
Time_To_Return : Sys_Time.T := Self.Data_Dependency_Timestamp_Override;
52+
begin
53+
-- Determine return data product ID:
54+
if Id_To_Return = 0 then
55+
case Arg.Id is
56+
-- ID for Spacecraft_Attitude:
57+
when 0 => Id_To_Return := 0;
58+
-- If ID can not be found, then return ID out of range error.
59+
when others =>
60+
if Return_Status = Data_Product_Enums.Fetch_Status.Success then
61+
Return_Status := Data_Product_Enums.Fetch_Status.Id_Out_Of_Range;
62+
end if;
63+
end case;
64+
end if;
65+
66+
-- Determine return data product length:
67+
if Length_To_Return = 0 then
68+
case Arg.Id is
69+
-- Length for Spacecraft_Attitude:
70+
when 0 => Length_To_Return := Nav_Att.Size_In_Bytes;
71+
-- If ID can not be found, then return ID out of range error.
72+
when others =>
73+
if Return_Status = Data_Product_Enums.Fetch_Status.Success then
74+
Return_Status := Data_Product_Enums.Fetch_Status.Id_Out_Of_Range;
75+
end if;
76+
end case;
77+
end if;
78+
79+
-- Determine return timestamp:
80+
if Time_To_Return = (0, 0) then
81+
Time_To_Return := Self.System_Time;
82+
end if;
83+
84+
-- Fill the data product buffer:
85+
if Return_Status = Data_Product_Enums.Fetch_Status.Success then
86+
case Arg.Id is
87+
-- Length for Spacecraft_Attitude:
88+
when 0 =>
89+
Buffer_To_Return (Buffer_To_Return'First .. Buffer_To_Return'First + Nav_Att.Size_In_Bytes - 1) :=
90+
Nav_Att.Serialization.To_Byte_Array (Self.Spacecraft_Attitude);
91+
-- Do not fill. The ID is not recognized.
92+
when others =>
93+
Return_Status := Data_Product_Enums.Fetch_Status.Id_Out_Of_Range;
94+
end case;
95+
end if;
96+
97+
-- Return the data product with the status:
98+
return (
99+
The_Status => Return_Status,
100+
The_Data_Product => (
101+
Header => (
102+
Time => Time_To_Return,
103+
Id => Id_To_Return,
104+
Buffer_Length => Length_To_Return
105+
),
106+
Buffer => Buffer_To_Return
107+
)
108+
);
109+
end Return_Data_Dependency;
110+
111+
---------------------------------------
112+
-- Invokee connector primitives:
113+
---------------------------------------
114+
-- Fetch a data product item from the database.
115+
overriding function Data_Product_Fetch_T_Service (Self : in out Instance; Arg : in Data_Product_Fetch.T) return Data_Product_Return.T is
116+
To_Return : constant Data_Product_Return.T := Self.Return_Data_Dependency (Arg);
117+
begin
118+
-- Push the argument onto the test history for looking at later:
119+
Self.Data_Product_Fetch_T_Service_History.Push (Arg);
120+
return To_Return;
121+
end Data_Product_Fetch_T_Service;
122+
123+
-- The data product invoker connector
124+
overriding procedure Data_Product_T_Recv_Sync (Self : in out Instance; Arg : in Data_Product.T) is
125+
begin
126+
-- Push the argument onto the test history for looking at later:
127+
Self.Data_Product_T_Recv_Sync_History.Push (Arg);
128+
-- Dispatch the data product to the correct handler:
129+
Self.Dispatch_Data_Product (Arg);
130+
end Data_Product_T_Recv_Sync;
131+
132+
-----------------------------------------------
133+
-- Data product handler primitive:
134+
-----------------------------------------------
135+
-- Description:
136+
-- Data products for the Sunline SRuKF component.
137+
-- Output state from the sunline SRuKF algorithm (timeTag, sigma_BN, omega_BN_B,
138+
-- vehSunPntBdy).
139+
overriding procedure Sunline_Srukf_State (Self : in out Instance; Arg : in Sunline_Srukf_Output.T) is
140+
begin
141+
-- Push the argument onto the test history for looking at later:
142+
Self.Sunline_Srukf_State_History.Push (Arg);
143+
end Sunline_Srukf_State;
144+
145+
end Component.Sunline_Srukf.Implementation.Tester;
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
--------------------------------------------------------------------------------
2+
-- Sunline_Srukf Component Tester Spec
3+
--------------------------------------------------------------------------------
4+
5+
-- Includes:
6+
with Component.Sunline_Srukf_Reciprocal;
7+
with Printable_History;
8+
with Data_Product_Return.Representation;
9+
with Data_Product_Fetch.Representation;
10+
with Data_Product.Representation;
11+
with Nav_Att;
12+
with Data_Product;
13+
with Sunline_Srukf_Output.Representation;
14+
15+
-- Sunline SRuKF pass-through algorithm wrapping the C++ SunlineSRuKFAlgorithm.
16+
package Component.Sunline_Srukf.Implementation.Tester is
17+
18+
use Component.Sunline_Srukf_Reciprocal;
19+
-- Invoker connector history packages:
20+
package Data_Product_Fetch_T_Service_History_Package is new Printable_History (Data_Product_Fetch.T, Data_Product_Fetch.Representation.Image);
21+
package Data_Product_Fetch_T_Service_Return_History_Package is new Printable_History (Data_Product_Return.T, Data_Product_Return.Representation.Image);
22+
package Data_Product_T_Recv_Sync_History_Package is new Printable_History (Data_Product.T, Data_Product.Representation.Image);
23+
24+
-- Data product history packages:
25+
package Sunline_Srukf_State_History_Package is new Printable_History (Sunline_Srukf_Output.T, Sunline_Srukf_Output.Representation.Image);
26+
27+
-- Component class instance:
28+
type Instance is new Component.Sunline_Srukf_Reciprocal.Base_Instance with record
29+
-- The component instance under test:
30+
Component_Instance : aliased Component.Sunline_Srukf.Implementation.Instance;
31+
-- Connector histories:
32+
Data_Product_Fetch_T_Service_History : Data_Product_Fetch_T_Service_History_Package.Instance;
33+
Data_Product_T_Recv_Sync_History : Data_Product_T_Recv_Sync_History_Package.Instance;
34+
-- Data product histories:
35+
Sunline_Srukf_State_History : Sunline_Srukf_State_History_Package.Instance;
36+
-- Data dependency return values. These can be set during unit test
37+
-- and will be returned to the component when a data dependency call
38+
-- is made.
39+
Spacecraft_Attitude : Nav_Att.T;
40+
-- The return status for the data dependency fetch. This can be set
41+
-- during unit test to return something other than Success.
42+
Data_Dependency_Return_Status_Override : Data_Product_Enums.Fetch_Status.E := Data_Product_Enums.Fetch_Status.Success;
43+
-- The ID to return with the data dependency. If this is set to zero then
44+
-- the valid ID for the requested dependency is returned, otherwise, the
45+
-- value of this variable is returned.
46+
Data_Dependency_Return_Id_Override : Data_Product_Types.Data_Product_Id := 0;
47+
-- The length to return with the data dependency. If this is set to zero then
48+
-- the valid length for the requested dependency is returned, otherwise, the
49+
-- value of this variable is returned.
50+
Data_Dependency_Return_Length_Override : Data_Product_Types.Data_Product_Buffer_Length_Type := 0;
51+
-- The timestamp to return with the data dependency. If this is set to (0, 0) then
52+
-- the system_Time (above) is returned, otherwise, the value of this variable is returned.
53+
Data_Dependency_Timestamp_Override : Sys_Time.T := (0, 0);
54+
end record;
55+
type Instance_Access is access all Instance;
56+
57+
---------------------------------------
58+
-- Initialize component heap variables:
59+
---------------------------------------
60+
procedure Init_Base (Self : in out Instance);
61+
procedure Final_Base (Self : in out Instance);
62+
63+
---------------------------------------
64+
-- Test initialization functions:
65+
---------------------------------------
66+
procedure Connect (Self : in out Instance);
67+
68+
---------------------------------------
69+
-- Invokee connector primitives:
70+
---------------------------------------
71+
-- Fetch a data product item from the database.
72+
overriding function Data_Product_Fetch_T_Service (Self : in out Instance; Arg : in Data_Product_Fetch.T) return Data_Product_Return.T;
73+
-- The data product invoker connector
74+
overriding procedure Data_Product_T_Recv_Sync (Self : in out Instance; Arg : in Data_Product.T);
75+
76+
-----------------------------------------------
77+
-- Data product handler primitives:
78+
-----------------------------------------------
79+
-- Description:
80+
-- Data products for the Sunline SRuKF component.
81+
-- Output state from the sunline SRuKF algorithm (timeTag, sigma_BN, omega_BN_B,
82+
-- vehSunPntBdy).
83+
overriding procedure Sunline_Srukf_State (Self : in out Instance; Arg : in Sunline_Srukf_Output.T);
84+
85+
end Component.Sunline_Srukf.Implementation.Tester;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from environments import test # noqa: F401
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
description: This is a unit test suite for the Sunline SRuKF component
3+
tests:
4+
- name: Test
5+
description: Run algorithm to ensure integration is sound.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
--------------------------------------------------------------------------------
2+
-- Sunline_Srukf Tests Body
3+
--------------------------------------------------------------------------------
4+
5+
with Basic_Assertions; use Basic_Assertions;
6+
with Nav_Att;
7+
with Sunline_Srukf_Output;
8+
with Packed_F32x3.Assertion; use Packed_F32x3.Assertion;
9+
10+
package body Sunline_Srukf_Tests.Implementation is
11+
12+
-------------------------------------------------------------------------
13+
-- Fixtures:
14+
-------------------------------------------------------------------------
15+
16+
overriding procedure Set_Up_Test (Self : in out Instance) is
17+
begin
18+
-- Allocate heap memory to component:
19+
Self.Tester.Init_Base;
20+
21+
-- Make necessary connections between tester and component:
22+
Self.Tester.Connect;
23+
24+
-- Call component init here.
25+
Self.Tester.Component_Instance.Init;
26+
27+
-- Call the component set up method that the assembly would normally call.
28+
Self.Tester.Component_Instance.Set_Up;
29+
end Set_Up_Test;
30+
31+
overriding procedure Tear_Down_Test (Self : in out Instance) is
32+
begin
33+
-- Free component heap:
34+
Self.Tester.Component_Instance.Destroy;
35+
Self.Tester.Final_Base;
36+
end Tear_Down_Test;
37+
38+
-------------------------------------------------------------------------
39+
-- Tests:
40+
-------------------------------------------------------------------------
41+
42+
-- Run algorithm to ensure integration is sound.
43+
-- The sunlineSRuKF algorithm is a pass-through: it copies sigma_BN,
44+
-- omega_BN_B, vehSunPntBdy, and timeTag from input to output.
45+
overriding procedure Test (Self : in out Instance) is
46+
T : Component.Sunline_Srukf.Implementation.Tester.Instance_Access renames Self.Tester;
47+
48+
-- Test data structure for pass-through verification
49+
type Test_Vector is record
50+
Att_Input : Nav_Att.T;
51+
Expected_Sigma_Bn : Packed_F32x3.T;
52+
Expected_Omega_Bn_B : Packed_F32x3.T;
53+
Expected_Veh_Sun_Pnt_Bdy : Packed_F32x3.T;
54+
end record;
55+
56+
-- Test cases: verify several different attitude values pass through correctly
57+
Test_Cases : constant array (1 .. 3) of Test_Vector := [
58+
-- Case 1: Typical attitude values
59+
(
60+
Att_Input => (
61+
Time_Tag => 11.11,
62+
Sigma_Bn => [0.1, 0.01, -0.1],
63+
Omega_Bn_B => [1.0, -0.5, 0.25],
64+
Veh_Sun_Pnt_Bdy => [0.577, 0.577, 0.577]
65+
),
66+
Expected_Sigma_Bn => [0.1, 0.01, -0.1],
67+
Expected_Omega_Bn_B => [1.0, -0.5, 0.25],
68+
Expected_Veh_Sun_Pnt_Bdy => [0.577, 0.577, 0.577]
69+
),
70+
-- Case 2: Zero values
71+
(
72+
Att_Input => (
73+
Time_Tag => 0.0,
74+
Sigma_Bn => [0.0, 0.0, 0.0],
75+
Omega_Bn_B => [0.0, 0.0, 0.0],
76+
Veh_Sun_Pnt_Bdy => [0.0, 0.0, 0.0]
77+
),
78+
Expected_Sigma_Bn => [0.0, 0.0, 0.0],
79+
Expected_Omega_Bn_B => [0.0, 0.0, 0.0],
80+
Expected_Veh_Sun_Pnt_Bdy => [0.0, 0.0, 0.0]
81+
),
82+
-- Case 3: Negative values
83+
(
84+
Att_Input => (
85+
Time_Tag => 99.99,
86+
Sigma_Bn => [-0.3, 0.2, -0.15],
87+
Omega_Bn_B => [-2.0, 3.0, -1.5],
88+
Veh_Sun_Pnt_Bdy => [-1.0, 0.0, 0.0]
89+
),
90+
Expected_Sigma_Bn => [-0.3, 0.2, -0.15],
91+
Expected_Omega_Bn_B => [-2.0, 3.0, -1.5],
92+
Expected_Veh_Sun_Pnt_Bdy => [-1.0, 0.0, 0.0]
93+
)
94+
];
95+
begin
96+
-- Run each test case
97+
for I in Test_Cases'Range loop
98+
-- Set data dependency via tester
99+
T.Spacecraft_Attitude := Test_Cases (I).Att_Input;
100+
101+
-- Call algorithm by sending tick
102+
T.Tick_T_Send ((Time => T.System_Time, Count => 0));
103+
104+
-- Verify data product was produced
105+
Natural_Assert.Eq (T.Data_Product_T_Recv_Sync_History.Get_Count, I);
106+
Natural_Assert.Eq (T.Sunline_Srukf_State_History.Get_Count, I);
107+
108+
-- Check output matches expected pass-through values
109+
declare
110+
Output : constant Sunline_Srukf_Output.T := T.Sunline_Srukf_State_History.Get (I);
111+
begin
112+
Packed_F32x3_Assert.Eq (
113+
Output.Sigma_Bn,
114+
Test_Cases (I).Expected_Sigma_Bn,
115+
Epsilon => 0.0001
116+
);
117+
Packed_F32x3_Assert.Eq (
118+
Output.Omega_Bn_B,
119+
Test_Cases (I).Expected_Omega_Bn_B,
120+
Epsilon => 0.0001
121+
);
122+
Packed_F32x3_Assert.Eq (
123+
Output.Veh_Sun_Pnt_Bdy,
124+
Test_Cases (I).Expected_Veh_Sun_Pnt_Bdy,
125+
Epsilon => 0.0001
126+
);
127+
end;
128+
end loop;
129+
end Test;
130+
131+
end Sunline_Srukf_Tests.Implementation;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--------------------------------------------------------------------------------
2+
-- Sunline_Srukf Tests Spec
3+
--------------------------------------------------------------------------------
4+
5+
-- This is a unit test suite for the Sunline SRuKF component
6+
package Sunline_Srukf_Tests.Implementation is
7+
8+
-- Test data and state:
9+
type Instance is new Sunline_Srukf_Tests.Base_Instance with private;
10+
type Class_Access is access all Instance'Class;
11+
12+
private
13+
-- Fixture procedures:
14+
overriding procedure Set_Up_Test (Self : in out Instance);
15+
overriding procedure Tear_Down_Test (Self : in out Instance);
16+
17+
-- Run algorithm to ensure integration is sound.
18+
overriding procedure Test (Self : in out Instance);
19+
20+
-- Test data and state:
21+
type Instance is new Sunline_Srukf_Tests.Base_Instance with record
22+
null;
23+
end record;
24+
end Sunline_Srukf_Tests.Implementation;

0 commit comments

Comments
 (0)