1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 This file is part of systemd.
5 Copyright 2016 Zbigniew Jędrzejewski-Szmek
10 #include "alloc-util.h"
13 #include "selinux-util.h"
14 #include "string-util.h"
15 #include "time-util.h"
18 static void test_testing(void) {
21 log_info("============ %s ==========", __func__);
23 b = mac_selinux_use();
24 log_info("mac_selinux_use → %s", yes_no(b));
26 b = mac_selinux_use();
27 log_info("mac_selinux_use → %s", yes_no(b));
31 b = mac_selinux_use();
32 log_info("mac_selinux_use → %s", yes_no(b));
34 b = mac_selinux_use();
35 log_info("mac_selinux_use → %s", yes_no(b));
38 static void test_loading(void) {
42 log_info("============ %s ==========", __func__);
44 n1 = now(CLOCK_MONOTONIC);
45 r = mac_selinux_init();
46 n2 = now(CLOCK_MONOTONIC);
47 log_info_errno(r, "mac_selinux_init → %d %.2fs (%m)", r, (n2 - n1)/1e6);
50 static void test_cleanup(void) {
53 log_info("============ %s ==========", __func__);
55 n1 = now(CLOCK_MONOTONIC);
57 n2 = now(CLOCK_MONOTONIC);
58 log_info("mac_selinux_finish → %.2fs", (n2 - n1)/1e6);
61 #if 0 /// UNNEEDED by elogind
62 static void test_misc(const char* fname) {
63 _cleanup_(mac_selinux_freep) char *label = NULL, *label2 = NULL, *label3 = NULL;
65 _cleanup_close_ int fd = -1;
67 log_info("============ %s ==========", __func__);
69 r = mac_selinux_get_our_label(&label);
70 log_info_errno(r, "mac_selinux_get_our_label → %d, \"%s\" (%m)",
73 r = mac_selinux_get_create_label_from_exe(fname, &label2);
74 log_info_errno(r, "mac_selinux_create_label_from_exe → %d, \"%s\" (%m)",
77 fd = socket(AF_INET, SOCK_DGRAM, 0);
80 r = mac_selinux_get_child_mls_label(fd, fname, label2, &label3);
81 log_info_errno(r, "mac_selinux_get_child_mls_label → %d, \"%s\" (%m)",
86 static void test_create_file_prepare(const char* fname) {
89 log_info("============ %s ==========", __func__);
91 r = mac_selinux_create_file_prepare(fname, S_IRWXU);
92 log_info_errno(r, "mac_selinux_create_file_prepare → %d (%m)", r);
94 mac_selinux_create_file_clear();
97 int main(int argc, char **argv) {
98 const char *path = SYSTEMD_BINARY_PATH;
102 log_set_max_level(LOG_DEBUG);
103 log_parse_environment();
107 #if 0 /// UNNEEDED by elogind
110 test_create_file_prepare(path);