diff --git a/firmware/console/binary/tooth_logger.cpp b/firmware/console/binary/tooth_logger.cpp index 0f9448fd64..1cd11a1993 100644 --- a/firmware/console/binary/tooth_logger.cpp +++ b/firmware/console/binary/tooth_logger.cpp @@ -243,6 +243,22 @@ static void SetNextCompositeEntry(efitick_t timestamp) { #endif // EFI_UNIT_TEST 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"); // bail if we aren't enabled if (!ToothLoggerEnabled) { diff --git a/unit_tests/.gitignore b/unit_tests/.gitignore index 999cf54ca0..02b79c147b 100644 --- a/unit_tests/.gitignore +++ b/unit_tests/.gitignore @@ -4,4 +4,5 @@ gcov_working_area triggers unittest*.logicdata unittest*.events.txt +unittest*.json /.idea/ diff --git a/unit_tests/test-framework/engine_test_helper.cpp b/unit_tests/test-framework/engine_test_helper.cpp index 46c5ceccae..b8d8b8f497 100644 --- a/unit_tests/test-framework/engine_test_helper.cpp +++ b/unit_tests/test-framework/engine_test_helper.cpp @@ -73,6 +73,8 @@ int EngineTestHelper::getWarningCounter() { return unitTestWarningCodeState.warningCounter; } + FILE *jsonTrace; + EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callback_t configurationCallback, const std::unordered_map& sensorValues) : EngineTestHelperBase(&engine, &persistentConfig.engineConfiguration, &persistentConfig) { @@ -80,6 +82,24 @@ EngineTestHelper::EngineTestHelper(engine_type_e engineType, configuration_callb 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::Iat, 30); @@ -181,6 +201,12 @@ EngineTestHelper::~EngineTestHelper() { writeEvents2(filePath.str().c_str()); } + if (jsonTrace != nullptr) { + fprintf(jsonTrace, "]}\n"); + fclose(jsonTrace); + jsonTrace = nullptr; + } + // Cleanup enginePins.reset(); enginePins.unregisterPins();