2 * Copyright (c) 2016 Spectra Logic Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification.
11 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12 * substantially similar to the "NO WARRANTY" disclaimer below
13 * ("Disclaimer") and any redistribution must be conditioned upon
14 * including a substantially similar Disclaimer requirement for further
15 * binary redistribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
26 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
27 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGES.
30 * Authors: Alan Somers (Spectra Logic Corporation)
35 #include <gtest/gtest.h>
41 #include <devdctl/guid.h>
42 #include <devdctl/event.h>
43 #include <devdctl/event_factory.h>
45 using namespace DevdCtl;
47 using namespace testing;
49 #define REGISTRY_SIZE 2
51 struct DevNameTestParams
58 class DevNameTest : public TestWithParam<DevNameTestParams>{
62 m_factory = new EventFactory();
63 m_factory->UpdateRegistry(s_registry, REGISTRY_SIZE);
66 virtual void TearDown()
68 if (m_ev) delete m_ev;
69 if (m_factory) delete m_factory;
72 EventFactory *m_factory;
74 static EventFactory::Record s_registry[REGISTRY_SIZE];
77 DevdCtl::EventFactory::Record DevNameTest::s_registry[REGISTRY_SIZE] = {
78 { Event::NOTIFY, "DEVFS", &DevfsEvent::Builder },
79 { Event::NOTIFY, "GEOM", &GeomEvent::Builder }
82 TEST_P(DevNameTest, TestDevname) {
84 DevNameTestParams param = GetParam();
86 string evString(param.evs);
87 m_ev = Event::CreateEvent(*m_factory, evString);
88 m_ev->DevName(devname);
89 EXPECT_STREQ(param.devname, devname.c_str());
92 TEST_P(DevNameTest, TestIsDiskDev) {
93 DevNameTestParams param = GetParam();
95 string evString(param.evs);
96 m_ev = Event::CreateEvent(*m_factory, evString);
97 EXPECT_EQ(param.is_disk, m_ev->IsDiskDev());
100 /* TODO: clean this up using C++-11 uniform initializers */
101 INSTANTIATE_TEST_CASE_P(IsDiskDevTestInstantiation, DevNameTest, Values(
103 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=da6\n",
104 .is_disk = true, .devname = "da6"},
105 (DevNameTestParams){.is_disk = false, .devname = "cuau0",
106 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=cuau0\n"},
107 (DevNameTestParams){.is_disk = true, .devname = "ada6",
108 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=ada6\n"},
109 (DevNameTestParams){.is_disk = true, .devname = "da6p1",
110 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=da6p1\n"},
111 (DevNameTestParams){.is_disk = true, .devname = "ada6p1",
112 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=ada6p1\n"},
113 (DevNameTestParams){.is_disk = true, .devname = "da6s0p1",
114 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=da6s0p1\n"},
115 (DevNameTestParams){.is_disk = true, .devname = "ada6s0p1",
116 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=ada6s0p1\n"},
118 * Test physical path nodes. These are currently all set to false since
119 * physical path nodes are implemented with symlinks, and most CAM and
120 * ZFS operations can't use symlinked device nodes
122 /* A SpectraBSD-style physical path node*/
123 (DevNameTestParams){.is_disk = false, .devname = "enc@50030480019f53fd/elmtype@array_device/slot@18/da",
124 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=enc@50030480019f53fd/elmtype@array_device/slot@18/da\n"},
125 (DevNameTestParams){.is_disk = false, .devname = "enc@50030480019f53fd/elmtype@array_device/slot@18/pass",
126 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=enc@50030480019f53fd/elmtype@array_device/slot@18/pass\n"},
127 /* A FreeBSD-style physical path node */
128 (DevNameTestParams){.is_disk = true, .devname = "enc@n50030480019f53fd/type@0/slot@18/elmdesc@ArrayDevice18/da6",
129 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=enc@n50030480019f53fd/type@0/slot@18/elmdesc@ArrayDevice18/da6\n"},
130 (DevNameTestParams){.is_disk = false, .devname = "enc@n50030480019f53fd/type@0/slot@18/elmdesc@ArrayDevice18/pass6",
131 .evs = "!system=DEVFS subsystem=CDEV type=CREATE cdev=enc@n50030480019f53fd/type@0/slot@18/elmdesc@ArrayDevice18/pass6\n"},
134 * Test some GEOM events
136 (DevNameTestParams){.is_disk = true, .devname = "da5",
137 .evs = "!system=GEOM subsystem=disk type=GEOM::physpath devname=da5\n"})