1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-04 12:24:11 +01:00
LibrePilot/flight/tests/lednotification/unittest.cpp
Alessio Morale 233dec6d8d OP-1379 - Various fixes and additions
- Support blocks of led for notification (that is a certain number of leds between a min and a max index);
- Fix an issue with bogus colours on fast updates at LED N°0.
- Add NOTIFY_SEQUENCE_NULL to skip handling a specific alarm status;
- Adjust sequences and add Config and Receiver Alarms;
- fix issue with Alarm trigger/repetition;
- Enables Notify module only if a WS281x output is enabled.
- Add some documentation for sequence/alarm definitions (sequences.h)
- Make sequences more coherent. All GPS related info are now shown in green.
- Revert to original blinking rate for onboard led
- add Notify on DiscoveryF4Bare target
2014-09-06 12:11:53 +02:00

100 lines
3.3 KiB
C++

#include "gtest/gtest.h"
#include <stdio.h> /* printf */
#include <stdlib.h> /* abort */
#include <string.h> /* memset */
extern "C" {
#define xTaskGetTickCount() 1
#define portTICK_RATE_MS 1
#include "lednotification.c"
void PIOS_WS2811_setColorRGB(__attribute__((unused)) Color_t c, __attribute__((unused)) uint8_t led, __attribute__((unused)) bool update) {}
void PIOS_WS2811_Update() {}
}
class LedNotificationTest : public testing::Test {};
void insert(NotifierLedStatus_t *status, pios_notify_priority priority)
{
ExtLedNotification_t notification;
notification.priority = priority;
push_queued_sequence(&notification, status);
}
void init(NotifierLedStatus_t *status, pios_notify_priority priority)
{
for (uint8_t i = 0; i < MAX_BACKGROUND_NOTIFICATIONS; i++) {
status->queued_priorities[i] = priority;
}
}
TEST_F(LedNotificationTest, TestQueueOrder1) {
NotifierLedStatus_t status;
init(&status, NOTIFY_PRIORITY_BACKGROUND);
insert(&status, NOTIFY_PRIORITY_LOW);
insert(&status, NOTIFY_PRIORITY_CRITICAL);
insert(&status, NOTIFY_PRIORITY_LOW);
insert(&status, NOTIFY_PRIORITY_CRITICAL);
EXPECT_EQ(NOTIFY_PRIORITY_LOW, status.queued_priorities[0]);
EXPECT_EQ(NOTIFY_PRIORITY_LOW, status.queued_priorities[1]);
EXPECT_EQ(NOTIFY_PRIORITY_CRITICAL, status.queued_priorities[2]);
EXPECT_EQ(NOTIFY_PRIORITY_CRITICAL, status.queued_priorities[3]);
EXPECT_EQ(NOTIFY_PRIORITY_BACKGROUND, status.queued_priorities[4]);
}
TEST_F(LedNotificationTest, TestQueueOrder2) {
NotifierLedStatus_t status;
// Fails because insert_point and first_point will both be -1. This will also cause an array-out-of bounds at:
// 146 status->queued_priorities[insert_point] = new_notification->priority;
// 147 status->queued_sequences[insert_point] = new_notification->sequence;
// 148 updated_sequence = insert_point;
init(&status, NOTIFY_PRIORITY_LOW);
insert(&status, NOTIFY_PRIORITY_REGULAR);
EXPECT_EQ(NOTIFY_PRIORITY_REGULAR, status.queued_priorities[4]);
EXPECT_EQ(NOTIFY_PRIORITY_LOW, status.queued_priorities[3]);
EXPECT_EQ(NOTIFY_PRIORITY_LOW, status.queued_priorities[2]);
EXPECT_EQ(NOTIFY_PRIORITY_LOW, status.queued_priorities[1]);
EXPECT_EQ(NOTIFY_PRIORITY_LOW, status.queued_priorities[0]);
}
TEST_F(LedNotificationTest, TestQueueOrder3) {
NotifierLedStatus_t status;
// Fails because queued_priorities[0] _LOW and not _REGULAR. I _think_ this is a bug.
init(&status, NOTIFY_PRIORITY_REGULAR);
insert(&status, NOTIFY_PRIORITY_LOW);
for (uint8_t i = 0; i < MAX_BACKGROUND_NOTIFICATIONS; i++) {
EXPECT_EQ(NOTIFY_PRIORITY_REGULAR, status.queued_priorities[i]);
}
}
TEST_F(LedNotificationTest, TestQueueOrder4) {
NotifierLedStatus_t status;
init(&status, NOTIFY_PRIORITY_BACKGROUND);
insert(&status, NOTIFY_PRIORITY_REGULAR);
insert(&status, NOTIFY_PRIORITY_REGULAR);
insert(&status, NOTIFY_PRIORITY_REGULAR);
insert(&status, NOTIFY_PRIORITY_LOW);
EXPECT_EQ(NOTIFY_PRIORITY_BACKGROUND, status.queued_priorities[4]);
EXPECT_EQ(NOTIFY_PRIORITY_REGULAR, status.queued_priorities[3]);
EXPECT_EQ(NOTIFY_PRIORITY_REGULAR, status.queued_priorities[2]);
EXPECT_EQ(NOTIFY_PRIORITY_REGULAR, status.queued_priorities[1]);
EXPECT_EQ(NOTIFY_PRIORITY_LOW, status.queued_priorities[0]);
}