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