Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
Loading...
Searching...
No Matches
shellhelpers.cpp
Go to the documentation of this file.
1
// Copyright (C) 2026 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3
4
#
include
"shellhelpers.h"
5
6
QT_BEGIN_NAMESPACE
7
8
using
namespace
Qt::StringLiterals;
9
10
void
forceStopBundle
(
const
Hdc &hdc,
const
QString &bundleName)
11
{
12
hdc.shell({ u"aa"_s, u"force-stop"_s, bundleName });
13
}
14
15
bool
isProcessAlive
(
const
Hdc &hdc,
const
QString &bundleName)
16
{
17
return
!hdc.shell({u"pidof"_s, bundleName}).trimmed().isEmpty();
18
}
19
20
// wc -c + tail -c +N runs device-side; both use plain read() syscalls (SELinux
21
// permits, unlike inotify), and one persistent hdc connection avoids per-poll
22
// reconnect overhead.
23
std
::
unique_ptr
<
QProcess
>
streamDeviceFileWhileAppRuns
(
24
const
Hdc &hdc,
const
QString &devicePath,
const
QString &bundleName)
25
{
26
static
constexpr
int
startTimeoutMs = 5000;
27
28
const
QString followFileFromStart = u"sz=0; f='"_s + devicePath + u"';"_s;
29
const
QString definePrintNewBytes =
30
u" dump() { new=$(wc -c < \"$f\" 2>/dev/null);"
31
" if [ \"${new:-0}\" -gt \"$sz\" ]; then"
32
" tail -c +$((sz+1)) \"$f\" 2>/dev/null | head -c $((new-sz)); sz=$new; fi; };"_s
;
33
const
QString printNewBytesUntilAppExits =
34
u" while true; do dump;"
35
" pidof "_s
+ bundleName + u" >/dev/null 2>&1 || { dump; break; };"
36
" sleep 0.1; done"_s
;
37
const
QString streamUntilAppExits =
38
followFileFromStart + definePrintNewBytes + printNewBytesUntilAppExits;
39
40
auto
process = std::make_unique<QProcess>();
41
// SeparateChannels so we can scan stdout for PASS/FAIL while forwarding it.
42
process->setProcessChannelMode(QProcess::SeparateChannels);
43
process->start(hdc.program(), hdc.shellArguments({streamUntilAppExits}));
44
if
(!process->waitForStarted(startTimeoutMs))
45
return
{};
46
return
process;
47
}
48
49
QString
readDeviceFile
(
const
Hdc &hdc,
const
QString &devicePath)
50
{
51
return
hdc.shell({ u"cat"_s, devicePath });
52
}
53
54
QT_END_NAMESPACE
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qsequentialanimationgroup.cpp:47
readDeviceFile
QString readDeviceFile(const Hdc &hdc, const QString &devicePath)
Definition
shellhelpers.cpp:49
forceStopBundle
QT_BEGIN_NAMESPACE void forceStopBundle(const Hdc &hdc, const QString &bundleName)
Definition
shellhelpers.cpp:10
streamDeviceFileWhileAppRuns
std::unique_ptr< QProcess > streamDeviceFileWhileAppRuns(const Hdc &hdc, const QString &devicePath, const QString &bundleName)
Definition
shellhelpers.cpp:23
isProcessAlive
bool isProcessAlive(const Hdc &hdc, const QString &bundleName)
Definition
shellhelpers.cpp:15
qtbase
src
tools
harmonyostestrunner
shellhelpers.cpp
Generated on
for Qt by
1.18.0