| 9 | #define VAL(v) ((size_t)(v##ULL << (sizeof(size_t) * 8 - 4))) |
| 10 | |
| 11 | static void test_region(void **state) |
| 12 | { |
| 13 | /* Self-test: make sure VAL() overflow works as intended. */ |
| 14 | assert_true(VAL(5) + VAL(10) > VAL(10)); |
| 15 | assert_true(VAL(7) + VAL(10) < VAL(10)); |
| 16 | |
| 17 | struct region outer = {.offset = VAL(2), .size = VAL(4)}; |
| 18 | assert_int_equal(region_offset(&outer), VAL(2)); |
| 19 | assert_int_equal(region_sz(&outer), VAL(4)); |
| 20 | assert_int_equal(region_last(&outer), VAL(6) - 1); |
| 21 | |
| 22 | struct region inner = {.offset = VAL(3), .size = VAL(2)}; |
| 23 | assert_true(region_is_subregion(&outer, &inner)); |
| 24 | |
| 25 | struct region touching_bottom = {.offset = VAL(2), .size = VAL(1)}; |
| 26 | assert_true(region_is_subregion(&outer, &touching_bottom)); |
| 27 | |
| 28 | struct region touching_top = {.offset = VAL(5), .size = VAL(1)}; |
| 29 | assert_true(region_is_subregion(&outer, &touching_top)); |
| 30 | |
| 31 | struct region overlap_bottom = {.offset = VAL(1), .size = VAL(2)}; |
| 32 | assert_false(region_is_subregion(&outer, &overlap_bottom)); |
| 33 | |
| 34 | struct region overlap_top = {.offset = VAL(5), .size = VAL(2)}; |
| 35 | assert_false(region_is_subregion(&outer, &overlap_top)); |
| 36 | |
| 37 | struct region below = {.offset = 0, .size = VAL(1)}; |
| 38 | assert_false(region_is_subregion(&outer, &below)); |
| 39 | |
| 40 | struct region above = {.offset = VAL(0xf), .size = VAL(1)}; |
| 41 | assert_false(region_is_subregion(&outer, &above)); |
| 42 | } |
| 43 | |
| 44 | static void *mock_mmap(const struct region_device *rdev, size_t offset, size_t size) |
| 45 | { |
nothing calls this directly
no test coverage detected