Debian Codegraph @

tests/test-xdp-utils.c

raw symbols SCIP
1 #cxx . . $ `<file>/tests/test-xdp-utils.c`/include "config.h"cxx . . $ `<file>/build/config.h`/
2
3 #include <glib.h>
4
5 #include "xdp-app-info-host-private.h"cxx . . $ `<file>/src/xdp-app-info-host-private.h`/
6 #include "xdp-app-info-private.h"cxx . . $ `<file>/src/xdp-app-info-private.h`/
7 #include "xdp-app-info-snap-private.h"cxx . . $ `<file>/src/xdp-app-info-snap-private.h`/
8 #include "xdp-utils.h"cxx . . $ `<file>/src/xdp-utils.h`/
9
10 #define snap_parse_cgroupcxx . . $ `tests/test-xdp-utils.c:10:9`! _xdp_app_info_snap_parse_cgroup_file
11 #define host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! _xdp_app_info_host_parse_app_id_from_unit_name
12
13 static void
14 test_parse_cgroup_unifiedcxx . . $ test_parse_cgroup_unified(49f6e7a06ebc5aa8). (void)
15 {
16 char data[] = "0::/user.slice/user-1000.slice/[email protected]/apps.slice/snap.something.scope\n";
17 FILEcxx . . $ FILE# *f;
18 int res;
19 gbooleancxx . . $ gboolean# is_snap = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!;
20
21 f = fmemopencxx . . $ fmemopen(19216ad837c85d72).(data, sizeof(data), "r");
22
23 res = snap_parse_cgroupcxx . . $ `tests/test-xdp-utils.c:10:9`! (f, &is_snap);
24 g_assert_cmpintcxx . . $ `<external>/15287032793271088244/gtestutils.h:72:9`! (res, ==, 0);
25 g_assert_truecxx . . $ `<external>/15287032793271088244/gtestutils.h:227:9`! (is_snap);
26 fclosecxx . . $ fclose(89bc1efcdac0ca22).(f);
27 }
28
29 static void
30 test_parse_cgroup_freezercxx . . $ test_parse_cgroup_freezer(49f6e7a06ebc5aa8). (void)
31 {
32 char data[] =
33 "12:pids:/user.slice/user-1000.slice/[email protected]\n"
34 "11:perf_event:/\n"
35 "10:net_cls,net_prio:/\n"
36 "9:cpuset:/\n"
37 "8:memory:/user.slice/user-1000.slice/[email protected]/apps.slice/apps-org.gnome.Terminal.slice/vte-spawn-228ae109-a869-4533-8988-65ea4c10b492.scope\n"
38 "7:rdma:/\n"
39 "6:devices:/user.slice\n"
40 "5:blkio:/user.slice\n"
41 "4:hugetlb:/\n"
42 "3:freezer:/snap.portal-test\n"
43 "2:cpu,cpuacct:/user.slice\n"
44 "1:name=systemd:/user.slice/user-1000.slice/[email protected]/apps.slice/apps-org.gnome.Terminal.slice/vte-spawn-228ae109-a869-4533-8988-65ea4c10b492.scope\n"
45 "0::/user.slice/user-1000.slice/[email protected]/apps.slice/apps-org.gnome.Terminal.slice/vte-spawn-228ae109-a869-4533-8988-65ea4c10b492.scope\n";
46 FILEcxx . . $ FILE# *f;
47 int res;
48 gbooleancxx . . $ gboolean# is_snap = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!;
49
50 f = fmemopencxx . . $ fmemopen(19216ad837c85d72).(data, sizeof(data), "r");
51
52 res = snap_parse_cgroupcxx . . $ `tests/test-xdp-utils.c:10:9`! (f, &is_snap);
53 g_assert_cmpintcxx . . $ `<external>/15287032793271088244/gtestutils.h:72:9`! (res, ==, 0);
54 g_assert_truecxx . . $ `<external>/15287032793271088244/gtestutils.h:227:9`! (is_snap);
55 fclosecxx . . $ fclose(89bc1efcdac0ca22).(f);
56 }
57
58 static void
59 test_parse_cgroup_systemdcxx . . $ test_parse_cgroup_systemd(49f6e7a06ebc5aa8). (void)
60 {
61 char data[] = "1:name=systemd:/user.slice/user-1000.slice/[email protected]/apps.slice/snap.something.scope\n";
62 FILEcxx . . $ FILE# *f;
63 int res;
64 gbooleancxx . . $ gboolean# is_snap = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!;
65
66 f = fmemopencxx . . $ fmemopen(19216ad837c85d72).(data, sizeof(data), "r");
67
68 res = snap_parse_cgroupcxx . . $ `tests/test-xdp-utils.c:10:9`! (f, &is_snap);
69 g_assert_cmpintcxx . . $ `<external>/15287032793271088244/gtestutils.h:72:9`! (res, ==, 0);
70 g_assert_truecxx . . $ `<external>/15287032793271088244/gtestutils.h:227:9`! (is_snap);
71 fclosecxx . . $ fclose(89bc1efcdac0ca22).(f);
72 }
73
74 static void
75 test_parse_cgroup_not_snapcxx . . $ test_parse_cgroup_not_snap(49f6e7a06ebc5aa8). (void)
76 {
77 char data[] =
78 "12:pids:/\n"
79 "11:perf_event:/\n"
80 "10:net_cls,net_prio:/\n"
81 "9:cpuset:/\n"
82 "8:memory:/\n"
83 "7:rdma:/\n"
84 "6:devices:/\n"
85 "5:blkio:/\n"
86 "4:hugetlb:/\n"
87 "3:freezer:/\n"
88 "2:cpu,cpuacct:/\n"
89 "1:name=systemd:/\n"
90 "0::/\n";
91
92 FILEcxx . . $ FILE# *f;
93 int res;
94 gbooleancxx . . $ gboolean# is_snap = FALSEcxx . . $ `<external>/12741050725406041920/gmacros.h:967:9`!;
95
96 f = fmemopencxx . . $ fmemopen(19216ad837c85d72).(data, sizeof(data), "r");
97
98 res = snap_parse_cgroupcxx . . $ `tests/test-xdp-utils.c:10:9`! (f, &is_snap);
99 g_assert_cmpintcxx . . $ `<external>/15287032793271088244/gtestutils.h:72:9`! (res, ==, 0);
100 g_assert_falsecxx . . $ `<external>/15287032793271088244/gtestutils.h:232:9`! (is_snap);
101 fclosecxx . . $ fclose(89bc1efcdac0ca22).(f);
102 }
103
104 static void
105 test_alternate_doc_pathcxx . . $ test_alternate_doc_path(49f6e7a06ebc5aa8). (void)
106 {
107 g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *path = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
108
109 xdp_set_documents_mountpointcxx . . $ xdp_set_documents_mountpoint(85c52e162fed56f9). (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
110
111 /* If no documents mount point is set, there is no alternate path */
112 path = xdp_get_alternate_document_pathcxx . . $ xdp_get_alternate_document_path(a713fe7b9a57cf96). ("/whatever", "app-id");
113 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (path, ==, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
114
115 xdp_set_documents_mountpointcxx . . $ xdp_set_documents_mountpoint(85c52e162fed56f9). ("/doc/portal");
116
117 /* Paths outside of the document portal do not have an alternate path */
118 path = xdp_get_alternate_document_pathcxx . . $ xdp_get_alternate_document_path(a713fe7b9a57cf96). ("/whatever", "app-id");
119 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (path, ==, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
120
121 /* The doc portal mount point itself does not have an alternate path */
122 path = xdp_get_alternate_document_pathcxx . . $ xdp_get_alternate_document_path(a713fe7b9a57cf96). ("/doc/portal", "app-id");
123 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (path, ==, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
124
125 /* Paths under the doc portal mount point have an alternate path */
126 path = xdp_get_alternate_document_pathcxx . . $ xdp_get_alternate_document_path(a713fe7b9a57cf96). ("/doc/portal/foo/bar", "app-id");
127 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (path, ==, "/doc/portal/by-app/app-id/foo/bar");
128
129 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&path, g_free);
130 path = xdp_get_alternate_document_pathcxx . . $ xdp_get_alternate_document_path(a713fe7b9a57cf96). ("/doc/portal/foo/bar", "second-app");
131 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (path, ==, "/doc/portal/by-app/second-app/foo/bar");
132
133 xdp_set_documents_mountpointcxx . . $ xdp_set_documents_mountpoint(85c52e162fed56f9). (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
134 }
135
136 #if HAVE_LIBSYSTEMDcxx . . $ `build/config.h:18:9`!
137 static void
138 test_app_id_via_systemd_unitcxx . . $ test_app_id_via_systemd_unit(49f6e7a06ebc5aa8). (void)
139 {
140 g_autofreecxx . . $ `<external>/12741050725406041920/gmacros.h:1429:9`! char *app_id = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!;
141
142 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-not-a-well-formed-unit-name");
143 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "");
144 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
145
146 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-gnome-org.gnome.Evolution\\x2dalarm\\x2dnotify-2437.scope");
147 /* Note, this is not Evolution's app ID, because the scope is for a background service */
148 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "org.gnome.Evolution-alarm-notify");
149 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
150
151 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-gnome-org.gnome.Epiphany-182352.scope");
152 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "org.gnome.Epiphany");
153 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
154
155 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-glib-spice\\x2dvdagent-1839.scope");
156 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "spice-vdagent");
157 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
158
159 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("[email protected]");
160 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "org.kde.okular");
161 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
162
163 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-firefox.service");
164 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "firefox");
165 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
166
167 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-org.kde.amarok.service");
168 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "org.kde.amarok");
169 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
170
171 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-gnome-org.gnome.SettingsDaemon.DiskUtilityNotify-autostart.service");
172 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "org.gnome.SettingsDaemon.DiskUtilityNotify");
173 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
174
175 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-gnome-org.gnome.Terminal-92502.slice");
176 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "org.gnome.Terminal");
177 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
178
179 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-com.obsproject.Studio-d70acc38b5154a3a8b4a60accc4b15f4.scope");
180 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "com.obsproject.Studio");
181 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
182
183 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-firefox-jcfppqx.scope");
184 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "firefox");
185 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
186
187 app_id = host_parse_app_idcxx . . $ `tests/test-xdp-utils.c:11:9`! ("app-gnome-firefox.service");
188 g_assert_cmpstrcxx . . $ `<external>/15287032793271088244/gtestutils.h:46:9`! (app_id, ==, "firefox");
189 g_clear_pointercxx . . $ `<external>/1123956534522462559/gmem.h:135:9`! (&app_id, g_free);
190 }
191 #endif /* HAVE_LIBSYSTEMD */
192
193 int maincxx . . $ main(afcd3168fc1188a4). (int argc, char **argv)
194 {
195 g_test_initcxx . . $ g_test_init(b91bcc5cc1349d78). (&argc, &argv, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!);
196 g_test_add_funccxx . . $ g_test_add_func(18fee6cbb4bb18a4). ("/parse-cgroup/unified", test_parse_cgroup_unifiedcxx . . $ test_parse_cgroup_unified(49f6e7a06ebc5aa8).);
197 g_test_add_funccxx . . $ g_test_add_func(18fee6cbb4bb18a4). ("/parse-cgroup/freezer", test_parse_cgroup_freezercxx . . $ test_parse_cgroup_freezer(49f6e7a06ebc5aa8).);
198 g_test_add_funccxx . . $ g_test_add_func(18fee6cbb4bb18a4). ("/parse-cgroup/systemd", test_parse_cgroup_systemdcxx . . $ test_parse_cgroup_systemd(49f6e7a06ebc5aa8).);
199 g_test_add_funccxx . . $ g_test_add_func(18fee6cbb4bb18a4). ("/parse-cgroup/not-snap", test_parse_cgroup_not_snapcxx . . $ test_parse_cgroup_not_snap(49f6e7a06ebc5aa8).);
200 g_test_add_funccxx . . $ g_test_add_func(18fee6cbb4bb18a4). ("/alternate-doc-path", test_alternate_doc_pathcxx . . $ test_alternate_doc_path(49f6e7a06ebc5aa8).);
201 #if HAVE_LIBSYSTEMDcxx . . $ `build/config.h:18:9`!
202 g_test_add_funccxx . . $ g_test_add_func(18fee6cbb4bb18a4). ("/app-id-via-systemd-unit", test_app_id_via_systemd_unitcxx . . $ test_app_id_via_systemd_unit(49f6e7a06ebc5aa8).);
203 #endif
204 return g_test_runcxx . . $ g_test_run(b126dc7c1de90089). ();
205 }