diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/build.mk | 2 | ||||
-rw-r--r-- | test/test_config.h | 11 | ||||
-rw-r--r-- | test/usb_pd_pdo_fixed.tasklist | 10 | ||||
-rw-r--r-- | test/usb_pd_pdo_fixed_test.c | 47 |
4 files changed, 70 insertions, 0 deletions
diff --git a/test/build.mk b/test/build.mk index 36882c1b26..9dd576aa41 100644 --- a/test/build.mk +++ b/test/build.mk @@ -83,6 +83,7 @@ test-list-host += usb_pd_int test-list-host += usb_pd test-list-host += usb_pd_giveback test-list-host += usb_pd_rev30 +test-list-host += usb_pd_pdo_fixed test-list-host += usb_ppc test-list-host += usb_sm_framework_h3 test-list-host += usb_sm_framework_h2 @@ -200,6 +201,7 @@ usb_pd_int-y=usb_pd_int.o usb_pd-y=usb_pd.o usb_pd_giveback-y=usb_pd.o usb_pd_rev30-y=usb_pd.o +usb_pd_pdo_fixed-y=usb_pd_pdo_fixed_test.o usb_ppc-y=usb_ppc.o usb_sm_framework_h3-y=usb_sm_framework_h3.o usb_sm_framework_h2-y=usb_sm_framework_h3.o diff --git a/test/test_config.h b/test/test_config.h index eb78fa1995..d06db8252e 100644 --- a/test/test_config.h +++ b/test/test_config.h @@ -333,6 +333,17 @@ int ncp15wb_calculate_temp(uint16_t adc); #define CONFIG_SW_CRC #endif +#ifdef TEST_USB_PD_PDO_FIXED +#define CONFIG_USB_POWER_DELIVERY +#define CONFIG_USB_PD_TCPMV1 +#define CONFIG_USB_PD_PORT_MAX_COUNT 1 +#define CONFIG_USB_PD_TCPC +#define CONFIG_USB_PD_TCPM_STUB +#define CONFIG_SHA256 +#define CONFIG_SW_CRC +#define CONFIG_USB_PD_ONLY_FIXED_PDOS +#endif + #if defined(TEST_USB_SM_FRAMEWORK_H3) || \ defined(TEST_USB_SM_FRAMEWORK_H2) || \ defined(TEST_USB_SM_FRAMEWORK_H1) || \ diff --git a/test/usb_pd_pdo_fixed.tasklist b/test/usb_pd_pdo_fixed.tasklist new file mode 100644 index 0000000000..9a1e6b3e08 --- /dev/null +++ b/test/usb_pd_pdo_fixed.tasklist @@ -0,0 +1,10 @@ +/* Copyright 2021 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. + */ + +/** + * See CONFIG_TASK_LIST in config.h for details. + */ +#define CONFIG_TEST_TASK_LIST + diff --git a/test/usb_pd_pdo_fixed_test.c b/test/usb_pd_pdo_fixed_test.c new file mode 100644 index 0000000000..ad247c3ba2 --- /dev/null +++ b/test/usb_pd_pdo_fixed_test.c @@ -0,0 +1,47 @@ +/* Copyright 2021 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 USB common module. + */ +#include "test_util.h" +#include "usb_common.h" + +#define PDO_FIXED_FLAGS \ + (PDO_FIXED_DUAL_ROLE | PDO_FIXED_DATA_SWAP | PDO_FIXED_COMM_CAP) + +/* Test that a non-fixed PDO will never be selected by pd_find_pdo_index. */ +test_static int test_pd_find_pdo_index(void) +{ + const uint32_t pd_snk_pdo[] = { + PDO_FIXED(5000, 500, PDO_FIXED_FLAGS), + PDO_VAR(4750, PD_MAX_VOLTAGE_MV, PD_MAX_CURRENT_MA), + PDO_BATT(4750, PD_MAX_VOLTAGE_MV, PD_MAX_POWER_MW), + PDO_FIXED(9000, 3000, PDO_FIXED_FLAGS), + PDO_FIXED(12000, 3000, PDO_FIXED_FLAGS), + PDO_FIXED(20000, 3000, PDO_FIXED_FLAGS), + }; + const int pd_snk_pdo_cnt = ARRAY_SIZE(pd_snk_pdo); + uint32_t pdo; + + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 5000, &pdo), 0, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 9000, &pdo), 3, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 10000, &pdo), 3, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 12000, &pdo), 4, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 15000, &pdo), 4, + "%d"); + TEST_EQ(pd_find_pdo_index(pd_snk_pdo_cnt, pd_snk_pdo, 20000, &pdo), 5, + "%d"); + return EC_SUCCESS; +} + +void run_test(int argc, char **argv) +{ + RUN_TEST(test_pd_find_pdo_index); + + test_print_result(); +} |