summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorDenis Brockus <dbrockus@google.com>2020-11-16 18:12:48 -0700
committerCommit Bot <commit-bot@chromium.org>2020-11-17 20:53:44 +0000
commit73b90bcbad5d68c255dbff87a60cd269463d5aab (patch)
treea4412c292905d305442594fdbc06454d1928e63e /test
parent72f06af17e55a5c88d51e8925d26a010297eb820 (diff)
downloadchrome-ec-73b90bcbad5d68c255dbff87a60cd269463d5aab.tar.gz
genvif: add unit test for genvif and genvif override
Any of the following will run the test from platform/ec make buildall make runtests make run-genvif_test The following will run the test from platform/ec/test/genvif make clean test BUG=b:173219559 BRANCH=none TEST=make buildall Signed-off-by: Denis Brockus <dbrockus@google.com> Change-Id: Ic5594ae96d040adc332c2afc8fa8a8eb8b373882 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2542745 Tested-by: Denis Brockus <dbrockus@chromium.org> Reviewed-by: Jett Rink <jettrink@chromium.org> Commit-Queue: Denis Brockus <dbrockus@chromium.org>
Diffstat (limited to 'test')
-rw-r--r--test/build.mk4
-rw-r--r--test/genvif/.gitignore2
-rw-r--r--test/genvif/Makefile24
-rwxr-xr-xtest/genvif/genvif.sh8
-rw-r--r--test/genvif/src/atomic.h8
-rw-r--r--test/genvif/src/board.h9
-rw-r--r--test/genvif/src/config_chip.h8
-rw-r--r--test/genvif/src/fuzz_config.h8
-rw-r--r--test/genvif/src/helper.c29
-rw-r--r--test/genvif/src/test_config.h8
-rw-r--r--test/genvif/src/timer.h8
-rw-r--r--test/genvif/vif/exp_test_over_vif.xml88
-rw-r--r--test/genvif/vif/exp_test_vif.xml86
-rw-r--r--test/genvif/vif/over_test_vif.xml19
14 files changed, 309 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk
index 1a9f3657a8..e994695ab0 100644
--- a/test/build.mk
+++ b/test/build.mk
@@ -228,3 +228,7 @@ is_enabled_error-y=is_enabled_error.o.cmd
host-static_if_error: TEST_SCRIPT=static_if_error.sh
static_if_error-y=static_if_error.o.cmd
+
+run-genvif_test:
+ @echo " TEST genvif_test"
+ @test/genvif/genvif.sh
diff --git a/test/genvif/.gitignore b/test/genvif/.gitignore
new file mode 100644
index 0000000000..eabdcbd17f
--- /dev/null
+++ b/test/genvif/.gitignore
@@ -0,0 +1,2 @@
+genvif
+vif_output
diff --git a/test/genvif/Makefile b/test/genvif/Makefile
new file mode 100644
index 0000000000..566b6bb042
--- /dev/null
+++ b/test/genvif/Makefile
@@ -0,0 +1,24 @@
+# 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.
+#
+
+CC=gcc
+CFLAGS=-O2 -Isrc -I../../include
+
+genvif: ../../util/genvif.c src/helper.c
+ @$(CC) -o $@ $^ $(CFLAGS)
+
+test: genvif
+ @mkdir vif_output 2>/dev/null
+ @./genvif -b test -o vif_output
+ @./genvif -b exp_test -o vif_output -n -v vif/exp_test_vif.xml
+ @diff vif_output/test_vif.xml vif_output/exp_test_vif.xml
+ @./genvif -b test_over -o vif_output -v vif/over_test_vif.xml
+ @./genvif -b exp_test_over -o vif_output -n -v vif/exp_test_over_vif.xml
+ @diff vif_output/test_over_vif.xml vif_output/exp_test_over_vif.xml
+
+.PHONY: clean
+clean:
+ @rm -f genvif
+ @rm -rf vif_output
diff --git a/test/genvif/genvif.sh b/test/genvif/genvif.sh
new file mode 100755
index 0000000000..4a275ed2c1
--- /dev/null
+++ b/test/genvif/genvif.sh
@@ -0,0 +1,8 @@
+#!/bin/bash -e
+# 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.
+
+cd test/genvif
+make clean
+make test
diff --git a/test/genvif/src/atomic.h b/test/genvif/src/atomic.h
new file mode 100644
index 0000000000..f2fa112e81
--- /dev/null
+++ b/test/genvif/src/atomic.h
@@ -0,0 +1,8 @@
+/* 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.
+ */
+
+/*
+ * Blank shell to avoid including the real file
+ */
diff --git a/test/genvif/src/board.h b/test/genvif/src/board.h
new file mode 100644
index 0000000000..8f175443d0
--- /dev/null
+++ b/test/genvif/src/board.h
@@ -0,0 +1,9 @@
+/* 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.
+ */
+
+#define PD_OPERATING_POWER_MW 15000
+#define PD_MAX_POWER_MW 65000
+#define PD_MAX_CURRENT_MA 3250
+#define PD_MAX_VOLTAGE_MV 20000
diff --git a/test/genvif/src/config_chip.h b/test/genvif/src/config_chip.h
new file mode 100644
index 0000000000..f2fa112e81
--- /dev/null
+++ b/test/genvif/src/config_chip.h
@@ -0,0 +1,8 @@
+/* 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.
+ */
+
+/*
+ * Blank shell to avoid including the real file
+ */
diff --git a/test/genvif/src/fuzz_config.h b/test/genvif/src/fuzz_config.h
new file mode 100644
index 0000000000..f2fa112e81
--- /dev/null
+++ b/test/genvif/src/fuzz_config.h
@@ -0,0 +1,8 @@
+/* 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.
+ */
+
+/*
+ * Blank shell to avoid including the real file
+ */
diff --git a/test/genvif/src/helper.c b/test/genvif/src/helper.c
new file mode 100644
index 0000000000..adb7bdbd0f
--- /dev/null
+++ b/test/genvif/src/helper.c
@@ -0,0 +1,29 @@
+/* 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.
+ */
+
+#include "common.h"
+#include "usb_pd.h"
+
+#ifndef CONFIG_USB_PD_CUSTOM_PDO
+#define PDO_FIXED_FLAGS (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP |\
+ PDO_FIXED_COMM_CAP)
+
+const uint32_t pd_src_pdo[] = {
+ PDO_FIXED(5000, 1500, PDO_FIXED_FLAGS),
+};
+const int pd_src_pdo_cnt = ARRAY_SIZE(pd_src_pdo);
+const uint32_t pd_src_pdo_max[] = {
+ PDO_FIXED(5000, 3000, PDO_FIXED_FLAGS),
+};
+const int pd_src_pdo_max_cnt = ARRAY_SIZE(pd_src_pdo_max);
+
+const uint32_t pd_snk_pdo[] = {
+ PDO_FIXED(5000, 500, PDO_FIXED_FLAGS),
+ PDO_BATT(4750, PD_MAX_VOLTAGE_MV, PD_OPERATING_POWER_MW),
+ PDO_VAR(4750, PD_MAX_VOLTAGE_MV, PD_MAX_CURRENT_MA),
+};
+const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo);
+#endif /* CONFIG_USB_PD_CUSTOM_PDO */
+
diff --git a/test/genvif/src/test_config.h b/test/genvif/src/test_config.h
new file mode 100644
index 0000000000..f2fa112e81
--- /dev/null
+++ b/test/genvif/src/test_config.h
@@ -0,0 +1,8 @@
+/* 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.
+ */
+
+/*
+ * Blank shell to avoid including the real file
+ */
diff --git a/test/genvif/src/timer.h b/test/genvif/src/timer.h
new file mode 100644
index 0000000000..f2fa112e81
--- /dev/null
+++ b/test/genvif/src/timer.h
@@ -0,0 +1,8 @@
+/* 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.
+ */
+
+/*
+ * Blank shell to avoid including the real file
+ */
diff --git a/test/genvif/vif/exp_test_over_vif.xml b/test/genvif/vif/exp_test_over_vif.xml
new file mode 100644
index 0000000000..9f0281dbc7
--- /dev/null
+++ b/test/genvif/vif/exp_test_over_vif.xml
@@ -0,0 +1,88 @@
+<?xml version="1.0" encoding="utf-8"?>
+<VIF>
+ <VIF_Specification>3.12</VIF_Specification>
+ <Vendor_Name>Google</Vendor_Name>
+ <Model_Part_Number>SuperTestWithOverride</Model_Part_Number>
+ <Product_Revision>Final</Product_Revision>
+ <TID>12345</TID>
+ <VIF_Product_Type value="0">Port Product</VIF_Product_Type>
+ <Certification_Type value="0">End Product</Certification_Type>
+ <Product>
+ <Product_VID value="6353">18D1</Product_VID>
+ </Product>
+ <Component>
+ <Port_Label>0</Port_Label>
+ <Connector_Type value="2">Type-C®</Connector_Type>
+ <USB4_Supported value="false">NO</USB4_Supported>
+ <USB_PD_Support value="true">YES</USB_PD_Support>
+ <PD_Port_Type value="4">DRP</PD_Port_Type>
+ <Type_C_State_Machine value="2">DRP</Type_C_State_Machine>
+ <Captive_Cable value="false">NO</Captive_Cable>
+ <Port_Battery_Powered value="false">NO</Port_Battery_Powered>
+ <BC_1_2_Support value="0">None</BC_1_2_Support>
+ <PD_Spec_Revision_Major value="3" />
+ <PD_Spec_Revision_Minor value="0" />
+ <PD_Spec_Version_Major value="2" />
+ <PD_Spec_Version_Minor value="0" />
+ <PD_Specification_Revision value="2">Revision 3</PD_Specification_Revision>
+ <USB_Comms_Capable value="true">YES</USB_Comms_Capable>
+ <DR_Swap_To_DFP_Supported value="true">YES</DR_Swap_To_DFP_Supported>
+ <DR_Swap_To_UFP_Supported value="false">NO</DR_Swap_To_UFP_Supported>
+ <Unconstrained_Power value="false">NO</Unconstrained_Power>
+ <VCONN_Swap_To_On_Supported value="false">NO</VCONN_Swap_To_On_Supported>
+ <VCONN_Swap_To_Off_Supported value="false">NO</VCONN_Swap_To_Off_Supported>
+ <Responds_To_Discov_SOP_UFP value="false">NO</Responds_To_Discov_SOP_UFP>
+ <Responds_To_Discov_SOP_DFP value="false">NO</Responds_To_Discov_SOP_DFP>
+ <Attempts_Discov_SOP value="true">YES</Attempts_Discov_SOP>
+ <Chunking_Implemented_SOP value="false">NO</Chunking_Implemented_SOP>
+ <Unchunked_Extended_Messages_Supported value="false">NO</Unchunked_Extended_Messages_Supported>
+ <Manufacturer_Info_Supported_Port value="false">NO</Manufacturer_Info_Supported_Port>
+ <Security_Msgs_Supported_SOP value="false">NO</Security_Msgs_Supported_SOP>
+ <Num_Fixed_Batteries value="1" />
+ <Num_Swappable_Battery_Slots value="0" />
+ <ID_Header_Connector_Type_SOP value="2">USB Type-C® Receptacle</ID_Header_Connector_Type_SOP>
+ <SOP_Capable value="true">YES</SOP_Capable>
+ <SOP_P_Capable value="false">NO</SOP_P_Capable>
+ <SOP_PP_Capable value="false">NO</SOP_PP_Capable>
+ <SOP_P_Debug_Capable value="false">NO</SOP_P_Debug_Capable>
+ <SOP_PP_Debug_Capable value="false">NO</SOP_PP_Debug_Capable>
+ <Type_C_Implements_Try_SRC value="false">NO</Type_C_Implements_Try_SRC>
+ <Type_C_Implements_Try_SNK value="false">NO</Type_C_Implements_Try_SNK>
+ <RP_Value value="1">1.5A</RP_Value>
+ <Type_C_Is_VCONN_Powered_Accessory value="false">NO</Type_C_Is_VCONN_Powered_Accessory>
+ <Type_C_Is_Debug_Target_SRC value="true">YES</Type_C_Is_Debug_Target_SRC>
+ <Type_C_Is_Debug_Target_SNK value="true">YES</Type_C_Is_Debug_Target_SNK>
+ <Type_C_Can_Act_As_Host value="true">YES</Type_C_Can_Act_As_Host>
+ <Type_C_Is_Alt_Mode_Controller value="false">NO</Type_C_Is_Alt_Mode_Controller>
+ <Type_C_Can_Act_As_Device value="false">NO</Type_C_Can_Act_As_Device>
+ <Type_C_Is_Alt_Mode_Adapter value="false">NO</Type_C_Is_Alt_Mode_Adapter>
+ <Type_C_Power_Source value="1">UFP-powered</Type_C_Power_Source>
+ <Type_C_Port_On_Hub value="false">NO</Type_C_Port_On_Hub>
+ <Type_C_Supports_Audio_Accessory value="false">NO</Type_C_Supports_Audio_Accessory>
+ <Type_C_Sources_VCONN value="false">NO</Type_C_Sources_VCONN>
+ <Device_Speed value="0">USB 2</Device_Speed>
+ <Host_Speed value="0">USB 2</Host_Speed>
+ <Host_Contains_Captive_Retimer value="false">NO</Host_Contains_Captive_Retimer>
+ <Host_Is_Embedded value="false">NO</Host_Is_Embedded>
+ <PD_Power_As_Source value="15000">15000 mW</PD_Power_As_Source>
+ <USB_Suspend_May_Be_Cleared value="false">NO</USB_Suspend_May_Be_Cleared>
+ <FR_Swap_Type_C_Current_Capability_As_Initial_Sink value="0">FR_Swap not supported</FR_Swap_Type_C_Current_Capability_As_Initial_Sink>
+ <Master_Port value="false">NO</Master_Port>
+ <Num_Src_PDOs value="1" />
+ <PD_OC_Protection value="false">NO</PD_OC_Protection>
+ <XID_SOP value="0" />
+ <PID_SOP value="65535">FFFF</PID_SOP>
+ <Product_Total_Source_Power_mW value="15000">15000 mW</Product_Total_Source_Power_mW>
+ <Port_Source_Power_Type value="0">Assured</Port_Source_Power_Type>
+ <SrcPdoList>
+ <SrcPDO>
+ <Src_PDO_Supply_Type value="0">Fixed</Src_PDO_Supply_Type>
+ <Src_PDO_Peak_Current value="0">100% IOC</Src_PDO_Peak_Current>
+ <Src_PDO_Voltage value="100">5000 mV</Src_PDO_Voltage>
+ <Src_PDO_Max_Current value="300">3000 mA</Src_PDO_Max_Current>
+ <Src_PD_OCP_OC_Debounce value="50">50 msec</Src_PD_OCP_OC_Debounce>
+ <Src_PD_OCP_OC_Threshold value="360">3600 mA</Src_PD_OCP_OC_Threshold>
+ </SrcPDO>
+ </SrcPdoList>
+ </Component>
+</VIF>
diff --git a/test/genvif/vif/exp_test_vif.xml b/test/genvif/vif/exp_test_vif.xml
new file mode 100644
index 0000000000..355c9812a4
--- /dev/null
+++ b/test/genvif/vif/exp_test_vif.xml
@@ -0,0 +1,86 @@
+<VIF>
+ <VIF_Specification>3.12</VIF_Specification>
+ <Vendor_Name>Google</Vendor_Name>
+ <Model_Part_Number>test</Model_Part_Number>
+ <Product_Revision>FIX-ME</Product_Revision>
+ <TID>65535</TID>
+ <VIF_Product_Type value="0">Port Product</VIF_Product_Type>
+ <Certification_Type value="0">End Product</Certification_Type>
+ <Product>
+ <Product_VID value="6353">18D1</Product_VID>
+ </Product>
+ <Component>
+ <Port_Label>0</Port_Label>
+ <Connector_Type value="2">Type-C®</Connector_Type>
+ <USB4_Supported value="false">NO</USB4_Supported>
+ <USB_PD_Support value="true">YES</USB_PD_Support>
+ <PD_Port_Type value="4">DRP</PD_Port_Type>
+ <Type_C_State_Machine value="2">DRP</Type_C_State_Machine>
+ <Captive_Cable value="false">NO</Captive_Cable>
+ <Port_Battery_Powered value="false">NO</Port_Battery_Powered>
+ <BC_1_2_Support value="0">None</BC_1_2_Support>
+ <PD_Spec_Revision_Major value="3" />
+ <PD_Spec_Revision_Minor value="0" />
+ <PD_Spec_Version_Major value="2" />
+ <PD_Spec_Version_Minor value="0" />
+ <PD_Specification_Revision value="2">Revision 3</PD_Specification_Revision>
+ <USB_Comms_Capable value="true">YES</USB_Comms_Capable>
+ <DR_Swap_To_DFP_Supported value="true">YES</DR_Swap_To_DFP_Supported>
+ <DR_Swap_To_UFP_Supported value="false">NO</DR_Swap_To_UFP_Supported>
+ <Unconstrained_Power value="false">NO</Unconstrained_Power>
+ <VCONN_Swap_To_On_Supported value="false">NO</VCONN_Swap_To_On_Supported>
+ <VCONN_Swap_To_Off_Supported value="false">NO</VCONN_Swap_To_Off_Supported>
+ <Responds_To_Discov_SOP_UFP value="false">NO</Responds_To_Discov_SOP_UFP>
+ <Responds_To_Discov_SOP_DFP value="false">NO</Responds_To_Discov_SOP_DFP>
+ <Attempts_Discov_SOP value="true">YES</Attempts_Discov_SOP>
+ <Chunking_Implemented_SOP value="false">NO</Chunking_Implemented_SOP>
+ <Unchunked_Extended_Messages_Supported value="false">NO</Unchunked_Extended_Messages_Supported>
+ <Manufacturer_Info_Supported_Port value="false">NO</Manufacturer_Info_Supported_Port>
+ <Security_Msgs_Supported_SOP value="false">NO</Security_Msgs_Supported_SOP>
+ <Num_Fixed_Batteries value="1" />
+ <Num_Swappable_Battery_Slots value="0" />
+ <ID_Header_Connector_Type_SOP value="2">USB Type-C® Receptacle</ID_Header_Connector_Type_SOP>
+ <SOP_Capable value="true">YES</SOP_Capable>
+ <SOP_P_Capable value="false">NO</SOP_P_Capable>
+ <SOP_PP_Capable value="false">NO</SOP_PP_Capable>
+ <SOP_P_Debug_Capable value="false">NO</SOP_P_Debug_Capable>
+ <SOP_PP_Debug_Capable value="false">NO</SOP_PP_Debug_Capable>
+ <Type_C_Implements_Try_SRC value="false">NO</Type_C_Implements_Try_SRC>
+ <Type_C_Implements_Try_SNK value="false">NO</Type_C_Implements_Try_SNK>
+ <RP_Value value="1">1.5A</RP_Value>
+ <Type_C_Is_VCONN_Powered_Accessory value="false">NO</Type_C_Is_VCONN_Powered_Accessory>
+ <Type_C_Is_Debug_Target_SRC value="true">YES</Type_C_Is_Debug_Target_SRC>
+ <Type_C_Is_Debug_Target_SNK value="true">YES</Type_C_Is_Debug_Target_SNK>
+ <Type_C_Can_Act_As_Host value="true">YES</Type_C_Can_Act_As_Host>
+ <Type_C_Is_Alt_Mode_Controller value="false">NO</Type_C_Is_Alt_Mode_Controller>
+ <Type_C_Can_Act_As_Device value="false">NO</Type_C_Can_Act_As_Device>
+ <Type_C_Is_Alt_Mode_Adapter value="false">NO</Type_C_Is_Alt_Mode_Adapter>
+ <Type_C_Power_Source value="1">UFP-powered</Type_C_Power_Source>
+ <Type_C_Port_On_Hub value="false">NO</Type_C_Port_On_Hub>
+ <Type_C_Supports_Audio_Accessory value="false">NO</Type_C_Supports_Audio_Accessory>
+ <Type_C_Sources_VCONN value="false">NO</Type_C_Sources_VCONN>
+ <Device_Speed value="0">USB 2</Device_Speed>
+ <Host_Speed value="0">USB 2</Host_Speed>
+ <Host_Contains_Captive_Retimer value="false">NO</Host_Contains_Captive_Retimer>
+ <Host_Is_Embedded value="false">NO</Host_Is_Embedded>
+ <PD_Power_As_Source value="15000">15000 mW</PD_Power_As_Source>
+ <USB_Suspend_May_Be_Cleared value="false">NO</USB_Suspend_May_Be_Cleared>
+ <Sends_Pings value="false">NO</Sends_Pings>
+ <FR_Swap_Type_C_Current_Capability_As_Initial_Sink value="0">FR_Swap not supported</FR_Swap_Type_C_Current_Capability_As_Initial_Sink>
+ <Master_Port value="false">NO</Master_Port>
+ <Num_Src_PDOs value="1" />
+ <PD_OC_Protection value="false">NO</PD_OC_Protection>
+ <XID_SOP value="0" />
+ <PID_SOP value="65535">FFFF</PID_SOP>
+ <Product_Total_Source_Power_mW value="15000">15000 mW</Product_Total_Source_Power_mW>
+ <Port_Source_Power_Type value="0">Assured</Port_Source_Power_Type>
+ <SrcPdoList>
+ <SrcPDO>
+ <Src_PDO_Supply_Type value="0">Fixed</Src_PDO_Supply_Type>
+ <Src_PDO_Peak_Current value="0">100% IOC</Src_PDO_Peak_Current>
+ <Src_PDO_Voltage value="100">5000 mV</Src_PDO_Voltage>
+ <Src_PDO_Max_Current value="300">3000 mA</Src_PDO_Max_Current>
+ </SrcPDO>
+ </SrcPdoList>
+ </Component>
+</VIF>
diff --git a/test/genvif/vif/over_test_vif.xml b/test/genvif/vif/over_test_vif.xml
new file mode 100644
index 0000000000..64e1148c68
--- /dev/null
+++ b/test/genvif/vif/over_test_vif.xml
@@ -0,0 +1,19 @@
+<VIF>
+ <!-- Override the following fields -->
+ <Model_Part_Number>SuperTestWithOverride</Model_Part_Number>
+ <Product_Revision>Final</Product_Revision>
+ <TID>12345</TID>
+
+ <Component>
+ <!-- Remove Sends_Pings -->
+ <Sends_Pings />
+
+ <SrcPdoList>
+ <SrcPDO>
+ <!-- Add in missing fields for SrcPdo0 -->
+ <Src_PD_OCP_OC_Debounce value="50">50 msec</Src_PD_OCP_OC_Debounce>
+ <Src_PD_OCP_OC_Threshold value="360">3600 mA</Src_PD_OCP_OC_Threshold>
+ </SrcPDO>
+ </SrcPdoList>
+ </Component>
+</VIF>