Commit 02240a73 authored by Dominic Clifton's avatar Dominic Clifton
Browse files

Merge branch 'SteveAmor-baro_unit_tests'

parents 5dee96c3 847b9387
......@@ -26,6 +26,8 @@
#include "system.h"
#include "bus_i2c.h"
#include "build_config.h"
// MS5611, Standard address 0x77
#define MS5611_ADDR 0x77
......@@ -44,7 +46,7 @@
static void ms5611_reset(void);
static uint16_t ms5611_prom(int8_t coef_num);
static int8_t ms5611_crc(uint16_t *prom);
STATIC_UNIT_TESTED int8_t ms5611_crc(uint16_t *prom);
static uint32_t ms5611_read_adc(void);
static void ms5611_start_ut(void);
static void ms5611_get_ut(void);
......@@ -102,7 +104,7 @@ static uint16_t ms5611_prom(int8_t coef_num)
return rxbuf[0] << 8 | rxbuf[1];
}
static int8_t ms5611_crc(uint16_t *prom)
STATIC_UNIT_TESTED int8_t ms5611_crc(uint16_t *prom)
{
int32_t i, j;
uint32_t res = 0;
......
......@@ -58,7 +58,8 @@ TESTS = \
ws2811_unittest \
encoding_unittest \
io_serial_unittest \
lowpass_unittest
lowpass_unittest \
baro_unittest
# All Google Test headers. Usually you shouldn't change this
# definition.
......@@ -463,6 +464,29 @@ rx_rx_unittest : \
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
$(OBJECT_DIR)/drivers/barometer_ms5611.o : \
$(USER_DIR)/drivers/barometer_ms5611.c \
$(USER_DIR)/drivers/barometer_ms5611.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CC) $(C_FLAGS) $(TEST_CFLAGS) -c $(USER_DIR)/drivers/barometer_ms5611.c -o $@
$(OBJECT_DIR)/baro_unittest.o : \
$(TEST_DIR)/baro_unittest.cc \
$(USER_DIR)/drivers/barometer_ms5611.h \
$(GTEST_HEADERS)
@mkdir -p $(dir $@)
$(CXX) $(CXX_FLAGS) $(TEST_CFLAGS) -c $(TEST_DIR)/baro_unittest.cc -o $@
baro_unittest : \
$(OBJECT_DIR)/drivers/barometer_ms5611.o \
$(OBJECT_DIR)/baro_unittest.o \
$(OBJECT_DIR)/gtest_main.a
$(CXX) $(CXX_FLAGS) $^ -o $(OBJECT_DIR)/$@
test: $(TESTS)
set -e && for test in $(TESTS) ; do \
$(OBJECT_DIR)/$$test; \
......
/*
* 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>
extern "C" {
int8_t ms5611_crc(uint16_t *prom);
}
#include "unittest_macros.h"
#include "gtest/gtest.h"
TEST(baroTest, TestValidMs5611Crc)
{
// given
uint16_t ms5611_prom[] = {0x3132,0x3334,0x3536,0x3738,0x3940,0x4142,0x4344,0x450B};
// when
int8_t result = ms5611_crc(ms5611_prom);
// then
EXPECT_EQ(0, result);
}
TEST(baroTest, TestInvalidMs5611Crc)
{
// given
uint16_t ms5611_prom[] = {0x3132,0x3334,0x3536,0x3738,0x3940,0x4142,0x4344,0x4500};
// when
int8_t result = ms5611_crc(ms5611_prom);
// then
EXPECT_EQ(-1, result);
}
TEST(baroTest, TestMs5611AllZeroProm)
{
// given
uint16_t ms5611_prom[] = {0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000,0x0000};
// when
int8_t result = ms5611_crc(ms5611_prom);
// then
EXPECT_EQ(-1, result);
}
TEST(baroTest, TestMs5611AllOnesProm)
{
// given
uint16_t ms5611_prom[] = {0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF,0xFFFF};
// when
int8_t result = ms5611_crc(ms5611_prom);
// then
EXPECT_EQ(-1, result);
}
// STUBS
extern "C" {
void delay(uint32_t) {}
void delayMicroseconds(uint32_t) {}
bool i2cWrite(uint8_t, uint8_t, uint8_t) {
return 1;
}
bool i2cRead(uint8_t, uint8_t, uint8_t, uint8_t) {
return 1;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment