xref: /openbmc/dbus-sensors/src/tests/test_MCTPEndpoint.cpp (revision 275f7c39190bab69efa11218b68587e8955cc588)
1*275f7c39SAndrew Jeffery #include "MCTPEndpoint.hpp"
2*275f7c39SAndrew Jeffery #include "Utils.hpp"
3*275f7c39SAndrew Jeffery 
4*275f7c39SAndrew Jeffery #include <stdexcept>
5*275f7c39SAndrew Jeffery 
6*275f7c39SAndrew Jeffery #include <gtest/gtest.h>
7*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,matchEmptyConfig)8*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, matchEmptyConfig)
9*275f7c39SAndrew Jeffery {
10*275f7c39SAndrew Jeffery     SensorData config{};
11*275f7c39SAndrew Jeffery     EXPECT_FALSE(I2CMCTPDDevice::match(config));
12*275f7c39SAndrew Jeffery }
13*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,matchIrrelevantConfig)14*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, matchIrrelevantConfig)
15*275f7c39SAndrew Jeffery {
16*275f7c39SAndrew Jeffery     SensorData config{{"xyz.openbmc_project.Configuration.NVME1000", {}}};
17*275f7c39SAndrew Jeffery     EXPECT_FALSE(I2CMCTPDDevice::match(config));
18*275f7c39SAndrew Jeffery }
19*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,matchRelevantConfig)20*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, matchRelevantConfig)
21*275f7c39SAndrew Jeffery {
22*275f7c39SAndrew Jeffery     SensorData config{{"xyz.openbmc_project.Configuration.MCTPI2CTarget", {}}};
23*275f7c39SAndrew Jeffery     EXPECT_TRUE(I2CMCTPDDevice::match(config));
24*275f7c39SAndrew Jeffery }
25*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,fromBadIfaceNoType)26*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, fromBadIfaceNoType)
27*275f7c39SAndrew Jeffery {
28*275f7c39SAndrew Jeffery     SensorBaseConfigMap iface{{}};
29*275f7c39SAndrew Jeffery     EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
30*275f7c39SAndrew Jeffery }
31*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,fromBadIfaceWrongType)32*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, fromBadIfaceWrongType)
33*275f7c39SAndrew Jeffery {
34*275f7c39SAndrew Jeffery     SensorBaseConfigMap iface{{"Type", "NVME1000"}};
35*275f7c39SAndrew Jeffery     EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
36*275f7c39SAndrew Jeffery }
37*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,fromBadIfaceNoAddress)38*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, fromBadIfaceNoAddress)
39*275f7c39SAndrew Jeffery {
40*275f7c39SAndrew Jeffery     SensorBaseConfigMap iface{
41*275f7c39SAndrew Jeffery         {"Bus", "0"},
42*275f7c39SAndrew Jeffery         {"Name", "test"},
43*275f7c39SAndrew Jeffery         {"Type", "MCTPI2CTarget"},
44*275f7c39SAndrew Jeffery     };
45*275f7c39SAndrew Jeffery     EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
46*275f7c39SAndrew Jeffery }
47*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,fromBadIfaceBadAddress)48*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, fromBadIfaceBadAddress)
49*275f7c39SAndrew Jeffery {
50*275f7c39SAndrew Jeffery     SensorBaseConfigMap iface{
51*275f7c39SAndrew Jeffery         {"Address", "not a number"},
52*275f7c39SAndrew Jeffery         {"Bus", "0"},
53*275f7c39SAndrew Jeffery         {"Name", "test"},
54*275f7c39SAndrew Jeffery         {"Type", "MCTPI2CTarget"},
55*275f7c39SAndrew Jeffery     };
56*275f7c39SAndrew Jeffery     EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
57*275f7c39SAndrew Jeffery }
58*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,fromBadIfaceNoBus)59*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, fromBadIfaceNoBus)
60*275f7c39SAndrew Jeffery {
61*275f7c39SAndrew Jeffery     SensorBaseConfigMap iface{
62*275f7c39SAndrew Jeffery         {"Address", "0x1d"},
63*275f7c39SAndrew Jeffery         {"Name", "test"},
64*275f7c39SAndrew Jeffery         {"Type", "MCTPI2CTarget"},
65*275f7c39SAndrew Jeffery     };
66*275f7c39SAndrew Jeffery     EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
67*275f7c39SAndrew Jeffery }
68*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,fromBadIfaceBadBus)69*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, fromBadIfaceBadBus)
70*275f7c39SAndrew Jeffery {
71*275f7c39SAndrew Jeffery     SensorBaseConfigMap iface{
72*275f7c39SAndrew Jeffery         {"Address", "0x1d"},
73*275f7c39SAndrew Jeffery         {"Bus", "not a number"},
74*275f7c39SAndrew Jeffery         {"Name", "test"},
75*275f7c39SAndrew Jeffery         {"Type", "MCTPI2CTarget"},
76*275f7c39SAndrew Jeffery     };
77*275f7c39SAndrew Jeffery     EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
78*275f7c39SAndrew Jeffery }
79*275f7c39SAndrew Jeffery 
TEST(I2CMCTPDDevice,fromBadIfaceNoName)80*275f7c39SAndrew Jeffery TEST(I2CMCTPDDevice, fromBadIfaceNoName)
81*275f7c39SAndrew Jeffery {
82*275f7c39SAndrew Jeffery     SensorBaseConfigMap iface{
83*275f7c39SAndrew Jeffery         {"Address", "0x1d"},
84*275f7c39SAndrew Jeffery         {"Bus", "0"},
85*275f7c39SAndrew Jeffery         {"Type", "MCTPI2CTarget"},
86*275f7c39SAndrew Jeffery     };
87*275f7c39SAndrew Jeffery     EXPECT_THROW(I2CMCTPDDevice::from({}, iface), std::invalid_argument);
88*275f7c39SAndrew Jeffery }
89