| 92 | } |
| 93 | |
| 94 | void |
| 95 | MultiThreadUnitTests::serialStream2ThreadLoop() |
| 96 | { |
| 97 | const size_t threadLoopStartTimeMilliseconds = getTimeInMilliSeconds() ; |
| 98 | size_t timeElapsedMilliSeconds = 0; |
| 99 | |
| 100 | while (timeElapsedMilliSeconds < timeOutMilliseconds) |
| 101 | { |
| 102 | // |
| 103 | // Write data to the serial port. It should be received by the other |
| 104 | // thread. |
| 105 | // |
| 106 | serialStream2 << writeString2 << std::endl; |
| 107 | serialStream2.DrainWriteBuffer() ; |
| 108 | |
| 109 | // |
| 110 | // Wait for data to arrive from the other thread |
| 111 | // |
| 112 | if (serialStream2.IsDataAvailable()) |
| 113 | { |
| 114 | alarm(5) ; // Set a system alarm in case getline() blocks longer than 5 seconds. |
| 115 | readString1.clear() ; |
| 116 | getline(serialStream2, readString1) ; |
| 117 | alarm(0) ; // Deactivate the alarm. |
| 118 | |
| 119 | if(readString1 != writeString1) |
| 120 | { |
| 121 | const std::lock_guard<std::mutex> lock {mutex} ; |
| 122 | failureRate++; |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | const std::lock_guard<std::mutex> lock {mutex} ; |
| 127 | loopCount++; |
| 128 | |
| 129 | timeElapsedMilliSeconds = getTimeInMilliSeconds() - threadLoopStartTimeMilliseconds; |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | void |
| 134 | MultiThreadUnitTests::serialPort1ThreadLoop() |
nothing calls this directly
no test coverage detected