Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integration tests for led change notification. Copyright msgs. #307

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion tests/core-v1/testapp1/LED.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
// Copyright (c) 2014 Spark Labs, Inc. All rights reserved.

#include "application.h"
#include "unit-test/unit-test.h"



/**
* Handles the notification of LED change
*/
uint8_t rgbNotify[3];
volatile uint32_t rgbNotifyCount;
void onChangeRGBLED(uint8_t r, uint8_t g, uint8_t b) {
rgbNotify[0] = r;
rgbNotify[1] = g;
rgbNotify[2] = b;
rgbNotifyCount++;
}

void assertLEDColor(uint8_t r, uint8_t g, uint8_t b, bool equal) {
uint8_t rgb[3];
LED_RGB_Get(rgb);
Expand All @@ -18,6 +33,12 @@ void assertLEDColor(uint8_t r, uint8_t g, uint8_t b, bool equal) {
}
}

void assertLEDNotify(uint8_t r, uint8_t g, uint8_t b) {
assertEqual(rgbNotify[0], r);
assertEqual(rgbNotify[1], g);
assertEqual(rgbNotify[2], b);
}

void assertLEDColorIs(uint8_t r, uint8_t g, uint8_t b) {
assertLEDColor(r, g, b, true);
}
Expand Down Expand Up @@ -67,6 +88,14 @@ test(LED_ChangesWhenNotControlled) {
assertFalse(rgbInitial[0]==rgbChanged[0] && rgbInitial[1]==rgbChanged[1] && rgbInitial[2]==rgbChanged[2]);
}

test(LED_Updated) {
RGB.control(false);
uint32_t start = rgbNotifyCount;
delay(500);
uint32_t end = rgbNotifyCount;
assertMore((end-start), uint32_t(20)); // I think it's meant to be 100Hz, but this is fine as a smoke test
}

test(LED_StaticWhenControlled) {
// given
RGB.control(true);
Expand All @@ -86,7 +115,11 @@ test(LED_StaticWhenControlled) {
assertEqual(rgbInitial[i], rgbExpected[i]);

for (int i=0; i<3; i++)
assertEqual(rgbInitial[i], rgbChanged[i]);
assertEqual(rgbInitial[i], rgbChanged[i]);

for (int i=0; i<3; i++)
assertEqual(rgbInitial[i], rgbNotify[i]);

}

test(LED_SettingRGBAfterOverrideShouldChangeLED) {
Expand Down Expand Up @@ -138,3 +171,5 @@ test(LED_BrightnessIsPersisted) {

assertLEDColorIs(ledAdjust(255,128),ledAdjust(255,128),0);
}


1 change: 1 addition & 0 deletions tests/core-v1/testapp1/application.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Copyright (c) 2014 Spark Labs, Inc. All rights reserved.

#include "application.h"
#include "unit-test/unit-test.h"
Expand Down
16 changes: 10 additions & 6 deletions tests/unit/makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
## Copyright (c) 2014 Spark Labs, Inc. All rights reserved.
## -*- Makefile -*-

CCC = gcc
Expand All @@ -14,7 +15,7 @@ MKDIR = mkdir -p
SRC_ROOT=../../

# location of this folder relative to the root
SRC_PATH=/tests/unit
SRC_PATH=tests/unit/


TARGETDIR=obj/
Expand All @@ -32,20 +33,21 @@ rwildcard = $(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2
# $2 the pattern to match, e.g. *.cpp
target_files = $(patsubst $(SRC_ROOT)%,%,$(call rwildcard,$(SRC_ROOT)$1,$2))

CSRC += $(call target_files,$(LIB_CORE_COMMON_PATH)SPARK_Services/src,*.c)
CPPSRC += $(call target_files,tests/unit/,*.cpp)
CPPSRC += $(call target_files,src,spark_wiring_random.cpp)
CPPSRC += src/spark_wiring_string.cpp
CPPSRC += $(call target_files,src,spark_wiring_string.cpp)

# Paths to dependent projects, referenced from root of this project
LIB_CORE_COMMON_PATH = ../core-common-lib/
CSRC += $(call target_files,$(LIB_CORE_COMMON_PATH)SPARK_Services/src,*.c)


# Additional include directories, applied to objects built for this target.
# todo - delegate this to a include.mk file in each repo so include dirs are better
# encapsulated by their owning repo
INCLUDE_DIRS += $(LIB_CORE_COMMON_PATH)SPARK_Services/inc
INCLUDE_DIRS += inc
INCLUDE_DIRS += $(SRC_PATH)/include

CFLAGS += $(patsubst %,-I$(SRC_ROOT)%,$(INCLUDE_DIRS)) -I.
CFLAGS += -ffunction-sections -Wall
Expand All @@ -60,11 +62,13 @@ CFLAGS += -DDEBUG_BUILD

CPPFLAGS += -std=gnu++11

LDFLAGS += -Wl,--gc-sections
LDFLAGS += -Wl,--gc-sections

# Collect all object and dep files
ALLOBJ += $(addprefix $(BUILD_PATH), $(CSRC:.c=.o))
# Collect all object and dep files.
# For the weak symbols in core-common-lib to be overridden by local code, the
# cpp objs have to be on the path first
ALLOBJ += $(addprefix $(BUILD_PATH), $(CPPSRC:.cpp=.o))
ALLOBJ += $(addprefix $(BUILD_PATH), $(CSRC:.c=.o))

ALLDEPS += $(addprefix $(BUILD_PATH), $(CSRC:.c=.o.d))
ALLDEPS += $(addprefix $(BUILD_PATH), $(CPPSRC:.cpp=.o.d))
Expand Down