Debian Codegraph @

tests/README.md

raw
1 xdg-desktop-portal test suite
2 =============================
3
4 ## Unit tests
5
6 This directory contains a number of unit tests. The tests are written in C and
7 are using the glib testing framework (https://docs.gtk.org/glib/testing.html).
8
9 The files follow the pattern `test-$NAME.c` and are compiled by meson. The tests
10 can be run with `meson test --suite unit`.
11
12 ## Integration tests
13
14 The integration tests usually test a specific portal in a fully integrated
15 environment. The tests are written in python using the pytest framework.
16
17 The files follow the pattern `test_$NAME.py`. The tests can be run with
18 `meson test --suite integration` or with `run-test.sh` in the source directory.
19
20 The environment is being set up by fixtures in `conftest.py` which can be
21 overwritten or parameterized by the tests themselves. There are a bunch of
22 convenient functions and classes in `__init__.py`. The portal backends are
23 implemented using dbusmock templates in the `templates` directory.
24
25 ### Environment
26
27 Some environment variables need to be set for the integration tests to function
28 properly and the harness will refuse to launch if they are not set. If the
29 harness is executed by meson or run-test.sh, they will be set automatically.
30
31 * `XDG_DESKTOP_PORTAL_PATH`: The path to the xdg-desktop-portal binary
32
33 * `XDG_PERMISSION_STORE_PATH`: The path to the xdg-permission-store binary
34
35 * `XDG_DOCUMENT_PORTAL_PATH`: The path to the xdg-document-portal binary
36
37 * `XDP_VALIDATE_ICON`: The path to the xdg-desktop-portal-validate-icon binary
38
39 * `XDP_VALIDATE_SOUND`: The path to the xdg-desktop-portal-validate-sound binary
40
41 * `XDP_VALIDATE_AUTO`: If set, automatically discovers the icon and sound
42 validators (only useful for installed tests) instead of using
43 `XDP_VALIDATE_ICON` and `XDP_VALIDATE_SOUND`.
44
45 Some optional environment variables that can be set to influence how the test
46 harness behaves.
47
48 * `XDP_TEST_IN_CI`: If set (to any value), some unreliable tests might get
49 skipped and some tests might run less iterations or otherwise test less
50 thoroughly.
51 Set this for automated QA testing, leave it unset during development.
52
53 * `XDP_TEST_RUN_LONG`: If set (to any value), some tests will run more
54 iterations or otherwise test more thoroughly
55
56 * `XDP_TEST_VALGRIND`: If set (to any value), tests will run via Valgrind's
57 Memcheck.
58
59 * `FLATPAK_BWRAP`: Path to the **bwrap**(1) executable
60 (default: discovered at build-time)
61
62 * `XDP_VALIDATE_ICON_INSECURE`: If set (to any value), x-d-p doesn't
63 sandbox the icon validator using **bwrap**(1), even if sandboxed
64 validation was enabled at compile time.
65 This can be used to run build-time tests in a chroot or unprivileged
66 container environment, where **bwrap**(1) normally can't work.
67 It should never be set on a production system that will be validating
68 untrusted icons!
69
70 * `XDP_VALIDATE_SOUND_INSECURE`: Same as `XDP_VALIDATE_ICON_INSECURE`,
71 but for sounds
72
73 Some optional environment variables that can be set to help with debugging.
74
75 * `G_MESSAGES_DEBUG=all`: Enable debug output, see
76 https://docs.gtk.org/glib/running.html
77
78 * `XDP_DBUS_MONITOR`: If set, starts dbus-monitor on the test dbus server
79
80 * `XDP_DBUS_TIMEOUT`: Maximum timeout for dbus calls in ms (default: 5s)
81
82 * `XDG_DESKTOP_PORTAL_WAIT_FOR_DEBUGGER`: Makes xdg-desktop-portal wait for
83 a debugger to attach by raising SIGSTOP
84
85 * `XDG_DOCUMENT_PORTAL_WAIT_FOR_DEBUGGER`: Makes xdg-document-portal wait
86 for a debugger to attach by raising SIGSTOP
87
88 * `XDG_PERMISSION_STORE_WAIT_FOR_DEBUGGER`: Makes xdg-permission-store wait
89 for a debugger to attach by raising SIGSTOP
90
91 Internal environment variables the tests use via pytest fixtures to set up the
92 environment they need.
93
94 * `XDG_DESKTOP_PORTAL_TEST_APP_INFO_KIND`: If set, the portal will use a
95 XdpAppInfo with the specified kind (`host`, `flatpak`, `snap`). More
96 environment variables might be required, depending on the kind.
97
98 * `XDG_DESKTOP_PORTAL_TEST_HOST_APPID`: The app id the XdpAppInfo shall be
99 using. Must be set if `XDG_DESKTOP_PORTAL_TEST_APP_INFO_KIND` is set to
100 `host`.
101
102 * `XDG_DESKTOP_PORTAL_TEST_FLATPAK_METADATA`: A path to a file containing
103 flatpak app metadata the XdpAppInfo shall use. Must be set if
104 `XDG_DESKTOP_PORTAL_TEST_APP_INFO_KIND` is set to `flatpak`.
105
106 * `XDG_DESKTOP_PORTAL_TEST_SNAP_METADATA`: A path to a file containing metadata
107 in the format of `snap routine portal-info` the XdpAppInfo shall use. Must
108 be set if `XDG_DESKTOP_PORTAL_TEST_APP_INFO_KIND` is set to `snap`.
109
110 ### Adding new tests
111
112 Make sure the required portals are listed in
113 `xdg_desktop_portal_dir_default_files` in `conftest.py`.
114
115 Add a `test_${name}.py` file to this directory and add the file to
116 `meson.build`.
117
118 If the portal that is being tested requires a backend implementation, add
119 it to the `templates` directory and add the file to `meson.build`. See the
120 dbusmock documentation for details on those templates.