Skip to content

Commit

Permalink
Filter out ECC bits from asic programming test
Browse files Browse the repository at this point in the history
Summary: Filter out ECC bits since they can change between cold/warm boot.

Reviewed By: nivinl

Differential Revision: D66323084

fbshipit-source-id: 6d2be53e6fc3818ffa19efecc166d3952fea494b
  • Loading branch information
maxwindiff authored and facebook-github-bot committed Nov 22, 2024
1 parent 5ad8e68 commit a63997d
Show file tree
Hide file tree
Showing 2 changed files with 13,989 additions and 13,967 deletions.
80 changes: 51 additions & 29 deletions fboss/agent/hw/test/HwAsicDefaultProgrammingTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ class HwAsicDefaultProgrammingTest : public HwTest {
std::string line;
while (std::getline(iss, line)) {
std::string type, key, value;
folly::split(',', line, type, key, value);
// <false> means putting all remaining parts into the last field.
if (!folly::split<false>(',', line, type, key, value)) {
throw std::invalid_argument("Failed to parse: " + line);
}
ret[type + ":" + key] = folly::trimWhitespace(value);
}
return ret;
Expand Down Expand Up @@ -99,20 +102,33 @@ class HwAsicDefaultProgrammingTest : public HwTest {
for (const auto& [type, var] : queries->second) {
std::string cmd;
if (type == "mem") {
cmd = "dump raw " + var + "\n";
// Dump in the standard format instead of the raw format so that we can
// filter out the ECC bits, also it's easier to inspect for diffs.
cmd = "dump " + var + "\n";
} else if (type == "reg") {
cmd = "getreg raw " + var + "\n";
cmd = "getreg " + var + "\n";
}

getHwSwitchEnsemble()->runDiagCommand(cmd, diagOut);

std::istringstream iss(diagOut);
std::string line;
while (std::getline(iss, line)) {
// Example: CIG_RCI_CONFIGS.CIG0[0x103]=0x5140e101f407d081ac
static const re2::RE2 pattern("([a-zA-Z0-9_()\\.\\[\\]]+)\\s*[:=](.*)");
// mem example:
// CGM_PB_VSQ_RJCT_MASK.CGM0[0]: <VOQ_RJCT_MASK=0x3ff,
// VSQ_RJCT_MASK=0xffffff, GLBL_RJCT_MASK=0xf>

// reg example:
// FDTS_FDT_SHAPER_CONFIGURATIONS.FDTS0[0x104]=0x500a0006428080a4176004e601:
// <FABRIC_SHAPER_EN=1, AUTO_DOC_NAME_23=0x27300,
// ...,
// FDT_SHAPER_CONFIGURATIONS_FIELD_6=0x14>
static const re2::RE2 pattern(
"([a-zA-Z0-9_()\\.\\[\\]]+)\\s*[:=]\\s*(.*)");
std::string key, value;
if (re2::RE2::FullMatch(line, pattern, &key, &value)) {
static const re2::RE2 eccPattern(", ECC=[x0-9a-fA-F]+");
re2::RE2::Replace(&value, eccPattern, "");
ret[type + ":" + key] = folly::trimWhitespace(value);
} else {
// Ignored any junk echoed by the diag shell.
Expand All @@ -126,33 +142,39 @@ class HwAsicDefaultProgrammingTest : public HwTest {
};

TEST_F(HwAsicDefaultProgrammingTest, verifyDefaultProgramming) {
auto golden = loadGoldenData(getAsicType());
auto fetched = fetchData(getAsicType());

// Do a manual comparison in order to emit better error messages.
for (const auto& [key, goldenValue] : golden) {
auto fetchedValue = fetched.find(key);
if (fetchedValue != fetched.end()) {
EXPECT_EQ(fetchedValue->second, goldenValue) << "Diff in key: " << key;
} else {
ADD_FAILURE() << "Missing key in fetched data: " << key << "="
<< goldenValue;
auto setup = [&]() {};

auto verify = [&]() {
auto golden = loadGoldenData(getAsicType());
auto fetched = fetchData(getAsicType());

// Do a manual comparison in order to emit better error messages.
for (const auto& [key, goldenValue] : golden) {
auto fetchedValue = fetched.find(key);
if (fetchedValue != fetched.end()) {
EXPECT_EQ(fetchedValue->second, goldenValue) << "Diff in key: " << key;
} else {
ADD_FAILURE() << "Missing key in fetched data: " << key << "="
<< goldenValue;
}
}
for (const auto& [key, fetchedValue] : fetched) {
EXPECT_TRUE(golden.contains(key))
<< "Extra key in fetched data: " << key << " = " << fetchedValue;
}
}
for (const auto& [key, fetchedValue] : fetched) {
EXPECT_TRUE(golden.contains(key))
<< "Extra key in fetched data: " << key << "=" << fetchedValue;
}

// Dump golden data if requested.
if (!FLAGS_dump_golden_data.empty()) {
std::ofstream ofs(FLAGS_dump_golden_data);
for (const auto& [key, value] : fetched) {
std::string type, var;
folly::split(':', key, type, var);
ofs << type << "," << var << "," << value << "\n";
// Dump golden data if requested.
if (!FLAGS_dump_golden_data.empty()) {
std::ofstream ofs(FLAGS_dump_golden_data);
for (const auto& [key, value] : fetched) {
std::string type, var;
folly::split(':', key, type, var);
ofs << type << "," << var << "," << value << "\n";
}
}
}
};

verifyAcrossWarmBoots(setup, verify);
}

} // namespace facebook::fboss
Loading

0 comments on commit a63997d

Please sign in to comment.