bios_setting: Add a read handler

Tested:
```
~# echo -n "01234567" > /run/oem_bios_setting
~# ipmitool raw 0x2e 0x32 0x79 0x2b 0x00 0x18
 79 2b 00 18 08 30 31 32 33 34 35 36 37
~# rm /run/oem_bios_setting
~# ipmitool raw 0x2e 0x32 0x79 0x2b 0x00 0x18
Unable to send RAW command (channel=0x0 netfn=0x2e lun=0x0 cmd=0x32 rsp=0xca): Cannot return number of requested data bytes
```

Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: Icde2de4799a751634f56a580351bf10254dd7e4f
diff --git a/test/bios_setting_unittest.cpp b/test/bios_setting_unittest.cpp
new file mode 100644
index 0000000..45373f4
--- /dev/null
+++ b/test/bios_setting_unittest.cpp
@@ -0,0 +1,88 @@
+// Copyright 2024 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//      http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#include "bios_setting.hpp"
+#include "commands.hpp"
+#include "helper.hpp"
+
+#include <stdplus/gtest/tmp.hpp>
+
+#include <fstream>
+#include <ios>
+#include <iostream>
+#include <string>
+#include <vector>
+
+#include <gtest/gtest.h>
+
+namespace google
+{
+namespace ipmi
+{
+
+using testing::_;
+using ::testing::ElementsAre;
+
+class BiosSettingTest : public stdplus::gtest::TestWithTmp
+{
+  public:
+    std::string filename = std::format("{}/oem_bios_setting", CaseTmpDir());
+
+    void writeTmpFile(std::vector<uint8_t> payload)
+    {
+        std::ofstream ofs;
+        ofs.open(filename, std::ios::trunc | std::ios::binary);
+        ofs.write(reinterpret_cast<char*>(payload.data()), payload.size());
+        ofs.close();
+    }
+};
+
+TEST_F(BiosSettingTest, NoOrEmptyFileRead)
+{
+    std::vector<uint8_t> request = {};
+
+    HandlerMock hMock;
+    EXPECT_EQ(::ipmi::responseRetBytesUnavailable(),
+              readBiosSetting(request, &hMock));
+
+    // Create an empty file
+    writeTmpFile({});
+    EXPECT_EQ(::ipmi::responseRetBytesUnavailable(),
+              readBiosSetting(request, &hMock, filename));
+    std::remove(filename.c_str());
+}
+
+TEST_F(BiosSettingTest, SuccessfulRead)
+{
+    std::vector<uint8_t> request = {};
+    // Ensure 0x0A which is a new line character '\n', is read properly
+    std::vector<uint8_t> payload = {0x0A, 0xDE, 0xAD, 0xBE, 0xEF, 0x0A};
+    std::vector<uint8_t> expectedReply = {6,    0x0A, 0xDE, 0xAD,
+                                          0xBE, 0xEF, 0x0A};
+
+    writeTmpFile(payload);
+
+    HandlerMock hMock;
+    auto reply = readBiosSetting(request, &hMock, filename);
+    auto result = ValidateReply(reply);
+    auto& data = result.second;
+
+    EXPECT_EQ(SysOEMCommands::SysReadBiosSetting, result.first);
+    EXPECT_EQ(expectedReply.size() - 1, data.front());
+    EXPECT_EQ(expectedReply, data);
+    std::remove(filename.c_str());
+}
+
+} // namespace ipmi
+} // namespace google
diff --git a/test/meson.build b/test/meson.build
index f7e3bb9..061b352 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -2,7 +2,7 @@
 gmock = dependency('gmock', disabler: true, required: get_option('tests'))
 
 tests_pre = declare_dependency(
-  dependencies: [sys_dep, gtest, gmock])
+  dependencies: [sys_dep, gtest, gmock, dependency('stdplus-gtest')])
 
 tests_lib = static_library(
   'common',
@@ -32,6 +32,7 @@
   'linux_boot_done',
   'bm_mode_transition',
   'bm_instance',
+  'bios_setting',
 ]
 
 foreach t : tests