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 | |
Patrick Venture | 0e9aae5 | 2020-08-13 13:07:09 -0700 | [diff] [blame] | 15 | #include "commands.hpp" |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 16 | #include "handler_mock.hpp" |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 17 | #include "helper.hpp" |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 18 | #include "psu.hpp" |
| 19 | |
| 20 | #include <cstdint> |
| 21 | #include <cstring> |
| 22 | #include <vector> |
| 23 | |
| 24 | #include <gtest/gtest.h> |
| 25 | |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 26 | using ::testing::Return; |
| 27 | |
| 28 | namespace google |
| 29 | { |
| 30 | namespace ipmi |
| 31 | { |
| 32 | |
| 33 | TEST(PsuCommandTest, InvalidRequestLength) |
| 34 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 35 | std::vector<std::uint8_t> request = {}; |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 36 | HandlerMock hMock; |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 37 | |
| 38 | EXPECT_EQ(::ipmi::responseReqDataLenInvalid(), |
| 39 | psuHardReset(request, &hMock)); |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 40 | } |
| 41 | |
| 42 | TEST(PsuCommandTest, ValidRequest) |
| 43 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 44 | std::uint8_t delayValue = 0x45; |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 45 | struct PsuResetRequest requestContents; |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 46 | requestContents.delay = delayValue; |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 47 | std::vector<std::uint8_t> request(sizeof(requestContents)); |
| 48 | std::memcpy(request.data(), &requestContents, sizeof(requestContents)); |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 49 | |
| 50 | HandlerMock hMock; |
| 51 | EXPECT_CALL(hMock, psuResetDelay(delayValue)); |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 52 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 53 | auto reply = psuHardReset(request, &hMock); |
| 54 | auto result = ValidateReply(reply, /*hasData=*/false); |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 55 | |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 56 | EXPECT_EQ(SysOEMCommands::SysPsuHardReset, result.first); |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | TEST(PsuResetOnShutdownCommandTest, ValidRequest) |
| 60 | { |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 61 | std::vector<std::uint8_t> request = {}; |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 62 | |
| 63 | HandlerMock hMock; |
| 64 | EXPECT_CALL(hMock, psuResetOnShutdown()); |
Willy Tu | ff3cd8e | 2021-09-14 22:49:55 -0700 | [diff] [blame] | 65 | |
| 66 | auto reply = psuHardResetOnShutdown(request, &hMock); |
| 67 | auto result = ValidateReply(reply, /*hasData=*/false); |
| 68 | |
| 69 | EXPECT_EQ(SysOEMCommands::SysPsuHardResetOnShutdown, result.first); |
Shounak Mitra | ac4a16f | 2021-02-02 11:11:44 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Patrick Venture | aa37412 | 2019-03-15 15:09:10 -0700 | [diff] [blame] | 72 | } // namespace ipmi |
| 73 | } // namespace google |