Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0: test_sidebar failing on macOS in headless environment #3674

Open
6t8k opened this issue Nov 5, 2023 · 13 comments · May be fixed by #3676
Open

2.0: test_sidebar failing on macOS in headless environment #3674

6t8k opened this issue Nov 5, 2023 · 13 comments · May be fixed by #3676

Comments

@6t8k
Copy link

6t8k commented Nov 5, 2023

Hi, I'm working on updating the Geany package in nixpkgs from 1.38 to 2.0: NixOS/nixpkgs#265362.

With Geany 2.0, tests/test_sidebar.c fails on nixpkgs' automatic PR builder (ofborg) on macOS, but not on macOS locally - presumably due to the environment being headless in the former case. On Linux, test_sidebar succeeds both locally and on the builder. The issue would likely show up on Hydra as well, our central CI service, and would cause us to introduce workarounds that are probably avoidable.

The return value of gtk_init_check here is never examined. https://docs.gtk.org/gtk3/func.init_check.html says:

"Note that calling any GTK function or instantiating any GTK type after this function returns FALSE results in undefined behavior."

Maybe it returns FALSE on Linux in this scenario (too)?

Could you please take a look at this? I can't really gauge what it would take to make the test run properly on Darwin in a headless environment (if possible). Worst case the test could skip itself and emit an appropriate message if GTK can't initialize, which would still be better than downstream having to explicitly work around it.


The build log for x86_64-darwin with the failing test can be viewed here. I attached it here in case that link becomes inaccessible: geany_2.0_x86_64-darwin_ofborg_buildlog.txt

@elextr
Copy link
Member

elextr commented Nov 5, 2023

Well, the test program should test the result of gtk_init_check() and early out, but what to return, if it returns failure any environment where it doesn't init is left with a failure to handle, but on the other hand return success isn't right either as it gives the impression the test ran. I can see why @kugel- ignored it.

My personal approach would be to return fail unless the whole test ran, and environments where the test cannot run need to disable it.

@6t8k
Copy link
Author

6t8k commented Nov 5, 2023

I was thinking it could work with g_test_skip ("Indicates that a test was skipped."), like used here. It looks like that isn't a GTK function, thus it should be safe to call even if gtk_init_check returns FALSE.

@elextr
Copy link
Member

elextr commented Nov 5, 2023

IIUC the call to gtk_init_func() is not inside a test, so g_test_skip() will do nothing. The example you pointed out is inside a function that is registered as a test. And that still leaves the question of what to return to your test environment, pass or fail. As I said, returning pass when none of the test ran isn't useful.

@6t8k
Copy link
Author

6t8k commented Nov 5, 2023

You can return 77 to tell Automake that the test was skipped.12

IIUC the call to gtk_init_func() is not inside a test, so g_test_skip() will do nothing. The example you pointed out is inside a function that is registered as a test.

If it turns out to be necessary, you could just set a variable, e.g. skip_tests = true and based on that let all functions that are registered as a test call g_test_skip.

Footnotes

  1. https://docs.gtk.org/glib/func.test_run.html

  2. https://www.gnu.org/software/automake/manual/automake.html#index-Exit-status-77_002c-special-interpretation

@elextr
Copy link
Member

elextr commented Nov 5, 2023

I guess if "somebody" made a PR it would get accepted.

@kugel-
Copy link
Member

kugel- commented Nov 5, 2023

On headless systems you should run the tests under Xephyr or something similar. That would be preferable over skipping the tests.

That's what I do when I build geany on my local Jenkins instance.

6t8k added a commit to 6t8k/geany that referenced this issue Nov 5, 2023
This may happen in headless environments.

The return value of `gtk_init_check` was not examined before; according
to [1], "calling any GTK function or instantiating any GTK type after
this function returns FALSE results in undefined behavior."

The value 77 can be returned to tell Automake that the test was
skipped.[2][3]

Fixes geany#3674

[2] https://www.gnu.org/software/automake/manual/automake.html#index-Exit-status-77_002c-special-interpretation
[3] https://docs.gtk.org/glib/func.test_run.html
6t8k added a commit to 6t8k/geany that referenced this issue Nov 5, 2023
This may happen in headless environments.

The return value of `gtk_init_check` was not examined before; according
to [1], "calling any GTK function or instantiating any GTK type after
this function returns FALSE results in undefined behavior."

The value 77 can be returned to tell Automake that the test was
skipped.[2][3]

Fixes geany#3674

[1] https://docs.gtk.org/gtk3/func.init_check.html
[2] https://www.gnu.org/software/automake/manual/automake.html#index-Exit-status-77_002c-special-interpretation
[3] https://docs.gtk.org/glib/func.test_run.html
@6t8k 6t8k linked a pull request Nov 5, 2023 that will close this issue
@6t8k
Copy link
Author

6t8k commented Nov 5, 2023

@kugel- Based on e.g. here: "Xephyr is a nested X server that runs as an X application." So using that would require an existing X server in the first place?

At any rate, I think such an approach can be a good solution and it's good that you do this, it's just overkill to add downstream just for that one test.

I proposed an implementation of what I had in mind here and hope it could be considered :) The return value of gtk_init_check should really be checked. For the time being, I am probably going to explicitly skip the test in nixpkgs.

@kugel-
Copy link
Member

kugel- commented Nov 5, 2023

Sorry, I mixed it up. I mean Xvfb. That's a pure software emulated X environment.

Why do you execute the tests at all?

@6t8k
Copy link
Author

6t8k commented Nov 5, 2023

Xvfb

Thanks.

Why do you execute the tests at all?

Basically, I saw no reason to disable anything inside Geany's test suite until now, or disabling running the test suite altogether (but then again, it's only since a couple months that I'm active to some degree in nixpkgs). It was enabled since Geany's initial addition to nixpkgs and seems to have been fine since.12 The rest is just me liking to get to the bottom of things sometimes. ^^;

I think it doesn't hurt to run Geany's suite in nixpkgs as it's relatively quick and lightweight—as long as it doesn't break things and cause additional maintenance burden.

Footnotes

  1. Some context: running upstream test suites is by default disabled in nixpkgs; package(r)s have to explicitly opt into this, ordinarily with doCheck = true;. There was come discussion around enabling this by default, as there are arguably good reasons for both approaches (notably https://github.com/NixOS/nixpkgs/issues/33599 and https://github.com/NixOS/rfcs/pull/95), but it seems to have petered out.

  2. But "we've always been doing it this way" is never a good argument.

@kugel-
Copy link
Member

kugel- commented Nov 5, 2023

I still recommend Xvfb. Geany is a GTK program, so you can expect that future tests will also require successful GTK initialization.

But a PR that skips the test would probably be accepted. Do you know if the exit 77 trick works on meson as well?

@6t8k
Copy link
Author

6t8k commented Nov 5, 2023

Do you know if the exit 77 trick works on meson as well?

It should work: https://mesonbuild.com/Unit-tests.html#skipped-tests-and-hard-errors

But it's not a "trick", it's the GNU standard approach (as mentioned there).

@6t8k
Copy link
Author

6t8k commented Nov 5, 2023

I still recommend Xvfb. Geany is a GTK program, so you can expect that future tests will also require successful GTK initialization.

Yeah, thanks. I will consider it. Other builds in nixpkgs are already using it in their checkPhase.

Edit: xvfb-run does not work on Darwin1, so this may at most help in the headless Linux case, but the bigger issue was with macOS (see above). One should also consider that Xorg is de-facto deprecated in favor of Wayland/XWayland.

Footnotes

  1. https://github.com/NixOS/nixpkgs/pull/123097

@6t8k
Copy link
Author

6t8k commented Nov 6, 2023

@kugel-: the approach works with Geany's Meson-based build too: #3676 (comment)

6t8k added a commit to 6t8k/geany that referenced this issue Dec 18, 2023
This may happen in headless environments.

The return value of `gtk_init_check` was not examined before; according
to [1], "calling any GTK function or instantiating any GTK type after
this function returns FALSE results in undefined behavior."

The value 77 can be returned to tell Automake and Meson that the test
was skipped.[2][3][4]

Fixes geany#3674

[1] https://docs.gtk.org/gtk3/func.init_check.html
[2] https://www.gnu.org/software/automake/manual/automake.html#index-Exit-status-77_002c-special-interpretation
[3] https://docs.gtk.org/glib/func.test_run.html
[4] https://mesonbuild.com/Unit-tests.html#skipped-tests-and-hard-errors
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants