blob: b74cccf5fb91406a133d9e819cfeaf1ba562db21 [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 <gtest/gtest.h>
6
Patrick Venturecdd61342020-08-07 15:49:56 -07007namespace pid_control
8{
9namespace
10{
11
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070012TEST(UtilTest, WriteTypeEmptyString_ReturnsNONE)
13{
Patrick Ventureda064282018-06-12 19:33:47 -070014 // Verify it responds to an empty string.
15
Patrick Venture7af157b2018-10-30 11:24:40 -070016 EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType(""));
Patrick Ventureda064282018-06-12 19:33:47 -070017}
18
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070019TEST(UtilTest, WriteTypeNonePath_ReturnsNONE)
20{
Patrick Ventureda064282018-06-12 19:33:47 -070021 // Verify it responds to a path of "None"
22
Patrick Venture7af157b2018-10-30 11:24:40 -070023 EXPECT_EQ(IOInterfaceType::NONE, getWriteInterfaceType("None"));
Patrick Ventureda064282018-06-12 19:33:47 -070024}
25
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070026TEST(UtilTest, WriteTypeSysfs_ReturnsSYSFS)
27{
Patrick Ventureda064282018-06-12 19:33:47 -070028 // Verify the sysfs type is determined with an expected path
29
30 std::string path = "/sys/devices/asfdadsf";
Patrick Venture7af157b2018-10-30 11:24:40 -070031 EXPECT_EQ(IOInterfaceType::SYSFS, getWriteInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070032}
33
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070034TEST(UtilTest, WriteTypeUnknown_ReturnsUNKNOWN)
35{
Patrick Ventureda064282018-06-12 19:33:47 -070036 // Verify it reports unknown by default.
37
38 std::string path = "/xyz/openbmc_project";
Patrick Venture7af157b2018-10-30 11:24:40 -070039 EXPECT_EQ(IOInterfaceType::UNKNOWN, getWriteInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070040}
41
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070042TEST(UtilTest, ReadTypeEmptyString_ReturnsNONE)
43{
Patrick Ventureda064282018-06-12 19:33:47 -070044 // Verify it responds to an empty string.
45
Patrick Venture7af157b2018-10-30 11:24:40 -070046 EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType(""));
Patrick Ventureda064282018-06-12 19:33:47 -070047}
48
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070049TEST(UtilTest, ReadTypeNonePath_ReturnsNONE)
50{
Patrick Ventureda064282018-06-12 19:33:47 -070051 // Verify it responds to a path of "None"
52
Patrick Venture7af157b2018-10-30 11:24:40 -070053 EXPECT_EQ(IOInterfaceType::NONE, getReadInterfaceType("None"));
Patrick Ventureda064282018-06-12 19:33:47 -070054}
55
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070056TEST(UtilTest, ReadTypeExternalSensors_ReturnsEXTERNAL)
57{
Patrick Ventureda064282018-06-12 19:33:47 -070058 // Verify it responds to a path that represents a host sensor.
59
60 std::string path = "/xyz/openbmc_project/extsensors/temperature/fleeting0";
Patrick Venture7af157b2018-10-30 11:24:40 -070061 EXPECT_EQ(IOInterfaceType::EXTERNAL, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070062}
63
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070064TEST(UtilTest, ReadTypeOpenBMCSensor_ReturnsDBUSPASSIVE)
65{
Patrick Ventureda064282018-06-12 19:33:47 -070066 // Verify it responds to a path that represents a dbus sensor.
67
68 std::string path = "/xyz/openbmc_project/sensors/fan_tach/fan1";
Patrick Venture7af157b2018-10-30 11:24:40 -070069 EXPECT_EQ(IOInterfaceType::DBUSPASSIVE, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070070}
71
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070072TEST(UtilTest, ReadTypeSysfsPath_ReturnsSYSFS)
73{
Patrick Ventureda064282018-06-12 19:33:47 -070074 // Verify the sysfs type is determined with an expected path
75
76 std::string path = "/sys/devices/asdf/asdf0";
Patrick Venture7af157b2018-10-30 11:24:40 -070077 EXPECT_EQ(IOInterfaceType::SYSFS, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070078}
79
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070080TEST(UtilTest, ReadTypeUnknownDefault_ReturnsUNKNOWN)
81{
Patrick Ventureda064282018-06-12 19:33:47 -070082 // Verify it reports unknown by default.
83
84 std::string path = "asdf09as0df9a0fd";
Patrick Venture7af157b2018-10-30 11:24:40 -070085 EXPECT_EQ(IOInterfaceType::UNKNOWN, getReadInterfaceType(path));
Patrick Ventureda064282018-06-12 19:33:47 -070086}
Patrick Venturecdd61342020-08-07 15:49:56 -070087
88} // namespace
89} // namespace pid_control