From: Tomasz Kulasek <tomaszx.kulasek@intel.com>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v3 1/3] test: test.h rework
Date: Thu, 29 Jan 2015 09:51:54 +0100 [thread overview]
Message-ID: <1422521516-780-2-git-send-email-tomaszx.kulasek@intel.com> (raw)
In-Reply-To: <1422521516-780-1-git-send-email-tomaszx.kulasek@intel.com>
v3 changes
- No major changes. Patch re-created for current release to maintain
consistency.
Signed-off-by: Pawel Wodkowski <pawelx.wodkowski@intel.com>
Signed-off-by: Tomasz Kulasek <tomaszx.kulasek@intel.com>
---
app/test/test.h | 112 ++++++++++++++++++++++++++++++++-----------------------
1 file changed, 66 insertions(+), 46 deletions(-)
diff --git a/app/test/test.h b/app/test/test.h
index 896f7db..5450986 100644
--- a/app/test/test.h
+++ b/app/test/test.h
@@ -36,62 +36,79 @@
#include <sys/queue.h>
-#define TEST_ASSERT(cond, msg, ...) do { \
- if (!(cond)) { \
- printf("TestCase %s() line %d failed: " \
- msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
- return -1; \
- } \
-} while (0)
+#define TEST_SUCCESS (0)
+#define TEST_FAILED (-1)
+
+/* Before including test.h file you can define
+ * TEST_TRACE_FAILURE(_file, _line, _func) macro to better trace/debug test
+ * failures. Mostly useful in test development phase. */
+#ifndef TEST_TRACE_FAILURE
+# define TEST_TRACE_FAILURE(_file, _line, _func)
+#endif
-#define TEST_ASSERT_EQUAL(a, b, msg, ...) do { \
- if (!(a == b)) { \
- printf("TestCase %s() line %d failed: " \
- msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
- return -1; \
- } \
+#define TEST_ASSERT(cond, msg, ...) do { \
+ if (!(cond)) { \
+ printf("TestCase %s() line %d failed: " \
+ msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+ TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
+ return TEST_FAILED; \
+ } \
} while (0)
-#define TEST_ASSERT_NOT_EQUAL(a, b, msg, ...) do { \
- if (!(a != b)) { \
- printf("TestCase %s() line %d failed: " \
- msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
- return -1; \
- } \
+#define TEST_ASSERT_EQUAL(a, b, msg, ...) do { \
+ if (!(a == b)) { \
+ printf("TestCase %s() line %d failed: " \
+ msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+ TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
+ return TEST_FAILED; \
+ } \
} while (0)
-#define TEST_ASSERT_SUCCESS(val, msg, ...) do { \
- if (!(val == 0)) { \
- printf("TestCase %s() line %d failed (err %d): " \
- msg "\n", __func__, __LINE__, val, \
- ##__VA_ARGS__); \
- return -1; \
- } \
+#define TEST_ASSERT_NOT_EQUAL(a, b, msg, ...) do { \
+ if (!(a != b)) { \
+ printf("TestCase %s() line %d failed: " \
+ msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+ TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
+ return TEST_FAILED; \
+ } \
} while (0)
-#define TEST_ASSERT_FAIL(val, msg, ...) do { \
- if (!(val != 0)) { \
- printf("TestCase %s() line %d failed: " \
- msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
- return -1; \
- } \
+#define TEST_ASSERT_SUCCESS(val, msg, ...) do { \
+ typeof(val) _val = (val); \
+ if (!(_val == 0)) { \
+ printf("TestCase %s() line %d failed (err %d): " \
+ msg "\n", __func__, __LINE__, _val, \
+ ##__VA_ARGS__); \
+ TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
+ return TEST_FAILED; \
+ } \
} while (0)
+#define TEST_ASSERT_FAIL(val, msg, ...) do { \
+ if (!(val != 0)) { \
+ printf("TestCase %s() line %d failed: " \
+ msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+ TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
+ return TEST_FAILED; \
+ } \
+} while (0)
-#define TEST_ASSERT_NULL(val, msg, ...) do { \
- if (!(val == NULL)) { \
- printf("TestCase %s() line %d failed: " \
- msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
- return -1; \
- } \
+#define TEST_ASSERT_NULL(val, msg, ...) do { \
+ if (!(val == NULL)) { \
+ printf("TestCase %s() line %d failed: " \
+ msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+ TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
+ return TEST_FAILED; \
+ } \
} while (0)
-#define TEST_ASSERT_NOT_NULL(val, msg, ...) do { \
- if (!(val != NULL)) { \
- printf("TestCase %s() line %d failed: " \
- msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
- return -1; \
- } \
+#define TEST_ASSERT_NOT_NULL(val, msg, ...) do { \
+ if (!(val != NULL)) { \
+ printf("TestCase %s() line %d failed: " \
+ msg "\n", __func__, __LINE__, ##__VA_ARGS__); \
+ TEST_TRACE_FAILURE(__FILE__, __LINE__, __func__); \
+ return TEST_FAILED; \
+ } \
} while (0)
struct unit_test_case {
@@ -104,8 +121,11 @@ struct unit_test_case {
#define TEST_CASE(fn) { NULL, NULL, fn, #fn " succeeded", #fn " failed"}
-#define TEST_CASE_ST(setup, teardown, testcase) \
- { setup, teardown, testcase, #testcase " succeeded", \
+#define TEST_CASE_NAMED(name, fn) { NULL, NULL, fn, name " succeeded", \
+ name " failed"}
+
+#define TEST_CASE_ST(setup, teardown, testcase) \
+ { setup, teardown, testcase, #testcase " succeeded", \
#testcase " failed "}
#define TEST_CASES_END() { NULL, NULL, NULL, NULL, NULL }
--
1.7.9.5
next prev parent reply other threads:[~2015-01-29 8:53 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-12-12 9:14 [dpdk-dev] [PATCH 0/3] bond mode 4: add unit tests Michal Jastrzebski
2014-12-12 9:14 ` [dpdk-dev] [PATCH 1/3] bond change warning Michal Jastrzebski
2015-02-18 18:06 ` Thomas Monjalon
2014-12-12 9:14 ` [dpdk-dev] [PATCH 2/3] PMD ring MAC management, fix initialization, link up/down Michal Jastrzebski
2015-01-15 10:53 ` Thomas Monjalon
2015-01-19 11:56 ` [dpdk-dev] [PATCH v2 0/3] " Tomasz Kulasek
2015-01-19 11:56 ` [dpdk-dev] [PATCH v2 1/3] PMD Ring - Add link up/down functions Tomasz Kulasek
2015-01-19 11:56 ` [dpdk-dev] [PATCH v2 2/3] PMD Ring - Add MAC addr add/remove functions Tomasz Kulasek
2015-01-19 11:56 ` [dpdk-dev] [PATCH v2 3/3] PMD Ring - Fix for MAC per device management Tomasz Kulasek
2015-01-28 11:56 ` [dpdk-dev] [PATCH v2 0/3] PMD ring MAC management, fix initialization, link up/down Doherty, Declan
2015-02-18 17:33 ` Thomas Monjalon
2014-12-12 9:14 ` [dpdk-dev] [PATCH 3/3] unit tests add mode 4 unit test Michal Jastrzebski
2015-01-15 10:55 ` Thomas Monjalon
2015-01-19 12:43 ` [dpdk-dev] [PATCH v2 0/2] " Tomasz Kulasek
2015-01-19 12:43 ` [dpdk-dev] [PATCH v2 1/2] Unit tests - test.h rework Tomasz Kulasek
2015-01-19 12:43 ` [dpdk-dev] [PATCH v2 2/2] Unit tests for mode 4 Tomasz Kulasek
2015-01-29 8:51 ` [dpdk-dev] [PATCH v3 0/3] " Tomasz Kulasek
2015-01-29 8:51 ` Tomasz Kulasek [this message]
2015-01-29 8:51 ` [dpdk-dev] [PATCH v3 2/3] test: " Tomasz Kulasek
2015-02-12 11:49 ` Declan Doherty
2015-01-29 8:51 ` [dpdk-dev] [PATCH v3] mk: Link test app against librte_pmd_ring when needed Tomasz Kulasek
2015-02-12 11:50 ` Declan Doherty
2015-02-13 10:38 ` [dpdk-dev] [PATCH v4 0/4] Unit tests for mode 4 Tomasz Kulasek
2015-02-13 10:38 ` [dpdk-dev] [PATCH v4 1/4] test: test.h rework Tomasz Kulasek
2015-02-13 10:38 ` [dpdk-dev] [PATCH v4 2/4] test: Unit tests for mode 4 Tomasz Kulasek
2015-02-13 10:38 ` [dpdk-dev] [PATCH v4 3/4] mk: Link test app against librte_pmd_ring when needed Tomasz Kulasek
2015-02-13 10:38 ` [dpdk-dev] [PATCH v4 4/4] pmd_bond: Set routines required by test app global Tomasz Kulasek
2015-02-13 11:08 ` [dpdk-dev] [PATCH v4 0/4] Unit tests for mode 4 Declan Doherty
2015-02-18 18:00 ` Thomas Monjalon
2014-12-12 15:27 ` [dpdk-dev] [PATCH 0/3] bond mode 4: add unit tests Doherty, Declan
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=1422521516-780-2-git-send-email-tomaszx.kulasek@intel.com \
--to=tomaszx.kulasek@intel.com \
--cc=dev@dpdk.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).