Commit Graph

2218 Commits

Author SHA1 Message Date
Colin Walters
8d7c1f9b75 tests: Finish update of gdbus-example-proxy-subclass to new GDBus API
This fixes bug #624696.

Incorporates a more recent change from 1dc774a653 to drop the
`g_type_init()` call, and reformats the indentation a bit.

Fixes: #322
2023-03-20 13:03:04 +00:00
Philip Withnall
9d7c796f1e Merge branch 'fix-monitor-root-directory-fail' into 'main'
inotify: Avoid empty root directory string

See merge request GNOME/glib!3241
2023-03-16 12:12:01 +00:00
Philip Withnall
f535d0915f tests: Add a test for creating a file monitor on the root directory
While we can’t check for any events on it, this at least tests that
creating a file monitor works. It should cover the fix from the previous
commit.

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

Helps: !3241
2023-03-15 14:45:10 +00:00
Philip Withnall
1a9be3a1c8 tests: Add a test for D-Bus activating an unknown app with a context
This should catch regressions in the critical warning fixed in the
previous commit.

The launch has to have several conditions:
 - Session bus is running (to avoid the launch happening via the spawn
   codepath)
 - Use a non-existent D-Bus name (to trigger a launch error)
 - Use a launch context (to hit the critical warning code path)
 - Not have a startup ID specified in the platform data — this implies
   having an empty launch context
 - Use an async launch, as that provides an error handling path

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-15 13:50:51 +00:00
Philip Withnall
764f8426d4 tests: Remove explicit timeout handler from gdbus-auth tests
The timeout runs for the entire duration of the test, which is a
function that Meson’s test harness already provides for us.

Meson’s timeout can be easily adjusted by a factor to allow for running
tests more slowly under valgrind. The timeout in the code cannot, which
leads to spurious failures like
https://gitlab.gnome.org/GNOME/glib/-/jobs/2645271.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-13 11:21:17 +00:00
Philip Withnall
642ee744b8 tests: Fix g_source_remove() of non-existent source in gapplication test
If the timeout callback was executed, it would remove the timeout
source, leaving the `g_source_remove()` call in the main function with a
dangling source ID.

Fixes commit 73205b8bbd.

Spotted in https://gitlab.gnome.org/GNOME/glib/-/jobs/2645271.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-03-13 11:19:56 +00:00
Markus Volk
caab1a41dc gio/tests/cxx.cpp: fix missing sentinel for musl
This fixes:
| ../glib-2.75.3/gio/tests/cxx.cpp: In function 'int main(int, char**)':
| ../glib-2.75.3/gio/tests/cxx.cpp:61:15: error: missing sentinel in function call [-Werror=format=]
|    61 |   g_test_init (&argc, &argv, NULL);

if built with musl libc

Signed-off-by: Markus Volk <f_l_k@t-online.de>
2023-02-23 15:02:26 +01:00
Simon McVittie
88fd3f0a76 Merge branch 'build-with-llvm-toolchain' into 'main'
Fix building gio/tests/test_resources.o with LLVM ld

Closes #2720

See merge request GNOME/glib!3186
2023-02-22 16:51:05 +00:00
Philip Withnall
5d469dbe5a tests: Remove custom printerr logging from live-g-file
Use `g_test_message()` instead, so that the logs get treated properly
for TAP output.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-02-16 13:50:15 +00:00
Philip Withnall
bde724e5ac Revert "Revert "tests: Temporarily disable socket test due to a kernel bug""
This reverts commit 27bee8fe5d.

Inevitably, despite testing the CI multiple times before merging commit
27bee8fe, the CI is now failing again in the `socket` test due to (what
I continue to assume is) the kernel regression:

https://gitlab.gnome.org/martinpitt/glib/-/jobs/2585332

In order to unblock development on `main` expediently, I guess I’ll just
revert the revert.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
Reopens: #2879
2023-02-15 13:23:13 +00:00
Philip Withnall
27bee8fe5d Revert "tests: Temporarily disable socket test due to a kernel bug"
This reverts commit 1507585869.

Maybe it works now? It will work as soon as the CI host kernel is
updated.

Fixes: #2879
2023-02-13 19:35:30 +00:00
Marco Trevisan
155e44652e Merge branch 'gstring-free-warning' into 'main'
Make g_string_free (_, FALSE) warn on unused result

See merge request GNOME/glib!3226
2023-02-01 16:28:02 +00:00
Philip Withnall
bd5e57ef17 tests: Fix a few minor leaks in gdbus-example-peer
One leak spotted by the Coverity, the others found via valgrind.

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

Coverity CID: #1504322
2023-01-31 11:44:44 +00:00
Alex Richardson
c434743111 Fix build of gio/ttests/est_resources2.o with LLVM objcopy
LLVM objcopy's --strip-all is more aggressive that GNU objcopy --strip-all
and will remove everything that is not actually used. In this case we
see the following error:
`error: 'gio/tests/test_resources.o': Symbol table has link index of 5 which is not a valid index`

Fix this by only removing debug symbols instead of all unused symbols and
sections.

Helps: https://gitlab.gnome.org/GNOME/glib/-/issues/2720
2023-01-28 10:46:50 +00:00
Alex Richardson
6d93568e36 Fix building gio/tests/test_resources.o with LLVM ld
Unlike GNU ld which has a default target architecture, ld.lld is always a
cross-linker and has the same behaviour for all targets. If you don't tell
ld.lld what the target architecture is it can't infer the right ELF flags
for the resulting object file.
```
$ ~/cheri/output/sdk/bin/ld -r -b binary gio/tests/test5.gresource -o gio/tests/test_resources.o -v
LLD 14.0.0 (compatible with GNU linkers)
ld: error: target emulation unknown: -m or at least one .o file required
```

As you can see from the error message it can't infer the target
architecture (you need a least one valid .o file or the -m flag).
If you use the compiler instead of directly invoking the linker it will
pass the appropriate flags:
```
$ ~/cheri/output/sdk/bin/clang -r -Wl,-b,binary gio/tests/test5.gresource -o gio/tests/test_resources.o -v
clang version 14.0.0 (https://github.com/CTSRD-CHERI/llvm-project.git ff66b683475fc44355b2010dbcbe1202d785e6f8)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /home/alexrichardson/cheri/output/sdk/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/10
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/11
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/12
Candidate multilib: .;@m64
Selected multilib: .;@m64
 "/home/alexrichardson/cheri/output/sdk/bin/ld" --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o gio/tests/test_resources.o -L/usr/lib/gcc/x86_64-linux-gnu/12 -L/usr/lib/gcc/x86_64-linux-gnu/12/../../../../lib64 -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/../lib64 -L/home/alexrichardson/cheri/output/sdk/bin/../lib -L/lib -L/usr/lib -r -b binary gio/tests/test5.gresource
❯ file gio/tests/test_resources.o
gio/tests/test_resources.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), not stripped
```

This works for most architectures, but ones that need additional metadata
sections to encode the used ABI, etc. will require a different approach
using .incbin. However, that is a change for another MR.

Partially fixes: https://gitlab.gnome.org/GNOME/glib/-/issues/2720
2023-01-28 10:46:50 +00:00
Sergey Bugaev
c121118bc4 tests: Silence a warning
In case the OS does not support epoll and kqueue, we get the warning:

gio/tests/pollable.c: In function ‘test_pollable_unix_nulldev’:
gio/tests/pollable.c:266:7: warning: unused variable ‘fd’
[-Wunused-variable]
  266 |   int fd;

Get rid of it.

Signed-off-by: Sergey Bugaev <bugaevc@gmail.com>
2023-01-27 11:58:56 +03:00
Marco Trevisan (Treviño)
23da6bade0 {glib,gio}/cxx: Add more tests for C++ inline funcs
These could behave differently in C++ so let's ensure this is not the
case.
2023-01-26 16:52:36 +01:00
Marco Trevisan
452e9957a4 Merge branch 'leak-suppressions' into 'main'
Add a few suppressions to glib.supp and fix a minor bug in gapplication test

See merge request GNOME/glib!3223
2023-01-26 15:40:22 +00:00
Philip Withnall
ac30b7d824 Merge branch 'leak-fix' into 'main'
tests/desktop-app-info: fix stack-use-after-scope

See merge request GNOME/glib!3187
2023-01-26 15:36:22 +00:00
Marc-André Lureau
f50a4f8501 tests/desktop-app-info: fix stack-use-after-scope
Fix the tests, by allocating the structure.

==121338==ERROR: AddressSanitizer: stack-use-after-scope on address 0x7ffe44018610 at pc 0x00000040ff71 bp 0x7ffe440178f0 sp 0x7ffe440178e8
READ of size 8 at 0x7ffe44018610 thread T0
    #0 0x40ff70 in test_launch_uris_with_terminal ../gio/tests/desktop-app-info.c:1393
    #1 0x7efd97b831e8 in test_case_run ../glib/gtestutils.c:2947
    #2 0x7efd97b831e8 in g_test_run_suite_internal ../glib/gtestutils.c:3037
    #3 0x7efd97b82d23 in g_test_run_suite_internal ../glib/gtestutils.c:3056
    #4 0x7efd97b82d23 in g_test_run_suite_internal ../glib/gtestutils.c:3056
    #5 0x7efd97b82d23 in g_test_run_suite_internal ../glib/gtestutils.c:3056
    #6 0x7efd97b84189 in g_test_run_suite ../glib/gtestutils.c:3136
    #7 0x7efd97b842c5 in g_test_run ../glib/gtestutils.c:2248
    #8 0x4055bc in main ../gio/tests/desktop-app-info.c:1901
    #9 0x7efd9564a50f in __libc_start_call_main (/lib64/libc.so.6+0x2750f)
    #10 0x7efd9564a5c8 in __libc_start_main_alias_1 (/lib64/libc.so.6+0x275c8)
    #11 0x4059f4 in _start (/home/elmarco/src/gnome/glib/build/gio/tests/desktop-app-info+0x4059f4)

Address 0x7ffe44018610 is located in stack of thread T0 at offset 128 in frame
    #0 0x404d1f in main ../gio/tests/desktop-app-info.c:1823

  This frame has 6 object(s):
    [48, 52) 'argc' (line 1821)
    [64, 72) 'path' (line 1870)
    [96, 104) 'argv' (line 1822)
    [128, 144) '<unknown>' <== Memory access at offset 128 is inside this variable
    [160, 176) '<unknown>'
    [192, 288) 'supported_terminals' (line 1825)

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
2023-01-24 23:43:20 +04:00
Philip Withnall
1507585869 tests: Temporarily disable socket test due to a kernel bug
There’s a kernel bug on the CI machines which is causing this test to
fail all the time and it’s getting my goat.

The test can be re-enabled later (by reverting this commit) when the
kernel on the CI VM host is fixed. I don’t know when that’s going to
happen.

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

Helps: #2879
2023-01-24 11:46:25 +00:00
Philip Withnall
73205b8bbd tests: Explicitly remove a timeout handler in gapplication test
Otherwise if, for whatever reason, the `app` loses its D-Bus name,
`g_application_quit()` is called from `name_was_lost()` before it’s
called from `quit_already()`, and then `quit_already()` does an invalid
read on `app`.

If the name was not meant to be lost at this point in the test, the
subsequent `g_assert_false (name_lost)` will catch that, so this change
shouldn’t cause the test to pass unnecessarily.

Signed-off-by: Philip Withnall <pwithnall@endlessos.org>
2023-01-24 11:25:34 +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)
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)
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
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)
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
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
Marco Trevisan (Treviño)
45ec0aa81e tests/gsettings: Check that per-desktop settings are used by GAction's 2023-01-14 04:17:51 +01:00
banjiuqingshan
d9a1d7524f gio/tests/file.c: Fix expectations when running as root
Includes tweaks by Philip Withnall.
2023-01-13 22:21:07 +00:00
Emmanuele Bassi
684d9aa0c3 build: Don't overwrite build variables
We cannot use `gvisibility_h` for different visibility header files; you
never know when you're going to refer to the variable again, and
projects might end up needing to retrieve the variable contents—like,
for instance, gobject-introspection using glib as a subproject.
2023-01-08 00:33:14 +00:00
Philip Withnall
73fa684e30 Merge branch 'ptr-array-sort-values' into 'main'
garray: Add g_ptr_array_sort_values[_with_data]() wrappers

See merge request GNOME/glib!3155
2023-01-06 12:09:37 +00:00
Marco Trevisan (Treviño)
861e82efbc gio: Use g_ptr_array_sort_values()
Cleanup some code using GPtrArray sorting with functions that were taking
pointer to pointers arguments.
2023-01-06 11:46:01 +00:00
Guido Günther
4cb945d780 codegen: Support markdown suitable for gi-docgen 2022-12-29 12:42:12 +00:00
Philip Withnall
9e2ad88455 Merge branch 'search-app-prefix-strstr' into 'main'
gdesktopappinfo: Group search results by both categories and match types

See merge request GNOME/glib!3107
2022-12-21 11:42:35 +00:00
Alynx Zhou
0e612effbe tests: Update search tests for desktop-icon-info
Because we now put substring match in the next group of prefix match,
the test cases should also be updated.
2022-12-20 09:59:09 +08:00
Philip Withnall
d3a26bb4de Merge branch 'activation-token' into 'main'
gdesktopappinfo: Set XDG_ACTIVATION_TOKEN/activation-token startup ID key

Closes #2709

See merge request GNOME/glib!3090
2022-12-19 13:05:57 +00:00
Ilya Fedin
627f2738e0 gdesktopappinfo: Set XDG_ACTIVATION_TOKEN/activation-token startup ID key
See:
 * https://gitlab.freedesktop.org/xdg/xdg-specs/-/blob/master/desktop-entry/desktop-entry-spec.xml#L1061-1068
 * https://wayland.app/protocols/xdg-activation-v1
 * https://gitlab.freedesktop.org/wayland/wayland-protocols/-/blob/main/staging/xdg-activation/x11-interoperation.rst

Fixes: #2709
2022-12-19 12:45:02 +00:00
Philip Withnall
a8826215b0 Merge branch 'fix-cancellable-connect-race' into 'main'
GCancellable: Ensure it is always cancelled on connect callback

See merge request GNOME/glib!2764
2022-12-16 18:11:03 +00:00
Alex Richardson
994f96fb2b tests/gdbus-method-invocation: Fix missing g_variant_new() argument
I noticed this when running the test on an Arm Morello system where varargs
have bounds. g_variant_new() was trying to read an integer using va_arg(),
but since there was no argument it resulted in a bounds errors there.
On most other architectures this will just read whatever value is contained
in the next argument register and is not something that ASan can detect, so
it never resulted in test failures.
2022-12-16 10:28:50 +00:00
Marco Trevisan (Treviño)
cdda03a690 GCancellable: Ensure it is always cancelled on connect callback
When a cancellable is cancelled when we call g_cancellable_connect we
used to immediately call the provided callback, while this is fine we
actually had race in case the cancellable was about to be reset or in
the middle of a cancellation.

In fact it could happen that when we released the mutex, another thread
could reset the cancellable just before the callback is actually called
and so leading to call it with g_cancellable_cancelled() == FALSE.

So to handle this, make disconnect and reset function to wait for
connection emission to finish, not to break their assumptions.

This can be tested using some "brute-force" tests where multiple threads
are racing to connect and disconnect while others are cancelling and
resetting a cancellable, ensuring that all works as we expect.
2022-12-15 19:30:43 +01:00
Philip Withnall
8a60c22bb4 Merge branch '861-dbus-menu-model-robustness' into 'main'
gmenumodel: disallow exporting large menus on the bus

Closes #861

See merge request GNOME/glib!3133
2022-12-14 16:18:07 +00:00
Lars Uebernickel
89a7bbcf6e gmenumodel: disallow exporting large menus on the bus
This solves problems with validating untrusted inputs from D-Bus, where
invalid numbers of added and removed menu entries, and positions, could
be specified.

Original patch from
https://bugzilla.gnome.org/show_bug.cgi?id=728733#c7, tweaked by Philip
Withnall to add a few code comments and make
`G_MENU_EXPORTER_MAX_SECTION_SIZE` public so callers can check their
inputs against it if they want. Also tweaked to use `g_warning()` instead
of the nonexistent `g_dbus_warning()`.

Fixes: #861
2022-12-14 15:42:14 +00:00
Philip Withnall
a2c8a8c630 tests: Release GApplication a little later to avoid assertion failures
If it takes one more `GMainContext` cycle than expected for the
`activate` signals to be handled, the `GApplication` under test can be
released too early, and the test will fail due to not seeing a high
enough value of `n_activations`.

Hopefully avoid that by moving the release to a low priority idle
callback.

This fix is only hopeful because I’ve only been able to reproduce the
failure on FreeBSD CI and not locally.

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

Fixes: #2835
2022-12-14 09:33:18 +00:00
Marco Trevisan
a9e8b3f7e4 Merge branch '2837-test-timeouts' into 'main'
tests: Increase a timeout in contexts test

Closes #2837

See merge request GNOME/glib!3122
2022-12-13 14:57:44 +00:00
Philip Withnall
cad9256c3d tests: Increase a timeout in contexts test
The timeout is just to stop the test hanging forever, so there’s no need
for it to be so short. It’s caused at least one spurious CI failure:
https://gitlab.gnome.org/GNOME/glib/-/jobs/2445023.

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

Fixes: #2837
2022-12-13 14:07:58 +00:00
Philip Withnall
3c15df01c8 Merge branch 'wip/3v1n0/desktop-app-info-fail-on-not-existent' into 'main'
gdesktopappinfo: Fail early if trying to launch an invalid executable and always use desktop Path and context $PATH

See merge request GNOME/glib!3042
2022-12-13 13:01:09 +00:00
Marco Trevisan (Treviño)
511d1cad02 gdesktopappinfo: Fail early if trying to launch an invalid executable
GDesktopAppInfo never failed in the most simple of the cases: when a
desktop file or a command line app info was pointing to an invalid
executable (for the context).

The reason for this is that we're launching all the programs using
gio-launch-desktop which will always exist in a sane GLib installation,
and thus our call to execvp won't ever fail on failure.

This was partially mitigated by not allowing to create a desktop app
icon using a non-existent executable (even if not fully correctly) but
still did not work in case a custom PATH was provided in the launch
context.

To avoid this, use g_find_program_for_path() to find early if a program
that we're about to launch is available, and if it's not the case return
the same error that g_spawn_async_with_fds() would throw in such cases.

While this is slowing a bit our preparation phase, would avoid to leave
to the exec function the job to find where our program is.

Add tests simulating this behavior.
2022-12-12 15:58:13 +01:00
Marco Trevisan (Treviño)
da8aa0b66d desktop-app-info: Use launch context PATH and desktop Path to find terminals
We used to launch applications with terminals using the normal program
finder logic that did not consider the context path nor the desktop file
working dir. Switch to g_find_program_for_path() to find terminals so we
can ensure that both conditions are true.

Update tests to consider this case too.
2022-12-12 15:58:13 +01:00