| 131 | } |
| 132 | |
| 133 | void |
| 134 | MultiThreadUnitTests::serialPort1ThreadLoop() |
| 135 | { |
| 136 | const size_t threadLoopStartTimeMilliseconds = getTimeInMilliSeconds() ; |
| 137 | size_t timeElapsedMilliSeconds = 0; |
| 138 | |
| 139 | while (timeElapsedMilliSeconds < timeOutMilliseconds) |
| 140 | { |
| 141 | // |
| 142 | // Write data to the serial port. It should be received by the other |
| 143 | // thread. |
| 144 | // |
| 145 | serialPort1.Write(writeString1 + '\n') ; |
| 146 | serialPort1.DrainWriteBuffer() ; |
| 147 | |
| 148 | // |
| 149 | // Wait for data to arrive from the other thread |
| 150 | // |
| 151 | if (serialPort1.IsDataAvailable()) |
| 152 | { |
| 153 | try |
| 154 | { |
| 155 | readString2.clear() ; |
| 156 | serialPort1.ReadLine(readString2, '\n', timeOutMilliseconds) ; |
| 157 | } |
| 158 | catch (const std::exception& err) |
| 159 | { |
| 160 | std::cerr << err.what() << std::endl ; |
| 161 | } |
| 162 | |
| 163 | if(readString2 != writeString2 + '\n') |
| 164 | { |
| 165 | const std::lock_guard<std::mutex> lock {mutex} ; |
| 166 | failureRate++; |
| 167 | } |
| 168 | } |
| 169 | |
| 170 | const std::lock_guard<std::mutex> lock {mutex} ; |
| 171 | loopCount++; |
| 172 | |
| 173 | timeElapsedMilliSeconds = getTimeInMilliSeconds() - threadLoopStartTimeMilliseconds; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void |
| 178 | MultiThreadUnitTests::serialPort2ThreadLoop() |
nothing calls this directly
no test coverage detected