From 73b90bcbad5d68c255dbff87a60cd269463d5aab Mon Sep 17 00:00:00 2001 From: Denis Brockus Date: Mon, 16 Nov 2020 18:12:48 -0700 Subject: [PATCH] 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 Change-Id: Ic5594ae96d040adc332c2afc8fa8a8eb8b373882 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2542745 Tested-by: Denis Brockus Reviewed-by: Jett Rink Commit-Queue: Denis Brockus --- Makefile.rules | 2 +- test/build.mk | 4 ++ test/genvif/.gitignore | 2 + test/genvif/Makefile | 24 ++++++++ test/genvif/genvif.sh | 8 +++ test/genvif/src/atomic.h | 8 +++ test/genvif/src/board.h | 9 +++ test/genvif/src/config_chip.h | 8 +++ test/genvif/src/fuzz_config.h | 8 +++ test/genvif/src/helper.c | 29 +++++++++ test/genvif/src/test_config.h | 8 +++ test/genvif/src/timer.h | 8 +++ test/genvif/vif/exp_test_over_vif.xml | 88 +++++++++++++++++++++++++++ test/genvif/vif/exp_test_vif.xml | 86 ++++++++++++++++++++++++++ test/genvif/vif/over_test_vif.xml | 19 ++++++ 15 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 test/genvif/.gitignore create mode 100644 test/genvif/Makefile create mode 100755 test/genvif/genvif.sh create mode 100644 test/genvif/src/atomic.h create mode 100644 test/genvif/src/board.h create mode 100644 test/genvif/src/config_chip.h create mode 100644 test/genvif/src/fuzz_config.h create mode 100644 test/genvif/src/helper.c create mode 100644 test/genvif/src/test_config.h create mode 100644 test/genvif/src/timer.h create mode 100644 test/genvif/vif/exp_test_over_vif.xml create mode 100644 test/genvif/vif/exp_test_vif.xml create mode 100644 test/genvif/vif/over_test_vif.xml diff --git a/Makefile.rules b/Makefile.rules index ffcbf42977..fb06e6008d 100644 --- a/Makefile.rules +++ b/Makefile.rules @@ -359,7 +359,7 @@ hosttests: $(host-test-targets) runhosttests: TEST_FLAG=TEST_HOSTTEST=y runhosttests: $(run-test-targets) runfuzztests: $(run-fuzz-test-targets) -runtests: runhosttests runfuzztests +runtests: runhosttests runfuzztests run-genvif_test # Automatically enumerate all suites. cts_excludes := common 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 @@ + + + 3.12 + Google + SuperTestWithOverride + Final + 12345 + Port Product + End Product + + 18D1 + + + 0 + Type-C® + NO + YES + DRP + DRP + NO + NO + None + + + + + Revision 3 + YES + YES + NO + NO + NO + NO + NO + NO + YES + NO + NO + NO + NO + + + USB Type-C® Receptacle + YES + NO + NO + NO + NO + NO + NO + 1.5A + NO + YES + YES + YES + NO + NO + NO + UFP-powered + NO + NO + NO + USB 2 + USB 2 + NO + NO + 15000 mW + NO + FR_Swap not supported + NO + + NO + + FFFF + 15000 mW + Assured + + + Fixed + 100% IOC + 5000 mV + 3000 mA + 50 msec + 3600 mA + + + + 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 @@ + + 3.12 + Google + test + FIX-ME + 65535 + Port Product + End Product + + 18D1 + + + 0 + Type-C® + NO + YES + DRP + DRP + NO + NO + None + + + + + Revision 3 + YES + YES + NO + NO + NO + NO + NO + NO + YES + NO + NO + NO + NO + + + USB Type-C® Receptacle + YES + NO + NO + NO + NO + NO + NO + 1.5A + NO + YES + YES + YES + NO + NO + NO + UFP-powered + NO + NO + NO + USB 2 + USB 2 + NO + NO + 15000 mW + NO + NO + FR_Swap not supported + NO + + NO + + FFFF + 15000 mW + Assured + + + Fixed + 100% IOC + 5000 mV + 3000 mA + + + + 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 @@ + + + SuperTestWithOverride + Final + 12345 + + + + + + + + + 50 msec + 3600 mA + + + +