| 53 | } |
| 54 | |
| 55 | void |
| 56 | MultiThreadUnitTests::serialStream1ThreadLoop() |
| 57 | { |
| 58 | size_t threadLoopStartTimeMilliseconds = getTimeInMilliSeconds() ; |
| 59 | size_t timeElapsedMilliSeconds = 0; |
| 60 | |
| 61 | while (timeElapsedMilliSeconds < timeOutMilliseconds) |
| 62 | { |
| 63 | // |
| 64 | // Write data to the serial port. It should be received by the other |
| 65 | // thread. |
| 66 | // |
| 67 | serialStream1 << writeString1 << std::endl; |
| 68 | serialStream1.DrainWriteBuffer() ; |
| 69 | |
| 70 | // |
| 71 | // Wait for data to arrive from the other thread |
| 72 | // |
| 73 | if (serialStream1.IsDataAvailable()) |
| 74 | { |
| 75 | alarm(5) ; // Set a system alarm in case getline() blocks longer than 5 seconds. |
| 76 | readString2.clear() ; |
| 77 | getline(serialStream1, readString2) ; |
| 78 | alarm(0) ; // Deactivate the alarm. |
| 79 | |
| 80 | if(readString2 != writeString2) |
| 81 | { |
| 82 | const std::lock_guard<std::mutex> lock {mutex} ; |
| 83 | failureRate++; |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | const std::lock_guard<std::mutex> lock {mutex} ; |
| 88 | loopCount++; |
| 89 | |
| 90 | timeElapsedMilliSeconds = getTimeInMilliSeconds() - threadLoopStartTimeMilliseconds; |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | void |
| 95 | MultiThreadUnitTests::serialStream2ThreadLoop() |
nothing calls this directly
no test coverage detected