test multiple starts (#2888)
* test * pi * typo * private * test short gap too Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
parent
50e25605b8
commit
2a85bfc73f
|
@ -15,7 +15,7 @@ static char* trim(char *str) {
|
|||
return str;
|
||||
}
|
||||
|
||||
void CsvReader::open(const char *fileName, int *columnIndeces) {
|
||||
void CsvReader::open(const char *fileName, const int* columnIndeces) {
|
||||
printf("Reading from %s\r\n", fileName);
|
||||
fp = fopen(fileName, "r");
|
||||
this->columnIndeces = columnIndeces;
|
||||
|
@ -24,8 +24,8 @@ void CsvReader::open(const char *fileName, int *columnIndeces) {
|
|||
|
||||
bool CsvReader::haveMore() {
|
||||
bool result = fgets(buffer, sizeof(buffer), fp) != nullptr;
|
||||
lineIndex++;
|
||||
if (lineIndex == 0) {
|
||||
m_lineIndex++;
|
||||
if (m_lineIndex == 0) {
|
||||
// skip header
|
||||
return haveMore();
|
||||
}
|
||||
|
@ -46,14 +46,16 @@ void CsvReader::processLine(EngineTestHelper *eth) {
|
|||
char *secondToken = trim(strtok(NULL, s));
|
||||
|
||||
newState[columnIndeces[0]] = firstToken[0] == '1';
|
||||
if (secondToken != nullptr && triggerCount > 1) {
|
||||
if (secondToken != nullptr && m_triggerCount > 1) {
|
||||
newState[columnIndeces[1]] = secondToken[0] == '1';
|
||||
}
|
||||
|
||||
double timeStamp = std::stod(timeStampstr);
|
||||
|
||||
timeStamp += m_timestampOffset;
|
||||
|
||||
eth->setTimeAndInvokeEventsUs(1'000'000 * timeStamp);
|
||||
for (int index = 0; index < 2; index++) {
|
||||
for (int index = 0; index < m_triggerCount; index++) {
|
||||
if (currentState[index] == newState[index]) {
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -4,24 +4,35 @@
|
|||
* @date Jun 26, 2021
|
||||
* @author Andrey Belomutskiy, (c) 2012-2021
|
||||
*/
|
||||
|
||||
|
||||
class CsvReader {
|
||||
public:
|
||||
CsvReader(size_t triggerCount) : CsvReader(triggerCount, 0.0) {}
|
||||
CsvReader(size_t triggerCount, double timestampOffset)
|
||||
: m_triggerCount(triggerCount)
|
||||
, m_timestampOffset(timestampOffset)
|
||||
{
|
||||
}
|
||||
|
||||
void open(const char *fileName, const int* columnIndeces);
|
||||
bool haveMore();
|
||||
void processLine(EngineTestHelper *eth);
|
||||
void readLine(EngineTestHelper *eth);
|
||||
|
||||
int lineIndex() const {
|
||||
return m_lineIndex;
|
||||
}
|
||||
|
||||
private:
|
||||
const size_t m_triggerCount;
|
||||
const double m_timestampOffset;
|
||||
|
||||
FILE *fp;
|
||||
char buffer[255];
|
||||
|
||||
bool currentState[2];
|
||||
|
||||
int triggerCount = 2;
|
||||
int m_lineIndex = -1;
|
||||
|
||||
int lineIndex = -1;
|
||||
|
||||
int * columnIndeces;
|
||||
|
||||
void open(const char *fileName, int * columnIndeces);
|
||||
bool haveMore();
|
||||
void processLine(EngineTestHelper *eth);
|
||||
void readLine(EngineTestHelper *eth);
|
||||
const int* columnIndeces;
|
||||
};
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@
|
|||
#include <string>
|
||||
|
||||
TEST(cranking, realCrankingFromFile) {
|
||||
CsvReader reader;
|
||||
CsvReader reader(2);
|
||||
int indeces[2] = {1, 0}; // this logic data file has first trigger channel in second column and second trigger channel in first column
|
||||
reader.open("tests/trigger/recourses/cranking_na_3.csv", indeces);
|
||||
|
||||
|
@ -22,24 +22,24 @@ TEST(cranking, realCrankingFromFile) {
|
|||
reader.readLine(ð);
|
||||
}
|
||||
|
||||
ASSERT_EQ( 42, GET_RPM())<< reader.lineIndex << " @ 0";
|
||||
ASSERT_EQ( 42, GET_RPM())<< reader.lineIndex() << " @ 0";
|
||||
ASSERT_EQ( 0, eth.recentWarnings()->getCount())<< "warningCounter#got synch";
|
||||
|
||||
ASSERT_EQ(0, engine->tdcScheduler[1].momentX);
|
||||
reader.readLine(ð);
|
||||
|
||||
ASSERT_EQ( 213, GET_RPM())<< reader.lineIndex << " @ 1";
|
||||
ASSERT_EQ( 213, GET_RPM())<< reader.lineIndex() << " @ 1";
|
||||
|
||||
for (int i = 0; i < 30; i++) {
|
||||
reader.readLine(ð);
|
||||
}
|
||||
ASSERT_EQ( 223, GET_RPM())<< reader.lineIndex;
|
||||
ASSERT_EQ( 223, GET_RPM())<< reader.lineIndex();
|
||||
|
||||
|
||||
for (int i = 0; i < 30; i++) {
|
||||
reader.readLine(ð);
|
||||
}
|
||||
ASSERT_EQ( 297, GET_RPM())<< reader.lineIndex << " @ 2";
|
||||
ASSERT_EQ( 297, GET_RPM())<< reader.lineIndex() << " @ 2";
|
||||
|
||||
while (reader.haveMore()) {
|
||||
reader.processLine(ð);
|
||||
|
@ -48,5 +48,5 @@ TEST(cranking, realCrankingFromFile) {
|
|||
// TODO: we should avoid this warning
|
||||
// See https://github.com/rusefi/rusefi/issues/2889
|
||||
ASSERT_EQ(1, eth.recentWarnings()->getCount())<< "warningCounter#realCranking";
|
||||
ASSERT_EQ(560, GET_RPM())<< reader.lineIndex;
|
||||
ASSERT_EQ(560, GET_RPM()) << reader.lineIndex();
|
||||
}
|
||||
|
|
|
@ -10,10 +10,8 @@
|
|||
#include "logicdata_csv_reader.h"
|
||||
|
||||
TEST(crankingVW, vwRealCrankingFromFile) {
|
||||
CsvReader reader;
|
||||
reader.triggerCount = 1;
|
||||
CsvReader reader(1);
|
||||
int indeces[1] = {0};
|
||||
// setVerboseTrigger(true);
|
||||
|
||||
reader.open("tests/trigger/recourses/nick_1.csv", indeces);
|
||||
WITH_ENGINE_TEST_HELPER (VW_ABA);
|
||||
|
@ -24,6 +22,56 @@ TEST(crankingVW, vwRealCrankingFromFile) {
|
|||
}
|
||||
|
||||
ASSERT_EQ( 0, eth.recentWarnings()->getCount())<< "warningCounter#vwRealCranking";
|
||||
ASSERT_EQ( 1687, GET_RPM())<< reader.lineIndex;
|
||||
|
||||
ASSERT_EQ( 1687, GET_RPM())<< reader.lineIndex();
|
||||
}
|
||||
|
||||
TEST(crankingVW, crankingTwiceWithGap) {
|
||||
WITH_ENGINE_TEST_HELPER (VW_ABA);
|
||||
eth.setTriggerType(TT_60_2_VW PASS_ENGINE_PARAMETER_SUFFIX);
|
||||
|
||||
{
|
||||
CsvReader reader(1);
|
||||
int indeces[1] = {0};
|
||||
|
||||
reader.open("tests/trigger/recourses/nick_1.csv", indeces);
|
||||
|
||||
while (reader.haveMore()) {
|
||||
reader.processLine(ð);
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, eth.recentWarnings()->getCount())<< "warningCounter#vwRealCranking";
|
||||
ASSERT_EQ(1687, GET_RPM())<< reader.lineIndex();
|
||||
}
|
||||
|
||||
auto now = getTimeNowNt();
|
||||
|
||||
{
|
||||
// Offset by a short time offset, 10 seconds
|
||||
CsvReader reader(1, 10);
|
||||
int indeces[1] = {0};
|
||||
|
||||
reader.open("tests/trigger/recourses/nick_1.csv", indeces);
|
||||
|
||||
while (reader.haveMore()) {
|
||||
reader.processLine(ð);
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, eth.recentWarnings()->getCount());
|
||||
ASSERT_EQ(1687, GET_RPM())<< reader.lineIndex();
|
||||
}
|
||||
|
||||
{
|
||||
// Offset by long time offset, 5m14.15s
|
||||
CsvReader reader(1, 314.159);
|
||||
int indeces[1] = {0};
|
||||
|
||||
reader.open("tests/trigger/recourses/nick_1.csv", indeces);
|
||||
|
||||
while (reader.haveMore()) {
|
||||
reader.processLine(ð);
|
||||
}
|
||||
|
||||
ASSERT_EQ(0, eth.recentWarnings()->getCount());
|
||||
ASSERT_EQ(1688, GET_RPM())<< reader.lineIndex();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue