1/* 2 * Copyright (c) 2023 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "usbfn_mtp_test.h" 17 18#include <cinttypes> 19#include <cstdio> 20#include <iostream> 21#include <sstream> 22#include <vector> 23#include <fcntl.h> 24 25#include "directory_ex.h" 26#include "file_ex.h" 27#include "hdf_log.h" 28#include "securec.h" 29#include "v1_0/iusb_interface.h" 30#include "v1_0/iusbfn_mtp_interface.h" 31#include "v1_0/usb_types.h" 32#include "v1_0/usbfn_mtp_types.h" 33 34#define HDF_LOG_TAG usbfn_mtp_ut 35 36using namespace testing::ext; 37using namespace OHOS; 38using namespace OHOS::HDI::Usb::V1_0; 39using namespace std; 40using namespace OHOS::HDI::Usb::Gadget::Mtp::V1_0; 41 42namespace { 43constexpr int32_t SLEEP_TIME = 3; 44constexpr int32_t MTP_EVENT_PACKET_MAX_BYTES = 28; 45constexpr int32_t MTP_EVENT_PACKET_VALID_LEN = 20; 46constexpr int32_t MTP_EVENT_PACKET_INVALID_LEN = 29; 47constexpr uint16_t CMD_CODE_GET_DEVICE_INFO = 0x1001; 48constexpr uint32_t TRANSACTION_ID_RANDOM = 0xF00D; 49/* mtp packet head defined as [struct UsbMtpDataHeader] in usbfn_mtp_impl.h */ 50constexpr uint32_t MTP_PACKET_HEADER_SIZE = 12; 51constexpr uint32_t BULK_OUT_ONCE_MAX_SIZE = 1024; 52constexpr uint32_t BULK_OUT_LESS_THEN_ONCE = 23; 53constexpr uint32_t BULK_OUT_MORE_THEN_ONCE = 1025; 54constexpr uint32_t BULK_IN_ONCE_MAX_SIZE = 1024; 55constexpr uint32_t BULK_IN_LESS_THEN_ONCE = 45; 56constexpr uint32_t BULK_IN_MORE_THEN_ONCE = 2023; 57constexpr uint32_t MTP_FILE_SIZE_ONE_REQ = 1024; 58constexpr uint32_t MTP_FILE_SIZE_REUSE_REQ = 12 * 1024; 59/* 0xFFFFFFFFLL is 4 * 1024 * 1024 * 1024 - 1 = 4GB - 1 */ 60constexpr int64_t MTP_MAX_FILE_SIZE = 0xFFFFFFFFLL; 61constexpr int64_t GEN_FILE_BUF_SIZE = 1024; 62constexpr int64_t GEN_FILE_LIMIT_512MB = 512 * 1024 * 1024; 63constexpr int32_t PRINT_VECTOR_MAX_LENGTH = 30; 64constexpr const char *WORKED_UT_PATH = "/data/local/tmp/"; 65constexpr const char *MTP_TEST_SEND_FILE = "/data/local/tmp/sampleFile.mtp"; 66constexpr const char *MTP_TEST_RECV_FILE = "/data/local/tmp/sampleFile.mtp"; 67 68sptr<IUsbfnMtpInterface> g_usbfnMtpInterface = nullptr; 69sptr<IUsbInterface> g_usbInterface = nullptr; 70int32_t g_currentFunc = USB_FUNCTION_NONE; 71int32_t g_fileTestCount = 0; 72 73struct UsbFnMtpFileSlice g_mfs = { 74 .offset = 0, 75 .length = 0, 76 .command = 0, 77 .transactionId = 0, 78}; 79 80void PrintVector(const std::string &msg, std::vector<uint8_t> &data, bool hexFormat) 81{ 82 size_t printLen = data.size(); 83 bool ignore = false; 84 if (printLen > static_cast<size_t>(PRINT_VECTOR_MAX_LENGTH)) { 85 printLen = static_cast<size_t>(PRINT_VECTOR_MAX_LENGTH); 86 ignore = true; 87 } 88 std::stringstream ss; 89 for (size_t i = 0; i < printLen; i++) { 90 if (hexFormat) { 91 ss << std::hex << "0x" << (0xFF & data.at(i)) << " "; 92 } else { 93 ss << data.at(i); 94 } 95 } 96 std::string output = msg + std::string("(") + std::to_string(printLen) + std::string("):") + ss.str(); 97 if (ignore) { 98 output += "......"; 99 } 100 HDF_LOGV("UsbfnMtpTest::PrintVector %{public}s", output.c_str()); 101} 102 103uint64_t GetFileSize(const std::string &pathName) 104{ 105 struct stat statbuf; 106 uint64_t ret = stat(pathName.c_str(), &statbuf); 107 if (ret != 0) { 108 return 0; 109 } 110 return static_cast<uint64_t>(statbuf.st_size); 111} 112 113bool WriteRandomDataToFile(const std::string &pathName, uint64_t fileSize) 114{ 115 int32_t random = open("/dev/urandom", O_RDONLY); 116 if (random < 0) { 117 HDF_LOGE("UsbfnMtpTest::WriteRandomDataToFile get random data failed"); 118 return false; 119 } 120 FILE *opFile = std::fopen(pathName.c_str(), "w"); 121 if (opFile == nullptr) { 122 HDF_LOGE("UsbfnMtpTest::WriteRandomDataToFile create file failed: %{public}s", pathName.c_str()); 123 return false; 124 } 125 char buffer[GEN_FILE_BUF_SIZE]; 126 int64_t count = static_cast<int64_t>(fileSize); 127 while (count > 0) { 128 (void)memset_s(buffer, sizeof(buffer), 0, sizeof(buffer)); 129 int64_t readSize = count > GEN_FILE_BUF_SIZE ? GEN_FILE_BUF_SIZE : count; 130 ssize_t readActual = read(random, static_cast<void *>(buffer), static_cast<size_t>(readSize)); 131 if (readActual != static_cast<ssize_t>(readSize)) { 132 HDF_LOGW("UsbfnMtpTest::WriteRandomDataToFile read random failed"); 133 break; 134 } 135 size_t writeActual = std::fwrite(static_cast<void *>(buffer), 1, static_cast<size_t>(readSize), opFile); 136 if (writeActual != static_cast<size_t>(readSize)) { 137 HDF_LOGW("UsbfnMtpTest::WriteRandomDataToFile write failed"); 138 break; 139 } 140 count -= readSize; 141 } 142 std::fflush(opFile); 143 std::fclose(opFile); 144 close(random); 145 HDF_LOGV("UsbfnMtpTest::WriteRandomDataToFile file %{public}s: %{public}" PRIu64 "/%{public}" PRIu64 "", 146 pathName.c_str(), GetFileSize(pathName), fileSize); 147 return count > 0 ? false : true; 148} 149 150bool GenerateFile(const std::string &pathName, int64_t fileSize) 151{ 152 if (GetFileSize(pathName) == static_cast<uint64_t>(fileSize)) { 153 HDF_LOGW("UsbfnMtpTest::GenerateFile file already exist"); 154 return true; 155 } 156 if (fileSize > GEN_FILE_LIMIT_512MB) { 157 int32_t ret = truncate(pathName.c_str(), static_cast<off_t>(fileSize)); 158 if (ret != 0) { 159 HDF_LOGE("UsbfnMtpTest::GenerateFile fail to truncate file to size: %{public}" PRId64 "", fileSize); 160 return false; 161 } 162 HDF_LOGV("UsbfnMtpTest::GenerateFile truncate %{public}s %{public}" PRId64 "", pathName.c_str(), fileSize); 163 return true; 164 } 165 return WriteRandomDataToFile(pathName, static_cast<uint64_t>(fileSize)); 166} 167 168int32_t SwitchErrCode(int32_t ret) 169{ 170 return ret == HDF_ERR_NOT_SUPPORT ? HDF_SUCCESS : ret; 171} 172 173void UsbfnMtpTest::SetUpTestCase(void) 174{ 175 // Selinux config this UT only works in directory WORKED_UT_PATH for open/read/write file for case send/recvfile. 176 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 177 std::cout << "===>please connect to PC use USB 3.0 interface, press enter to continue set function to mtp" 178 << std::endl; 179 int32_t c; 180 while ((c = getchar()) != '\n' && c != EOF) {} 181 182 g_usbInterface = IUsbInterface::Get(); 183 ASSERT_TRUE(g_usbInterface != nullptr); 184 auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE); 185 sleep(SLEEP_TIME); 186 ret = SwitchErrCode(ret); 187 ASSERT_EQ(0, ret); 188 ret = g_usbInterface->GetCurrentFunctions(g_currentFunc); 189 ASSERT_EQ(0, ret); 190 std::cout << "===>current function=" << g_currentFunc << ", set function to mtp, please wait" << std::endl; 191 ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_MTP); 192 ASSERT_EQ(0, ret); 193 194 g_usbfnMtpInterface = IUsbfnMtpInterface::Get(); 195 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 196 ret = g_usbfnMtpInterface->Start(); 197 ASSERT_EQ(0, ret); 198} 199 200void UsbfnMtpTest::TearDownTestCase(void) 201{ 202 HDF_LOGV("UsbfnMtpTest::TearDownTestCase"); 203 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 204 auto ret = g_usbfnMtpInterface->Stop(); 205 ASSERT_EQ(0, ret); 206 ASSERT_TRUE(g_usbInterface != nullptr); 207 ret = g_usbInterface->SetCurrentFunctions(g_currentFunc); 208 ASSERT_EQ(0, ret); 209 if (g_fileTestCount == 0) { 210 return; 211 } 212 /* 1 means single test, run with '--gtest_filter=' option */ 213 if (g_fileTestCount == 1) { 214 std::cout << "===>please delete temporary test file if needed: sendfile=" << MTP_TEST_SEND_FILE 215 << " recvfile=" << MTP_TEST_RECV_FILE << std::endl; 216 return; 217 } 218 if (FileExists(std::string(MTP_TEST_SEND_FILE))) { 219 if (remove(MTP_TEST_SEND_FILE) != 0) { 220 std::cout << "[-] remove send file failed: " << MTP_TEST_SEND_FILE << std::endl; 221 } 222 } 223 if (FileExists(std::string(MTP_TEST_RECV_FILE))) { 224 if (remove(MTP_TEST_RECV_FILE) != 0) { 225 std::cout << "[-] remove recv file failed: " << MTP_TEST_RECV_FILE << std::endl; 226 } 227 } 228} 229 230void UsbfnMtpTest::SetUp(void) {} 231 232void UsbfnMtpTest::TearDown(void) {} 233 234/** 235 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_0100 236 * @tc.desc: Test functions to Read 237 * @tc.desc: int32_t Read(std::vector<uint8_t>& data); 238 * @tc.desc: Positive test: parameters correctly, read length less then one packet size 239 * @tc.type: FUNC 240 */ 241HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_0100, Function | MediumTest | Level1) 242{ 243 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 244 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_0100 Case Start"); 245 std::vector<uint8_t> devData; 246 247 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_0100===>use libusb in PC launch bulk-out transfer(size=" 248 << BULK_OUT_LESS_THEN_ONCE << "), press enter to continue" << std::endl; 249 int32_t c; 250 while ((c = getchar()) != '\n' && c != EOF) {} 251 252 int32_t ret = g_usbfnMtpInterface->Read(devData); 253 ASSERT_EQ(ret, 0); 254 ASSERT_EQ(devData.size(), static_cast<size_t>(BULK_OUT_LESS_THEN_ONCE)); 255} 256 257/** 258 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_0200 259 * @tc.desc: Test functions to Read 260 * @tc.desc: int32_t Read(std::vector<uint8_t>& data); 261 * @tc.desc: Positive test: parameters correctly, read length exactly one packet size 262 * @tc.type: FUNC 263 */ 264HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_0200, Function | MediumTest | Level1) 265{ 266 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 267 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_0200 Case Start"); 268 std::vector<uint8_t> devData; 269 270 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_0200===>use libusb in PC launch bulk-out transfer(size=" 271 << BULK_OUT_ONCE_MAX_SIZE << "), press enter to continue" << std::endl; 272 int32_t c; 273 while ((c = getchar()) != '\n' && c != EOF) {} 274 275 int32_t ret = g_usbfnMtpInterface->Read(devData); 276 ASSERT_EQ(ret, 0); 277 ASSERT_EQ(devData.size(), static_cast<size_t>(BULK_OUT_ONCE_MAX_SIZE)); 278} 279 280/** 281 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_0300 282 * @tc.desc: Test functions to Read 283 * @tc.desc: int32_t Read(std::vector<uint8_t>& data); 284 * @tc.desc: Positive test: parameters correctly, read length more then one packet size, please read again 285 * @tc.type: FUNC 286 */ 287HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_0300, Function | MediumTest | Level1) 288{ 289 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 290 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_0300 Case Start"); 291 std::vector<uint8_t> devData; 292 293 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_0300===>use libusb in PC launch bulk-out transfer(size=" 294 << BULK_OUT_MORE_THEN_ONCE << "), press enter to continue" << std::endl; 295 int32_t c; 296 while ((c = getchar()) != '\n' && c != EOF) {} 297 298 int32_t ret = g_usbfnMtpInterface->Read(devData); 299 ASSERT_EQ(ret, 0); 300 ASSERT_EQ(devData.size(), static_cast<size_t>(BULK_OUT_ONCE_MAX_SIZE)); 301 devData.clear(); 302 ret = g_usbfnMtpInterface->Read(devData); 303 ASSERT_EQ(ret, 0); 304 ASSERT_EQ(devData.size(), static_cast<size_t>(BULK_OUT_MORE_THEN_ONCE - BULK_OUT_ONCE_MAX_SIZE)); 305} 306 307/** 308 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_0400 309 * @tc.desc: Test functions to Read 310 * @tc.desc: int32_t Read(std::vector<uint8_t>& data) 311 * @tc.desc: Positive test: parameters correctly, no specific read size 312 * @tc.type: FUNC 313 */ 314HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_0400, Function | MediumTest | Level1) 315{ 316 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 317 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_0400 Case Start"); 318 std::vector<uint8_t> devData; 319 320 std::cout 321 << "SUB_USB_DeviceManager_HDI_MTPPTP_0400===>use libusb in PC launch bulk-out transfer(size in [0, 1024]), " 322 << "press enter to continue" << std::endl; 323 int32_t c; 324 while ((c = getchar()) != '\n' && c != EOF) {} 325 326 auto ret = g_usbfnMtpInterface->Read(devData); 327 ASSERT_EQ(ret, 0); 328 ASSERT_GE(devData.size(), 0); 329} 330 331/** 332 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_0500 333 * @tc.desc: Test functions to Read 334 * @tc.desc: int32_t Read(std::vector<uint8_t>& data) 335 * @tc.desc: Positive test: parameters correctly, check read content 336 * @tc.type: FUNC 337 */ 338HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_0500, Function | MediumTest | Level1) 339{ 340 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 341 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_0500 Case Start"); 342 std::vector<uint8_t> devData; 343 // hex value of string "read005" 344 std::vector<uint8_t> expectData = {0x72, 0x65, 0x61, 0x64, 0x30, 0x30, 0x35}; 345 346 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_0500===>" 347 << "use libusb in PC launch bulk-out transfer(string=read005), " 348 << "press enter to continue" << std::endl; 349 int32_t c; 350 while ((c = getchar()) != '\n' && c != EOF) {} 351 352 auto ret = g_usbfnMtpInterface->Read(devData); 353 ASSERT_EQ(ret, 0); 354 ASSERT_EQ(devData, expectData); 355 PrintVector("read005", devData, true); 356} 357 358/** 359 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_0600 360 * @tc.desc: Test functions to Write 361 * @tc.desc: int32_t Write(const std::vector<uint8_t>& data) 362 * @tc.desc: Positive test: parameters correctly 363 * @tc.type: FUNC 364 */ 365HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_0600, Function | MediumTest | Level1) 366{ 367 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 368 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_0600 Case Start"); 369 uint32_t length = BULK_IN_LESS_THEN_ONCE; 370 std::vector<uint8_t> devData; 371 devData.assign(length, 'w'); 372 373 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_0600===>use libusb in PC launch bulk-in transfer(expect=" << length 374 << "), press enter to continue" << std::endl; 375 int32_t c; 376 while ((c = getchar()) != '\n' && c != EOF) {} 377 378 auto ret = g_usbfnMtpInterface->Write(devData); 379 ASSERT_EQ(ret, 0); 380} 381 382/** 383 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_0700 384 * @tc.desc: Test functions to Write 385 * @tc.desc: int32_t Write(const std::vector<uint8_t>& data) 386 * @tc.desc: Positive test: parameters correctly 387 * @tc.type: FUNC 388 */ 389HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_0700, Function | MediumTest | Level1) 390{ 391 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 392 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_0700 Case Start"); 393 uint32_t length = BULK_IN_ONCE_MAX_SIZE; 394 std::vector<uint8_t> devData; 395 devData.assign(length, 'w'); 396 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_0700===>use libusb in PC launch bulk-in transfer(expect=" << length 397 << "), press enter to continue" << std::endl; 398 int32_t c; 399 while ((c = getchar()) != '\n' && c != EOF) {} 400 401 auto ret = g_usbfnMtpInterface->Write(devData); 402 ASSERT_EQ(ret, 0); 403} 404 405/** 406 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_0800 407 * @tc.desc: Test functions to Write 408 * @tc.desc: int32_t Write(const std::vector<uint8_t>& data) 409 * @tc.desc: Positive test: parameters correctly 410 * @tc.type: FUNC 411 */ 412HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_0800, Function | MediumTest | Level1) 413{ 414 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 415 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_0800 Case Start"); 416 uint32_t length = BULK_IN_MORE_THEN_ONCE; 417 std::vector<uint8_t> devData; 418 devData.assign(length, 'w'); 419 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_0800===>use libusb in PC launch bulk-in transfer(expect=" << length 420 << "), press enter to continue" << std::endl; 421 int32_t c; 422 while ((c = getchar()) != '\n' && c != EOF) {} 423 424 auto ret = g_usbfnMtpInterface->Write(devData); 425 ASSERT_EQ(ret, 0); 426} 427 428/** 429 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_0900 430 * @tc.desc: Test functions to Write 431 * @tc.desc: int32_t Write(const std::vector<uint8_t>& data) 432 * @tc.desc: Positive test: parameters correctly, write empty data 433 * @tc.type: FUNC 434 */ 435HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_0900, Function | MediumTest | Level1) 436{ 437 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 438 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_0900 Case Start"); 439 std::vector<uint8_t> devData; 440 auto ret = g_usbfnMtpInterface->Write(devData); 441 ASSERT_EQ(ret, 0); 442} 443 444/** 445 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1000 446 * @tc.desc: Test functions to Write 447 * @tc.desc: int32_t Write(const std::vector<uint8_t>& data) 448 * @tc.desc: Positive test: parameters correctly, write specific data 449 * @tc.type: FUNC 450 */ 451HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1000, Function | MediumTest | Level1) 452{ 453 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 454 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1000 Case Start"); 455 // hex value of string "write005" 456 std::vector<uint8_t> devData = {0x77, 0x72, 0x69, 0x74, 0x65, 0x30, 0x30, 0x35}; 457 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1000===>" 458 << "use libusb in PC launch bulk-in transfer(expect string=write005), " 459 << "press enter to continue" << std::endl; 460 int32_t c; 461 while ((c = getchar()) != '\n' && c != EOF) {} 462 463 auto ret = g_usbfnMtpInterface->Write(devData); 464 ASSERT_EQ(ret, 0); 465 PrintVector("write005", devData, true); 466} 467 468/** 469 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1100 470 * @tc.desc: Test functions to SendEvent 471 * @tc.desc: int32_t SendEvent(const std::vector<uint8_t> &eventData); 472 * @tc.desc: Positive test: parameters correctly, valid length 473 * @tc.type: FUNC 474 */ 475HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1100, Function | MediumTest | Level1) 476{ 477 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 478 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1100 Case Start"); 479 std::vector<uint8_t> devData; 480 devData.assign(MTP_EVENT_PACKET_VALID_LEN, 'e'); 481 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1100===>use libusb in PC launch intr-in transfer(expect=" 482 << devData.size() << "), press enter to continue" << std::endl; 483 int32_t c; 484 while ((c = getchar()) != '\n' && c != EOF) {} 485 486 auto ret = g_usbfnMtpInterface->SendEvent(devData); 487 ASSERT_EQ(0, ret); 488} 489 490/** 491 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1200 492 * @tc.desc: Test functions to SendEvent 493 * @tc.desc: int32_t SendEvent(const std::vector<uint8_t> &eventData); 494 * @tc.desc: Positive test: parameters correctly, max length 495 * @tc.type: FUNC 496 */ 497HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1200, Function | MediumTest | Level1) 498{ 499 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 500 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1200 Case Start"); 501 std::vector<uint8_t> devData; 502 devData.assign(MTP_EVENT_PACKET_MAX_BYTES, 'e'); 503 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1200===>use libusb in PC launch intr-in transfer(expect=" 504 << devData.size() << "), press enter to continue" << std::endl; 505 int32_t c; 506 while ((c = getchar()) != '\n' && c != EOF) {} 507 auto ret = g_usbfnMtpInterface->SendEvent(devData); 508 ASSERT_EQ(0, ret); 509} 510 511/** 512 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1300 513 * @tc.desc: Test functions to SendEvent 514 * @tc.desc: int32_t SendEvent(const std::vector<uint8_t> &eventData); 515 * @tc.desc: Negative test: parameters exception, size overflow 516 * @tc.type: FUNC 517 */ 518HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1300, Function | MediumTest | Level1) 519{ 520 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 521 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1300 Case Start"); 522 std::vector<uint8_t> devData; 523 devData.assign(MTP_EVENT_PACKET_INVALID_LEN, 'e'); 524 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1300===>use libusb in PC launch intr-in transfer(expect=no data, " 525 << "or error), press enter to continue" << std::endl; 526 int32_t c; 527 while ((c = getchar()) != '\n' && c != EOF) {} 528 529 auto ret = g_usbfnMtpInterface->SendEvent(devData); 530 ASSERT_NE(0, ret); 531 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1300===>make sure transfer timeout in PC, then start next test " 532 << std::endl; 533} 534 535/** 536 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1400 537 * @tc.desc: Test functions to SendEvent 538 * @tc.desc: int32_t SendEvent(const std::vector<uint8_t> &eventData); 539 * @tc.desc: Positive test: parameters correctly, max length, check content 540 * @tc.type: FUNC 541 */ 542HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1400, Function | MediumTest | Level1) 543{ 544 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 545 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1400 Case Start"); 546 // hex value of string "event004" 547 std::vector<uint8_t> devData = {0x65, 0x76, 0x65, 0x6E, 0x74, 0x30, 0x30, 0x34}; 548 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1400===>" 549 << "use libusb in PC launch intr-in transfer(expect string=event004), " 550 << "press enter to continue" << std::endl; 551 int32_t c; 552 while ((c = getchar()) != '\n' && c != EOF) {} 553 auto ret = g_usbfnMtpInterface->SendEvent(devData); 554 ASSERT_EQ(0, ret); 555 PrintVector("event004", devData, true); 556} 557 558/** 559 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1500 560 * @tc.desc: Test functions to ReceiveFile 561 * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs); 562 * @tc.desc: Positive test: parameters correctly, one packet enough 563 * @tc.type: FUNC 564 */ 565HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1500, Function | MediumTest | Level1) 566{ 567 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 568 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 569 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1500 Case Start"); 570 g_fileTestCount++; 571 struct UsbFnMtpFileSlice mfs = g_mfs; 572 mfs.length = BULK_OUT_LESS_THEN_ONCE; 573 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1500===>use libusb in PC launch bulk-out transfer(size = " 574 << mfs.length << "), press enter to continue" << std::endl; 575 int32_t c; 576 while ((c = getchar()) != '\n' && c != EOF) {} 577 578 std::string filePathName = MTP_TEST_RECV_FILE; 579 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777); 580 ASSERT_GT(mfs.fd, 0); 581 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs); 582 close(mfs.fd); 583 ASSERT_EQ(ret, 0); 584 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length)); 585} 586 587/** 588 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1600 589 * @tc.desc: Test functions to ReceiveFile 590 * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs); 591 * @tc.desc: Positive test: parameters correctly, zero length 592 * @tc.type: FUNC 593 */ 594HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1600, Function | MediumTest | Level1) 595{ 596 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 597 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 598 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1600 Case Start"); 599 g_fileTestCount++; 600 struct UsbFnMtpFileSlice mfs = g_mfs; 601 mfs.length = 0; 602 std::string filePathName = MTP_TEST_RECV_FILE; 603 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777); 604 ASSERT_GT(mfs.fd, 0); 605 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs); 606 close(mfs.fd); 607 ASSERT_EQ(ret, 0); 608 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length)); 609} 610 611/** 612 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1700 613 * @tc.desc: Test functions to ReceiveFile 614 * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs); 615 * @tc.desc: Positive test: parameters correctly, one normal packet + short packet 616 * @tc.type: FUNC 617 */ 618HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1700, Function | MediumTest | Level1) 619{ 620 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 621 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 622 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1700 Case Start"); 623 g_fileTestCount++; 624 struct UsbFnMtpFileSlice mfs = g_mfs; 625 mfs.length = BULK_OUT_MORE_THEN_ONCE; 626 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1700===>use libusb in PC launch bulk-out transfer(size = " 627 << mfs.length << "), press enter to continue" << std::endl; 628 int32_t c; 629 while ((c = getchar()) != '\n' && c != EOF) {} 630 631 std::string filePathName = MTP_TEST_RECV_FILE; 632 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777); 633 ASSERT_GT(mfs.fd, 0); 634 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs); 635 close(mfs.fd); 636 ASSERT_EQ(ret, 0); 637 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length)); 638} 639 640/** 641 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1800 642 * @tc.desc: Test functions to ReceiveFile 643 * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs); 644 * @tc.desc: Positive test: mfs.length set to max, 12 packet + ZLP 645 * @tc.type: FUNC 646 */ 647HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1800, Function | MediumTest | Level1) 648{ 649 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 650 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 651 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1800 Case Start"); 652 g_fileTestCount++; 653 struct UsbFnMtpFileSlice mfs = g_mfs; 654 mfs.length = MTP_FILE_SIZE_REUSE_REQ; 655 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1800===>use libusb in PC launch bulk-out transfer(size = " 656 << mfs.length << "), press enter to continue" << std::endl; 657 int32_t c; 658 while ((c = getchar()) != '\n' && c != EOF) {} 659 660 std::string filePathName = MTP_TEST_RECV_FILE; 661 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777); 662 ASSERT_GT(mfs.fd, 0); 663 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs); 664 close(mfs.fd); 665 ASSERT_EQ(ret, 0); 666 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length)); 667} 668 669/** 670 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_1900 671 * @tc.desc: Test functions to ReceiveFile 672 * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs); 673 * @tc.desc: Positive test: parameters correctly, command and transactionId ignored 674 * @tc.type: FUNC 675 */ 676HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_1900, Function | MediumTest | Level1) 677{ 678 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 679 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 680 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_1900 Case Start"); 681 g_fileTestCount++; 682 struct UsbFnMtpFileSlice mfs = g_mfs; 683 mfs.length = BULK_OUT_LESS_THEN_ONCE; 684 mfs.command = CMD_CODE_GET_DEVICE_INFO; 685 mfs.transactionId = TRANSACTION_ID_RANDOM; 686 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_1900===>use libusb in PC launch bulk-out transfer(size = " 687 << mfs.length << "), press enter to continue" << std::endl; 688 int32_t c; 689 while ((c = getchar()) != '\n' && c != EOF) {} 690 691 std::string filePathName = MTP_TEST_RECV_FILE; 692 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777); 693 ASSERT_GT(mfs.fd, 0); 694 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs); 695 close(mfs.fd); 696 ASSERT_EQ(ret, 0); 697 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length)); 698} 699 700/** 701 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2000 702 * @tc.desc: Test functions to ReceiveFile 703 * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs); 704 * @tc.desc: Positive test: mfs.length set to max, recv actual file size depend on xfer count 705 * @tc.type: FUNC 706 */ 707HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2000, Function | MediumTest | Level1) 708{ 709 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 710 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 711 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2000 Case Start"); 712 g_fileTestCount++; 713 struct UsbFnMtpFileSlice mfs = g_mfs; 714 mfs.length = MTP_MAX_FILE_SIZE; 715 std::cout 716 << "SUB_USB_DeviceManager_HDI_MTPPTP_2000===>use libusb in PC launch bulk-out transfer(size = any), " 717 << "press enter to continue" << std::endl; 718 int32_t c; 719 while ((c = getchar()) != '\n' && c != EOF) {} 720 721 std::string filePathName = MTP_TEST_RECV_FILE; 722 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777); 723 ASSERT_GT(mfs.fd, 0); 724 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs); 725 close(mfs.fd); 726 ASSERT_EQ(ret, 0); 727 ASSERT_GE(GetFileSize(filePathName), 0); 728} 729 730/** 731 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2100 732 * @tc.desc: Test functions to ReceiveFile 733 * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs); 734 * @tc.desc: Positive test: mfs.length set to max - 1: 4GB - 2 735 * @tc.type: FUNC 736 */ 737HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2100, Function | MediumTest | Level1) 738{ 739 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 740 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 741 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2100 Case Start"); 742 g_fileTestCount++; 743 struct UsbFnMtpFileSlice mfs = g_mfs; 744 mfs.length = MTP_MAX_FILE_SIZE - 1; 745 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_2100===>use libusb in PC launch bulk-out transfer(size = " 746 << mfs.length << "), press enter to continue" << std::endl; 747 int32_t c; 748 while ((c = getchar()) != '\n' && c != EOF) {} 749 750 std::string filePathName = MTP_TEST_RECV_FILE; 751 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777); 752 ASSERT_GT(mfs.fd, 0); 753 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs); 754 close(mfs.fd); 755 ASSERT_EQ(ret, 0); 756 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length)); 757} 758 759/** 760 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2200 761 * @tc.desc: Test functions to ReceiveFile 762 * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs); 763 * @tc.desc: Positive test: mfs.length set to max + 1: 4GB 764 * @tc.type: FUNC 765 */ 766HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2200, Function | MediumTest | Level1) 767{ 768 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 769 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 770 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2200 Case Start"); 771 g_fileTestCount++; 772 struct UsbFnMtpFileSlice mfs = g_mfs; 773 mfs.length = MTP_MAX_FILE_SIZE + 1; 774 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_2200===>use libusb in PC launch bulk-out transfer(size = " 775 << mfs.length << "), press enter to continue" << std::endl; 776 int32_t c; 777 while ((c = getchar()) != '\n' && c != EOF) {} 778 779 std::string filePathName = MTP_TEST_RECV_FILE; 780 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777); 781 ASSERT_GT(mfs.fd, 0); 782 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs); 783 close(mfs.fd); 784 ASSERT_EQ(ret, 0); 785 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length)); 786} 787 788/** 789 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2300 790 * @tc.desc: Test functions to ReceiveFile 791 * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs); 792 * @tc.desc: Positive test: mfs.length set to max + 2: 4GB + 1 793 * @tc.type: FUNC 794 */ 795HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2300, Function | MediumTest | Level1) 796{ 797 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 798 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 799 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2300 Case Start"); 800 g_fileTestCount++; 801 struct UsbFnMtpFileSlice mfs = g_mfs; 802 mfs.length = MTP_MAX_FILE_SIZE + 2; 803 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_2300===>use libusb in PC launch bulk-out transfer(size = " 804 << mfs.length << "), press enter to continue" << std::endl; 805 int32_t c; 806 while ((c = getchar()) != '\n' && c != EOF) {} 807 808 std::string filePathName = MTP_TEST_RECV_FILE; 809 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777); 810 ASSERT_GT(mfs.fd, 0); 811 auto ret = g_usbfnMtpInterface->ReceiveFile(mfs); 812 close(mfs.fd); 813 ASSERT_EQ(ret, 0); 814 ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length)); 815} 816 817/** 818 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2400 819 * @tc.desc: Test functions to SendFile 820 * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs); 821 * @tc.desc: Positive test: parameters correctly, length in one packet 822 * @tc.type: FUNC 823 */ 824HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2400, Function | MediumTest | Level1) 825{ 826 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 827 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 828 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2400 Case Start"); 829 g_fileTestCount++; 830 struct UsbFnMtpFileSlice mfs = g_mfs; 831 mfs.length = BULK_IN_LESS_THEN_ONCE; 832 std::string filePathName = MTP_TEST_SEND_FILE; 833 EXPECT_TRUE(GenerateFile(filePathName, mfs.length)); 834 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_2400===>" 835 << "use libusb in PC launch bulk-in transfer(expect " << mfs.length 836 << "), press enter to continue" << std::endl; 837 int32_t c; 838 while ((c = getchar()) != '\n' && c != EOF) {} 839 840 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY); 841 ASSERT_GT(mfs.fd, 0); 842 auto ret = g_usbfnMtpInterface->SendFile(mfs); 843 close(mfs.fd); 844 ASSERT_EQ(ret, 0); 845} 846 847/** 848 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2500 849 * @tc.desc: Test functions to SendFile 850 * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs); 851 * @tc.desc: Positive test: parameters correctly, send header + data in one packet 852 * @tc.type: FUNC 853 */ 854HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2500, Function | MediumTest | Level1) 855{ 856 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 857 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 858 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2500 Case Start"); 859 g_fileTestCount++; 860 struct UsbFnMtpFileSlice mfs = g_mfs; 861 mfs.length = BULK_IN_LESS_THEN_ONCE; 862 mfs.command = CMD_CODE_GET_DEVICE_INFO; 863 std::string filePathName = MTP_TEST_SEND_FILE; 864 EXPECT_TRUE(GenerateFile(filePathName, mfs.length)); 865 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_2500===>use libusb in PC launch bulk-in transfer(expect " 866 << mfs.length + MTP_PACKET_HEADER_SIZE << "), press enter to continue" << std::endl; 867 int32_t c; 868 while ((c = getchar()) != '\n' && c != EOF) {} 869 870 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY); 871 ASSERT_GT(mfs.fd, 0); 872 auto ret = g_usbfnMtpInterface->SendFile(mfs); 873 close(mfs.fd); 874 ASSERT_EQ(0, ret); 875} 876 877/** 878 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2600 879 * @tc.desc: Test functions to SendFile 880 * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs); 881 * @tc.desc: Positive test: parameters correctly, zero length 882 * @tc.type: FUNC 883 */ 884HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2600, Function | MediumTest | Level1) 885{ 886 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 887 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 888 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2600 Case Start"); 889 g_fileTestCount++; 890 struct UsbFnMtpFileSlice mfs = g_mfs; 891 mfs.length = 0; 892 std::string filePathName = MTP_TEST_SEND_FILE; 893 EXPECT_TRUE(GenerateFile(filePathName, mfs.length)); 894 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY); 895 ASSERT_GT(mfs.fd, 0); 896 auto ret = g_usbfnMtpInterface->SendFile(mfs); 897 close(mfs.fd); 898 ASSERT_EQ(0, ret); 899} 900 901/** 902 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2700 903 * @tc.desc: Test functions to SendFile 904 * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs); 905 * @tc.desc: Positive test: parameters correctly, send header + data in two packet: normal + short 906 * @tc.type: FUNC 907 */ 908HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2700, Function | MediumTest | Level1) 909{ 910 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 911 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 912 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2700 Case Start"); 913 g_fileTestCount++; 914 struct UsbFnMtpFileSlice mfs = g_mfs; 915 mfs.length = MTP_FILE_SIZE_ONE_REQ; 916 mfs.command = CMD_CODE_GET_DEVICE_INFO; 917 std::string filePathName = MTP_TEST_SEND_FILE; 918 EXPECT_TRUE(GenerateFile(filePathName, mfs.length)); 919 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_2700===>use libusb in PC launch bulk-in transfer(expect " 920 << mfs.length + MTP_PACKET_HEADER_SIZE << "), press enter to continue" << std::endl; 921 int32_t c; 922 while ((c = getchar()) != '\n' && c != EOF) {} 923 924 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY); 925 ASSERT_GT(mfs.fd, 0); 926 auto ret = g_usbfnMtpInterface->SendFile(mfs); 927 close(mfs.fd); 928 ASSERT_EQ(0, ret); 929} 930 931/** 932 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2800 933 * @tc.desc: Test functions to SendFile 934 * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs); 935 * @tc.desc: Positive test: parameters correctly, mfs.length set to max 936 * @tc.type: FUNC 937 */ 938HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2800, Function | MediumTest | Level1) 939{ 940 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 941 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 942 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2800 Case Start"); 943 g_fileTestCount++; 944 struct UsbFnMtpFileSlice mfs = g_mfs; 945 mfs.length = MTP_FILE_SIZE_REUSE_REQ; 946 std::string filePathName = MTP_TEST_SEND_FILE; 947 EXPECT_TRUE(GenerateFile(filePathName, mfs.length)); 948 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_2800===>use libusb in PC launch bulk-in transfer(speed, expect " 949 << mfs.length << "), press enter to continue" << std::endl; 950 int32_t c; 951 while ((c = getchar()) != '\n' && c != EOF) {} 952 953 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY); 954 ASSERT_GT(mfs.fd, 0); 955 auto ret = g_usbfnMtpInterface->SendFile(mfs); 956 close(mfs.fd); 957 ASSERT_EQ(0, ret); 958} 959 960/** 961 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_2900 962 * @tc.desc: Test functions to SendFile 963 * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs); 964 * @tc.desc: Positive test: parameters correctly, mfs.length set to max: 4GB - 1 965 * @tc.type: FUNC 966 */ 967HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_2900, Function | MediumTest | Level1) 968{ 969 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 970 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 971 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_2900 Case Start"); 972 g_fileTestCount++; 973 struct UsbFnMtpFileSlice mfs = g_mfs; 974 mfs.length = MTP_MAX_FILE_SIZE; 975 std::string filePathName = MTP_TEST_SEND_FILE; 976 EXPECT_TRUE(GenerateFile(filePathName, mfs.length)); 977 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_2900===>use libusb in PC launch bulk-in transfer(speed, expect " 978 << mfs.length << "), press enter to continue" << std::endl; 979 int32_t c; 980 while ((c = getchar()) != '\n' && c != EOF) {} 981 982 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY); 983 ASSERT_GT(mfs.fd, 0); 984 auto ret = g_usbfnMtpInterface->SendFile(mfs); 985 close(mfs.fd); 986 ASSERT_EQ(0, ret); 987} 988 989/** 990 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_3000 991 * @tc.desc: Test functions to SendFile 992 * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs); 993 * @tc.desc: Positive test: parameters correctly, mfs.length set to max + 1: 4GB 994 * @tc.type: FUNC 995 */ 996HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_3000, Function | MediumTest | Level1) 997{ 998 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 999 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 1000 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_3000 Case Start"); 1001 g_fileTestCount++; 1002 struct UsbFnMtpFileSlice mfs = g_mfs; 1003 mfs.length = MTP_MAX_FILE_SIZE + 1; 1004 std::string filePathName = MTP_TEST_SEND_FILE; 1005 EXPECT_TRUE(GenerateFile(filePathName, mfs.length)); 1006 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_3000===>use libusb in PC launch bulk-in transfer(speed, expect " 1007 << mfs.length << "), press enter to continue" << std::endl; 1008 int32_t c; 1009 while ((c = getchar()) != '\n' && c != EOF) {} 1010 1011 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY); 1012 ASSERT_GT(mfs.fd, 0); 1013 auto ret = g_usbfnMtpInterface->SendFile(mfs); 1014 close(mfs.fd); 1015 ASSERT_EQ(0, ret); 1016} 1017 1018/** 1019 * @tc.name: SUB_USB_DeviceManager_HDI_MTPPTP_3100 1020 * @tc.desc: Test functions to SendFile 1021 * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs); 1022 * @tc.desc: Positive test: parameters correctly, mfs.length set to max + 1: 4GB + 1 1023 * @tc.type: FUNC 1024 */ 1025HWTEST_F(UsbfnMtpTest, SUB_USB_DeviceManager_HDI_MTPPTP_3100, Function | MediumTest | Level1) 1026{ 1027 ASSERT_TRUE(g_usbfnMtpInterface != nullptr); 1028 ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH)); 1029 HDF_LOGI("UsbfnMtpTest::SUB_USB_DeviceManager_HDI_MTPPTP_3100 Case Start"); 1030 g_fileTestCount++; 1031 struct UsbFnMtpFileSlice mfs = g_mfs; 1032 mfs.length = MTP_MAX_FILE_SIZE + 2; 1033 std::string filePathName = MTP_TEST_SEND_FILE; 1034 EXPECT_TRUE(GenerateFile(filePathName, mfs.length)); 1035 std::cout << "SUB_USB_DeviceManager_HDI_MTPPTP_3100===>use libusb in PC launch bulk-in transfer(speed, expect " 1036 << mfs.length << "), press enter to continue" << std::endl; 1037 int32_t c; 1038 while ((c = getchar()) != '\n' && c != EOF) {} 1039 1040 mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY); 1041 ASSERT_GT(mfs.fd, 0); 1042 auto ret = g_usbfnMtpInterface->SendFile(mfs); 1043 close(mfs.fd); 1044 ASSERT_EQ(0, ret); 1045} 1046 1047} // namespace 1048