xref: /spdk/test/unit/lib/nvme/nvme_quirks.c/nvme_quirks_ut.c (revision ea941caeaf896fdf2aef7685f86f37023060faed)
1 /*   SPDX-License-Identifier: BSD-3-Clause
2  *   Copyright (C) 2016 Intel Corporation.
3  *   All rights reserved.
4  */
5 
6 #include "spdk_internal/cunit.h"
7 
8 #include "nvme/nvme_quirks.c"
9 
SPDK_LOG_REGISTER_COMPONENT(nvme)10 SPDK_LOG_REGISTER_COMPONENT(nvme)
11 
12 static void
13 test_nvme_quirks_striping(void)
14 {
15 	struct spdk_pci_id pci_id = {};
16 	uint64_t quirks = 0;
17 
18 	/* Non-Intel device should not have striping enabled */
19 	quirks = nvme_get_quirks(&pci_id);
20 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) == 0);
21 
22 	/* Set the vendor id to Intel, but no device id. No striping. */
23 	pci_id.class_id = SPDK_PCI_CLASS_NVME;
24 	pci_id.vendor_id = SPDK_PCI_VID_INTEL;
25 	quirks = nvme_get_quirks(&pci_id);
26 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) == 0);
27 
28 	/* Device ID 0x0953 should have striping enabled */
29 	pci_id.device_id = 0x0953;
30 	quirks = nvme_get_quirks(&pci_id);
31 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) != 0);
32 
33 	/* Even if specific subvendor/subdevice ids are set,
34 	 * striping should be enabled.
35 	 */
36 	pci_id.subvendor_id = SPDK_PCI_VID_INTEL;
37 	pci_id.subdevice_id = 0x3704;
38 	quirks = nvme_get_quirks(&pci_id);
39 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) != 0);
40 
41 	pci_id.subvendor_id = 1234;
42 	pci_id.subdevice_id = 42;
43 	quirks = nvme_get_quirks(&pci_id);
44 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) != 0);
45 }
46 
47 int
main(int argc,char ** argv)48 main(int argc, char **argv)
49 {
50 	CU_pSuite	suite = NULL;
51 	unsigned int	num_failures;
52 
53 	CU_initialize_registry();
54 
55 	suite = CU_add_suite("nvme_quirks", NULL, NULL);
56 
57 	CU_ADD_TEST(suite, test_nvme_quirks_striping);
58 
59 	num_failures = spdk_ut_run_tests(argc, argv, NULL);
60 	CU_cleanup_registry();
61 	return num_failures;
62 }
63