blob: 063aac30334910fd3498b4ff8bf372f527eb23d6 [file] [log] [blame]
Patrick Venturefe75b192018-06-08 11:19:43 -07001#include "sensors/manager.hpp"
Ed Tanousf8b6e552025-06-27 13:27:50 -07002#include "sensors/sensor.hpp"
Patrick Ventureda4a5dd2018-08-31 09:42:48 -07003#include "test/sensor_mock.hpp"
4
5#include <sdbusplus/test/sdbus_mock.hpp>
Patrick Venturefe75b192018-06-08 11:19:43 -07006
Ed Tanousf8b6e552025-06-27 13:27:50 -07007#include <cstdint>
8#include <memory>
9#include <string>
10#include <utility>
11
Patrick Venturefe75b192018-06-08 11:19:43 -070012#include <gmock/gmock.h>
13#include <gtest/gtest.h>
Patrick Venture98055432018-06-08 14:04:43 -070014
Patrick Venturea0764872020-08-08 07:48:43 -070015namespace pid_control
16{
17namespace
18{
19
Patrick Venturefe75b192018-06-08 11:19:43 -070020using ::testing::_;
21using ::testing::IsNull;
22using ::testing::Return;
23using ::testing::StrEq;
24
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070025TEST(SensorManagerTest, BoringConstructorTest)
26{
Patrick Venturefe75b192018-06-08 11:19:43 -070027 // Build a boring SensorManager.
28
29 sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host;
30 auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive);
31 auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host);
32
33 EXPECT_CALL(sdbus_mock_host,
34 sd_bus_add_object_manager(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070035 IsNull(), _, StrEq("/xyz/openbmc_project/extsensors")))
Patrick Venturea58197c2018-06-11 15:29:45 -070036 .WillOnce(Return(0));
Patrick Venturefe75b192018-06-08 11:19:43 -070037
James Feist1fe08952019-05-07 09:17:16 -070038 SensorManager s(bus_mock_passive, bus_mock_host);
Patrick Venturefe75b192018-06-08 11:19:43 -070039 // Success
40}
Patrick Venture98055432018-06-08 14:04:43 -070041
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070042TEST(SensorManagerTest, AddSensorInvalidTypeTest)
43{
Patrick Venture98055432018-06-08 14:04:43 -070044 // AddSensor doesn't validate the type of sensor you're adding, because
45 // ultimately it doesn't care -- but if we decide to change that this
46 // test will start failing :D
47
48 sdbusplus::SdBusMock sdbus_mock_passive, sdbus_mock_host;
49 auto bus_mock_passive = sdbusplus::get_mocked_new(&sdbus_mock_passive);
50 auto bus_mock_host = sdbusplus::get_mocked_new(&sdbus_mock_host);
51
52 EXPECT_CALL(sdbus_mock_host,
53 sd_bus_add_object_manager(
Patrick Ventureda4a5dd2018-08-31 09:42:48 -070054 IsNull(), _, StrEq("/xyz/openbmc_project/extsensors")))
Patrick Venturea58197c2018-06-11 15:29:45 -070055 .WillOnce(Return(0));
Patrick Venture98055432018-06-08 14:04:43 -070056
James Feist1fe08952019-05-07 09:17:16 -070057 SensorManager s(bus_mock_passive, bus_mock_host);
Patrick Venture98055432018-06-08 14:04:43 -070058
59 std::string name = "name";
60 std::string type = "invalid";
61 int64_t timeout = 1;
Patrick Williamsbd63bca2024-08-16 15:21:10 -040062 std::unique_ptr<Sensor> sensor =
63 std::make_unique<SensorMock>(name, timeout);
Patrick Venturee2ec0f62018-09-04 12:30:27 -070064 Sensor* sensor_ptr = sensor.get();
Patrick Venture98055432018-06-08 14:04:43 -070065
66 s.addSensor(type, name, std::move(sensor));
Patrick Venturea58197c2018-06-11 15:29:45 -070067 EXPECT_EQ(s.getSensor(name), sensor_ptr);
Patrick Venture98055432018-06-08 14:04:43 -070068}
Patrick Venturea0764872020-08-08 07:48:43 -070069
70} // namespace
71} // namespace pid_control