From: Eduardo Habkost <ehabkost@redhat.com>
To: qemu-devel@nongnu.org
Cc: Markus Armbruster <armbru@redhat.com>,
Michael Roth <mdroth@linux.vnet.ibm.com>
Subject: [Qemu-devel] [RFC 01/15] tests: Test cases for error API
Date: Tue, 13 Jun 2017 13:52:59 -0300 [thread overview]
Message-ID: <20170613165313.20954-2-ehabkost@redhat.com> (raw)
In-Reply-To: <20170613165313.20954-1-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
---
tests/test-qapi-util.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++++++
tests/Makefile.include | 2 +-
2 files changed, 100 insertions(+), 1 deletion(-)
diff --git a/tests/test-qapi-util.c b/tests/test-qapi-util.c
index e8697577a5..3695034c32 100644
--- a/tests/test-qapi-util.c
+++ b/tests/test-qapi-util.c
@@ -75,11 +75,110 @@ static void test_parse_qapi_name(void)
g_assert(ret == -1);
}
+static void successfn(Error **errp)
+{
+ g_assert(!errp || !*errp);
+}
+
+static void fail1(Error **errp)
+{
+ g_assert(!errp || !*errp);
+
+ error_setg(errp, "error1");
+
+ g_assert(!errp || *errp);
+}
+
+static void fail2(Error **errp)
+{
+ g_assert(!errp || !*errp);
+
+ error_setg(errp, "error2");
+
+ g_assert(!errp || *errp);
+}
+
+static void multifn(Error **errp)
+{
+ Error *err1 = NULL, *err2 = NULL;
+ successfn(&err1);
+ g_assert(!err1);
+
+ fail1(&err1);
+ g_assert(err1);
+ g_assert_cmpstr(error_get_pretty(err1), ==, "error1");
+
+ fail2(&err2);
+ g_assert(err2);
+ g_assert_cmpstr(error_get_pretty(err2), ==, "error2");
+
+ error_propagate(&err1, err2);
+ g_assert(err1);
+ g_assert_cmpstr(error_get_pretty(err1), ==, "error1");
+
+ error_propagate(errp, err1);
+}
+
+static void test_propagate(void (*fn)(Error **), Error **errp)
+{
+ bool failed;
+ Error *local_err = NULL;
+
+ g_assert(!errp || !*errp);
+
+ fn(&local_err);
+ failed = !!local_err;
+ error_propagate(errp, local_err);
+
+ g_assert(!errp || (failed == !!*errp));
+}
+
+static void test_error_api(void)
+{
+ Error *err = NULL;
+
+ successfn(NULL);
+ test_propagate(successfn, NULL);
+
+ fail1(NULL);
+ test_propagate(fail1, NULL);
+
+ multifn(NULL);
+ test_propagate(multifn, NULL);
+
+ successfn(&err);
+ g_assert(!err);
+
+ test_propagate(successfn, &err);
+ g_assert(!err);
+
+ fail1(&err);
+ g_assert(err);
+ g_assert_cmpstr(error_get_pretty(err), ==, "error1");
+ error_free_or_abort(&err);
+
+ test_propagate(fail1, &err);
+ g_assert(err);
+ g_assert_cmpstr(error_get_pretty(err), ==, "error1");
+ error_free_or_abort(&err);
+
+ multifn(&err);
+ g_assert(err);
+ g_assert_cmpstr(error_get_pretty(err), ==, "error1");
+ error_free_or_abort(&err);
+
+ test_propagate(multifn, &err);
+ g_assert(err);
+ g_assert_cmpstr(error_get_pretty(err), ==, "error1");
+ error_free_or_abort(&err);
+}
+
int main(int argc, char *argv[])
{
g_test_init(&argc, &argv, NULL);
g_test_add_func("/qapi/util/qapi_enum_parse", test_qapi_enum_parse);
g_test_add_func("/qapi/util/parse_qapi_name", test_parse_qapi_name);
+ g_test_add_func("/qapi/util/error", test_error_api);
g_test_run();
return 0;
}
diff --git a/tests/Makefile.include b/tests/Makefile.include
index f42f3dfa72..e38abfabeb 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -129,7 +129,7 @@ check-unit-y += tests/test-uuid$(EXESUF)
check-unit-y += tests/ptimer-test$(EXESUF)
gcov-files-ptimer-test-y = hw/core/ptimer.c
check-unit-y += tests/test-qapi-util$(EXESUF)
-gcov-files-test-qapi-util-y = qapi/qapi-util.c
+gcov-files-test-qapi-util-y = qapi/qapi-util.c qapi/error.c
check-block-$(CONFIG_POSIX) += tests/qemu-iotests-quick.sh
--
2.11.0.259.g40922b1
next prev parent reply other threads:[~2017-06-13 16:53 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-06-13 16:52 [Qemu-devel] [RFC 00/15] Error API: Flag errors in *errp even if errors are being ignored Eduardo Habkost
2017-06-13 16:52 ` Eduardo Habkost [this message]
2017-06-13 16:53 ` [Qemu-devel] [RFC 02/15] error: New IGNORE_ERRORS macro Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 03/15] Add qapi/error.h includes on files that will need it Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 04/15] [coccinelle] Use IGNORE_ERRORS instead of NULL as errp argument Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 05/15] qapi: Use IGNORE_ERRORS instead of NULL on generated code Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 06/15] test-qapi-util: Use IGNORE_ERRORS instead of NULL Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 07/15] Manual changes to use " Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 08/15] error: New ERR_IS_* macros for checking Error** values Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 09/15] [coccinelle] Use ERR_IS_* macros Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 10/15] test-qapi-util: " Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 11/15] Manual changes to use " Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 12/15] error: Make IGNORED_ERRORS not a NULL pointer Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 13/15] rdma: Simplify var declaration to avoid confusing Coccinelle Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 14/15] [coccinelle] Eliminate unnecessary local_err/error_propagate() usage Eduardo Habkost
2017-06-13 16:53 ` [Qemu-devel] [RFC 15/15] [test only] Use 'Error *err[static 1]' instead of 'Error **errp' to catch NULL errp arguments Eduardo Habkost
[not found] ` <20170615121407.GA2399@work-vm>
2017-06-17 19:33 ` Eduardo Habkost
2017-06-19 8:48 ` Dr. David Alan Gilbert
2017-06-19 9:43 ` Peter Maydell
2017-06-19 13:26 ` Eduardo Habkost
2017-06-27 20:12 ` Eric Blake
2017-06-27 21:31 ` Eduardo Habkost
2017-06-27 20:22 ` [Qemu-devel] [RFC 00/15] Error API: Flag errors in *errp even if errors are being ignored Eric Blake
2017-06-28 9:05 ` Markus Armbruster
2017-06-28 17:41 ` Eduardo Habkost
2017-06-29 6:54 ` Markus Armbruster
2017-06-29 12:57 ` Eduardo Habkost
2017-06-30 11:40 ` Markus Armbruster
2017-07-01 14:20 ` Eduardo Habkost
2017-07-03 12:51 ` Markus Armbruster
2017-07-01 14:29 ` Eduardo Habkost
2017-07-03 13:21 ` Markus Armbruster
2017-07-03 13:47 ` Eduardo Habkost
2017-06-29 14:01 ` Daniel P. Berrange
2017-06-29 13:39 ` Paolo Bonzini
2017-06-29 14:18 ` Daniel P. Berrange
2017-06-29 17:09 ` Eduardo Habkost
2017-06-29 17:38 ` Daniel P. Berrange
2017-06-29 17:47 ` Eduardo Habkost
2017-06-29 18:04 ` Daniel P. Berrange
2017-06-29 14:14 ` Daniel P. Berrange
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170613165313.20954-2-ehabkost@redhat.com \
--to=ehabkost@redhat.com \
--cc=armbru@redhat.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).