summaryrefslogtreecommitdiff
path: root/include/tests/enum_strings.h
diff options
context:
space:
mode:
authorJett Rink <jettrink@chromium.org>2020-03-31 13:42:07 -0600
committerCommit Bot <commit-bot@chromium.org>2020-04-03 09:37:01 +0000
commit47f4e1bb56535e5e24785497ef48bae5cca10419 (patch)
tree6acebf09e97759f9e89b60e8745a5cd952fd881c /include/tests/enum_strings.h
parenteffcc803f8e406f1496af4f73654326b82914eee (diff)
downloadchrome-ec-stabilize-13020.87.B-master.tar.gz
Also update prints functionality to make tests easier to see what is happening BRANCH=none BUG=b:153071799 TEST=use mock in child CL Change-Id: Ia9cfeeff220e3255e6fc0aa41f0795df3b1920e4 Signed-off-by: Jett Rink <jettrink@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2131049 Commit-Queue: LaMont Jones <lamontjones@chromium.org>
Diffstat (limited to 'include/tests/enum_strings.h')
-rw-r--r--include/tests/enum_strings.h94
1 files changed, 94 insertions, 0 deletions
diff --git a/include/tests/enum_strings.h b/include/tests/enum_strings.h
new file mode 100644
index 0000000000..ece2df362f
--- /dev/null
+++ b/include/tests/enum_strings.h
@@ -0,0 +1,94 @@
+/* Copyright 2020 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.
+ */
+
+/* Defines helper function that convert Enums to strings for prints in tests */
+
+#include "usb_pd_tcpm.h"
+#include "usb_pd.h"
+
+#ifndef __CROS_EC_TEST_ENUM_STINGS_H
+#define __CROS_EC_TEST_ENUM_STINGS_H
+
+#ifndef TEST_BUILD
+#error enum_strings.h can only be used in test builds
+#endif
+
+static inline const char *from_tcpc_rp_value(enum tcpc_rp_value value)
+{
+ switch (value) {
+ case TYPEC_RP_USB:
+ return "USB-DEFAULT";
+ case TYPEC_RP_1A5:
+ return "1A5";
+ case TYPEC_RP_3A0:
+ return "3A0";
+ case TYPEC_RP_RESERVED:
+ return "RESERVED";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+static inline const char *from_tcpc_cc_pull(enum tcpc_cc_pull value)
+{
+ switch (value) {
+ case TYPEC_CC_RA:
+ return "RA";
+ case TYPEC_CC_RP:
+ return "RP";
+ case TYPEC_CC_RD:
+ return "RD";
+ case TYPEC_CC_OPEN:
+ return "OPEN";
+ case TYPEC_CC_RA_RD:
+ return "RA_RD";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+static inline const char *from_tcpc_cc_polarity(enum tcpc_cc_polarity value)
+{
+ switch (value) {
+ case POLARITY_CC1:
+ return "CC1";
+ case POLARITY_CC2:
+ return "CC2";
+ case POLARITY_CC1_DTS:
+ return "CC1 DTS";
+ case POLARITY_CC2_DTS:
+ return "CC2 DTS";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+static inline const char *from_pd_power_role(enum pd_power_role value)
+{
+ switch (value) {
+ case PD_ROLE_SINK:
+ return "SNK";
+ case PD_ROLE_SOURCE:
+ return "SRC";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+static inline const char *from_pd_data_role(enum pd_data_role value)
+{
+ switch (value) {
+ case PD_ROLE_UFP:
+ return "UFP";
+ case PD_ROLE_DFP:
+ return "DRP";
+ case PD_ROLE_DISCONNECTED:
+ return "DISCONNECTED";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+#endif /* __CROS_EC_TEST_ENUM_STINGS_H */