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

Function test_mem_rdev

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

Source from the content-addressed store, hash-verified

328}
329
330static void test_mem_rdev(void **state)
331{
332 const size_t size = 256;
333 u8 backing[size];
334 u8 scratch[size];
335 int i;
336 struct region_device mem;
337 rdev_chain_mem_rw(&mem, backing, size);
338
339 /* Test writing to and reading from full mapping. */
340 memset(backing, 0xa5, size);
341 u8 *mapping = rdev_mmap_full(&mem);
342 assert_non_null(mapping);
343 for (i = 0; i < size; i++)
344 assert_int_equal(mapping[i], 0xa5);
345 memset(mapping, 0x5a, size);
346 for (i = 0; i < size; i++)
347 assert_int_equal(backing[i], 0x5a);
348 assert_int_equal(rdev_munmap(&mem, mapping), 0);
349
350 /* Test read/write/erase of single bytes. */
351 for (i = 0; i < size; i++) {
352 u8 val = i + 0xaa;
353 scratch[0] = val;
354 assert_int_equal(rdev_writeat(&mem, &scratch, i, 1), 1);
355 assert_int_equal(backing[i], val);
356 assert_int_equal(scratch[0], val);
357 val = i + 0x55;
358 backing[i] = val;
359 assert_int_equal(rdev_readat(&mem, &scratch, i, 1), 1);
360 assert_int_equal(scratch[0], val);
361 assert_int_equal(backing[i], val);
362 assert_int_equal(rdev_eraseat(&mem, i, 1), 1);
363 assert_int_equal(backing[i], 0);
364 }
365
366 /* Test read/write/erase of larger chunk. */
367 size_t offs = 0x47;
368 size_t chunk = 0x72;
369 memset(backing, 0, size);
370 memset(scratch, 0, size);
371 memset(scratch + offs, 0x39, chunk);
372 assert_int_equal(rdev_writeat(&mem, scratch + offs, offs, chunk), chunk);
373 assert_memory_equal(backing, scratch, size);
374 memset(backing, 0, size);
375 assert_int_equal(rdev_readat(&mem, scratch + offs, offs, chunk), chunk);
376 assert_memory_equal(backing, scratch, size);
377 memset(scratch + offs + 1, 0, chunk - 1);
378 assert_int_equal(rdev_eraseat(&mem, offs + 1, chunk - 1), chunk - 1);
379 assert_memory_equal(backing, scratch, size);
380
381 /* Test mapping of larger chunk. */
382 memset(backing, 0, size);
383 mapping = rdev_mmap(&mem, offs, chunk);
384 assert_non_null(mapping);
385 memset(scratch, 0x93, size);
386 memcpy(mapping, scratch, chunk);
387 memset(scratch, 0, size);

Callers

nothing calls this directly

Calls 9

rdev_chain_mem_rwFunction · 0.85
rdev_mmap_fullFunction · 0.85
rdev_munmapFunction · 0.85
rdev_writeatFunction · 0.85
rdev_readatFunction · 0.85
rdev_eraseatFunction · 0.85
rdev_mmapFunction · 0.85
memsetFunction · 0.50
memcpyFunction · 0.50

Tested by

no test coverage detected