]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | /* |
2 | * <tested_file_path>src/concurrency/ocf_metadata_concurrency.c</tested_file_path> | |
3 | * <tested_function>ocf_req_hash_lock_rd</tested_function> | |
4 | * <functions_to_leave> | |
5 | * INSERT HERE LIST OF FUNCTIONS YOU WANT TO LEAVE | |
6 | * ONE FUNCTION PER LINE | |
7 | * </functions_to_leave> | |
8 | */ | |
9 | ||
10 | #undef static | |
11 | ||
12 | #undef inline | |
13 | ||
14 | ||
15 | #include <stdarg.h> | |
16 | #include <stddef.h> | |
17 | #include <setjmp.h> | |
18 | #include <cmocka.h> | |
19 | #include "print_desc.h" | |
20 | ||
21 | #include "ocf_metadata_concurrency.h" | |
22 | #include "../metadata/metadata_misc.h" | |
23 | ||
24 | #include "concurrency/ocf_metadata_concurrency.c/ocf_metadata_concurrency_generated_wraps.c" | |
25 | ||
26 | void __wrap_ocf_metadata_hash_lock(struct ocf_metadata_lock *metadata_lock, | |
27 | ocf_cache_line_t hash, int rw) | |
28 | { | |
29 | check_expected(hash); | |
30 | function_called(); | |
31 | } | |
32 | ||
33 | #define MAP_SIZE 16 | |
34 | ||
35 | static struct ocf_request *alloc_req() | |
36 | { | |
37 | struct ocf_request *req; | |
38 | struct ocf_cache *cache = test_malloc(sizeof(*cache)); | |
39 | ||
40 | req = test_malloc(sizeof(*req) + MAP_SIZE * sizeof(req->map[0])); | |
41 | req->map = req->__map; | |
42 | req->cache = cache; | |
43 | ||
44 | return req; | |
45 | } | |
46 | ||
47 | static void free_req(struct ocf_request *req) | |
48 | { | |
49 | test_free(req->cache); | |
50 | test_free(req); | |
51 | } | |
52 | ||
53 | static void _test_lock_order(struct ocf_request* req, | |
54 | unsigned hash[], unsigned hash_count, | |
55 | unsigned expected_call[], unsigned expected_call_count) | |
56 | { | |
57 | unsigned i; | |
58 | ||
59 | req->core_line_count = hash_count; | |
60 | ||
61 | for (i = 0; i < hash_count; i++) | |
62 | req->map[i].hash = hash[i]; | |
63 | ||
64 | for (i = 0; i < expected_call_count; i++) { | |
65 | expect_function_call(__wrap_ocf_metadata_hash_lock); | |
66 | expect_value(__wrap_ocf_metadata_hash_lock, hash, expected_call[i]); | |
67 | } | |
68 | ||
69 | ocf_req_hash_lock_rd(req); | |
70 | ||
71 | } | |
72 | ||
73 | static void ocf_req_hash_lock_rd_test01(void **state) | |
74 | { | |
75 | struct ocf_request *req = alloc_req(); | |
76 | struct { | |
77 | struct { | |
78 | unsigned val[MAP_SIZE]; | |
79 | unsigned count; | |
80 | } hash, expected_call; | |
81 | } test_cases[] = { | |
82 | { | |
83 | .hash = {.val = {2}, .count = 1}, | |
84 | .expected_call = {.val = {2}, .count = 1} | |
85 | }, | |
86 | { | |
87 | .hash = {.val = {2, 3, 4}, .count = 3}, | |
88 | .expected_call = {.val = {2, 3, 4}, .count = 3} | |
89 | }, | |
90 | { | |
91 | .hash = {.val = {2, 3, 4, 0}, .count = 4}, | |
92 | .expected_call = {.val = {0, 2, 3, 4}, .count = 4} | |
93 | }, | |
94 | { | |
95 | .hash = {.val = {2, 3, 4, 0, 1, 2, 3, 4, 0, 1}, .count = 10}, | |
96 | .expected_call = {.val = {0, 1, 2, 3, 4}, .count = 5} | |
97 | }, | |
98 | { | |
99 | .hash = {.val = {4, 0}, .count = 2}, | |
100 | .expected_call = {.val = {0, 4}, .count = 2} | |
101 | }, | |
102 | { | |
103 | .hash = {.val = {0, 1, 2, 3, 4, 0, 1}, .count = 7}, | |
104 | .expected_call = {.val = {0, 1, 2, 3, 4}, .count = 5} | |
105 | }, | |
106 | { | |
107 | .hash = {.val = {1, 2, 3, 4, 0, 1}, .count = 6}, | |
108 | .expected_call = {.val = {0, 1, 2, 3, 4}, .count = 5} | |
109 | }, | |
110 | }; | |
111 | const unsigned test_case_count = sizeof(test_cases) / sizeof(test_cases[0]); | |
112 | unsigned i; | |
113 | ||
114 | req->cache->metadata.lock.num_hash_entries = 5; | |
115 | ||
116 | print_test_description("Verify hash locking order\n"); | |
117 | ||
118 | for (i = 0; i < test_case_count; i++) { | |
119 | _test_lock_order(req, test_cases[i].hash.val, test_cases[i].hash.count, | |
120 | test_cases[i].expected_call.val, test_cases[i].expected_call.count); | |
121 | } | |
122 | ||
123 | free_req(req); | |
124 | } | |
125 | ||
126 | int main(void) | |
127 | { | |
128 | const struct CMUnitTest tests[] = { | |
129 | cmocka_unit_test(ocf_req_hash_lock_rd_test01) | |
130 | }; | |
131 | ||
132 | print_message("Unit test for ocf_req_hash_lock_rd\n"); | |
133 | ||
134 | return cmocka_run_group_tests(tests, NULL, NULL); | |
135 | } |