only added a google test
This commit is contained in:
+13
-1
@@ -645,10 +645,22 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms)
|
||||
bool mixCondition = (md->flightModes != 0 || md->swtch);
|
||||
delayval_t mixEnabled = (!(md->flightModes & (1 << mixerCurrentFlightMode)) && getSwitch(md->swtch)) ? DELAY_POS_MARGIN+1 : 0;
|
||||
|
||||
#define MIXER_LINE_DISABLE() (mixCondition = true, mixEnabled = 0)
|
||||
|
||||
if (mixEnabled && md->srcRaw >= MIXSRC_FIRST_TRAINER && md->srcRaw <= MIXSRC_LAST_TRAINER && !ppmInValid) {
|
||||
mixEnabled = 0;
|
||||
MIXER_LINE_DISABLE();
|
||||
}
|
||||
|
||||
#if defined(PCBTARANIS) && defined(LUA_MODEL_SCRIPTS)
|
||||
// disable mixer if Lua script is used as source and script was killed
|
||||
if (mixEnabled && md->srcRaw >= MIXSRC_FIRST_LUA && md->srcRaw <= MIXSRC_LAST_LUA) {
|
||||
div_t qr = div(md->srcRaw-MIXSRC_FIRST_LUA, MAX_SCRIPT_OUTPUTS);
|
||||
if (scriptInternalData[qr.quot].state != SCRIPT_OK) {
|
||||
MIXER_LINE_DISABLE();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//========== VALUE ===============
|
||||
getvalue_t v = 0;
|
||||
if (mode > e_perout_mode_inactive_flight_mode) {
|
||||
|
||||
@@ -0,0 +1,164 @@
|
||||
/*
|
||||
* Authors (alphabetical order)
|
||||
* - Andre Bernet <bernet.andre@gmail.com>
|
||||
* - Andreas Weitl
|
||||
* - Bertrand Songis <bsongis@gmail.com>
|
||||
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
|
||||
* - Cameron Weeks <th9xer@gmail.com>
|
||||
* - Erez Raviv
|
||||
* - Gabriel Birkus
|
||||
* - Jean-Pierre Parisy
|
||||
* - Karl Szmutny
|
||||
* - Michael Blandford
|
||||
* - Michal Hlavinka
|
||||
* - Pat Mackenzie
|
||||
* - Philip Moss
|
||||
* - Rob Thomson
|
||||
* - Romolo Manfredini <romolo.manfredini@gmail.com>
|
||||
* - Thomas Husterer
|
||||
*
|
||||
* opentx is based on code named
|
||||
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
|
||||
* er9x by Erez Raviv: http://code.google.com/p/er9x/,
|
||||
* and the original (and ongoing) project by
|
||||
* Thomas Husterer, th9x: http://code.google.com/p/th9x/
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gtests.h"
|
||||
|
||||
#if !defined(PCBSKY9X)
|
||||
TEST(EEPROM, 100_random_writes)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
RlcFile f;
|
||||
uint8_t buf[1000];
|
||||
uint8_t buf2[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<100; i++) {
|
||||
int size = rand()%800;
|
||||
for(int j=0; j<size; j++) {
|
||||
buf[j] = rand() < (RAND_MAX/10000*i) ? 0 : (j&0xff);
|
||||
}
|
||||
f.writeRlc(5, 5, buf, size, 100);
|
||||
// printf("size=%4d red=%4d\n\n\n", size, f.size());
|
||||
f.openRd(5);
|
||||
uint16_t n = f.readRlc(buf2,size+1);
|
||||
EXPECT_EQ(n, size);
|
||||
EXPECT_EQ(memcmp(buf, buf2, size), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(EEPROM, test2)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
RlcFile f;
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
f.writeRlc(6, 6, buf, 300, 100);
|
||||
|
||||
f.openRd(6);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=f.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 300);
|
||||
}
|
||||
|
||||
TEST(EEPROM, eeCheckImmediately)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
// RlcFile f;
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
theFile.writeRlc(6, 6, buf, 300, false);
|
||||
|
||||
eeCheck(true);
|
||||
|
||||
theFile.openRd(6);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=theFile.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 300);
|
||||
}
|
||||
|
||||
TEST(EEPROM, copy)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
theFile.writeRlc(5, 6, buf, 300, true);
|
||||
|
||||
theFile.copy(6, 5);
|
||||
|
||||
theFile.openRd(6);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=theFile.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 300);
|
||||
}
|
||||
|
||||
TEST(EEPROM, rm)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
theFile.writeRlc(5, 6, buf, 300, true);
|
||||
|
||||
EXPECT_EQ(EFile::exists(5), true);
|
||||
|
||||
EFile::rm(5);
|
||||
|
||||
EXPECT_EQ(EFile::exists(5), false);
|
||||
|
||||
theFile.openRd(5);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=theFile.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 0);
|
||||
}
|
||||
#endif
|
||||
@@ -34,18 +34,7 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <math.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define SWAP_DEFINED
|
||||
#include "opentx.h"
|
||||
|
||||
#define TELEMETRY_RESET() \
|
||||
memclear(&frskyData, sizeof(frskyData)); \
|
||||
frskyData.rssi[0].value = 100
|
||||
|
||||
extern bool checkScreenshot(QString test);
|
||||
#include "gtests.h"
|
||||
|
||||
#if defined(FRSKY) && !defined(FRSKY_SPORT)
|
||||
extern void frskyDProcessPacket(uint8_t *packet);
|
||||
@@ -181,6 +170,7 @@ TEST(FrSkySPORT, frskySetCellVoltage)
|
||||
{
|
||||
uint8_t packet[FRSKY_SPORT_PACKET_SIZE];
|
||||
|
||||
MODEL_RESET();
|
||||
TELEMETRY_RESET();
|
||||
|
||||
// test that simulates 3 cell battery
|
||||
@@ -290,6 +280,7 @@ TEST(FrSkySPORT, frskySetCellVoltageTwoSensors)
|
||||
{
|
||||
uint8_t packet[FRSKY_SPORT_PACKET_SIZE];
|
||||
|
||||
MODEL_RESET();
|
||||
TELEMETRY_RESET();
|
||||
|
||||
//sensor 1: 3 cell battery
|
||||
|
||||
+10
-130
@@ -35,10 +35,17 @@
|
||||
*/
|
||||
|
||||
#include <QtGui/QApplication>
|
||||
#include <gtest/gtest.h>
|
||||
#include "gtests.h"
|
||||
|
||||
#define SWAP_DEFINED
|
||||
#include "opentx.h"
|
||||
int32_t lastAct = 0;
|
||||
uint16_t anaInValues[NUM_STICKS+NUM_POTS] = { 0 };
|
||||
uint16_t anaIn(uint8_t chan)
|
||||
{
|
||||
if (chan < NUM_STICKS+NUM_POTS)
|
||||
return anaInValues[chan];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static char _zchar2stringResult[200];
|
||||
const char * zchar2string(const char * zstring, int size)
|
||||
@@ -50,133 +57,6 @@ const char * zchar2string(const char * zstring, int size)
|
||||
return _zchar2stringResult;
|
||||
}
|
||||
|
||||
#if !defined(PCBSKY9X)
|
||||
TEST(EEPROM, 100_random_writes)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
RlcFile f;
|
||||
uint8_t buf[1000];
|
||||
uint8_t buf2[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<100; i++) {
|
||||
int size = rand()%800;
|
||||
for(int j=0; j<size; j++) {
|
||||
buf[j] = rand() < (RAND_MAX/10000*i) ? 0 : (j&0xff);
|
||||
}
|
||||
f.writeRlc(5, 5, buf, size, 100);
|
||||
// printf("size=%4d red=%4d\n\n\n", size, f.size());
|
||||
f.openRd(5);
|
||||
uint16_t n = f.readRlc(buf2,size+1);
|
||||
EXPECT_EQ(n, size);
|
||||
EXPECT_EQ(memcmp(buf, buf2, size), 0);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(EEPROM, test2)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
RlcFile f;
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
f.writeRlc(6, 6, buf, 300, 100);
|
||||
|
||||
f.openRd(6);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=f.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 300);
|
||||
}
|
||||
|
||||
TEST(EEPROM, eeCheckImmediately)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
// RlcFile f;
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
theFile.writeRlc(6, 6, buf, 300, false);
|
||||
|
||||
eeCheck(true);
|
||||
|
||||
theFile.openRd(6);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=theFile.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 300);
|
||||
}
|
||||
|
||||
TEST(EEPROM, copy)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
theFile.writeRlc(5, 6, buf, 300, true);
|
||||
|
||||
theFile.copy(6, 5);
|
||||
|
||||
theFile.openRd(6);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=theFile.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 300);
|
||||
}
|
||||
|
||||
TEST(EEPROM, rm)
|
||||
{
|
||||
eepromFile = NULL; // in memory
|
||||
|
||||
uint8_t buf[1000];
|
||||
|
||||
EeFsFormat();
|
||||
|
||||
for(int i=0; i<1000; i++) buf[i]='6'+i%4;
|
||||
|
||||
theFile.writeRlc(5, 6, buf, 300, true);
|
||||
|
||||
EXPECT_EQ(EFile::exists(5), true);
|
||||
|
||||
EFile::rm(5);
|
||||
|
||||
EXPECT_EQ(EFile::exists(5), false);
|
||||
|
||||
theFile.openRd(5);
|
||||
uint16_t sz=0;
|
||||
for(int i=0; i<500; i++){
|
||||
uint8_t b;
|
||||
uint16_t n=theFile.readRlc(&b,1);
|
||||
if(n) EXPECT_EQ(b, ('6'+sz%4));
|
||||
sz+=n;
|
||||
}
|
||||
EXPECT_EQ(sz, 0);
|
||||
}
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
QCoreApplication app(argc, argv);
|
||||
|
||||
@@ -0,0 +1,53 @@
|
||||
#ifndef __GTESTS_H
|
||||
#define __GTESTS_H
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <math.h>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#define SWAP_DEFINED
|
||||
#include "opentx.h"
|
||||
|
||||
#define CHANNEL_MAX (1024*256)
|
||||
|
||||
extern int32_t lastAct;
|
||||
extern uint16_t anaInValues[NUM_STICKS+NUM_POTS];
|
||||
|
||||
void doMixerCalculations();
|
||||
|
||||
inline void MODEL_RESET()
|
||||
{
|
||||
memset(&g_model, 0, sizeof(g_model));
|
||||
memset(&anaInValues, 0, sizeof(anaInValues));
|
||||
extern uint8_t s_mixer_first_run_done;
|
||||
s_mixer_first_run_done = false;
|
||||
lastFlightMode = 255;
|
||||
}
|
||||
|
||||
inline void MIXER_RESET()
|
||||
{
|
||||
memset(channelOutputs, 0, sizeof(channelOutputs));
|
||||
memset(chans, 0, sizeof(chans));
|
||||
memset(ex_chans, 0, sizeof(ex_chans));
|
||||
memset(act, 0, sizeof(act));
|
||||
memset(swOn, 0, sizeof(swOn));
|
||||
#if !defined(CPUARM)
|
||||
s_last_switch_used = 0;
|
||||
s_last_switch_value = 0;
|
||||
#endif
|
||||
mixerCurrentFlightMode = lastFlightMode = 0;
|
||||
lastAct = 0;
|
||||
logicalSwitchesReset();
|
||||
}
|
||||
|
||||
inline void TELEMETRY_RESET()
|
||||
{
|
||||
memclear(&frskyData, sizeof(frskyData));
|
||||
frskyData.rssi[0].value = 100;
|
||||
}
|
||||
|
||||
void MIXER_RESET();
|
||||
|
||||
bool checkScreenshot(QString test);
|
||||
|
||||
#endif
|
||||
+40
-63
@@ -34,47 +34,31 @@
|
||||
*
|
||||
*/
|
||||
|
||||
#include <math.h>
|
||||
#include <gtest/gtest.h>
|
||||
#include "gtests.h"
|
||||
|
||||
#define SWAP_DEFINED
|
||||
#include "opentx.h"
|
||||
#define CHECK_NO_MOVEMENT(channel, value, duration) \
|
||||
for (int i=1; i<=(duration); i++) { \
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1); \
|
||||
EXPECT_EQ(chans[(channel)], (value)); \
|
||||
}
|
||||
|
||||
#define CHANNEL_MAX (1024*256)
|
||||
#define CHECK_SLOW_MOVEMENT(channel, sign, duration) \
|
||||
do { \
|
||||
for (int i=1; i<=(duration); i++) { \
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1); \
|
||||
lastAct = lastAct + (sign) * (1<<19)/500; /* 100 on ARM */ \
|
||||
EXPECT_EQ(chans[(channel)], 256 * (lastAct >> 8)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
void doMixerCalculations();
|
||||
|
||||
#define MODEL_RESET() \
|
||||
memset(&g_model, 0, sizeof(g_model)); \
|
||||
memset(&anaInValues, 0, sizeof(anaInValues)); \
|
||||
extern uint8_t s_mixer_first_run_done; \
|
||||
s_mixer_first_run_done = false; \
|
||||
lastFlightMode = 255;
|
||||
|
||||
int32_t lastAct = 0;
|
||||
void MIXER_RESET()
|
||||
{
|
||||
memset(channelOutputs, 0, sizeof(channelOutputs));
|
||||
memset(ex_chans, 0, sizeof(ex_chans));
|
||||
memset(act, 0, sizeof(act));
|
||||
memset(swOn, 0, sizeof(swOn));
|
||||
#if !defined(CPUARM)
|
||||
s_last_switch_used = 0;
|
||||
s_last_switch_value = 0;
|
||||
#endif
|
||||
mixerCurrentFlightMode = lastFlightMode = 0;
|
||||
lastAct = 0;
|
||||
logicalSwitchesReset();
|
||||
}
|
||||
|
||||
uint16_t anaInValues[NUM_STICKS+NUM_POTS] = { 0 };
|
||||
uint16_t anaIn(uint8_t chan)
|
||||
{
|
||||
if (chan < NUM_STICKS+NUM_POTS)
|
||||
return anaInValues[chan];
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
#define CHECK_DELAY(channel, duration) \
|
||||
do { \
|
||||
int32_t value = chans[(channel)]; \
|
||||
for (int i=1; i<=(duration); i++) { \
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1); \
|
||||
EXPECT_EQ(chans[(channel)], value); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
TEST(Trims, throttleTrim)
|
||||
{
|
||||
@@ -643,30 +627,6 @@ TEST(Mixer, RecursiveAddChannelAfterInactivePhase)
|
||||
EXPECT_EQ(chans[1], CHANNEL_MAX);
|
||||
}
|
||||
|
||||
#define CHECK_NO_MOVEMENT(channel, value, duration) \
|
||||
for (int i=1; i<=(duration); i++) { \
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1); \
|
||||
EXPECT_EQ(chans[(channel)], (value)); \
|
||||
}
|
||||
|
||||
#define CHECK_SLOW_MOVEMENT(channel, sign, duration) \
|
||||
do { \
|
||||
for (int i=1; i<=(duration); i++) { \
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1); \
|
||||
lastAct = lastAct + (sign) * (1<<19)/500; /* 100 on ARM */ \
|
||||
EXPECT_EQ(chans[(channel)], 256 * (lastAct >> 8)); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#define CHECK_DELAY(channel, duration) \
|
||||
do { \
|
||||
int32_t value = chans[(channel)]; \
|
||||
for (int i=1; i<=(duration); i++) { \
|
||||
evalFlightModeMixes(e_perout_mode_normal, 1); \
|
||||
EXPECT_EQ(chans[(channel)], value); \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
#if !defined(CPUARM)
|
||||
TEST(Mixer, SlowOnSwitch)
|
||||
{
|
||||
@@ -1009,7 +969,9 @@ TEST(Heli, Mode2Test)
|
||||
EXPECT_EQ(chans[1], CHANNEL_MAX/2);
|
||||
EXPECT_EQ(chans[2], CHANNEL_MAX/2);
|
||||
}
|
||||
#elif defined(HELI)
|
||||
#endif
|
||||
|
||||
#if defined(HELI) && !defined(PCBTARANIS)
|
||||
TEST(Heli, SimpleTest)
|
||||
{
|
||||
MODEL_RESET();
|
||||
@@ -1021,3 +983,18 @@ TEST(Heli, SimpleTest)
|
||||
EXPECT_EQ(chans[1], CHANNEL_MAX/2);
|
||||
}
|
||||
#endif
|
||||
|
||||
TEST(Trainer, UnpluggedTest)
|
||||
{
|
||||
MODEL_RESET();
|
||||
MIXER_RESET();
|
||||
g_model.mixData[0].destCh = 0;
|
||||
g_model.mixData[0].mltpx = MLTPX_ADD;
|
||||
g_model.mixData[0].srcRaw = MIXSRC_FIRST_TRAINER;
|
||||
g_model.mixData[0].weight = 100;
|
||||
g_model.mixData[0].delayUp = DELAY_STEP*5;
|
||||
g_model.mixData[0].delayDown = DELAY_STEP*5;
|
||||
ppmInValid = 0;
|
||||
g_ppmIns[0] = 1024;
|
||||
CHECK_DELAY(0, 5000);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user