• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
36 using namespace testing::ext;
37 using namespace OHOS;
38 using namespace OHOS::HDI::Usb::V1_0;
39 using namespace std;
40 using namespace OHOS::HDI::Usb::Gadget::Mtp::V1_0;
41 
42 namespace {
43 constexpr int32_t SLEEP_TIME = 3;
44 constexpr int32_t MTP_EVENT_PACKET_MAX_BYTES = 28;
45 constexpr int32_t MTP_EVENT_PACKET_VALID_LEN = 20;
46 constexpr int32_t MTP_EVENT_PACKET_INVALID_LEN = 29;
47 constexpr uint16_t CMD_CODE_GET_DEVICE_INFO = 0x1001;
48 constexpr uint32_t TRANSACTION_ID_RANDOM = 0xF00D;
49 /* mtp packet head defined as [struct UsbMtpDataHeader] in usbfn_mtp_impl.h  */
50 constexpr uint32_t MTP_PACKET_HEADER_SIZE = 12;
51 constexpr uint32_t BULK_OUT_ONCE_MAX_SIZE = 1024;
52 constexpr uint32_t BULK_OUT_LESS_THEN_ONCE = 23;
53 constexpr uint32_t BULK_OUT_MORE_THEN_ONCE = 1025;
54 constexpr uint32_t BULK_IN_ONCE_MAX_SIZE = 1024;
55 constexpr uint32_t BULK_IN_LESS_THEN_ONCE = 45;
56 constexpr uint32_t BULK_IN_MORE_THEN_ONCE = 2023;
57 constexpr uint32_t MTP_FILE_SIZE_ONE_REQ = 1024;
58 constexpr uint32_t MTP_FILE_SIZE_REUSE_REQ = 12 * 1024;
59 /* 0xFFFFFFFFLL is 4 * 1024 * 1024 * 1024 - 1 = 4GB - 1 */
60 constexpr int64_t MTP_MAX_FILE_SIZE = 0xFFFFFFFFLL;
61 constexpr int64_t GEN_FILE_BUF_SIZE = 1024;
62 constexpr int64_t GEN_FILE_LIMIT_512MB = 512 * 1024 * 1024;
63 constexpr int32_t PRINT_VECTOR_MAX_LENGTH = 30;
64 constexpr const char *WORKED_UT_PATH = "/data/local/tmp/";
65 constexpr const char *MTP_TEST_SEND_FILE = "/data/local/tmp/sampleFile.mtp";
66 constexpr const char *MTP_TEST_RECV_FILE = "/data/local/tmp/sampleFile.mtp";
67 
68 sptr<IUsbfnMtpInterface> g_usbfnMtpInterface = nullptr;
69 sptr<IUsbInterface> g_usbInterface = nullptr;
70 int32_t g_currentFunc = USB_FUNCTION_NONE;
71 int32_t g_fileTestCount = 0;
72 
73 struct UsbFnMtpFileSlice g_mfs = {
74     .offset = 0,
75     .length = 0,
76     .command = 0,
77     .transactionId = 0,
78 };
79 
PrintVector(const std::string & msg,std::vector<uint8_t> & data,bool hexFormat)80 void 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 
GetFileSize(const std::string & pathName)103 uint64_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 
WriteRandomDataToFile(const std::string & pathName,uint64_t fileSize)113 bool 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 
GenerateFile(const std::string & pathName,int64_t fileSize)150 bool 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 
SetUpTestCase(void)168 void UsbfnMtpTest::SetUpTestCase(void)
169 {
170     // Selinux config this UT only works in directory WORKED_UT_PATH for open/read/write file for case send/recvfile.
171     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
172     std::cout << "===>please connect to PC use USB 3.0 interface, press enter to continue set function to mtp"
173               << std::endl;
174     int32_t c;
175     while ((c = getchar()) != '\n' && c != EOF) {}
176 
177     g_usbInterface = IUsbInterface::Get();
178     ASSERT_TRUE(g_usbInterface != nullptr);
179     auto ret = g_usbInterface->SetPortRole(DEFAULT_PORT_ID, POWER_ROLE_SINK, DATA_ROLE_DEVICE);
180     sleep(SLEEP_TIME);
181     ASSERT_EQ(0, ret);
182     ret = g_usbInterface->GetCurrentFunctions(g_currentFunc);
183     ASSERT_EQ(0, ret);
184     std::cout << "===>current function=" << g_currentFunc << ", set function to mtp, please wait" << std::endl;
185     ret = g_usbInterface->SetCurrentFunctions(USB_FUNCTION_MTP);
186     ASSERT_EQ(0, ret);
187 
188     g_usbfnMtpInterface = IUsbfnMtpInterface::Get();
189     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
190     ret = g_usbfnMtpInterface->Start();
191     ASSERT_EQ(0, ret);
192 }
193 
TearDownTestCase(void)194 void UsbfnMtpTest::TearDownTestCase(void)
195 {
196     HDF_LOGV("UsbfnMtpTest::TearDownTestCase");
197     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
198     auto ret = g_usbfnMtpInterface->Stop();
199     ASSERT_EQ(0, ret);
200     ASSERT_TRUE(g_usbInterface != nullptr);
201     ret = g_usbInterface->SetCurrentFunctions(g_currentFunc);
202     ASSERT_EQ(0, ret);
203     if (g_fileTestCount == 0) {
204         return;
205     }
206     /* 1 means single test, run with '--gtest_filter=' option */
207     if (g_fileTestCount == 1) {
208         std::cout << "===>please delete temporary test file if needed: sendfile=" << MTP_TEST_SEND_FILE
209                   << " recvfile=" << MTP_TEST_RECV_FILE << std::endl;
210         return;
211     }
212     if (FileExists(std::string(MTP_TEST_SEND_FILE))) {
213         if (remove(MTP_TEST_SEND_FILE) != 0) {
214             std::cout << "[-] remove send file failed: " << MTP_TEST_SEND_FILE << std::endl;
215         }
216     }
217     if (FileExists(std::string(MTP_TEST_RECV_FILE))) {
218         if (remove(MTP_TEST_RECV_FILE) != 0) {
219             std::cout << "[-] remove recv file failed: " << MTP_TEST_RECV_FILE << std::endl;
220         }
221     }
222 }
223 
SetUp(void)224 void UsbfnMtpTest::SetUp(void) {}
225 
TearDown(void)226 void UsbfnMtpTest::TearDown(void) {}
227 
228 /**
229  * @tc.name: SUB_USB_HDI_FnMtpRead_2390
230  * @tc.desc: Test functions to Read
231  * @tc.desc: int32_t Read(std::vector<uint8_t>& data);
232  * @tc.desc: Positive test: parameters correctly, read length less then one packet size
233  * @tc.type: FUNC
234  */
235 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpRead_2390, Function | MediumTest | Level1)
236 {
237     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
238     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpRead_2390 Case Start");
239     std::vector<uint8_t> devData;
240 
241     std::cout << "SUB_USB_HDI_FnMtpRead_2390===>use libusb in PC launch bulk-out transfer(size="
242               << BULK_OUT_LESS_THEN_ONCE << "), press enter to continue" << std::endl;
243     int32_t c;
244     while ((c = getchar()) != '\n' && c != EOF) {}
245 
246     int32_t ret = g_usbfnMtpInterface->Read(devData);
247     ASSERT_EQ(ret, 0);
248     ASSERT_EQ(devData.size(), static_cast<size_t>(BULK_OUT_LESS_THEN_ONCE));
249 }
250 
251 /**
252  * @tc.name: SUB_USB_HDI_FnMtpRead_2400
253  * @tc.desc: Test functions to Read
254  * @tc.desc: int32_t Read(std::vector<uint8_t>& data);
255  * @tc.desc: Positive test: parameters correctly, read length exactly one packet size
256  * @tc.type: FUNC
257  */
258 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpRead_2400, Function | MediumTest | Level1)
259 {
260     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
261     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpRead_2400 Case Start");
262     std::vector<uint8_t> devData;
263 
264     std::cout << "SUB_USB_HDI_FnMtpRead_2400===>use libusb in PC launch bulk-out transfer(size="
265               << BULK_OUT_ONCE_MAX_SIZE << "), press enter to continue" << std::endl;
266     int32_t c;
267     while ((c = getchar()) != '\n' && c != EOF) {}
268 
269     int32_t ret = g_usbfnMtpInterface->Read(devData);
270     ASSERT_EQ(ret, 0);
271     ASSERT_EQ(devData.size(), static_cast<size_t>(BULK_OUT_ONCE_MAX_SIZE));
272 }
273 
274 /**
275  * @tc.name: SUB_USB_HDI_FnMtpRead_2410
276  * @tc.desc: Test functions to Read
277  * @tc.desc: int32_t Read(std::vector<uint8_t>& data);
278  * @tc.desc: Positive test: parameters correctly, read length more then one packet size, please read again
279  * @tc.type: FUNC
280  */
281 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpRead_2410, Function | MediumTest | Level1)
282 {
283     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
284     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpRead_2410 Case Start");
285     std::vector<uint8_t> devData;
286 
287     std::cout << "SUB_USB_HDI_FnMtpRead_2410===>use libusb in PC launch bulk-out transfer(size="
288               << BULK_OUT_MORE_THEN_ONCE << "), press enter to continue" << std::endl;
289     int32_t c;
290     while ((c = getchar()) != '\n' && c != EOF) {}
291 
292     int32_t ret = g_usbfnMtpInterface->Read(devData);
293     ASSERT_EQ(ret, 0);
294     ASSERT_EQ(devData.size(), static_cast<size_t>(BULK_OUT_ONCE_MAX_SIZE));
295     devData.clear();
296     ret = g_usbfnMtpInterface->Read(devData);
297     ASSERT_EQ(ret, 0);
298     ASSERT_EQ(devData.size(), static_cast<size_t>(BULK_OUT_MORE_THEN_ONCE - BULK_OUT_ONCE_MAX_SIZE));
299 }
300 
301 /**
302  * @tc.name: SUB_USB_HDI_FnMtpRead_2420
303  * @tc.desc: Test functions to Read
304  * @tc.desc: int32_t Read(std::vector<uint8_t>& data)
305  * @tc.desc: Positive test: parameters correctly, no specific read size
306  * @tc.type: FUNC
307  */
308 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpRead_2420, Function | MediumTest | Level1)
309 {
310     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
311     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpRead_2420 Case Start");
312     std::vector<uint8_t> devData;
313 
314     std::cout
315         << "SUB_USB_HDI_FnMtpRead_2420===>use libusb in PC launch bulk-out transfer(size in [0, 1024]), "
316         << "press enter to continue" << std::endl;
317     int32_t c;
318     while ((c = getchar()) != '\n' && c != EOF) {}
319 
320     auto ret = g_usbfnMtpInterface->Read(devData);
321     ASSERT_EQ(ret, 0);
322     ASSERT_GE(devData.size(), 0);
323 }
324 
325 /**
326  * @tc.name: SUB_USB_HDI_FnMtpRead_2430
327  * @tc.desc: Test functions to Read
328  * @tc.desc: int32_t Read(std::vector<uint8_t>& data)
329  * @tc.desc: Positive test: parameters correctly, check read content
330  * @tc.type: FUNC
331  */
332 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpRead_2430, Function | MediumTest | Level1)
333 {
334     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
335     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpRead_2430 Case Start");
336     std::vector<uint8_t> devData;
337     // hex value of string "read005"
338     std::vector<uint8_t> expectData = {0x72, 0x65, 0x61, 0x64, 0x30, 0x30, 0x35};
339 
340     std::cout << "SUB_USB_HDI_FnMtpRead_2430===>use libusb in PC launch bulk-out transfer(string=read005), "
341               << "press enter to continue" << std::endl;
342     int32_t c;
343     while ((c = getchar()) != '\n' && c != EOF) {}
344 
345     auto ret = g_usbfnMtpInterface->Read(devData);
346     ASSERT_EQ(ret, 0);
347     ASSERT_EQ(devData, expectData);
348     PrintVector("read005", devData, true);
349 }
350 
351 /**
352  * @tc.name: SUB_USB_HDI_FnMtpWrite_2440
353  * @tc.desc: Test functions to Write
354  * @tc.desc: int32_t Write(const std::vector<uint8_t>& data)
355  * @tc.desc: Positive test: parameters correctly
356  * @tc.type: FUNC
357  */
358 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpWrite_2440, Function | MediumTest | Level1)
359 {
360     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
361     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpWrite_2440 Case Start");
362     uint32_t length = BULK_IN_LESS_THEN_ONCE;
363     std::vector<uint8_t> devData;
364     devData.assign(length, 'w');
365 
366     std::cout << "SUB_USB_HDI_FnMtpWrite_2440===>use libusb in PC launch bulk-in transfer(expect=" << length
367               << "), press enter to continue" << std::endl;
368     int32_t c;
369     while ((c = getchar()) != '\n' && c != EOF) {}
370 
371     auto ret = g_usbfnMtpInterface->Write(devData);
372     ASSERT_EQ(ret, 0);
373 }
374 
375 /**
376  * @tc.name: SUB_USB_HDI_FnMtpWrite_2450
377  * @tc.desc: Test functions to Write
378  * @tc.desc: int32_t Write(const std::vector<uint8_t>& data)
379  * @tc.desc: Positive test: parameters correctly
380  * @tc.type: FUNC
381  */
382 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpWrite_2450, Function | MediumTest | Level1)
383 {
384     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
385     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpWrite_2450 Case Start");
386     uint32_t length = BULK_IN_ONCE_MAX_SIZE;
387     std::vector<uint8_t> devData;
388     devData.assign(length, 'w');
389     std::cout << "SUB_USB_HDI_FnMtpWrite_2450===>use libusb in PC launch bulk-in transfer(expect=" << length
390               << "), press enter to continue" << std::endl;
391     int32_t c;
392     while ((c = getchar()) != '\n' && c != EOF) {}
393 
394     auto ret = g_usbfnMtpInterface->Write(devData);
395     ASSERT_EQ(ret, 0);
396 }
397 
398 /**
399  * @tc.name: SUB_USB_HDI_FnMtpWrite_2460
400  * @tc.desc: Test functions to Write
401  * @tc.desc: int32_t Write(const std::vector<uint8_t>& data)
402  * @tc.desc: Positive test: parameters correctly
403  * @tc.type: FUNC
404  */
405 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpWrite_2460, Function | MediumTest | Level1)
406 {
407     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
408     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpWrite_2460 Case Start");
409     uint32_t length = BULK_IN_MORE_THEN_ONCE;
410     std::vector<uint8_t> devData;
411     devData.assign(length, 'w');
412     std::cout << "SUB_USB_HDI_FnMtpWrite_2460===>use libusb in PC launch bulk-in transfer(expect=" << length
413               << "), press enter to continue" << std::endl;
414     int32_t c;
415     while ((c = getchar()) != '\n' && c != EOF) {}
416 
417     auto ret = g_usbfnMtpInterface->Write(devData);
418     ASSERT_EQ(ret, 0);
419 }
420 
421 /**
422  * @tc.name: SUB_USB_HDI_FnMtpWrite_2470
423  * @tc.desc: Test functions to Write
424  * @tc.desc: int32_t Write(const std::vector<uint8_t>& data)
425  * @tc.desc: Positive test: parameters correctly, write empty data
426  * @tc.type: FUNC
427  */
428 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpWrite_2470, Function | MediumTest | Level1)
429 {
430     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
431     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpWrite_2470 Case Start");
432     std::vector<uint8_t> devData;
433     auto ret = g_usbfnMtpInterface->Write(devData);
434     ASSERT_EQ(ret, 0);
435 }
436 
437 /**
438  * @tc.name: SUB_USB_HDI_FnMtpWrite_2480
439  * @tc.desc: Test functions to Write
440  * @tc.desc: int32_t Write(const std::vector<uint8_t>& data)
441  * @tc.desc: Positive test: parameters correctly, write specific data
442  * @tc.type: FUNC
443  */
444 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpWrite_2480, Function | MediumTest | Level1)
445 {
446     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
447     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpWrite_2480 Case Start");
448     // hex value of string "write005"
449     std::vector<uint8_t> devData = {0x77, 0x72, 0x69, 0x74, 0x65, 0x30, 0x30, 0x35};
450     std::cout << "SUB_USB_HDI_FnMtpWrite_2480===>use libusb in PC launch bulk-in transfer(expect string=write005), "
451               << "press enter to continue" << std::endl;
452     int32_t c;
453     while ((c = getchar()) != '\n' && c != EOF) {}
454 
455     auto ret = g_usbfnMtpInterface->Write(devData);
456     ASSERT_EQ(ret, 0);
457     PrintVector("write005", devData, true);
458 }
459 
460 /**
461  * @tc.name: SUB_USB_HDI_FnMtpSendEvent_2490
462  * @tc.desc: Test functions to SendEvent
463  * @tc.desc: int32_t SendEvent(const std::vector<uint8_t> &eventData);
464  * @tc.desc: Positive test: parameters correctly, valid length
465  * @tc.type: FUNC
466  */
467 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpSendEvent_2490, Function | MediumTest | Level1)
468 {
469     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
470     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpSendEvent_2490 Case Start");
471     std::vector<uint8_t> devData;
472     devData.assign(MTP_EVENT_PACKET_VALID_LEN, 'e');
473     std::cout << "SUB_USB_HDI_FnMtpSendEvent_2490===>use libusb in PC launch intr-in transfer(expect="
474               << devData.size() << "), press enter to continue" << std::endl;
475     int32_t c;
476     while ((c = getchar()) != '\n' && c != EOF) {}
477 
478     auto ret = g_usbfnMtpInterface->SendEvent(devData);
479     ASSERT_EQ(0, ret);
480 }
481 
482 /**
483  * @tc.name: SUB_USB_HDI_FnMtpSendEvent_2500
484  * @tc.desc: Test functions to SendEvent
485  * @tc.desc: int32_t SendEvent(const std::vector<uint8_t> &eventData);
486  * @tc.desc: Positive test: parameters correctly, max length
487  * @tc.type: FUNC
488  */
489 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpSendEvent_2500, Function | MediumTest | Level1)
490 {
491     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
492     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpSendEvent_2500 Case Start");
493     std::vector<uint8_t> devData;
494     devData.assign(MTP_EVENT_PACKET_MAX_BYTES, 'e');
495     std::cout << "SUB_USB_HDI_FnMtpSendEvent_2500===>use libusb in PC launch intr-in transfer(expect="
496               << devData.size() << "), press enter to continue" << std::endl;
497     int32_t c;
498     while ((c = getchar()) != '\n' && c != EOF) {}
499     auto ret = g_usbfnMtpInterface->SendEvent(devData);
500     ASSERT_EQ(0, ret);
501 }
502 
503 /**
504  * @tc.name: SUB_USB_HDI_FnMtpSendEvent_2510
505  * @tc.desc: Test functions to SendEvent
506  * @tc.desc: int32_t SendEvent(const std::vector<uint8_t> &eventData);
507  * @tc.desc: Negative test: parameters exception, size overflow
508  * @tc.type: FUNC
509  */
510 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpSendEvent_2510, Function | MediumTest | Level1)
511 {
512     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
513     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpSendEvent_2510 Case Start");
514     std::vector<uint8_t> devData;
515     devData.assign(MTP_EVENT_PACKET_INVALID_LEN, 'e');
516     std::cout << "SUB_USB_HDI_FnMtpSendEvent_2510===>use libusb in PC launch intr-in transfer(expect=no data, "
517               << "or error), press enter to continue" << std::endl;
518     int32_t c;
519     while ((c = getchar()) != '\n' && c != EOF) {}
520 
521     auto ret = g_usbfnMtpInterface->SendEvent(devData);
522     ASSERT_NE(0, ret);
523     std::cout << "SUB_USB_HDI_FnMtpSendEvent_2510===>make sure transfer timeout in PC, then start next test "
524               << std::endl;
525 }
526 
527 /**
528  * @tc.name: SUB_USB_HDI_FnMtpSendEvent_2520
529  * @tc.desc: Test functions to SendEvent
530  * @tc.desc: int32_t SendEvent(const std::vector<uint8_t> &eventData);
531  * @tc.desc: Positive test: parameters correctly, max length, check content
532  * @tc.type: FUNC
533  */
534 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpSendEvent_2520, Function | MediumTest | Level1)
535 {
536     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
537     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpSendEvent_2520 Case Start");
538     // hex value of string "event004"
539     std::vector<uint8_t> devData = {0x65, 0x76, 0x65, 0x6E, 0x74, 0x30, 0x30, 0x34};
540     std::cout << "SUB_USB_HDI_FnMtpSendEvent_2520===>use libusb in PC launch intr-in transfer(expect string=event004), "
541               << "press enter to continue" << std::endl;
542     int32_t c;
543     while ((c = getchar()) != '\n' && c != EOF) {}
544     auto ret = g_usbfnMtpInterface->SendEvent(devData);
545     ASSERT_EQ(0, ret);
546     PrintVector("event004", devData, true);
547 }
548 
549 /**
550  * @tc.name: SUB_USB_HDI_FnMtpFileReceive_2530
551  * @tc.desc: Test functions to ReceiveFile
552  * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs);
553  * @tc.desc: Positive test: parameters correctly, one packet enough
554  * @tc.type: FUNC
555  */
556 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileReceive_2530, Function | MediumTest | Level1)
557 {
558     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
559     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
560     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileReceive_2530 Case Start");
561     g_fileTestCount++;
562     struct UsbFnMtpFileSlice mfs = g_mfs;
563     mfs.length = BULK_OUT_LESS_THEN_ONCE;
564     std::cout << "SUB_USB_HDI_FnMtpFileReceive_2530===>use libusb in PC launch bulk-out transfer(size = "
565               << mfs.length << "), press enter to continue" << std::endl;
566     int32_t c;
567     while ((c = getchar()) != '\n' && c != EOF) {}
568 
569     std::string filePathName = MTP_TEST_RECV_FILE;
570     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
571     ASSERT_GT(mfs.fd, 0);
572     auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
573     close(mfs.fd);
574     ASSERT_EQ(ret, 0);
575     ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
576 }
577 
578 /**
579  * @tc.name: SUB_USB_HDI_FnMtpFileReceive_2540
580  * @tc.desc: Test functions to ReceiveFile
581  * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs);
582  * @tc.desc: Positive test: parameters correctly, zero length
583  * @tc.type: FUNC
584  */
585 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileReceive_2540, Function | MediumTest | Level1)
586 {
587     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
588     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
589     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileReceive_2540 Case Start");
590     g_fileTestCount++;
591     struct UsbFnMtpFileSlice mfs = g_mfs;
592     mfs.length = 0;
593     std::string filePathName = MTP_TEST_RECV_FILE;
594     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
595     ASSERT_GT(mfs.fd, 0);
596     auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
597     close(mfs.fd);
598     ASSERT_EQ(ret, 0);
599     ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
600 }
601 
602 /**
603  * @tc.name: SUB_USB_HDI_FnMtpFileReceive_2550
604  * @tc.desc: Test functions to ReceiveFile
605  * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs);
606  * @tc.desc: Positive test: parameters correctly, one normal packet + short packet
607  * @tc.type: FUNC
608  */
609 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileReceive_2550, Function | MediumTest | Level1)
610 {
611     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
612     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
613     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileReceive_2550 Case Start");
614     g_fileTestCount++;
615     struct UsbFnMtpFileSlice mfs = g_mfs;
616     mfs.length = BULK_OUT_MORE_THEN_ONCE;
617     std::cout << "SUB_USB_HDI_FnMtpFileReceive_2550===>use libusb in PC launch bulk-out transfer(size = "
618               << mfs.length << "), press enter to continue" << std::endl;
619     int32_t c;
620     while ((c = getchar()) != '\n' && c != EOF) {}
621 
622     std::string filePathName = MTP_TEST_RECV_FILE;
623     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
624     ASSERT_GT(mfs.fd, 0);
625     auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
626     close(mfs.fd);
627     ASSERT_EQ(ret, 0);
628     ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
629 }
630 
631 /**
632  * @tc.name: SUB_USB_HDI_FnMtpFileReceive_2560
633  * @tc.desc: Test functions to ReceiveFile
634  * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs);
635  * @tc.desc: Positive test: mfs.length set to max, 12 packet + ZLP
636  * @tc.type: FUNC
637  */
638 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileReceive_2560, Function | MediumTest | Level1)
639 {
640     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
641     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
642     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileReceive_2560 Case Start");
643     g_fileTestCount++;
644     struct UsbFnMtpFileSlice mfs = g_mfs;
645     mfs.length = MTP_FILE_SIZE_REUSE_REQ;
646     std::cout << "SUB_USB_HDI_FnMtpFileReceive_2560===>use libusb in PC launch bulk-out transfer(size = "
647               << mfs.length << "), press enter to continue" << std::endl;
648     int32_t c;
649     while ((c = getchar()) != '\n' && c != EOF) {}
650 
651     std::string filePathName = MTP_TEST_RECV_FILE;
652     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
653     ASSERT_GT(mfs.fd, 0);
654     auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
655     close(mfs.fd);
656     ASSERT_EQ(ret, 0);
657     ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
658 }
659 
660 /**
661  * @tc.name: SUB_USB_HDI_FnMtpFileReceive_2570
662  * @tc.desc: Test functions to ReceiveFile
663  * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs);
664  * @tc.desc: Positive test: parameters correctly, command and transactionId ignored
665  * @tc.type: FUNC
666  */
667 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileReceive_2570, Function | MediumTest | Level1)
668 {
669     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
670     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
671     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileReceive_2570 Case Start");
672     g_fileTestCount++;
673     struct UsbFnMtpFileSlice mfs = g_mfs;
674     mfs.length = BULK_OUT_LESS_THEN_ONCE;
675     mfs.command = CMD_CODE_GET_DEVICE_INFO;
676     mfs.transactionId = TRANSACTION_ID_RANDOM;
677     std::cout << "SUB_USB_HDI_FnMtpFileReceive_2570===>use libusb in PC launch bulk-out transfer(size = "
678               << mfs.length << "), press enter to continue" << std::endl;
679     int32_t c;
680     while ((c = getchar()) != '\n' && c != EOF) {}
681 
682     std::string filePathName = MTP_TEST_RECV_FILE;
683     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
684     ASSERT_GT(mfs.fd, 0);
685     auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
686     close(mfs.fd);
687     ASSERT_EQ(ret, 0);
688     ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
689 }
690 
691 /**
692  * @tc.name: SUB_USB_HDI_FnMtpFileReceive_2580
693  * @tc.desc: Test functions to ReceiveFile
694  * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs);
695  * @tc.desc: Positive test: mfs.length set to max, recv actual file size depend on xfer count
696  * @tc.type: FUNC
697  */
698 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileReceive_2580, Function | MediumTest | Level1)
699 {
700     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
701     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
702     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileReceive_2580 Case Start");
703     g_fileTestCount++;
704     struct UsbFnMtpFileSlice mfs = g_mfs;
705     mfs.length = MTP_MAX_FILE_SIZE;
706     std::cout
707         << "SUB_USB_HDI_FnMtpFileReceive_2580===>use libusb in PC launch bulk-out transfer(size = any), "
708         << "press enter to continue" << std::endl;
709     int32_t c;
710     while ((c = getchar()) != '\n' && c != EOF) {}
711 
712     std::string filePathName = MTP_TEST_RECV_FILE;
713     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
714     ASSERT_GT(mfs.fd, 0);
715     auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
716     close(mfs.fd);
717     ASSERT_EQ(ret, 0);
718     ASSERT_GE(GetFileSize(filePathName), 0);
719 }
720 
721 /**
722  * @tc.name: SUB_USB_HDI_FnMtpFileReceive_2590
723  * @tc.desc: Test functions to ReceiveFile
724  * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs);
725  * @tc.desc: Positive test: mfs.length set to max - 1: 4GB - 2
726  * @tc.type: FUNC
727  */
728 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileReceive_2590, Function | MediumTest | Level1)
729 {
730     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
731     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
732     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileReceive_2590 Case Start");
733     g_fileTestCount++;
734     struct UsbFnMtpFileSlice mfs = g_mfs;
735     mfs.length = MTP_MAX_FILE_SIZE - 1;
736     std::cout << "SUB_USB_HDI_FnMtpFileReceive_2590===>use libusb in PC launch bulk-out transfer(size = "
737               << mfs.length << "), press enter to continue" << std::endl;
738     int32_t c;
739     while ((c = getchar()) != '\n' && c != EOF) {}
740 
741     std::string filePathName = MTP_TEST_RECV_FILE;
742     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
743     ASSERT_GT(mfs.fd, 0);
744     auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
745     close(mfs.fd);
746     ASSERT_EQ(ret, 0);
747     ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
748 }
749 
750 /**
751  * @tc.name: SUB_USB_HDI_FnMtpFileReceive_2600
752  * @tc.desc: Test functions to ReceiveFile
753  * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs);
754  * @tc.desc: Positive test: mfs.length set to max + 1: 4GB
755  * @tc.type: FUNC
756  */
757 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileReceive_2600, Function | MediumTest | Level1)
758 {
759     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
760     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
761     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileReceive_2600 Case Start");
762     g_fileTestCount++;
763     struct UsbFnMtpFileSlice mfs = g_mfs;
764     mfs.length = MTP_MAX_FILE_SIZE + 1;
765     std::cout << "SUB_USB_HDI_FnMtpFileReceive_2600===>use libusb in PC launch bulk-out transfer(size = "
766               << mfs.length << "), press enter to continue" << std::endl;
767     int32_t c;
768     while ((c = getchar()) != '\n' && c != EOF) {}
769 
770     std::string filePathName = MTP_TEST_RECV_FILE;
771     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
772     ASSERT_GT(mfs.fd, 0);
773     auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
774     close(mfs.fd);
775     ASSERT_EQ(ret, 0);
776     ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
777 }
778 
779 /**
780  * @tc.name: SUB_USB_HDI_FnMtpFileReceive_2610
781  * @tc.desc: Test functions to ReceiveFile
782  * @tc.desc: int32_t ReceiveFile(const UsbFnMtpFileSlice &mfs);
783  * @tc.desc: Positive test: mfs.length set to max + 2: 4GB + 1
784  * @tc.type: FUNC
785  */
786 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileReceive_2610, Function | MediumTest | Level1)
787 {
788     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
789     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
790     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileReceive_2610 Case Start");
791     g_fileTestCount++;
792     struct UsbFnMtpFileSlice mfs = g_mfs;
793     mfs.length = MTP_MAX_FILE_SIZE + 2;
794     std::cout << "SUB_USB_HDI_FnMtpFileReceive_2610===>use libusb in PC launch bulk-out transfer(size = "
795               << mfs.length << "), press enter to continue" << std::endl;
796     int32_t c;
797     while ((c = getchar()) != '\n' && c != EOF) {}
798 
799     std::string filePathName = MTP_TEST_RECV_FILE;
800     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDWR | O_TRUNC, 0777);
801     ASSERT_GT(mfs.fd, 0);
802     auto ret = g_usbfnMtpInterface->ReceiveFile(mfs);
803     close(mfs.fd);
804     ASSERT_EQ(ret, 0);
805     ASSERT_EQ(GetFileSize(filePathName), static_cast<uint64_t>(mfs.length));
806 }
807 
808 /**
809  * @tc.name: SUB_USB_HDI_FnMtpFileSend_2620
810  * @tc.desc: Test functions to SendFile
811  * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs);
812  * @tc.desc: Positive test: parameters correctly, length in one packet
813  * @tc.type: FUNC
814  */
815 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileSend_2620, Function | MediumTest | Level1)
816 {
817     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
818     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
819     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileSend_2620 Case Start");
820     g_fileTestCount++;
821     struct UsbFnMtpFileSlice mfs = g_mfs;
822     mfs.length = BULK_IN_LESS_THEN_ONCE;
823     std::string filePathName = MTP_TEST_SEND_FILE;
824     EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
825     std::cout << "SUB_USB_HDI_FnMtpFileSend_2620===>use libusb in PC launch bulk-in transfer(expect " << mfs.length
826               << "), press enter to continue" << std::endl;
827     int32_t c;
828     while ((c = getchar()) != '\n' && c != EOF) {}
829 
830     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
831     ASSERT_GT(mfs.fd, 0);
832     auto ret = g_usbfnMtpInterface->SendFile(mfs);
833     close(mfs.fd);
834     ASSERT_EQ(ret, 0);
835 }
836 
837 /**
838  * @tc.name: SUB_USB_HDI_FnMtpFileSend_2630
839  * @tc.desc: Test functions to SendFile
840  * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs);
841  * @tc.desc: Positive test: parameters correctly, send header + data in one packet
842  * @tc.type: FUNC
843  */
844 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileSend_2630, Function | MediumTest | Level1)
845 {
846     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
847     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
848     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileSend_2630 Case Start");
849     g_fileTestCount++;
850     struct UsbFnMtpFileSlice mfs = g_mfs;
851     mfs.length = BULK_IN_LESS_THEN_ONCE;
852     mfs.command = CMD_CODE_GET_DEVICE_INFO;
853     std::string filePathName = MTP_TEST_SEND_FILE;
854     EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
855     std::cout << "SUB_USB_HDI_FnMtpFileSend_2630===>use libusb in PC launch bulk-in transfer(expect "
856               << mfs.length + MTP_PACKET_HEADER_SIZE << "), press enter to continue" << std::endl;
857     int32_t c;
858     while ((c = getchar()) != '\n' && c != EOF) {}
859 
860     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
861     ASSERT_GT(mfs.fd, 0);
862     auto ret = g_usbfnMtpInterface->SendFile(mfs);
863     close(mfs.fd);
864     ASSERT_EQ(0, ret);
865 }
866 
867 /**
868  * @tc.name: SUB_USB_HDI_FnMtpFileSend_2640
869  * @tc.desc: Test functions to SendFile
870  * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs);
871  * @tc.desc: Positive test: parameters correctly, zero length
872  * @tc.type: FUNC
873  */
874 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileSend_2640, Function | MediumTest | Level1)
875 {
876     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
877     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
878     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileSend_2640 Case Start");
879     g_fileTestCount++;
880     struct UsbFnMtpFileSlice mfs = g_mfs;
881     mfs.length = 0;
882     std::string filePathName = MTP_TEST_SEND_FILE;
883     EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
884     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
885     ASSERT_GT(mfs.fd, 0);
886     auto ret = g_usbfnMtpInterface->SendFile(mfs);
887     close(mfs.fd);
888     ASSERT_EQ(0, ret);
889 }
890 
891 /**
892  * @tc.name: SUB_USB_HDI_FnMtpFileSend_2650
893  * @tc.desc: Test functions to SendFile
894  * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs);
895  * @tc.desc: Positive test: parameters correctly, send header + data in two packet: normal + short
896  * @tc.type: FUNC
897  */
898 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileSend_2650, Function | MediumTest | Level1)
899 {
900     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
901     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
902     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileSend_2650 Case Start");
903     g_fileTestCount++;
904     struct UsbFnMtpFileSlice mfs = g_mfs;
905     mfs.length = MTP_FILE_SIZE_ONE_REQ;
906     mfs.command = CMD_CODE_GET_DEVICE_INFO;
907     std::string filePathName = MTP_TEST_SEND_FILE;
908     EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
909     std::cout << "SUB_USB_HDI_FnMtpFileSend_2650===>use libusb in PC launch bulk-in transfer(expect "
910               << mfs.length + MTP_PACKET_HEADER_SIZE << "), press enter to continue" << std::endl;
911     int32_t c;
912     while ((c = getchar()) != '\n' && c != EOF) {}
913 
914     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
915     ASSERT_GT(mfs.fd, 0);
916     auto ret = g_usbfnMtpInterface->SendFile(mfs);
917     close(mfs.fd);
918     ASSERT_EQ(0, ret);
919 }
920 
921 /**
922  * @tc.name: SUB_USB_HDI_FnMtpFileSend_2660
923  * @tc.desc: Test functions to SendFile
924  * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs);
925  * @tc.desc: Positive test: parameters correctly, mfs.length set to max
926  * @tc.type: FUNC
927  */
928 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileSend_2660, Function | MediumTest | Level1)
929 {
930     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
931     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
932     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileSend_2660 Case Start");
933     g_fileTestCount++;
934     struct UsbFnMtpFileSlice mfs = g_mfs;
935     mfs.length = MTP_FILE_SIZE_REUSE_REQ;
936     std::string filePathName = MTP_TEST_SEND_FILE;
937     EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
938     std::cout << "SUB_USB_HDI_FnMtpFileSend_2660===>use libusb in PC launch bulk-in transfer(speed, expect "
939               << mfs.length << "), press enter to continue" << std::endl;
940     int32_t c;
941     while ((c = getchar()) != '\n' && c != EOF) {}
942 
943     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
944     ASSERT_GT(mfs.fd, 0);
945     auto ret = g_usbfnMtpInterface->SendFile(mfs);
946     close(mfs.fd);
947     ASSERT_EQ(0, ret);
948 }
949 
950 /**
951  * @tc.name: SUB_USB_HDI_FnMtpFileSend_2670
952  * @tc.desc: Test functions to SendFile
953  * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs);
954  * @tc.desc: Positive test: parameters correctly, mfs.length set to max: 4GB - 1
955  * @tc.type: FUNC
956  */
957 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileSend_2670, Function | MediumTest | Level1)
958 {
959     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
960     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
961     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileSend_2670 Case Start");
962     g_fileTestCount++;
963     struct UsbFnMtpFileSlice mfs = g_mfs;
964     mfs.length = MTP_MAX_FILE_SIZE;
965     std::string filePathName = MTP_TEST_SEND_FILE;
966     EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
967     std::cout << "SUB_USB_HDI_FnMtpFileSend_2670===>use libusb in PC launch bulk-in transfer(speed, expect "
968               << mfs.length << "), press enter to continue" << std::endl;
969     int32_t c;
970     while ((c = getchar()) != '\n' && c != EOF) {}
971 
972     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
973     ASSERT_GT(mfs.fd, 0);
974     auto ret = g_usbfnMtpInterface->SendFile(mfs);
975     close(mfs.fd);
976     ASSERT_EQ(0, ret);
977 }
978 
979 /**
980  * @tc.name: SUB_USB_HDI_FnMtpFileSend_2680
981  * @tc.desc: Test functions to SendFile
982  * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs);
983  * @tc.desc: Positive test: parameters correctly, mfs.length set to max + 1: 4GB
984  * @tc.type: FUNC
985  */
986 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileSend_2680, Function | MediumTest | Level1)
987 {
988     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
989     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
990     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileSend_2680 Case Start");
991     g_fileTestCount++;
992     struct UsbFnMtpFileSlice mfs = g_mfs;
993     mfs.length = MTP_MAX_FILE_SIZE + 1;
994     std::string filePathName = MTP_TEST_SEND_FILE;
995     EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
996     std::cout << "SUB_USB_HDI_FnMtpFileSend_2680===>use libusb in PC launch bulk-in transfer(speed, expect "
997               << mfs.length << "), press enter to continue" << std::endl;
998     int32_t c;
999     while ((c = getchar()) != '\n' && c != EOF) {}
1000 
1001     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1002     ASSERT_GT(mfs.fd, 0);
1003     auto ret = g_usbfnMtpInterface->SendFile(mfs);
1004     close(mfs.fd);
1005     ASSERT_EQ(0, ret);
1006 }
1007 
1008 /**
1009  * @tc.name: SUB_USB_HDI_FnMtpFileSend_2690
1010  * @tc.desc: Test functions to SendFile
1011  * @tc.desc: int32_t SendFile(const UsbFnMtpFileSlice &mfs);
1012  * @tc.desc: Positive test: parameters correctly, mfs.length set to max + 1: 4GB + 1
1013  * @tc.type: FUNC
1014  */
1015 HWTEST_F(UsbfnMtpTest, SUB_USB_HDI_FnMtpFileSend_2690, Function | MediumTest | Level1)
1016 {
1017     ASSERT_TRUE(g_usbfnMtpInterface != nullptr);
1018     ASSERT_TRUE(GetCurrentProcPath() == std::string(WORKED_UT_PATH));
1019     HDF_LOGI("UsbfnMtpTest::SUB_USB_HDI_FnMtpFileSend_2690 Case Start");
1020     g_fileTestCount++;
1021     struct UsbFnMtpFileSlice mfs = g_mfs;
1022     mfs.length = MTP_MAX_FILE_SIZE + 2;
1023     std::string filePathName = MTP_TEST_SEND_FILE;
1024     EXPECT_TRUE(GenerateFile(filePathName, mfs.length));
1025     std::cout << "SUB_USB_HDI_FnMtpFileSend_2690===>use libusb in PC launch bulk-in transfer(speed, expect "
1026               << mfs.length << "), press enter to continue" << std::endl;
1027     int32_t c;
1028     while ((c = getchar()) != '\n' && c != EOF) {}
1029 
1030     mfs.fd = open(filePathName.c_str(), O_CREAT | O_RDONLY);
1031     ASSERT_GT(mfs.fd, 0);
1032     auto ret = g_usbfnMtpInterface->SendFile(mfs);
1033     close(mfs.fd);
1034     ASSERT_EQ(0, ret);
1035 }
1036 
1037 } // namespace
1038