fru-device: add FRUReader EEPROM cache
This doesn't provide a huge benefit currently, but is a preparatory step
for adding support for a wider variety of FRU format parsers. If
parsers for multiple formats are interested in reading the same areas of
an EEPROM, the caching provided by this abstraction avoids the redundant
bus traffic of all of them re-reading the same bytes over and over.
Tested: on an ASRock Rack romed8hm3, fru-device successfully recognizes
and parses the baseboard FRU EEPROM as it did prior to this patch.
Signed-off-by: Zev Weiss <zev@bewilderbeest.net>
Change-Id: I0d774508bc29dbda346309fe7fe42dbdf97bee43
diff --git a/include/fru_reader.hpp b/include/fru_reader.hpp
new file mode 100644
index 0000000..b1d21d8
--- /dev/null
+++ b/include/fru_reader.hpp
@@ -0,0 +1,62 @@
+/*
+// Copyright (c) 2022 Equinix, Inc.
+//
+// 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.
+*/
+
+#pragma once
+
+#include <cstdint>
+#include <functional>
+#include <map>
+#include <optional>
+#include <utility>
+
+extern "C"
+{
+// For I2C_SMBUS_BLOCK_MAX
+#include <linux/i2c.h>
+}
+
+// A function to read up to I2C_SMBUS_BLOCK_MAX bytes of FRU data. Returns
+// negative on error, or the number of bytes read otherwise, which may be (but
+// is not guaranteed to be) less than len if the read would go beyond the end
+// of the FRU.
+using ReadBlockFunc =
+ std::function<int64_t(off_t offset, size_t len, uint8_t* outbuf)>;
+
+// A caching wrapper around a ReadBlockFunc
+class FRUReader
+{
+ public:
+ FRUReader(ReadBlockFunc readFunc) : readFunc(std::move(readFunc))
+ {}
+ // The ::read() operation here is analogous to ReadBlockFunc (with the same
+ // return value semantics), but is not subject to SMBus block size
+ // limitations; it can read as much data as needed in a single call.
+ ssize_t read(off_t start, size_t len, uint8_t* outbuf);
+
+ private:
+ static constexpr size_t cacheBlockSize = 32;
+ static_assert(cacheBlockSize <= I2C_SMBUS_BLOCK_MAX);
+ using CacheBlock = std::array<uint8_t, cacheBlockSize>;
+
+ // indexed by block number (byte number / block size)
+ using Cache = std::map<uint32_t, CacheBlock>;
+
+ ReadBlockFunc readFunc;
+ Cache cache;
+
+ // byte offset of the end of the FRU (if readFunc has reported it)
+ std::optional<size_t> eof;
+};
diff --git a/include/fru_utils.hpp b/include/fru_utils.hpp
index c072ae5..ebb2b19 100644
--- a/include/fru_utils.hpp
+++ b/include/fru_utils.hpp
@@ -16,6 +16,7 @@
/// \file fru_utils.hpp
#pragma once
+#include "fru_reader.hpp"
#include <boost/container/flat_map.hpp>
#include <cstdint>
@@ -83,10 +84,6 @@
1);
}
-using ReadBlockFunc =
- std::function<ssize_t(int flag, int file, uint16_t address, off_t offset,
- size_t length, uint8_t* outBuf)>;
-
inline const std::string& getFruAreaName(fruAreas area)
{
return fruAreaNames[static_cast<unsigned int>(area)];
@@ -132,30 +129,22 @@
ssize_t getFieldLength(uint8_t fruFieldTypeLenValue);
/// \brief Find a FRU header.
-/// \param flag the flag required for raw i2c
-/// \param file the open file handle
-/// \param address the i2c device address
-/// \param readBlock a read method
+/// \param reader the FRUReader to read via
/// \param errorHelp and a helper string for failures
/// \param blockData buffer to return the last read block
/// \param baseOffset the offset to start the search at;
/// set to 0 to perform search;
/// returns the offset at which a header was found
/// \return whether a header was found
-bool findFRUHeader(int flag, int file, uint16_t address,
- const ReadBlockFunc& readBlock, const std::string& errorHelp,
+bool findFRUHeader(FRUReader& reader, const std::string& errorHelp,
std::array<uint8_t, I2C_SMBUS_BLOCK_MAX>& blockData,
off_t& baseOffset);
/// \brief Read and validate FRU contents.
-/// \param flag the flag required for raw i2c
-/// \param file the open file handle
-/// \param address the i2c device address
-/// \param readBlock a read method
+/// \param reader the FRUReader to read via
/// \param errorHelp and a helper string for failures
/// \return the FRU contents from the file
-std::vector<uint8_t> readFRUContents(int flag, int file, uint16_t address,
- const ReadBlockFunc& readBlock,
+std::vector<uint8_t> readFRUContents(FRUReader& reader,
const std::string& errorHelp);
/// \brief Validate an IPMI FRU common header
diff --git a/meson.build b/meson.build
index f852eb7..aa0bf19 100644
--- a/meson.build
+++ b/meson.build
@@ -227,6 +227,7 @@
'test_fru_utils',
'test/test_fru-utils.cpp',
'src/fru_utils.cpp',
+ 'src/fru_reader.cpp',
cpp_args: test_boost_args,
dependencies: [
boost,
diff --git a/src/fru_device.cpp b/src/fru_device.cpp
index af53e7f..b4c3668 100644
--- a/src/fru_device.cpp
+++ b/src/fru_device.cpp
@@ -116,9 +116,7 @@
}
}
-static ssize_t readFromEeprom(int flag __attribute__((unused)), int fd,
- uint16_t address __attribute__((unused)),
- off_t offset, size_t len, uint8_t* buf)
+static int64_t readFromEeprom(int fd, off_t offset, size_t len, uint8_t* buf)
{
auto result = lseek(fd, offset, SEEK_SET);
if (result < 0)
@@ -189,21 +187,21 @@
it->second->initialize();
}
-static int isDevice16Bit(int file)
+static std::optional<bool> isDevice16Bit(int file)
{
// Set the higher data word address bits to 0. It's safe on 8-bit addressing
// EEPROMs because it doesn't write any actual data.
int ret = i2c_smbus_write_byte(file, 0);
if (ret < 0)
{
- return ret;
+ return std::nullopt;
}
/* Get first byte */
int byte1 = i2c_smbus_read_byte_data(file, 0);
if (byte1 < 0)
{
- return byte1;
+ return std::nullopt;
}
/* Read 7 more bytes, it will read same first byte in case of
* 8 bit but it will read next byte in case of 16 bit
@@ -213,14 +211,14 @@
int byte2 = i2c_smbus_read_byte_data(file, 0);
if (byte2 < 0)
{
- return byte2;
+ return std::nullopt;
}
if (byte2 != byte1)
{
- return 1;
+ return true;
}
}
- return 0;
+ return false;
}
// Issue an I2C transaction to first write to_slave_buf_len bytes,then read
@@ -256,10 +254,10 @@
return (ret == SMBUS_IOCTL_WRITE_THEN_READ_MSG_COUNT) ? msgs[1].len : -1;
}
-static ssize_t readBlockData(int flag, int file, uint16_t address, off_t offset,
- size_t len, uint8_t* buf)
+static int64_t readBlockData(bool is16bit, int file, uint16_t address,
+ off_t offset, size_t len, uint8_t* buf)
{
- if (flag == 0)
+ if (!is16bit)
{
return i2c_smbus_read_i2c_block_data(file, static_cast<uint8_t>(offset),
len, buf);
@@ -285,8 +283,11 @@
std::string errorMessage = "eeprom at " + std::to_string(bus) +
" address " + std::to_string(address);
- std::vector<uint8_t> device = readFRUContents(
- 0, file, static_cast<uint16_t>(address), readFromEeprom, errorMessage);
+ auto readFunc = [file](off_t offset, size_t length, uint8_t* outbuf) {
+ return readFromEeprom(file, offset, length, outbuf);
+ };
+ FRUReader reader(std::move(readFunc));
+ std::vector<uint8_t> device = readFRUContents(reader, errorMessage);
close(file);
return device;
@@ -431,8 +432,8 @@
}
/* Check for Device type if it is 8 bit or 16 bit */
- int flag = isDevice16Bit(file);
- if (flag < 0)
+ std::optional<bool> is16Bit = isDevice16Bit(file);
+ if (!is16Bit.has_value())
{
std::cerr << "failed to read bus " << bus << " address " << ii
<< "\n";
@@ -442,12 +443,17 @@
}
continue;
}
+ bool is16BitBool{*is16Bit};
+ auto readFunc = [is16BitBool, file, ii](off_t offset, size_t length,
+ uint8_t* outbuf) {
+ return readBlockData(is16BitBool, file, ii, offset, length,
+ outbuf);
+ };
+ FRUReader reader(std::move(readFunc));
std::string errorMessage =
"bus " + std::to_string(bus) + " address " + std::to_string(ii);
- std::vector<uint8_t> device =
- readFRUContents(flag, file, static_cast<uint16_t>(ii),
- readBlockData, errorMessage);
+ std::vector<uint8_t> device = readFRUContents(reader, errorMessage);
if (device.empty())
{
continue;
diff --git a/src/fru_reader.cpp b/src/fru_reader.cpp
new file mode 100644
index 0000000..e381e7e
--- /dev/null
+++ b/src/fru_reader.cpp
@@ -0,0 +1,90 @@
+/*
+// Copyright (c) 2022 Equinix, Inc.
+//
+// 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 "fru_reader.hpp"
+
+#include <cstring>
+
+ssize_t FRUReader::read(off_t start, size_t len, uint8_t* outbuf)
+{
+ size_t done = 0;
+ size_t remaining = len;
+ size_t cursor = start;
+ while (done < len)
+ {
+ if (eof.has_value() && cursor >= eof.value())
+ {
+ break;
+ }
+
+ const uint8_t* blkData;
+ size_t available;
+ size_t blk = cursor / cacheBlockSize;
+ size_t blkOffset = cursor % cacheBlockSize;
+ auto findBlk = cache.find(blk);
+ if (findBlk == cache.end())
+ {
+ // miss, populate cache
+ uint8_t* newData = cache[blk].data();
+ int64_t ret =
+ readFunc(blk * cacheBlockSize, cacheBlockSize, newData);
+
+ // if we've reached the end of the eeprom, record its size
+ if (ret >= 0 && static_cast<size_t>(ret) < cacheBlockSize)
+ {
+ eof = (blk * cacheBlockSize) + ret;
+ }
+
+ if (ret <= 0)
+ {
+ // don't leave empty blocks in the cache
+ cache.erase(blk);
+ return done ? done : ret;
+ }
+
+ blkData = newData;
+ available = ret;
+ }
+ else
+ {
+ // hit, use cached data
+ blkData = findBlk->second.data();
+
+ // if the hit is to the block containing the (previously
+ // discovered on the miss that populated it) end of the eeprom,
+ // don't copy spurious bytes past the end
+ if (eof.has_value() && (eof.value() / cacheBlockSize == blk))
+ {
+ available = eof.value() % cacheBlockSize;
+ }
+ else
+ {
+ available = cacheBlockSize;
+ }
+ }
+
+ size_t toCopy = (blkOffset >= available)
+ ? 0
+ : std::min(available - blkOffset, remaining);
+
+ memcpy(outbuf + done, blkData + blkOffset, toCopy);
+ cursor += toCopy;
+ done += toCopy;
+ remaining -= toCopy;
+ }
+
+ return done;
+}
diff --git a/src/fru_utils.cpp b/src/fru_utils.cpp
index 62390c6..99f4aa9 100644
--- a/src/fru_utils.cpp
+++ b/src/fru_utils.cpp
@@ -587,12 +587,11 @@
return true;
}
-bool findFRUHeader(int flag, int file, uint16_t address,
- const ReadBlockFunc& readBlock, const std::string& errorHelp,
+bool findFRUHeader(FRUReader& reader, const std::string& errorHelp,
std::array<uint8_t, I2C_SMBUS_BLOCK_MAX>& blockData,
off_t& baseOffset)
{
- if (readBlock(flag, file, address, baseOffset, 0x8, blockData.data()) < 0)
+ if (reader.read(baseOffset, 0x8, blockData.data()) < 0)
{
std::cerr << "failed to read " << errorHelp << " base offset "
<< baseOffset << "\n";
@@ -620,8 +619,7 @@
{
// look for the FRU header at offset 0x6000
baseOffset = 0x6000;
- return findFRUHeader(flag, file, address, readBlock, errorHelp,
- blockData, baseOffset);
+ return findFRUHeader(reader, errorHelp, blockData, baseOffset);
}
if (debug)
@@ -633,15 +631,13 @@
return false;
}
-std::vector<uint8_t> readFRUContents(int flag, int file, uint16_t address,
- const ReadBlockFunc& readBlock,
+std::vector<uint8_t> readFRUContents(FRUReader& reader,
const std::string& errorHelp)
{
std::array<uint8_t, I2C_SMBUS_BLOCK_MAX> blockData;
off_t baseOffset = 0x0;
- if (!findFRUHeader(flag, file, address, readBlock, errorHelp, blockData,
- baseOffset))
+ if (!findFRUHeader(reader, errorHelp, blockData, baseOffset))
{
return {};
}
@@ -685,8 +681,7 @@
areaOffset *= fruBlockSize;
- if (readBlock(flag, file, address, baseOffset + areaOffset, 0x2,
- blockData.data()) < 0)
+ if (reader.read(baseOffset + areaOffset, 0x2, blockData.data()) < 0)
{
std::cerr << "failed to read " << errorHelp << " base offset "
<< baseOffset << "\n";
@@ -716,8 +711,7 @@
{
// In multi-area, the area offset points to the 0th record, each
// record has 3 bytes of the header we care about.
- if (readBlock(flag, file, address, baseOffset + areaOffset, 0x3,
- blockData.data()) < 0)
+ if (reader.read(baseOffset + areaOffset, 0x3, blockData.data()) < 0)
{
std::cerr << "failed to read " << errorHelp << " base offset "
<< baseOffset << "\n";
@@ -748,8 +742,8 @@
size_t requestLength =
std::min(static_cast<size_t>(I2C_SMBUS_BLOCK_MAX), fruLength);
- if (readBlock(flag, file, address, baseOffset + readOffset,
- requestLength, blockData.data()) < 0)
+ if (reader.read(baseOffset + readOffset, requestLength,
+ blockData.data()) < 0)
{
std::cerr << "failed to read " << errorHelp << " base offset "
<< baseOffset << "\n";
diff --git a/src/meson.build b/src/meson.build
index 8ddb21e..d2959bf 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -32,6 +32,7 @@
'fru_device.cpp',
'utils.cpp',
'fru_utils.cpp',
+ 'fru_reader.cpp',
cpp_args: cpp_args_fd,
dependencies: [
boost,
diff --git a/test/test_fru-utils.cpp b/test/test_fru-utils.cpp
index 5a6ce52..02abc34 100644
--- a/test/test_fru-utils.cpp
+++ b/test/test_fru-utils.cpp
@@ -12,6 +12,8 @@
#include <linux/i2c.h>
}
+static constexpr size_t blockSize = I2C_SMBUS_BLOCK_MAX;
+
TEST(ValidateHeaderTest, InvalidFruVersionReturnsFalse)
{
// Validates the FruVersion is checked for the only legal value.
@@ -145,9 +147,7 @@
EXPECT_EQ(calculateChecksum(data), 255);
}
-int64_t getDataTempl(const std::vector<uint8_t>& data,
- [[maybe_unused]] int flag, [[maybe_unused]] int file,
- [[maybe_unused]] uint16_t address, off_t offset,
+int64_t getDataTempl(const std::vector<uint8_t>& data, off_t offset,
size_t length, uint8_t* outBuf)
{
if (offset >= static_cast<off_t>(data.size()))
@@ -165,16 +165,153 @@
return idx - offset;
}
+TEST(FRUReaderTest, ReadData)
+{
+ std::vector<uint8_t> data = {};
+ for (size_t i = 0; i < blockSize * 2; i++)
+ {
+ data.push_back(i);
+ }
+ std::array<uint8_t, blockSize * 2> rdbuf;
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
+ };
+ FRUReader reader(getData);
+
+ EXPECT_EQ(reader.read(0, data.size(), rdbuf.data()),
+ static_cast<ssize_t>(data.size()));
+ EXPECT_TRUE(std::equal(rdbuf.begin(), rdbuf.end(), data.begin()));
+ for (size_t i = 0; i < blockSize * 2; i++)
+ {
+ EXPECT_EQ(reader.read(i, 1, rdbuf.data()), 1);
+ EXPECT_EQ(rdbuf[i], i);
+ }
+ EXPECT_EQ(reader.read(blockSize - 1, 2, rdbuf.data()), 2);
+ EXPECT_EQ(rdbuf[0], blockSize - 1);
+ EXPECT_EQ(rdbuf[1], blockSize);
+}
+
+TEST(FRUReaderTest, StartPastUnknownEOF)
+{
+ const std::vector<uint8_t> data = {};
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
+ };
+ FRUReader reader(getData);
+
+ EXPECT_EQ(reader.read(1, 1, nullptr), 0);
+}
+
+TEST(FRUReaderTest, StartPastKnownEOF)
+{
+ std::vector<uint8_t> data = {};
+ data.resize(blockSize / 2);
+ std::array<uint8_t, blockSize> blockData;
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
+ };
+ FRUReader reader(getData);
+
+ EXPECT_EQ(reader.read(0, blockSize, blockData.data()),
+ static_cast<ssize_t>(data.size()));
+ EXPECT_EQ(reader.read(data.size(), 1, nullptr), 0);
+ EXPECT_EQ(reader.read(data.size() + 1, 1, nullptr), 0);
+ EXPECT_EQ(reader.read(blockSize, 1, nullptr), 0);
+ EXPECT_EQ(reader.read(blockSize + 1, 1, nullptr), 0);
+}
+
+TEST(FRUReaderTest, DecreasingEOF)
+{
+ const std::vector<uint8_t> data = {};
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
+ };
+ FRUReader reader(getData);
+
+ EXPECT_EQ(reader.read(blockSize * 2, 1, nullptr), 0);
+ EXPECT_EQ(reader.read(blockSize + (blockSize / 2), 1, nullptr), 0);
+ EXPECT_EQ(reader.read(blockSize, 1, nullptr), 0);
+ EXPECT_EQ(reader.read(blockSize / 2, 1, nullptr), 0);
+ EXPECT_EQ(reader.read(0, 1, nullptr), 0);
+}
+
+TEST(FRUReaderTest, CacheHit)
+{
+ std::vector<uint8_t> data = {'X'};
+ std::array<uint8_t, blockSize> read1, read2;
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
+ };
+ FRUReader reader(getData);
+
+ // cache hit should return the same data for the second read even if we
+ // change it behind the FRUReader's back after the first
+ EXPECT_EQ(reader.read(0, blockSize, read1.data()), 1);
+ data[0] = 'Y';
+ EXPECT_EQ(reader.read(0, blockSize, read2.data()), 1);
+ EXPECT_EQ(read1[0], read2[0]);
+}
+
+TEST(FRUReaderTest, ReadPastKnownEnd)
+{
+ const std::vector<uint8_t> data = {'X', 'Y'};
+ std::array<uint8_t, blockSize> rdbuf;
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
+ };
+ FRUReader reader(getData);
+
+ EXPECT_EQ(reader.read(0, data.size(), rdbuf.data()),
+ static_cast<ssize_t>(data.size()));
+ EXPECT_EQ(rdbuf[0], 'X');
+ EXPECT_EQ(rdbuf[1], 'Y');
+ EXPECT_EQ(reader.read(1, data.size(), rdbuf.data()),
+ static_cast<ssize_t>(data.size() - 1));
+ EXPECT_EQ(rdbuf[0], 'Y');
+}
+
+TEST(FRUReaderTest, MultiBlockRead)
+{
+ std::vector<uint8_t> data = {};
+ data.resize(blockSize, 'X');
+ data.resize(2 * blockSize, 'Y');
+ std::array<uint8_t, 2 * blockSize> rdbuf;
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
+ };
+ FRUReader reader(getData);
+
+ EXPECT_EQ(reader.read(0, 2 * blockSize, rdbuf.data()),
+ static_cast<ssize_t>(2 * blockSize));
+ EXPECT_TRUE(std::equal(rdbuf.begin(), rdbuf.end(), data.begin()));
+}
+
+TEST(FRUReaderTest, ShrinkingEEPROM)
+{
+ std::vector<uint8_t> data = {};
+ data.resize(3 * blockSize, 'X');
+ std::array<uint8_t, blockSize> rdbuf;
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
+ };
+ FRUReader reader(getData);
+
+ EXPECT_EQ(reader.read(data.size() - 1, 2, rdbuf.data()), 1);
+ data.resize(blockSize);
+ EXPECT_EQ(reader.read(data.size() - 1, 2, rdbuf.data()), 1);
+}
+
TEST(FindFRUHeaderTest, InvalidHeader)
{
const std::vector<uint8_t> data = {255, 16};
off_t offset = 0;
std::array<uint8_t, I2C_SMBUS_BLOCK_MAX> blockData;
- auto getData = [&data](auto fl, auto fi, auto a, auto o, auto l, auto* b) {
- return getDataTempl(data, fl, fi, a, o, l, b);
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
};
+ FRUReader reader(getData);
- EXPECT_FALSE(findFRUHeader(0, 0, 0, getData, "error", blockData, offset));
+ EXPECT_FALSE(findFRUHeader(reader, "error", blockData, offset));
}
TEST(FindFRUHeaderTest, NoData)
@@ -182,11 +319,12 @@
const std::vector<uint8_t> data = {};
off_t offset = 0;
std::array<uint8_t, I2C_SMBUS_BLOCK_MAX> blockData;
- auto getData = [&data](auto fl, auto fi, auto a, auto o, auto l, auto* b) {
- return getDataTempl(data, fl, fi, a, o, l, b);
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
};
+ FRUReader reader(getData);
- EXPECT_FALSE(findFRUHeader(0, 0, 0, getData, "error", blockData, offset));
+ EXPECT_FALSE(findFRUHeader(reader, "error", blockData, offset));
}
TEST(FindFRUHeaderTest, ValidHeader)
@@ -195,11 +333,12 @@
0x03, 0x04, 0x00, 0xf5};
off_t offset = 0;
std::array<uint8_t, I2C_SMBUS_BLOCK_MAX> blockData;
- auto getData = [&data](auto fl, auto fi, auto a, auto o, auto l, auto* b) {
- return getDataTempl(data, fl, fi, a, o, l, b);
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
};
+ FRUReader reader(getData);
- EXPECT_TRUE(findFRUHeader(0, 0, 0, getData, "error", blockData, offset));
+ EXPECT_TRUE(findFRUHeader(reader, "error", blockData, offset));
EXPECT_EQ(0, offset);
}
@@ -209,11 +348,12 @@
data.resize(0x6000 + I2C_SMBUS_BLOCK_MAX);
off_t offset = 0;
std::array<uint8_t, I2C_SMBUS_BLOCK_MAX> blockData;
- auto getData = [&data](auto fl, auto fi, auto a, auto o, auto l, auto* b) {
- return getDataTempl(data, fl, fi, a, o, l, b);
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
};
+ FRUReader reader(getData);
- EXPECT_FALSE(findFRUHeader(0, 0, 0, getData, "error", blockData, offset));
+ EXPECT_FALSE(findFRUHeader(reader, "error", blockData, offset));
}
TEST(FindFRUHeaderTest, TyanNoData)
@@ -221,11 +361,12 @@
const std::vector<uint8_t> data = {'$', 'T', 'Y', 'A', 'N', '$', 0, 0};
off_t offset = 0;
std::array<uint8_t, I2C_SMBUS_BLOCK_MAX> blockData;
- auto getData = [&data](auto fl, auto fi, auto a, auto o, auto l, auto* b) {
- return getDataTempl(data, fl, fi, a, o, l, b);
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
};
+ FRUReader reader(getData);
- EXPECT_FALSE(findFRUHeader(0, 0, 0, getData, "error", blockData, offset));
+ EXPECT_FALSE(findFRUHeader(reader, "error", blockData, offset));
}
TEST(FindFRUHeaderTest, TyanValidHeader)
@@ -238,10 +379,11 @@
off_t offset = 0;
std::array<uint8_t, I2C_SMBUS_BLOCK_MAX> blockData;
- auto getData = [&data](auto fl, auto fi, auto a, auto o, auto l, auto* b) {
- return getDataTempl(data, fl, fi, a, o, l, b);
+ auto getData = [&data](auto o, auto l, auto* b) {
+ return getDataTempl(data, o, l, b);
};
+ FRUReader reader(getData);
- EXPECT_TRUE(findFRUHeader(0, 0, 0, getData, "error", blockData, offset));
+ EXPECT_TRUE(findFRUHeader(reader, "error", blockData, offset));
EXPECT_EQ(0x6000, offset);
}