Skip to content

Commit

Permalink
Merge pull request #155 from spacelab-ufsc/feat_unit_tests
Browse files Browse the repository at this point in the history
Add unit test structure files for the following devices:

OBDH;
TTC;
Voltage sensor;
Temp sensor;
Current sensor
The related issues (#147, #146, #150, #149 and #148 respectively) are not being closed, given that the tests are not properly implemented, as the files are templates only.
  • Loading branch information
lzacchi authored Nov 3, 2021
2 parents bfc8362 + 2ef039e commit 60d66e9
Show file tree
Hide file tree
Showing 26 changed files with 1,310 additions and 6 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ name: Test Workflow

on:
push:
branches: [ dev_firmware ]
branches: [ dev_firmware, feat_unit_tests ]
pull_request:
branches: [ master, dev, dev_firmware]

Expand Down
96 changes: 92 additions & 4 deletions firmware/tests/devices/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
TARGET_LEDS=leds_unit_test
TARGET_CURRENT_SENSOR=current_sensor_unit_test
TARGET_TEMP_SENSOR=temp_sensor_unit_test
TARGET_VOLTAGE_SENSOR=voltage_sensor_unit_test
TARGET_OBDH=obdh_unit_test
TARGET_TTC=ttc_unit_test

ifndef BUILD_DIR
BUILD_DIR=$(CURDIR)
Expand All @@ -8,25 +13,108 @@ CC=gcc
INC=../../
FLAGS=-fpic -std=c99 -Wall -pedantic -Wshadow -Wpointer-arith -Wcast-qual -Wstrict-prototypes -Wmissing-prototypes -I$(INC) -Wl,--wrap=sys_log_print_event_from_module,--wrap=sys_log_new_line,--wrap=sys_log_print_msg,--wrap=sys_log_print_uint,--wrap=sys_log_print_int,--wrap=sys_log_print_float,--wrap=adc_init,--wrap=adc_read,--wrap=adc_temp_get_mref,--wrap=adc_temp_get_nref,--wrap=gpio_init,--wrap=gpio_set_state,--wrap=gpio_get_state,--wrap=gpio_toggle,--wrap=wdt_init,--wrap=wdt_reset,--wrap=tps382x_init,--wrap=tps382x_trigger

CURRENT_SENSOR_TEST_FLAGS=$(FLAGS),--wrap=adc_init,--wrap=adc_read,--wrap=adc_temp_get_mref,--wrap=adc_temp_get_nref,--wrap=adc_mutex_give,--wrap=adc_mutex_take,--wrap=max9934_read,--wrap=max9934_init
VOLTAGE_SENSOR_TEST_FLAGS=$(FLAGS),--wrap=adc_init,--wrap=adc_read,--wrap=adc_temp_get_mref,--wrap=adc_temp_get_nref,--wrap=adc_mutex_give,--wrap=adc_mutex_take
TEMP_SENSOR_TEST_FLAGS=$(FLAGS),--wrap=ads1248_init,--wrap=ads1248_reset,--wrap=ads1248_config_regs,--wrap=ads1248_read_regs,--wrap=ads1248_read_data,--wrap=ads1248_write_cmd,--wrap=ads1248_set_powerdown_mode,--wrap=adc_init,--wrap=adc_read,--wrap=adc_temp_get_mref,--wrap=adc_temp_get_nref,--wrap=adc_mutex_give,--wrap=adc_mutex_take
OBDH_TEST_FLAGS=$(FLAGS),--wrap=tca4311a_init,--wrap=tca4311a_enable,--wrap=tca4311a_disable,--wrap=tca4311a_is_ready,--wrap=i2c_slave_init,--wrap=i2c_slave_set_mode,--wrap=i2c_slave_enable,--wrap=i2c_slave_disable,--wrap=i2c_slave_write,--wrap=i2c_master_init,--wrap=i2c_write,--wrap=i2c_read
TTC_TEST_FLAGS=$(FLAGS),--wrap=uart_interrupt_init,--wrap=uart_interrupt_enable,--wrap=uart_interrupt_disable,--wrap=uart_interrupt_write

.PHONY: all
all: leds_test
all: leds_test current_sensor_test temp_sensor_test voltage_sensor_test obdh_test ttc_test

.PHONY: leds_test
leds_test: $(BUILD_DIR)/leds.o $(BUILD_DIR)/leds_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/gpio_wrap.o
$(CC) $(FLAGS) $(BUILD_DIR)/leds.o $(BUILD_DIR)/leds_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/gpio_wrap.o -o $(BUILD_DIR)/$(TARGET_LEDS) -lcmocka


.PHONY: current_sensor_test
current_sensor_test: $(BUILD_DIR)/current_sensor.o $(BUILD_DIR)/current_sensor_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/adc_wrap.o $(BUILD_DIR)/max9934_wrap.o
$(CC) $(CURRENT_SENSOR_TEST_FLAGS) $(BUILD_DIR)/current_sensor.o $(BUILD_DIR)/current_sensor_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/adc_wrap.o $(BUILD_DIR)/max9934_wrap.o -o $(BUILD_DIR)/$(TARGET_CURRENT_SENSOR) -lcmocka

.PHONY: temp_sensor_test
temp_sensor_test: $(BUILD_DIR)/temp_sensor.o $(BUILD_DIR)/temp_sensor_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/ads1248_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/adc_wrap.o
$(CC) $(TEMP_SENSOR_TEST_FLAGS) $(BUILD_DIR)/temp_sensor.o $(BUILD_DIR)/temp_sensor_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/ads1248_wrap.o $(BUILD_DIR)/gpio_wrap.o $(BUILD_DIR)/adc_wrap.o -o $(BUILD_DIR)/$(TARGET_TEMP_SENSOR) -lcmocka

.PHONY: voltage_sensor_test
voltage_sensor_test: $(BUILD_DIR)/voltage_sensor.o $(BUILD_DIR)/voltage_sensor_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/adc_wrap.o
$(CC) $(VOLTAGE_SENSOR_TEST_FLAGS) $(BUILD_DIR)/voltage_sensor.o $(BUILD_DIR)/voltage_sensor_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/adc_wrap.o -o $(BUILD_DIR)/$(TARGET_VOLTAGE_SENSOR) -lcmocka

.PHONY: obdh_test
obdh_test: $(BUILD_DIR)/obdh.o $(BUILD_DIR)/obdh_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/tca4311a_wrap.o $(BUILD_DIR)/i2c_slave_wrap.o $(BUILD_DIR)/i2c_wrap.o
$(CC) $(OBDH_TEST_FLAGS) $(BUILD_DIR)/obdh.o $(BUILD_DIR)/obdh_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/tca4311a_wrap.o $(BUILD_DIR)/i2c_slave_wrap.o $(BUILD_DIR)/i2c_wrap.o -o $(BUILD_DIR)/$(TARGET_OBDH) -lcmocka

.PHONY: ttc_test
ttc_test: $(BUILD_DIR)/ttc.o $(BUILD_DIR)/ttc_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/uart_interrupt_wrap.o
$(CC) $(TTC_TEST_FLAGS) $(BUILD_DIR)/ttc.o $(BUILD_DIR)/ttc_test.o $(BUILD_DIR)/sys_log_wrap.o $(BUILD_DIR)/uart_interrupt_wrap.o -o $(BUILD_DIR)/$(TARGET_TTC) -lcmocka


# Devices
$(BUILD_DIR)/leds.o: ../../devices/leds/leds.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/current_sensor.o: ../../devices/current_sensor/current_sensor.c
$(CC) $(CURRENT_SENSOR_TEST_FLAGS) -c $< -o $@

$(BUILD_DIR)/temp_sensor.o: ../../devices/temp_sensor/temp_sensor.c
$(CC) $(TEMP_SENSOR_TEST_FLAGS) -c $< -o $@

$(BUILD_DIR)/voltage_sensor.o: ../../devices/voltage_sensor/voltage_sensor.c
$(CC) $(VOLTAGE_SENSOR_TEST_FLAGS) -c $< -o $@

$(BUILD_DIR)/obdh.o: ../../devices/obdh/obdh.c
$(CC) $(OBDH_TEST_FLAGS) -c $< -o $@

$(BUILD_DIR)/ttc.o: ../../devices/ttc/ttc.c
$(CC) $(TTC_TEST_FLAGS) -c $< -o $@

# Tests
$(BUILD_DIR)/current_sensor_test.o: current_sensor_test.c
$(CC) $(CURRENT_SENSOR_TEST_FLAGS) -c $< -o $@

$(BUILD_DIR)/leds_test.o: leds_test.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/sys_log_wrap.o: ../mockups/sys_log_wrap.c
$(BUILD_DIR)/temp_sensor_test.o: temp_sensor_test.c
$(CC) $(TEMP_SENSOR_TEST_FLAGS) -c $< -o $@

$(BUILD_DIR)/voltage_sensor_test.o: voltage_sensor_test.c
$(CC) $(VOLTAGE_SENSOR_TEST_FLAGS) -c $< -o $@

$(BUILD_DIR)/obdh_test.o: obdh_test.c
$(CC) $(OBDH_TEST_FLAGS) -c $< -o $@

$(BUILD_DIR)/ttc_test.o: ttc_test.c
$(CC) $(TTC_TEST_FLAGS) -c $< -o $@

# Mockups
$(BUILD_DIR)/sys_log_wrap.o: ../mockups/sys_log_wrap/sys_log_wrap.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/gpio_wrap.o: ../mockups/gpio_wrap/gpio_wrap.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/adc_wrap.o: ../mockups/adc_wrap/adc_wrap.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/max9934_wrap.o: ../mockups/max9934_wrap/max9934_wrap.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/ads1248_wrap.o: ../mockups/ads1248_wrap/ads1248_wrap.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/tca4311a_wrap.o: ../mockups/tca4311a_wrap/tca4311a_wrap.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/i2c_wrap.o: ../mockups/i2c_wrap/i2c_wrap.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/i2c_slave_wrap.o: ../mockups/i2c_slave_wrap/i2c_slave_wrap.c
$(CC) $(FLAGS) -c $< -o $@

$(BUILD_DIR)/gpio_wrap.o: ../mockups/gpio_wrap.c
$(BUILD_DIR)/uart_interrupt_wrap.o: ../mockups/uart_interrupt_wrap/uart_interrupt_wrap.c
$(CC) $(FLAGS) -c $< -o $@


.PHONY: clean
clean:
rm $(BUILD_DIR)/$(TARGET_LEDS) $(BUILD_DIR)/*.o
rm $(BUILD_DIR)/$(TARGET_LEDS) $(BUILD_DIR)/$(TARGET_CURRENT_SENSOR) $(BUILD_DIR)/$(TARGET_TEMP_SENSOR) $(BUILD_DIR)/$(TARGET_VOLTAGE_SENSOR) $(BUILD_DIR)/$(TARGET_OBDH) $(BUILD_DIR)/$(TARGET_TTC) $(BUILD_DIR)/*.o
67 changes: 67 additions & 0 deletions firmware/tests/devices/current_sensor_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* current_sensor_test.c
*
* Copyright (C) 2021, SpaceLab.
*
* This file is part of EPS 2.0.
*
* EPS 2.0 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.
*
* EPS 2.0 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 EPS 2.0. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* \brief Unit test of the Current Sensor device
*
* \author Lucas Zacchi de Medeiros <[email protected]>
*
* \version 0.1.0
*
* \date 2021/08/23
*
* \defgroup current_sensor_test Current Sensor
* \ingroup tests
* \{
*/

#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <float.h>
#include <cmocka.h>

#include <devices/current_sensor/current_sensor.h>
#include <system/sys_log/sys_log.h>
#include <drivers/adc/adc.h>
#include <drivers/max9934/max9934.h>

static void current_sensor_init_test(void **state) {

}

static void current_sensor_raw_read_test(void **state) {

}

int main(void) {
const struct CMUnitTest current_sensor_tests[] = {
cmocka_unit_test(current_sensor_init_test),
cmocka_unit_test(current_sensor_raw_read_test),
};

return cmocka_run_group_tests(current_sensor_tests, NULL, NULL);
}


/** \} End of current_sensor_test group */
1 change: 0 additions & 1 deletion firmware/tests/devices/leds_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@

#include <devices/leds/leds.h>
#include <drivers/gpio/gpio.h>
#include <tests/mockups/gpio_wrap.h>

#define LED_SYSTEM_NUM 0
#define LED_FAULT_NUM 1
Expand Down
72 changes: 72 additions & 0 deletions firmware/tests/devices/obdh_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* obdh_test.c
*
* Copyright (C) 2021, SpaceLab.
*
* This file is part of EPS 2.0.
*
* EPS 2.0 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.
*
* EPS 2.0 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 EPS 2.0. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* \brief Unit test of the OBDH device.
*
* \author Lucas Zacchi de Medeiros <[email protected]>
*
* \version 0.1.0
*
* \date 2021/09/15
*
* \defgroup obdh_unit_test OBDH
* \ingroup tests
* \{
*/

#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <setjmp.h>
#include <float.h>
#include <cmocka.h>

#include <devices/obdh/obdh.h>
#include <drivers/tca4311a/tca4311a.h>
#include <drivers/i2c_slave/i2c_slave.h>
#include <drivers/i2c/i2c.h>

static void obdh_init_test(void** state) {

}

static void obdh_decocde_test(void **state) {

}

static void obdh_answer_test(void** state) {

}

int main(void) {
const struct CMUnitTest obdh_tests[] = {
cmocka_unit_test(obdh_init_test),
cmocka_unit_test(obdh_decocde_test),
cmocka_unit_test(obdh_answer_test),

};

return cmocka_run_group_tests(obdh_tests, NULL, NULL);
}

/** \} End of obdh_test group */
113 changes: 113 additions & 0 deletions firmware/tests/devices/temp_sensor_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/*
* temp_sensor_test.c
*
* Copyright (C) 2021, SpaceLab.
*
* This file is part of EPS 2.0.
*
* EPS 2.0 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.
*
* EPS 2.0 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 EPS 2.0. If not, see <http://www.gnu.org/licenses/>.
*
*/

/**
* \brief Unit test of the Temp Sensor device.
*
* \author Lucas Zacchi de Medeiros <[email protected]>
*
* \version 0.1.0
*
* \date 2021/09/06
*
* \defgroup leds_unit_test LEDs
* \ingroup tests
* \{
*/

#include <stdarg.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <setjmp.h>
#include <float.h>
#include <cmocka.h>

#include <devices/temp_sensor/temp_sensor.h>
#include <drivers/ads1248/ads1248.h>

static void temp_sensor_init_test(void **state) {

}

static void temp_sensor_suspend_test(void **state) {

}

static void temp_mcu_read_raw_test(void **state) {

}

static void temp_mcu_raw_to_c_test(void **state) {

}

static void temp_mcu_raw_to_k_test(void **state) {

}

static void temp_mcu_read_c_test(void **state) {

}

static void temp_mcu_read_k_test(void **state) {

}

static void temp_rtd_read_raw_test(void **state) {

}

static void temp_rtd_raw_to_c_test(void **state) {

}

static void temp_rtd_raw_to_k_test(void **state) {

}

static void temp_rtd_read_c_test(void **state) {

}

static void temp_rtd_read_k_test(void **state) {

}

int main(void) {
const struct CMUnitTest temp_sensor_tests[] = {
cmocka_unit_test(temp_sensor_init_test),
cmocka_unit_test(temp_sensor_suspend_test),
cmocka_unit_test(temp_mcu_read_raw_test),
cmocka_unit_test(temp_mcu_raw_to_c_test),
cmocka_unit_test(temp_mcu_raw_to_k_test),
cmocka_unit_test(temp_mcu_read_c_test),
cmocka_unit_test(temp_mcu_read_k_test),
cmocka_unit_test(temp_rtd_read_raw_test),
cmocka_unit_test(temp_rtd_raw_to_c_test),
cmocka_unit_test(temp_rtd_raw_to_k_test),
cmocka_unit_test(temp_rtd_read_c_test),
cmocka_unit_test(temp_rtd_read_k_test)
};

return cmocka_run_group_tests(temp_sensor_tests, NULL, NULL);
}
Loading

0 comments on commit 60d66e9

Please sign in to comment.