blob: 457c47061ac3c720956e5a76b208e36548f4ac83 [file] [log] [blame]
Patrick Venturecdd61342020-08-07 15:49:56 -07001#include "sensors/build_utils.hpp"
Patrick Ventureda064282018-06-12 19:33:47 -07002
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
Patrick Venturecdd61342020-08-07 15:49:56 -07008namespace pid_control
9{
10namespace
11{
12
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070013TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE)
14{
Patrick Ventureda064282018-06-12 19:33:47 -070015 // Verify it responds to an empty string.
16
Patrick Venture7af157b2018-10-30 11:24:40 -070017 EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType(""));
Patrick Ventureda064282018-06-12 19:33:47 -070018}
19
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070020TEST(UtilTest, WriteTypeNonePath_ReturnsNONE)
21{
Patrick Ventureda064282018-06-12 19:33:47 -070022 // Verify it responds to a path of "None"
23
Patrick Venture7af157b2018-10-30 11:24:40 -070024 EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType("None"));
Patrick Ventureda064282018-06-12 19:33:47 -070025}
26
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070027TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS)
28{
Patrick Ventureda064282018-06-12 19:33:47 -070029 // Verify the sysfs type is determined with an expected path
30
31 std::string path = "/sys/devices/asfdadsf";
Patrick Venture7af157b2018-10-30 11:24:40 -070032 EXPECT_EQ(IOInterfaceType::SYSFS, getWriteInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070033}
34
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070035TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN)
36{
Patrick Ventureda064282018-06-12 19:33:47 -070037 // Verify it reports unknown by default.
38
39 std::string path = "/xyz/openbmc_project";
Patrick Venture7af157b2018-10-30 11:24:40 -070040 EXPECT_EQ(IOInterfaceType::UNKNOWN, getWriteInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070041}
42
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070043TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE)
44{
Patrick Ventureda064282018-06-12 19:33:47 -070045 // Verify it responds to an empty string.
46
Patrick Venture7af157b2018-10-30 11:24:40 -070047 EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType(""));
Patrick Ventureda064282018-06-12 19:33:47 -070048}
49
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070050TEST(UtilTest, ReadTypeNonePath_ReturnsNONE)
51{
Patrick Ventureda064282018-06-12 19:33:47 -070052 // Verify it responds to a path of "None"
53
Patrick Venture7af157b2018-10-30 11:24:40 -070054 EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType("None"));
Patrick Ventureda064282018-06-12 19:33:47 -070055}
56
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070057TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL)
58{
Patrick Ventureda064282018-06-12 19:33:47 -070059 // Verify it responds to a path that represents a host sensor.
60
61 std::string path = "/xyz/openbmc_project/extsensors/temperature/fleeting0";
Patrick Venture7af157b2018-10-30 11:24:40 -070062 EXPECT_EQ(IOInterfaceType::EXTERNAL, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070063}
64
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070065TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE)
66{
Patrick Ventureda064282018-06-12 19:33:47 -070067 // Verify it responds to a path that represents a dbus sensor.
68
69 std::string path = "/xyz/openbmc_project/sensors/fan_tach/fan1";
Patrick Venture7af157b2018-10-30 11:24:40 -070070 EXPECT_EQ(IOInterfaceType::DBUSPASSIVE, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070071}
72
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070073TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS)
74{
Patrick Ventureda064282018-06-12 19:33:47 -070075 // Verify the sysfs type is determined with an expected path
76
77 std::string path = "/sys/devices/asdf/asdf0";
Patrick Venture7af157b2018-10-30 11:24:40 -070078 EXPECT_EQ(IOInterfaceType::SYSFS, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070079}
80
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070081TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN)
82{
Patrick Ventureda064282018-06-12 19:33:47 -070083 // Verify it reports unknown by default.
84
85 std::string path = "asdf09as0df9a0fd";
Patrick Venture7af157b2018-10-30 11:24:40 -070086 EXPECT_EQ(IOInterfaceType::UNKNOWN, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070087}
Patrick Venturecdd61342020-08-07 15:49:56 -070088
89} // namespace
90} // namespace pid_control