rusefi-1/unit_tests/main.cpp

222 lines
4.4 KiB
C++
Raw Normal View History

2015-07-10 06:01:56 -07:00
/**
* @file main.cpp
* @file First step towards unit-testing rusEfi algorithms
*
* @author Andrey Belomutskiy (c) 2012-2014
*/
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdarg.h>
#include "main.h"
#include "error_handling.h"
#include "test_accel_enrichment.h"
#include "test_interpolation_3d.h"
#include "test_find_index.h"
#include "test_sensors.h"
#include "test_speed_density.h"
#include "test_fuel_map.h"
#include "fuel_math.h"
#include "test_logic_expression.h"
#include "engine_configuration.h"
#include "test_idle_controller.h"
#include "test_signal_executor.h"
#include "trigger_central.h"
#include "test_util.h"
#include "map_resize.h"
#include "test_event_registry.h"
#include "engine_math.h"
#include "test_engine_math.h"
#include "test_trigger_decoder.h"
2016-08-29 20:02:15 -07:00
typedef int32_t msg_t;
#include "chstreams.h"
#include "memstreams.h"
2015-07-10 06:01:56 -07:00
static engine_configuration_s ec;
engine_configuration_s *engineConfiguration = &ec;
int timeNow = 0;
efitimeus_t getTimeNowUs(void) {
return timeNow;
}
efitick_t getTimeNowNt(void) {
return getTimeNowUs() * US_TO_NT_MULTIPLIER;
}
2016-09-03 09:03:10 -07:00
void assertEqualsM3(const char *prefix, const char *message, float expected, float actual, float EPS) {
char msg[100];
strcpy(msg, prefix);
strcat(msg, message);
2015-07-10 06:01:56 -07:00
if (cisnan(actual) && !cisnan(expected)) {
printf("Assert failed: %s %.4f while expected %.4f\r\n", msg, actual, expected);
exit(-1);
}
float delta = absF(actual - expected);
if (delta > EPS) {
printf("delta: %.7f\r\n", delta);
printf("Unexpected: %s %.4f while expected %.4f\r\n", msg, actual, expected);
exit(-1);
}
printf("Validated %s: %f\r\n", msg, expected);
}
2016-09-03 09:03:10 -07:00
void assertEqualsM2(const char *msg, float expected, float actual, float eps) {
assertEqualsM3("", msg, expected, actual, eps);
}
void assertEqualsM4(const char *prefix, const char *msg, float expected, float actual) {
assertEqualsM3(prefix, msg, expected, actual, 0.00001);
}
2016-01-26 10:01:40 -08:00
void assertEqualsLM(const char *msg, long expected, long actual) {
2016-01-25 20:01:36 -08:00
if (expected != actual) {
printf("Assert failed: %s %d while expected %d\r\n", msg, actual, expected);
exit(-1);
}
}
2015-07-10 06:01:56 -07:00
void assertEqualsM(const char *msg, float expected, float actual) {
assertEqualsM2(msg, expected, actual, 0.0001);
}
void assertEquals(float expected, float actual) {
assertEqualsM("", expected, actual);
}
void assertTrueM(const char *msg, float actual) {
assertEqualsM(msg, TRUE, actual);
}
void assertTrue(float actual) {
assertTrueM("", actual);
}
void assertFalseM(const char *msg, float actual) {
assertEqualsM(msg, FALSE, actual);
}
void assertFalse(float actual) {
assertFalseM("", actual);
}
void chDbgAssert(int c, char *msg, void *arg) {
if (!c) {
printf("assert failed: %s\r\n", msg);
exit(-1);
}
}
2016-09-04 22:03:25 -07:00
extern int revolutionCounterSinceBootForUnitTest;
2015-07-10 06:01:56 -07:00
int getRevolutionCounter(void) {
2016-09-04 22:03:25 -07:00
return revolutionCounterSinceBootForUnitTest;
2015-07-10 06:01:56 -07:00
}
int main(void) {
2016-11-07 19:02:21 -08:00
testMissedSpark299();
2016-10-31 18:02:36 -07:00
testSparkReverseOrderBug319();
2016-09-03 10:02:55 -07:00
testFuelSchedulerBug299smallAndLarge();
2016-09-03 11:01:47 -07:00
testFuelSchedulerBug299smallAndMedium();
2015-07-10 06:01:56 -07:00
testLogicExpressions();
testOverflow64Counter();
testInterpolate3d();
testFindIndex();
testInterpolate2d();
testGpsParser();
testMisc();
testFuelMap();
testEngineMath();
testIgnitionPlanning();
testEventRegistry();
testSensors();
testCyclicBuffer();
testCrc();
testSignalExecutor();
testHistogram();
testMalfunctionCentral();
testConsoleLogic();
testAngleResolver();
testPinHelper();
testSetTableValue();
testAccelEnrichment();
testSpeedDensity();
testFLStack();
testIdleController();
testMenuTree();
testMafLookup();
2015-12-24 11:02:03 -08:00
testIgnitionMapGenerator();
2015-07-10 06:01:56 -07:00
testMafFuelMath();
testPidController();
testTriggerDecoder();
// resizeMap();
2016-10-31 18:02:36 -07:00
printf("Success 20161031\r\n");
2015-07-10 06:01:56 -07:00
printAllTriggers();
return EXIT_SUCCESS;
}
2016-11-07 19:02:21 -08:00
int warningCounter = 0;
2016-10-31 18:02:36 -07:00
bool warning(obd_code_e code, const char *format, ...) {
2016-11-07 19:02:21 -08:00
warningCounter++;
2016-10-31 18:02:36 -07:00
printf("Warning: ");
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
printf("\r\n");
2015-07-10 06:01:56 -07:00
}
bool hasFirmwareErrorFlag = false;
2016-10-10 11:02:17 -07:00
void firmwareError(obd_code_e code, const char *fmt, ...) {
2015-07-10 06:01:56 -07:00
printf(fmt);
exit(-1);
}
void print(const char *format, ...) {
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
}
bool isCranking(void) {
return 0;
}
void initLogging(LoggingWithStorage *logging, const char *name) {
}
2016-10-31 18:02:36 -07:00
void scheduleMsg(Logging *logging, const char *format, ...) {
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
printf("\r\n");
2015-07-10 06:01:56 -07:00
}