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