Strictly validate stack use in hardware CI (#4880)

* firmware error in case of low stack only on HW CI

* send date

* I don't java good

* I still don't java good

* send the right command

* I guess we can check it on every single test?

* javaaaaaa

* atoi breaks on later non-digit

* avoid sscanf use (for atoi)

to avoid bloating the stack

* less churn

* less churn

Co-authored-by: Nathan Schulte <nmschulte@desmas.net>
This commit is contained in:
Matthew Kennedy 2022-12-08 10:20:55 -08:00 committed by GitHub
parent 463b0a2d44
commit a1f69c853c
4 changed files with 34 additions and 10 deletions

View File

@ -1109,13 +1109,19 @@ void setDateTime(const char * const isoDateTime) {
#if EFI_RTC
if (strlen(isoDateTime) >= 19 && isoDateTime[10] == 'T') {
efidatetime_t dateTime;
int scanned = sscanf(isoDateTime, "%4lu", &dateTime.year);
scanned += sscanf(isoDateTime + 5, "%2hhu", &dateTime.month);
scanned += sscanf(isoDateTime + 8, "%2hhu", &dateTime.day);
scanned += sscanf(isoDateTime + 11, "%2hhu", &dateTime.hour);
scanned += sscanf(isoDateTime + 14, "%2hhu", &dateTime.minute);
scanned += sscanf(isoDateTime + 17, "%2hhu", &dateTime.second);
if (scanned == 6) { // 6 fields to properly scan
dateTime.year = atoi(isoDateTime);
dateTime.month = atoi(isoDateTime + 5);
dateTime.day = atoi(isoDateTime + 8);
dateTime.hour = atoi(isoDateTime + 11);
dateTime.minute = atoi(isoDateTime + 14);
dateTime.second = atoi(isoDateTime + 17);
if (dateTime.year != ATOI_ERROR_CODE &&
dateTime.month >= 1 && dateTime.month <= 12 &&
dateTime.day >= 1 && dateTime.day <= 31 &&
dateTime.hour <= 23 &&
dateTime.minute <= 59 &&
dateTime.second <= 59) {
// doesn't concern about leap years or seconds; ChibiOS doesn't support (added) leap seconds anyway
setRtcDateTime(&dateTime);
return;
}

View File

@ -82,7 +82,6 @@ int indexOf(const char *string, char ch) {
// string to integer
int atoi(const char *string) {
// todo: use stdlib '#include <stdlib.h> '
int len = strlen(string);
if (len == 0) {
return -ATOI_ERROR_CODE;
@ -95,8 +94,12 @@ int atoi(const char *string) {
for (int i = 0; i < len; i++) {
char ch = string[i];
if (ch < '0' || ch > '9') {
if (i > 0) {
break;
} else {
return ATOI_ERROR_CODE;
}
}
int c = ch - '0';
result = result * 10 + c;
}

View File

@ -2,7 +2,7 @@ package com.rusefi;
import com.rusefi.functional_tests.EcuTestHelper;
import com.rusefi.waves.EngineChart;
import org.junit.Before;
import org.junit.*;
public class RusefiTestBase {
protected EcuTestHelper ecu;
@ -17,6 +17,11 @@ public class RusefiTestBase {
ecu = EcuTestHelper.createInstance(needsHardwareTriggerInput());
}
@After
public void checkStackUsage() {
ecu.sendCommand("threadsinfo");
}
protected EngineChart nextChart() {
return TestingUtils.nextChart(ecu.commandQueue);
}

View File

@ -7,6 +7,7 @@ import com.rusefi.core.SensorCentral;
import org.junit.Test;
import static com.devexperts.util.TimeUtil.SECOND;
import static com.rusefi.IoUtil.sleepSeconds;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
@ -37,4 +38,13 @@ public class MiscTest extends RusefiTestBase {
// wow sometimes my utility closet is pretty warm?
assertTrue(message, mcuTemp < 52);
}
@Test
public void testSetDate() {
// set some random time
ecu.sendCommand("set date 2022-12-07T11:14:22");
// If things are going to crash, let it happen in this test
sleepSeconds(5);
}
}