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
testoutputforwarder.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
"testoutputforwarder.h"
5
#
include
"shellhelpers.h"
6
7
#
include
<
QtCore
/
qdeadlinetimer
.
h
>
8
#
include
<
QtCore
/
qthread
.
h
>
9
10
#
include
<
chrono
>
11
#
include
<
cstdio
>
12
13
QT_BEGIN_NAMESPACE
14
15
using
namespace
std::chrono_literals;
16
17
constexpr
auto
finalCopyRetryDelay
= 1s;
18
19
TestOutputForwarder
::
TestOutputForwarder
(
Hdc
hdc, QString devicePath, QString localCopyPath)
20
:
m_hdc
(
std
::
move
(
hdc
)),
21
m_devicePath
(
std
::
move
(
devicePath
)),
22
m_localCopyPath
(
std
::
move
(
localCopyPath
))
23
{
24
}
25
26
q23
::
expected
<
QByteArray
,
QString
>
TestOutputForwarder
::
forwardAvailable
()
27
{
28
const
q23::expected<QByteArray, QString> copiedOutput =
29
copyDeviceFile(m_hdc, m_devicePath, m_localCopyPath);
30
if
(!copiedOutput)
31
return
q23::unexpected(copiedOutput.error());
32
if
(copiedOutput->size() <= m_forwardedBytes)
33
return
QByteArray();
34
const
QByteArray newOutput = copiedOutput->sliced(m_forwardedBytes);
35
forward(newOutput);
36
return
newOutput;
37
}
38
39
bool
TestOutputForwarder
::forwardRemaining(qxp::function_ref<
bool
()> isInterrupted)
40
{
41
const
QDeadlineTimer deadline(hdcOutageTolerance);
42
q23::expected<QByteArray, QString> copiedOutput =
43
copyDeviceFile(m_hdc, m_devicePath, m_localCopyPath);
44
while
(!copiedOutput && !isInterrupted() && !deadline.hasExpired()
45
&& queryDeviceFileState(m_hdc, m_devicePath) != DeviceFileState::Absent) {
46
QThread::sleep(finalCopyRetryDelay);
47
copiedOutput = copyDeviceFile(m_hdc, m_devicePath, m_localCopyPath);
48
}
49
if
(!copiedOutput) {
50
reportUnreadOutput(copiedOutput.error());
51
return
false
;
52
}
53
if
(copiedOutput->size() < m_forwardedBytes) {
54
fprintf(stderr,
"harmonyostestrunner: forwarded %lld bytes of test output, but %s holds "
55
"only %lld\n"
,
static_cast
<
long
long
>(m_forwardedBytes), qPrintable(m_devicePath),
56
static_cast
<
long
long
>(copiedOutput->size()));
57
return
false
;
58
}
59
forward(copiedOutput->sliced(m_forwardedBytes));
60
return
true
;
61
}
62
63
void
TestOutputForwarder
::forward(
const
QByteArray &output)
64
{
65
if
(output.isEmpty())
66
return
;
67
fwrite(output.constData(), 1,
static_cast
<size_t>(output.size()), stdout);
68
fflush(stdout);
69
m_forwardedBytes += output.size();
70
}
71
72
void
TestOutputForwarder
::reportUnreadOutput(
const
QString &failure)
const
73
{
74
fprintf(stderr,
"harmonyostestrunner: could not copy the test output from %s (%s), "
75
"it is incomplete after %lld bytes\n"
, qPrintable(m_devicePath),
76
qPrintable(failure),
static_cast
<
long
long
>(m_forwardedBytes));
77
}
78
79
QT_END_NAMESPACE
Hdc
Definition
hdc.h:17
TestOutputForwarder
Definition
testoutputforwarder.h:17
TestOutputForwarder::forwardAvailable
q23::expected< QByteArray, QString > forwardAvailable()
Definition
testoutputforwarder.cpp:26
TestOutputForwarder::TestOutputForwarder
TestOutputForwarder(Hdc hdc, QString devicePath, QString localCopyPath)
Definition
testoutputforwarder.cpp:19
finalCopyRetryDelay
constexpr auto finalCopyRetryDelay
Definition
testoutputforwarder.cpp:17
qtbase
src
tools
harmonyostestrunner
testoutputforwarder.cpp
Generated on
for Qt by
1.18.0