| 175 | } |
| 176 | |
| 177 | void |
| 178 | MultiThreadUnitTests::serialPort2ThreadLoop() |
| 179 | { |
| 180 | const size_t threadLoopStartTimeMilliseconds = getTimeInMilliSeconds() ; |
| 181 | size_t timeElapsedMilliSeconds = 0; |
| 182 | |
| 183 | while (timeElapsedMilliSeconds < timeOutMilliseconds) |
| 184 | { |
| 185 | // |
| 186 | // Write data to the serial port. It should be received by the other |
| 187 | // thread. |
| 188 | // |
| 189 | serialPort2.Write(writeString2 + '\n') ; |
| 190 | serialPort2.DrainWriteBuffer() ; |
| 191 | |
| 192 | // |
| 193 | // Wait for data to arrive from the other thread |
| 194 | // |
| 195 | if (serialPort2.IsDataAvailable()) |
| 196 | { |
| 197 | try |
| 198 | { |
| 199 | readString1.clear() ; |
| 200 | serialPort2.ReadLine(readString1, '\n', timeOutMilliseconds) ; |
| 201 | } |
| 202 | catch (const std::exception& err) |
| 203 | { |
| 204 | std::cerr << err.what() << std::endl ; |
| 205 | } |
| 206 | |
| 207 | if(readString1 != writeString1 + '\n') |
| 208 | { |
| 209 | const std::lock_guard<std::mutex> lock {mutex} ; |
| 210 | failureRate++; |
| 211 | } |
| 212 | } |
| 213 | |
| 214 | const std::lock_guard<std::mutex> lock {mutex} ; |
| 215 | loopCount++; |
| 216 | |
| 217 | timeElapsedMilliSeconds = getTimeInMilliSeconds() - threadLoopStartTimeMilliseconds; |
| 218 | } |
| 219 | } |
| 220 | |
| 221 | void |
| 222 | MultiThreadUnitTests::testMultiThreadSerialStreamReadWrite() |
nothing calls this directly
no test coverage detected