test: dm: pci: Add cases for finding next PCI capability APIs
authorBin Meng <bmeng.cn@gmail.com>
Mon, 15 Oct 2018 09:21:22 +0000 (02:21 -0700)
committerSimon Glass <sjg@chromium.org>
Wed, 14 Nov 2018 17:16:28 +0000 (09:16 -0800)
Add test cases to cover the two newly added PCI APIs:
dm_pci_find_next_capability() & dm_pci_find_next_ext_capability().

Signed-off-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
drivers/misc/swap_case.c
test/dm/pci.c

index bffb809f14d9fdc87f6464e3a948dbd898cc2621..fa608cec1b92a0a9cd2a55586ddb135fd27df263 100644 (file)
@@ -124,12 +124,21 @@ static int sandbox_swap_case_read_config(struct udevice *emul, uint offset,
        case PCI_CAP_ID_PM_OFFSET:
                *valuep = (PCI_CAP_ID_EXP_OFFSET << 8) | PCI_CAP_ID_PM;
                break;
+       case PCI_CAP_ID_PM_OFFSET + PCI_CAP_LIST_NEXT:
+               *valuep = PCI_CAP_ID_EXP_OFFSET;
+               break;
        case PCI_CAP_ID_EXP_OFFSET:
                *valuep = (PCI_CAP_ID_MSIX_OFFSET << 8) | PCI_CAP_ID_EXP;
                break;
+       case PCI_CAP_ID_EXP_OFFSET + PCI_CAP_LIST_NEXT:
+               *valuep = PCI_CAP_ID_MSIX_OFFSET;
+               break;
        case PCI_CAP_ID_MSIX_OFFSET:
                *valuep = PCI_CAP_ID_MSIX;
                break;
+       case PCI_CAP_ID_MSIX_OFFSET + PCI_CAP_LIST_NEXT:
+               *valuep = 0;
+               break;
        case PCI_EXT_CAP_ID_ERR_OFFSET:
                *valuep = (PCI_EXT_CAP_ID_VC_OFFSET << 20) | PCI_EXT_CAP_ID_ERR;
                break;
index a1dedd84a74b18922ba511b8a8803de2ca25aba1..a1febd54b7f01bebb982660132a601e1adcc8336 100644 (file)
@@ -211,6 +211,16 @@ static int dm_test_pci_cap(struct unit_test_state *uts)
        cap = dm_pci_find_capability(swap, PCI_CAP_ID_PCIX);
        ut_asserteq(0, cap);
 
+       /* look up PCI_CAP_ID_MSIX starting from PCI_CAP_ID_PM_OFFSET */
+       cap = dm_pci_find_next_capability(swap, PCI_CAP_ID_PM_OFFSET,
+                                         PCI_CAP_ID_MSIX);
+       ut_asserteq(PCI_CAP_ID_MSIX_OFFSET, cap);
+
+       /* look up PCI_CAP_ID_VNDR starting from PCI_CAP_ID_EXP_OFFSET */
+       cap = dm_pci_find_next_capability(swap, PCI_CAP_ID_EXP_OFFSET,
+                                         PCI_CAP_ID_VNDR);
+       ut_asserteq(0, cap);
+
        ut_assertok(uclass_get_device_by_seq(UCLASS_PCI, 1, &bus));
        ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &swap));
 
@@ -222,6 +232,16 @@ static int dm_test_pci_cap(struct unit_test_state *uts)
        cap = dm_pci_find_ext_capability(swap, PCI_EXT_CAP_ID_SRIOV);
        ut_asserteq(0, cap);
 
+       /* look up PCI_EXT_CAP_ID_DSN starting from PCI_EXT_CAP_ID_ERR_OFFSET */
+       cap = dm_pci_find_next_ext_capability(swap, PCI_EXT_CAP_ID_ERR_OFFSET,
+                                             PCI_EXT_CAP_ID_DSN);
+       ut_asserteq(PCI_EXT_CAP_ID_DSN_OFFSET, cap);
+
+       /* look up PCI_EXT_CAP_ID_RCRB starting from PCI_EXT_CAP_ID_VC_OFFSET */
+       cap = dm_pci_find_next_ext_capability(swap, PCI_EXT_CAP_ID_VC_OFFSET,
+                                             PCI_EXT_CAP_ID_RCRB);
+       ut_asserteq(0, cap);
+
        return 0;
 }
 DM_TEST(dm_test_pci_cap, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);