1 // SPDX-License-Identifier: GPL-2.0
2
3 /*
4 * Copyright (C) 2020 Google LLC.
5 */
6
7 #include <test_progs.h>
8 #include <linux/limits.h>
9
10 #include "local_storage.skel.h"
11 #include "network_helpers.h"
12
create_and_unlink_file(void)13 int create_and_unlink_file(void)
14 {
15 char fname[PATH_MAX] = "/tmp/fileXXXXXX";
16 int fd;
17
18 fd = mkstemp(fname);
19 if (fd < 0)
20 return fd;
21
22 close(fd);
23 unlink(fname);
24 return 0;
25 }
26
test_test_local_storage(void)27 void test_test_local_storage(void)
28 {
29 struct local_storage *skel = NULL;
30 int err, duration = 0, serv_sk = -1;
31
32 skel = local_storage__open_and_load();
33 if (CHECK(!skel, "skel_load", "lsm skeleton failed\n"))
34 goto close_prog;
35
36 err = local_storage__attach(skel);
37 if (CHECK(err, "attach", "lsm attach failed: %d\n", err))
38 goto close_prog;
39
40 skel->bss->monitored_pid = getpid();
41
42 err = create_and_unlink_file();
43 if (CHECK(err < 0, "exec_cmd", "err %d errno %d\n", err, errno))
44 goto close_prog;
45
46 CHECK(skel->data->inode_storage_result != 0, "inode_storage_result",
47 "inode_local_storage not set\n");
48
49 serv_sk = start_server(AF_INET6, SOCK_STREAM, NULL, 0, 0);
50 if (CHECK(serv_sk < 0, "start_server", "failed to start server\n"))
51 goto close_prog;
52
53 CHECK(skel->data->sk_storage_result != 0, "sk_storage_result",
54 "sk_local_storage not set\n");
55
56 close(serv_sk);
57
58 close_prog:
59 local_storage__destroy(skel);
60 }
61