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

Function fmap_append_area_test

util/cbfstool/test.c:87–134  ·  view source on GitHub ↗

this test re-allocates the fmap, so it gets a double-pointer */

Source from the content-addressed store, hash-verified

85
86/* this test re-allocates the fmap, so it gets a double-pointer */
87static int fmap_append_area_test(struct fmap **fmap)
88{
89 int total_size;
90 uint16_t nareas_orig;
91 /* test_area will be used by fmap_csum_test and find_area_test */
92 struct fmap_area test_area = {
93 .offset = htole32(0x400),
94 .size = htole32(0x10000),
95 .name = "test_area_1",
96 .flags = htole16(FMAP_AREA_STATIC),
97 };
98
99 status = fail;
100
101 if ((fmap_append_area(NULL, 0, 0, test_area.name, 0) >= 0) ||
102 (fmap_append_area(fmap, 0, 0, NULL, 0) >= 0)) {
103 printf("FAILURE: failed to abort on NULL pointer input\n");
104 goto fmap_append_area_test_exit;
105 }
106
107 nareas_orig = le16toh((*fmap)->nareas);
108 (*fmap)->nareas = htole16(~(0));
109 if (fmap_append_area(fmap, 0, 0, (const uint8_t *)"foo", 0) >= 0) {
110 printf("FAILURE: failed to abort with too many areas\n");
111 goto fmap_append_area_test_exit;
112 }
113 (*fmap)->nareas = htole16(nareas_orig);
114
115 total_size = sizeof(**fmap) + sizeof(test_area);
116 if (fmap_append_area(fmap,
117 le32toh(test_area.offset),
118 le32toh(test_area.size),
119 test_area.name,
120 le16toh(test_area.flags)
121 ) != total_size) {
122 printf("failed to append area\n");
123 goto fmap_append_area_test_exit;
124 }
125
126 if (le16toh((*fmap)->nareas) != 1) {
127 printf("FAILURE: failed to increment number of areas\n");
128 goto fmap_append_area_test_exit;
129 }
130
131 status = pass;
132fmap_append_area_test_exit:
133 return status;
134}
135
136static int fmap_find_area_test(struct fmap *fmap)
137{

Callers 1

fmap_testFunction · 0.85

Calls 2

fmap_append_areaFunction · 0.85
printfFunction · 0.85

Tested by

no test coverage detected