xref: /spdk/test/unit/lib/nvme/nvme_quirks.c/nvme_quirks_ut.c (revision b30d57cdad6d2bc75cc1e4e2ebbcebcb0d98dcfa)
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright (c) Intel Corporation.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
11  *     * Redistributions of source code must retain the above copyright
12  *       notice, this list of conditions and the following disclaimer.
13  *     * Redistributions in binary form must reproduce the above copyright
14  *       notice, this list of conditions and the following disclaimer in
15  *       the documentation and/or other materials provided with the
16  *       distribution.
17  *     * Neither the name of Intel Corporation nor the names of its
18  *       contributors may be used to endorse or promote products derived
19  *       from this software without specific prior written permission.
20  *
21  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24  *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25  *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27  *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include "spdk_cunit.h"
35 
36 #include "nvme/nvme_quirks.c"
37 
38 SPDK_LOG_REGISTER_COMPONENT(nvme)
39 
40 static void
41 test_nvme_quirks_striping(void)
42 {
43 	struct spdk_pci_id pci_id = {};
44 	uint64_t quirks = 0;
45 
46 	/* Non-Intel device should not have striping enabled */
47 	quirks = nvme_get_quirks(&pci_id);
48 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) == 0);
49 
50 	/* Set the vendor id to Intel, but no device id. No striping. */
51 	pci_id.class_id = SPDK_PCI_CLASS_NVME;
52 	pci_id.vendor_id = SPDK_PCI_VID_INTEL;
53 	quirks = nvme_get_quirks(&pci_id);
54 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) == 0);
55 
56 	/* Device ID 0x0953 should have striping enabled */
57 	pci_id.device_id = 0x0953;
58 	quirks = nvme_get_quirks(&pci_id);
59 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) != 0);
60 
61 	/* Even if specific subvendor/subdevice ids are set,
62 	 * striping should be enabled.
63 	 */
64 	pci_id.subvendor_id = SPDK_PCI_VID_INTEL;
65 	pci_id.subdevice_id = 0x3704;
66 	quirks = nvme_get_quirks(&pci_id);
67 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) != 0);
68 
69 	pci_id.subvendor_id = 1234;
70 	pci_id.subdevice_id = 42;
71 	quirks = nvme_get_quirks(&pci_id);
72 	CU_ASSERT((quirks & NVME_INTEL_QUIRK_STRIPING) != 0);
73 }
74 
75 int main(int argc, char **argv)
76 {
77 	CU_pSuite	suite = NULL;
78 	unsigned int	num_failures;
79 
80 	CU_set_error_action(CUEA_ABORT);
81 	CU_initialize_registry();
82 
83 	suite = CU_add_suite("nvme_quirks", NULL, NULL);
84 
85 	CU_ADD_TEST(suite, test_nvme_quirks_striping);
86 
87 	CU_basic_set_mode(CU_BRM_VERBOSE);
88 	CU_basic_run_tests();
89 	num_failures = CU_get_number_of_failures();
90 	CU_cleanup_registry();
91 	return num_failures;
92 }
93