summaryrefslogtreecommitdiff
path: root/include/test_util.h
diff options
context:
space:
mode:
authorVic Yang <victoryang@chromium.org>2013-05-09 07:16:01 +0800
committerChromeBot <chrome-bot@google.com>2013-05-08 18:11:01 -0700
commite71f008388b3c69cf01a534c5084d7e3a441149b (patch)
treec68a0ba7443eef434ca3799ae85b4207ccfbc68c /include/test_util.h
parent4f463ebc46463d397e8a4c5296ad2168ce881bde (diff)
downloadchrome-ec-e71f008388b3c69cf01a534c5084d7e3a441149b.tar.gz
Put test utility macros in header
Several test utility macros have been duplicated across tests. Let's put them in a single place. BUG=chrome-os-partner:19236 TEST='make runtests', 'BOARD=spring make tests' BRANCH=None Change-Id: Ib0c9f829715425cc23e33b8ef456b17dfadab13c Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://gerrit.chromium.org/gerrit/50513 Reviewed-by: Vincent Palatin <vpalatin@chromium.org>
Diffstat (limited to 'include/test_util.h')
-rw-r--r--include/test_util.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/include/test_util.h b/include/test_util.h
new file mode 100644
index 0000000000..40ce8c2633
--- /dev/null
+++ b/include/test_util.h
@@ -0,0 +1,50 @@
+/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+/* Various utility for unit testing */
+
+#ifndef __CROS_EC_TEST_UTIL_H
+#define __CROS_EC_TEST_UTIL_H
+
+#include "common.h"
+#include "console.h"
+
+#define RUN_TEST(n) \
+ do { \
+ ccprintf("Running %s...", #n); \
+ cflush(); \
+ if (n() == EC_SUCCESS) { \
+ ccputs("OK\n"); \
+ } else { \
+ ccputs("Fail\n"); \
+ __test_error_count++; \
+ } \
+ } while (0)
+
+#define TEST_ASSERT(n) \
+ do { \
+ if (!(n)) { \
+ ccprintf("ASSERTION failed: %s\n", #n); \
+ return EC_ERROR_UNKNOWN; \
+ } \
+ } while (0)
+
+#define TEST_CHECK(n) \
+ do { \
+ if (n) \
+ return EC_SUCCESS; \
+ else \
+ return EC_ERROR_UNKNOWN; \
+ } while (0)
+
+void run_test(void);
+
+void test_reset(void);
+
+void test_print_result(void);
+
+extern int __test_error_count;
+
+#endif /* __CROS_EC_TEST_UTIL_H */