Received: from eggs.gnu.org ([2001:4830:134:3::10]:47841) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1oPS-0002G3-4F for qemu-devel@nongnu.org; Thu, 18 Dec 2014 22:39:26 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Y1oPM-0008Fq-H4 for qemu-devel@nongnu.org; Thu, 18 Dec 2014 22:39:22 -0500 Received: from [59.151.112.132] (port=55792 helo=heian.cn.fujitsu.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Y1oPM-0008Cn-59 for qemu-devel@nongnu.org; Thu, 18 Dec 2014 22:39:16 -0500 From: Yang Hongyang Date: Fri, 19 Dec 2014 11:38:06 +0800 Message-ID: <1418960286-4749-3-git-send-email-yanghy@cn.fujitsu.com> In-Reply-To: <1418960286-4749-1-git-send-email-yanghy@cn.fujitsu.com> References: <1418960286-4749-1-git-send-email-yanghy@cn.fujitsu.com> MIME-Version: 1.0 Content-Type: text/plain Subject: [Qemu-devel] [RESEND PATCH 2/2] Tests: QEMUSizedBuffer/QEMUBuffer List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Amit Shah , Yang Hongyang , "Dr. David Alan Gilbert" , Juan Quintela Modify some of tests/test-vmstate.c due to qemu_bufopen() change. If you create a QEMUSizedBuffer yourself, you have to explicitly free it. Signed-off-by: Yang Hongyang Cc: Dr. David Alan Gilbert Cc: Juan Quintela Cc: Amit Shah Reviewed-by: Dr. David Alan Gilbert --- tests/test-vmstate.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/test-vmstate.c b/tests/test-vmstate.c index 5e0fd13..39b7b01 100644 --- a/tests/test-vmstate.c +++ b/tests/test-vmstate.c @@ -60,16 +60,6 @@ static QEMUFile *open_test_file(bool write) return qemu_fdopen(fd, write ? "wb" : "rb"); } -/* Open a read-only qemu-file from an existing memory block */ -static QEMUFile *open_mem_file_read(const void *data, size_t len) -{ - /* The qsb gets freed by qemu_fclose */ - QEMUSizedBuffer *qsb = qsb_create(data, len); - g_assert(qsb); - - return qemu_bufopen("r", qsb); -} - /* * Check that the contents of the memory-buffered file f match * the given size/data. @@ -450,7 +440,9 @@ static void test_load_noskip(void) QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ }; - QEMUFile *loading = open_mem_file_read(buf, sizeof(buf)); + QEMUSizedBuffer *qsb = qsb_create(buf, sizeof(buf)); + g_assert(qsb); + QEMUFile *loading = qemu_bufopen("r", qsb); TestStruct obj = { .skip_c_e = false }; vmstate_load_state(loading, &vmstate_skipping, &obj, 2); g_assert(!qemu_file_get_error(loading)); @@ -461,6 +453,7 @@ static void test_load_noskip(void) g_assert_cmpint(obj.e, ==, 50); g_assert_cmpint(obj.f, ==, 60); qemu_fclose(loading); + qsb_free(qsb); } static void test_load_skip(void) @@ -473,7 +466,9 @@ static void test_load_skip(void) QEMU_VM_EOF, /* just to ensure we won't get EOF reported prematurely */ }; - QEMUFile *loading = open_mem_file_read(buf, sizeof(buf)); + QEMUSizedBuffer *qsb = qsb_create(buf, sizeof(buf)); + g_assert(qsb); + QEMUFile *loading = qemu_bufopen("r", qsb); TestStruct obj = { .skip_c_e = true, .c = 300, .e = 500 }; vmstate_load_state(loading, &vmstate_skipping, &obj, 2); g_assert(!qemu_file_get_error(loading)); @@ -484,6 +479,7 @@ static void test_load_skip(void) g_assert_cmpint(obj.e, ==, 500); g_assert_cmpint(obj.f, ==, 60); qemu_fclose(loading); + qsb_free(qsb); } int main(int argc, char **argv) -- 1.9.1