Commit Graph

43 Commits

Author SHA1 Message Date
Eike Ziller
737877984d Use QTEST_GUILESS_MAIN where applicable
instead of QTEST_MAIN. Reduces the initialization that is done by the Qt
test applications, and can also reduce interference with normal OS
operations like the current window loosing focus.

Change-Id: If88f289281aa1c8703ac7d4dbe0799d067c16588
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-06-13 06:06:44 +00:00
Jarek Kobus
f051ed3076 QtcProcess: Add a test for various quit methods
The quitBlockingProcess() test examines different types
of process quitting and illustrates differences in
behavior.

Change-Id: I9209f00576e03eef66fbdf5665351138ed437ac9
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-06-08 06:57:49 +00:00
Jarek Kobus
6455d7fcf3 QtcProcess: Make the class final
Currently, as a result of many refactorings, the QtcProcess
is designed so that if you want to customize the behavior
you should implement custom ProcessInterface subclass.
Adding virtual methods directly to QtcProcess caused tons of
unpredicted side effects and nasty bugs, which were hard to
track and hard to fix, as provided fixes were usually fixing
particular case while introducing regressions in not related
code paths.

Consider also aggregating QtcProcess object instead of
deriving from it when some additional methods are required.

This patch removes the last virtual methods from QtcProcess API
and makes the class final in order to prevent from adding
any new virtual methods to this class in the future.

This commit message should make it clear that having subclasses
of QtcProcess is not a desired design. It's a post-mortem
conclusion. So: don't derive from QtcProcess - we mean it!

Change-Id: I1e43ed45be326b366422fd7db6e05ba48ea5fb98
Reviewed-by: hjk <hjk@qt.io>
2022-05-09 07:42:29 +00:00
David Schulz
11ce6e365f Utils: fix QProcess backend on Windows
Do not return false from QtcProces::waitForStarted if the process is
already running. This causes mayor issues on windows since QProcess
directly emits started and therefore switches to the running state after
calling QProcess::start.

Change-Id: I4604b08a59918d3df11c8a174b57e1e483e78a0d
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-04-25 10:04:48 +00:00
Jarek Kobus
a4a651aa32 QtcProcess: Fix StartFailed result
Amends 4ca336762e

Change-Id: I3781bec37b17ea3f86eedc51657db0931a456c39
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-14 07:55:22 +00:00
Jarek Kobus
00acccfd3d QtcProcess: Fix terminate() for process launcher
ProcessLauncherImpl::terminate() was behaving the same as
ProcessLauncherImpl::kill() in case of process launcher
implementation - in both cases the launcher
immediately returned confirmation about receiving the
close request and was putting the corresponding
process into its reaper. However, the issue with this approach
is that we can't receive anymore any potential ready
read signal from the process being terminated after
a call to terminate().

The fix is to diverge the behavior of terminate()
and kill() of ProcessLauncherImpl. The behavior of kill()
remains the same, while terminate() just instructs the
process launcher to start termination without putting
the process into the reaper, yet.

Add a test that checks for any possible zombies.

We run the RecursiveBlockingProcess recursively. The most
nested process blocks. After a short wait we terminate
the outermost process. With this test we are trying to see
if terminating the middle process terminates also its
children and doesn't leave zombies.

Before we execute the test (and also by the end of this test)
we call Singleton::deleteAll() in order to ensure that reaping
of previously running processes has finished. We ensure the
number of running processtestapps is zero. Later, we ensure that
the leaf process was already started and the number of running
processtestapps equals the depth of recursion.

Fix apparent bug in getLocalProcessesUsingProc().

Change-Id: I7e2bc46ad5ca22f26620da86fbaf0fa00a7db3c3
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-04-12 13:59:41 +00:00
Jarek Kobus
2794b5e543 tst_QtcProcess: Get rid of lineCallbackIntern() test
This test introduced some additional private API to QtcProcess.
This makes refactorings of QtcProcess harder, as we need to
handle this artificial code working.

We have a real lineCallback() test instead which doesn't
employ this private API.

Change-Id: Idbc314210cecc2044e1ccc298e5d3e0a9747e811
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-11 15:26:10 +00:00
Jarek Kobus
97132cf7f0 tst_QtcProcess: Add a test that invokes a process recursively
After the required depth of recursion is met, the most
nested process waits for one seconds and crashes.

Change-Id: I8d9b359459fc7aa1983734685e5c5f19eb49ee94
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-05 11:40:20 +00:00
Jarek Kobus
8f427c1c95 tst_QtcProcess: Move subprocesses into a separate executable
Don't invoke subcreator test in order to run a custom process.
Run a separate executable instead. The advantages are:
1. Faster test running (no need for QTest specific code path
   when running subprocess).
2. Don't use std::exit() from subprocesses as it doesn't
   clean up properly. Use qApp->exit() instead.
3. This should support returning NormalExit and proper
   exit code of subprocess in case the code wasn't 0.

Change-Id: I1395bd8a7873c95a594c3e054087f00c55a15376
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-04-05 11:40:00 +00:00
Jarek Kobus
679a7ba7ef tst_QtcProcess: Rename ProcessChannelForwarding into ChannelForwarding
Amends 91c11c769f

Change-Id: Ib38edca1f720a313c42ee6224cbd9109fb50fa84
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-04-04 07:20:02 +00:00
Alessandro Portale
91c11c769f Utils: Add mergedChannels test to tst_QtcProcess
Change-Id: Ia6c25004ca37c97c0cfa61bc2eb944493f796217
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-03-31 22:32:11 +00:00
Jarek Kobus
127ca236a7 Ensure we never encounter the message about destroying QProcess
Until we remove the process launcher / process reaper.

Change-Id: I9c68c40c3c856c0a515277b69fc3084ba2addbee
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-03-24 09:42:07 +00:00
Jarek Kobus
ae49fb213b Ensure that after a call to waitForFinished() process is not running
Amends 5de5f1cf0a

Change-Id: I64db8c6736c6a7cc6805813f852faf1048ebb629
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-03-23 12:12:39 +00:00
Jarek Kobus
5de5f1cf0a QtcProcess: Add a test for crashing app
Ensure that when waitForFinished() didn't timeout
but the process has terminated, it returns true,
like QProcess does, in contrary to what QProcess'
documentation says.

Change-Id: I6af5034f4df7fc2e14a83bab74334a8abefe7a0f
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2022-03-22 11:30:24 +00:00
Christian Stenger
f69de8b5bc Tests: Fix compile
Amends 47bcb63854.

Change-Id: I34a867b3b0b868933937e37e8268b98078aa3023
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2022-03-21 07:59:19 +00:00
Jarek Kobus
dabe2e1493 ProcessLauncher: Don't emit error twice on process crash
Behave the same as QProcess in this circumstances.

Change-Id: If8175ccb7102d6a561584ee73c2e5c5844f2770d
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-03-18 15:19:35 +00:00
Jarek Kobus
47bcb63854 Add new types of blocking processes
Change-Id: I7668d0ac94a4e949f7ea67d8a1c0c144af5bd541
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-03-18 09:35:44 +00:00
Jarek Kobus
67497e6bc4 Compile fix
Amends cfe8b7ad88

Change-Id: I4a570c481cf631ee6650a5c9d3b0f0540df88671
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2022-03-14 09:41:42 +00:00
Jarek Kobus
cfe8b7ad88 Fix handling of unfinished lines by QtcProcess callbacks
Don't detect a call to QtcProcess::kill() from inside the
QtcProcess callback while awaiting inside QtcProcess::waitFor...().
That's not needed, since a call to kill() sends a stop message
to the process launcher, so we wait for confirmation
from process launcher instead. This may bring e.g. new
read data from the running process.

Fix a runBlockingStdOut() test so that when we write to the stdOut
from the running process we flush the unfinished line so that
it's not buffered inside the process.

Change-Id: I7944ac214d8cb9e10a71715a7ef8bfacab6df7c9
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-03-14 07:38:08 +00:00
Alessandro Portale
a863958aa4 Utils: Silence MSVC deprecation warnings in tst_qtcprocess
warning: C4996: 'setmode': The POSIX name for this item is deprecated.
Instead, use the ISO C and C++ conformant name: _setmode. See online
help for details.

...same for 'fileno'

Change-Id: I85090b65532b17b535914b88de835d718f654f6a
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2022-03-11 08:04:35 +00:00
Jarek Kobus
b2331dd5f6 Fix paths to subprocesses when test is run from other directory
Now it's possible to run the test outside of directory
where the test is located.

Change-Id: I2a2c693d382917ac7b84488c8ccf161538b58238
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2022-03-10 10:27:29 +00:00
Jarek Kobus
e66bd6ed90 Simplify starting subCreator process even more
Use SUB_CREATOR_PROCESS macro for registering subprocess'
main() function.

Invoke registered subprocesses by a call to
invokeSubProcessIfRequired().

Substitute subTestCase env variables with TestCase subclasses.
This should make the code even more readable.

Amends bbb0270fb1

Change-Id: Id63b15841ea539f367dab4972a6ecbb298d277e7
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-03-10 08:42:56 +00:00
Jarek Kobus
bbb0270fb1 Simplify starting subCreator process
Introduce SubCreatorConfig class that helps setting up
a Creator subprocess. This limits the code repetition.

Introduce SUB_CREATOR_PROCESS(subProcess) macro to easily define
environment variables referred to Creator subprocesses.
This macro also forward declares the subProcessMain()
function.

Match names of main subprocess functions with their
corresponding environment variables.

Group subProcessMain() functions near the corresponding
test function for clarity.

Change-Id: Ib4365cf18fddc1527ebc99accee1fbb974bbf7a1
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-03-09 12:17:14 +00:00
Jarek Kobus
809b371108 Fix tst_qtcprocess when Qt is showing warnings on startup
In my case Qt is persistently showing the following warning
at startup of every application:

Warning: Ignoring WAYLAND_DISPLAY on Gnome.
Use QT_QPA_PLATFORM=wayland to run on Wayland anyway.

There is no easy solution here, as even when I run this test
with -platform xcb option, then this test is running
another instance of Creator that doesn't have this option
passed. Since QTest's internal main function parses the
argv options and filters out those recognized by Qt itself,
calling QCoreApplication::arguments() doesn't return
the originally passed -platform xcb option.

The solution here is simple - we ignore initial lines
in callback (so we filter out the initial warnings
generated by Qt) and wait for first expected line.
The final check of parsed line numbers should prevent
the case when we have filtered out all the lines.

Change-Id: Ideff0dc7c409b6e3ad81ec13577cb67e5211d5df
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-03-09 10:49:53 +00:00
Jarek Kobus
a7f867ab06 Fix a path to process launcher in tst_qtcprocess
Change-Id: I1de71ff51ffdcc02a2ec8dd117a26625514cd309
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2022-03-09 09:29:06 +00:00
Jarek Kobus
8e0ae8ba96 QtcProcess: Limit the inclusion of qtcprocess.h
Move the rest of QtcProcess enums to processenums.h.
Move ExitCodeInterpreter into processenums.h.
Remove superfluous Utils:: prefix.

Change-Id: Iaa596f353d33d6930085a621b114cc15a35caa80
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-03-02 13:30:39 +00:00
Jarek Kobus
acfe224281 Flush finished() signal when waitForReadyRead() was called
Apparently the QProcess behaves like that.

Change-Id: Idb1993b8abccbd7943582d41bd456eacc9a1c185
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2021-11-04 12:30:03 +00:00
Jarek Kobus
7958de05f5 Introduce Utils::Singleton
Introduce Utils::Singleton class and
Utils::SingletonWithOptionalDependencies class template
that helps implementing singletons that depend on other
singletons. It's guaranteed that whenever singleton B depends
on singleton A, than A is always created before B is being
created, and that the order of destruction is always
opposite to the order of creation.

Dependencies of singleton are listed as template arguments
for SingletonWithOptionalDependencies class template.
The first argument of SingletonWithOptionalDependencies
class template is always a singleton class itself.

Prepare a common interface for all singleton subclasses:
SingletonSubClass *SingletonWithOptionalDependencies::instance();

Make instantiating singletons and its dependencies thread-safe.

Create singletons on demand (only if some code needs them).
It's not needed anymore to explicitly instantiate
all required singletons in tests.

Make it possible (and thread-safe) to instantiate ProcessReaper
and LauncherInterface singletons in non-main threads.

Make the following dependencies between existing singletons:
   SshConnectionManager depends on:
-> LauncherInterface depends on:
-> ProcessReaper

Change-Id: Iefaacab561c2b3dcf07e7fafbb87339ea6a15278
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-28 10:25:29 +00:00
Jarek Kobus
ecfe6b7fc1 Add a test ensuring we don't receive a warning when killing process
Before we were receiving the following warning when detroying the
QtcProcess while still running:

QProcess: Destroyed while process ("[program_name]") is still running.

With the new implementation it won't appear anymore since terminating
running QtcProcesses is done internally by the reaper.

Change-Id: I14a0de136f463966cb1e4c43c5cb26b4de47e7ce
Reviewed-by: hjk <hjk@qt.io>
2021-09-09 14:34:59 +00:00
Jarek Kobus
ace765c199 Move ProcessReaper into lib/utils
Reuse ProcessReaper inside process launcher.
Automatically reap all internal QProcesses of QtcProcess
(either direct child of QtcProcess in QProcessImpl
or indirectly inside process launcher).
Make ProcessReaper work again on QProcess instead of on
QtcProcess, so it may still be reused for non-QtcProcesses.

Change-Id: I950cac5cec28f17ae97fe474d6a4e48c01d6aaa2
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2021-09-06 21:28:19 +00:00
Jarek Kobus
a454b3dc23 Use QProcess' / process lanuncher's exit code
Change-Id: I802116c45847daf9a647771ee293aef8463fc3c7
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-03 10:56:19 +00:00
Jarek Kobus
597750507e Implement process channel forwarding in process launcher
Change-Id: I9e526eb40ebc46284f773d10ec0e285a009c524d
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-03 10:56:12 +00:00
Jarek Kobus
15c183fce6 Set process state to NotRunning after FailedToStart error
Remove the process in process launcher after error has appeared.
Remove unneeded stopStopProcedure as we are disconnecting from
process' signals inside removeProcess().
In order to behave as much similar to what QProcess does,
provide a test that:
- ensures the FailedToStart error is synchronously emitted
  when waitForStarted is being executed
- ensures that process state is reset to NotRunning after
  FailedToStart error
- 2nd call to start/waitForStarted doesn't block on
  waitForStarted

Change-Id: I139354421d037739f1cc1a2685b66f1e5b6170c8
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-08-31 12:09:36 +00:00
Jarek Kobus
6c45764fa1 Rename test case, use both verbs in passive voice
waitForStartAndFinished -> waitForStartedAndFinished.

Change-Id: I44440a21cd91105b84227e13d1ea3d5b9490148f
Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2021-08-25 07:54:31 +00:00
Jarek Kobus
43b82bfc5f Add a test for waitingForStarted and waitingForFinished
Change-Id: I2d38bb2d37a71aad6d762aa68f1f3b329a4fa302
Reviewed-by: hjk <hjk@qt.io>
2021-08-24 18:24:41 +00:00
Jarek Kobus
9966cc4bcc Start and stop the process launcher in tst_qtcprocess
Change-Id: Ib28450d10c699abe3964f8bef2ff24baae0074f7
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-08-19 07:44:48 +00:00
hjk
7c28c4f744 Utils: Introduce a FilePath constructor from char arrays
Similar to QT_RESTRICTED_CAST_FROM_ASCII to avoid the need for
decorations in user code.

At the same time, drop some convenience constructors and functions
in CommandLine and Icon essentially serving the same purpose.

Change-Id: Ida4e5ac19c2da0a4298a97b2a8e1511d56bbb79d
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-08-17 05:34:10 +00:00
Christian Stenger
75aa1f2a6c Tests: Expect fail
Amends ada39349a2.

Change-Id: I4221590941ba17e28fff1d12bb0c80d92ecac911
Reviewed-by: hjk <hjk@qt.io>
2021-07-15 04:59:38 +00:00
hjk
430e81facd All: Replace most SynchronousProcess by QtcProcess
Change-Id: I0bf22fef2cd4a7297ef5a1e9aa9c3e2b9348ba42
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-23 07:55:31 +00:00
hjk
ada39349a2 Utils: Merge QtcProcess line reading functions
- Pass everything through the codec.
- Always emit even incomplete last lines when the process finishes.
- Don't store raw output when line-wise processing is requested.

Change-Id: I5cc30ad0d7ab79387bfb00b48ff957468a1bd004
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-21 10:59:40 +00:00
Alessandro Portale
27f8e2dbce Utils: Fix splitting in ChannelBuffer::takeFirstLine()
Escape the '\r'

Change-Id: I8cee40dc4a65f893f1a11c7cf066777498c37339
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-09 06:40:11 +00:00
Alessandro Portale
8a5b917d8f tst_qtcprocess: Add check for QtcProcess::FinishedWithSuccess
Change-Id: Ic13368459e23b199bc203076d04da43407090c36
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2021-06-04 11:32:35 +00:00
hjk
90e9de5d5d Tests: Move auto/qtcprocess to auto/utils/qtcprocess
Change-Id: Ied95a0f0109ed96703b96c9e79d268d509eda211
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2021-05-31 13:17:03 +00:00