def test_antennas_are_not_deployed_too_soon(self): event = TestEvent() self.system.primary_antenna.on_begin_deployment = event.set self.power_on_and_wait() self.system.obc.suspend_mission() self.system.obc.jump_to_time(20 * 60) self.next_step() self.assertFalse(event.wait_for_change(1), "antenna deployment process began too soon")
def test_reset_watchdog_b(self): ev = TestEvent() self.system.eps.controller_b.on_reset_watchdog = ev.set self.system.obc.eps_reset_watchdog(ResetWatchdogOn.B) self.assertTrue(ev.wait_for_change(1), "Watchdog should be reseted (controller A)")
def test_set_baud_rate(self): event = TestEvent() self.system.transmitter.on_set_baudrate = event.set self.power_on_obc() self.system.obc.comm_set_bitrate(BaudRate.BaudRate9600) event.wait_for_change(2) self.assertEqual(self.system.transmitter.baud_rate, BaudRate.BaudRate9600)
def test_power_cycle_a(self): ev = TestEvent() self.system.eps.controller_a.on_power_cycle = ev.set self.system.obc.power_cycle(PowerCycleBy.A) self.assertTrue(ev.wait_for_change(1), "Should trigger power cycle (controller A)") self.system.restart()
def test_should_remove_frame_after_receive(self): event = TestEvent() self.system.receiver.on_frame_remove = event.set self.power_on_obc() self.system.receiver.put_frame("ABD") self.system.obc.receive_frame() self.assertTrue(event.wait_for_change(1)) self.assertEqual(self.system.receiver.queue_size(), 0)
def test_manual_deployment(self): event = TestEvent() def handler(driver, antenna): if antenna == 2: event.set() self.system.primary_antenna.on_begin_deployment = handler self.power_on_and_wait() self.system.obc.antenna_deploy(AntennaChannel.Primary, AntennaId.Antenna2, OverrideSwitches.Disabled) self.assertTrue(event.wait_for_change(1))
def test_manual_deployment_with_override(self): event = TestEvent() def handler(driver, antenna): if antenna == 2: event.set() self.system.backup_antenna.on_begin_deployment = handler self.power_on_and_wait() result = self.system.obc.antenna_deploy(AntennaChannel.Backup, AntennaId.Antenna2, OverrideSwitches.Enabled) self.assertTrue(event.wait_for_change(1)) self.assertTrue(self.system.backup_antenna.ignore_deployment_switch)
def _start(self): e = TestEvent() def on_reset(_): e.set() self.system.comm.on_hardware_reset = on_reset self.power_on_obc() e.wait_for_change(1)
def test_power_cycle_auto_fallback_to_b_when_a_not_responding(self): pc_b = TestEvent() self.system.i2c.enable_bus_devices([self.system.eps.controller_a.address], False) self.system.eps.controller_b.on_power_cycle = pc_b.set self.system.obc.power_cycle(PowerCycleBy.Auto) self.assertTrue(pc_b.wait_for_change(10), "Should trigger power cycle (controller B)") self.system.restart()
def test_reset_transmitter(self): event = TestEvent() def on_reset(): event.set() self.system.transmitter.on_reset = on_reset self._start() event.reset() self.system.comm.put_frame(telecommand.ResetTransmitterTelecommand()) self.assertTrue(event.wait_for_change(30))
def test_antennas_are_not_deployed_too_soon(self): event = TestEvent() self.system.primary_antenna.on_begin_deployment = event.set t = timedelta(minutes=20) for i in xrange(0, 10): t += timedelta(seconds=60) self.system.obc.jump_to_time(t) self.system.obc.run_mission() self.assertFalse(event.wait_for_change(1), "antenna deployment process began too soon")
def test_should_trigger_power_cycle_after_reaching_error_limit(self): self.system.i2c.enable_bus_devices([self.system.comm.receiver.address], False) power_cycle_requested = TestEvent() self.system.eps.controller_a.on_power_cycle = power_cycle_requested.set limit = 128 increment = 5 errors = ceil(limit / increment) requested = power_cycle_requested.wait_for_change(errors * 1.5) self.assertTrue(requested, "Power cycle should be requested")
def test_should_trigger_power_cycle(self): self._start() power_cycle_requested = TestEvent() self.system.eps.controller_a.on_power_cycle = power_cycle_requested.set self.system.comm.put_frame(PowerCycleTelecommand(0x21)) ack = self.system.comm.get_frame(5, filter_type=PowerSuccessFrame) self.assertIsInstance(ack, PowerSuccessFrame) power_cycle_requested.wait_for_change(1) self.system.restart()
def test_bus_latch_should_trigger_system_power_cycle(self): self.system.obc.i2c_transfer('wr', 'payload', 0x14, chr(0x2)) power_cycle_trigger = TestEvent() self.system.eps.controller_a.on_power_cycle = power_cycle_trigger.set() self.assertTrue(power_cycle_trigger.wait_for_change(15), "Power cycle should be triggered") self.system.restart() response = self.system.obc.i2c_transfer('wr', 'system', 0x12, 'abc') self.assertEqual(response, 'bcd')
def test_self_test(self): test_started = TestEvent() self.system.imtq.on_start_self_test = test_started.set self_test_result = self.system.obc._command('imtq PerformSelfTest true') self.assertMultiLineEqual(self_test_result, """0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0""") self.assertTrue(test_started.wait_for_change(0), "Self test should be started")
def _start(self): e = TestEvent() def on_reset(_): e.set() self.system.comm.on_hardware_reset = on_reset self.power_on_obc() e.wait_for_change(1) self.systemEcho = EchoDevice(0x12, "Echo") self.payloadEcho = EchoDevice(0x13, "Echo") self.system.i2c.add_bus_device(self.systemEcho) self.system.i2c.add_pld_device(self.payloadEcho) self.system.i2c.enable_bus_devices([self.systemEcho.address], True) self.system.i2c.enable_pld_devices([self.payloadEcho.address], True)
def test_set_bitrate(self): self._start() event = TestEvent() self.system.obc.comm_set_bitrate(BaudRate.BaudRate9600) event.wait_for_change(2) self.system.comm.put_frame(telecommand.SetBitrate(0x12, 2)) frame = self.system.comm.get_frame(20, filter_type=SetBitrateSuccessFrame) self.assertIsInstance(frame, SetBitrateSuccessFrame) self.assertEqual(frame.seq(), 0) self.assertEqual(frame.correlation_id, 0x12) self.assertEqual(self.system.transmitter.baud_rate, BaudRate.BaudRate2400)
def test_disable_sail_deployment_should_disable_automatic_deploy(self): self._start() self.system.obc.run_mission() sail_opening = TestEvent() self.system.eps.TKmain.on_enable = sail_opening.set self.system.comm.put_frame(StopSailDeployment(11)) frame = self.system.comm.get_frame(20, filter_type=StopSailDeploymentSuccessFrame) self.assertIsInstance(frame, StopSailDeploymentSuccessFrame) self.system.obc.run_mission() self.system.obc.jump_to_time(timedelta(days=41)) self.system.obc.run_mission() self.assertFalse(sail_opening.wait_for_change(5), "Sail deployment should not be performed")
def test_disable_overheat_submode(self): self._start() event = TestEvent() self.system.eps.controller_b.on_disable_overheat_submode = event.set self.system.comm.put_frame( telecommand.DisableOverheatSubmode(correlation_id=0x28, controller=1)) frame = self.system.comm.get_frame( 20, filter_type=DisableOverheatSubmodeSuccessFrame) self.assertIsInstance(frame, DisableOverheatSubmodeSuccessFrame) self.assertEqual(frame.seq(), 0) self.assertEqual(frame.correlation_id, 0x28) self.assertTrue(event.wait_for_change(2), "Should disable overheat mode (controller B)")
def test_leave_idle_state(self): event = TestEvent() def on_set_idle_state(state): if not state: event.set() self.system.transmitter.on_set_idle_state = on_set_idle_state self._start() self.system.comm.put_frame( telecommand.EnterIdleState(correlation_id=0x11, duration=1)) frame = self.system.comm.get_frame(20, filter_type=CommSuccessFrame) self.assertIsInstance(frame, CommSuccessFrame) self.assertEqual(frame.seq(), 0) self.assertEqual(frame.correlation_id, 0x11) self.assertTrue(event.wait_for_change(30))
def test_beacon_auto_activation(self): event = TestEvent() def reset_handler(*args): return False def catch_beacon(_, frame): if frame[0] == BeaconMarker(): event.set() self.system.primary_antenna.begin_deployment() self.system.primary_antenna.finish_deployment() self.system.backup_antenna.begin_deployment() self.system.backup_antenna.finish_deployment() self.system.primary_antenna.on_reset = reset_handler self.system.backup_antenna.on_reset = reset_handler self.system.comm.transmitter.on_send_frame = catch_beacon self.begin() self.assertTrue(event.wait_for_change(1), "beacon should be set once the antennas are deployed")
def test_should_perform_self_test_before_enabling_builtin_detumbling(self): bdot_started = TestEvent() test_started = TestEvent() power_on = TestEvent() self.system.imtq.on_start_bdot = bdot_started.set self.system.eps.IMTQ.on_enable = power_on.set def on_self_test_start(*args): if bdot_started.flag.is_set: test_started.set() self.system.imtq.on_start_self_test = on_self_test_start self.system.obc.adcs_enable_builtin() self.assertTrue(test_started.wait_for_change(5), "Self test should be performed before BDot") self.assertTrue(bdot_started.wait_for_change(5), "BDot should be enabled") self.assertTrue(power_on.wait_for_change(5), "LCL should be enabled")
def test_power_cycle_auto_fallback_to_b_when_not_restart_by_a(self): pc_a = TestEvent() pc_b = TestEvent() self.system.eps.controller_a.on_power_cycle = pc_a.set self.system.eps.controller_b.on_power_cycle = pc_b.set self.system.obc.power_cycle(PowerCycleBy.Auto) self.assertTrue(pc_a.wait_for_change(1), "Should trigger power cycle (controller A)") self.assertTrue(pc_b.wait_for_change(10), "Should trigger power cycle (controller B)") self.system.restart()
def test_reset_watchdog_both(self): ev_a = TestEvent() ev_b = TestEvent() self.system.eps.controller_a.on_reset_watchdog = ev_a.set self.system.eps.controller_b.on_reset_watchdog = ev_b.set self.system.obc.eps_reset_watchdog(ResetWatchdogOn.Both) self.assertTrue(ev_a.wait_for_change(1), "Watchdog should be reseted (controller A)") self.assertTrue(ev_b.wait_for_change(1), "Watchdog should be reseted (controller B)")
def test_should_kick_watchdog_in_mission_loop(self): ev_a = TestEvent() ev_b = TestEvent() self.system.eps.controller_a.on_reset_watchdog = ev_a.set self.system.eps.controller_b.on_reset_watchdog = ev_b.set self.system.obc.run_mission() self.assertTrue(ev_a.wait_for_change(1), "Watchdog should be kicked (A)") self.assertTrue(ev_b.wait_for_change(1), "Watchdog should be kicked (B)")
def test_should_trigger_sail_opening(self): self._start() sail_opening = TestEvent() overheat_disabled = TestEvent() self.system.eps.TKmain.on_enable = sail_opening.set self.system.eps.controller_a.on_disable_overheat_submode = overheat_disabled.set self.system.comm.put_frame(OpenSailTelecommand(0x31, False)) ack = self.system.comm.get_frame(5, filter_type=SailSuccessFrame) self.assertIsInstance(ack, SailSuccessFrame) self.assertTrue(sail_opening.wait_for_change(20), "Sail opening procedure should start") self.assertFalse(overheat_disabled.wait_for_change(0), "Overheat should not be disabled")
def test_enable_lcl(self): ev = TestEvent() self.system.eps.TKmain.on_enable = ev.set self.system.obc.enable_lcl(0x01) self.assertTrue(ev.wait_for_change(1), "Should enable TKmain LCL (controller A)") ev = TestEvent() self.system.eps.TKred.on_enable = ev.set self.system.obc.enable_lcl(0x11) self.assertTrue(ev.wait_for_change(1), "Should enable TKred LCL (controller B)")
def test_set_idle_state(self): enabled = TestEvent() disabled = TestEvent() def on_set_idle_state(state): if state: enabled.set() else: disabled.set() self.system.transmitter.on_set_idle_state = on_set_idle_state self.power_on_obc() self.system.obc.comm_set_idle_state(True) self.assertTrue(enabled.wait_for_change(1)) self.system.obc.comm_set_idle_state(False) self.assertTrue(disabled.wait_for_change(1))
def test_enable_burn_switch(self): ev = TestEvent() self.system.eps.SAILmain.on_enable = ev.set self.system.obc.enable_burn_switch(True, 1) self.assertTrue(ev.wait_for_change(1), "Burn switch should be enabled (controller A)") ev = TestEvent() self.system.eps.SAILred.on_enable = ev.set self.system.obc.enable_burn_switch(False, 1) self.assertTrue(ev.wait_for_change(1), "Burn switch should be enabled (controller B)")
def test_disable_overheat_mode(self): ev = TestEvent() self.system.eps.controller_a.on_disable_overheat_submode = ev.set self.assertTrue(self.system.obc.disable_overheat_submode('A')) self.assertTrue(ev.wait_for_change(1), "Should disable overheat mode (controller A)") ev = TestEvent() self.system.eps.controller_b.on_disable_overheat_submode = ev.set self.assertTrue(self.system.obc.disable_overheat_submode('B')) self.assertTrue(ev.wait_for_change(1), "Should disable overheat mode (controller B)")
def test_should_perform_experiment(self): self._start() power_on = TestEvent() power_off = TestEvent() self.system.eps.IMTQ.on_enable = power_on.set self.system.eps.IMTQ.on_disable = power_off.set log = logging.getLogger("TEST") start_time = datetime.now() self.system.rtc.set_response_time(start_time) log.info('Sending telecommand') self.system.comm.put_frame( telecommand.PerformDetumblingExperiment( correlation_id=5, duration=timedelta(hours=4), sampling_interval=timedelta(seconds=2))) response = self.system.comm.get_frame( 5, filter_type=ExperimentSuccessFrame) self.assertIsInstance(response, ExperimentSuccessFrame) log.info('Waiting for experiment') self.system.obc.wait_for_experiment(ExperimentType.Detumbling, 40) self.system.obc.wait_for_experiment_iteration(1, 30) self.assertTrue(power_on.wait_for_change(5), "IMTQ should be powered on") log.info('Advancing time') self.system.obc.advance_time(timedelta(hours=4, minutes=1)) self.system.rtc.set_response_time(start_time + timedelta(hours=4, minutes=1)) log.info('Waiting for experiment finish') self.system.obc.wait_for_experiment(None, 25) self.assertTrue(power_off.wait_for_change(5), "IMTQ should be powered off")
def test_disable_sail_deployment_should_not_disable_deployment_on_command(self): self._start() self.system.obc.run_mission() sail_opening = TestEvent() overheat_disabled = TestEvent() self.system.eps.TKmain.on_enable = sail_opening.set self.system.eps.controller_a.on_disable_overheat_submode = overheat_disabled.set self.system.comm.put_frame(StopSailDeployment(11)) frame = self.system.comm.get_frame(20, filter_type=StopSailDeploymentSuccessFrame) self.assertIsInstance(frame, StopSailDeploymentSuccessFrame) self.system.obc.run_mission() self.system.comm.put_frame(OpenSailTelecommand(0x31, True)) frame = self.system.comm.get_frame(20, filter_type=SailSuccessFrame) self.assertIsInstance(frame, SailSuccessFrame) self.system.obc.run_mission() self.assertTrue(sail_opening.wait_for_change(5), "Sail deployment should be performed") self.assertTrue(overheat_disabled.wait_for_change(1), "Overheat should be disabled")
def test_deployment_completion(self): event = TestEvent() self.system.backup_antenna.on_deployment_cancel = event.set self.begin(5) self.assertTrue(event.wait_for_change(1), "antenna deployment on backup controller was not cancelled")
def test_process_begins_automatically_by_controller_reset(self): event = TestEvent() self.system.primary_antenna.on_reset = event.set self.begin(1) self.assertTrue(event.wait_for_change(1), "antenna controller was not reset")
def test_happy_path(self): days_40 = timedelta(days=40) minutes_2 = timedelta(minutes=2) now = datetime.now() self.system.rtc.set_response_time(now) self.system.obc.jump_to_time(days_40) overheat_disabled_a = TestEvent() overheat_disabled_b = TestEvent() tk_main_lcl_enabled = TestEvent() tk_main_lcl_disabled = TestEvent() tk_red_lcl_enabled = TestEvent() tk_red_lcl_disabled = TestEvent() main_burn_switch = TestEvent() red_burn_switch = TestEvent() self.system.eps.controller_a.on_disable_overheat_submode = overheat_disabled_a.set self.system.eps.controller_b.on_disable_overheat_submode = overheat_disabled_b.set self.system.eps.TKmain.on_enable = tk_main_lcl_enabled.set self.system.eps.TKmain.on_disable = tk_main_lcl_disabled.set self.system.eps.TKred.on_enable = tk_red_lcl_enabled.set self.system.eps.TKred.on_disable = tk_red_lcl_disabled.set self.system.eps.SAILmain.on_enable = main_burn_switch.set self.system.eps.SAILred.on_enable = red_burn_switch.set self.assertTrue(overheat_disabled_a.wait_for_change(16)) self.assertTrue(overheat_disabled_b.wait_for_change(16)) self.assertTrue(tk_main_lcl_enabled.wait_for_change(16)) self.assertTrue(main_burn_switch.wait_for_change(10)) self.system.rtc.set_response_time(now + minutes_2) self.system.obc.advance_time(timedelta(minutes=2)) self.assertTrue(tk_main_lcl_disabled.wait_for_change(16)) self.assertTrue(tk_red_lcl_enabled.wait_for_change(16)) self.assertTrue(red_burn_switch.wait_for_change(10)) self.system.rtc.set_response_time(now + 2 * minutes_2) self.system.obc.advance_time(timedelta(minutes=2)) self.assertTrue(tk_main_lcl_disabled.wait_for_change(16)) self.assertTrue(tk_red_lcl_disabled.wait_for_change(16)) tk_main_lcl_enabled.reset() self.system.obc.sync_fs() self.system.restart(boot_chain=[]) self.assertTrue(tk_main_lcl_enabled.wait_for_change(120))
def test_process_begins_automatically(self): event = TestEvent() self.system.primary_antenna.on_begin_deployment = event.set self.begin(2) self.assertTrue(event.wait_for_change(1), "antenna deployment process did not began when it should")
def test_deployment_finalization(self): event = TestEvent() self.system.backup_antenna.on_deployment_cancel = event.set self.power_on_and_wait() result = self.system.obc.antenna_cancel_deployment(AntennaChannel.Backup) self.assertTrue(event.wait_for_change(1))
def test_deployment_is_cancelled_on_retry(self): event = TestEvent() self.system.primary_antenna.on_deployment_cancel = event.set self.begin(2) self.assertTrue(event.wait_for_change(1), "antenna deployment process was not cancelled")
def test_backup_antenna_is_reset_at_startup(self): event = TestEvent() self.system.backup_antenna.on_reset = event.set self.system.obc.power_on() self.assertTrue(event.wait_for_change(1))