mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-16 21:05:35 +03:00
Added CMS test code
This commit is contained in:
parent
576ad19914
commit
2c9d71aeae
5 changed files with 260 additions and 7 deletions
|
@ -32,8 +32,9 @@
|
||||||
|
|
||||||
#ifdef CMS
|
#ifdef CMS
|
||||||
|
|
||||||
#include "build/version.h"
|
#include "build/build_config.h"
|
||||||
#include "build/debug.h"
|
#include "build/debug.h"
|
||||||
|
#include "build/version.h"
|
||||||
|
|
||||||
#include "cms/cms.h"
|
#include "cms/cms.h"
|
||||||
#include "cms/cms_menu_builtin.h"
|
#include "cms/cms_menu_builtin.h"
|
||||||
|
@ -124,7 +125,7 @@ static displayPort_t *cmsDisplayPortSelectNext(void)
|
||||||
|
|
||||||
static bool cmsInMenu = false;
|
static bool cmsInMenu = false;
|
||||||
|
|
||||||
static CMS_Menu *currentMenu; // Points to top entry of the current page
|
STATIC_UNIT_TESTED CMS_Menu *currentMenu; // Points to top entry of the current page
|
||||||
|
|
||||||
// XXX Does menu backing support backing into second page???
|
// XXX Does menu backing support backing into second page???
|
||||||
|
|
||||||
|
@ -481,7 +482,7 @@ long cmsMenuChange(displayPort_t *pDisplay, void *ptr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static long cmsMenuBack(displayPort_t *pDisplay)
|
STATIC_UNIT_TESTED long cmsMenuBack(displayPort_t *pDisplay)
|
||||||
{
|
{
|
||||||
// Let onExit function decide whether to allow exit or not.
|
// Let onExit function decide whether to allow exit or not.
|
||||||
|
|
||||||
|
@ -512,7 +513,7 @@ static long cmsMenuBack(displayPort_t *pDisplay)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cmsMenuOpen(void)
|
STATIC_UNIT_TESTED void cmsMenuOpen(void)
|
||||||
{
|
{
|
||||||
if (!cmsInMenu) {
|
if (!cmsInMenu) {
|
||||||
// New open
|
// New open
|
||||||
|
@ -587,7 +588,7 @@ long cmsMenuExit(displayPort_t *pDisplay, void *ptr)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
STATIC_UNIT_TESTED uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key)
|
||||||
{
|
{
|
||||||
uint16_t res = BUTTON_TIME;
|
uint16_t res = BUTTON_TIME;
|
||||||
OSD_Entry *p;
|
OSD_Entry *p;
|
||||||
|
@ -845,6 +846,8 @@ void cmsHandler(uint32_t currentTime)
|
||||||
// Can it be done with the current main()?
|
// Can it be done with the current main()?
|
||||||
void cmsInit(void)
|
void cmsInit(void)
|
||||||
{
|
{
|
||||||
|
cmsDeviceCount = 0;
|
||||||
|
cmsCurrentDevice = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // CMS
|
#endif // CMS
|
||||||
|
|
|
@ -55,7 +55,7 @@ typedef enum
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char *text;
|
const char *text;
|
||||||
OSD_MenuElement type;
|
OSD_MenuElement type;
|
||||||
CMSEntryFuncPtr func;
|
CMSEntryFuncPtr func;
|
||||||
void *data;
|
void *data;
|
||||||
|
@ -92,7 +92,7 @@ typedef long (*CMSMenuOnExitPtr)(OSD_Entry *self);
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
// These two are debug aids for menu content creators.
|
// These two are debug aids for menu content creators.
|
||||||
char *GUARD_text;
|
const char *GUARD_text;
|
||||||
OSD_MenuElement GUARD_type;
|
OSD_MenuElement GUARD_type;
|
||||||
|
|
||||||
CMSMenuFuncPtr onEnter;
|
CMSMenuFuncPtr onEnter;
|
||||||
|
|
|
@ -110,6 +110,14 @@ $(OBJECT_DIR)/common/maths.o : \
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/common/maths.c -o $@
|
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/common/maths.c -o $@
|
||||||
|
|
||||||
|
$(OBJECT_DIR)/common/typeconversion.o : \
|
||||||
|
$(USER_DIR)/common/typeconversion.c \
|
||||||
|
$(USER_DIR)/common/typeconversion.h \
|
||||||
|
$(GTEST_HEADERS)
|
||||||
|
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/common/typeconversion.c -o $@
|
||||||
|
|
||||||
$(OBJECT_DIR)/common/filter.o : \
|
$(OBJECT_DIR)/common/filter.o : \
|
||||||
$(USER_DIR)/common/filter.c \
|
$(USER_DIR)/common/filter.c \
|
||||||
$(USER_DIR)/common/filter.h \
|
$(USER_DIR)/common/filter.h \
|
||||||
|
@ -574,6 +582,39 @@ $(OBJECT_DIR)/alignsensor_unittest : \
|
||||||
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
|
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
|
||||||
|
|
||||||
|
|
||||||
|
$(OBJECT_DIR)/drivers/display.o : \
|
||||||
|
$(USER_DIR)/drivers/display.c \
|
||||||
|
$(USER_DIR)/drivers/display.h \
|
||||||
|
$(GTEST_HEADERS)
|
||||||
|
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/drivers/display.c -o $@
|
||||||
|
|
||||||
|
$(OBJECT_DIR)/cms/cms.o : \
|
||||||
|
$(USER_DIR)/cms/cms.c \
|
||||||
|
$(USER_DIR)/cms/cms.h \
|
||||||
|
$(GTEST_HEADERS)
|
||||||
|
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/cms/cms.c -o $@
|
||||||
|
|
||||||
|
$(OBJECT_DIR)/cms_unittest.o : \
|
||||||
|
$(TEST_DIR)/cms_unittest.cc \
|
||||||
|
$(GTEST_HEADERS)
|
||||||
|
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/cms_unittest.cc -o $@
|
||||||
|
|
||||||
|
$(OBJECT_DIR)/cms_unittest : \
|
||||||
|
$(OBJECT_DIR)/cms_unittest.o \
|
||||||
|
$(OBJECT_DIR)/common/typeconversion.o \
|
||||||
|
$(OBJECT_DIR)/drivers/display.o \
|
||||||
|
$(OBJECT_DIR)/cms/cms.o \
|
||||||
|
$(OBJECT_DIR)/gtest_main.a
|
||||||
|
|
||||||
|
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
|
||||||
|
|
||||||
|
|
||||||
## test : Build and run the Unit Tests
|
## test : Build and run the Unit Tests
|
||||||
test: $(TESTS:%=test-%)
|
test: $(TESTS:%=test-%)
|
||||||
|
|
||||||
|
|
207
src/test/unit/cms_unittest.cc
Normal file
207
src/test/unit/cms_unittest.cc
Normal file
|
@ -0,0 +1,207 @@
|
||||||
|
/*
|
||||||
|
* This file is part of Cleanflight.
|
||||||
|
*
|
||||||
|
* Cleanflight is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* Cleanflight 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
|
#include <math.h>
|
||||||
|
|
||||||
|
#define BARO
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
#include "target.h"
|
||||||
|
#include "drivers/display.h"
|
||||||
|
#include "cms/cms.h"
|
||||||
|
#include "cms/cms_types.h"
|
||||||
|
void cmsMenuOpen(void);
|
||||||
|
long cmsMenuBack(displayPort_t *pDisplay);
|
||||||
|
uint16_t cmsHandleKey(displayPort_t *pDisplay, uint8_t key);
|
||||||
|
extern CMS_Menu *currentMenu; // Points to top entry of the current page
|
||||||
|
}
|
||||||
|
|
||||||
|
#include "unittest_macros.h"
|
||||||
|
#include "gtest/gtest.h"
|
||||||
|
|
||||||
|
static displayPort_t testDisplayPort;
|
||||||
|
static int displayPortTestGrab(displayPort_t *displayPort)
|
||||||
|
{
|
||||||
|
UNUSED(displayPort);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int displayPortTestRelease(displayPort_t *displayPort)
|
||||||
|
{
|
||||||
|
UNUSED(displayPort);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int displayPortTestClear(displayPort_t *displayPort)
|
||||||
|
{
|
||||||
|
UNUSED(displayPort);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int displayPortTestWrite(displayPort_t *displayPort, uint8_t x, uint8_t y, const char *s)
|
||||||
|
{
|
||||||
|
UNUSED(displayPort);
|
||||||
|
UNUSED(x);
|
||||||
|
UNUSED(y);
|
||||||
|
UNUSED(s);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int displayPortTestHeartbeat(displayPort_t *displayPort)
|
||||||
|
{
|
||||||
|
UNUSED(displayPort);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void displayPortTestResync(displayPort_t *displayPort)
|
||||||
|
{
|
||||||
|
UNUSED(displayPort);
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint32_t displayPortTestTxBytesFree(const displayPort_t *displayPort)
|
||||||
|
{
|
||||||
|
UNUSED(displayPort);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static const displayPortVTable_t testDisplayPortVTable = {
|
||||||
|
.grab = displayPortTestGrab,
|
||||||
|
.release = displayPortTestRelease,
|
||||||
|
.clear = displayPortTestClear,
|
||||||
|
.write = displayPortTestWrite,
|
||||||
|
.heartbeat = displayPortTestHeartbeat,
|
||||||
|
.resync = displayPortTestResync,
|
||||||
|
.txBytesFree = displayPortTestTxBytesFree
|
||||||
|
};
|
||||||
|
|
||||||
|
displayPort_t *displayPortTestInit(void)
|
||||||
|
{
|
||||||
|
testDisplayPort.vTable = &testDisplayPortVTable;
|
||||||
|
testDisplayPort.rows = 10;
|
||||||
|
testDisplayPort.cols = 40;
|
||||||
|
testDisplayPort.isGrabbed = false;
|
||||||
|
return &testDisplayPort;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSUnittest, TestCmsDisplayPortRegister)
|
||||||
|
{
|
||||||
|
cmsInit();
|
||||||
|
displayPort_t *displayPort = displayPortTestInit();
|
||||||
|
for (int ii = 0; ii < CMS_MAX_DEVICE; ++ii) {
|
||||||
|
const bool registered = cmsDisplayPortRegister(displayPort);
|
||||||
|
EXPECT_EQ(true, registered);
|
||||||
|
}
|
||||||
|
const bool registered = cmsDisplayPortRegister(displayPort);
|
||||||
|
EXPECT_EQ(false, registered);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSUnittest, TestCmsMenuOpen)
|
||||||
|
{
|
||||||
|
cmsInit();
|
||||||
|
displayPort_t *displayPort = displayPortTestInit();
|
||||||
|
displayGrab(displayPort);
|
||||||
|
cmsDisplayPortRegister(displayPort);
|
||||||
|
|
||||||
|
cmsMenuOpen();
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSUnittest, TestCmsMenuExit0)
|
||||||
|
{
|
||||||
|
cmsInit();
|
||||||
|
displayPort_t *displayPort = displayPortTestInit();
|
||||||
|
cmsDisplayPortRegister(displayPort);
|
||||||
|
|
||||||
|
cmsMenuOpen();
|
||||||
|
long exit = cmsMenuExit(displayPort, (void*)0);
|
||||||
|
EXPECT_EQ(0, exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSUnittest, TestCmsMenuExit1)
|
||||||
|
{
|
||||||
|
cmsInit();
|
||||||
|
displayPort_t *displayPort = displayPortTestInit();
|
||||||
|
cmsDisplayPortRegister(displayPort);
|
||||||
|
|
||||||
|
cmsMenuOpen();
|
||||||
|
long exit = cmsMenuExit(displayPort, (void*)0);
|
||||||
|
EXPECT_EQ(0, exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSUnittest, TestCmsMenuBack)
|
||||||
|
{
|
||||||
|
cmsInit();
|
||||||
|
displayPort_t *displayPort = displayPortTestInit();
|
||||||
|
cmsDisplayPortRegister(displayPort);
|
||||||
|
|
||||||
|
cmsMenuOpen();
|
||||||
|
long exit = cmsMenuBack(displayPort);
|
||||||
|
EXPECT_EQ(0, exit);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST(CMSUnittest, TestCmsMenuKey)
|
||||||
|
{
|
||||||
|
#define KEY_ENTER 0
|
||||||
|
#define KEY_UP 1
|
||||||
|
#define KEY_DOWN 2
|
||||||
|
#define KEY_LEFT 3
|
||||||
|
#define KEY_RIGHT 4
|
||||||
|
#define KEY_ESC 5
|
||||||
|
#define BUTTON_TIME 250 // msec
|
||||||
|
#define BUTTON_PAUSE 500 // msec
|
||||||
|
cmsInit();
|
||||||
|
displayPort_t *displayPort = &testDisplayPort;
|
||||||
|
cmsDisplayPortRegister(displayPort);
|
||||||
|
|
||||||
|
cmsMenuOpen();
|
||||||
|
uint16_t result = cmsHandleKey(displayPort, KEY_ESC);
|
||||||
|
EXPECT_EQ(BUTTON_PAUSE, result);
|
||||||
|
}
|
||||||
|
// STUBS
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
static OSD_Entry menuMainEntries[] =
|
||||||
|
{
|
||||||
|
{"-- MAIN MENU --", OME_Label, NULL, NULL, 0},
|
||||||
|
{"SAVE&REBOOT", OME_OSD_Exit, cmsMenuExit, (void*)1, 0},
|
||||||
|
{"EXIT", OME_OSD_Exit, cmsMenuExit, (void*)0, 0},
|
||||||
|
{NULL, OME_END, NULL, NULL, 0}
|
||||||
|
};
|
||||||
|
CMS_Menu menuMain = {
|
||||||
|
"MENUMAIN",
|
||||||
|
OME_MENU,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
menuMainEntries,
|
||||||
|
};
|
||||||
|
uint8_t armingFlags;
|
||||||
|
int16_t debug[4];
|
||||||
|
int16_t rcData[18];
|
||||||
|
void delay(uint32_t) {}
|
||||||
|
uint32_t micros(void) { return 0; }
|
||||||
|
uint32_t millis(void) { return 0; }
|
||||||
|
void saveConfigAndNotify(void) {}
|
||||||
|
void stopMotors(void) {}
|
||||||
|
void stopPwmAllMotors(void) {}
|
||||||
|
void systemReset(void) {}
|
||||||
|
}
|
|
@ -17,6 +17,8 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define CMS
|
||||||
|
#define CMS_MAX_DEVICE 4
|
||||||
#define MAG
|
#define MAG
|
||||||
#define BARO
|
#define BARO
|
||||||
#define GPS
|
#define GPS
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue