blob: 6e5e548b23cb958cb9a10af0c476785d37d8b8d6 [file] [log] [blame]
Patrick Ventureda064282018-06-12 19:33:47 -07001#include "util.hpp"
2
Patrick Ventureda064282018-06-12 19:33:47 -07003#include <string>
4
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07005#include <gmock/gmock.h>
6#include <gtest/gtest.h>
7
8TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE)
9{
Patrick Ventureda064282018-06-12 19:33:47 -070010 // Verify it responds to an empty string.
11
Patrick Venture7af157b2018-10-30 11:24:40 -070012 EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType(""));
Patrick Ventureda064282018-06-12 19:33:47 -070013}
14
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070015TEST(UtilTest, WriteTypeNonePath_ReturnsNONE)
16{
Patrick Ventureda064282018-06-12 19:33:47 -070017 // Verify it responds to a path of "None"
18
Patrick Venture7af157b2018-10-30 11:24:40 -070019 EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType("None"));
Patrick Ventureda064282018-06-12 19:33:47 -070020}
21
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070022TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS)
23{
Patrick Ventureda064282018-06-12 19:33:47 -070024 // Verify the sysfs type is determined with an expected path
25
26 std::string path = "/sys/devices/asfdadsf";
Patrick Venture7af157b2018-10-30 11:24:40 -070027 EXPECT_EQ(IOInterfaceType::SYSFS, getWriteInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070028}
29
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070030TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN)
31{
Patrick Ventureda064282018-06-12 19:33:47 -070032 // Verify it reports unknown by default.
33
34 std::string path = "/xyz/openbmc_project";
Patrick Venture7af157b2018-10-30 11:24:40 -070035 EXPECT_EQ(IOInterfaceType::UNKNOWN, getWriteInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070036}
37
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070038TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE)
39{
Patrick Ventureda064282018-06-12 19:33:47 -070040 // Verify it responds to an empty string.
41
Patrick Venture7af157b2018-10-30 11:24:40 -070042 EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType(""));
Patrick Ventureda064282018-06-12 19:33:47 -070043}
44
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070045TEST(UtilTest, ReadTypeNonePath_ReturnsNONE)
46{
Patrick Ventureda064282018-06-12 19:33:47 -070047 // Verify it responds to a path of "None"
48
Patrick Venture7af157b2018-10-30 11:24:40 -070049 EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType("None"));
Patrick Ventureda064282018-06-12 19:33:47 -070050}
51
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070052TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL)
53{
Patrick Ventureda064282018-06-12 19:33:47 -070054 // Verify it responds to a path that represents a host sensor.
55
56 std::string path = "/xyz/openbmc_project/extsensors/temperature/fleeting0";
Patrick Venture7af157b2018-10-30 11:24:40 -070057 EXPECT_EQ(IOInterfaceType::EXTERNAL, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070058}
59
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070060TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE)
61{
Patrick Ventureda064282018-06-12 19:33:47 -070062 // Verify it responds to a path that represents a dbus sensor.
63
64 std::string path = "/xyz/openbmc_project/sensors/fan_tach/fan1";
Patrick Venture7af157b2018-10-30 11:24:40 -070065 EXPECT_EQ(IOInterfaceType::DBUSPASSIVE, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070066}
67
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070068TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS)
69{
Patrick Ventureda064282018-06-12 19:33:47 -070070 // Verify the sysfs type is determined with an expected path
71
72 std::string path = "/sys/devices/asdf/asdf0";
Patrick Venture7af157b2018-10-30 11:24:40 -070073 EXPECT_EQ(IOInterfaceType::SYSFS, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070074}
75
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070076TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN)
77{
Patrick Ventureda064282018-06-12 19:33:47 -070078 // Verify it reports unknown by default.
79
80 std::string path = "asdf09as0df9a0fd";
Patrick Venture7af157b2018-10-30 11:24:40 -070081 EXPECT_EQ(IOInterfaceType::UNKNOWN, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070082}