fwt_software/tests/test_hardwarechecks.cpp

90 lines
3.4 KiB
C++

#include "doctest/doctest.h"
#include "fgc/HardwareChecks.h"
using namespace fgc;
TEST_CASE("usbfs_memory_mb is checked against the value frames actually need") {
CHECK(checkUsbfsMemory("1000", 1000).pass);
CHECK(checkUsbfsMemory("2048\n", 1000).pass);
// The reboot default. This is the exact state that was found on the
// LattePanda and stalled frame delivery.
auto low = checkUsbfsMemory("16", 1000);
CHECK_FALSE(low.pass);
CHECK(low.detail.find("kernel cmdline") != std::string::npos);
}
TEST_CASE("an unreadable usbfs node fails rather than passing by default") {
// A check that did not happen must not report PASS - that is how a silent
// precondition regression survives a green test run.
CHECK_FALSE(checkUsbfsMemory("", 1000).pass);
CHECK_FALSE(checkUsbfsMemory("not-a-number", 1000).pass);
}
TEST_CASE("USB3 LPM must be off, and anything unreadable is a failure") {
CHECK(checkUsb3Lpm("0").pass);
CHECK(checkUsb3Lpm(" 0\n").pass);
auto on = checkUsb3Lpm("1");
CHECK_FALSE(on.pass);
CHECK(on.detail.find("re-enumerate") != std::string::npos);
CHECK_FALSE(checkUsb3Lpm("").pass);
}
TEST_CASE("an SMBus-only adapter is caught before it looks like a dead sensor") {
CHECK(checkI2cFunctionality(kI2cFuncI2c).pass);
CHECK(checkI2cFunctionality(kI2cFuncI2c | 0xF0).pass);
auto smbus = checkI2cFunctionality(0xF0); // SMBus bits only
CHECK_FALSE(smbus.pass);
CHECK(smbus.detail.find("i2cdetect -F") != std::string::npos);
}
TEST_CASE("an undeclared axis has no drivetrain skew to find") {
DrivetrainExpectation want; // declared == false
DrivetrainEcho got; // all -1
auto r = checkDrivetrainAdopted("yaw", want, got);
CHECK_FALSE(r.ran);
CHECK(r.pass);
}
TEST_CASE("a firmware that cannot echo the current is a version skew, not zero current") {
DrivetrainExpectation want{true, 80, 31, 7};
DrivetrainEcho got; // all absent
auto r = checkDrivetrainAdopted("yaw", want, got);
CHECK(r.ran);
CHECK_FALSE(r.pass);
CHECK(r.detail.find("predates") != std::string::npos);
CHECK(r.detail.find("Re-flash") != std::string::npos);
}
TEST_CASE("the IOTA tower's declared current, adopted") {
DrivetrainExpectation want{true, 80, 31, 7}; // 756 mA run, 189 mA homing at 75 mOhm
DrivetrainEcho got{80, 31, 7};
auto r = checkDrivetrainAdopted("yaw", want, got);
CHECK(r.ran);
CHECK(r.pass);
}
TEST_CASE("a homing current that did not land is named as the damaging case") {
// The exact failure that sheared the endstop: run current correct, homing
// current still at the firmware default.
DrivetrainExpectation want{true, 80, 31, 7};
DrivetrainEcho got{80, 31, 31};
auto r = checkDrivetrainAdopted("yaw", want, got);
CHECK_FALSE(r.pass);
CHECK(r.detail.find("homing IRUN wanted 7, firmware has 31") != std::string::npos);
CHECK(r.detail.find("endstop") != std::string::npos);
}
TEST_CASE("every mismatched field is reported, not just the first") {
DrivetrainExpectation want{true, 80, 31, 7};
DrivetrainEcho got{255, 16, 31};
auto r = checkDrivetrainAdopted("yaw", want, got);
CHECK_FALSE(r.pass);
CHECK(r.detail.find("GLOBALSCALER") != std::string::npos);
CHECK(r.detail.find("IRUN wanted 31") != std::string::npos);
CHECK(r.detail.find("homing IRUN") != std::string::npos);
}