1#!/usr/bin/env python 2# 3# Copyright (C) 2018 The Android Open Source Project 4# 5# Licensed under the Apache License, Version 2.0 (the "License"); 6# you may not use this file except in compliance with the License. 7# You may obtain a copy of the License at 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 11# Unless required by applicable law or agreed to in writing, software 12# distributed under the License is distributed on an "AS IS" BASIS, 13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14# See the License for the specific language governing permissions and 15# limitations under the License. 16# 17 18import logging 19import time 20 21from vts.runners.host import asserts 22from vts.runners.host import base_test 23from vts.runners.host import const 24from vts.runners.host import test_runner 25from vts.proto import ComponentSpecificationMessage_pb2 as CompSpecMsg 26 27 28class VtsHalTestsMsgqV1_0HostTest(base_test.BaseTestClass): 29 """This testcase is converted from FMQ HAL service test on the target side 30 (system/libfmq/tests/msgq_test_client.cpp). 31 Since current host-side doesn't support long-form blocking or 32 zero copy operations, all testcases related to these two features are not 33 converted here. 34 UnsynchronizedWriteClientMultiProcess class is not converted here 35 because the testcase is similar to OverflowNotificationTest in 36 UnsynchronizedWriteClient class. 37 """ 38 TEST_HAL_SERVICES = {"android.hardware.tests.msgq@1.0::ITestMsgQ"} 39 MAX_NUM_MSG = 1024 40 MAX_RETRY = 3 41 SERVICE_NAME = "android.hardware.tests.msgq@1.0-service-test" 42 COMMAND_32 = "TREBLE_TESTING_OVERRIDE=true /data/nativetest/" + SERVICE_NAME + "/" + SERVICE_NAME + " &" 43 COMMAND_64 = "TREBLE_TESTING_OVERRIDE=true /data/nativetest64/" + SERVICE_NAME + "/" + SERVICE_NAME + " &" 44 CHECK_COMMAND = "lshal --types=b | grep \"android.hardware.tests.msgq@1.0\"" 45 46 def setUpClass(self): 47 self.dut = self.android_devices[0] 48 if (int(self.abi_bitness) == 64): 49 self.dut.shell.Execute(self.COMMAND_64) 50 else: 51 self.dut.shell.Execute(self.COMMAND_32) 52 53 start_hal_success = False 54 # Wait until service is started. 55 # Retry at most three times. 56 for i in range(self.MAX_RETRY): 57 result = self.dut.shell.Execute(self.CHECK_COMMAND) 58 if (result[const.STDOUT][0] != ""): 59 start_hal_success = True # setup successful 60 break 61 time.sleep(1) # wait one second. 62 63 # msgq HAL service is still not started after waiting for 64 # self.MAX_RETRY times, stop the testcase. 65 if (not start_hal_success): 66 logging.error("Failed to start msgq HAL service.") 67 return False 68 69 super(VtsHalTestsMsgqV1_0HostTest, self).setUpClass() 70 # Load a msgq test hal driver. 71 self.dut.hal.InitHidlHal( 72 target_type="tests_msgq", 73 target_basepaths=self.dut.libPaths, 74 target_version_major=1, 75 target_version_minor=0, 76 target_package="android.hardware.tests.msgq", 77 target_component_name="ITestMsgQ", 78 bits=int(self.abi_bitness), 79 is_test_hal=True) 80 81 # create a shortcut. 82 self._tests_msgq = self.dut.hal.tests_msgq 83 84 def setUp(self): 85 # Initialize a FMQ on the target-side driver. 86 self._sync_client = self.dut.resource.InitFmq( 87 data_type="uint16_t", 88 sync=True, 89 queue_size=self.MAX_NUM_MSG, 90 blocking=True, 91 client=self.dut.hal.GetTcpClient("tests_msgq")) 92 asserts.assertNotEqual(self._sync_client.queueId, -1) 93 94 # Prepare a VariableSpecificationMessage to specify the FMQ that will be 95 # passed into the HAL service. 96 var_msg = CompSpecMsg.VariableSpecificationMessage() 97 var_msg.type = CompSpecMsg.TYPE_FMQ_SYNC 98 fmq_val = var_msg.fmq_value.add() 99 fmq_val.fmq_id = self._sync_client.queueId 100 fmq_val.scalar_type = "uint16_t" 101 fmq_val.type = CompSpecMsg.TYPE_SCALAR 102 103 # Call API in the HAL server. 104 sync_init_result = self._tests_msgq.configureFmqSyncReadWrite(var_msg) 105 asserts.assertTrue( 106 sync_init_result, 107 "Hal should configure a synchronized queue without error.") 108 109 # Initialize an unsynchronized queue on the server. 110 [success, 111 self._unsync_client1] = self._tests_msgq.getFmqUnsyncWrite(True) 112 asserts.assertTrue( 113 success, 114 "Hal should configure an unsynchronized queue without error.") 115 # An unsynchronized queue is registered successfully on the target driver. 116 asserts.assertNotEqual(self._unsync_client1, None) 117 asserts.assertNotEqual(self._unsync_client1.queueId, -1) 118 # Register another reader. 119 self._unsync_client2 = self.dut.resource.InitFmq( 120 existing_queue=self._unsync_client1, 121 client=self.dut.hal.GetTcpClient("tests_msgq")) 122 asserts.assertNotEqual(self._unsync_client2.queueId, -1) 123 124 def testSyncQueueBlockingReadWriteSuccess(self): 125 """This test operates on the synchronized queue. 126 Mirrors testcase: BlockingReadWrite2. 127 Server is blocked because there is no data to read. 128 Client writes once, which unblocks the server. 129 Another write from client will also succeed. 130 """ 131 # Request a blocking read from the server. 132 # This call returns immediately. 133 self._tests_msgq.requestBlockingReadDefaultEventFlagBits( 134 self.MAX_NUM_MSG) 135 136 # Client writes, unblocks server. 137 write_data = generateSequentialData(self.MAX_NUM_MSG) 138 asserts.assertTrue( 139 self._sync_client.writeBlocking(write_data, self.MAX_NUM_MSG), 140 "Client should write successfully.") 141 142 # If blocking read was successful from the server, another write of 143 # size 1000 will succeed because there is space to write now. 144 asserts.assertTrue( 145 self._sync_client.writeBlocking(write_data, self.MAX_NUM_MSG, 146 5000000000), 147 "Client should write successfully if server blocking read is successful." 148 ) 149 # Server reads it back again. 150 self._tests_msgq.requestBlockingReadDefaultEventFlagBits( 151 self.MAX_NUM_MSG) 152 153 def testSyncQueueSmallInputReaderTest1(self): 154 """This test operates on the synchronized queue. 155 Mirrors testcase: SynchronizedReadWriteClient, SmallInputReaderTest1. 156 Server writes a small number of messages and client reads it back. 157 """ 158 data_len = 16 159 160 # Server writes. 161 asserts.assertTrue( 162 self._tests_msgq.requestWriteFmqSync(data_len), 163 "Server should write successfully.") 164 # Client reads. 165 read_data = [] 166 asserts.assertTrue( 167 self._sync_client.read(read_data, data_len), 168 "Client should read successfully.") 169 asserts.assertEqual(read_data, generateSequentialData(data_len)) 170 171 def testSyncQueueSmallInputWriterTest1(self): 172 """This test operates on the synchronized queue. 173 Mirrors testcase: SynchronizedReadWriteClient, SmallInputWriterTest1. 174 Client writes a small number of messages and server reads it back. 175 """ 176 data_len = 16 177 write_data = generateSequentialData(data_len) 178 179 # Client writes. 180 asserts.assertTrue( 181 self._sync_client.write(write_data, data_len), 182 "Server should write successfully.") 183 # Server reads. 184 asserts.assertTrue( 185 self._tests_msgq.requestReadFmqSync(data_len), 186 "Client should read successfully.") 187 188 def testSyncQueueReadWhenEmpty(self): 189 """This test operates on the synchronized queue. 190 Mirrors testcase: SynchronizedReadWriteClient, ReadWhenEmpty. 191 Read should fail when queue is empty. 192 """ 193 asserts.assertEqual(self._sync_client.availableToRead(), 0) 194 asserts.assertFalse( 195 self._sync_client.read([], 2), 196 "Client should fail to read because queue is empty.") 197 198 def testSyncQueueWriteWhenFull(self): 199 """This test operates on the synchronized queue. 200 Mirrors testcase: SynchronizedReadWriteClient, WriteWhenFull. 201 Write should fail when queue is full. 202 """ 203 write_data = generateSequentialData(self.MAX_NUM_MSG) 204 205 # Client writes. 206 asserts.assertTrue( 207 self._sync_client.write(write_data, self.MAX_NUM_MSG), 208 "Client should write successfully.") 209 asserts.assertEqual(self._sync_client.availableToWrite(), 0) 210 # Client tries to write more, fails. 211 asserts.assertFalse( 212 self._sync_client.write([1], 1), 213 "Client should fail to write because queue is full.") 214 # Server should read data back correctly. 215 asserts.assertTrue( 216 self._tests_msgq.requestReadFmqSync(self.MAX_NUM_MSG), 217 "Server should read successfully") 218 219 def testSyncQueueLargeInputTest1(self): 220 """This test operates on the synchronized queue. 221 Mirrors testcase: SynchronizedReadWriteClient, LargeInputTest1. 222 Server writes to the queue and client reads the data back. 223 """ 224 # Server writes. 225 asserts.assertTrue( 226 self._tests_msgq.requestWriteFmqSync(self.MAX_NUM_MSG), 227 "Server should write successfully.") 228 229 write_data = generateSequentialData(self.MAX_NUM_MSG) 230 read_data = [] 231 # Client reads. 232 asserts.assertEqual(self._sync_client.availableToRead(), 233 self.MAX_NUM_MSG) 234 self._sync_client.read(read_data, self.MAX_NUM_MSG) 235 asserts.assertEqual(write_data, read_data) 236 237 def testSyncQueueLargeInputTest2(self): 238 """This test operates on the synchronized queue. 239 Mirrors testcase: SynchronizedReadWriteClient, LargeInputTest2. 240 Server attempts to write more than the queue capacity and fails. 241 """ 242 asserts.assertEqual(0, self._sync_client.availableToRead()) 243 # Server attempts to write more than the queue capacity. 244 asserts.assertFalse( 245 self._tests_msgq.requestWriteFmqSync(self.MAX_NUM_MSG * 2), 246 "Server should fail because it writes more than queue capacity.") 247 # Check there is still no data for client. 248 asserts.assertEqual(0, self._sync_client.availableToRead()) 249 asserts.assertFalse( 250 self._sync_client.read([], 1), 251 "Client should fail to read because queue is empty.") 252 253 def testSyncQueueLargeInputTest3(self): 254 """This test operates on the synchronized queue. 255 Mirrors testcase: SynchronizedReadWriteClient, LargeInputTest3. 256 Client writes until the queue is full, attempts to write one more, 257 and fails. 258 """ 259 write_data = generateSequentialData(self.MAX_NUM_MSG) 260 261 # Client fills up the queue. 262 asserts.assertTrue( 263 self._sync_client.write(write_data, self.MAX_NUM_MSG), 264 "Client should write successfully.") 265 asserts.assertEqual(0, self._sync_client.availableToWrite()) 266 # Client attempts to write one more, fails. 267 asserts.assertFalse( 268 self._sync_client.write([1], 1), 269 "Client should fail to write because queue is full.") 270 # Server reads back data from client. 271 asserts.assertTrue( 272 self._tests_msgq.requestReadFmqSync(self.MAX_NUM_MSG), 273 "Server should read successfully.") 274 275 def testSyncQueueClientMultipleRead(self): 276 """This test operates on the synchronized queue. 277 Mirrors testcase: SynchronizedReadWriteClient, MultipleRead. 278 Server acts as a writer, and client reads the data back in batches. 279 """ 280 chunk_size = 100 281 chunk_num = 5 282 num_messages = chunk_num * chunk_size 283 write_data = generateSequentialData(num_messages) 284 285 # Client has no data to read yet. 286 asserts.assertEqual(self._sync_client.availableToRead(), 0) 287 # Server writes. 288 asserts.assertTrue( 289 self._tests_msgq.requestWriteFmqSync(num_messages), 290 "Server should write successfully.") 291 292 # Client reads it back continuously. 293 total_read_data = [] 294 for i in range(chunk_num): 295 read_data = [] 296 asserts.assertTrue( 297 self._sync_client.read(read_data, chunk_size), 298 "Client should read successfully.") 299 total_read_data.extend(read_data) 300 301 # Check read_data and write_data are equal. 302 asserts.assertEqual(write_data, total_read_data) 303 304 def testSyncQueueClientMultipleWrite(self): 305 """This test operates on the synchronized queue. 306 Mirrors testcase: SynchronizedReadWriteClient, MultipleWrite. 307 Client writes the data in batches, and server reads it back together. 308 """ 309 chunk_size = 100 310 chunk_num = 5 311 num_messages = chunk_num * chunk_size 312 write_data = generateSequentialData(num_messages) 313 314 # Client should see an empty queue. 315 asserts.assertEqual(self._sync_client.availableToWrite(), 316 self.MAX_NUM_MSG) 317 for i in range(chunk_num): # Client keeps writing. 318 curr_write_data = write_data[i * chunk_size:(i + 1) * chunk_size] 319 asserts.assertTrue( 320 self._sync_client.write(curr_write_data, chunk_size), 321 "Client should write successfully.") 322 323 # Server reads data back correctly. 324 asserts.assertTrue( 325 self._tests_msgq.requestReadFmqSync(num_messages), 326 "Server should read successfully.") 327 328 def testSyncQueueReadWriteWrapAround(self): 329 """This test operates on the synchronized queue. 330 Mirrors testcase: SynchronizedReadWriteClient, ReadWriteWrapAround1. 331 Client writes half of the queue and server reads back. 332 Client writes the max capacity, which will cause a wrap 333 around in the queue, server should still read back correctly. 334 """ 335 num_messages = self.MAX_NUM_MSG / 2 336 write_data = generateSequentialData(self.MAX_NUM_MSG) 337 338 # Client writes half of the queue capacity, and server reads it. 339 asserts.assertTrue( 340 self._sync_client.write(write_data, num_messages), 341 "Client should write successfully.") 342 asserts.assertTrue( 343 self._tests_msgq.requestReadFmqSync(num_messages), 344 "Server should read successfully.") 345 # Client writes the max queue capacity, causes a wrap around 346 asserts.assertTrue( 347 self._sync_client.write(write_data, self.MAX_NUM_MSG), 348 "Client should write successfully.") 349 # Server reads back data correctly 350 asserts.assertTrue( 351 self._tests_msgq.requestReadFmqSync(self.MAX_NUM_MSG), 352 "Server should read successfully.") 353 354 def testUnsyncQueueSmallInputReaderTest1(self): 355 """This test operates on the unsynchronized queue. 356 Mirrors testcase: UnsynchronizedWriteClient, SmallInputReaderTest1. 357 Server writes a small number of messages and client reads it back. 358 """ 359 data_len = 16 360 361 # Server writes. 362 asserts.assertTrue( 363 self._tests_msgq.requestWriteFmqUnsync(data_len), 364 "Server should write successfully.") 365 # Client reads. 366 read_data = [] 367 asserts.assertTrue( 368 self._unsync_client1.read(read_data, data_len), 369 "Client should read successfully.") 370 asserts.assertEqual(read_data, generateSequentialData(16)) 371 372 def testUnsyncQueueSmallInputWriterTest1(self): 373 """This test operates on the unsynchronized queue. 374 Mirrors testcase: UnsynchronizedWriteClient, SmallInputWriterTest1. 375 Client writes a small number of messages and server reads it back. 376 """ 377 data_len = 16 378 write_data = generateSequentialData(16) 379 380 # Client writes. 381 asserts.assertTrue( 382 self._unsync_client1.write(write_data, data_len), 383 "Server should write successfully.") 384 # Server reads. 385 asserts.assertTrue( 386 self._tests_msgq.requestReadFmqUnsync(data_len), 387 "Client should read successfully.") 388 389 def testUnsyncQueueReadWhenEmpty(self): 390 """This test operates on the unsynchronized queue. 391 Mirrors testcase: UnsynchronizedWriteClient, ReadWhenEmpty. 392 Read should fail when queue is empty. 393 """ 394 asserts.assertEqual(self._unsync_client1.availableToRead(), 0) 395 asserts.assertFalse( 396 self._unsync_client1.read([], 2), 397 "Client should fail to read because queue is empty.") 398 399 def testUnsyncQueueWriteWhenFull(self): 400 """This test operates on the unsynchronized queue. 401 Mirrors testcase: UnsynchronizedWriteClient, WriteWhenFull. 402 Write should still succeed because unsynchronized queue 403 allows overflow. Subsequent read should fail. 404 """ 405 write_data = generateSequentialData(self.MAX_NUM_MSG) 406 407 # Client writes. 408 asserts.assertTrue( 409 self._unsync_client1.write(write_data, self.MAX_NUM_MSG), 410 "Client should write successfully.") 411 asserts.assertEqual(self._unsync_client1.availableToWrite(), 0) 412 # Client tries to write more, still succeeds. 413 asserts.assertTrue( 414 self._unsync_client1.write([1], 1), 415 "Client should write successfully " 416 + "even if queue is full for unsynchronized queue.") 417 # Server should fail because queue overflows. 418 asserts.assertFalse( 419 self._tests_msgq.requestReadFmqUnsync(self.MAX_NUM_MSG), 420 "Server should fail to read because queue overflows.") 421 422 def testUnsyncQueueLargeInputTest1(self): 423 """This test operates on the unsynchronized queue. 424 Mirrors testcase: UnsynchronizedWriteClient, LargeInputTest1. 425 Server writes to the queue and client reads the data back. 426 """ 427 # Server writes. 428 asserts.assertTrue( 429 self._tests_msgq.requestWriteFmqUnsync(self.MAX_NUM_MSG), 430 "Server should write successfully.") 431 432 write_data = generateSequentialData(self.MAX_NUM_MSG) 433 read_data = [] 434 # Client reads. 435 asserts.assertEqual(self._unsync_client1.availableToRead(), 436 self.MAX_NUM_MSG) 437 asserts.assertTrue( 438 self._unsync_client1.read(read_data, self.MAX_NUM_MSG), 439 "Client should read successfully.") 440 asserts.assertEqual(write_data, read_data) 441 442 def testUnsyncQueueLargeInputTest2(self): 443 """This test operates on the unsynchronized queue. 444 Mirrors testcase: UnsynchronizedWriteClient, LargeInputTest2. 445 Server attempts to write more than the queue capacity and fails. 446 """ 447 asserts.assertEqual(0, self._unsync_client1.availableToRead()) 448 # Server attempts to write more than the queue capacity. 449 asserts.assertFalse( 450 self._tests_msgq.requestWriteFmqUnsync(self.MAX_NUM_MSG + 1), 451 "Server should fail because it writes more than queue capacity.") 452 # Check there is still no data for client. 453 asserts.assertEqual(0, self._unsync_client1.availableToRead()) 454 asserts.assertFalse( 455 self._unsync_client1.read([], 1), 456 "Client should fail to read because queue is empty.") 457 458 def testUnsyncQueueLargeInputTest3(self): 459 """This test operates on the unsynchronized queue. 460 Mirrors testcase: UnsynchronizedWriteClient, LargeInputTest3. 461 Client writes until the queue is full, and writes one more, 462 which overflows the queue. Read should fail after that. 463 Client writes again, and server should be able to read again. 464 """ 465 write_data = generateSequentialData(self.MAX_NUM_MSG) 466 467 # Client fills up the queue. 468 asserts.assertTrue( 469 self._unsync_client1.write(write_data, self.MAX_NUM_MSG), 470 "Client should write successfully.") 471 asserts.assertEqual(0, self._unsync_client1.availableToWrite()) 472 # Client attempts to write one more, still succeeds. 473 asserts.assertTrue( 474 self._unsync_client1.write([1], 1), 475 "Client should write successfully " 476 + "even if queue is full for unsynchronized queue.") 477 # Server fails to read because queue overflows. 478 asserts.assertFalse( 479 self._tests_msgq.requestReadFmqUnsync(self.MAX_NUM_MSG), 480 "Server should fail to read because queue overflows.") 481 482 # Do another interaction, and both should succeed. 483 asserts.assertTrue( 484 self._unsync_client1.write(write_data, self.MAX_NUM_MSG), 485 "Client should write successfully.") 486 asserts.assertTrue( 487 self._tests_msgq.requestReadFmqUnsync(self.MAX_NUM_MSG), 488 "Server should read successfully.") 489 490 def testUnsyncQueueClientMultipleRead(self): 491 """This test operates on the unsynchronized queue. 492 Mirrors testcase: UnsynchronizedWriteClient, MultipleRead. 493 Server acts as a writer, and client reads the data back in batches. 494 """ 495 chunk_size = 100 496 chunk_num = 5 497 num_messages = chunk_num * chunk_size 498 write_data = generateSequentialData(num_messages) 499 500 # Client has no data to read yet. 501 asserts.assertEqual(self._unsync_client1.availableToRead(), 0) 502 # Server writes. 503 asserts.assertTrue( 504 self._tests_msgq.requestWriteFmqUnsync(num_messages), 505 "Server should write successfully.") 506 507 # Client reads it back continuously. 508 total_read_data = [] 509 for i in range(chunk_num): 510 read_data = [] 511 asserts.assertTrue( 512 self._unsync_client1.read(read_data, chunk_size), 513 "Client should read successfully.") 514 total_read_data.extend(read_data) 515 516 # Check read_data and write_data are equal. 517 asserts.assertEqual(write_data, total_read_data) 518 519 def testUnsyncQueueClientMultipleWrite(self): 520 """This test operates on the unsynchronized queue. 521 Mirrors testcase: UnsynchronizedWriteClient, MultipleWrite. 522 Client writes the data in batches, and server reads it back together. 523 """ 524 chunk_size = 100 525 chunk_num = 5 526 num_messages = chunk_num * chunk_size 527 write_data = generateSequentialData(num_messages) 528 529 # Client should see an empty queue. 530 asserts.assertEqual(self._unsync_client1.availableToWrite(), 531 self.MAX_NUM_MSG) 532 for i in range(chunk_num): # Client keeps writing. 533 curr_write_data = write_data[i * chunk_size:(i + 1) * chunk_size] 534 asserts.assertTrue( 535 self._unsync_client1.write(curr_write_data, chunk_size), 536 "Client should write successfully.") 537 538 # Server reads data back correctly. 539 asserts.assertTrue( 540 self._tests_msgq.requestReadFmqUnsync(num_messages), 541 "Server should read successfully.") 542 543 def testUnsyncQueueReadWriteWrapAround(self): 544 """This test operates on the unsynchronized queue. 545 Mirrors testcase: UnsynchronizedWriteClient, ReadWriteWrapAround. 546 Client writes half of the queue and server reads back. 547 Client writes the max capacity, which will cause a wrap 548 around in the queue, server should still read back correctly. 549 """ 550 num_messages = self.MAX_NUM_MSG / 2 551 write_data = generateSequentialData(self.MAX_NUM_MSG) 552 553 # Client writes half of the queue capacity, and server reads it. 554 asserts.assertTrue( 555 self._unsync_client1.write(write_data, num_messages), 556 "Client should write successfully.") 557 asserts.assertTrue( 558 self._tests_msgq.requestReadFmqUnsync(num_messages), 559 "Server should read successfully.") 560 # Client writes the max queue capacity, causes a wrap around 561 asserts.assertTrue( 562 self._unsync_client1.write(write_data, self.MAX_NUM_MSG), 563 "Client should write successfully.") 564 # Server reads back data correctly 565 asserts.assertTrue( 566 self._tests_msgq.requestReadFmqUnsync(self.MAX_NUM_MSG), 567 "Server should read successfully.") 568 569 def testUnsyncQueueSmallInputMultipleReaderTest(self): 570 """This test operates on the unsynchronized queue. 571 Mirrors testcase: UnsynchronizedWriteClient, 572 SmallInputMultipleReaderTest. 573 Server writes once, and two readers read the data back separately. 574 """ 575 data_len = 16 576 # Server writes. 577 asserts.assertTrue( 578 self._tests_msgq.requestWriteFmqUnsync(data_len), 579 "Server should write successfully.") 580 write_data = generateSequentialData(data_len) 581 582 # Client 1 reads back data correctly. 583 read_data1 = [] 584 asserts.assertTrue( 585 self._unsync_client1.read(read_data1, data_len), 586 "Client 1 should read successfully.") 587 asserts.assertEqual(write_data, read_data1) 588 # Client 2 reads back data correctly. 589 read_data2 = [] 590 asserts.assertTrue( 591 self._unsync_client2.read(read_data2, data_len), 592 "Client 2 should read successfully.") 593 asserts.assertEqual(write_data, read_data2) 594 595 def testUnsyncQueueOverflowNotificationTest(self): 596 """This test operates on the unsynchronized queue. 597 Mirror testcase: UnsynchronizedWriteClient, OverflowNotificationTest. 598 For unsynchronized queue, multiple readers can recover from 599 a write overflow condition. 600 """ 601 # Server writes twice, overflows the queue. 602 asserts.assertTrue( 603 self._tests_msgq.requestWriteFmqUnsync(self.MAX_NUM_MSG), 604 "Server should write successfully.") 605 asserts.assertTrue( 606 self._tests_msgq.requestWriteFmqUnsync(self.MAX_NUM_MSG), 607 "Server should write successfully even if queue overflows.") 608 609 # Both clients fail to read. 610 read_data1 = [] 611 read_data2 = [] 612 asserts.assertFalse( 613 self._unsync_client1.read(read_data1, self.MAX_NUM_MSG), 614 "Client 1 should fail to read because queue overflows.") 615 asserts.assertFalse( 616 self._unsync_client2.read(read_data2, self.MAX_NUM_MSG), 617 "Client 2 should fail to read because queue overflows.") 618 619 # Server writes the data again. 620 asserts.assertTrue( 621 self._tests_msgq.requestWriteFmqUnsync(self.MAX_NUM_MSG), 622 "Server should write successfully.") 623 # Both clients should be able to read. 624 asserts.assertTrue( 625 self._unsync_client1.read(read_data1, self.MAX_NUM_MSG), 626 "Client 1 should read successfully.") 627 asserts.assertTrue( 628 self._unsync_client2.read(read_data2, self.MAX_NUM_MSG), 629 "Client 2 should read successfully.") 630 631 632def generateSequentialData(data_size): 633 """Util method to generate sequential data from 0 up to MAX_NUM_MSG. 634 We use this method because in ITestMsgQ hal server, it always assumes 635 writing and reading sequential data from 0 up to MAX_NUM_MSG. 636 637 Args: 638 MAX_NUM_MSG: int, length of the result list. 639 640 Returns: 641 int list, list of integers. 642 """ 643 return [i for i in range(data_size)] 644 645 646if __name__ == "__main__": 647 test_runner.main() 648