@@ -156,7 +156,7 @@ class GPIOComponentTestBase : public ::testing::TestWithParam<TP> {
156156 // TODO Not yet
157157 return false ;
158158 }
159- // Using TwoWire
159+ // Using GPIO
160160 return Units.add (*unit, pin_num_gpio_in, pin_num_gpio_out) && Units.begin ();
161161 }
162162
@@ -170,6 +170,61 @@ class GPIOComponentTestBase : public ::testing::TestWithParam<TP> {
170170 m5::unit::UnitUnified Units;
171171};
172172
173+ /* !
174+ @class UARTComponentTestBase
175+ @brief UnitComponent Derived class for testing (UART)
176+ @tparam U m5::unit::Component-derived classes to be tested
177+ @tparam TP parameter type for testing. see also INSTANTIATE_TEST_SUITE_P
178+ */
179+ template <typename U, typename TP >
180+ class UARTComponentTestBase : public ::testing::TestWithParam<TP > {
181+ static_assert (std::is_base_of<m5::unit::Component, U>::value, " U must be derived from Component" );
182+
183+ protected:
184+ virtual void SetUp () override
185+ {
186+ unit.reset (get_instance ());
187+ if (!unit) {
188+ FAIL () << " Failed to get_instance" ;
189+ GTEST_SKIP ();
190+ return ;
191+ }
192+ ustr = m5::utility::formatString (" %s:%s" , unit->deviceName (), is_using_hal () ? " HAL" : " UART" );
193+ if (!begin ()) {
194+ FAIL () << " Failed to begin " << ustr;
195+ GTEST_SKIP ();
196+ }
197+ }
198+
199+ virtual void TearDown () override
200+ {
201+ }
202+
203+ virtual bool begin ()
204+ {
205+ if (is_using_hal ()) {
206+ // Using M5HAL
207+ // TODO Not yet
208+ return false ;
209+ }
210+ // Using Serial
211+ serial = init_serial ();
212+ return serial && Units.add (*unit, *serial) && Units.begin ();
213+ }
214+
215+ // !@brief Function returning true if M5HAL is used (decision based on TP)
216+ virtual bool is_using_hal () const = 0;
217+ // ! @brief return m5::unit::Component-derived class instance (decision based on TP)
218+ virtual U* get_instance () = 0;
219+ // !@brief Initialize the serial to be used
220+ virtual HardwareSerial* init_serial () = 0;
221+
222+ std::string ustr{};
223+ std::unique_ptr<U> unit{};
224+ m5::unit::UnitUnified Units;
225+ HardwareSerial* serial{};
226+ };
227+
173228} // namespace googletest
174229} // namespace unit
175230} // namespace m5
0 commit comments