MCPcopy Create free account
hub / github.com/coreboot/coreboot / test_region

Function test_region

tests/commonlib/region-test.c:11–42  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9#define VAL(v) ((size_t)(v##ULL << (sizeof(size_t) * 8 - 4)))
10
11static 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
44static void *mock_mmap(const struct region_device *rdev, size_t offset, size_t size)
45{

Callers

nothing calls this directly

Calls 4

region_offsetFunction · 0.85
region_szFunction · 0.85
region_lastFunction · 0.85
region_is_subregionFunction · 0.85

Tested by

no test coverage detected