1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 Copyright 2016 Zbigniew Jędrzejewski-Szmek
8 #include "alloc-util.h"
11 #include "selinux-util.h"
12 #include "string-util.h"
13 #include "time-util.h"
16 static void test_testing(void) {
19 log_info("============ %s ==========", __func__);
21 b = mac_selinux_use();
22 log_info("mac_selinux_use → %s", yes_no(b));
24 b = mac_selinux_use();
25 log_info("mac_selinux_use → %s", yes_no(b));
29 b = mac_selinux_use();
30 log_info("mac_selinux_use → %s", yes_no(b));
32 b = mac_selinux_use();
33 log_info("mac_selinux_use → %s", yes_no(b));
36 static void test_loading(void) {
40 log_info("============ %s ==========", __func__);
42 n1 = now(CLOCK_MONOTONIC);
43 r = mac_selinux_init();
44 n2 = now(CLOCK_MONOTONIC);
45 log_info_errno(r, "mac_selinux_init → %d %.2fs (%m)", r, (n2 - n1)/1e6);
48 static void test_cleanup(void) {
51 log_info("============ %s ==========", __func__);
53 n1 = now(CLOCK_MONOTONIC);
55 n2 = now(CLOCK_MONOTONIC);
56 log_info("mac_selinux_finish → %.2fs", (n2 - n1)/1e6);
59 #if 0 /// UNNEEDED by elogind
60 static void test_misc(const char* fname) {
61 _cleanup_(mac_selinux_freep) char *label = NULL, *label2 = NULL, *label3 = NULL;
63 _cleanup_close_ int fd = -1;
65 log_info("============ %s ==========", __func__);
67 r = mac_selinux_get_our_label(&label);
68 log_info_errno(r, "mac_selinux_get_our_label → %d, \"%s\" (%m)",
71 r = mac_selinux_get_create_label_from_exe(fname, &label2);
72 log_info_errno(r, "mac_selinux_create_label_from_exe → %d, \"%s\" (%m)",
75 fd = socket(AF_INET, SOCK_DGRAM, 0);
78 r = mac_selinux_get_child_mls_label(fd, fname, label2, &label3);
79 log_info_errno(r, "mac_selinux_get_child_mls_label → %d, \"%s\" (%m)",
84 static void test_create_file_prepare(const char* fname) {
87 log_info("============ %s ==========", __func__);
89 r = mac_selinux_create_file_prepare(fname, S_IRWXU);
90 log_info_errno(r, "mac_selinux_create_file_prepare → %d (%m)", r);
92 mac_selinux_create_file_clear();
95 int main(int argc, char **argv) {
96 const char *path = SYSTEMD_BINARY_PATH;
100 log_set_max_level(LOG_DEBUG);
101 log_parse_environment();
105 #if 0 /// UNNEEDED by elogind
108 test_create_file_prepare(path);