diff --git a/lambda-test/.cproject b/lambda-test/.cproject index b394c0e..7e18fec 100644 --- a/lambda-test/.cproject +++ b/lambda-test/.cproject @@ -62,7 +62,7 @@ - + diff --git a/lambda-test/Makefile b/lambda-test/Makefile index 143f553..a981d1c 100644 --- a/lambda-test/Makefile +++ b/lambda-test/Makefile @@ -16,7 +16,7 @@ ## include the additional source (in same directory) here LOCAL_SOURCE = avrjunit.c adc-test.c alert-test.c command-test.c \ display-test.c integers-test.c interrupts-test.c release-test.c \ -rules-test.c sensors-test.c strings-test.c usart-test.c +rules-test.c scheduler-test.c sensors-test.c strings-test.c usart-test.c ## Here you can link to one more directory (and multiple .c files) EXTRA_SOURCE_DIR = ../lambda/ diff --git a/lambda-test/adc-test.c b/lambda-test/adc-test.c index 1ba9d38..140085c 100644 --- a/lambda-test/adc-test.c +++ b/lambda-test/adc-test.c @@ -9,6 +9,7 @@ */ #include "avrjunit.h" +#include "integers.h" #include "interrupts.h" #include "adc.h" #include "pins.h" @@ -58,4 +59,4 @@ {class, testGetVoltage_P, testGetVoltage} }; -TestClass adcClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass adcClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/alert-test.c b/lambda-test/alert-test.c index 71f0964..99bf76b 100644 --- a/lambda-test/alert-test.c +++ b/lambda-test/alert-test.c @@ -9,6 +9,7 @@ */ #include "avrjunit.h" +#include "integers.h" #include "interrupts.h" #include "alert.h" @@ -135,4 +136,4 @@ {class, testCancelAlert_P, testCancelAlert} }; -TestClass alertClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass alertClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/command-test.c b/lambda-test/command-test.c index 7089aa4..26b550f 100644 --- a/lambda-test/command-test.c +++ b/lambda-test/command-test.c @@ -12,6 +12,7 @@ #include "alert.h" #include "command.h" #include "display.h" +#include "integers.h" #include "interrupts.h" #include "sensors.h" @@ -86,4 +87,4 @@ {class, testCycleDisplay_P, testCycleDisplay} }; -TestClass commandClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass commandClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/display-test.c b/lambda-test/display-test.c index f88625a..6057024 100644 --- a/lambda-test/display-test.c +++ b/lambda-test/display-test.c @@ -11,6 +11,7 @@ #include #include "avrjunit.h" #include "display.h" +#include "integers.h" #include "sensors.h" #include "alert.h" @@ -164,4 +165,4 @@ {class, testDisplayText_P, testDisplayText} }; -TestClass displayClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass displayClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/integers-test.c b/lambda-test/integers-test.c index 41223ad..4635257 100644 --- a/lambda-test/integers-test.c +++ b/lambda-test/integers-test.c @@ -45,38 +45,6 @@ return true; } -static bool testDivRoundUp(void) { - assertTrue(divRoundUp(4, 2) == 2); - assertTrue(divRoundUp(5, 2) == 3); - assertTrue(divRoundUp(10, 3) == 4); - - return true; -} - -static bool testDivRoundUpNumNeg(void) { - assertTrue(divRoundUp(-4, 2) == -2); - assertTrue(divRoundUp(-5, 2) == -3); - assertTrue(divRoundUp(-10, 3) == -4); - - return true; -} - -static bool testDivRoundUpDenNeg(void) { - assertTrue(divRoundUp(4, -2) == -2); - assertTrue(divRoundUp(5, -2) == -3); - assertTrue(divRoundUp(10, -3) == -4); - - return true; -} - -static bool testDivRoundUpBothNeg(void) { - assertTrue(divRoundUp(-4, -2) == 2); - assertTrue(divRoundUp(-5, -2) == 3); - assertTrue(divRoundUp(-10, -3) == 4); - - return true; -} - /* Test "class" */ static const char class[] PROGMEM = "integers"; @@ -85,21 +53,13 @@ static const char testDivRoundNearestNumNeg_P[] PROGMEM = "testDivRoundNearestNumNeg"; static const char testDivRoundNearestDenNeg_P[] PROGMEM = "testDivRoundNearestDenNeg"; static const char testDivRoundNearestBothNeg_P[] PROGMEM = "testDivRoundNearestBothNeg"; -static const char testDivRoundUp_P[] PROGMEM = "testDivRoundUp"; -static const char testDivRoundUpNumNeg_P[] PROGMEM = "testDivRoundUpNumNeg"; -static const char testDivRoundUpDenNeg_P[] PROGMEM = "testDivRoundUpDenNeg"; -static const char testDivRoundUpBothNeg_P[] PROGMEM = "testDivRoundUpBothNeg"; /* Tests */ static TestCase const tests[] = { {class, testDivRoundNearest_P, testDivRoundNearest}, {class, testDivRoundNearestNumNeg_P, testDivRoundNearestNumNeg}, {class, testDivRoundNearestDenNeg_P, testDivRoundNearestDenNeg}, - {class, testDivRoundNearestBothNeg_P, testDivRoundNearestBothNeg}, - {class, testDivRoundUp_P, testDivRoundUp}, - {class, testDivRoundUpNumNeg_P, testDivRoundUpNumNeg}, - {class, testDivRoundUpDenNeg_P, testDivRoundUpDenNeg}, - {class, testDivRoundUpBothNeg_P, testDivRoundUpBothNeg}, + {class, testDivRoundNearestBothNeg_P, testDivRoundNearestBothNeg} }; -TestClass integersClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass integersClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/interrupts-test.c b/lambda-test/interrupts-test.c index 90512a7..e71db71 100644 --- a/lambda-test/interrupts-test.c +++ b/lambda-test/interrupts-test.c @@ -11,6 +11,7 @@ #include #include #include "avrjunit.h" +#include "integers.h" #include "interrupts.h" /* Module interrupts */ @@ -122,4 +123,4 @@ {class, testTime_P, testTime} }; -TestClass interruptsClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass interruptsClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/lambda-test.c b/lambda-test/lambda-test.c index 42909bf..57f7dd0 100644 --- a/lambda-test/lambda-test.c +++ b/lambda-test/lambda-test.c @@ -31,23 +31,25 @@ extern TestClass integersClass; extern TestClass interruptsClass; extern TestClass rulesClass; + extern TestClass schedulerClass; extern TestClass sensorsClass; extern TestClass stringsClass; extern TestClass usartClass; beginSuite("lambda"); runClass(releaseClass); + // run these before interrupts are initialized to avoid interference + runClass(rulesClass); runClass(adcClass); runClass(alertClass); runClass(commandClass); runClass(displayClass); runClass(integersClass); - runClass(rulesClass); + runClass(interruptsClass); + runClass(schedulerClass); runClass(sensorsClass); runClass(stringsClass); runClass(usartClass); - // run this one last since the timers interfere with some tests - runClass(interruptsClass); endSuite(); while (1) { diff --git a/lambda-test/release-test.c b/lambda-test/release-test.c index d29edd3..e481238 100644 --- a/lambda-test/release-test.c +++ b/lambda-test/release-test.c @@ -9,6 +9,7 @@ */ #include "avrjunit.h" +#include "integers.h" #include "interrupts.h" #include "messages.h" #include "pins.h" @@ -48,4 +49,4 @@ {class, testRelease_P, testRelease} }; -TestClass releaseClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass releaseClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/rules-test.c b/lambda-test/rules-test.c index 5bf79b6..33dcfc4 100644 --- a/lambda-test/rules-test.c +++ b/lambda-test/rules-test.c @@ -12,6 +12,7 @@ #include "avrjunit.h" #include "rules.h" #include "alert.h" +#include "integers.h" #include "interrupts.h" #include "airgate.h" @@ -533,4 +534,4 @@ {class, testHeaterTimeout1_P, testHeaterTimeout1} }; -TestClass rulesClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass rulesClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/scheduler-test.c b/lambda-test/scheduler-test.c new file mode 100644 index 0000000..06ef9b2 --- /dev/null +++ b/lambda-test/scheduler-test.c @@ -0,0 +1,107 @@ +/* + * scheduler-test.c + * + * Created on: 20.03.2016 + * Author: dode@luniks.net + */ + +#include "avrjunit.h" +#include "integers.h" +#include "interrupts.h" +#include "scheduler.h" + +/* Module scheduler */ + +static bool val1 = false; +static bool val2 = false; +static bool val3 = false; +static bool val4 = false; + +static void task1(void) { + val1 = true; +} + +static void task2(void) { + val2 = true; +} + +static void task3(void) { + val3 = true; +} + +static void task4(void) { + val4 = true; +} + +static void runAllTasks(void) { + resetTime(); + // make sure any tasks scheduled by other tests run + addTime(UINT32_MAX); + runTasks(); +} + +static bool testSchedule(void) { + + runAllTasks(); + resetTime(); + + assertTrue(scheduleTask(task1, 0)); + assertTrue(scheduleTask(task2, 10)); + assertTrue(scheduleTask(task3, 20)); + assertFalse(scheduleTask(task4, 30)); + + return true; +} + +static bool testRunTasks(void) { + + resetTime(); + + runTasks(); + assertTrue(val1); + assertFalse(val2); + assertFalse(val3); + assertFalse(val4); + assertTrue(scheduleTask(task4, 30)); + + addTime(10); + + runTasks(); + assertTrue(val1); + assertTrue(val2); + assertFalse(val3); + assertFalse(val4); + + addTime(15); + + runTasks(); + assertTrue(val1); + assertTrue(val2); + assertTrue(val3); + assertFalse(val4); + + addTime(30); + + runTasks(); + assertTrue(val1); + assertTrue(val2); + assertTrue(val3); + assertTrue(val4); + + return true; +} + +/* Test "class" */ +static const char class[] PROGMEM = "scheduler"; + +/* Test names */ +static const char testSchedule_P[] PROGMEM = "testSchedule"; +static const char testRunTasks_P[] PROGMEM = "testRunTasks"; + +/* Tests */ +static TestCase const tests[] = { + {class, testSchedule_P, testSchedule}, + {class, testRunTasks_P, testRunTasks} +}; + +TestClass schedulerClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/sensors-test.c b/lambda-test/sensors-test.c index a534a14..f690e14 100644 --- a/lambda-test/sensors-test.c +++ b/lambda-test/sensors-test.c @@ -11,6 +11,7 @@ #include #include #include "avrjunit.h" +#include "integers.h" #include "interrupts.h" #include "adc.h" #include "sensors.h" @@ -267,4 +268,4 @@ {class, testGetHeaterUptime_P, testGetHeaterUptime} }; -TestClass sensorsClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass sensorsClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/strings-test.c b/lambda-test/strings-test.c index 4ae4297..0a9b727 100644 --- a/lambda-test/strings-test.c +++ b/lambda-test/strings-test.c @@ -10,6 +10,7 @@ #include #include "avrjunit.h" +#include "integers.h" #include "strings.h" /* Module strings */ @@ -50,4 +51,4 @@ {class, testSplitSizeTooSmall_P, testSplitSizeTooSmall} }; -TestClass stringsClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass stringsClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda-test/usart-test.c b/lambda-test/usart-test.c index bbfb5c5..98f3611 100644 --- a/lambda-test/usart-test.c +++ b/lambda-test/usart-test.c @@ -11,6 +11,7 @@ #include "usart.h" #include #include "avrjunit.h" +#include "integers.h" /* Module usart */ @@ -51,4 +52,4 @@ {class, testInitUSART_P, testInitUSART} }; -TestClass usartClass = {tests, sizeof(tests) / sizeof(tests[0])}; +TestClass usartClass = {tests, ARRAY_LENGTH(tests)}; diff --git a/lambda/integers.c b/lambda/integers.c index b5fb14b..11c3329 100644 --- a/lambda/integers.c +++ b/lambda/integers.c @@ -16,9 +16,3 @@ ((num - den / 2) / den) : ((num + den / 2) / den); } - -int32_t divRoundUp(int32_t const num, int32_t const den) { - return ((num < 0) ^ (den < 0)) ? - ((num - ((den < 0) ? den + 1 : den - 1)) / den) : - ((num + ((den < 0) ? den + 1 : den - 1)) / den); -} diff --git a/lambda/integers.h b/lambda/integers.h index 94af8ab..0f4565f 100644 --- a/lambda/integers.h +++ b/lambda/integers.h @@ -11,7 +11,7 @@ #ifndef INTEGERS_H_ #define INTEGERS_H_ -#define ARRAY_LENGTH(array) sizeof(array) / sizeof(array[0]) +#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0])) #define MAX(x, y) (((x) > (y)) ? (x) : (y)) #define MIN(x, y) (((x) < (y)) ? (x) : (y)) @@ -23,13 +23,4 @@ */ int32_t divRoundNearest(int32_t num, int32_t den); -/** - * Divides the given numerator by the given denominator, - * rounds up and returns it. - */ -int32_t divRoundUp(int32_t num, int32_t den); - -// TODO function to divide and return result as decimal string? -// char* divToDecimalString(int32_t num, int32_t den); - #endif /* INTEGERS_H_ */ diff --git a/lambda/rules.c b/lambda/rules.c index ed4fcc4..0448733 100644 --- a/lambda/rules.c +++ b/lambda/rules.c @@ -167,7 +167,7 @@ if (getHeaterState() != heaterStateFault) { setHeaterState(heaterStateOn); } - setAirgate(100); + setAirgate(AIRGATE_OPEN); *fired = true; } if (state == burning_down && meas.tempI < TEMP_AIRGATE_0) {