Commit Graph

306 Commits

Author SHA1 Message Date
Paolo Bonzini ea2f34e286 mtest: allow quickly interrupting the test run
The new behavior of interrupting the longest running test with Ctrl-C is useful
when tests hang, but not when the run is completely broken for some reason.
Psychology tells us that the user will compulsively spam Ctrl-C in this case,
so exit if three Ctrl-C's are detected within a second.
2021-01-14 22:00:51 +00:00
Paolo Bonzini f13b2b4b1d mtest: fix flake8 2021-01-14 22:00:51 +00:00
Paolo Bonzini f13dde1f08 mtest: print TAP subtest count
The parentheses look ugly in the progress report.  To keep it aligned
with the test outcomes, remove them from the outcomes as well.
2021-01-07 19:20:40 +01:00
Paolo Bonzini b05aee5c94 mtest: print time that the test has been running
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:40 +01:00
Paolo Bonzini 4371756182 mtest: align decimal point of test durations 2021-01-07 19:20:40 +01:00
Paolo Bonzini 72e96a470a mtest: create runners in advance
Compute all options in advance so that we can compute the maximum
timeout.
2021-01-07 19:20:40 +01:00
Paolo Bonzini d470a915da mtest: move timeout message to ConsoleLogger
This adds a point where to call the progress report flush() method.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:40 +01:00
Paolo Bonzini d1ee242e0d mtest: store timeout in TestRun
This will be useful when printing the progress report.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:40 +01:00
Paolo Bonzini 4b8364b1e2 mtest: add more formatting options to TestHarness.format
Allow leaving extra space in the left column, as well as customizing parts of
the printed line.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:40 +01:00
Paolo Bonzini f97521a1ff mtest: align correctly tests with wide Unicode characters
This correctly formats tests with CJK names or, well, emoji.  It is not perfect
(for example it does not correctly format emoji that are variations of 1-wide
characters), but it is as good as most terminal emulators.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:40 +01:00
Paolo Bonzini fa4fb3e350 mtest: make test output parsing asynchronous
Instead of slurping in the entire stream, build the TestResult along
the way.  This allows reporting the results of TAP and Rust subtests as
they come in, either as part of the progress report or (in the future)
as individual lines of the output.
2021-01-07 19:20:40 +01:00
Paolo Bonzini f1938349c7 mtest: move Rust parsing inside TestRun
Make the code look like the TAP parser.  This simplifies the introduction of
asynchronous parsing.
2021-01-07 19:20:40 +01:00
Paolo Bonzini 755412b526 mtest: read test stdout/stderr via asyncio pipes
Instead of creating temporary files, get the StreamReaders from
_run_subprocess's returned object. Through asyncio magic, their
contents will be read as it becomes ready and then returned when
the StreamReader.read future is awaited.

Because of this change, the stdout and stderr can be easily
preserved when TestSubprocess returns an additional_error.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:40 +01:00
Paolo Bonzini 0ccc70ae1b mtest: do not wait inside _run_subprocess
We would like SingleTestRunner to run code before waiting on the process,
for example starting tasks to read stdout and stderr.

Return a new object that is able to complete _run_subprocess's task.
In the next patch, SingleTestRunner will also use the object to get hold
of the stdout and stderr StreamReaders.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:40 +01:00
Paolo Bonzini 63e26ba05f mtest: handle should_fail in common code
This is common to all protocols, place the code in a single
place.
2021-01-07 19:20:40 +01:00
Paolo Bonzini d2da7565fd mtest: reorder arguments to "complete"
Put them in the same order as complete_*.
2021-01-07 19:20:40 +01:00
Paolo Bonzini c48713e58c mtest: improve JUnit XML generation for TAP testsuites
Include the names from the TAP output and the SKIP/TODO explanations
if present.  Omit the classname attribute, it is optional.

In order to enable this, TestRun.results becomes a list of TAPParser.Test
objects.  If in the future there are other kinds of subtest results a
new class can be introduced, but for now it is enough.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:38 +01:00
Paolo Bonzini 35d3baaa2f mtest: improvements to JUnit XML generation
Omit the classname attribute, as it is optional, and add the duration.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:12 +01:00
Paolo Bonzini 723c4c9fef mtest: extract TAP parsing out of TestRun.make_tap
For now this is just a refactoring that simplifies the next patch.  However,
it will also come in handy when we will make the parsing asynchronous, because
it will make it possible to access subtest results while the test runs.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:12 +01:00
Paolo Bonzini e50861e62f mtest/TAPParser: use typing.NamedTuple
It is cleaner than collections.namedtuple.  It also catches that "count()" is
a method on tuple, so rename the field to num_tests.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-07 19:20:11 +01:00
Paolo Bonzini 304abaf9ee mtest: remove argument to the TAPParser constructor
Pass the StringIO object to the parse method instead, because
there will be no T.Iterator[str] to use in the asynchronous
case.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-06 08:44:22 +01:00
Paolo Bonzini ee5e7977e3 mtest: allow parsing TAP line by line
This is the first step towards asynchronous parsing of the TAP output.
We will need to call the same code from both a "for" loop (for unit
tests) and an "async for" loop (for mtest itself).  Because the same
function cannot be both a generator and an asynchronous generator, we
need to build both on a common core.  This commit therefore introduces
a parse_line function that "parse" can call in a loop.  All the local
variables of TAPParser.parse move into "self".

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2021-01-06 08:43:26 +01:00
Dylan Baker d89ec98b47 mtest: Add support for rust unit tests
Rust has it's own built in unit test format, which is invoked by
compiling a rust executable with the `--test` flag to rustc. The tests
are then run by simply invoking that binary. They output a custom test
format, which this patch adds parsing support for. This means that we
can report each subtest in the junit we generate correctly, which should
be helpful for orchestration systems like gitlab and jenkins which can
parse junit XML.
2021-01-05 10:23:41 -08:00
Dylan Baker 07ff9c61fe mtest: Handle subtest results as a dict
for non tap tests we want to associate names with the tests, to that end
store them as a dict. For TAP tests, we'll store the "name" as an
integer string that coresponds to the order that the tests were run in.
2021-01-05 10:17:27 -08:00
Paolo Bonzini 5d97bf615f mtest: flush progress report before warning 2020-12-27 13:55:53 +01:00
Paolo Bonzini 80ba696066 mtest: flush stdout after printing test results
Flush after each output line, even if printing to a file, so that each
result is immediately visible down a pipeline.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:53 +01:00
Paolo Bonzini 4cfd1e638c mtest: add progress report
Add a progress report in the style of "yum".  Every second the
report prints a different test among the ones that are running.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:52 +01:00
Paolo Bonzini aa03c06ffb mtest: merge print_stats and process_test_result
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini df0d5ce34e mtest: convert console output to TestLogger
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini 240036bced mtest: convert logfile to TestLogger
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini 119a928f9f mtest: convert jsonlogfile to TestLogger
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini fb02b5e858 mtest: introduce TestLogger
The TestLogger class lets us move the code for all those log files
out of TestHarness.  The interface is based on JunitBuilder, which
is converted already in this commit.  Over the next commits, we
will also convert JSON, text and console output.

The main difference with JunitBuilder is that the completion method is
asynchronous.  This can be useful if the logger needs to clean up after
itself and wait for asyncio tasks.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini a166df1f96 mtest: do not use __del__
Use try/finally instead of destructors to ensure that log files are closed.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini 109cde4ddc mtest: remove collected_logs
Just reuse the collected_failures collection now that it contains
TestRun objects.  Move the code to generate the short form of the log
to TestRun.

Note that the first line of the error log is not included in
get_log()'s return value, so the magic "first four lines are passed
unscathed" is changed to three lines only.  The resulting output is
like this:

    --- command ---
    <command line>
    --- Listing only the last 100 lines from a long log. ---
    --- stdout ---
    ...

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini 414aee6328 mtest: use backslash replace when printing error logs
If there's an UnicodeEncodeError while printing the error logs,
TestHarness tries an encode/decode pair to get rid of anything that
is not a 7-bit ASCII character; this however results in "?" characters
that are not very clear.  To make it easier to understand what is
going on, use backslashreplace instead.

While at it, fix the decode to use a matching encoding.  This will
only matter in the rare case of sys.stdout.encoding not being an
ASCII superset, but that should not matter.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini 2201e2bca6 mtest: improve colorization
Instead of colorizing the whole status line, only colorize the word
representing the outcome of the test (SKIP, OK, FAIL, etc.).  This
is less intrusive, so the patch also does the following changes:

- colorize OK and EXPECTEDFAIL, respectively as green and yellow

- colorize the summary of failures as well.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini 7b3cca5047 mtest: store TestRuns in collected_failures
Instead of storing the string, store the whole TestRun.  In the
next patches we'll use this to colorize the summary of failures,
and to allow a few more simplifications.

There is some code duplication between the console and logfile
code, but it won't matter as soon as console and logfile output
will be in two completely separate classes.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
Paolo Bonzini eadbf3dbf5 mtest: add test methods to TestResult
Keep the list of "ok" and "bad" statuses close to the definition of
the enum.

Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2020-12-27 13:55:33 +01:00
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
Gerion Entrup 7d01629580 mtest: add gdb_path option
When using the '--gdb' argument of meson test the executed binary can
now be specified with '--gdb-path'.

Closing: #4373
2019-10-04 01:10:07 +03:00
Dylan Baker d6c4e79c84 mtest: Don't require an exe wrapper for if the cross file says we don't need one
Fixes #5970
2019-09-28 18:11:06 +03:00
Marc-André Lureau 6a12f3fc16 mtest: TAP: ignore empty lines
According to http://testanything.org/tap-specification.html

"Any output line that is not a version, a plan, a test line, a
diagnostic or a bail out is considered an “unknown” line. A TAP parser
is required to not consider an unknown line as an error but may
optionally choose to capture said line and hand it to the test
harness, which may have custom behavior attached [...] TAP::Harness
reports TAP syntax errors at the end of a test run".

(glib gtest can generate empty lines)
2019-09-23 13:28:11 -04:00
Aleksey Gurtovoy 75daed27bc mesonlib.split_args/quote_arg/join_args 2019-09-05 23:42:47 +03:00
Thibault Saunier 42c5e4fe2b wine: Try to get the short paths when generating WINEPATH
The size of WINEPATH is limited (1024 [until recently]), we
can very easily reach that limit, and even the new one (2048) so
try to keep path as small as possible by using the shortPath
version of paths.

Also assert that we do not reach the new hard limit.

And avoid having duplicates in the list of path.

[until recently]: https://bugs.winehq.org/show_bug.cgi?id=45810
2019-08-24 06:43:47 -04:00
Michael Hirsch, Ph.D 148a3a83a6 DOC: meson test multiple --suite specifications [skip ci]
docs:wrap < 80 col
2019-07-30 19:08:48 +03:00
Michael Hirsch, Ph.D c904d3eefe remove vestigial $ from test error msg
Also:

* cleanup os.path use to pathlib.Path in associated code
* cleanup subprocess.Popen to subprocess.run
2019-07-27 13:06:41 +00:00
Christoph Weiss 185238fdb4 Change meson test's build failure exit code to 125 2019-07-12 21:51:17 +03:00
Jussi Pakkanen b2cdf528b8 Made TestHarness a context manager to ensure files get closed. 2019-06-21 19:59:09 +03:00
Dylan Baker c571b0b185 mtest: annotate and fix bugs found by annotating
This started out with a bug report of mtest trying to add bytes + str,
which I though "Oh, mypy can help!" and turned into an entire day of
awful code traversal and trying to figure out why attributes were
changing type. Hopefully this makes everything cleaner and easier to
follow.
2019-05-15 09:58:53 -07:00
Dylan Baker df44c86b2f mtest: precompile regular expressions
This should make the matching a little bit faster, and is nicer to look
at.
2019-05-14 11:41:41 -07:00
Dylan Baker 5dca885c5c mtest: reorder imports
I wanted to look at the imports for annotations but was having hard time
reading them because they're just all over the place. This is purely a
human readability issue.
2019-05-14 11:10:18 -07:00
Peter Hutterer 70997ca969 mtest: check for an empty suite list
For consistency, it can be useful to have an explicit empty test suite list
for a test:

   test('test-name', binary, suite: [])

This currently passes meson but fails when running meson tests:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/mesonbuild/mesonmain.py", line 122, in run
    return options.run_func(options)
  File "/usr/lib/python3.7/site-packages/mesonbuild/mtest.py", line 1005, in run
    return th.doit()
  File "/usr/lib/python3.7/site-packages/mesonbuild/mtest.py", line 756, in doit
    self.run_tests(tests)
  File "/usr/lib/python3.7/site-packages/mesonbuild/mtest.py", line 896, in run_tests
    visible_name = self.get_pretty_suite(test)
  File "/usr/lib/python3.7/site-packages/mesonbuild/mtest.py", line 875, in get_pretty_suite
    rv = TestHarness.split_suite_string(test.suite[0])[0]
IndexError: list index out of range

Fix it by simply checking for the test suite to be a valid list we can pass on

Fixes #5340

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
2019-05-02 22:12:58 +03:00
Jussi Pakkanen dc2044c56d Report xpass results as failures. 2019-04-21 03:01:04 +03:00
Paolo Bonzini a2c3ba474a mtest: fix TAP with --verbose (#5160)
* mtest: fix TAP with --verbose

TAP needs to process the test stdout even if --verbose is passed.
Capture it to a separate temporary file, and print it at the end
of the test if --verbose was passed.

In the future, we could parse it on the fly and print the result of
each TAP test point in verbose mode.

* Prefer "stderr is stdout" to "=="

The previous commit used "==" in accordance with the preexisting code,
but reviewers preferred using "is" instead. Fix both occurrences.
2019-04-07 02:42:44 +03:00
Paolo Bonzini 1e7ce3553b do not use Executor if only one process was requested
This will make verbose output nicer, since it will not interleave the test
stdout/stderr and the test results.
2019-03-27 14:04:02 +00:00
Jussi Pakkanen ee863d33c1
Merge pull request #2601 from 1ace/feature/completion
Add completion scripts for Bash and Zsh
2019-03-04 18:40:13 +02:00
Paolo Bonzini 91f847d308 mtest: implement TAP parsing
This provides an initial support for parsing TAP output.  It detects failures
and skipped tests without relying on exit code, as well as early termination
of the test due to an error or a crash.

For now, subtests are not recorded in the TestRun object.  However, because the
TAP output goes on stdout, it is printed by --print-errorlogs when a test does
not behave as expected.  Handling subtests as TestRuns, and serializing them
to JSON, can be added later.

The parser was written specifically for Meson, and comes with its own
test suite.

Fixes #2923.
2019-03-02 09:07:54 +01:00
Paolo Bonzini f2e513791e mtest: add support for hard errors
Hard errors also come from the GNU Automake test protocol.  They happen when
e.g., the set-up of a test case scenario fails, or when some
other unexpected or highly undesirable condition is encountered.

TAP will use them for parse errors too.  Add them to the exitcode protocol
first.
2019-03-02 09:07:54 +01:00
Paolo Bonzini d830945224 mtest: do not use return code to look for failed tests
--print-errorlogs is using the test's return code to look for failed
tests, instead of just looking at the TestResult.  Simplify the code and
make it work for TAP too.
2019-03-02 09:07:54 +01:00
Paolo Bonzini 1264f03637 mtest: refactor TestRun creation
Parse the error code outside SingleTestRunner's run() method.  This
will let us add TAP support without complicating that long method
further.
2019-03-02 09:07:54 +01:00
Eric Engestrom 182eb2ba3a mtest: make `meson test --list` return whether there was any test to list 2019-02-20 18:48:39 +00:00
Yeongjin Jeong a75bda7154 mtest: Don't use thread executor when enabled gdb in test_setup
If the global gdb option of mesontest is disabled (e.g. not set '--gdb')
and the gdb option of test_setup is enabled, an exception will be thrown.

Because signal.signal function can only be called from the main thread.
If attempting to call it from other threads will cause a ValueError exception to be raised.
2019-02-09 00:32:01 +02:00
Olivier Crête 7993747e13 Save surrogates as-is in log files
When python sees an invalid character in a filename for the current locale,
instead of clobbering it, it saves is as an invalid codepoint called a
surrogate.  We need to explicitly instruct the encoder to write those out
as-is. In the JSON file, we replace them instead to produce valid json.
2019-01-06 19:55:55 -05:00
Jussi Pakkanen c6e022b560 Print ASCII version of unrepresentable text. Closes #4600. 2018-12-07 23:12:44 +02:00
Jon Turney 4c4e3c8600 Fix flake8 whitespace reports
$ flake8
./mesonbuild/mtest.py:524:9: E122 continuation line missing indentation or outdented

per PEP8, this line requires more indentation to distinguish it from the
following line
2018-11-19 21:07:37 +02:00
Stian Selnes 0821462ce3 Add kwarg is_default to add_test_setup()
is_default may be used to set the name of the test setup that will be
used by default whenever the option --setup is not given.

Fixes #4430
2018-11-12 16:23:59 +05:30
Dave Reisner 96f8842b79 Report expected failures and unexpected passes separately
This makes it clear in the results that tests marked "should_fail"
exist. We also avoid the all caps output and make the classifications
unambigous compared to pytest or autotools' XFAIL/XPASS.

Before:

  OK:       329
  FAIL:       1
  SKIP:       0
  TIMEOUT:    0

After:

  Ok:                 323
  Expected Fail:        1
  Fail:                 6
  Unexpected Pass:      0
  Skipped:              0
  Timeout:              0
2018-11-08 20:43:42 +02:00
Dylan Baker e921e38301 mtest: Check that stdout is not None before seeking
As can be the case if additional_error is None and verbose is used.

Fixes #4470
2018-11-07 10:27:58 +02:00
Marcel Hollerbach 253c581412 test: do not use PIPE
as instructed in the python docs, you should not use PIPE here. This can
lead to deadlocks, with massive testsuite output. Which was the case for efl.
For now the output of the tests is redirected into the a temp file, the
content from there can then be used to fill the TestRun structure.

This fixes test running problems in efl.
2018-11-04 18:46:50 +02:00
Xavier Claessens 37067a53c4 Use a single ArgumentParser for all subcommands
This has the adventage that "meson --help" shows a list of all commands,
making them discoverable. This also reduce the manual parsing of
arguments to the strict minimum needed for backward compatibility.
2018-10-04 09:40:21 -04:00
Jussi Pakkanen 8ca463f9f1 Guard against the process redirecting stdout. Closes #3967. 2018-09-06 19:19:32 +03:00
Jussi Pakkanen 7e75451867 Try to kill processes even more thoroughly. Closes #4127. 2018-09-06 19:19:32 +03:00
Nirbheek Chauhan fc90c4a331 Print only custom env vars in the test log for each test
We still print the inherited env at the top of the test log because it
is useful when inspecting test results from a CI.

Fixes https://github.com/mesonbuild/meson/issues/3924
2018-08-11 09:15:05 -07:00
Nirbheek Chauhan e8dae2b966 cross: Be more permissive about not-found exe_wrapper
We used to immediately try to use whatever exe_wrapper was defined in
the cross file, but some people generate the cross file once and use
it for several projects, most of which do not even need an exe wrapper
to build.

Now we're a bit more resilient. We quietly fall back to using
non-exe-wrapper paths for compiler checks and skip the sanity check.
However, if some code needs the exe wrapper, f.ex., if you run a built
executable using custom_target() or run_target(), we will error out
during setup.

Tests will, of course, continue to error out when you run them if the
exe wrapper was not found. We don't want people's tests to silently
"pass" (aka skip) because of a bad CI setup.

Closes https://github.com/mesonbuild/meson/issues/3562

This commit also adds a test for the behaviour of exe_wrapper in these
cases, and refactors the unit tests a bit for it.
2018-07-09 05:39:40 +05:30
Nirbheek Chauhan 416a00308f cross: Use ExternalProgram for cross-file exe_wrapper
We already have code to fetch and find binaries specified in a cross
file, so use the same code for exe_wrapper. This allows us to handle
the same corner-cases that were fixed for other cross binaries.
2018-07-09 04:09:46 +05:30
Kurtis Rader 5290f41f31 Report exit status or signal that killed the test
When a test fails due to a signal (e.g., SIGSEGV) it can be somewhat
mysterious why the test failed. Also, even when a test fails due to a
non-zero exit status it would help if the exit status was reported. This
augments the result string to include the non-zero exit status or
signal number and name.

Resolves #3642
2018-06-17 21:22:42 +03:00
Nirbheek Chauhan efa9b75d5d Set WINEPATH when running serialized executables
When the exe runner is `wine` or `wine32` or `wine64`, etc.
This allows people to run tests with wine.

Note that you also have to set WINEPATH to point to your custom
prefix(es) if your tests use external dependencies.

Closes https://github.com/mesonbuild/meson/issues/3620
2018-06-05 10:50:22 +00:00
George Koehler 64906b0755 Don't call getpgid() when killing a test.
OpenBSD's getpgid(2) fails with EPERM (PermissionError) because the
test is in a different session: https://man.openbsd.org/getpgid

Use p.pid as the process group ID, because setsid() created a process
group with the same ID as the process.  See setsid(2) manuals:

 - FreeBSD: https://www.freebsd.org/cgi/man.cgi?query=setsid
 - illumos: https://illumos.org/man/setsid
 - Linux: http://man7.org/linux/man-pages/man2/setsid.2.html

This change fixes 'manual tests/8 timeout' on OpenBSD.  To verify this
change, one must run the manual test.  For example,

    $ cd 'manual tests/8 timeout'
    $ meson build
    $ ninja -C build test

It should report that the test timed out, and not show
PermissionError.

Fixes https://github.com/mesonbuild/meson/issues/3569
2018-05-29 02:14:52 +02:00
Alberto Sartori 717f7db67e improve suite of meson test (#3369) 2018-04-14 22:17:02 +03:00
Jussi Pakkanen be3387d937
Merge pull request #3322 from sarum9in/run_timeout 2018-03-29 21:48:09 +03:00
Aleksey Filippov ddc6f72507 Use consistent quotes 2018-03-28 21:31:04 +00:00
Aleksey Filippov 827d33c8b6 Split SingleTestRunner.run() 2018-03-28 18:57:50 +00:00
Aleksey Filippov 0e8c69b796 Split SingleTestRunner._get_cmd() out of run() 2018-03-28 18:34:02 +00:00
Aleksey Filippov 9596fd6c24 Move run_single_test() into separate class 2018-03-28 18:34:02 +00:00
Aleksey Filippov 3eebb1f83a Make run_single_test() method static
Closes #3318
2018-03-28 18:34:02 +00:00
Aleksey Filippov 9c01fc0e49 Do not access counters from parallel code 2018-03-28 18:34:02 +00:00
Aleksey Filippov 2aa1c3d575 Use enum instead of string constants 2018-03-28 18:33:50 +00:00
Aleksey Filippov 84e3cadc70 Use hermetic parameters in run_single_test(), initialize them before in the caller 2018-03-28 16:44:49 +00:00
Jussi Pakkanen 9b2e533d87 Always build parser objects anew to avoid leaking old data. 2018-03-27 00:39:45 +03:00
nyorain dd614015e0 Open mesontest logfiles in utf-8 mode
Otherwise unit tests fail on windows when they output some
non-utf8 data.
2018-03-20 22:28:59 +02:00
Alicia Boya García 70270d874d meson test: let gdb handle ^C instead of us
Fixes https://github.com/mesonbuild/meson/issues/3156
2018-03-05 00:04:28 +02:00
Hemmo Nieminen 275c737d57 Fix test setup's timeout_multiplier handling. 2018-03-03 21:23:33 +02:00
Hemmo Nieminen e0d0c0166a Avoid unnecessary unpickling of build data during testing. 2018-03-01 01:06:51 +02:00
Hemmo Nieminen 7fb8e518b2 Harmonize data pickling.
Try to be more consistent on using save() and load() methods to pickle
data.
2018-03-01 01:06:51 +02:00
Hemmo Nieminen 060560bf62 Use test setups from the active (sub)project by default.
Replace the logic where a test setup with no project specifier defaults to
the main project with one that takes the test setup from the same
(sub)project from where the to-be-executed test has been read from.
2018-02-25 21:44:59 +02:00
Hemmo Nieminen abcaf7c222 Namespace test setups.
Use $project_name:$test_setup namespace scheme for test setups. This
allows one to choose from which (sub)project a test setup is taken from
should there be several sharing the same name. Defaults to the main
project. E.g. "meson test --setup subproj:valgrind".
2018-02-25 21:44:59 +02:00
Alex Hirsch 3e8eab66a1 Do not set MALLOC_PERTURB_ for benchmarks
Setting MALLOC_PERTURB_ to a non-zero value is fine for regular test
cases. It helps catching bugs, but also comes with some runtime
overhead.

This overhead is noticeable for benchmarks when compared to running them
directly instead of through Meason.

Therefore, MALLOC_PERTURB_ is not touched for benchmarks.

closes #3034
2018-02-12 21:39:28 +02:00
Robert Doolittle 9b27f07002 don't use bare except 2018-01-30 10:17:45 -08:00
Robert Doolittle 60cfb87e69 mtest: catch ctrl-c and properly kill the child processes. Fixes #2281 2018-01-30 10:13:34 -08:00
Aleksey Filippov 2cf85ae16f Use os.path: basename() and dirname() instead of split()
According to Python documentation[1] dirname and basename
are defined as follows:
    os.path.dirname() = os.path.split()[0]
    os.path.basename() = os.path.split()[1]
For the purpose of better readability split() is replaced
by appropriate function if only one part of returned tuple
is used.

[1]: https://docs.python.org/3/library/os.path.html#os.path.split
2018-01-30 07:08:22 +11:00
Dylan Baker d573a29bda mtest: Chdir into the build directory before running tests with -C
When `ninja -C builddir/ test` is run, ninja will change into the build
dir before starting, but `meson test -C builddir/` does not. This is
important because meson does not use (for good reasons) absolute paths,
which means if a test case needs to be passed as an argument a file name
that is part of the build process, it will be relative builddir. Without
changing into the builddir the path will not exist (or worse, point at
the wrong thing), and test will not behave as intended.

To fix this mtest will change directory before starting tests, and will
change back after all tests have been finished.

Fixes #2710
2017-11-30 22:19:54 +02:00
Jussi Pakkanen 5cd8a7bbcc More defensive process killing. Closes #2629. 2017-11-19 18:20:41 +02:00
Eric Engestrom 5f7f5cdb05 Print correct command in help message
Taking mconf for instance:
before:
  $ meson configure --help
  usage: meson [-h] [-D SETS] [--clearcache] [directory [directory ...]]
after:
  $ meson configure --help
  usage: meson configure [-h] [-D SETS] [--clearcache] [directory [directory ...]]
2017-11-09 21:12:34 +02:00
Eric Engestrom 9b6214eb4d mtest: print correct name in error message 2017-10-31 10:11:05 +00:00
Jussi Pakkanen b63710863b Renamed test serialisation from is_cross to is_cross_built for clarity. 2017-09-12 20:32:07 +03:00
Jon Turney b04c4fa878 Add Windows extra_paths to beginning of PATH when running tests
Adding it to the end of PATH means that if an installed instance of a DLL
exists, that would be used instead of the built instance.

Compare with run_exe(), which already gets this right.
2017-09-12 20:28:42 +03:00
Jussi Pakkanen c2e40650e8 Turned mesontest into on internal module. 2017-08-02 22:00:09 +03:00