rusefi-1/unit_tests/main.cpp

190 lines
3.4 KiB
C++
Raw Normal View History

2014-08-29 07:52:33 -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"
2014-10-03 12:05:03 -07:00
#include "test_logic_expression.h"
#include "engine_configuration.h"
2014-08-29 07:52:33 -07:00
2015-01-01 11:03:23 -08:00
#include "test_idle_controller.h"
2015-01-12 16:05:46 -08:00
#include "test_signal_executor.h"
2014-08-29 07:52:33 -07:00
extern "C"
{
#include "map_resize.h"
#include "test_event_registry.h"
#include "test_util.h"
}
#include "engine_math.h"
#include "test_engine_math.h"
#include "test_trigger_decoder.h"
static engine_configuration_s ec;
engine_configuration_s *engineConfiguration = &ec;
int timeNow = 0;
uint64_t getTimeNowUs(void) {
return timeNow;
}
2014-09-13 06:04:55 -07:00
uint64_t getTimeNowNt(void) {
return getTimeNowUs() * US_TO_NT_MULTIPLIER;
}
2014-11-29 21:03:06 -08:00
void assertEqualsM2(const char *msg, float expected, float actual, float EPS) {
2014-08-29 07:52:33 -07:00
if (cisnan(actual) && !cisnan(expected)) {
2014-10-05 07:03:00 -07:00
printf("Assert failed: %s %.4f while expected %.4f\r\n", msg, actual, expected);
2014-08-29 07:52:33 -07:00
exit(-1);
}
float delta = absF(actual - expected);
2014-11-29 21:03:06 -08:00
if (delta > EPS) {
2014-08-29 07:52:33 -07:00
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);
}
2014-11-29 21:03:06 -08:00
void assertEqualsM(const char *msg, float expected, float actual) {
assertEqualsM2(msg, expected, actual, 0.0001);
}
2014-08-29 07:52:33 -07:00
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);
}
}
2014-11-11 13:05:09 -08:00
int getRevolutionCounter(void) {
return 0;
}
2014-08-29 07:52:33 -07:00
int main(void) {
2014-10-03 12:05:03 -07:00
testLogicExpressions();
2014-08-29 07:52:33 -07:00
testOverflow64Counter();
testInterpolate3d();
testFindIndex();
testInterpolate2d();
testGpsParser();
2014-09-25 22:02:43 -07:00
testMisc();
2014-08-29 07:52:33 -07:00
testFuelMap();
testEngineMath();
2015-01-30 20:09:23 -08:00
testIgnitionPlanning();
2014-08-29 07:52:33 -07:00
testEventRegistry();
testSensors();
testCyclicBuffer();
testCrc();
testSignalExecutor();
testHistogram();
testTriggerDecoder();
testMalfunctionCentral();
testConsoleLogic();
testAngleResolver();
testPinHelper();
testSetTableValue();
testAccelEnrichment();
testSpeedDensity();
testFLStack();
2015-01-01 11:03:23 -08:00
testIdleController();
2015-01-06 20:03:36 -08:00
testMenuTree();
2015-02-11 18:08:16 -08:00
testMafLookup();
2015-02-13 18:04:20 -08:00
testMafFuelMath();
2015-01-06 20:03:36 -08:00
2014-08-29 07:52:33 -07:00
// resizeMap();
2015-02-13 18:04:20 -08:00
printf("Success 20150213\r\n");
2014-08-29 07:52:33 -07:00
return EXIT_SUCCESS;
}
int warning(obd_code_e code, const char *fmt, ...) {
printf("Warning: %s\r\n", fmt);
}
2014-11-24 09:03:09 -08:00
bool hasFirmwareErrorFlag = false;
2014-08-29 07:52:33 -07:00
void firmwareError(const char *fmt, ...) {
printf(fmt);
exit(-1);
}
void print(const char *format, ...) {
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
}
void fatal3(char *msg, char *file, int line) {
printf(msg);
exit(-1);
}
int warning(const char *fmt, ...) {
printf(fmt);
exit(-1);
}
2014-11-11 13:05:09 -08:00
bool isCranking(void) {
2014-08-29 07:52:33 -07:00
return 0;
}
2015-01-01 16:03:31 -08:00
2015-01-13 19:04:02 -08:00
void initLogging(LoggingWithStorage *logging, const char *name) {
2015-01-01 16:03:31 -08:00
}
void scheduleMsg(Logging *logging, const char *fmt, ...) {
}