API
 
Loading...
Searching...
No Matches
ocam2KCtrl_lifecycle_test.cpp
Go to the documentation of this file.
1/** \file ocam2KCtrl_lifecycle_test.cpp
2 * \brief Isolated Catch2 lifecycle tests for the ocam2KCtrl app.
3 * \author OpenAI Codex
4 *
5 * \ingroup ocam2KCtrl_files
6 */
7
8#define OCAM2KCTRL_TEST_SUPPORT_ONLY
9#include "ocam2KCtrl_test.cpp"
10#undef OCAM2KCTRL_TEST_SUPPORT_ONLY
11
12namespace libXWCTest
13{
14
15/** \addtogroup ocam2KCtrl_unit_test
16 * \brief Additional lifecycle tests for the ocam2KCtrl application.
17 *
18 * \ingroup application_unit_test
19 */
20
21/// Namespace for `ocam2KCtrl` lifecycle unit tests.
22/** \ingroup ocam2KCtrl_unit_test
23 */
24namespace ocam2KCtrlTest
25{
26
27/// Verify lifecycle entrypoints cover startup failure handling and the POWERON fast-return path.
28/**
29 * \ingroup ocam2KCtrl_unit_test
30 */
31TEST_CASE( "ocam2KCtrl lifecycle entrypoints handle startup failures and POWERON logic", "[ocam2KCtrl]" )
32{
33 resetStubState();
34
35 // clang-format off
36 #ifdef OCAM2KCTRL_TEST_DOXYGEN_REF
39 #endif
40 // clang-format on
41
42 SECTION( "appStartup reports failure when the startup mode cannot be configured" )
43 {
44 ocam2KCtrl_test app;
45
46 app.m_startupMode = "";
47
48 REQUIRE( app.appStartup() < 0 );
49 }
50
51 SECTION( "appStartup reports failure when EDT startup cannot load the configured mode" )
52 {
53 ocam2KCtrl_test app;
54
55 configureStartupMode( app );
56 g_edtStubState.readcfgReturn = -1;
57
58 REQUIRE( app.appStartup() < 0 );
59 }
60
61 SECTION( "appStartup succeeds once a startup mode and telemetry path are configured" )
62 {
63 ocam2KCtrl_test app;
64 startupScope startup( app );
65
66 configureStartupMode( app );
67
68 const int startupRv = app.appStartup();
69 startup.markStarted( startupRv == 0 );
70
71 REQUIRE( startupRv == 0 );
72 REQUIRE( app.m_temps.CCD == Approx( -999.0f ) );
73 }
74
75 SECTION( "appLogic returns immediately while the app is still in POWERON and the wait has not elapsed" )
76 {
77 ocam2KCtrl_test app;
78
79 static_cast<MagAOXAppT &>( app ).m_powerState = 1;
80 app.m_powerTargetState = 1;
81 app.state( stateCodes::POWERON );
82 app.m_powerOnCounter = 0;
83 static_cast<MagAOXAppT &>( app ).m_loopPause = 0;
84 fgThreadScope fgThread( app );
85
86 REQUIRE( app.appLogic() == 0 );
87 REQUIRE( app.state() == stateCodes::POWERON );
88 }
89
90 SECTION( "appLogic returns an error if the framegrabber thread has already exited" )
91 {
92 auto *app = new ocam2KCtrl_test;
93
94 static_cast<MagAOXAppT &>( *app ).m_powerState = 1;
95 app->m_powerTargetState = 1;
96 app->state( stateCodes::POWERON );
97 startFgThread( *app, 1 );
98 std::this_thread::sleep_for( std::chrono::milliseconds( 20 ) );
99
100 REQUIRE( app->appLogic() == -1 );
101
102 // `frameGrabber::appLogic()` uses `pthread_tryjoin_np`, which consumes the native thread
103 // without clearing the owning `std::thread`. Leak this tiny test instance so its destructor
104 // does not terminate the process while exercising the error-return branch.
105 }
106}
107
108} // namespace ocam2KCtrlTest
109} // namespace libXWCTest
int m_powerState
Current power state, 1=On, 0=Off, -1=Unk.
int m_powerTargetState
Current target power state, 1=On, 0=Off, -1=Unk.
virtual int appLogic()
Implementation of the FSM for the OCAM 2K.
virtual int appStartup()
Startup functions.
@ POWERON
The device power is on.
TEST_CASE("ocam2KCtrl lifecycle entrypoints handle startup failures and POWERON logic", "[ocam2KCtrl]")
Verify lifecycle entrypoints cover startup failure handling and the POWERON fast-return path.
#define XWCTEST_DOXYGEN_REF(fxn)
This inserts an unused call to a function signature to make doxygen make the link.
Definition testXWC.hpp:18
Namespace for all libXWC tests.
Catch2 tests for the ocam2KCtrl app.