Commit Graph

2447 Commits

Author SHA1 Message Date
Benjamin Gilbert
51e3e7d9ae build: Bump Meson dependency to 1.4.0
Meson 1.5.1 is available in the fd.o SDK and in Debian testing, so the
glib Meson policy says we can update.  Update the minimum only as far as
1.4.0 because we don't yet have a need for 1.5.0.

This allows us to:

- Use file.full_path() to avoid deprecation warnings on str.format(file).
- Set c_std=gnu99,c99 to avoid deprecation warnings with gnu99 on MSVC.

Update all the CI builds to use the latest 1.4.x patch release, 1.4.2.

The FreeBSD runner cannot be updated via `gitlab-ci.yml`, so will be
broken for now.

Similarly, the macOS build will not work unless `-Dc_std=gnu99` is
specified at configure time, due to
https://github.com/mesonbuild/meson/issues/13639.
2024-09-12 19:15:05 +01:00
Philip Withnall
27c02a0be4
tests: Test against a sample mtab file in unix-mounts for getmntent()
The test in `unix-mounts` to see whether `g_unix_mounts_get_from_file()`
can parse an example file was working fine when GLib is built with
libmount, but not when built without it (and hence typically using
`getmntent()`).

This is because libmount supports mountinfo files (like
`/proc/self/mountinfo`), but `getmntent()` only supports mount files
(like `/proc/mounts`). The test was written only with the former.

So, change the test to use mount files when GLib is built without
libmount support.

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

Fixes: #3456
2024-08-27 12:13:35 +01:00
Philip Withnall
ce71da63ba
Revert "gio/tests/cancellable: Explain failure on GCancellableSource tests on valgrind"
This reverts commit 365411ea32.

Since commit 3a07b2abd4, issue 2309 has
been fixed, so we should no longer have failures from valgrind here.
2024-08-20 13:02:43 +01:00
Philip Withnall
71cd903118
tests: Run expected-to-hang cancellable tests in subprocesses
These tests are expected to cause a thread to deadlock. That seems to be
fine with glibc on Linux, but the glibc version on FreeBSD can detect
the deadlock, and aborts the whole test process with:
```
GLib (gthread-posix.c): Unexpected error from C library during 'pthread_mutex_lock': Resource deadlock avoided.  Aborting.
```

This is fair enough.

To avoid this causing the test suite to fail, run those two tests in
subprocesses. This also means we’re not carrying a deadlocked thread
around for the rest of the test suite.

Improves on commit 62192925b6.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-08-20 13:02:36 +01:00
Philip Withnall
f4aceb0e91 Merge branch 'wip/pwithnall/unix-mount-tests' into 'main'
gunixmounts: Add mount point/entry getters from files and add tests based on them

See merge request GNOME/glib!4163
2024-08-15 14:25:52 +00:00
Philip Withnall
04ee011171
tests: Add tests for handling of fstab and mtab files
While GLib doesn’t parse these files, it does provide API to access the
fields from them, and does implement some logic based on options fields
in them. It would be nice to be able to test that, and get coverage of
the methods for `GUnixMountPoint` and `GUnixMountEntry`.
2024-08-14 15:52:02 +01:00
Arjan Molenaar
2ad61ed0ee Fix formatting issues 2024-08-10 19:42:32 +02:00
Arjan Molenaar
d23c781e7b macos: Tune launch results for CI
It looks like we have no Finder running.
2024-08-10 19:34:29 +02:00
Arjan Molenaar
1053c016d9 macos: Add test case for invalid scheme
You may not always know which schemes are available.

The library should not bail out, but only show
an informal message. It's the responsibility of
the application to deal with invalid URI schemes.
2024-08-10 19:34:29 +02:00
Arjan Molenaar
fac8a8c8d8 macos: Add test for async launcher
The test brings a Finder window to the front. It's not ideal,
but I have no better idea at the moment. It would be cool if we
can make the test case register itself as handler for a particular
uri scheme, but I have no idea how to do that.
2024-08-10 19:34:29 +02:00
Marco Trevisan (Treviño)
3a07b2abd4 GCancellable: Use per-instance mutex logic instead of global critical sections
GCancellable is meant to be used in multi-thread operations but all the
cancellable instances were sharing a single mutex to synchronize them
which can be less optimal when many instances are in place.
Especially when we're doing a lock/unlock dances that may leave another
thread to take the control of a critical section in an unexpected way.

This in fact was leading to some races in GCancellableSources causing
leaks because we were assuming that the "cancelled" callback was always
called before our dispose implementation.

As per this, use per-instance mutexes.

The lock is also now used only to protect the calls that may interact
with cancelled state or that depends on that, as per this we can just
reduce it to the cancel and reset case, other than to the connect one to
prevent the race that we could have when connecting to a cancellable
that is reset from another thread.

We don't really need to release the locks during callbacks now as they
are per instance, and there's really no function that we allowed to call
during a ::cancelled signal callback that may require an unlocked state.
This could been done in case with a recursive lock, that is easy enough
to implement but not really needed for this case.

Fixes: #2309, #2313
2024-07-24 00:21:35 +02:00
Marco Trevisan (Treviño)
0a8cb10f22 gio/tests: Ensure that a GCancellableSource can be used muliple times
Closes: #774
2024-07-24 00:21:35 +02:00
Philip Withnall
929f2ae06b
tests: Fix compilation of resolver-parsing test on FreeBSD
This fixes commit cdcb179808.

`dn_comp()` is needed to build fake DNS records for most of the tests in
this file. The new ownership test is no exception.

See https://gitlab.gnome.org/GNOME/glib/-/jobs/4058481

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-07-09 21:41:03 +01:00
Philip Withnall
8d0bf4ed39
tests: Make an error check less specific in gsocketclient-slow
On Linux the error will be `G_IO_ERROR_CONNECTION_REFUSED`, but on macOS
it will be `G_IO_ERROR_TIMED_OUT`. Both errors seem reasonable to me, so
let’s not specifically require one of them.

See: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/4104#note_2161451

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-07-09 17:40:16 +01:00
Philip Withnall
8320085557 Merge branch 'andyholmes/resolver-ownership' into 'main'
gthreadedresolver: ref-sink returned records in lookup_records()

Closes #3393

See merge request GNOME/glib!4110
2024-07-05 06:26:51 +00:00
Andy Holmes
cdcb179808
tests: ensure DNS records are full-reference variants
For each test expected to return valid DNS records, test that the
record variants are not floating references.

Also add an test which checks this explicitly for a simple TXT record.
2024-07-04 17:37:44 -07:00
Benoit Pierre
caf7f8ef49 tests: fix some Windows testsuite failures
Add test dependencies on the 2 spawn helpers required on Windows.
2024-07-04 19:35:47 +00:00
Gleb Popov
6daebde9a6 Fix gsocketclient-slow test on FreeBSD
The "port" variable ends up being 0 even after successful g_socket_bind.
Use g_socket_get_local_address() to actually get a correct port number.
2024-06-30 15:37:22 +03:00
Gary Li
d64336e1a9 g_output_stream_write: Allow NULL buffer if count is 0
We currently fail a buffer != NULL assertion if buffer is NULL and count is 0. Allow this case without critical assertions.

Fixes https://gitlab.gnome.org/GNOME/glib/-/issues/3402
2024-06-26 14:18:41 -04:00
rong wang
478127e074 GLocalFile: support trashing long file name
When the file name is too long (for example, more than 238 bytes on
ext4), this will cause the creation of the .trashinfo file to fail.
Let's shorten the .trashinfo filename in this case, after all the
trash specification only requires unique filenames (see
`Contents of a trash directory` section in
https://specifications.freedesktop.org/trash-spec/trashspec-latest.html).
2024-06-19 10:27:33 +01:00
Philip Withnall
cce6ca8c88
tests: Improve 4GB file loading test to work on i386
This should test the limits of loading 4GB files on i386 platforms, such
as the Hurd CI runner. On such platforms, `sizeof(size_t) == 4`.

This should fix the compiler warning from
https://gitlab.gnome.org/GNOME/glib/-/jobs/3989442:
```
../gio/tests/file.c:2931:51: error: left shift count >= width of type [-Werror=shift-count-overflow]
 2931 | static const gsize testfile_4gb_size = ((gsize) 1 << 32) + (1 << 16); /* 4GB + a bit */
      |                                                   ^~
cc1: all warnings being treated as errors
```

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-18 12:58:51 +01:00
Philip Withnall
1f838b061b
tests: Skip >4GB file tests unless running tests in slow/thorough mode
They take too long to include in a normal test run. They’ll still be run
in CI once a week as part of our scheduled slow test job.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-17 13:03:08 +01:00
Philip Withnall
a8be45204e tests: Fix a typo in a test name in the file test suite
Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-17 13:03:05 +01:00
Benjamin Otte
e74294473e tests: Add test for >4GB reads with g_file_load_contents()
The tests - one for sync, one for async - create a sparse file for
this purpose, so this should be cheap on the fileystem.

Of course, the test still allocates >4GB of memory for the data that it
returns from g_file_load_contents(), I hope the CI test runners can deal
with that.
2024-06-17 13:03:05 +01:00
Benjamin Otte
77c35415a3 tests: Use g_clear_fd() 2024-06-17 13:03:05 +01:00
Philip Withnall
577ad8d07d
tests: Use g_assert_*() rather than g_assert() in notification tests
It won’t get compiled out with `G_DISABLE_ASSERT`.

Signed-off-by: Philip Withnall <pwithnall@gnome.org>
2024-06-14 23:05:25 +01:00
Natanael Copa
2c042cd466 tests: find update-desktop-database
Disable tests that require update-desktop-database when it is missing.

It requires glib to build so it will be missing when bootstrapping glib.

Refactor the ifdef for Windows and MacOS while at it and reduce number
of ifdefs.

Ref: https://gitlab.gnome.org/GNOME/glib/-/merge_requests/3658
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2024-06-14 16:35:44 +01:00
Natanael Copa
7322a925e2 tests: skip tests that requires dbus-daemon when its missing
dbus may not be built yet during bootstrap, because it needs glib to
build.

Ref: https://gitlab.gnome.org/GNOME/glib/-/issues/3317
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2024-06-14 16:35:44 +01:00
Natanael Copa
6a262b0c03 tests: skip test that requires shared-mime-info when its missing
shared-mime-info required glib to build and will not be there during
bootstrap. Skip the test if it is missing.

ref: https://gitlab.gnome.org/GNOME/glib/-/issues/3317
Signed-off-by: Natanael Copa <ncopa@alpinelinux.org>
2024-06-14 16:35:44 +01:00
Philip Withnall
f09a8e2be4
gioerror: Map EADDRNOTAVAIL to G_IO_ERROR_CONNECTION_REFUSED
Previously it was mapped (as a default) to `G_IO_ERROR_FAILED`.

It’s the error that macOS returns when trying to connect to a socket which
is bound but not listened to. Linux returns `ECONNREFUSED` in this case.
It’s helpful if they both map to the same `GIOError` value.

This should fix the `/socket-client/connection-fail` test on macOS,
which is currently
[failing](https://gitlab.gnome.org/GNOME/glib/-/jobs/3970547) with:
```
 # GLib-GIO-DEBUG: GSocketClient: Starting TCP connection attempt
 # GLib-GIO-DEBUG: GSocketClient: Connection attempt failed: Can't assign requested address
 # GLib-GIO-DEBUG: GSocketClient: Starting new address enumeration
 # GLib-GIO-DEBUG: GSocketClient: Address enumeration completed (out of addresses)
 # GLib-GIO-DEBUG: GSocketClient: Address enumeration failed: (null)
 # GLib-GIO-DEBUG: GSocketClient: Connection failed: Could not connect to localhost: Can't assign requested address
not ok /socket-client/connection-fail - GLib-GIO:ERROR:../gio/tests/gsocketclient-slow.c:231:test_connection_failed: assertion failed (local_error == (g-io-error-quark, 39)): Could not connect to localhost: Can't assign requested address (g-io-error-quark, 0)
Bail out!
```

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

See: #3184
Fixes: #3394
2024-06-13 20:00:12 +01:00
Johan Sternerup
61e006e16c gsocketclient: Add unit test for leak of task data in error path
The unit test cover the error path that causes the leak described in
https://gitlab.gnome.org/GNOME/glib/-/issues/3184.
2024-06-05 12:54:15 +01:00
Simon McVittie
510d0716be gdbus: Use symbolic constants for the most common D-Bus error names
To avoid adding a large block of macros to gdbusprivate.h, I've only
added a subset of the well-known error names. I chose to draw the
line by adding constants for the errors emitted via their string names
in GDBusConnection, but not for error names that are only mentioned
in `gdbuserror.c` or in tests.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
7c609f8142 gdbus: Use symbolic constants for interfaces from dbus-specification
Most D-Bus interfaces are domain-specific, but these interfaces from the
D-Bus Specification are intended to be commonly used in any context for
which they are found to be appropriate.

Most of these use `gdbusprivate.h`. One exception is that
`gio/tests/gdbus-example-*` redefine the constants locally: due to these
files' dual role as part of the unit tests and as sample code, it seems
desirable to ensure that they can still be compiled outside GLib.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
b4f8d4a5d5 gdbus: Use symbolic constants for the reserved Local path and interface
These are reserved by the D-Bus Specification.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
7401577074 gdbus: Move protocol constants from gdbusdaemon into gdbusprivate.h
These well-known flags and replies are part of the D-Bus Specification,
and also exist with the same names in libdbus header files.
Moving them into a private header means that unit tests like
gdbus-proxy-threads and gdbus-subscribe don't have to reinvent them.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
131a061aca gdbus: Use symbolic constants for various references to the message bus
Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
19223803f5 gdbus: Use symbolic constants to subscribe to message bus signals
Unlike the various functions to call D-Bus methods, these sort their
arguments in a non-obvious order (bus name, interface, signal, path),
presumably aiming to sort the most-likely-to-be-used arguments first.

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:23 +01:00
Simon McVittie
fe14968c0d gdbus: Use symbolic constants to call message bus methods
These function arguments are arranged in the obvious order from
conceptually largest to smallest: (bus name, path, interface, method).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:22 +01:00
Simon McVittie
2151a82007 gdbus tests: Fix a typo
This test was subscribing to the NameOwnerChanged signal with an
incorrect object path, so the callback would never be called. In this
particular case it doesn't actually matter, because the callback does
nothing anyway (the purpose of this particular test was to test that
the user-data is freed on unsubscription).

Signed-off-by: Simon McVittie <smcv@collabora.com>
2024-05-16 22:52:22 +01:00
Philip Withnall
7a7137838e
gactiongroupexporter: Fix memory problems on an error handling path
Almost identically to the previous commit, fix a similar latent bug in
`g_dbus_connection_export_action_group()`, which was not ready to handle
the fledgling `GActionGroupExporter` being freed early on an error
handling path.

See the previous commit message for details of the approach.

This includes a unit test.

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

Fixes: #3366
2024-05-15 14:00:09 +01:00
Philip Withnall
df2c5d925a
gmenuexporter: Fix a NULL pointer dereference on an error handling path
This latent bug wasn’t triggered until commit 3f30ec86c (or its
cherry-pick onto `glib-2-80`, 747e3af99, which was first released in
2.80.1).

That change means that `g_menu_exporter_free()` is now called on the
registration failure path by `g_dbus_connection_register_object()`
before it returns. The caller then tries to call `g_slice_free()` on the
exporter again. The call to `g_menu_exporter_free()` tries to
dereference/free members of the exporter which it expects to be
initialised — but because this is happening in an error handling path,
they are not initialised.

If it were to get any further, the `g_slice_free()` would then be a
double-free on the exporter allocation.

Fix that by making `g_menu_exporter_free()` robust to some of the
exporter members being `NULL`, and moving some of the initialisation
code higher in `g_dbus_connection_export_menu_model()`, and removing the
duplicate free code on the error handling path.

This includes a unit test.

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

Fixes: #3366
2024-05-15 12:52:38 +01:00
Marco Trevisan (Treviño)
486ad65535 gio/tests: Enable gsocketclient-slow under address santizer
The test can run properly, even though we won't do the right checks on
the preloaded library
2024-05-10 02:44:07 +02:00
Marco Trevisan (Treviño)
0eb6c85606 build: Define glib_sanitizers variable to easily get the sanitizers in use
It's an array containing the list of sanitizers in use, normally it
contains a value, but in some cases may have more than one (e.g.
'address' and 'undefined').

And so use it to avoid repeated checks
2024-05-10 02:15:52 +02:00
Marco Trevisan (Treviño)
84259c46fa gio/tests/subprocess: Skip the trapped test under ASAN since it uses ptrace
And as the sanitizer tells us, it doesn't support it
2024-05-09 17:51:10 +02:00
Marco Trevisan (Treviño)
5c84823342 gio/tests/gsettings: Cleanup allocated new locales 2024-05-09 17:25:56 +02:00
Marco Trevisan (Treviño)
365411ea32 gio/tests/cancellable: Explain failure on GCancellableSource tests on valgrind
It looks like that finally also valgrind notices the same leaks as
address sanitizer does. It does it more randomly but it still happens,
so better to inform about until #2309 is resolved.
2024-05-09 17:25:56 +02:00
Philip Withnall
86dd02f487 Merge branch 'convert-bytes' into 'main'
Add g_converter_convert_bytes

See merge request GNOME/glib!4035
2024-05-09 15:03:56 +00:00
Matthias Clasen
0855968727 Add g_converter_convert_bytes
Add a utility api to apply a GConverter to data in memory.

Test included.
2024-05-09 15:03:55 +00:00
Ray Strode
47866d252f gdbusconnection: Fix test signal subscription ordering
The test case assumes signals will dispatched in a different order than
they're subscribed. In fact, signals can be dispatched in any order,
and are often dispatched in order.

This commit reorders the subscriptions so they're in order, which is
more logical, and also changes the code to only exit the event loops
when there are no pending handlers ready to dispatch.
2024-05-07 18:45:45 -04:00
Simon McVittie
7b15b1db40 gdbus-proxy test: Wait before asserting name owner has gone away
GDBusConnection sends each signal to recipients in a separate idle
callback, and there's no particular guarantee about the order in which
they're scheduled or dispatched. For the NameOwnerChanged signal that
reports the name becoming unowned, it's possible that g_bus_watch_name()
gets its idle callback called before the GDBusProxy:g-name-owner
machinery has updated the name owner, in which case the assertion
will fail.

Fixing GNOME/glib#3268 introduced a new subscription to NameOwnerChanged
which can alter the order of delivery, particularly in the case where
G_DBUS_PROXY_FLAGS_NO_MATCH_RULE was used (as tested in
/gdbus/proxy/no-match-rule). The resulting test failure is intermittent,
but reliably appears within 100 repetitions of that test.

Fixes: 511c5f5b "tests: Wait for gdbus-testserver to die when killing it"
Signed-off-by: Simon McVittie <smcv@debian.org>
2024-05-07 14:40:52 +01:00