1 // Copyright 2022 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
15 #include "commands.hpp"
16 #include "handler_mock.hpp"
17 #include "helper.hpp"
18 #include "pcie_bifurcation.hpp"
19
20 #include <vector>
21
22 #include <gtest/gtest.h>
23
24 using ::testing::Return;
25
26 namespace google
27 {
28 namespace ipmi
29 {
30
31 using testing::_;
32 using ::testing::ContainerEq;
33
TEST(PcieBifurcationCommandTest,InvalidRequest)34 TEST(PcieBifurcationCommandTest, InvalidRequest)
35 {
36 std::vector<uint8_t> request = {};
37
38 HandlerMock hMock;
39 EXPECT_EQ(::ipmi::responseReqDataLenInvalid(),
40 pcieBifurcation(request, &hMock));
41 }
42
TEST(PcieBifurcationCommandTest,ValidRequest)43 TEST(PcieBifurcationCommandTest, ValidRequest)
44 {
45 std::vector<uint8_t> request = {5};
46 std::vector<uint8_t> expectedOutput = {4, 8, 1, 2};
47
48 HandlerMock hMock;
49 EXPECT_CALL(hMock, pcieBifurcation(5)).WillOnce(Return(expectedOutput));
50
51 auto reply = pcieBifurcation(request, &hMock);
52 auto result = ValidateReply(reply);
53 auto& data = result.second;
54
55 EXPECT_EQ(sizeof(struct PcieBifurcationReply) + expectedOutput.size(),
56 data.size());
57 EXPECT_EQ(SysOEMCommands::SysPCIeSlotBifurcation, result.first);
58 EXPECT_THAT(std::vector<uint8_t>(data.begin() + 1, data.end()),
59 ContainerEq(expectedOutput));
60 }
61
TEST(PcieBifurcationCommandTest,ReplyExceddedMaxValue)62 TEST(PcieBifurcationCommandTest, ReplyExceddedMaxValue)
63 {
64 std::vector<uint8_t> request = {5};
65 std::vector<uint8_t> expectedOutput(64, 1);
66
67 HandlerMock hMock;
68 EXPECT_CALL(hMock, pcieBifurcation(5)).WillOnce(Return(expectedOutput));
69 EXPECT_EQ(::ipmi::responseInvalidCommand(),
70 pcieBifurcation(request, &hMock));
71 }
72
73 } // namespace ipmi
74 } // namespace google
75