Skip to content

Commit a9a17ae

Browse files
binhuang00meta-codesync[bot]
authored andcommitted
Revert D90290258
Summary: Reverts D90290258 which added a buffer constructor to FbossEepromInterface. The file-based testing approach using folly::test::TemporaryDirectory is more valuable for catching issues at the unit test level rather than relying on hardware tests. This also removes the boost dependency in favor of std::transform for uppercase string conversion. Reviewed By: somasun Differential Revision: D90834969 fbshipit-source-id: 0539c4dc2f336a15721d3ce9f6991686440ce1d4
1 parent c0e76cf commit a9a17ae

File tree

7 files changed

+62
-97
lines changed

7 files changed

+62
-97
lines changed

cmake/PlatformWeutil.cmake

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ add_library(weutil_fboss_eeprom_interface
2929
)
3030

3131
target_link_libraries(weutil_fboss_eeprom_interface
32-
fmt::fmt
33-
Folly::folly
34-
weutil_crc16_ccitt_aug
35-
weutil_eeprom_contents_cpp2
32+
Folly::folly
33+
weutil_crc16_ccitt_aug
34+
weutil_eeprom_contents_cpp2
3635
)
3736

3837
add_library(weutil_lib

fboss/platform/weutil/BUCK

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ cpp_library(
1515
headers = [
1616
"WeutilInterface.h",
1717
],
18-
preferred_linkage = "static",
1918
exported_deps = [
2019
":config_utils_lib",
2120
":eeprom_content_validator",
@@ -31,7 +30,6 @@ cpp_library(
3130
],
3231
exported_external_deps = [
3332
"gflags",
34-
("boost", None, "boost_algorithm"),
3533
],
3634
)
3735

fboss/platform/weutil/FbossEepromInterface.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,15 +83,6 @@ FbossEepromInterface::FbossEepromInterface(
8383
const std::string& eepromPath,
8484
const uint16_t offset) {
8585
auto buffer = ParserUtils::loadEeprom(eepromPath, offset);
86-
initFromBuffer(buffer);
87-
}
88-
89-
FbossEepromInterface::FbossEepromInterface(
90-
const std::vector<uint8_t>& eepromBuffer) {
91-
initFromBuffer(eepromBuffer);
92-
}
93-
94-
void FbossEepromInterface::initFromBuffer(const std::vector<uint8_t>& buffer) {
9586
if (buffer.size() < kHeaderSize) {
9687
throw std::runtime_error("Invalid EEPROM size");
9788
}

fboss/platform/weutil/FbossEepromInterface.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,6 @@ class FbossEepromInterface {
3131

3232
FbossEepromInterface(const std::string& eepromPath, const uint16_t offset);
3333

34-
explicit FbossEepromInterface(const std::vector<uint8_t>& eepromBuffer);
35-
3634
// TODO: Get rid of getContents() in the future.
3735
std::vector<std::pair<std::string, std::string>> getContents() const;
3836

@@ -48,7 +46,6 @@ class FbossEepromInterface {
4846

4947
private:
5048
FbossEepromInterface() = default;
51-
void initFromBuffer(const std::vector<uint8_t>& buffer);
5249
void parseEepromBlobTLV(const std::vector<uint8_t>& buffer);
5350

5451
std::map<int, EepromFieldEntry> fieldMap_{};

fboss/platform/weutil/Weutil.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
// (c) Facebook, Inc. and its affiliates. Confidential and proprietary.
22
#include "fboss/platform/weutil/Weutil.h"
33

4-
#include <boost/algorithm/string.hpp>
54
#include <folly/logging/xlog.h>
65
#include <thrift/lib/cpp2/protocol/Serializer.h>
76

@@ -33,7 +32,12 @@ std::unique_ptr<WeutilInterface> createWeUtilIntf(
3332
}
3433
weutil::ConfigUtils configUtils(platformName);
3534
weutil::FruEeprom fruEeprom;
36-
auto upperEepromName = boost::to_upper_copy(eepromName);
35+
std::string upperEepromName = eepromName;
36+
std::transform(
37+
upperEepromName.begin(),
38+
upperEepromName.end(),
39+
upperEepromName.begin(),
40+
[](unsigned char c) { return std::toupper(c); });
3741
if (upperEepromName == "CHASSIS" || upperEepromName.empty()) {
3842
fruEeprom = configUtils.getFruEeprom(configUtils.getChassisEepromName());
3943
} else {

fboss/platform/weutil/test/BUCK

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,10 @@ cpp_unittest(
3838
"FbossEepromInterfaceTest.cpp",
3939
],
4040
deps = [
41-
"fbsource//third-party/fmt:fmt",
4241
"//fboss/platform/weutil:fboss_eeprom_lib",
4342
"//fboss/platform/weutil/if:eeprom_contents-cpp2-types",
43+
"//folly:file_util",
44+
"//folly/testing:test_util",
4445
],
4546
)
4647

fboss/platform/weutil/test/FbossEepromInterfaceTest.cpp

Lines changed: 51 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// (c) Meta Platforms, Inc. and affiliates. Confidential and proprietary.
22

3-
#include <fmt/format.h>
43
#include <gtest/gtest.h>
54

5+
#include <folly/FileUtil.h>
6+
#include <folly/testing/TestUtil.h>
7+
68
#include "fboss/platform/weutil/FbossEepromInterface.h"
79
#include "fboss/platform/weutil/if/gen-cpp2/eeprom_contents_types.h"
810

@@ -13,7 +15,7 @@ using EepromData = std::vector<uint8_t>;
1315

1416
// Based on the Spec for V5 EEPROM:
1517
// https://github.com/facebook/fboss/blob/main/fboss/docs/meta_eeprom_format_v5.md
16-
EepromData kEepromV5 = {
18+
const EepromData kEepromV5 = {
1719
0xfb, 0xfb, 0x05, 0xff, 0x01, 0x0d, 0x46, 0x49, 0x52, 0x53, 0x54, 0x5f,
1820
0x53, 0x51, 0x55, 0x45, 0x45, 0x5a, 0x45, 0x02, 0x08, 0x32, 0x30, 0x31,
1921
0x32, 0x33, 0x34, 0x35, 0x36, 0x03, 0x08, 0x53, 0x59, 0x53, 0x41, 0x31,
@@ -36,7 +38,7 @@ EepromData kEepromV5 = {
3638

3739
// EEPROM V5 with wrong CRC Programmed (same as the one above, but last 2
3840
// bytes have wrong CRC value programmed.)
39-
EepromData kEepromV5WrongCrc = {
41+
const EepromData kEepromV5WrongCrc = {
4042
0xfb, 0xfb, 0x05, 0xff, 0x01, 0x0d, 0x46, 0x49, 0x52, 0x53, 0x54, 0x5f,
4143
0x53, 0x51, 0x55, 0x45, 0x45, 0x5a, 0x45, 0x02, 0x08, 0x32, 0x30, 0x31,
4244
0x32, 0x33, 0x34, 0x35, 0x36, 0x03, 0x08, 0x53, 0x59, 0x53, 0x41, 0x31,
@@ -59,7 +61,7 @@ EepromData kEepromV5WrongCrc = {
5961

6062
// Based on the Spec for V6 EEPROM:
6163
// https://github.com/facebook/fboss/blob/main/fboss/docs/meta_eeprom_format_v6.md
62-
EepromData kEepromV6 = {
64+
const EepromData kEepromV6 = {
6365
0xfb, 0xfb, 0x06, 0xff, 0x01, 0x0d, 0x46, 0x49, 0x52, 0x53, 0x54, 0x5f,
6466
0x53, 0x51, 0x55, 0x45, 0x45, 0x5a, 0x45, 0x02, 0x08, 0x32, 0x30, 0x31,
6567
0x32, 0x33, 0x34, 0x35, 0x36, 0x03, 0x08, 0x53, 0x59, 0x53, 0x41, 0x31,
@@ -82,6 +84,14 @@ EepromData kEepromV6 = {
8284
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
8385
0xff};
8486

87+
FbossEepromInterface createFbossEepromInterface(const EepromData& data) {
88+
folly::test::TemporaryDirectory tmpDir = folly::test::TemporaryDirectory();
89+
std::string fileName = tmpDir.path().string() + "/eepromContent";
90+
folly::writeFile(data, fileName.c_str());
91+
92+
return FbossEepromInterface(fileName, 0);
93+
}
94+
8595
constexpr auto kProductName = "FIRST_SQUEEZE";
8696
constexpr auto kProductPartNumber = "20123456";
8797
constexpr auto kSystemAssemblyPartNumber = "SYSA1234";
@@ -106,10 +116,9 @@ constexpr auto kRma = "1";
106116
constexpr auto kVendorDefinedField1 = "0x0101010101";
107117
constexpr auto kVendorDefinedField2 = "0x48656c6c6f";
108118
constexpr auto kVendorDefinedField3 = "";
109-
constexpr auto kCrc16V5 = "0xd5c6";
110-
constexpr auto kCrc16V6 = "0x4a05";
111-
constexpr auto kCrcCorrectTemplate = "{} (CRC Matched)";
112-
constexpr auto kCrc16WrongTemplate = "0xa6b7 (CRC Mismatch. Expected {})";
119+
constexpr auto kCrc16V5 = "0xd5c6 (CRC Matched)";
120+
constexpr auto kCrc16V6 = "0x4a05 (CRC Matched)";
121+
constexpr auto kCrc16V5Wrong = "0xa6b7 (CRC Mismatch. Expected 0xd5c6)";
113122

114123
EepromContents createEepromContents(int version, bool crcMatched = true) {
115124
EepromContents result;
@@ -134,15 +143,13 @@ EepromContents createEepromContents(int version, bool crcMatched = true) {
134143
result.bmcMac() = kBmcMac;
135144
result.switchAsicMac() = kSwitchAsicMac;
136145
result.metaReservedMac() = kMetaReservedMac;
137-
const std::string crc16 = version == 5 ? kCrc16V5 : kCrc16V6;
138146

139-
if (crcMatched) {
140-
result.crc16() = fmt::format(kCrcCorrectTemplate, crc16);
141-
} else {
142-
result.crc16() = fmt::format(kCrc16WrongTemplate, crc16);
147+
if (version == 5) {
148+
result.crc16() = crcMatched ? kCrc16V5 : kCrc16V5Wrong;
149+
} else if (version == 6) {
150+
result.crc16() = kCrc16V6;
143151
}
144152

145-
// V6 unique fields
146153
if (version == 6) {
147154
result.rma() = kRma;
148155
result.vendorDefinedField1() = kVendorDefinedField1;
@@ -153,94 +160,62 @@ EepromContents createEepromContents(int version, bool crcMatched = true) {
153160
return result;
154161
};
155162

156-
struct CommonEepromFields {
157-
std::string productName;
158-
std::string productPartNumber;
159-
std::string productionState;
160-
std::string productionSubState;
161-
std::string variantIndicator;
162-
std::string productSerialNumber;
163-
164-
bool operator==(const CommonEepromFields& other) const = default;
165-
};
166-
167-
CommonEepromFields getCommonFields(const FbossEepromInterface& eeprom) {
168-
return CommonEepromFields{
169-
.productName = eeprom.getProductName(),
170-
.productPartNumber = eeprom.getProductPartNumber(),
171-
.productionState = eeprom.getProductionState(),
172-
.productionSubState = eeprom.getProductionSubState(),
173-
.variantIndicator = eeprom.getVariantVersion(),
174-
.productSerialNumber = eeprom.getProductSerialNumber(),
175-
};
176-
}
177-
178-
const CommonEepromFields kExpectedCommonFields{
179-
.productName = kProductName,
180-
.productPartNumber = kProductPartNumber,
181-
.productionState = kProductionState,
182-
.productionSubState = kProductionSubState,
183-
.variantIndicator = kVariantIndicator,
184-
.productSerialNumber = kProductSerialNumber,
185-
};
186-
187-
// Helper to verify common EEPROM fields parsed correctly
188-
void verifyCommonEepromFields(const FbossEepromInterface& eeprom) {
189-
EXPECT_EQ(getCommonFields(eeprom), kExpectedCommonFields);
190-
}
191-
192163
} // namespace
193164

194-
TEST(FbossEepromInterfaceTest, V5WithBufferConstructor) {
195-
FbossEepromInterface eeprom(kEepromV5);
196-
EXPECT_EQ(eeprom.getVersion(), 5);
197-
verifyCommonEepromFields(eeprom);
165+
TEST(FbossEepromInterfaceTest, V5) {
166+
auto eeprom = createFbossEepromInterface(kEepromV5);
167+
168+
EXPECT_EQ(eeprom.getProductName(), kProductName);
169+
EXPECT_EQ(eeprom.getProductPartNumber(), kProductPartNumber);
170+
EXPECT_EQ(eeprom.getProductionState(), kProductionState);
171+
EXPECT_EQ(eeprom.getProductionSubState(), kProductionSubState);
172+
EXPECT_EQ(eeprom.getVariantVersion(), kVariantIndicator);
173+
EXPECT_EQ(eeprom.getProductSerialNumber(), kProductSerialNumber);
198174
}
199175

200176
TEST(FbossEepromInterfaceTest, V5WrongCRC) {
201-
FbossEepromInterface eeprom(kEepromV5WrongCrc);
202-
EXPECT_EQ(eeprom.getVersion(), 5);
203-
verifyCommonEepromFields(eeprom);
177+
auto eeprom = createFbossEepromInterface(kEepromV5WrongCrc);
178+
EXPECT_EQ(eeprom.getProductName(), kProductName);
179+
EXPECT_EQ(eeprom.getProductPartNumber(), kProductPartNumber);
180+
EXPECT_EQ(eeprom.getProductionState(), kProductionState);
181+
EXPECT_EQ(eeprom.getProductionSubState(), kProductionSubState);
182+
EXPECT_EQ(eeprom.getVariantVersion(), kVariantIndicator);
183+
EXPECT_EQ(eeprom.getProductSerialNumber(), kProductSerialNumber);
204184
}
205185

206-
TEST(FbossEepromInterfaceTest, V6WithBufferConstructor) {
207-
FbossEepromInterface eeprom(kEepromV6);
208-
EXPECT_EQ(eeprom.getVersion(), 6);
209-
verifyCommonEepromFields(eeprom);
186+
TEST(FbossEepromInterfaceTest, V6) {
187+
auto eeprom = createFbossEepromInterface(kEepromV6);
188+
EXPECT_EQ(eeprom.getProductName(), kProductName);
189+
EXPECT_EQ(eeprom.getProductPartNumber(), kProductPartNumber);
190+
EXPECT_EQ(eeprom.getProductionState(), kProductionState);
191+
EXPECT_EQ(eeprom.getProductionSubState(), kProductionSubState);
192+
EXPECT_EQ(eeprom.getVariantVersion(), kVariantIndicator);
193+
EXPECT_EQ(eeprom.getProductSerialNumber(), kProductSerialNumber);
210194
}
211195

212196
TEST(FbossEepromInterfaceTest, V5Object) {
213-
FbossEepromInterface eepromInterface(kEepromV5);
214-
auto actualObj = eepromInterface.getEepromContents();
197+
auto eepromInterace = createFbossEepromInterface(kEepromV5);
198+
auto actualObj = eepromInterace.getEepromContents();
199+
215200
EepromContents expectedObj = createEepromContents(5);
216201

217202
EXPECT_EQ(actualObj, expectedObj);
218203
}
219204

220205
TEST(FbossEepromInterfaceTest, V6Object) {
221-
FbossEepromInterface eepromInterface(kEepromV6);
222-
auto actualObj = eepromInterface.getEepromContents();
206+
auto eepromInterace = createFbossEepromInterface(kEepromV6);
207+
auto actualObj = eepromInterace.getEepromContents();
223208
EepromContents expectedObj = createEepromContents(6);
224209

225210
EXPECT_EQ(actualObj, expectedObj);
226211
}
227212

228213
TEST(FbossEepromInterfaceTest, V5ObjWrongCrc) {
229-
FbossEepromInterface eeprom(kEepromV5WrongCrc);
214+
auto eeprom = createFbossEepromInterface(kEepromV5WrongCrc);
230215
auto actualObj = eeprom.getEepromContents();
231216
EepromContents expectedObj = createEepromContents(5, false);
232217

233218
EXPECT_EQ(actualObj, expectedObj);
234219
}
235220

236-
TEST(FbossEepromInterfaceTest, InvalidEepromSize) {
237-
std::vector<uint8_t> tooSmall = {0xfb, 0xfb};
238-
EXPECT_THROW((FbossEepromInterface{tooSmall}), std::runtime_error);
239-
}
240-
241-
TEST(FbossEepromInterfaceTest, InvalidVersion) {
242-
std::vector<uint8_t> badVersion = {0xfb, 0xfb, 0x99, 0xff};
243-
EXPECT_THROW((FbossEepromInterface{badVersion}), std::runtime_error);
244-
}
245-
246221
} // namespace facebook::fboss::platform

0 commit comments

Comments
 (0)