Skip to content

Commit 9da32e6

Browse files
author
Aaron Roller
committed
feat: tolerant of errors during unconfigured AM-695/error-on-init
1 parent 5933fbc commit 9da32e6

6 files changed

Lines changed: 83 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ if (CATKIN_ENABLE_TESTING)
222222
error_status
223223
error_status_without_stats
224224
error_terminal_before_config
225+
error_tolerant_before_config
225226
hz_config
226227
manual_to_disarming
227228
param

include/super_lib/am_life_cycle_mediator.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,12 @@ class AMLifeCycleMediator
193193

194194
bool redundantShutdown(const AMLifeCycleMediator::LifeCycleInfo& info);
195195

196+
/** @brief return true if already in error state */
196197
bool redundantError(const AMLifeCycleMediator::LifeCycleInfo& info);
197198

199+
/** @brief return true if in UNCONFIGURED or CONFIGURING */
200+
bool unconfigured(const AMLifeCycleMediator::LifeCycleInfo& info);
201+
198202
bool illegalDestroy(const AMLifeCycleMediator::LifeCycleInfo& info);
199203

200204
private:
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#include <am_rostest_lib/am_rostest.h>
2+
3+
/** Shows an error that happens upon construction will be reported as an ERROR during configuration.
4+
*/
5+
class LifeCycleErrorTest : public RostestBase, public am::AMLifeCycle
6+
{
7+
protected:
8+
9+
LifeCycleErrorTest() :
10+
RostestBase()
11+
{
12+
errorTolerant("tolerant error during construction", "HW8S");
13+
}
14+
15+
16+
void onConfigure()
17+
{
18+
//do nothing...stay in configure
19+
}
20+
};
21+
22+
TEST_F(LifeCycleErrorTest, testStatus_Error)
23+
{
24+
waitUntil(LifeCycleState::INACTIVE,"NAKW");
25+
waitUntil(LifeCycleStatus::OK,"NQNE");
26+
}
27+
28+
int main(int argc, char** argv)
29+
{
30+
::testing::InitGoogleTest(&argc, argv);
31+
ros::init(argc, argv, ros::this_node::getName());
32+
33+
return RUN_ALL_TESTS();
34+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<launch>
2+
<!-- include test file and pass in this test node name -->
3+
<include file="$(find am_super)/rostest/am_super_rostest.test">
4+
<arg name="test_name" value="error_tolerant_before_config"/>
5+
</include>
6+
</launch>

src/super_lib/am_life_cycle_mediator.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,19 @@ bool AMLifeCycleMediator::shutdown(const AMLifeCycleMediator::LifeCycleInfo& inf
205205
info.state == LifeCycleState::ACTIVE;
206206
}
207207

208+
bool AMLifeCycleMediator::unconfigured(const AMLifeCycleMediator::LifeCycleInfo& info)
209+
{
210+
switch (info.state)
211+
{
212+
case LifeCycleState::UNCONFIGURED:
213+
case LifeCycleState::CONFIGURING:
214+
return true;
215+
default:
216+
return false;
217+
}
218+
}
219+
220+
208221
bool AMLifeCycleMediator::redundantShutdown(const AMLifeCycleMediator::LifeCycleInfo& info)
209222
{
210223
return info.state == LifeCycleState::SHUTTING_DOWN ||

test/am_life_cycle_mediator_unit_tests.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ class AMLifeCycleMediatorTest : public ::testing::Test
6565
info.state = state;
6666
EXPECT_EQ(life_cycle_mediator_.illegalDestroy(info), expected);
6767
}
68+
69+
bool EXPECT_EQ_UNCONFIGURED(const LifeCycleState& state, bool expected)
70+
{
71+
AMLifeCycleMediator::LifeCycleInfo info;
72+
info.state = state;
73+
EXPECT_EQ(life_cycle_mediator_.unconfigured(info), expected);
74+
}
75+
6876
};
6977

7078
TEST_F(AMLifeCycleMediatorTest, statusError_LCStatusError)
@@ -299,6 +307,23 @@ TEST_F(AMLifeCycleMediatorTest, redundantError)
299307
EXPECT_EQ_REDUNDANT_ERROR(LifeCycleState::SHUTTING_DOWN, false);
300308
}
301309

310+
311+
TEST_F(AMLifeCycleMediatorTest, unconfigured)
312+
{
313+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::CONFIGURING, true);
314+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::UNCONFIGURED, true);
315+
316+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::FINALIZED, false);
317+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::ERROR_PROCESSING, false);
318+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::ACTIVATING, false);
319+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::ACTIVE, false);
320+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::CLEANING_UP, false);
321+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::DEACTIVATING, false);
322+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::INACTIVE, false);
323+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::INVALID, false);
324+
EXPECT_EQ_UNCONFIGURED(LifeCycleState::SHUTTING_DOWN, false);
325+
}
326+
302327
TEST_F(AMLifeCycleMediatorTest, illegalDestroy)
303328
{
304329
EXPECT_EQ_ILLEGAL_DESTROY(LifeCycleState::FINALIZED, false);

0 commit comments

Comments
 (0)