1 #include "sensors/build_utils.hpp"
2
3 #include <string>
4
5 #include <gmock/gmock.h>
6 #include <gtest/gtest.h>
7
8 namespace pid_control
9 {
10 namespace
11 {
12
TEST(UtilTest,WriteTypeEmptyString_ReturnsNONE)13 TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE)
14 {
15 // Verify it responds to an empty string.
16
17 EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType(""));
18 }
19
TEST(UtilTest,WriteTypeNonePath_ReturnsNONE)20 TEST(UtilTest, WriteTypeNonePath_ReturnsNONE)
21 {
22 // Verify it responds to a path of "None"
23
24 EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType("None"));
25 }
26
TEST(UtilTest,WriteTypeSysfs_ReturnsSYSFS)27 TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS)
28 {
29 // Verify the sysfs type is determined with an expected path
30
31 std::string path = "/sys/devices/asfdadsf";
32 EXPECT_EQ(IOInterfaceType::SYSFS, getWriteInterfaceType(path));
33 }
34
TEST(UtilTest,WriteTypeUnknown_ReturnsUNKNOWN)35 TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN)
36 {
37 // Verify it reports unknown by default.
38
39 std::string path = "/xyz/openbmc_project";
40 EXPECT_EQ(IOInterfaceType::UNKNOWN, getWriteInterfaceType(path));
41 }
42
TEST(UtilTest,ReadTypeEmptyString_ReturnsNONE)43 TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE)
44 {
45 // Verify it responds to an empty string.
46
47 EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType(""));
48 }
49
TEST(UtilTest,ReadTypeNonePath_ReturnsNONE)50 TEST(UtilTest, ReadTypeNonePath_ReturnsNONE)
51 {
52 // Verify it responds to a path of "None"
53
54 EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType("None"));
55 }
56
TEST(UtilTest,ReadTypeExternalSensors_ReturnsEXTERNAL)57 TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL)
58 {
59 // Verify it responds to a path that represents a host sensor.
60
61 std::string path = "/xyz/openbmc_project/extsensors/temperature/fleeting0";
62 EXPECT_EQ(IOInterfaceType::EXTERNAL, getReadInterfaceType(path));
63 }
64
TEST(UtilTest,ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE)65 TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE)
66 {
67 // Verify it responds to a path that represents a dbus sensor.
68
69 std::string path = "/xyz/openbmc_project/sensors/fan_tach/fan1";
70 EXPECT_EQ(IOInterfaceType::DBUSPASSIVE, getReadInterfaceType(path));
71 }
72
TEST(UtilTest,ReadTypeSysfsPath_ReturnsSYSFS)73 TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS)
74 {
75 // Verify the sysfs type is determined with an expected path
76
77 std::string path = "/sys/devices/asdf/asdf0";
78 EXPECT_EQ(IOInterfaceType::SYSFS, getReadInterfaceType(path));
79 }
80
TEST(UtilTest,ReadTypeUnknownDefault_ReturnsUNKNOWN)81 TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN)
82 {
83 // Verify it reports unknown by default.
84
85 std::string path = "asdf09as0df9a0fd";
86 EXPECT_EQ(IOInterfaceType::UNKNOWN, getReadInterfaceType(path));
87 }
88
89 } // namespace
90 } // namespace pid_control
91