]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/test/test-unit-name.c
build-sys: fix invalid args detected by meson 0.42 (#6561)
[thirdparty/systemd.git] / src / test / test-unit-name.c
CommitLineData
b0193f1c
LP
1/***
2 This file is part of systemd.
3
4 Copyright 2012 Lennart Poettering
1682ff60 5 Copyright 2013 Zbigniew Jędrzejewski-Szmek
068ae9fb 6 Copyright 2014 Ronny Chevalier
b0193f1c
LP
7
8 systemd is free software; you can redistribute it and/or modify it
9 under the terms of the GNU Lesser General Public License as published by
10 the Free Software Foundation; either version 2.1 of the License, or
11 (at your option) any later version.
12
13 systemd is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 Lesser General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with systemd; If not, see <http://www.gnu.org/licenses/>.
20***/
21
07630cea 22#include <pwd.h>
b0193f1c
LP
23#include <stdio.h>
24#include <stdlib.h>
25#include <string.h>
26
b5efdb8a 27#include "alloc-util.h"
2aaafcf5 28#include "glob-util.h"
07630cea
LP
29#include "hostname-util.h"
30#include "macro.h"
1682ff60 31#include "manager.h"
07630cea 32#include "path-util.h"
a04efff8 33#include "rm-rf.h"
07630cea
LP
34#include "specifier.h"
35#include "string-util.h"
36#include "test-helper.h"
a04efff8 37#include "tests.h"
b0193f1c 38#include "unit-name.h"
1682ff60 39#include "unit-printf.h"
07630cea 40#include "unit.h"
79413b67 41#include "user-util.h"
b0193f1c
LP
42#include "util.h"
43
7410616c
LP
44static void test_unit_name_is_valid(void) {
45 assert_se(unit_name_is_valid("foo.service", UNIT_NAME_ANY));
46 assert_se(unit_name_is_valid("foo.service", UNIT_NAME_PLAIN));
47 assert_se(!unit_name_is_valid("foo.service", UNIT_NAME_INSTANCE));
48 assert_se(!unit_name_is_valid("foo.service", UNIT_NAME_TEMPLATE));
49 assert_se(!unit_name_is_valid("foo.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
50
51 assert_se(unit_name_is_valid("foo@bar.service", UNIT_NAME_ANY));
52 assert_se(!unit_name_is_valid("foo@bar.service", UNIT_NAME_PLAIN));
53 assert_se(unit_name_is_valid("foo@bar.service", UNIT_NAME_INSTANCE));
54 assert_se(!unit_name_is_valid("foo@bar.service", UNIT_NAME_TEMPLATE));
55 assert_se(unit_name_is_valid("foo@bar.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
56
57 assert_se(unit_name_is_valid("foo@.service", UNIT_NAME_ANY));
58 assert_se(!unit_name_is_valid("foo@.service", UNIT_NAME_PLAIN));
59 assert_se(!unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE));
60 assert_se(unit_name_is_valid("foo@.service", UNIT_NAME_TEMPLATE));
61 assert_se(unit_name_is_valid("foo@.service", UNIT_NAME_INSTANCE|UNIT_NAME_TEMPLATE));
62
63 assert_se(!unit_name_is_valid(".service", UNIT_NAME_ANY));
64 assert_se(!unit_name_is_valid("", UNIT_NAME_ANY));
65 assert_se(!unit_name_is_valid("foo.waldo", UNIT_NAME_ANY));
66 assert_se(!unit_name_is_valid("@.service", UNIT_NAME_ANY));
67 assert_se(!unit_name_is_valid("@piep.service", UNIT_NAME_ANY));
68}
3251c0d2 69
21868586 70static void test_unit_name_replace_instance_one(const char *pattern, const char *repl, const char *expected, int ret) {
7410616c
LP
71 _cleanup_free_ char *t = NULL;
72 assert_se(unit_name_replace_instance(pattern, repl, &t) == ret);
73 puts(strna(t));
74 assert_se(streq_ptr(t, expected));
75}
3251c0d2 76
21868586 77static void test_unit_name_replace_instance(void) {
3251c0d2 78 puts("-------------------------------------------------");
21868586
LP
79 test_unit_name_replace_instance_one("foo@.service", "waldo", "foo@waldo.service", 0);
80 test_unit_name_replace_instance_one("foo@xyz.service", "waldo", "foo@waldo.service", 0);
81 test_unit_name_replace_instance_one("xyz", "waldo", NULL, -EINVAL);
82 test_unit_name_replace_instance_one("", "waldo", NULL, -EINVAL);
83 test_unit_name_replace_instance_one("foo.service", "waldo", NULL, -EINVAL);
84 test_unit_name_replace_instance_one(".service", "waldo", NULL, -EINVAL);
85 test_unit_name_replace_instance_one("foo@", "waldo", NULL, -EINVAL);
86 test_unit_name_replace_instance_one("@bar", "waldo", NULL, -EINVAL);
7410616c 87}
3251c0d2 88
21868586 89static void test_unit_name_from_path_one(const char *path, const char *suffix, const char *expected, int ret) {
7410616c 90 _cleanup_free_ char *t = NULL;
3251c0d2 91
7410616c
LP
92 assert_se(unit_name_from_path(path, suffix, &t) == ret);
93 puts(strna(t));
94 assert_se(streq_ptr(t, expected));
3251c0d2 95
7410616c
LP
96 if (t) {
97 _cleanup_free_ char *k = NULL;
98 assert_se(unit_name_to_path(t, &k) == 0);
99 puts(strna(k));
100 assert_se(path_equal(k, isempty(path) ? "/" : path));
101 }
102}
3251c0d2 103
21868586 104static void test_unit_name_from_path(void) {
3251c0d2 105 puts("-------------------------------------------------");
21868586
LP
106 test_unit_name_from_path_one("/waldo", ".mount", "waldo.mount", 0);
107 test_unit_name_from_path_one("/waldo/quuix", ".mount", "waldo-quuix.mount", 0);
108 test_unit_name_from_path_one("/waldo/quuix/", ".mount", "waldo-quuix.mount", 0);
109 test_unit_name_from_path_one("", ".mount", "-.mount", 0);
110 test_unit_name_from_path_one("/", ".mount", "-.mount", 0);
111 test_unit_name_from_path_one("///", ".mount", "-.mount", 0);
112 test_unit_name_from_path_one("/foo/../bar", ".mount", NULL, -EINVAL);
113 test_unit_name_from_path_one("/foo/./bar", ".mount", NULL, -EINVAL);
7410616c
LP
114}
115
21868586 116static void test_unit_name_from_path_instance_one(const char *pattern, const char *path, const char *suffix, const char *expected, int ret) {
7410616c
LP
117 _cleanup_free_ char *t = NULL;
118
119 assert_se(unit_name_from_path_instance(pattern, path, suffix, &t) == ret);
120 puts(strna(t));
121 assert_se(streq_ptr(t, expected));
122
123 if (t) {
124 _cleanup_free_ char *k = NULL, *v = NULL;
125
126 assert_se(unit_name_to_instance(t, &k) > 0);
127 assert_se(unit_name_path_unescape(k, &v) == 0);
128 assert_se(path_equal(v, isempty(path) ? "/" : path));
3251c0d2 129 }
7410616c 130}
3251c0d2 131
21868586 132static void test_unit_name_from_path_instance(void) {
7410616c 133 puts("-------------------------------------------------");
b0193f1c 134
21868586
LP
135 test_unit_name_from_path_instance_one("waldo", "/waldo", ".mount", "waldo@waldo.mount", 0);
136 test_unit_name_from_path_instance_one("waldo", "/waldo////quuix////", ".mount", "waldo@waldo-quuix.mount", 0);
137 test_unit_name_from_path_instance_one("waldo", "/", ".mount", "waldo@-.mount", 0);
138 test_unit_name_from_path_instance_one("waldo", "", ".mount", "waldo@-.mount", 0);
139 test_unit_name_from_path_instance_one("waldo", "///", ".mount", "waldo@-.mount", 0);
140 test_unit_name_from_path_instance_one("waldo", "..", ".mount", NULL, -EINVAL);
141 test_unit_name_from_path_instance_one("waldo", "/foo", ".waldi", NULL, -EINVAL);
142 test_unit_name_from_path_instance_one("wa--ldo", "/--", ".mount", "wa--ldo@\\x2d\\x2d.mount", 0);
7410616c
LP
143}
144
21868586 145static void test_unit_name_to_path_one(const char *unit, const char *path, int ret) {
7410616c
LP
146 _cleanup_free_ char *p = NULL;
147
148 assert_se(unit_name_to_path(unit, &p) == ret);
149 assert_se(streq_ptr(path, p));
150}
151
21868586
LP
152static void test_unit_name_to_path(void) {
153 test_unit_name_to_path_one("home.mount", "/home", 0);
154 test_unit_name_to_path_one("home-lennart.mount", "/home/lennart", 0);
155 test_unit_name_to_path_one("home-lennart-.mount", NULL, -EINVAL);
156 test_unit_name_to_path_one("-home-lennart.mount", NULL, -EINVAL);
157 test_unit_name_to_path_one("-home--lennart.mount", NULL, -EINVAL);
158 test_unit_name_to_path_one("home-..-lennart.mount", NULL, -EINVAL);
159 test_unit_name_to_path_one("", NULL, -EINVAL);
160 test_unit_name_to_path_one("home/foo", NULL, -EINVAL);
7410616c
LP
161}
162
2aaafcf5 163static void test_unit_name_mangle_one(UnitNameMangle allow_globs, const char *pattern, const char *expect, int ret) {
7410616c
LP
164 _cleanup_free_ char *t = NULL;
165
2aaafcf5 166 assert_se(unit_name_mangle(pattern, allow_globs, &t) == ret);
7410616c
LP
167 puts(strna(t));
168 assert_se(streq_ptr(t, expect));
169
170 if (t) {
171 _cleanup_free_ char *k = NULL;
172
2aaafcf5
LP
173 assert_se(unit_name_is_valid(t, UNIT_NAME_ANY) ||
174 (allow_globs == UNIT_NAME_GLOB && string_is_glob(t)));
7410616c 175
2aaafcf5 176 assert_se(unit_name_mangle(t, allow_globs, &k) == 0);
7410616c
LP
177 assert_se(streq_ptr(t, k));
178 }
179}
180
21868586 181static void test_unit_name_mangle(void) {
7410616c 182 puts("-------------------------------------------------");
2aaafcf5
LP
183 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "foo.service", "foo.service", 0);
184 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "/home", "home.mount", 1);
185 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "/dev/sda", "dev-sda.device", 1);
186 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "üxknürz.service", "\\xc3\\xbcxkn\\xc3\\xbcrz.service", 1);
187 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "foobar-meh...waldi.service", "foobar-meh...waldi.service", 0);
188 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "_____####----.....service", "_____\\x23\\x23\\x23\\x23----.....service", 1);
189 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "_____##@;;;,,,##----.....service", "_____\\x23\\x23@\\x3b\\x3b\\x3b\\x2c\\x2c\\x2c\\x23\\x23----.....service", 1);
190 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "xxx@@@@/////\\\\\\\\\\yyy.service", "xxx@@@@-----\\\\\\\\\\yyy.service", 1);
191 test_unit_name_mangle_one(UNIT_NAME_NOGLOB, "", NULL, -EINVAL);
192
193 test_unit_name_mangle_one(UNIT_NAME_GLOB, "foo.service", "foo.service", 0);
194 test_unit_name_mangle_one(UNIT_NAME_GLOB, "foo", "foo.service", 1);
195 test_unit_name_mangle_one(UNIT_NAME_GLOB, "foo*", "foo*", 0);
196 test_unit_name_mangle_one(UNIT_NAME_GLOB, "ü*", "\\xc3\\xbc*", 1);
1682ff60
ZJS
197}
198
49e5de64 199static int test_unit_printf(void) {
39883f62 200 Manager *m = NULL;
1682ff60 201 Unit *u, *u2;
c5e33bf8 202 int r;
1682ff60 203
79413b67 204 _cleanup_free_ char *mid = NULL, *bid = NULL, *host = NULL, *uid = NULL, *user = NULL, *shell = NULL, *home = NULL;
1682ff60 205
19f6d710
LP
206 assert_se(specifier_machine_id('m', NULL, NULL, &mid) >= 0 && mid);
207 assert_se(specifier_boot_id('b', NULL, NULL, &bid) >= 0 && bid);
79413b67
LP
208 assert_se(host = gethostname_malloc());
209 assert_se(user = getusername_malloc());
210 assert_se(asprintf(&uid, UID_FMT, getuid()));
211 assert_se(get_home_dir(&home) >= 0);
212 assert_se(get_shell(&shell) >= 0);
1682ff60 213
463d0d15 214 r = manager_new(UNIT_FILE_USER, true, &m);
a04efff8
YW
215 if (MANAGER_SKIP_TEST(r)) {
216 log_notice_errno(r, "Skipping test: manager_new: %m");
49e5de64 217 return EXIT_TEST_SKIP;
c5e33bf8 218 }
bdf7026e 219 assert_se(r == 0);
1682ff60
ZJS
220
221#define expect(unit, pattern, expected) \
222 { \
fa3cd739 223 char *e; \
e1ba963f 224 _cleanup_free_ char *t = NULL; \
19f6d710 225 assert_se(unit_full_printf(unit, pattern, &t) >= 0); \
c5e33bf8 226 printf("result: %s\nexpect: %s\n", t, expected); \
fa3cd739 227 if ((e = endswith(expected, "*"))) \
bdf7026e 228 assert_se(strncmp(t, e, e-expected)); \
fa3cd739 229 else \
bdf7026e 230 assert_se(streq(t, expected)); \
1682ff60
ZJS
231 }
232
1682ff60
ZJS
233 assert_se(u = unit_new(m, sizeof(Service)));
234 assert_se(unit_add_name(u, "blah.service") == 0);
235 assert_se(unit_add_name(u, "blah.service") == 0);
236
237 /* general tests */
238 expect(u, "%%", "%");
239 expect(u, "%%s", "%s");
240 expect(u, "%", ""); // REALLY?
241
242 /* normal unit */
243 expect(u, "%n", "blah.service");
14b0295f 244 expect(u, "%f", "/blah");
1682ff60
ZJS
245 expect(u, "%N", "blah");
246 expect(u, "%p", "blah");
247 expect(u, "%P", "blah");
248 expect(u, "%i", "");
79413b67
LP
249 expect(u, "%u", user);
250 expect(u, "%U", uid);
251 expect(u, "%h", home);
1682ff60
ZJS
252 expect(u, "%m", mid);
253 expect(u, "%b", bid);
254 expect(u, "%H", host);
fa3cd739 255 expect(u, "%t", "/run/user/*");
1682ff60
ZJS
256
257 /* templated */
258 assert_se(u2 = unit_new(m, sizeof(Service)));
259 assert_se(unit_add_name(u2, "blah@foo-foo.service") == 0);
260 assert_se(unit_add_name(u2, "blah@foo-foo.service") == 0);
261
262 expect(u2, "%n", "blah@foo-foo.service");
263 expect(u2, "%N", "blah@foo-foo");
14b0295f 264 expect(u2, "%f", "/foo/foo");
1682ff60
ZJS
265 expect(u2, "%p", "blah");
266 expect(u2, "%P", "blah");
267 expect(u2, "%i", "foo-foo");
268 expect(u2, "%I", "foo/foo");
79413b67
LP
269 expect(u2, "%u", user);
270 expect(u2, "%U", uid);
271 expect(u2, "%h", home);
1682ff60
ZJS
272 expect(u2, "%m", mid);
273 expect(u2, "%b", bid);
274 expect(u2, "%H", host);
fa3cd739 275 expect(u2, "%t", "/run/user/*");
49e5de64 276
b463b813 277 manager_free(m);
fee0a921 278#undef expect
b463b813 279
49e5de64 280 return 0;
1682ff60
ZJS
281}
282
068ae9fb
RC
283static void test_unit_instance_is_valid(void) {
284 assert_se(unit_instance_is_valid("fooBar"));
285 assert_se(unit_instance_is_valid("foo-bar"));
286 assert_se(unit_instance_is_valid("foo.stUff"));
287 assert_se(unit_instance_is_valid("fOo123.stuff"));
288 assert_se(unit_instance_is_valid("@f_oo123.Stuff"));
289
290 assert_se(!unit_instance_is_valid("$¢£"));
291 assert_se(!unit_instance_is_valid(""));
292 assert_se(!unit_instance_is_valid("foo bar"));
293 assert_se(!unit_instance_is_valid("foo/bar"));
294}
295
296static void test_unit_prefix_is_valid(void) {
297 assert_se(unit_prefix_is_valid("fooBar"));
298 assert_se(unit_prefix_is_valid("foo-bar"));
299 assert_se(unit_prefix_is_valid("foo.stUff"));
300 assert_se(unit_prefix_is_valid("fOo123.stuff"));
301 assert_se(unit_prefix_is_valid("foo123.Stuff"));
302
303 assert_se(!unit_prefix_is_valid("$¢£"));
304 assert_se(!unit_prefix_is_valid(""));
305 assert_se(!unit_prefix_is_valid("foo bar"));
306 assert_se(!unit_prefix_is_valid("foo/bar"));
307 assert_se(!unit_prefix_is_valid("@foo-bar"));
308}
309
310static void test_unit_name_change_suffix(void) {
7410616c 311 char *t;
068ae9fb 312
7410616c
LP
313 assert_se(unit_name_change_suffix("foo.mount", ".service", &t) == 0);
314 assert_se(streq(t, "foo.service"));
315 free(t);
068ae9fb 316
7410616c
LP
317 assert_se(unit_name_change_suffix("foo@stuff.service", ".socket", &t) == 0);
318 assert_se(streq(t, "foo@stuff.socket"));
319 free(t);
068ae9fb
RC
320}
321
322static void test_unit_name_build(void) {
7410616c 323 char *t;
068ae9fb 324
7410616c
LP
325 assert_se(unit_name_build("foo", "bar", ".service", &t) == 0);
326 assert_se(streq(t, "foo@bar.service"));
327 free(t);
068ae9fb 328
7410616c
LP
329 assert_se(unit_name_build("fo0-stUff_b", "bar", ".mount", &t) == 0);
330 assert_se(streq(t, "fo0-stUff_b@bar.mount"));
331 free(t);
068ae9fb 332
7410616c
LP
333 assert_se(unit_name_build("foo", NULL, ".service", &t) == 0);
334 assert_se(streq(t, "foo.service"));
335 free(t);
068ae9fb
RC
336}
337
93c47472
LP
338static void test_slice_name_is_valid(void) {
339 assert_se(slice_name_is_valid("-.slice"));
340 assert_se(slice_name_is_valid("foo.slice"));
341 assert_se(slice_name_is_valid("foo-bar.slice"));
342 assert_se(slice_name_is_valid("foo-bar-baz.slice"));
343 assert_se(!slice_name_is_valid("-foo-bar-baz.slice"));
344 assert_se(!slice_name_is_valid("foo-bar-baz-.slice"));
345 assert_se(!slice_name_is_valid("-foo-bar-baz-.slice"));
346 assert_se(!slice_name_is_valid("foo-bar--baz.slice"));
347 assert_se(!slice_name_is_valid("foo--bar--baz.slice"));
348 assert_se(!slice_name_is_valid(".slice"));
349 assert_se(!slice_name_is_valid(""));
350 assert_se(!slice_name_is_valid("foo.service"));
351}
352
068ae9fb
RC
353static void test_build_subslice(void) {
354 char *a;
355 char *b;
356
7410616c
LP
357 assert_se(slice_build_subslice("-.slice", "foo", &a) >= 0);
358 assert_se(slice_build_subslice(a, "bar", &b) >= 0);
068ae9fb 359 free(a);
7410616c 360 assert_se(slice_build_subslice(b, "barfoo", &a) >= 0);
068ae9fb 361 free(b);
7410616c 362 assert_se(slice_build_subslice(a, "foobar", &b) >= 0);
068ae9fb
RC
363 free(a);
364 assert_se(streq(b, "foo-bar-barfoo-foobar.slice"));
365 free(b);
366
7410616c
LP
367 assert_se(slice_build_subslice("foo.service", "bar", &a) < 0);
368 assert_se(slice_build_subslice("foo", "bar", &a) < 0);
068ae9fb
RC
369}
370
93c47472
LP
371static void test_build_parent_slice_one(const char *name, const char *expect, int ret) {
372 _cleanup_free_ char *s = NULL;
373
374 assert_se(slice_build_parent_slice(name, &s) == ret);
375 assert_se(streq_ptr(s, expect));
376}
377
378static void test_build_parent_slice(void) {
379 test_build_parent_slice_one("-.slice", NULL, 0);
380 test_build_parent_slice_one("foo.slice", "-.slice", 1);
381 test_build_parent_slice_one("foo-bar.slice", "foo.slice", 1);
382 test_build_parent_slice_one("foo-bar-baz.slice", "foo-bar.slice", 1);
383 test_build_parent_slice_one("foo-bar--baz.slice", NULL, -EINVAL);
384 test_build_parent_slice_one("-foo-bar.slice", NULL, -EINVAL);
385 test_build_parent_slice_one("foo-bar-.slice", NULL, -EINVAL);
386 test_build_parent_slice_one("foo-bar.service", NULL, -EINVAL);
387 test_build_parent_slice_one(".slice", NULL, -EINVAL);
388}
389
068ae9fb
RC
390static void test_unit_name_to_instance(void) {
391 char *instance;
392 int r;
393
394 r = unit_name_to_instance("foo@bar.service", &instance);
395 assert_se(r >= 0);
396 assert_se(streq(instance, "bar"));
397 free(instance);
398
fee0a921
RC
399 r = unit_name_to_instance("foo@.service", &instance);
400 assert_se(r >= 0);
401 assert_se(streq(instance, ""));
402 free(instance);
403
7410616c 404 r = unit_name_to_instance("fo0-stUff_b@b.service", &instance);
068ae9fb
RC
405 assert_se(r >= 0);
406 assert_se(streq(instance, "b"));
407 free(instance);
408
7410616c
LP
409 r = unit_name_to_instance("foo.service", &instance);
410 assert_se(r == 0);
068ae9fb
RC
411 assert_se(!instance);
412
413 r = unit_name_to_instance("fooj@unk", &instance);
414 assert_se(r < 0);
fee0a921
RC
415
416 r = unit_name_to_instance("foo@", &instance);
417 assert_se(r < 0);
068ae9fb
RC
418}
419
420static void test_unit_name_escape(void) {
421 _cleanup_free_ char *r;
422
423 r = unit_name_escape("ab+-c.a/bc@foo.service");
424 assert_se(r);
425 assert_se(streq(r, "ab\\x2b\\x2dc.a-bc\\x40foo.service"));
426}
427
fee0a921 428
7410616c
LP
429static void test_u_n_t_one(const char *name, const char *expected, int ret) {
430 _cleanup_free_ char *f = NULL;
fee0a921 431
7410616c
LP
432 assert_se(unit_name_template(name, &f) == ret);
433 printf("got: %s, expected: %s\n", strna(f), strna(expected));
434 assert_se(streq_ptr(f, expected));
435}
436
437static void test_unit_name_template(void) {
438 test_u_n_t_one("foo@bar.service", "foo@.service", 0);
439 test_u_n_t_one("foo.mount", NULL, -EINVAL);
fee0a921
RC
440}
441
93c47472
LP
442static void test_unit_name_path_unescape_one(const char *name, const char *path, int ret) {
443 _cleanup_free_ char *p = NULL;
444
445 assert_se(unit_name_path_unescape(name, &p) == ret);
446 assert_se(streq_ptr(path, p));
447}
448
449static void test_unit_name_path_unescape(void) {
450
451 test_unit_name_path_unescape_one("foo", "/foo", 0);
452 test_unit_name_path_unescape_one("foo-bar", "/foo/bar", 0);
453 test_unit_name_path_unescape_one("foo-.bar", "/foo/.bar", 0);
454 test_unit_name_path_unescape_one("foo-bar-baz", "/foo/bar/baz", 0);
455 test_unit_name_path_unescape_one("-", "/", 0);
456 test_unit_name_path_unescape_one("--", NULL, -EINVAL);
457 test_unit_name_path_unescape_one("-foo-bar", NULL, -EINVAL);
458 test_unit_name_path_unescape_one("foo--bar", NULL, -EINVAL);
459 test_unit_name_path_unescape_one("foo-bar-", NULL, -EINVAL);
460 test_unit_name_path_unescape_one(".-bar", NULL, -EINVAL);
461 test_unit_name_path_unescape_one("foo-..", NULL, -EINVAL);
462 test_unit_name_path_unescape_one("", NULL, -EINVAL);
463}
464
1682ff60 465int main(int argc, char* argv[]) {
a04efff8 466 _cleanup_(rm_rf_physical_and_freep) char *runtime_dir = NULL;
143bfdaf 467 int rc = 0;
a04efff8
YW
468
469 log_parse_environment();
470 log_open();
471
472 assert_se(runtime_dir = setup_fake_runtime_dir());
473
7410616c 474 test_unit_name_is_valid();
21868586
LP
475 test_unit_name_replace_instance();
476 test_unit_name_from_path();
477 test_unit_name_from_path_instance();
478 test_unit_name_mangle();
479 test_unit_name_to_path();
143bfdaf 480 TEST_REQ_RUNNING_SYSTEMD(rc = test_unit_printf());
068ae9fb
RC
481 test_unit_instance_is_valid();
482 test_unit_prefix_is_valid();
483 test_unit_name_change_suffix();
484 test_unit_name_build();
93c47472 485 test_slice_name_is_valid();
068ae9fb 486 test_build_subslice();
93c47472 487 test_build_parent_slice();
068ae9fb
RC
488 test_unit_name_to_instance();
489 test_unit_name_escape();
fee0a921 490 test_unit_name_template();
93c47472 491 test_unit_name_path_unescape();
068ae9fb 492
143bfdaf 493 return rc;
b0193f1c 494}