summaryrefslogtreecommitdiff
path: root/common
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 /common
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 'common')
-rw-r--r--common/build.mk1
-rw-r--r--common/test_util.c36
2 files changed, 37 insertions, 0 deletions
diff --git a/common/build.mk b/common/build.mk
index ae7ca4fd80..5df925b7d0 100644
--- a/common/build.mk
+++ b/common/build.mk
@@ -48,3 +48,4 @@ common-$(CONFIG_TMP006)+=tmp006.o
common-$(CONFIG_TSU6721)+=tsu6721.o
common-$(CONFIG_USB_PORT_POWER_SMART)+=usb_port_power_smart.o
common-$(CONFIG_USB_PORT_POWER_DUMB)+=usb_port_power_dumb.o
+common-$(TEST_BUILD)+=test_util.o
diff --git a/common/test_util.c b/common/test_util.c
new file mode 100644
index 0000000000..8594f3468e
--- /dev/null
+++ b/common/test_util.c
@@ -0,0 +1,36 @@
+/* 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.
+ *
+ * Test utilities.
+ */
+
+#include "console.h"
+#include "test_util.h"
+#include "util.h"
+
+int __test_error_count;
+
+/* Weak reference function as an entry point for unit test */
+test_mockable void run_test(void) { }
+
+void test_reset(void)
+{
+ __test_error_count = 0;
+}
+
+void test_print_result(void)
+{
+ if (__test_error_count)
+ ccprintf("Fail! (%d tests)\n", __test_error_count);
+ else
+ ccprintf("Pass!\n");
+}
+
+static int command_run_test(int argc, char **argv)
+{
+ run_test();
+ return EC_SUCCESS;
+}
+DECLARE_CONSOLE_COMMAND(runtest, command_run_test,
+ NULL, NULL, NULL);