@@ -52,6 +52,7 @@ MockDevice::~MockDevice(){
5252}
5353void MockDevice::print () const {
5454 std::lock_guard<Mutex> lg (m_device_lock);
55+ std::lock_guard<Mutex> lg1 (m_print_lock);
5556 pabb2_StreamCoalescer_print (&m_connection.stream_coalescer , true );
5657}
5758
@@ -65,6 +66,7 @@ size_t MockDevice::device_send_serial(const void* data, size_t bytes, bool is_re
6566 }
6667
6768 if ((rand () % 100 ) / 100 . < PABB2_DROP_DEVICE_TO_HOST){
69+ std::lock_guard<Mutex> lg1 (m_print_lock);
6870 cout << " **Intentionally Dropping Packet: device -> host**" << endl;
6971 return 0 ;
7072 }
@@ -77,6 +79,7 @@ size_t MockDevice::device_send_serial(const void* data, size_t bytes, bool is_re
7779 );
7880
7981 if ((rand () % 100 ) / 100 . < PABB2_DROP_DEVICE_TO_HOST){
82+ std::lock_guard<Mutex> lg1 (m_print_lock);
8083 cout << " **Intentionally Corrupting Packet: device -> host**" << endl;
8184 m_device_to_host_line[rand () % m_device_to_host_line.size ()] = 0 ;
8285 }
@@ -104,6 +107,7 @@ size_t MockDevice::send(const void* data, size_t bytes){
104107// cout << "MockDevice::send(const void* data, size_t bytes)" << endl;
105108
106109 if ((rand () % 100 ) / 100 . < PABB2_DROP_HOST_TO_DEVICE){
110+ std::lock_guard<Mutex> lg1 (m_print_lock);
107111 cout << " **Intentionally Dropping Packet: host -> device**" << endl;
108112 return 0 ;
109113 }
@@ -119,6 +123,7 @@ size_t MockDevice::send(const void* data, size_t bytes){
119123 );
120124
121125 if ((rand () % 100 ) / 100 . < PABB2_DROP_HOST_TO_DEVICE){
126+ std::lock_guard<Mutex> lg1 (m_print_lock);
122127 cout << " **Intentionally Corrupting Packet: host -> device**" << endl;
123128 m_host_to_device_line[rand () % m_host_to_device_line.size ()] = 0 ;
124129 }
@@ -131,6 +136,53 @@ size_t MockDevice::send(const void* data, size_t bytes){
131136 return bytes;
132137}
133138
139+ void MockDevice::push_expected_stream_data (const void * data, size_t bytes){
140+ std::lock_guard<Mutex> lg (m_device_lock);
141+
142+ m_expected_host_to_device_stream.insert (
143+ m_expected_host_to_device_stream.end (),
144+ (const uint8_t *)data,
145+ (const uint8_t *)data + bytes
146+ );
147+
148+ bytes = m_expected_host_to_device_stream.size ();
149+
150+ std::vector<uint8_t > actual (bytes);
151+ size_t read = pabb2_ReliableStreamConnection_read_stream (
152+ &m_connection,
153+ actual.data (), bytes
154+ );
155+
156+ {
157+ std::lock_guard<Mutex> lg1 (m_print_lock);
158+ cout << " read = " << read << endl;
159+ }
160+
161+
162+ std::vector<uint8_t > expected (
163+ m_expected_host_to_device_stream.begin (),
164+ m_expected_host_to_device_stream.begin () + read
165+ );
166+
167+ m_expected_host_to_device_stream.erase (
168+ m_expected_host_to_device_stream.begin (),
169+ m_expected_host_to_device_stream.begin () + read
170+ );
171+
172+ if (memcmp (actual.data (), expected.data (), read) == 0 ){
173+ return ;
174+ }
175+
176+ std::lock_guard<Mutex> lg1 (m_print_lock);
177+ cout << " MISMATCH: Expected: "
178+ << std::string ((const char *)expected.data (), read)
179+ << " , Actual: "
180+ << std::string ((const char *)actual.data (), read)
181+ << endl;
182+ }
183+
184+
185+
134186
135187void MockDevice::device_thread (){
136188 std::unique_lock<Mutex> lg (m_device_lock);
0 commit comments