API
 
Loading...
Searching...
No Matches
telemeter_test.cpp
Go to the documentation of this file.
1// #define CATCH_CONFIG_MAIN
2#include "../../../../tests/catch2/catch.hpp"
3
4#include <mx/sys/timeUtils.hpp>
5
6#include "telemeter_test.hpp"
7
8#undef app_telemeter_hpp
9#undef MAPPNS
10#define XWCTEST_NAMESPACE XWCTEST_TELEMETER_LOGSTART_ns
11#define XWCTEST_TELEMETER_LOGSTART
12#include "telemeter_test.hpp"
13#undef XWCTEST_NAMESPACE
14#undef XWCTEST_TELEMETER_LOGSTART
15
16/** \defgroup app_dev_unit_tests libXWC::app::dev Unit Tests
17 * \ingroup app_unit_test
18*/
19
20/** \defgroup telemeter_tests libXWC::app::dev::telemeter Unit Tests
21 * \ingroup app_dev_unit_tests
22 */
23
24/// Test telemeter Configuration
25/**
26 * \ingroup telemeter_tests
27 */
28TEST_CASE( "Test telemeter Configuration", "[dev::telemeter]" )
29{
30 SECTION( "a config file with no [telemeter] section, loading defaults" )
31 {
32 // Just a dummy config setting
33 mx::app::writeConfigFile( "/tmp/telemeter_test.conf", { "none" }, { "nada" }, { "0" } );
34
35 mx::app::appConfigurator config;
36
37 telemeter_tests::telemeterTest pdt( "xx", false );
38
39 int rv;
40 rv = pdt.setupConfig( config );
41 REQUIRE( rv == 0 );
42
43 config.readConfig( "/tmp/telemeter_test.conf" );
44
45 rv = pdt.loadConfig( config );
46 REQUIRE( rv == 0 );
47
48 REQUIRE( pdt.m_tel.logPath().find( "telem" ) != std::string::npos );
49 REQUIRE( pdt.m_tel.logExt() == "bintel" );
50 REQUIRE( pdt.m_tel.logName() == pdt.configName() );
51 REQUIRE( pdt.m_maxInterval == 10.0 );
52 }
53
54 SECTION( "a config file with a [telemeter] section changing everything" )
55 {
56 // Just a dummy config setting
57 mx::app::writeConfigFile( "/tmp/telemeter_test.conf",
58 { "telemeter", "telemeter", "telemeter" },
59 { "logDir", "logExt", "maxInterval" },
60 { "/new/log/path", "txt", "25" } );
61
62 mx::app::appConfigurator config;
63
64 telemeter_tests::telemeterTest pdt( "xx", false );
65
66 int rv;
67 rv = pdt.setupConfig( config );
68 REQUIRE( rv == 0 );
69
70 config.readConfig( "/tmp/telemeter_test.conf" );
71
72 rv = pdt.loadConfig( config );
73 REQUIRE( rv == 0 );
74
75 REQUIRE( pdt.m_tel.logPath() == "/new/log/path" );
76 REQUIRE( pdt.m_tel.logExt() == "txt" );
77 REQUIRE( pdt.m_maxInterval == 25 );
78 }
79
80 #ifdef XWCTEST_DOX_REF
83 #endif
84}
85
86/// Test telemeter app logic
87/**
88 * \ingroup telemeter_tests
89 */
90TEST_CASE( "Test telemeter app logic", "[dev::telemeter]" )
91{
92 SECTION( "no errors" )
93 {
94 // Just a dummy config setting
95 mx::app::writeConfigFile( "/tmp/telemeter_test.conf", { "none" }, { "nada" }, { "0" } );
96
97 mx::app::appConfigurator config;
98
99 telemeter_tests::telemeterTest pdt( "xx", false );
100
101 int rv;
102 rv = pdt.setupConfig( config );
103 REQUIRE( rv == 0 );
104
105 config.readConfig( "/tmp/telemeter_test.conf" );
106
107 rv = pdt.loadConfig( config );
108 REQUIRE( rv == 0 );
109
110 pdt.m_tel.logPath( "/tmp/telems" );
111
112 rv = pdt.appStartup();
113 REQUIRE( rv == 0 );
114
115 rv = pdt.appLogic();
116 REQUIRE( rv == 0 );
117
118 rv = pdt.appShutdown();
119 REQUIRE( rv == 0 );
120 }
121
122 SECTION( "log thread shutsdown" )
123 {
124 // Just a dummy config setting
125 mx::app::writeConfigFile( "/tmp/telemeter_test.conf", { "none" }, { "nada" }, { "0" } );
126
127 mx::app::appConfigurator config;
128
129 telemeter_tests::telemeterTest pdt( "xx", false );
130
131 int rv;
132 rv = pdt.setupConfig( config );
133 REQUIRE( rv == 0 );
134
135 config.readConfig( "/tmp/telemeter_test.conf" );
136
137 rv = pdt.loadConfig( config );
138 REQUIRE( rv == 0 );
139
140 pdt.m_tel.logPath( "/tmp/telems" );
141
142 rv = pdt.appStartup();
143 REQUIRE( rv == 0 );
144
145 rv = pdt.appLogic();
146 REQUIRE( rv == 0 );
147
148 pdt.m_tel.logShutdown( true );
149 sleep( 1 );
150
151 rv = pdt.appLogic();
152 REQUIRE( rv == -1 );
153
154 rv = pdt.appShutdown();
155 REQUIRE( rv == 0 );
156 }
157
158 #ifdef XWCTEST_DOX_REF
164 #endif
165}
166
167/// Test telemeter telem-logger fails to start
168/**
169 * \ingroup telemeter_tests
170 */
171TEST_CASE( "Test telemeter telem-logger fails to start", "[dev::telemeter]" )
172{
173 // Just a dummy config setting
174 mx::app::writeConfigFile( "/tmp/telemeter_test.conf", { "none" }, { "nada" }, { "0" } );
175
176 mx::app::appConfigurator config;
177
178 telemeter_tests::XWCTEST_TELEMETER_LOGSTART_ns::telemeterTest pdt( "xx", false );
179
180 int rv;
181 rv = pdt.setupConfig( config );
182 REQUIRE( rv == 0 );
183
184 config.readConfig( "/tmp/telemeter_test.conf" );
185
186 rv = pdt.loadConfig( config );
187 REQUIRE( rv == 0 );
188
189 pdt.m_tel.logPath( "/tmp/telems" );
190
191 rv = pdt.appStartup();
192 REQUIRE( rv == -1 );
193
194 #ifdef XWCTEST_DOX_REF
198 #endif
199}
std::string configName()
Get the config name.
TEST_CASE("Test telemeter Configuration", "[dev::telemeter]")
Test telemeter Configuration.
int appShutdown()
Perform telemeter application shutdown.
int loadConfig(appConfigurator &config)
Load the device section from an application configurator.
int appLogic()
Perform telemeter application logic.
int setupConfig(appConfigurator &config)
Setup an application configurator for the device section.
int appStartup()
Starts the telemetry log thread.
Test harness for dev::telemeter.
int setupConfig(mx::app::appConfigurator &config)
int appStartup()
Any tasks to perform prior to the main event loop go here.
int appShutdown()
Any tasks to perform after main loop exit go here.
int loadConfig(mx::app::appConfigurator &config)
int appLogic()
This is where derived applications implement their main FSM logic.