mirror of
https://gitee.com/openharmony/ability_ability_runtime
synced 2024-11-23 07:10:19 +00:00
!1557 【测试框架】shellcommand wait逻辑更新
Merge pull request !1557 from njupthan/update_master_0418_1
This commit is contained in:
commit
7f95488a14
@ -115,8 +115,9 @@ const std::string STRING_STOP_SERVICE_ABILITY_NG = "error: failed to stop servic
|
||||
const std::string STRING_FORCE_STOP_OK = "force stop process successfully.";
|
||||
const std::string STRING_FORCE_STOP_NG = "error: failed to force stop process.";
|
||||
|
||||
const std::string STRING_START_USER_TEST_OK = "start user test successfully.";
|
||||
const std::string STRING_START_USER_TEST_NG = "error: failed to start user test.";
|
||||
const std::string STRING_USER_TEST_STARTED = "user test started.";
|
||||
const std::string STRING_USER_TEST_FINISHED = "user test finished.";
|
||||
|
||||
const std::string STRING_BLOCK_ABILITY_OK = "block ability successfully.";
|
||||
const std::string STRING_BLOCK_ABILITY_NG = "error: failed to block stop ability.";
|
||||
|
@ -53,11 +53,11 @@ private:
|
||||
std::string cmd_;
|
||||
int64_t timeoutSec_ {0};
|
||||
ShellCommandResult cmdResult_;
|
||||
bool isDone_ {false};
|
||||
|
||||
std::shared_ptr<AppExecFwk::EventHandler> handler_;
|
||||
std::condition_variable cvWork_;
|
||||
std::mutex mtxWork_;
|
||||
std::mutex mtxSyncWork_;
|
||||
std::mutex mtxCopy_;
|
||||
};
|
||||
} // namespace AAFwk
|
||||
|
@ -1016,7 +1016,7 @@ ErrCode AbilityManagerShellCommand::StartUserTest(const std::map<std::string, st
|
||||
resultReceiver_.append(GetMessageFromCode(result));
|
||||
return result;
|
||||
}
|
||||
HILOG_INFO("%{public}s", STRING_START_USER_TEST_OK.c_str());
|
||||
HILOG_INFO("%{public}s", STRING_USER_TEST_STARTED.c_str());
|
||||
|
||||
std::signal(SIGCHLD, SIG_DFL);
|
||||
|
||||
@ -1030,8 +1030,8 @@ ErrCode AbilityManagerShellCommand::StartUserTest(const std::map<std::string, st
|
||||
return OHOS::ERR_INVALID_VALUE;
|
||||
}
|
||||
|
||||
HILOG_INFO("User test finished successfully");
|
||||
resultReceiver_ = STRING_START_USER_TEST_OK + "\n";
|
||||
HILOG_INFO("%{public}s", STRING_USER_TEST_FINISHED.c_str());
|
||||
resultReceiver_ = STRING_USER_TEST_FINISHED + "\n";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
@ -34,21 +34,17 @@ ShellCommandResult ShellCommandExecutor::WaitWorkDone()
|
||||
{
|
||||
HILOG_INFO("enter");
|
||||
|
||||
std::unique_lock<std::mutex> syncLock(mtxSyncWork_);
|
||||
|
||||
if (!DoWork()) {
|
||||
HILOG_INFO("Failed to execute command : \"%{public}s\"", cmd_.data());
|
||||
return cmdResult_;
|
||||
}
|
||||
|
||||
std::unique_lock<std::mutex> workLock(mtxWork_);
|
||||
syncLock.unlock();
|
||||
|
||||
auto condition = [this]() { return isDone_; };
|
||||
if (timeoutSec_ <= 0) {
|
||||
while (timeoutSec_ <= 0) {
|
||||
cvWork_.wait(workLock);
|
||||
}
|
||||
} else if (cvWork_.wait_for(workLock, timeoutSec_ * 1s) == std::cv_status::timeout) {
|
||||
cvWork_.wait(workLock, condition);
|
||||
} else if (!cvWork_.wait_for(workLock, timeoutSec_ * 1s, condition)) {
|
||||
HILOG_WARN("Command execution timed out! cmd : \"%{public}s\", timeoutSec : %{public}" PRId64,
|
||||
cmd_.data(), timeoutSec_);
|
||||
std::cout << "Warning! Command execution timed out! cmd : " << cmd_ << ", timeoutSec : " << timeoutSec_
|
||||
@ -86,12 +82,14 @@ bool ShellCommandExecutor::DoWork()
|
||||
handler_->PostTask([this, self]() {
|
||||
HILOG_INFO("DoWork async task begin, cmd : \"%{public}s\"", cmd_.data());
|
||||
|
||||
std::unique_lock<std::mutex> syncLock(mtxSyncWork_);
|
||||
|
||||
FILE *file = popen(cmd_.c_str(), "r");
|
||||
if (!file) {
|
||||
HILOG_ERROR("Failed to call popen, cmd : \"%{public}s\"", cmd_.data());
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> workLock(mtxWork_);
|
||||
isDone_ = true;
|
||||
}
|
||||
cvWork_.notify_one();
|
||||
HILOG_INFO("DoWork async task end, cmd : \"%{public}s\"", cmd_.data());
|
||||
return;
|
||||
@ -109,6 +107,10 @@ bool ShellCommandExecutor::DoWork()
|
||||
cmdResult_.exitCode = pclose(file);
|
||||
file = nullptr;
|
||||
|
||||
{
|
||||
std::unique_lock<std::mutex> workLock(mtxWork_);
|
||||
isDone_ = true;
|
||||
}
|
||||
cvWork_.notify_one();
|
||||
HILOG_INFO("DoWork async task end, cmd : \"%{public}s\"", cmd_.data());
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user