mirror of
https://github.com/qemu/qemu.git
synced 2026-07-08 17:46:10 +00:00
tests: add unit tests for RamDiscardManager multi-source aggregation
Add various unit tests for the RamDiscardManager multi-source aggregation functionality. The test uses a TestRamDiscardSource QOM object that tracks populated state via a bitmap, similar to RamBlockAttributes implementation. Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com> Link: https://lore.kernel.org/r/20260604-rdm5-v5-10-5768e6a0943d@redhat.com Signed-off-by: Peter Xu <peterx@redhat.com>
This commit is contained in:
committed by
Peter Xu
parent
a947cf84c5
commit
c2237aaf6d
@@ -3363,6 +3363,8 @@ F: system/memory-internal.h
|
||||
F: system/ram-block-attributes.c
|
||||
F: system/ram-discard-manager.c
|
||||
F: scripts/coccinelle/memory-region-housekeeping.cocci
|
||||
F: tests/unit/test-ram-discard-manager.c
|
||||
F: tests/unit/test-ram-discard-manager-stubs.c
|
||||
|
||||
Memory devices
|
||||
M: David Hildenbrand <david@kernel.org>
|
||||
|
||||
@@ -138,7 +138,13 @@ if have_system
|
||||
'test-bufferiszero': [],
|
||||
'test-smp-parse': [qom, meson.project_source_root() / 'hw/core/machine-smp.c'],
|
||||
'test-vmstate': [migration, io],
|
||||
'test-yank': ['socket-helpers.c', qom, io, chardev]
|
||||
'test-yank': ['socket-helpers.c', qom, io, chardev],
|
||||
'test-ram-discard-manager': [
|
||||
'test-ram-discard-manager.c',
|
||||
'test-ram-discard-manager-stubs.c',
|
||||
meson.project_source_root() / 'system/ram-discard-manager.c',
|
||||
genh, qemuutil, qom
|
||||
],
|
||||
}
|
||||
if config_host_data.get('CONFIG_INOTIFY1')
|
||||
tests += {'test-util-filemonitor': []}
|
||||
|
||||
48
tests/unit/test-ram-discard-manager-stubs.c
Normal file
48
tests/unit/test-ram-discard-manager-stubs.c
Normal file
@@ -0,0 +1,48 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-or-later */
|
||||
#include "qemu/osdep.h"
|
||||
#include "qom/object.h"
|
||||
#include "glib.h"
|
||||
#include "system/memory.h"
|
||||
|
||||
RamDiscardManager *memory_region_get_ram_discard_manager(MemoryRegion *mr)
|
||||
{
|
||||
return mr->rdm;
|
||||
}
|
||||
|
||||
int memory_region_add_ram_discard_source(MemoryRegion *mr,
|
||||
RamDiscardSource *source)
|
||||
{
|
||||
if (!mr->rdm) {
|
||||
mr->rdm = ram_discard_manager_new(mr);
|
||||
}
|
||||
return ram_discard_manager_add_source(mr->rdm, source);
|
||||
}
|
||||
|
||||
int memory_region_del_ram_discard_source(MemoryRegion *mr,
|
||||
RamDiscardSource *source)
|
||||
{
|
||||
RamDiscardManager *rdm = mr->rdm;
|
||||
|
||||
if (!rdm) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return ram_discard_manager_del_source(rdm, source);
|
||||
}
|
||||
|
||||
uint64_t memory_region_size(const MemoryRegion *mr)
|
||||
{
|
||||
return int128_get64(mr->size);
|
||||
}
|
||||
|
||||
MemoryRegionSection *memory_region_section_new_copy(MemoryRegionSection *s)
|
||||
{
|
||||
MemoryRegionSection *copy = g_new(MemoryRegionSection, 1);
|
||||
*copy = *s;
|
||||
return copy;
|
||||
}
|
||||
|
||||
void memory_region_section_free_copy(MemoryRegionSection *s)
|
||||
{
|
||||
g_free(s);
|
||||
}
|
||||
1235
tests/unit/test-ram-discard-manager.c
Normal file
1235
tests/unit/test-ram-discard-manager.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user