]>
Commit | Line | Data |
---|---|---|
53e1b683 | 1 | /* SPDX-License-Identifier: LGPL-2.1+ */ |
83555251 LP |
2 | /*** |
3 | This file is part of systemd. | |
4 | ||
5 | Copyright 2016 Lennart Poettering | |
6 | ||
7 | systemd is free software; you can redistribute it and/or modify it | |
8 | under the terms of the GNU Lesser General Public License as published by | |
9 | the Free Software Foundation; either version 2.1 of the License, or | |
10 | (at your option) any later version. | |
11 | ||
12 | systemd is distributed in the hope that it will be useful, but | |
13 | WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | Lesser General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU Lesser General Public License | |
18 | along with systemd; If not, see <http://www.gnu.org/licenses/>. | |
19 | ***/ | |
20 | ||
21 | #include <sys/mount.h> | |
22 | ||
23 | #include "log.h" | |
24 | #include "mount-util.h" | |
25 | #include "string-util.h" | |
26 | ||
c7383828 ZJS |
27 | static void test_mount_propagation_flags(const char *name, int ret, unsigned long expected) { |
28 | long unsigned flags; | |
83555251 | 29 | |
85e55d14 | 30 | assert_se(mount_propagation_flags_from_string(name, &flags) == ret); |
c7383828 ZJS |
31 | |
32 | if (ret >= 0) { | |
33 | const char *c; | |
34 | ||
35 | assert_se(flags == expected); | |
36 | ||
37 | c = mount_propagation_flags_to_string(flags); | |
38 | if (isempty(name)) | |
39 | assert_se(isempty(c)); | |
40 | else | |
41 | assert_se(streq(c, name)); | |
42 | } | |
83555251 LP |
43 | } |
44 | ||
45 | int main(int argc, char *argv[]) { | |
46 | ||
47 | log_set_max_level(LOG_DEBUG); | |
48 | ||
c7383828 ZJS |
49 | test_mount_propagation_flags("shared", 0, MS_SHARED); |
50 | test_mount_propagation_flags("slave", 0, MS_SLAVE); | |
51 | test_mount_propagation_flags("private", 0, MS_PRIVATE); | |
52 | test_mount_propagation_flags(NULL, 0, 0); | |
53 | test_mount_propagation_flags("", 0, 0); | |
54 | test_mount_propagation_flags("xxxx", -EINVAL, 0); | |
55 | test_mount_propagation_flags(" ", -EINVAL, 0); | |
83555251 LP |
56 | |
57 | return 0; | |
58 | } |