This source file includes following definitions.
- no_exe_file
- contents_too_long
- contents_ok
1
2
3
4
5
6
7
8
9
10 #include <crm_internal.h>
11
12 #include <crm/common/unittest_internal.h>
13
14 #include "mock_private.h"
15
16 #include <unistd.h>
17 #include <string.h>
18 #include <errno.h>
19
20 static void
21 no_exe_file(void **state)
22 {
23 size_t len = PATH_MAX;
24 char *path = calloc(len, sizeof(char));
25
26
27 pcmk__mock_readlink = true;
28
29 expect_string(__wrap_readlink, path, "/proc/1000/exe");
30 expect_value(__wrap_readlink, buf, path);
31 expect_value(__wrap_readlink, bufsize, len - 1);
32 will_return(__wrap_readlink, ENOENT);
33 will_return(__wrap_readlink, NULL);
34
35 assert_int_equal(pcmk__procfs_pid2path(1000, path, len), ENOENT);
36
37 pcmk__mock_readlink = false;
38
39 free(path);
40 }
41
42 static void
43 contents_too_long(void **state)
44 {
45 size_t len = 10;
46 char *path = calloc(len, sizeof(char));
47
48
49 pcmk__mock_readlink = true;
50
51 expect_string(__wrap_readlink, path, "/proc/1000/exe");
52 expect_value(__wrap_readlink, buf, path);
53 expect_value(__wrap_readlink, bufsize, len - 1);
54 will_return(__wrap_readlink, 0);
55 will_return(__wrap_readlink, "/more/than/10/characters");
56
57 assert_int_equal(pcmk__procfs_pid2path(1000, path, len),
58 ENAMETOOLONG);
59
60 pcmk__mock_readlink = false;
61
62 free(path);
63 }
64
65 static void
66 contents_ok(void **state)
67 {
68 size_t len = PATH_MAX;
69 char *path = calloc(len, sizeof(char));
70
71
72 pcmk__mock_readlink = true;
73
74 expect_string(__wrap_readlink, path, "/proc/1000/exe");
75 expect_value(__wrap_readlink, buf, path);
76 expect_value(__wrap_readlink, bufsize, len - 1);
77 will_return(__wrap_readlink, 0);
78 will_return(__wrap_readlink, "/ok");
79
80 assert_int_equal(pcmk__procfs_pid2path((pid_t) 1000, path, len),
81 pcmk_rc_ok);
82 assert_string_equal(path, "/ok");
83
84 pcmk__mock_readlink = false;
85
86 free(path);
87 }
88
89 PCMK__UNIT_TEST(NULL, NULL,
90 cmocka_unit_test(no_exe_file),
91 cmocka_unit_test(contents_too_long),
92 cmocka_unit_test(contents_ok))