Branch data Line data Source code
1 : : #include "sute.h"
2 : :
3 : : /* Test-only sysconf() control for file_buffer_memory().
4 : : file_buffer_memory.c routes only its own TESTITALL sysconf() calls through
5 : : libtestmocking, so the rest of the test binary keeps native sysconf()
6 : : behavior */
7 : :
8 : 1 : static Return test0005_1(void)
9 : : {
10 : 1 : INITTEST;
11 : :
12 : 1 : testmocking_sysconf_return_next(1,-1,4096);
13 : :
14 : 1 : size_t result = file_buffer_memory();
15 : 1 : testmocking_sysconf_disable();
16 : 1 : ASSERT(result == (size_t)(1024*1024));
17 : :
18 : 1 : RETURN_STATUS;
19 : : }
20 : :
21 : 1 : static Return test0005_2(void)
22 : : {
23 : 1 : INITTEST;
24 : :
25 : 1 : testmocking_sysconf_return_next(2,1000,-1);
26 : :
27 : 1 : size_t result = file_buffer_memory();
28 : 1 : testmocking_sysconf_disable();
29 : 1 : ASSERT(result == (size_t)(1024*1024));
30 : :
31 : 1 : RETURN_STATUS;
32 : : }
33 : :
34 : 1 : static Return test0005_3(void)
35 : : {
36 : 1 : INITTEST;
37 : :
38 : 1 : testmocking_sysconf_return_next(2,0,4096);
39 : :
40 : 1 : size_t result = file_buffer_memory();
41 : 1 : testmocking_sysconf_disable();
42 : 1 : ASSERT(result == (size_t)0);
43 : :
44 : 1 : RETURN_STATUS;
45 : : }
46 : :
47 : 1 : static Return test0005_4(void)
48 : : {
49 : 1 : INITTEST;
50 : :
51 : 1 : testmocking_sysconf_return_next(2,12345,0);
52 : :
53 : 1 : size_t result = file_buffer_memory();
54 : 1 : testmocking_sysconf_disable();
55 : 1 : ASSERT(result == (size_t)0);
56 : :
57 : 1 : RETURN_STATUS;
58 : : }
59 : :
60 : 1 : static Return test0005_5(void)
61 : : {
62 : 1 : INITTEST;
63 : :
64 : 1 : testmocking_sysconf_return_next(2,12345,1);
65 : :
66 : 1 : size_t result = file_buffer_memory();
67 : 1 : testmocking_sysconf_disable();
68 : 1 : ASSERT(result == (size_t)123);
69 : :
70 : 1 : RETURN_STATUS;
71 : : }
72 : :
73 : 1 : static Return test0005_6(void)
74 : : {
75 : 1 : INITTEST;
76 : :
77 : 1 : testmocking_sysconf_return_next(2,1000000,4096);
78 : :
79 : 1 : size_t result = file_buffer_memory();
80 : 1 : testmocking_sysconf_disable();
81 : 1 : ASSERT(result == (size_t)40960000);
82 : :
83 : 1 : RETURN_STATUS;
84 : : }
85 : :
86 : : /**
87 : : * @brief Run unit tests for file_buffer_memory()
88 : : *
89 : : * @details
90 : : * The tests use a test-only sysconf() hook to make failure, zero-value,
91 : : * rounding, and normal calculation paths deterministic
92 : : */
93 : 1 : Return test0005(void)
94 : : {
95 : 1 : INITTEST;
96 : :
97 : 1 : TEST(test0005_1,"file_buffer_memory(): returns default on pages failure");
98 : 1 : TEST(test0005_2,"file_buffer_memory(): returns default on page size failure");
99 : 1 : TEST(test0005_3,"file_buffer_memory(): 0 pages yields 0");
100 : 1 : TEST(test0005_4,"file_buffer_memory(): 0 page size yields 0");
101 : 1 : TEST(test0005_5,"file_buffer_memory(): integer division rounding down");
102 : 1 : TEST(test0005_6,"file_buffer_memory(): normal case computation");
103 : :
104 : : /* The sysconf() mock state is shared by the whole test binary.
105 : : Keep the suite closed by leaving the libtestmocking hook disabled
106 : : after all file_buffer_memory() unit checks have finished */
107 : 1 : testmocking_sysconf_disable();
108 : :
109 : 1 : RETURN_STATUS;
110 : : }
|