Commit Graph

26771 Commits

Author SHA1 Message Date
Marco Trevisan (Treviño)
d8e4c1a8f8 gtestutils: Do not make a subtest to Bail out! the root one
This is something that a base test should decide, so if a subtest fails it's
up to the caller to decide whether to bail out the whole suite or just the
subtest.
2023-01-20 15:27:27 +01:00
Marco Trevisan (Treviño)
f5f09445b8 gtestutils: Define TAP version clearly as defined value
As we do in tests
2023-01-20 15:23:59 +01:00
Philip Withnall
e6fbd2afa6 Merge branch 'meson-use-tap-protocol' into 'main'
meson: Use 'tap' test protocol and support TAP 13/14

See merge request GNOME/glib!3140
2023-01-20 13:45:12 +00:00
Marco Trevisan (Treviño)
6a4f6c593c gsettings: Skip tests in the proper way
This will make TAP happier in reporting what's wrong
2023-01-20 14:10:08 +01:00
Marco Trevisan (Treviño)
03f5d0b060 gtestutils: Use test print handler to write subprocess output
When using verbose logging, all the printing and the glib info and debug
logs may end up being written in standard out, making meson TAP parser to be
confused and to fail with TAP parsing errors.

So, in such case write the subprocess output all at once using the the gtest
printer so that we add proper formatting.

Also do not write any gtest result message for subprocesses
2023-01-20 14:10:08 +01:00
Marco Trevisan (Treviño)
8b7b5f5457 gtestutils: Define a custom g_print handler for TAP
When using TAP output in gtest, all the printed strings should be commented
not to break the spec, so enforce this at GTest level, by ensuring that
all the lines written via g_print() will be in the commented form and will
respect the subtest indentation.

As per this we can remove some custom code in g_test_log() as now there are
very few cases in which we need to use the default print handler which is
now private when testing.
2023-01-20 14:10:08 +01:00
Marco Trevisan (Treviño)
3d1736c828 gmessages: Make print handler functions to return default handlers
g_set_print_handler() and g_set_printerr_handler() are supposed to return
the old printer handlers, but in case the default is used NULL is returned
instead.

This makes hard to override the default handler to e.g. decorate the output
with some minor content, without having to rewrite the low-level
implementation.

So, make the default printers to be functions and set them as the default
ones. Also this avoids having to check each time what function to use at
print time.
2023-01-20 14:06:23 +01:00
Marco Trevisan (Treviño)
5d91834d9b gtestutils: Do not generate the random seed if provided
There's no point to generate a seed if we're going to overwrite it when
--seed is used.
2023-01-20 14:06:23 +01:00
Marco Trevisan (Treviño)
871c4b4698 spawn-test-win32-gui: Write state to stderr
Makes TAP happier
2023-01-20 14:06:23 +01:00
Marco Trevisan (Treviño)
1daf05ecda gpoll: Print results to stderr
This will make it compatible with TAP reporting.
2023-01-20 14:06:23 +01:00
Marco Trevisan (Treviño)
04e8c8c719 gio/tests/gsettings: Write subprocess stdout as test message
This won't confuse the meson TAP parser.
2023-01-20 14:06:23 +01:00
Marco Trevisan (Treviño)
49a115d6db tests/logging, testing: Add more tests for cases enforcing gmessages on stderr 2023-01-20 14:06:23 +01:00
Philip Withnall
7514efab05 Merge branch 'gstring-free-and-steal' into 'main'
Add g_string_free_and_steal

See merge request GNOME/glib!3219
2023-01-19 14:47:14 +00:00
Matthias Clasen
58dd3d3965 Add g_string_free_and_steal 2023-01-19 14:47:11 +00:00
Philip Withnall
30d11c4366 Merge branch 'ossfuzz-54577-variant-text-optimisation' into 'main'
gvariant: Optimise g_variant_print() for nested maybes

Closes #2862

See merge request GNOME/glib!3213
2023-01-18 12:40:43 +00:00
Philip Withnall
5283a169d9 gvariant: Remove some unnecessary type assertions on a hot path
While checking the validity of a `GVariantTypeInfo` is good, this code
path is very hot, and I’ve never seen these assertions catch a bug in
practice.

Lean more towards the performance side of the performance/correctness
tradeoff in this case, by removing the assertions here.

They remain in place in a number of other `GVariantTypeInfo` code paths,
so invalid `GVariantTypeInfo` pointers should hopefully still be caught
quickly.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-18 12:12:15 +00:00
Philip Withnall
fa17060027 gvariant: Remove redundant g_variant_serialised_n_children() calls
These functions were previously calling
`g_variant_serialised_n_children()` twice just to validate the input, in
the case that the input was a serialised variant.

That’s not necessary, and checking the number of children in a
serialised variant is not necessarily cheap.

Move the checks around so that the number of children is only checked
once on each code path. This doesn’t introduce any functional changes.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-18 12:12:15 +00:00
Philip Withnall
a1213e343e gvariant: Optimise g_variant_print() for nested maybes
As with commit 9ae59bd647, deeply nested
maybes in an array can be exploited by a malicious caller to cause a
geometric increase in processing time and number of `GVariant` instances
handled by the `g_variant_print()` code.

Optimise this by skipping recursing through most of the chain of maybes,
thus avoiding all the setup checks in each recursive call.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

oss-fuzz#54577
2023-01-18 12:12:12 +00:00
Marco Trevisan
82da45c465 Merge branch 'string-test-leak' into 'main'
tests: Fix a minor leak in the GString tests

See merge request GNOME/glib!3207
2023-01-17 21:55:20 +00:00
Marco Trevisan (Treviño)
b3fd737eaa gmessages: Share the same logic to pick the output for log level
Use the very same logic in both the fallback handler and the default handler
2023-01-17 21:10:47 +01:00
Marco Trevisan (Treviño)
ed8810216a gio/tests: Use default log writer to stderr for launched processes
We don't want to bother TAP parser with subprocess messages when using
verbose logging, so let's just use stderr by default.
2023-01-17 21:08:49 +01:00
Xavier Claessens
19c7d4f15e tests: Use g_test_message() in gdatetime tests 2023-01-17 21:08:49 +01:00
Xavier Claessens
c00135ec73 gtestutils: Do not use default log handler when using TAP
Only use g_test_log() because it will prepend `#` to log messages when
using TAP protocol. Meson >=1.0 rightfully prints a warning when using
TAP protocol and stdout contains non-comment unknown TAP command.
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
f893df4b7d gtestutils: Use TAP 13 comments syntax for subtests
Sadly meson 60 doesn't support parsing TAP 14 subtests properly, so it would
fail.

So temporary go back to the previous logic in a simple way so that this
commit can be reverted quickly when we can use a newer meson version.
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
28b73434be gtestutils: Use TAP version 14 Subtests syntax to show subtests output
Instead of just commenting all the output of sub-processes we can just use
the TAP 14 syntax for subtests, by using 4-spaces to indent the subtests
output.

This may not work perfectly when there are sub-process that may write
output mixed with the parent, but it should be enough to expose the
hierarchy.
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
9cfae23915 gtestutils: Do not allow newlines in Bail out! messages
It would break TAP parsing, so let's just print all inline
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
a3f26bd509 testing: Add TAP test for Bail out! messages 2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
07ff0f7460 gtestutils: Print commented TAP output if running a subprocess
If a gtest process is run as a child of another process, we should not print
the TAP output in plain mode or we'll break the parent results.

We can instead just comment their output so that it gets ignored by TAP
parsers.
2023-01-17 21:08:49 +01:00
Xavier Claessens
28299eb467 gtestutils: "Bail out!" TAP message cannot be multiline
Extra lines must be prepended with `#` which g_test_message() does for
us. Note that lines after "Bail out" are ignored, so we print
stdout/stderr before.
2023-01-17 21:08:49 +01:00
Marco Trevisan (Treviño)
250f3f0644 gtestutils: Write g_test_message() output in a single operation
Do not write it in multiple lines, to ensure it's going to be written
all together, and nothing else could be written in the middle.

Also optimize a bit the code.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
78a206f467 tests/testing, testing-helper: Add test to check g_test_message on TAP
Ensure that g_test_message() output is conformant to TAP specifications.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
f68c49102e gtestutils: Write log to stderr atomically
We used to send the test log to stderr in pieces, but this could be
problematic when running multiple tests in parallel, so let's just prepare
the string in pieces and write it all at once.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
a943d42104 gtestutils: Use TAP format for all the verbose output
In some cases if verbose output was enabled we were using wrong output
format in TAP mode, so let's fix these cases and run the 'testing' test
case in --verbose mode to ensure we won't regress.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
5c799ff01d gtestutils: Write tap test results atomically
When running multiple tests in parallel using meson, the output could be
mixed and if we write the TAP reports in multiple steps the output could
be mangled together with other results.

An example is: https://gitlab.gnome.org/3v1n0/glib/-/jobs/2507620

Where we have:
  ok 5 /cancellable/poll-fd# GLib-GIO-DEBUG: Collecting capable appnames: 0ms
  # Allocating hashtables:...... 0ms
  # Reading capable apps:        63ms
  # Reading URL associations:... 0ms
  # Reading extension assocs:    78ms
  # Reading exe-only apps:...... 47ms
  # Reading classes:             312ms
  # Reading UWP apps:            47ms
  # Postprocessing:..............16ms
  # TOTAL:                       563ms
   # SKIP Platform not supported

Leading to a clear TAP parsing error
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
254c71e7c6 gtestutils: Set the TAP version 13 as first line of tests output
This is not required, but meson may warn about in future versions, so it's
safer to define it.

However, we must be sure that we only expose it once and in the root binary
if a test file launches another subprocess test file.
To avoid this, we set an environment variable at test init, so that it can
be inherited by children.
It's not the best solution, but for sure the best-effort one without having
to change gtest arguments and called binaries.

Non mentioning a version was considered as assuming we were using TAP
version 12, while no version earlier than 13 can be specified
explicitly so let's use it.

See: https://testanything.org/tap-specification.html
And: https://testanything.org/tap-version-13-specification.html
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
d4088e7f2a gio: Use 'cpp' suite for C++ tests
That's what we use for all the tests, so be consistent.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
6efbc7c624 meson: Add 'core' suite to glib (only) tests
As per meson default, the project name is a suite per se that is always
added to a test, so running `meson test --suite=glib` is the same as not
passing the `--suite` argument at all, and so making all the tests to run.

To be able to only run the *glib* tests without using the `--no-suite` args,
add a `core` suite that only targets the glib folder tests.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
1594cf77eb meson: Use exitcode protocol for some c++ and gobject definition tests
In all these cases we don't really care about running the test file,
while building and basic execution it is relevant.

Also they don't support TAP at all.
2023-01-17 21:08:48 +01:00
Marco Trevisan (Treviño)
58031feb17 meson: Use 'tap' test protocol by default
Meson supports tap protocol results parsing, allowing us to track better
the tests that are running (and the ones that are actually skipped) without
manually parsing the test output.

However this also implies that using the verbose mode for a test doesn't
show its output by default (unless there are failures).
2023-01-17 21:08:48 +01:00
Marco Trevisan
f21772ead0 Merge branch 'spawn-test-debugging' into 'main'
tests: Add a test print to spawn-test on Windows

See merge request GNOME/glib!3206
2023-01-17 20:07:25 +00:00
Philip Withnall
13e775dcf6 Merge branch 'print-avoid-allocations' into 'main'
gmessages: Avoid strings duplication if there's nothing to format

See merge request GNOME/glib!3205
2023-01-17 19:57:53 +00:00
Marco Trevisan (Treviño)
71a7603e7f gmessages: Avoid strings duplication if there's nothing to format
g_print(), g_printerr() and all the g_log() functions used to always
duplicating a string when printing even if there's nothing to format.

This can be avoided in many cases though, so if a string has no formatting
directive, we can just write it as it is without duplicating and free'ing
it.

From my tests the potential `strchr` overhead is minimal.
2023-01-17 16:41:54 +01:00
Philip Withnall
91d4100a41 tests: Fix a minor leak in the GString tests
Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-17 15:34:10 +00:00
Philip Withnall
42b8929407 tests: Add a test print to spawn-test on Windows
To try and debug why the following assert sometimes fails on
`msys2-clang64`, such as in this job:
https://gitlab.gnome.org/GNOME/glib/-/jobs/2515166.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>

Helps: #1371
2023-01-17 15:31:03 +00:00
Philip Withnall
438006899e Merge branch 'document-gtask-brokenness' into 'main'
GTask: Document issues

See merge request GNOME/glib!3203
2023-01-16 14:43:20 +00:00
Marco Trevisan
dabb650ad4 Merge branch 'settings-action-per-desktop-default' into 'main'
gsettings: Support per-desktop overrides in GSettingsAction

See merge request GNOME/glib!3193
2023-01-16 13:30:53 +00:00
Matthias Clasen
f999481ec2 GTask: Document issues
We may not be able to fix GTasks broken design,
but at least we should document it and not let
users stumble into this bear trap without warning.

Helps: #1346
2023-01-16 08:19:23 -05:00
Philip Withnall
f7a02efbb7 Merge branch 'issue_2883b' into 'main'
Use 'write' with 'count' <= max value of its return type

Closes #2883

See merge request GNOME/glib!3200
2023-01-16 13:08:43 +00:00
CCode
e9e4d52de8 gfileutils: Use 'write' with 'count' <= max value of its return type
Limit `count` so that `write` can properly report the number of written bytes.

Limits:
 - POSIX: `SSIZE_MAX`
 - Windows: `INT_MAX`

Fixes: #2883
2023-01-16 13:08:42 +00:00
Philip Withnall
26728b4ecc Merge branch 'gstring-optimizations' into 'main'
Some GString optimizations

See merge request GNOME/glib!3199
2023-01-16 12:38:54 +00:00