mirror of https://github.com/FOME-Tech/fome-fw.git
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:
parent
463b0a2d44
commit
a1f69c853c
|
@ -1109,13 +1109,19 @@ void setDateTime(const char * const isoDateTime) {
|
||||||
#if EFI_RTC
|
#if EFI_RTC
|
||||||
if (strlen(isoDateTime) >= 19 && isoDateTime[10] == 'T') {
|
if (strlen(isoDateTime) >= 19 && isoDateTime[10] == 'T') {
|
||||||
efidatetime_t dateTime;
|
efidatetime_t dateTime;
|
||||||
int scanned = sscanf(isoDateTime, "%4lu", &dateTime.year);
|
dateTime.year = atoi(isoDateTime);
|
||||||
scanned += sscanf(isoDateTime + 5, "%2hhu", &dateTime.month);
|
dateTime.month = atoi(isoDateTime + 5);
|
||||||
scanned += sscanf(isoDateTime + 8, "%2hhu", &dateTime.day);
|
dateTime.day = atoi(isoDateTime + 8);
|
||||||
scanned += sscanf(isoDateTime + 11, "%2hhu", &dateTime.hour);
|
dateTime.hour = atoi(isoDateTime + 11);
|
||||||
scanned += sscanf(isoDateTime + 14, "%2hhu", &dateTime.minute);
|
dateTime.minute = atoi(isoDateTime + 14);
|
||||||
scanned += sscanf(isoDateTime + 17, "%2hhu", &dateTime.second);
|
dateTime.second = atoi(isoDateTime + 17);
|
||||||
if (scanned == 6) { // 6 fields to properly scan
|
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);
|
setRtcDateTime(&dateTime);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -82,7 +82,6 @@ int indexOf(const char *string, char ch) {
|
||||||
|
|
||||||
// string to integer
|
// string to integer
|
||||||
int atoi(const char *string) {
|
int atoi(const char *string) {
|
||||||
// todo: use stdlib '#include <stdlib.h> '
|
|
||||||
int len = strlen(string);
|
int len = strlen(string);
|
||||||
if (len == 0) {
|
if (len == 0) {
|
||||||
return -ATOI_ERROR_CODE;
|
return -ATOI_ERROR_CODE;
|
||||||
|
@ -95,8 +94,12 @@ int atoi(const char *string) {
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
char ch = string[i];
|
char ch = string[i];
|
||||||
if (ch < '0' || ch > '9') {
|
if (ch < '0' || ch > '9') {
|
||||||
|
if (i > 0) {
|
||||||
|
break;
|
||||||
|
} else {
|
||||||
return ATOI_ERROR_CODE;
|
return ATOI_ERROR_CODE;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
int c = ch - '0';
|
int c = ch - '0';
|
||||||
result = result * 10 + c;
|
result = result * 10 + c;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package com.rusefi;
|
||||||
|
|
||||||
import com.rusefi.functional_tests.EcuTestHelper;
|
import com.rusefi.functional_tests.EcuTestHelper;
|
||||||
import com.rusefi.waves.EngineChart;
|
import com.rusefi.waves.EngineChart;
|
||||||
import org.junit.Before;
|
import org.junit.*;
|
||||||
|
|
||||||
public class RusefiTestBase {
|
public class RusefiTestBase {
|
||||||
protected EcuTestHelper ecu;
|
protected EcuTestHelper ecu;
|
||||||
|
@ -17,6 +17,11 @@ public class RusefiTestBase {
|
||||||
ecu = EcuTestHelper.createInstance(needsHardwareTriggerInput());
|
ecu = EcuTestHelper.createInstance(needsHardwareTriggerInput());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void checkStackUsage() {
|
||||||
|
ecu.sendCommand("threadsinfo");
|
||||||
|
}
|
||||||
|
|
||||||
protected EngineChart nextChart() {
|
protected EngineChart nextChart() {
|
||||||
return TestingUtils.nextChart(ecu.commandQueue);
|
return TestingUtils.nextChart(ecu.commandQueue);
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.rusefi.core.SensorCentral;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static com.devexperts.util.TimeUtil.SECOND;
|
import static com.devexperts.util.TimeUtil.SECOND;
|
||||||
|
import static com.rusefi.IoUtil.sleepSeconds;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
@ -37,4 +38,13 @@ public class MiscTest extends RusefiTestBase {
|
||||||
// wow sometimes my utility closet is pretty warm?
|
// wow sometimes my utility closet is pretty warm?
|
||||||
assertTrue(message, mcuTemp < 52);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue