Merge branch 'master' of gitee.com:openharmony/developtools_hdc into master

Signed-off-by: maliang <maliang87@huawei.com>
This commit is contained in:
maliang 2024-08-13 06:10:01 +00:00 committed by Gitee
commit eca0939814
9 changed files with 58 additions and 56 deletions

View File

@ -106,7 +106,7 @@ template("hdcd_source_set") {
defines += [ "JS_JDWP_CONNECT" ] defines += [ "JS_JDWP_CONNECT" ]
} }
if (use_musl) { if (use_musl) {
if (use_jemalloc && use_jemalloc_dfx_intf) { if (musl_use_jemalloc && musl_use_jemalloc_dfx_intf) {
defines += [ "CONFIG_USE_JEMALLOC_DFX_INIF" ] defines += [ "CONFIG_USE_JEMALLOC_DFX_INIF" ]
} }
} }

View File

@ -27,7 +27,7 @@ import pytest
from dev_hdc_test import GP from dev_hdc_test import GP
from dev_hdc_test import check_library_installation, check_hdc_version, check_cmd_time from dev_hdc_test import check_library_installation, check_hdc_version, check_cmd_time
from dev_hdc_test import check_hdc_cmd, check_hdc_targets, get_local_path, get_remote_path, run_command_with_timeout from dev_hdc_test import check_hdc_cmd, check_hdc_targets, get_local_path, get_remote_path, run_command_with_timeout
from dev_hdc_test import check_app_install, check_app_uninstall, prepare_source, pytest_run, update_source, check_rate from dev_hdc_test import check_app_install, check_app_uninstall, prepare_source, pytest_run, update_source, check_rate, get_shell_result
from dev_hdc_test import make_multiprocess_file, rmdir from dev_hdc_test import make_multiprocess_file, rmdir
from dev_hdc_test import check_app_install_multi, check_app_uninstall_multi from dev_hdc_test import check_app_install_multi, check_app_uninstall_multi
from dev_hdc_test import check_rom, check_shell from dev_hdc_test import check_rom, check_shell
@ -223,7 +223,11 @@ def test_target_cmd():
assert check_hdc_targets() assert check_hdc_targets()
time.sleep(3) time.sleep(3)
check_hdc_cmd("target boot") check_hdc_cmd("target boot")
time.sleep(60) # reboot needs at least 60 seconds start_time = time.time()
run_command_with_timeout("hdc wait", 60) # reboot takes up to 60 seconds
end_time = time.time()
print(f"command exec time {end_time - start_time}")
assert (end_time - start_time) > 5 # Reboot takes at least 5 seconds
assert (check_hdc_cmd("target mount", "Mount finish") or assert (check_hdc_cmd("target mount", "Mount finish") or
check_hdc_cmd("target mount", "[Fail]Operate need running as root") or check_hdc_cmd("target mount", "[Fail]Operate need running as root") or
check_hdc_cmd("target mount", "Remount successful.") check_hdc_cmd("target mount", "Remount successful.")
@ -248,6 +252,18 @@ def test_file_switch_on():
assert check_hdc_cmd(f"file recv {get_remote_path('it_small')} {get_local_path('small_recv')}") assert check_hdc_cmd(f"file recv {get_remote_path('it_small')} {get_local_path('small_recv')}")
def test_target_mount():
check_shell(f"target mount")
mount_after = get_shell_result(f'shell "mount |grep /vendor |head -1"')
assert "rw" in mount_after
def test_target_key():
device_key = get_shell_result(f"list targets").split("\r\n")[0]
hdcd_pid = get_shell_result(f"-t {device_key} shell pgrep -x hdcd").split("\r\n")[0]
assert hdcd_pid.isdigit()
def test_version_cmd(): def test_version_cmd():
version = "Ver: 2.0.0a" version = "Ver: 2.0.0a"
assert check_hdc_version("-v", version) assert check_hdc_version("-v", version)

View File

@ -1951,14 +1951,8 @@ void PrintLogEx(const char *functionName, int line, uint8_t logLevel, const char
} }
return _wfopen(resolvedPath, wideMode.c_str()); return _wfopen(resolvedPath, wideMode.c_str());
#else #else
char resolvedPath[PATH_MAX + 1] = { 0 };
std::string filePath(fileName);
if (!realpath(filePath.c_str(), resolvedPath)) {
WRITE_LOG(LOG_FATAL, "realpath %s failed", filePath.c_str());
return nullptr;
}
// unix paltform open file with default char // unix paltform open file with default char
return fopen(resolvedPath, mode); return fopen(fileName, mode);
#endif #endif
} }
} }

View File

@ -32,7 +32,7 @@ private:
void CheckMaster(CtxFile *context) override; void CheckMaster(CtxFile *context) override;
void WhenTransferFinish(CtxFile *context) override; void WhenTransferFinish(CtxFile *context) override;
bool BeginTransfer(CtxFile *context, const string &command); bool BeginTransfer(CtxFile *context, const string &command);
void TransferSummary(CtxFile *context) override; void TransferSummary(CtxFile *context);
bool SetMasterParameters(CtxFile *context, const char *command, int argc, char **argv); bool SetMasterParameters(CtxFile *context, const char *command, int argc, char **argv);
bool FileModeSync(const uint16_t cmd, uint8_t *payload, const int payloadSize); bool FileModeSync(const uint16_t cmd, uint8_t *payload, const int payloadSize);
}; };

View File

@ -202,19 +202,6 @@ out:
return ret; return ret;
} }
void HdcTransferBase::Next(HdcTransferBase *thisClass, CtxFile *context)
{
if (context->isDir) {
uint8_t payload = 1;
uint16_t cmdFinish = (thisClass->commandBegin == CMD_FILE_BEGIN ? CMD_FILE_FINISH : CMD_APP_FINISH);
thisClass->CommandDispatch(cmdFinish, &payload, 1);
} else {
thisClass->TransferSummary(context);
thisClass->TaskFinish();
}
return;
}
void HdcTransferBase::OnFileIO(uv_fs_t *req) void HdcTransferBase::OnFileIO(uv_fs_t *req)
{ {
CtxFileIO *contextIO = reinterpret_cast<CtxFileIO *>(req->data); CtxFileIO *contextIO = reinterpret_cast<CtxFileIO *>(req->data);
@ -243,11 +230,6 @@ void HdcTransferBase::OnFileIO(uv_fs_t *req)
WRITE_LOG(LOG_DEBUG, "read file data %" PRIu64 "/%" PRIu64 "", context->indexIO, WRITE_LOG(LOG_DEBUG, "read file data %" PRIu64 "/%" PRIu64 "", context->indexIO,
context->fileSize); context->fileSize);
#endif // HDC_DEBUG #endif // HDC_DEBUG
if (req->result == 0 && context->fileSize > 0) {
Next(thisClass, context);
return;
}
if (!thisClass->SendIOPayload(context, context->indexIO - req->result, bufIO, req->result)) { if (!thisClass->SendIOPayload(context, context->indexIO - req->result, bufIO, req->result)) {
context->ioFinish = true; context->ioFinish = true;
break; break;
@ -751,7 +733,7 @@ bool HdcTransferBase::CheckFeatures(CtxFile *context, uint8_t *payload, const in
{ {
if (payloadSize == FEATURE_FLAG_MAX_SIZE) { if (payloadSize == FEATURE_FLAG_MAX_SIZE) {
union FeatureFlagsUnion feature{}; union FeatureFlagsUnion feature{};
if (memcpy_s(&feature, sizeof(feature), payload, payloadSize)) { if (memcpy_s(&feature, sizeof(feature), payload, payloadSize) != EOK) {
WRITE_LOG(LOG_FATAL, "CheckFeatures memcpy_s failed"); WRITE_LOG(LOG_FATAL, "CheckFeatures memcpy_s failed");
return false; return false;
} }

View File

@ -121,9 +121,6 @@ protected:
virtual void WhenTransferFinish(CtxFile *context) virtual void WhenTransferFinish(CtxFile *context)
{ {
} }
virtual void TransferSummary(CtxFile *context)
{
}
bool MatchPackageExtendName(string fileName, string extName); bool MatchPackageExtendName(string fileName, string extName);
bool ResetCtx(CtxFile *context, bool full = false); bool ResetCtx(CtxFile *context, bool full = false);
bool SmartSlavePath(string &cwd, string &localPath, const char *optName); bool SmartSlavePath(string &cwd, string &localPath, const char *optName);
@ -150,7 +147,6 @@ private:
}; };
static const uint8_t payloadPrefixReserve = 64; static const uint8_t payloadPrefixReserve = 64;
static void OnFileIO(uv_fs_t *req); static void OnFileIO(uv_fs_t *req);
static void Next(HdcTransferBase *thisClass, CtxFile *context);
int SimpleFileIO(CtxFile *context, uint64_t index, uint8_t *sendBuf, int bytes); int SimpleFileIO(CtxFile *context, uint64_t index, uint8_t *sendBuf, int bytes);
bool SendIOPayload(CtxFile *context, uint64_t index, uint8_t *data, int dataSize); bool SendIOPayload(CtxFile *context, uint64_t index, uint8_t *data, int dataSize);
bool RecvIOPayload(CtxFile *context, uint8_t *data, int dataSize); bool RecvIOPayload(CtxFile *context, uint8_t *data, int dataSize);

View File

@ -21,6 +21,7 @@ HdcHostApp::HdcHostApp(HTaskInfo hTaskInfo)
{ {
commandBegin = CMD_APP_BEGIN; commandBegin = CMD_APP_BEGIN;
commandData = CMD_APP_DATA; commandData = CMD_APP_DATA;
originLocalDir = "";
} }
HdcHostApp::~HdcHostApp() HdcHostApp::~HdcHostApp()
@ -77,6 +78,7 @@ bool HdcHostApp::BeginInstall(CtxFile *context, const char *command)
string tarpath = Dir2Tar(path.c_str()); string tarpath = Dir2Tar(path.c_str());
if (!tarpath.empty()) { if (!tarpath.empty()) {
context->taskQueue.push_back(tarpath); context->taskQueue.push_back(tarpath);
originLocalDir = path;
} }
} }
} }
@ -167,8 +169,11 @@ bool HdcHostApp::CheckInstallContinue(AppModType mode, bool lastResult, const ch
WRITE_LOG(LOG_DEBUG, "unlink path:%s", path.c_str()); WRITE_LOG(LOG_DEBUG, "unlink path:%s", path.c_str());
} }
} }
LogMsg(MSG_INFO, "%s path:%s, queuesize:%d, msg:%s", modeDesc.c_str(), ctxNow.localPath.c_str(), string path = ctxNow.localPath;
ctxNow.taskQueue.size(), msg + printedMsgLen); if (!originLocalDir.empty()) {
path = originLocalDir;
}
LogMsg(MSG_INFO, "%s path:%s msg:%s", modeDesc.c_str(), path.c_str(), msg + printedMsgLen);
printedMsgLen = strlen(msg); printedMsgLen = strlen(msg);
if (singalStop || !ctxNow.taskQueue.size()) { if (singalStop || !ctxNow.taskQueue.size()) {
LogMsg(MSG_OK, "AppMod finish"); LogMsg(MSG_OK, "AppMod finish");

View File

@ -31,6 +31,7 @@ private:
bool BeginSideload(CtxFile *context, const char *localPath); bool BeginSideload(CtxFile *context, const char *localPath);
string Dir2Tar(const char *dir); string Dir2Tar(const char *dir);
size_t printedMsgLen = 0; size_t printedMsgLen = 0;
string originLocalDir = "";
}; };
} }
#endif #endif

View File

@ -219,24 +219,25 @@ ohos_unittest("hdc_jdwp_unittest") {
} }
public_deps = [ ":hdc_daemon_platform" ] public_deps = [ ":hdc_daemon_platform" ]
deps = [ "//third_party/googletest:gmock_main" ]
sources = [ "unittest/common/HdcJdwpTest.cpp" ] sources = [ "unittest/common/HdcJdwpTest.cpp" ]
deps += [ ":hdc_common" ] deps = [ ":hdc_common" ]
include_dirs = [ include_dirs = [
"${hdc_path}/test/unittest/common/include", "${hdc_path}/test/unittest/common/include",
"${hdc_path}/src/daemon", "${hdc_path}/src/daemon",
"${hdc_path}/src/common", "${hdc_path}/src/common",
"//third_party/bounds_checking_function/include",
"//third_party/libuv",
] ]
external_deps = [ "googletest:gmock_main" ]
if (is_linux) { if (is_linux) {
static_link = false static_link = false
} }
subsystem_name = "developtools" subsystem_name = "developtools"
defines += [ "OPENSSL_SUPPRESS_DEPRECATED" ] defines += [ "OPENSSL_SUPPRESS_DEPRECATED" ]
public_external_deps = [
"bounds_checking_function:libsec_static",
"libuv:uv",
]
} }
ohos_unittest("hdc_uart_unittest") { ohos_unittest("hdc_uart_unittest") {
@ -251,9 +252,9 @@ ohos_unittest("hdc_uart_unittest") {
configs = [ ":hdc_common_config" ] configs = [ ":hdc_common_config" ]
configs += [ ":hdc_ut_code_flag" ] configs += [ ":hdc_ut_code_flag" ]
deps = [ ":hdc_daemon" ] deps = [ ":hdc_daemon" ]
deps += [ "//third_party/googletest:gmock_main" ]
defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
external_deps = [ "googletest:gmock_main" ]
} }
ohos_unittest("hdc_host_uart_unittest") { ohos_unittest("hdc_host_uart_unittest") {
@ -273,8 +274,9 @@ ohos_unittest("hdc_host_uart_unittest") {
deps = [ ":hdc_host" ] deps = [ ":hdc_host" ]
deps += [ "//third_party/googletest:gmock_main" ]
defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ] defines = [ "OPENSSL_SUPPRESS_DEPRECATED" ]
external_deps = [ "googletest:gmock_main" ]
} }
group("HdcJdwpTest") { group("HdcJdwpTest") {
@ -315,8 +317,6 @@ config("hdc_test_config") {
"${hdc_path}/test/fuzztest/forwardreadstream_fuzzer", "${hdc_path}/test/fuzztest/forwardreadstream_fuzzer",
"${hdc_path}/src/daemon", "${hdc_path}/src/daemon",
"${hdc_path}/src/common", "${hdc_path}/src/common",
"//third_party/bounds_checking_function/include",
"//third_party/libuv/include",
] ]
} }
@ -349,17 +349,20 @@ ohos_fuzztest("JdwpReadStreamFuzzTest") {
fuzz_config_file = "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer" fuzz_config_file = "${hdc_path}/test/fuzztest/jdwpreadstream_fuzzer"
configs = [ ":hdc_test_config" ] configs = [ ":hdc_test_config" ]
cflags = fuzz_cflags cflags = fuzz_cflags
deps = [ "//third_party/libuv:uv" ]
sources = [ sources = [
"${hdc_path}/src/daemon/jdwp.cpp", "${hdc_path}/src/daemon/jdwp.cpp",
"${hdc_path}/src/daemon/system_depend.cpp", "${hdc_path}/src/daemon/system_depend.cpp",
"fuzztest/jdwpreadstream_fuzzer/JdwpReadStream_fuzzer.cpp", "fuzztest/jdwpreadstream_fuzzer/JdwpReadStream_fuzzer.cpp",
] ]
deps += [ ":hdc_common" ] deps = [ ":hdc_common" ]
external_deps = [ external_deps = [
"init:libbeget_proxy", "init:libbeget_proxy",
"init:libbegetutil", "init:libbegetutil",
] ]
public_external_deps = [
"bounds_checking_function:libsec_static",
"libuv:uv",
]
} }
ohos_fuzztest("ForwardReadStreamFuzzTest") { ohos_fuzztest("ForwardReadStreamFuzzTest") {
@ -367,11 +370,15 @@ ohos_fuzztest("ForwardReadStreamFuzzTest") {
fuzz_config_file = "${hdc_path}/test/fuzztest/forwardreadstream_fuzzer" fuzz_config_file = "${hdc_path}/test/fuzztest/forwardreadstream_fuzzer"
configs = [ ":hdc_test_config" ] configs = [ ":hdc_test_config" ]
cflags = fuzz_cflags cflags = fuzz_cflags
deps = [ "//third_party/libuv:uv" ]
sources = [ "fuzztest/forwardreadstream_fuzzer/ForwardReadStream_fuzzer.cpp" ] sources = [ "fuzztest/forwardreadstream_fuzzer/ForwardReadStream_fuzzer.cpp" ]
deps += [ ":hdc_common" ] deps = [ ":hdc_common" ]
subsystem_name = "developtools" subsystem_name = "developtools"
part_name = "hdc" part_name = "hdc"
external_deps = [ "libuv:uv" ]
public_external_deps = [
"bounds_checking_function:libsec_static",
"libuv:uv",
]
} }
ohos_fuzztest("DaemonUsbReadFuzzTest") { ohos_fuzztest("DaemonUsbReadFuzzTest") {
@ -379,17 +386,20 @@ ohos_fuzztest("DaemonUsbReadFuzzTest") {
fuzz_config_file = "${hdc_path}/test/fuzztest/daemonusbread_fuzzer" fuzz_config_file = "${hdc_path}/test/fuzztest/daemonusbread_fuzzer"
configs = [ ":hdc_test_config" ] configs = [ ":hdc_test_config" ]
cflags = fuzz_cflags cflags = fuzz_cflags
deps = [ "//third_party/libuv:uv" ]
sources = [ sources = [
"${hdc_path}/src/daemon/daemon_usb.cpp", "${hdc_path}/src/daemon/daemon_usb.cpp",
"${hdc_path}/src/daemon/system_depend.cpp", "${hdc_path}/src/daemon/system_depend.cpp",
"fuzztest/daemonusbread_fuzzer/DaemonUsbRead_fuzzer.cpp", "fuzztest/daemonusbread_fuzzer/DaemonUsbRead_fuzzer.cpp",
] ]
deps += [ ":hdc_common" ] deps = [ ":hdc_common" ]
external_deps = [ external_deps = [
"init:libbeget_proxy", "init:libbeget_proxy",
"init:libbegetutil", "init:libbegetutil",
] ]
public_external_deps = [
"bounds_checking_function:libsec_static",
"libuv:uv",
]
} }
group("hdc_fuzztest") { group("hdc_fuzztest") {
@ -415,15 +425,13 @@ ohos_unittest("hdc_register_unittest") {
configs = [ ":hdc_register_config" ] configs = [ ":hdc_register_config" ]
deps = [
"//third_party/googletest:gmock_main",
"//third_party/libuv:uv",
]
external_deps = [ external_deps = [
"c_utils:utils", "c_utils:utils",
"googletest:gmock_main",
"hilog:libhilog", "hilog:libhilog",
"init:libbeget_proxy", "init:libbeget_proxy",
"init:libbegetutil", "init:libbegetutil",
"libuv:uv",
] ]
subsystem_name = "developtools" subsystem_name = "developtools"