[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PULL v2 36/65] libqos/ahci: Add ahci_clean_mem
From: |
Stefan Hajnoczi |
Subject: |
[Qemu-devel] [PULL v2 36/65] libqos/ahci: Add ahci_clean_mem |
Date: |
Mon, 16 Feb 2015 15:46:01 +0000 |
From: John Snow <address@hidden>
Clean up guest memory being used in ahci_clean_mem, to be
called during ahci_shutdown. With all guest memory leaks removed,
add an option to the allocator to throw an assertion if a leak
occurs.
This test adds some sanity to both the AHCI library and the
allocator.
Signed-off-by: John Snow <address@hidden>
Reviewed-by: Paolo Bonzini <address@hidden>
Message-id: address@hidden
Signed-off-by: Stefan Hajnoczi <address@hidden>
---
tests/ahci-test.c | 3 +++
tests/libqos/ahci.c | 18 ++++++++++++++++++
tests/libqos/ahci.h | 1 +
tests/libqos/malloc.c | 5 +++++
tests/libqos/malloc.h | 1 +
5 files changed, 28 insertions(+)
diff --git a/tests/ahci-test.c b/tests/ahci-test.c
index 47491fe..3a0131a 100644
--- a/tests/ahci-test.c
+++ b/tests/ahci-test.c
@@ -86,6 +86,7 @@ static AHCIQState *ahci_boot(void)
"-device ide-hd,drive=drive0 "
"-global ide-hd.ver=%s";
s->parent = qtest_pc_boot(cli, tmp_path, "testdisk", "version");
+ alloc_set_flags(s->parent->alloc, ALLOC_LEAK_ASSERT);
/* Verify that we have an AHCI device present. */
s->dev = get_ahci_device(&s->fingerprint);
@@ -99,6 +100,8 @@ static AHCIQState *ahci_boot(void)
static void ahci_shutdown(AHCIQState *ahci)
{
QOSState *qs = ahci->parent;
+
+ ahci_clean_mem(ahci);
free_ahci_device(ahci->dev);
g_free(ahci);
qtest_shutdown(qs);
diff --git a/tests/libqos/ahci.c b/tests/libqos/ahci.c
index 8522224..a6105c7 100644
--- a/tests/libqos/ahci.c
+++ b/tests/libqos/ahci.c
@@ -130,6 +130,24 @@ void free_ahci_device(QPCIDevice *dev)
qpci_free_pc(pcibus);
}
+/* Free all memory in-use by the AHCI device. */
+void ahci_clean_mem(AHCIQState *ahci)
+{
+ uint8_t port, slot;
+
+ for (port = 0; port < 32; ++port) {
+ if (ahci->port[port].fb) {
+ ahci_free(ahci, ahci->port[port].fb);
+ }
+ if (ahci->port[port].clb) {
+ for (slot = 0; slot < 32; slot++) {
+ ahci_destroy_command(ahci, port, slot);
+ }
+ ahci_free(ahci, ahci->port[port].clb);
+ }
+ }
+}
+
/*** Logical Device Initialization ***/
/**
diff --git a/tests/libqos/ahci.h b/tests/libqos/ahci.h
index 9133033..39b99d3 100644
--- a/tests/libqos/ahci.h
+++ b/tests/libqos/ahci.h
@@ -499,6 +499,7 @@ uint64_t ahci_alloc(AHCIQState *ahci, size_t bytes);
void ahci_free(AHCIQState *ahci, uint64_t addr);
QPCIDevice *get_ahci_device(uint32_t *fingerprint);
void free_ahci_device(QPCIDevice *dev);
+void ahci_clean_mem(AHCIQState *ahci);
void ahci_pci_enable(AHCIQState *ahci);
void start_ahci_device(AHCIQState *ahci);
void ahci_hba_enable(AHCIQState *ahci);
diff --git a/tests/libqos/malloc.c b/tests/libqos/malloc.c
index 42e3434..67f3190 100644
--- a/tests/libqos/malloc.c
+++ b/tests/libqos/malloc.c
@@ -324,3 +324,8 @@ void alloc_set_page_size(QGuestAllocator *allocator, size_t
page_size)
g_assert(is_power_of_2(page_size));
allocator->page_size = page_size;
}
+
+void alloc_set_flags(QGuestAllocator *allocator, QAllocOpts opts)
+{
+ allocator->opts |= opts;
+}
diff --git a/tests/libqos/malloc.h b/tests/libqos/malloc.h
index a39dba4..71ac407 100644
--- a/tests/libqos/malloc.h
+++ b/tests/libqos/malloc.h
@@ -36,5 +36,6 @@ QGuestAllocator *alloc_init(uint64_t start, uint64_t end);
QGuestAllocator *alloc_init_flags(QAllocOpts flags,
uint64_t start, uint64_t end);
void alloc_set_page_size(QGuestAllocator *allocator, size_t page_size);
+void alloc_set_flags(QGuestAllocator *allocator, QAllocOpts opts);
#endif
--
2.1.0
- [Qemu-devel] [PULL v2 22/65] qtest/ahci: rename 'Command' to 'CommandHeader', (continued)
- [Qemu-devel] [PULL v2 22/65] qtest/ahci: rename 'Command' to 'CommandHeader', Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 23/65] libqos/ahci: Add command header helpers, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 25/65] libqos/ahci: Add ahci_port_check_interrupts helper, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 26/65] libqos/ahci: Add port_check_nonbusy helper, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 28/65] qtest/ahci: Demagic ahci tests., Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 29/65] qtest/ahci: add ahci_write_fis, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 30/65] libqos/ahci: Add ide cmd properties, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 32/65] libqos/ahci: add ahci command verify, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 34/65] libqos/ahci: Add ahci_guest_io, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 31/65] libqos/ahci: add ahci command functions, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 36/65] libqos/ahci: Add ahci_clean_mem,
Stefan Hajnoczi <=
- [Qemu-devel] [PULL v2 33/65] libqos/ahci: add ahci command size setters, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 35/65] libqos/ahci: add ahci_io, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 41/65] block: vmdk - fixed sizeof() error, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 43/65] qemu-io: Account IO by aio_read and aio_write, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 38/65] qtest/ahci: Adding simple dma read-write test, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 40/65] savevm: Improve error message for blocked migration, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 39/65] nbd: fix the co_queue multi-adding bug, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 42/65] qtest: Fix deadloop by running main loop AIO context's timers, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 44/65] qtest: Add scripts/qtest.py, Stefan Hajnoczi, 2015/02/16
- [Qemu-devel] [PULL v2 37/65] qtest/ahci: Assert sector size in identify test, Stefan Hajnoczi, 2015/02/16