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