unit_tests "logic analyzer" style output #6403

only:uaefi
This commit is contained in:
rusefillc 2024-12-25 21:28:00 -05:00
parent a86976b6f1
commit 3a5ea90417
3 changed files with 43 additions and 0 deletions

View File

@ -243,6 +243,22 @@ static void SetNextCompositeEntry(efitick_t timestamp) {
#endif // EFI_UNIT_TEST #endif // EFI_UNIT_TEST
void LogTriggerTooth(trigger_event_e tooth, efitick_t timestamp) { void LogTriggerTooth(trigger_event_e tooth, efitick_t timestamp) {
#if EFI_UNIT_TEST
extern FILE *jsonTrace;
//static efitick_t risingTimestamp = 0;
if (jsonTrace != nullptr) {
if (tooth == SHAFT_PRIMARY_RISING) {
fprintf(jsonTrace, ",\n");
fprintf(jsonTrace, "{\"name\":\"trg0\",\"ph\":\"B\",\"tid\":0,\"pid\":54,\"ts\":%f}", timestamp / 1000.0);
} else if (tooth == SHAFT_PRIMARY_FALLING) {
fprintf(jsonTrace, ",\n");
fprintf(jsonTrace, "{\"name\":\"trg0\",\"ph\":\"E\",\"tid\":0,\"pid\":54,\"ts\":%f}", timestamp / 1000.0);
}
}
#endif // EFI_UNIT_TEST
efiAssertVoid(ObdCode::CUSTOM_ERR_6650, hasLotsOfRemainingStack(), "l-t-t"); efiAssertVoid(ObdCode::CUSTOM_ERR_6650, hasLotsOfRemainingStack(), "l-t-t");
// bail if we aren't enabled // bail if we aren't enabled
if (!ToothLoggerEnabled) { if (!ToothLoggerEnabled) {

View File

@ -4,4 +4,5 @@ gcov_working_area
triggers triggers
unittest*.logicdata unittest*.logicdata
unittest*.events.txt unittest*.events.txt
unittest*.json
/.idea/ /.idea/

View File

@ -73,6 +73,8 @@ int EngineTestHelper::getWarningCounter() {
return unitTestWarningCodeState.warningCounter; return unitTestWarningCodeState.warningCounter;
} }
FILE *jsonTrace;
EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t configurationCallback, const std::unordered_map<SensorType, float>& sensorValues) : EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t configurationCallback, const std::unordered_map<SensorType, float>& sensorValues) :
EngineTestHelperBase(&engine, &persistentConfig.engineConfiguration, &persistentConfig) EngineTestHelperBase(&engine, &persistentConfig.engineConfiguration, &persistentConfig)
{ {
@ -80,6 +82,24 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callb
memset(&pinRepository, 0, sizeof(pinRepository)); memset(&pinRepository, 0, sizeof(pinRepository));
auto testInfo = ::testing::UnitTest::GetInstance()->current_test_info();
extern bool hasInitGtest;
if (hasInitGtest) {
std::stringstream filePath;
filePath << "unittest_" << testInfo->test_case_name() << "_" << testInfo->name() << "_trace.json";
const char *fileName = filePath.str().c_str();
// jsonTrace = fopen(fileName, "wb");
if (jsonTrace == nullptr) {
// criticalError("Error creating file [%s]", fileName);
} else {
// fprintf(jsonTrace, "{\"traceEvents\": [\n");
// fprintf(jsonTrace, "{\"name\":\"process_name\",\"ph\":\"M\",\"pid\":-16,\"tid\":0,\"args\":{\"name\":\"Main\"}}\n");
}
} else {
// todo: document why this branch even exists
jsonTrace = nullptr;
}
Sensor::setMockValue(SensorType::Clt, 70); Sensor::setMockValue(SensorType::Clt, 70);
Sensor::setMockValue(SensorType::Iat, 30); Sensor::setMockValue(SensorType::Iat, 30);
@ -181,6 +201,12 @@ EngineTestHelper::~EngineTestHelper() {
writeEvents2(filePath.str().c_str()); writeEvents2(filePath.str().c_str());
} }
if (jsonTrace != nullptr) {
fprintf(jsonTrace, "]}\n");
fclose(jsonTrace);
jsonTrace = nullptr;
}
// Cleanup // Cleanup
enginePins.reset(); enginePins.reset();
enginePins.unregisterPins(); enginePins.unregisterPins();