Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(433)

Side by Side Diff: device/usb/usb_device_handle_unittest.cc

Issue 2843613002: Fix crash when closing a device from a USB transfer timeout (Closed)
Patch Set: Address mcasas@ nits Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | device/usb/usb_device_handle_usbfs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "device/usb/usb_device_handle.h" 5 #include "device/usb/usb_device_handle.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 10
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
109 transferred_ = transferred; 109 transferred_ = transferred;
110 run_loop_.Quit(); 110 run_loop_.Quit();
111 } 111 }
112 112
113 const UsbDeviceHandle::TransferCallback callback_; 113 const UsbDeviceHandle::TransferCallback callback_;
114 base::RunLoop run_loop_; 114 base::RunLoop run_loop_;
115 UsbTransferStatus status_; 115 UsbTransferStatus status_;
116 size_t transferred_; 116 size_t transferred_;
117 }; 117 };
118 118
119 void ExpectTimeoutAndClose(scoped_refptr<UsbDeviceHandle> handle,
120 const base::Closure& quit_closure,
121 UsbTransferStatus status,
122 scoped_refptr<net::IOBuffer> buffer,
123 size_t transferred) {
124 EXPECT_EQ(UsbTransferStatus::TIMEOUT, status);
125 handle->Close();
126 quit_closure.Run();
127 }
128
119 TEST_F(UsbDeviceHandleTest, InterruptTransfer) { 129 TEST_F(UsbDeviceHandleTest, InterruptTransfer) {
120 if (!UsbTestGadget::IsTestEnabled()) { 130 if (!UsbTestGadget::IsTestEnabled()) {
121 return; 131 return;
122 } 132 }
123 133
124 std::unique_ptr<UsbTestGadget> gadget = 134 std::unique_ptr<UsbTestGadget> gadget =
125 UsbTestGadget::Claim(io_thread_->task_runner()); 135 UsbTestGadget::Claim(io_thread_->task_runner());
126 ASSERT_TRUE(gadget.get()); 136 ASSERT_TRUE(gadget.get());
127 ASSERT_TRUE(gadget->SetType(UsbTestGadget::ECHO)); 137 ASSERT_TRUE(gadget->SetType(UsbTestGadget::ECHO));
128 138
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 buffer->size(), 413 buffer->size(),
404 10, // 10 millisecond timeout 414 10, // 10 millisecond timeout
405 completion.callback()); 415 completion.callback());
406 416
407 completion.WaitForResult(); 417 completion.WaitForResult();
408 ASSERT_EQ(UsbTransferStatus::TIMEOUT, completion.status()); 418 ASSERT_EQ(UsbTransferStatus::TIMEOUT, completion.status());
409 419
410 handle->Close(); 420 handle->Close();
411 } 421 }
412 422
423 TEST_F(UsbDeviceHandleTest, CloseReentrancy) {
424 if (!UsbTestGadget::IsTestEnabled())
425 return;
426
427 std::unique_ptr<UsbTestGadget> gadget =
428 UsbTestGadget::Claim(io_thread_->task_runner());
429 ASSERT_TRUE(gadget.get());
430 ASSERT_TRUE(gadget->SetType(UsbTestGadget::ECHO));
431
432 TestOpenCallback open_device;
433 gadget->GetDevice()->Open(open_device.callback());
434 scoped_refptr<UsbDeviceHandle> handle = open_device.WaitForResult();
435 ASSERT_TRUE(handle.get());
436
437 TestResultCallback claim_interface;
438 handle->ClaimInterface(1, claim_interface.callback());
439 ASSERT_TRUE(claim_interface.WaitForResult());
440
441 base::RunLoop run_loop;
442 auto buffer = base::MakeShared<net::IOBufferWithSize>(512);
443 handle->GenericTransfer(
444 UsbTransferDirection::INBOUND, 0x82, buffer.get(), buffer->size(),
445 10, // 10 millisecond timeout
446 base::Bind(&ExpectTimeoutAndClose, handle, run_loop.QuitClosure()));
447 // Drop handle so that the completion callback holds the last reference.
448 handle = nullptr;
449 run_loop.Run();
450 }
451
413 } // namespace 452 } // namespace
414 453
415 } // namespace device 454 } // namespace device
OLDNEW
« no previous file with comments | « no previous file | device/usb/usb_device_handle_usbfs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698