Commit Graph

118 Commits

Author SHA1 Message Date
Paolo Bonzini 9d29bd0225 mtest: move test_count and name_max_len to TestHarness class
Avoid passing them around as parameters; this will be useful when logging
is moved out of TestHarness, because individual loggers will call back
into TestHarness to do common formatting chores.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:30 +01:00
Paolo Bonzini 3f8c901245 mtest: add name and number to TestRun
Place in TestRun everything that is needed in order to
format the result.  This avoids passing around the number
and visible test name as arguments.

Test numbers are assigned the first time they are used.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:02 +01:00
Paolo Bonzini 30741a0f20 mtest: create TestRun object early on
This will provide a way to pass more information from the TestHarness
local variables to the SingleTestRunner and use them outside the
run_test function.  For example, the name could be used to report
progress while the tests are running.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:02 +01:00
Paolo Bonzini 79e2c52a15 mtest: only build what is needed for the tests
It is a usual workflow to fix something and retest to see if it is fixed using a
particular test.  When tests start to become numerous, it becomes time consuming
for "meson test" to relink all of them (and in fact rebuild the whole project)
where the user has already specified the tests they want to run, as well as
the tests' dependencies.

Teach meson to be smart and only build what is needed for the test (or suite)
that were specified.

Fixes: #7473
Related: #7830
2020-12-14 10:53:36 +01:00
Oleg B b8052f9e50
Support native tests in crossbuild 2020-12-13 16:32:52 +02:00
Dylan Baker f6672c7a19 use real pathlib module
We added the _pathlib module to work around defeciencies in python 3.5's
implementation, since we now rely on 3.6 lets drop this
2020-11-20 15:08:40 -08:00
Jussi Pakkanen ef6f85f8ba
Merge pull request #7836 from bonzini/mtest-asyncio
[RFC] mtest: use asyncio instead of concurrency.futures
2020-11-18 23:09:47 +02:00
Paolo Bonzini f1ce78d77f mtest: cleanup and fix print_stats
Avoid calling self.collected_failures.append twice, and avoid
inflated indentation by adding a "plain" decorator to mlog.

Fixes: ba71fde18 ("mtest: collect failures regardless of colorized console", 2020-10-12)
2020-11-18 22:49:41 +02:00
Paolo Bonzini a2c134c30b mtest: switch to asyncio subprocesses
No functional change except that the extra thread goes away.
2020-11-15 14:12:43 +01:00
Paolo Bonzini 09253c1c70 mtest: use ProactorEventLoop
This is needed to use asyncio with pipes and processes.
2020-11-15 14:12:43 +01:00
Paolo Bonzini cdbb0255a7 mtest: improve handling of SIGINT and SIGTERM
Handle SIGINT and SIGTERM by respectively cancelling the longest running
and all the running tests.
2020-11-15 14:12:43 +01:00
Paolo Bonzini acf5d78f34 mtest: remove usage of executors
Rewrite the SingleTestRunner to use asyncio to manage subprocesses,
while still using subprocess.Popen to run them.  Concurrency is
managed with an asyncio Semaphore; for simplicity (since this is
a temporary state) we create a new thread for each test that is run
instead of having a pool.

This already provides the main advantage of asyncio, which is better
control on cancellation; with the current code, KeyboardInterrupt
was never handled by the thread executor so the code that tried to handle
it in SingleTestRunner only worked for non-parallel tests.  And
because executor futures cannot be cancelled, there was no way for
the user to kill a test that got stuck.  Instead, without executors
^C exits "meson test" immediately.  The next patch will improve things
even further, allowing a single test to be interrupted with ^C.
2020-11-15 14:12:43 +01:00
Paolo Bonzini 98d3863fa4 mtest: add INTERRUPT to TestResult
Distinguish a failure due to user interrupt from a presumable ERROR
result due to the SIGTERM.  The test should fail after CTRL+C even if
the test traps SIGTERM and exits with a return code of 0.
2020-11-15 14:12:43 +01:00
Paolo Bonzini bd526ec2dc mtest: always ignore ProcessLookupError
ProcessLookupError can also happen from p.kill().  There is also
nothing we can do in that case, so move the "try" for that
exception to the entire kill_process function.

The ValueError case seems like dead code, so get rid of it.
2020-11-15 14:12:43 +01:00
Paolo Bonzini 57b918f281 mtest: refactor _run_cmd
A large part of _run_cmd is devoted to setting up and killing the
test subprocess.  Move that to a separate function to make the
test runner logic easier to understand.
2020-11-15 14:12:43 +01:00
Paolo Bonzini 8cf90e6370 mtest: add back SIGINT handling 2020-11-15 14:12:43 +01:00
Paolo Bonzini 659a5cbaa3 mtest: use asyncio for run loop
Use asyncio futures for the run loop, while still handling I/O in
a thread pool using run_on_executor.

The handling of the test result is not duplicated anymore between
run_tests and drain_futures.  Instead, the test result is always processed
and printed by run_test after single_test.run() completes and (in verbose
mode) it cannot interleave with the test output.  Therefore the special
case for self.options.num_processes == 1 can be removed.
2020-11-15 14:12:43 +01:00
Paolo Bonzini f532b0a9c3 mtest: remove run_special
run_special and doit are the same except that run_special forgot to
set self.is_run.  There is no need for the duplication.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-11-15 14:12:43 +01:00
Paolo Bonzini 98fe195613 mtest: fix flake8 issues 2020-11-15 14:12:43 +01:00
Sergey Kartashev c9b7e5bd40
Fix gtest invoking while workdir is set (#7904)
* Fix gtest invoking while workdir is set

* Fix gtest invoking when workdir is not set

* Code style fix

Co-authored-by: Sergey Kartashev <kartashev.sv@mipt.ru>
2020-10-28 17:04:11 -07:00
Nirbheek Chauhan 55cf399ff8 mtest: Allow filtering tests by subproject
You could always specify a list of tests to run by passing the names as
arguments to `meson test`. If there were multiple tests with that name (in the
same project or different subprojects), all of them would be run. Now you can:

1. Run all tests with the specified name from a specific subproject: `meson test subprojname:testname`
1. Run all tests defined in a specific subproject: `meson test subprojectname:`

Also forbid ':' in test names. We already forbid this elsewhere, so
should not be a big deal.
2020-10-13 19:01:15 +03:00
Camilo Celis Guzman ba71fde186 mtest: collect failures regardless of colorized console 2020-10-12 00:51:21 +03:00
Daniel Mensinger 1dfaccfd91 pathlib: Fix resolve() by overriding it in Python 3.5 2020-10-04 10:45:48 +02:00
Nirbheek Chauhan 8bb3f16f09 mtest: Refactor test data checking 2020-09-10 12:38:05 +00:00
Nirbheek Chauhan fb7099c6cf mtest: Check version in the test data after loading
Same as coredata.dat and build.dat loading. Also, do not assert if
things change. Raise the appropriate exception.

Fixes https://github.com/mesonbuild/meson/issues/7613
2020-09-10 08:18:16 +00:00
Daniel Mensinger 23818fc5a3
typing: more fixes 2020-09-08 20:15:58 +02:00
Daniel Mensinger 0490372449
typing: fully annotate mintro and mtest 2020-09-08 20:15:57 +02:00
Paolo Bonzini 492afe50a4 environment: use ExternalProgram to find ninja
This allows the NINJA environment variable to support all the Windows special
cases, especially allowing an absolute path without extension.

Based on a patch by Yonggang Luo.

Fixes: #7659
Suggested-by: Nirbheek Chauhan <nirbheek@centricular.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-09-04 15:38:12 +02:00
Christoph Reiter 0710ad18d9 Be stricter when detecting Windows/Cygwin
This removes the check for "mingw" for platform.system(). The only case I know
where "mingw" is return is if using a msys Python under a msys2 mingw environment.
This combination is not really supported by meson and will result in weird errors,
so remove the check.

The second change is checking sys.platform for cygwin instead of platform.system().
The former is document to return "cygwin", while the latter is not and just
returns uname().

While under Cygwin it uname() always starts with "cygwin" it's not hardcoded in MSYS2
and starts with the environment name. Using sys.platform is safer here.

Fixes #7552
2020-08-30 23:37:46 +03:00
Nirbheek Chauhan cdc2a67687 mtest: Actually call colorize_console() 2020-08-13 22:54:19 +03:00
Marc-André Lureau 8e98819b06 mtest: fix skipping with various prefixes
According to the specification:
https://testanything.org/tap-specification.html#skipping-tests

  The harness should report the text after # SKIP\S*\s+ as a reason for
  skipping.

(it's not exactly like the TODO directive, the phrasing/presentation of
the spec could be improved).
2020-08-08 01:25:05 +03:00
Simon McVittie 7db49db67d
mtest: TestResult.SKIP is not a failure (#7525)
* mtest: TestResult.SKIP is not a failure

If some but not all tests in a run were skipped, then the overall result
is given by whether there were any failures among the non-skipped tests.

Resolves: https://github.com/mesonbuild/meson/issues/7515
Signed-off-by: Simon McVittie <smcv@debian.org>

* Add test-cases for partially skipped TAP tests

issue7515.txt is the output of one of the real TAP tests in gjs, which
failed as a result of #7515. The version inline in meson.build is
a minimal reproducer.

Signed-off-by: Simon McVittie <smcv@debian.org>
2020-08-05 23:08:05 +03:00
Camilo Celis Guzman 8da1b29899 mtest: report failures and overall summary *after* test(s) logs 2020-07-30 16:38:07 +03:00
Dylan Baker af787874a8 pass exe_wrapper to test scripts through the environment
This adds a new MESON_EXE_WRAPPER environment variable containing the
string form of the exe_wrapper, if there is an exe_wrapper defined.

Fixes #4427
2020-05-18 13:53:58 -07:00
Dylan Baker 0ec94ca062 backends: Consider arguments passed to a test when cross compiling
Otherwise a wrapper script which takes an executable as an argument will
mistakenly run when that executable is cross compiled. This does not
wrap said executable in an exe_wrapper, just skip it.

Fixes #5982
2020-05-18 13:53:58 -07:00
Dylan Baker 754080843b mtest: don't use len() to test container emptiness
It's not idiomatic python and is significantly slower than not using the
bool protocol.
2020-05-18 13:53:58 -07:00
Dylan Baker 083c5f6357 Add native support for gtest tests
Gtest can output junit results with a command line switch. We can parse
this to get more detailed results than the returncode, and put those in
our own Junit output. We basically just throw away the top level
'testsuites' object, then fixup the names of the tests, and shove that
into our junit.
2020-05-04 11:33:19 -07:00
Dylan Baker 28e3ce67ae Convert test protocol into an enum
This gives us better type safety, and will be important as we add more
test methods
2020-04-30 13:54:46 -07:00
Dylan Baker fe46515630 mtest: use argparse.type to simplify some code 2020-04-30 13:30:37 -07:00
Dylan Baker 542255993c mtest: Replace if (bool) { return bool; } with return bool; 2020-04-30 13:29:16 -07:00
Dylan Baker 7b7f93a09f mtest: Generate a JUnit xml result file
JUnit is pretty ubiquitous, lots of services and results viewers
understand it, in particular gitlab and jenkins know how to consume
JUnit xml. This means projects using CI services can have their test
results consumed automatically.

Fixes: #6972
2020-04-23 13:26:01 -07:00
Dylan Baker 0c3bb15357 mtest: Store individual results for TAP tests
This will be used by the Junit writer
2020-04-23 13:26:01 -07:00
Dylan Baker 4dcbb9254a mtest: Use textrwap.dedent for large block
This allows editors like vim to properly fold the code, and makes it
generally easier to read.
2020-04-22 13:55:19 -07:00
Hemmo Nieminen 30ba9cca72 mtest: Improve test output formatting.
Remove some weirdness from test output such as extra commas, missing
spaces and way too precise time durations. Also improve the overall
alignment of the output.
2020-04-03 00:51:52 +03:00
Camilo Celis Guzman 18373cba74 mtest: terminate a test via SIGTERM first then (if needed) via SIGKILL 2020-03-19 23:04:36 +02:00
Michael Brockus 98ddd52ced
Cherry-picking - (rm python2 % add python3 .format) (#6725) 2020-03-03 21:45:43 +02:00
Daniel Mensinger 09b53c534f types: import typing as T (fixes #6333) 2020-01-08 15:28:17 +01:00
Camilo Celis Guzman 7a76fecdf7 mesonbuild/mtest: plumb and report a test's start time 2019-11-07 22:22:14 +02:00
Michael Hirsch, Ph.D 6e708208dd CI: add initial type annotation checking 2019-11-07 22:18:21 +02:00
Wolfgang Stöggl f037e7ef45 Fix typos found by codespell
- Typos were found by codespell v1.16.0
2019-11-06 09:55:30 -05:00