1+ """
2+ load_switch_test.py:
3+
4+ Integration tests for the Load-Switch component.
5+ """
6+
7+ import time
8+
9+ import pytest
10+ from common import proves_send_and_assert_command
11+ from fprime_gds .common .data_types .ch_data import ChData
12+ from fprime_gds .common .testing_fw .api import IntegrationTestAPI
13+
14+ loadswitch = "ReferenceDeployment.loadswitch"
15+
16+ @pytest .fixture (autouse = True )
17+ def ensure_loadswitch_off (fprime_test_api : IntegrationTestAPI , start_gds ):
18+ """Ensure LoadSwitch starts in OFF state"""
19+ turn_off (fprime_test_api )
20+ yield
21+ turn_off (fprime_test_api )
22+
23+ def turn_on (fprime_test_api : IntegrationTestAPI ):
24+ """Helper function to turn on the loadswitch"""
25+ proves_send_and_assert_command (
26+ fprime_test_api ,
27+ f"{ loadswitch } .TURN_ON" ,
28+ )
29+
30+ def turn_off (fprime_test_api : IntegrationTestAPI ):
31+ """Helper function to turn off the loadswitch"""
32+ proves_send_and_assert_command (
33+ fprime_test_api ,
34+ f"{ loadswitch } .TURN_OFF"
35+ )
36+
37+ def get_is_on (fprime_test_api : IntegrationTestAPI ) -> int :
38+ """Helper function to request packet and get fresh IsOn telemetry"""
39+ proves_send_and_assert_command (
40+ fprime_test_api ,
41+ "CdhCore.tlmSend.SEND_PKT" ,
42+ ["9" ],
43+ )
44+ result : ChData = fprime_test_api .assert_telemetry (
45+ f"{ loadswitch } .IsOn" , start = "NOW" , timeout = 3
46+ )
47+ return result .get_val ()
48+
49+ def test_01_loadswitch_telemetry_basic (fprime_test_api : IntegrationTestAPI , start_gds ):
50+ """Test that we can read IsOn telemetry"""
51+ value = get_is_on (fprime_test_api )
52+ assert value in (0 , 1 ), f"IsOn should be 0 or 1, got { value } "
53+
54+ def test_02_turn_on_sets_high (fprime_test_api : IntegrationTestAPI , start_gds ):
55+ """
56+ Test TURN_ON command sets GPIO high, emits ON event, and updates telemetry
57+ """
58+
59+ # Send turn_on command
60+ turn_on (fprime_test_api )
61+
62+ # Confirm Load-Switch turned ON
63+ fprime_test_api .assert_event (f"{ loadswitch } .StatusChanged" , args = [1 ], timeout = 2 )
64+
65+ # Confirm telemetry IsOn is 1
66+ value = get_is_on (fprime_test_api )
67+ assert value == 1 , f"Expected IsOn = 1 after TURN_ON, got { value } "
68+
69+ def test_03_turn_off_sets_low (fprime_test_api : IntegrationTestAPI , start_gds ):
70+ """
71+ Test TURN_OFF command sets GPIO low, emits OFF event, and updates telemetry
72+ """
73+
74+ # Send turn_on command
75+ turn_off (fprime_test_api )
76+
77+ # Confirm Load-Switch turned OFF
78+ fprime_test_api .assert_event (f"{ loadswitch } .StatusChanged" , args = [0 ], timeout = 2 )
79+
80+ # Confirm telemetry IsOn is 0
81+ value = get_is_on (fprime_test_api )
82+ assert value == 0 , f"Expected IsOn = 0 after TURN_OFF, got { value } "
0 commit comments