Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 1 | #ifndef AOS_COMMON_CONTROLS_CONTROL_LOOP_TEST_H_ |
| 2 | #define AOS_COMMON_CONTROLS_CONTROL_LOOP_TEST_H_ |
| 3 | |
| 4 | #include "gtest/gtest.h" |
| 5 | |
| 6 | #include "aos/common/queue_testutils.h" |
Brian Silverman | bbc8678 | 2014-08-19 12:13:05 -0400 | [diff] [blame] | 7 | #include "aos/common/time.h" |
Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 8 | |
| 9 | namespace aos { |
| 10 | namespace testing { |
| 11 | |
| 12 | // Handles setting up the environment that all control loops need to actually |
| 13 | // run. |
| 14 | // This includes sending the queue messages and Clear()ing the queues when |
| 15 | // appropriate. |
| 16 | // It also includes dealing with ::aos::time. |
| 17 | class ControlLoopTest : public ::testing::Test { |
| 18 | public: |
| 19 | ControlLoopTest(); |
Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 20 | virtual ~ControlLoopTest(); |
| 21 | |
Brian Silverman | e6f64ab | 2015-02-05 17:03:56 -0500 | [diff] [blame^] | 22 | // Sends out all of the required queue messages. |
| 23 | void SendMessages(bool enabled); |
| 24 | // Ticks time for a single control loop cycle. |
| 25 | void TickTime() { |
| 26 | ::aos::time::Time::SetMockTime(current_time_ += kTimeTick); |
| 27 | } |
| 28 | |
| 29 | // Simulates everything that happens during 1 loop time step. |
| 30 | void SimulateTimestep(bool enabled) { |
| 31 | SendMessages(enabled); |
| 32 | TickTime(); |
| 33 | } |
Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 34 | |
| 35 | private: |
Brian Silverman | e6f64ab | 2015-02-05 17:03:56 -0500 | [diff] [blame^] | 36 | static constexpr ::aos::time::Time kTimeTick = ::aos::time::Time::InUS(10000); |
| 37 | static constexpr ::aos::time::Time kDSPacketTime = |
| 38 | ::aos::time::Time::InMS(20); |
| 39 | |
| 40 | ::aos::time::Time last_ds_time_ = ::aos::time::Time::InSeconds(0); |
Brian Silverman | bbc8678 | 2014-08-19 12:13:05 -0400 | [diff] [blame] | 41 | ::aos::time::Time current_time_ = ::aos::time::Time::InSeconds(0); |
Brian Silverman | 65e4970 | 2014-04-30 17:36:40 -0700 | [diff] [blame] | 42 | |
| 43 | ::aos::common::testing::GlobalCoreInstance my_core; |
| 44 | }; |
| 45 | |
| 46 | } // namespace testing |
| 47 | } // namespace aos |
| 48 | |
| 49 | #endif // AOS_COMMON_CONTROLS_CONTROL_LOOP_TEST_H_ |