Willy Tu | a2056e9 | 2021-10-10 13:36:16 -0700 | [diff] [blame] | 1 | // Copyright 2021 Google LLC |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 15 | #include "commands.hpp" |
| 16 | #include "handler_mock.hpp" |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 17 | #include "helper.hpp" |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 18 | #include "host_power_off.hpp" |
| 19 | |
| 20 | #include <cstdint> |
| 21 | #include <cstring> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <gtest/gtest.h> |
| 25 | |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 26 | namespace google |
| 27 | { |
| 28 | namespace ipmi |
| 29 | { |
| 30 | |
| 31 | TEST(PowerOffCommandTest, InvalidRequestLength) |
| 32 | { |
| 33 | std::vector<std::uint8_t> request = {SysOEMCommands::SysHostPowerOff}; |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 34 | HandlerMock hMock; |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 35 | |
| 36 | EXPECT_EQ(::ipmi::responseReqDataLenInvalid(), |
| 37 | hostPowerOff(request, &hMock)); |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | TEST(PowerOffCommandTest, ValidRequest) |
| 41 | { |
| 42 | // Set the dealy to 15 mins |
| 43 | std::uint32_t delayValue = 0x384; |
| 44 | struct HostPowerOffRequest requestContents; |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 45 | requestContents.delay = delayValue; |
| 46 | |
| 47 | std::vector<std::uint8_t> request(sizeof(requestContents)); |
| 48 | std::memcpy(request.data(), &requestContents, sizeof(requestContents)); |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 49 | |
| 50 | HandlerMock hMock; |
| 51 | EXPECT_CALL(hMock, hostPowerOffDelay(delayValue)); |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 52 | |
| 53 | auto reply = hostPowerOff(request, &hMock); |
| 54 | auto result = ValidateReply(reply, false); |
| 55 | EXPECT_EQ(SysOEMCommands::SysHostPowerOff, result.first); |
linyuny | 8cfa4c4 | 2021-06-16 13:53:08 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | } // namespace ipmi |
| 59 | } // namespace google |