18
18
#include " pru-hardware-interface.h"
19
19
#include " segment-queue.h"
20
20
21
- using ::testing::NiceMock;
22
-
23
21
// PRU-side mock implementation of the ring buffer.
24
22
struct MockPRUCommunication {
25
23
internal::QueueStatus status;
@@ -30,15 +28,16 @@ class MockPRUInterface : public PruHardwareInterface {
30
28
public:
31
29
MockPRUInterface () : execution_index_(QUEUE_LEN - 1 ) {
32
30
mmap = NULL ;
33
- ON_CALL (*this , Init).WillByDefault ([]() { return true ; });
34
- ON_CALL (*this , Shutdown).WillByDefault ([]() { return true ; });
35
31
}
36
32
~MockPRUInterface () override { free (mmap); }
37
33
34
+ bool Init () final { return true ; }
38
35
bool StartExecution () final { return true ; }
39
36
unsigned WaitEvent () final { return 1 ; }
40
- MOCK_METHOD (bool , Init, (), ());
41
- MOCK_METHOD (bool , Shutdown, (), ());
37
+ bool Shutdown () final { return true ; }
38
+
39
+ MOCK_METHOD (void , Halt, (), (final ));
40
+ MOCK_METHOD (void , Restart, (), (final ));
42
41
43
42
bool AllocateSharedMem (void **pru_mmap, const size_t size) final {
44
43
if (mmap != NULL ) return true ;
@@ -70,15 +69,15 @@ class MockPRUInterface : public PruHardwareInterface {
70
69
71
70
TEST (PruMotionQueue, status_init) {
72
71
MotorsRegister absolute_pos_loops;
73
- NiceMock< MockPRUInterface> pru_interface;
72
+ MockPRUInterface pru_interface;
74
73
HardwareMapping hmap = HardwareMapping ();
75
74
PRUMotionQueue motion_backend (&hmap, (PruHardwareInterface *)&pru_interface);
76
75
EXPECT_EQ (motion_backend.GetPendingElements (NULL ), 0 );
77
76
}
78
77
79
78
TEST (PruMotionQueue, single_exec) {
80
79
MotorsRegister absolute_pos_loops;
81
- NiceMock< MockPRUInterface> pru_interface;
80
+ MockPRUInterface pru_interface;
82
81
HardwareMapping hmap = HardwareMapping ();
83
82
PRUMotionQueue motion_backend (&hmap, (PruHardwareInterface *)&pru_interface);
84
83
@@ -91,7 +90,7 @@ TEST(PruMotionQueue, single_exec) {
91
90
92
91
TEST (PruMotionQueue, full_exec) {
93
92
MotorsRegister absolute_pos_loops;
94
- NiceMock< MockPRUInterface> pru_interface;
93
+ MockPRUInterface pru_interface;
95
94
HardwareMapping hmap = HardwareMapping ();
96
95
PRUMotionQueue motion_backend (&hmap, (PruHardwareInterface *)&pru_interface);
97
96
@@ -104,7 +103,7 @@ TEST(PruMotionQueue, full_exec) {
104
103
105
104
TEST (PruMotionQueue, single_exec_some_loops) {
106
105
MotorsRegister absolute_pos_loops;
107
- NiceMock< MockPRUInterface> pru_interface;
106
+ MockPRUInterface pru_interface;
108
107
HardwareMapping hmap = HardwareMapping ();
109
108
PRUMotionQueue motion_backend (&hmap, (PruHardwareInterface *)&pru_interface);
110
109
@@ -119,7 +118,7 @@ TEST(PruMotionQueue, single_exec_some_loops) {
119
118
120
119
TEST (PruMotionQueue, one_round_queue) {
121
120
MotorsRegister absolute_pos_loops;
122
- NiceMock< MockPRUInterface> pru_interface;
121
+ MockPRUInterface pru_interface;
123
122
HardwareMapping hmap = HardwareMapping ();
124
123
PRUMotionQueue motion_backend (&hmap, (PruHardwareInterface *)&pru_interface);
125
124
@@ -141,7 +140,7 @@ TEST(PruMotionQueue, one_round_queue) {
141
140
// Check the PRU is reset and no elements are pending.
142
141
TEST (PruMotionQueue, clear_queue) {
143
142
MotorsRegister absolute_pos_loops;
144
- NiceMock< MockPRUInterface> pru_interface;
143
+ MockPRUInterface pru_interface;
145
144
HardwareMapping hmap = HardwareMapping ();
146
145
PRUMotionQueue motion_backend (&hmap, (PruHardwareInterface *)&pru_interface);
147
146
@@ -157,18 +156,18 @@ TEST(PruMotionQueue, clear_queue) {
157
156
ASSERT_TRUE (testing::Mock::VerifyAndClearExpectations (&pru_interface));
158
157
{
159
158
testing::InSequence seq;
160
- EXPECT_CALL (pru_interface, Shutdown ())
161
- .Times (1 )
162
- . WillRepeatedly ( testing::Return ( true ));
163
- EXPECT_CALL (pru_interface, Init ()) .Times (1 ). WillOnce ( testing::Return ( true ) );
159
+ EXPECT_CALL (pru_interface, Halt ())
160
+ .Times (1 );
161
+ EXPECT_CALL (pru_interface, Restart ())
162
+ .Times (1 );
164
163
}
165
164
EXPECT_TRUE (motion_backend.Clear ());
166
165
EXPECT_EQ (motion_backend.GetPendingElements (NULL ), 0 );
167
166
}
168
167
169
168
TEST (PruMotionQueue, exec_index_lt_queue_pos) {
170
169
MotorsRegister absolute_pos_loops;
171
- NiceMock< MockPRUInterface> pru_interface;
170
+ MockPRUInterface pru_interface;
172
171
HardwareMapping hmap = HardwareMapping ();
173
172
PRUMotionQueue motion_backend (&hmap, (PruHardwareInterface *)&pru_interface);
174
173
0 commit comments