File tree Expand file tree Collapse file tree 1 file changed +10
-8
lines changed
CD_CI/UnitTests/VoltageDividerMonitorTest Expand file tree Collapse file tree 1 file changed +10
-8
lines changed Original file line number Diff line number Diff line change 3030
3131VoltageDividerMonitor *hardware = nullptr ;
3232int receivedBatteryLevel = 999 ;
33- std::counting_semaphore<1 > received{1 };
34- bool waiting;
33+ bool running = false ;
34+ std::binary_semaphore producer{0 };
35+ std::binary_semaphore consumer{0 };
3536
3637// ------------------------------------------------------------------
3738// MOCKS
@@ -53,17 +54,18 @@ class BatteryCalibrationMock : public BatteryCalibrationService
5354
5455void get_current_battery_level (const BatteryStatus &status)
5556{
57+ if (!running)
58+ return ;
59+ producer.acquire ();
5660 // std::cout << "get_current_battery_level" << std::endl;
5761 receivedBatteryLevel = status.stateOfCharge .value_or (0 );
58- received.release ();
59- waiting = false ;
62+ consumer.release ();
6063}
6164
6265void waitFor (std::string message = " " )
6366{
64- waiting = true ;
65- while (waiting)
66- received.acquire ();
67+ producer.release ();
68+ consumer.acquire ();
6769}
6870
6971// ------------------------------------------------------------------
@@ -74,7 +76,6 @@ void waitFor(std::string message = "")
7476
7577void test1 ()
7678{
77-
7879 std::cout << " - test 1 (ADC value injection)-" << std::endl;
7980 internals::hal::gpio::setFakeADCReading ({2000 });
8081
@@ -166,6 +167,7 @@ int main()
166167 batteryMonitor::setPeriod (1 );
167168 internals::batteryMonitor::getReady ();
168169 OnStart::notify ();
170+ running = true ;
169171
170172 test1 ();
171173 test2 ();
You can’t perform that action at this time.
0 commit comments