diff --git a/TESTS/API/PWM_fall/PWM_fall.cpp b/TESTS/API/PWM_fall/PWM_fall.cpp new file mode 100644 index 0000000..b9f06f4 --- /dev/null +++ b/TESTS/API/PWM_fall/PWM_fall.cpp @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//#error [NOT_SUPPORTED] PWM tests are still being written and validated, not for public use yet. + +#if !DEVICE_PWMOUT + #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include +#include "ci_test_config.h" + +using namespace utest::v1; + +volatile int fall_count; +void cbfn_fall(void){ + fall_count++; +} + +// Template to test that a PWM signal has the correct length by measuring the number falls +// interrupts during a specified number of tests. +template +void PWM_Period_Test(){ + // Initialize PWM, InterruptIn, Timer, and Rising / Falling edge counts + fall_count = 0; + PwmOut pwm(pwm_out_pin); + InterruptIn iin(int_in_pin); + iin.fall(cbfn_fall); + pwm.period((float)period_in_miliseconds/1000); + + //Start Testing + pwm.write(0.5f); // 50% duty cycle + wait_ms(num_tests * period_in_miliseconds); // wait for pwm to run and counts to add up + iin.disable_irq(); // This is here because otherwise it fails on some platforms + int fc = fall_count; // grab the numbers to work with as the pwm may continue going + + int expected_count = num_tests; + + float ten_percent = (expected_count * 0.1f); + float five_percent = (expected_count * 0.05f); + float one_percent = (expected_count * 0.01f); + + // fudge factor + if(ten_percent < 1){ + ten_percent = 1; + } + if(five_percent < 1){ + five_percent = 1; + } + if(one_percent < 1){ + one_percent = 1; + } + + DEBUG_PRINTF("\r\n*****\r\n fall count = %d, expected count = %d",fc,expected_count); + DEBUG_PRINTF("\r\n .10 = %f, .05 = %f, .01 = %f",ten_percent,five_percent,one_percent); + + DEBUG_PRINTF("\r\n abs(expected-fc) = %d\r\n*****\r\n",std::abs(expected_count - fc)); + TEST_ASSERT_MESSAGE( std::abs(expected_count - fc) <= ten_percent, "There was more than 10 percent variance in number of fall cycles seen and number expected."); + TEST_ASSERT_MESSAGE( std::abs(expected_count - fc) <= five_percent,"There was more than 5 percent variance in number of fall cycles seen and number expected."); + //TEST_ASSERT_MESSAGE( std::abs(expected_count - fc) <= one_percent, "There was more than 1 percent variance in number of fall cycles seen and number expected."); +} + +// test if software constructor / destructor works +void pwm_define_test(){ + PwmOut pwm0(MBED_CONF_APP_PWM_0); + PwmOut pwm1(MBED_CONF_APP_PWM_1); + PwmOut pwm2(MBED_CONF_APP_PWM_2); + PwmOut pwm3(MBED_CONF_APP_PWM_3); + + pwm0.period(1.0f); + pwm1.period(1.0f); + pwm2.period(1.0f); + pwm3.period(1.0f); + + pwm0.write(0.5f); + pwm1.write(0.5f); + pwm2.write(0.5f); + pwm3.write(0.5f); + + TEST_ASSERT_MESSAGE(true,"The fact that it hasnt errored out proves this passes the sniff test"); +} + +utest::v1::status_t test_setup(const size_t number_of_cases){ + // Setup Greentea using a reasonable timeout in seconds + GREENTEA_SETUP(200, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +// Handle test failures, keep testing, dont stop +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason){ + greentea_case_failure_abort_handler(source, reason); + return STATUS_CONTINUE; +} + +// Test cases +// TODO: take pin names from config file or generate from pinmap file +Case cases[] = { + // Test Creat PwmOut Objects + Case("Pwm object definable", pwm_define_test,greentea_failure_handler), // test pwm object constructor works + + // Test Frequency length by counting fall ticks + Case("PWM_0 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_1 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_2 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_3 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle +}; + +Specification specification(test_setup, cases); + +// Entry point into the tests +int main(){ + return !Harness::run(specification); +} diff --git a/TESTS/API/PWM_rise/PWM_rise.cpp b/TESTS/API/PWM_rise/PWM_rise.cpp new file mode 100644 index 0000000..0a6b920 --- /dev/null +++ b/TESTS/API/PWM_rise/PWM_rise.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//#error [NOT_SUPPORTED] PWM tests are still being written and validated, not for public use yet. + +#if !DEVICE_PWMOUT + #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include +#include "ci_test_config.h" + +using namespace utest::v1; + +volatile int rise_count; +void cbfn_rise(void){ + rise_count++; +} + +// Template to test that a PWM signal has the correct length by measuring the number of rise interrupts +// interrupts during a specified number of tests. +template +void PWM_Period_Test(){ + // Initialize PWM, InterruptIn, Timer, and Rising / Falling edge counts + rise_count = 0; + PwmOut pwm(pwm_out_pin); + InterruptIn iin(int_in_pin); + iin.rise(cbfn_rise); + pwm.period((float)period_in_miliseconds/1000); + + //Start Testing + pwm.write(0.5f); // 50% duty cycle + wait_ms(num_tests * period_in_miliseconds); // wait for pwm to run and counts to add up + iin.disable_irq(); // This is here because otherwise it fails on some platforms + int rc = rise_count; // grab the numbers to work with as the pwm may continue going + + int expected_count = num_tests; + + float ten_percent = (expected_count * 0.1f); + float five_percent = (expected_count * 0.05f); + float one_percent = (expected_count * 0.01f); + + // fudge factor + if(ten_percent < 1){ + ten_percent = 1; + } + if(five_percent < 1){ + five_percent = 1; + } + if(one_percent < 1){ + one_percent = 1; + } + + DEBUG_PRINTF("\r\n*****\r\n rise count = %d, expected count = %d",rc,expected_count); + DEBUG_PRINTF("\r\n .10 = %f, .05 = %f, .01 = %f",ten_percent,five_percent,one_percent); + + DEBUG_PRINTF("\r\n abs(expected-rc) = %d",std::abs(expected_count - rc)); + TEST_ASSERT_MESSAGE( std::abs(expected_count - rc) <= ten_percent, "There was more than 10 percent variance in number of rise cycles seen and number expected."); + TEST_ASSERT_MESSAGE( std::abs(expected_count - rc) <= five_percent,"There was more than 5 percent variance in number of rise cycles seen and number expected."); + //TEST_ASSERT_MESSAGE( std::abs(expected_count - rc) <= one_percent, "There was more than 1 percent variance in number of rise cycles seen and number expected."); +} + +// test if software constructor / destructor works +void pwm_define_test(){ + PwmOut pwm0(MBED_CONF_APP_PWM_0); + PwmOut pwm1(MBED_CONF_APP_PWM_1); + PwmOut pwm2(MBED_CONF_APP_PWM_2); + PwmOut pwm3(MBED_CONF_APP_PWM_3); + + pwm0.period(1.0f); + pwm1.period(1.0f); + pwm2.period(1.0f); + pwm3.period(1.0f); + + pwm0.write(0.5f); + pwm1.write(0.5f); + pwm2.write(0.5f); + pwm3.write(0.5f); + + TEST_ASSERT_MESSAGE(true,"The fact that it hasnt errored out proves this passes the sniff test"); +} + +utest::v1::status_t test_setup(const size_t number_of_cases){ + // Setup Greentea using a reasonable timeout in seconds + GREENTEA_SETUP(200, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +// Handle test failures, keep testing, dont stop +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason){ + greentea_case_failure_abort_handler(source, reason); + return STATUS_CONTINUE; +} + +// Test cases +// TODO: take pin names from config file or generate from pinmap file +Case cases[] = { + // test pwm object constructor works + Case("Pwm object definable", pwm_define_test,greentea_failure_handler), + + // Test Frequency length by counting rise ticks + Case("PWM_0 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_1 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_2 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_3 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + +}; + +Specification specification(test_setup, cases); + +// Entry point into the tests +int main() +{ + return !Harness::run(specification); +} diff --git a/TESTS/API/PWM_rise_fall/PWM_rise_fall.cpp b/TESTS/API/PWM_rise_fall/PWM_rise_fall.cpp new file mode 100644 index 0000000..9922645 --- /dev/null +++ b/TESTS/API/PWM_rise_fall/PWM_rise_fall.cpp @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +//#error [NOT_SUPPORTED] PWM tests are still being written and validated, not for public use yet. + +#if !DEVICE_PWMOUT + #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include +#include "ci_test_config.h" + +using namespace utest::v1; + +Timer duty_timer; +volatile int last_rise_time; +volatile int duty_rise_count; + +void duty_cbfn_rise(void){ + duty_rise_count++; + last_rise_time = duty_timer.read_ms(); +} + +volatile int duty_running_count; +volatile int duty_fall_count; + +void duty_cbfn_fall(void){ + duty_fall_count++; + if (last_rise_time == 0){ + // do nothing + } + else{ + duty_running_count = duty_running_count + (duty_timer.read_ms() - last_rise_time); + } +} + +// Template to test the Duty cycle API on PWM Pins. This test will collect a sample size of tests and average out the length of the duty cycle +// the averaged duty cycle is then compared against the expected duty cycle. +void PWM_Duty_slave(PinName pwm_out_pin, PinName int_in_pin, int period_in_ms, float duty_cycle_percent){ + #define NUM_TESTS 30 + PwmOut pwm(pwm_out_pin); + InterruptIn iin(int_in_pin); + duty_rise_count = 0; // reset counters + duty_fall_count = 0; + last_rise_time = 0; + duty_running_count = 0; + duty_timer.reset(); + iin.rise(duty_cbfn_rise); + iin.fall(duty_cbfn_fall); + DEBUG_PRINTF("\r\n*****\r\n period = %fs, duty cycle = %f ",(float)period_in_ms / 1000, duty_cycle_percent); + + pwm.period((float)period_in_ms / 1000); // set PWM period + duty_timer.start(); + pwm.write(duty_cycle_percent); // set duty cycle + wait_ms(NUM_TESTS*period_in_ms); + iin.disable_irq(); // This is here because otherwise it fails on some platforms + duty_timer.stop(); + + float avgTime = (float)duty_running_count / NUM_TESTS; + float expectedTime = (float)period_in_ms * duty_cycle_percent; + + DEBUG_PRINTF("\r\n rise_count = %d, fall count = %d, TotalTime = %d, avgTime = %f, expected time = %f ",duty_rise_count,duty_fall_count,duty_running_count,avgTime, expectedTime); + + float ten_percent = expectedTime * 0.1; + float five_percent = expectedTime * 0.05; + float one_percent = expectedTime * 0.01; + + DEBUG_PRINTF("\r\n .10 = %f, .05 = %f, .01 = %f\r\n*****\r\n",ten_percent,five_percent,one_percent); + + TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= ten_percent, "Greater than 10 percent variance between expected and measured duty cycle"); + TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= five_percent,"Greater than 5 percent variance between expected and measured duty cycle"); + //TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= one_percent, "Greater than 1 percent variance between expected and measured duty cycle"); +} + +// Template to iterate through a PWM pin, takes in period and tries 10%-100% duty cycle in intervals of 10% +template +void PWM_DutyCycle_Test(){ + #define DUTY_CYCLE_STEP 0.2f + #define MIN_DUTY_CYCLE 0.1f + #define MAX_DUTY_CYCLE 0.9f + + float x = 0; + for(x = MIN_DUTY_CYCLE; x < MAX_DUTY_CYCLE; x = x+DUTY_CYCLE_STEP){ // iterate duty cycle test + PWM_Duty_slave(pwm_out_pin, int_in_pin, period_in_miliseconds, x); + DEBUG_PRINTF("\r\n**************\r\n expected 10 cycles, saw %d rise, %d fall\r\n*******\r\n",duty_rise_count,duty_fall_count); + //TEST_ASSERT_MESSAGE(100 == rise_count,"Number of cycles not equivalent to amount expected\r\n"); + } +} + + +volatile int rise_count; +void cbfn_rise(void){ + rise_count++; +} + +volatile int fall_count; +void cbfn_fall(void){ + fall_count++; +} + +// Template to test that a PWM signal has the correct length by measuring the number of rise and fall +// interrupts during a specified number of tests. +template +void PWM_Period_Test(){ + // Initialize PWM, InterruptIn, Timer, and Rising / Falling edge counts + fall_count = 0; + rise_count = 0; + PwmOut pwm(pwm_out_pin); + InterruptIn iin(int_in_pin); + iin.rise(cbfn_rise); + iin.fall(cbfn_fall); + pwm.period((float)period_in_miliseconds/1000); + + //Start Testing + pwm.write(0.5f); // 50% duty cycle + wait_ms(num_tests * period_in_miliseconds); // wait for pwm to run and counts to add up + iin.disable_irq(); // This is here because otherwise it fails on some platforms + int rc = rise_count; // grab the numbers to work with as the pwm may continue going + int fc = fall_count; + + int expected_count = num_tests; + + float ten_percent = (expected_count * 0.1f); + float five_percent = (expected_count * 0.05f); + float one_percent = (expected_count * 0.01f); + + // fudge factor + if(ten_percent < 1){ + ten_percent = 1; + } + if(five_percent < 1){ + five_percent = 1; + } + if(one_percent < 1){ + one_percent = 1; + } + + DEBUG_PRINTF("\r\n*****\r\n rise count = %d, fall count = %d, expected count = %d",rc,fc,expected_count); + DEBUG_PRINTF("\r\n .10 = %f, .05 = %f, .01 = %f",ten_percent,five_percent,one_percent); + + TEST_ASSERT_MESSAGE( std::abs(rc-fc) <= ten_percent, "There was more than 10percent variance in number of rise vs fall cycles"); + TEST_ASSERT_MESSAGE( std::abs(rc-fc) <= five_percent,"There was more than 5percent variance in number of rise vs fall cycles"); + //TEST_ASSERT_MESSAGE( std::abs(rc-fc) <= one_percent, "There was more than 1percent variance in number of rise vs fall cycles"); + + DEBUG_PRINTF("\r\n abs(expected-rc) = %d",std::abs(expected_count - rc)); + TEST_ASSERT_MESSAGE( std::abs(expected_count - rc) <= ten_percent, "There was more than 10 percent variance in number of rise cycles seen and number expected."); + TEST_ASSERT_MESSAGE( std::abs(expected_count - rc) <= five_percent,"There was more than 5 percent variance in number of rise cycles seen and number expected."); + //TEST_ASSERT_MESSAGE( std::abs(expected_count - rc) <= one_percent, "There was more than 1 percent variance in number of rise cycles seen and number expected."); + + DEBUG_PRINTF("\r\n abs(expected-fc) = %d\r\n*****\r\n",std::abs(expected_count - fc)); + TEST_ASSERT_MESSAGE( std::abs(expected_count - fc) <= ten_percent, "There was more than 10 percent variance in number of fall cycles seen and number expected."); + TEST_ASSERT_MESSAGE( std::abs(expected_count - fc) <= five_percent,"There was more than 5 percent variance in number of fall cycles seen and number expected."); + //TEST_ASSERT_MESSAGE( std::abs(expected_count - fc) <= one_percent, "There was more than 1 percent variance in number of fall cycles seen and number expected."); +} + +// test if software constructor / destructor works +void pwm_define_test(){ + PwmOut pwm0(MBED_CONF_APP_PWM_0); + PwmOut pwm1(MBED_CONF_APP_PWM_1); + PwmOut pwm2(MBED_CONF_APP_PWM_2); + PwmOut pwm3(MBED_CONF_APP_PWM_3); + + pwm0.period(1.0f); + pwm1.period(1.0f); + pwm2.period(1.0f); + pwm3.period(1.0f); + + pwm0.write(0.5f); + pwm1.write(0.5f); + pwm2.write(0.5f); + pwm3.write(0.5f); + + TEST_ASSERT_MESSAGE(true,"The fact that it hasnt errored out proves this passes the sniff test"); +} + +utest::v1::status_t test_setup(const size_t number_of_cases){ + // Setup Greentea using a reasonable timeout in seconds + GREENTEA_SETUP(200, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + +// Handle test failures, keep testing, dont stop +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason){ + greentea_case_failure_abort_handler(source, reason); + return STATUS_CONTINUE; +} + +// Test cases +// TODO: take pin names from config file or generate from pinmap file +Case cases[] = { + // Test Creat PwmOut Objects + Case("Pwm object definable", pwm_define_test,greentea_failure_handler), // test pwm object constructor works + + // Test Frequency length by counting rise / fall ticks + Case("PWM_0 Frequency 10ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 10, 1000 >, greentea_failure_handler), // Test at 10ms 1000 times, default 50%duty cycle + Case("PWM_0 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_0 Frequency 100ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 100, 100 >, greentea_failure_handler), // Test at 100ms 100 times, default 50%duty cycle + //Case("PWM_0 Frequency 500ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 500, 20 >, greentea_failure_handler), // Test at 500ms 20 times, default 50%duty cycle + Case("PWM_1 Frequency 10ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 10, 1000 >, greentea_failure_handler), // Test at 10ms 1000 times, default 50%duty cycle + Case("PWM_1 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_1 Frequency 100ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 100, 100 >, greentea_failure_handler), // Test at 100ms 100 times, default 50%duty cycle + //Case("PWM_1 Frequency 500ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 500, 20 >, greentea_failure_handler), // Test at 500ms 20 times, default 50%duty cycle + Case("PWM_2 Frequency 10ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 10, 1000 >, greentea_failure_handler), // Test at 10ms 1000 times, default 50%duty cycle + Case("PWM_2 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_2 Frequency 100ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 100, 100 >, greentea_failure_handler), // Test at 100ms 100 times, default 50%duty cycle + //Case("PWM_2 Frequency 500ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 500, 20 >, greentea_failure_handler), // Test at 500ms 20 times, default 50%duty cycle + Case("PWM_3 Frequency 10ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 10, 1000 >, greentea_failure_handler), // Test at 10ms 1000 times, default 50%duty cycle + Case("PWM_3 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle + Case("PWM_3 Frequency 100ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 100, 100 >, greentea_failure_handler), // Test at 100ms 100 times, default 50%duty cycle + //Case("PWM_3 Frequency 500ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 500, 20 >, greentea_failure_handler), // Test at 500ms 20 times, default 50%duty cycle + + // Test Duty Cycle width (10%->90%) + Case("PWM_0 Duty Cycle 10ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 10 >, greentea_failure_handler), // Test 10ms Frequency with 10% to 90% duty cycle + Case("PWM_0 Duty Cycle 30ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 30 >, greentea_failure_handler), // Test 30ms Frequency with 10% to 90% duty cycle + Case("PWM_0 Duty Cycle 100ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 100>, greentea_failure_handler), // Test 100ms Frequency with 10% to 90% duty cycle + //Case("PWM_0 Duty Cycle 500ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 500 >, greentea_failure_handler), // Test 500ms Frequency with 10% to 90% duty cycle + Case("PWM_1 Duty Cycle 10ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 10 >, greentea_failure_handler), // Test 10ms Frequency with 10% to 90% duty cycle + Case("PWM_1 Duty Cycle 30ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 30 >, greentea_failure_handler), // Test 30ms Frequency with 10% to 90% duty cycle + Case("PWM_1 Duty Cycle 100ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 100>, greentea_failure_handler), // Test 100ms Frequency with 10% to 90% duty cycle + //Case("PWM_1 Duty Cycle 500ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 500>, greentea_failure_handler), // Test 500ms Frequency with 10% to 90% duty cycle + Case("PWM_2 Duty Cycle 10ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 10 >, greentea_failure_handler), // Test 10ms Frequency with 10% to 90% duty cycle + Case("PWM_2 Duty Cycle 30ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 30 >, greentea_failure_handler), // Test 30ms Frequency with 10% to 90% duty cycle + Case("PWM_2 Duty Cycle 100ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 100>, greentea_failure_handler), // Test 100ms Frequency with 10% to 90% duty cycle + //Case("PWM_2 Duty Cycle 500ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 500>, greentea_failure_handler), // Test 500ms Frequency with 10% to 90% duty cycle + Case("PWM_3 Duty Cycle 10ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 10 >, greentea_failure_handler), // Test 10ms Frequency with 10% to 90% duty cycle + Case("PWM_3 Duty Cycle 30ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 30 >, greentea_failure_handler), // Test 30ms Frequency with 10% to 90% duty cycle + Case("PWM_3 Duty Cycle 100ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 100>, greentea_failure_handler), // Test 100ms Frequency with 10% to 90% duty cycle + //Case("PWM_3 Duty Cycle 500ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 500>, greentea_failure_handler), // Test 500ms Frequency with 10% to 90% duty cycle +}; + +Specification specification(test_setup, cases); + +// Entry point into the tests +int main(){ + return !Harness::run(specification); +} diff --git a/TESTS/API/Pwm/Pwm.cpp b/TESTS/API/Pwm/Pwm.cpp deleted file mode 100644 index 4d752bd..0000000 --- a/TESTS/API/Pwm/Pwm.cpp +++ /dev/null @@ -1,262 +0,0 @@ -/* - * Copyright (c) 2016 ARM Limited - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -//#error [NOT_SUPPORTED] PWM tests are still being written and validated, not for public use yet. - -#if !DEVICE_PWMOUT - #error [NOT_SUPPORTED] PWMOUT not supported on this platform, add 'DEVICE_PWMOUT' definition to your platform. -#endif - -#include "mbed.h" -#include "greentea-client/test_env.h" -#include "unity.h" -#include "utest.h" -#include -#include "ci_test_config.h" - -using namespace utest::v1; - -Timer duty_timer; -volatile int last_rise_time; -volatile int duty_rise_count; - -void duty_cbfn_rise(void){ - duty_rise_count++; - last_rise_time = duty_timer.read_ms(); -} - -volatile int duty_running_count; -volatile int duty_fall_count; - -void duty_cbfn_fall(void) -{ - duty_fall_count++; - if (last_rise_time == 0) { - // do nothing - } else { - duty_running_count = duty_running_count + (duty_timer.read_ms() - last_rise_time); - } -} - -// Template to test the Duty cycle API on PWM Pins. This test will collect a sample size of tests and average out the length of the duty cycle -// the averaged duty cycle is then compared against the expected duty cycle. -void PWM_Duty_slave(PinName pwm_out_pin, PinName int_in_pin, int period_in_ms, float duty_cycle_percent) -{ - #define NUM_TESTS 30 - PwmOut pwm(pwm_out_pin); - InterruptIn iin(int_in_pin); - duty_rise_count = 0; // reset counters - duty_fall_count = 0; - last_rise_time = 0; - duty_running_count = 0; - duty_timer.reset(); - iin.rise(duty_cbfn_rise); - iin.fall(duty_cbfn_fall); - DEBUG_PRINTF("\r\n*****\r\n period = %fs, duty cycle = %f ",(float)period_in_ms / 1000, duty_cycle_percent); - - pwm.period((float)period_in_ms / 1000); // set PWM period - duty_timer.start(); - pwm.write(duty_cycle_percent); // set duty cycle - wait_ms(NUM_TESTS*period_in_ms); - iin.disable_irq(); // This is here because otherwise it fails on some platforms - duty_timer.stop(); - - float avgTime = (float)duty_running_count / NUM_TESTS; - float expectedTime = (float)period_in_ms * duty_cycle_percent; - - DEBUG_PRINTF("\r\n rise_count = %d, fall count = %d, TotalTime = %d, avgTime = %f, expected time = %f ",duty_rise_count,duty_fall_count,duty_running_count,avgTime, expectedTime); - - float ten_percent = expectedTime * 0.1; - float five_percent = expectedTime * 0.05; - float one_percent = expectedTime * 0.01; - - DEBUG_PRINTF("\r\n .10 = %f, .05 = %f, .01 = %f\r\n*****\r\n",ten_percent,five_percent,one_percent); - - TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= ten_percent, "Greater than 10 percent variance between expected and measured duty cycle"); - TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= five_percent,"Greater than 5 percent variance between expected and measured duty cycle"); - //TEST_ASSERT_MESSAGE( std::abs(expectedTime - avgTime) <= one_percent, "Greater than 1 percent variance between expected and measured duty cycle"); -} - -// Template to iterate through a PWM pin, takes in period and tries 10%-100% duty cycle in intervals of 10% -template -void PWM_DutyCycle_Test() -{ - #define DUTY_CYCLE_STEP 0.2f - #define MIN_DUTY_CYCLE 0.1f - #define MAX_DUTY_CYCLE 0.9f - - float x = 0; - for(x = MIN_DUTY_CYCLE; x < MAX_DUTY_CYCLE; x = x+DUTY_CYCLE_STEP){ // iterate duty cycle test - PWM_Duty_slave(pwm_out_pin, int_in_pin, period_in_miliseconds, x); - DEBUG_PRINTF("\r\n**************\r\n expected 10 cycles, saw %d rise, %d fall\r\n*******\r\n",duty_rise_count,duty_fall_count); - //TEST_ASSERT_MESSAGE(100 == rise_count,"Number of cycles not equivalent to amount expected\r\n"); - } -} - - -volatile int rise_count; -void cbfn_rise(void) -{ - rise_count++; -} - -volatile int fall_count; -void cbfn_fall(void) -{ - fall_count++; -} - -// Template to test that a PWM signal has the correct length by measuring the number of rise and fall -// interrupts during a specified number of tests. -template -void PWM_Period_Test() -{ - // Initialize PWM, InterruptIn, Timer, and Rising / Falling edge counts - fall_count = 0; - rise_count = 0; - PwmOut pwm(pwm_out_pin); - InterruptIn iin(int_in_pin); - iin.rise(cbfn_rise); - iin.fall(cbfn_fall); - pwm.period((float)period_in_miliseconds/1000); - - //Start Testing - pwm.write(0.5f); // 50% duty cycle - wait_ms(num_tests * period_in_miliseconds); // wait for pwm to run and counts to add up - iin.disable_irq(); // This is here because otherwise it fails on some platforms - int rc = rise_count; // grab the numbers to work with as the pwm may continue going - int fc = fall_count; - - int expected_count = num_tests; - - float ten_percent = (expected_count * 0.1f); - float five_percent = (expected_count * 0.05f); - float one_percent = (expected_count * 0.01f); - - // fudge factor - if(ten_percent < 1) { - ten_percent = 1; - } - if(five_percent < 1) { - five_percent = 1; - } - if(one_percent < 1) { - one_percent = 1; - } - - DEBUG_PRINTF("\r\n*****\r\n rise count = %d, fall count = %d, expected count = %d",rc,fc,expected_count); - DEBUG_PRINTF("\r\n .10 = %f, .05 = %f, .01 = %f",ten_percent,five_percent,one_percent); - - TEST_ASSERT_MESSAGE( std::abs(rc-fc) <= ten_percent, "There was more than 10percent variance in number of rise vs fall cycles"); - TEST_ASSERT_MESSAGE( std::abs(rc-fc) <= five_percent,"There was more than 5percent variance in number of rise vs fall cycles"); - //TEST_ASSERT_MESSAGE( std::abs(rc-fc) <= one_percent, "There was more than 1percent variance in number of rise vs fall cycles"); - - DEBUG_PRINTF("\r\n abs(expected-rc) = %d",std::abs(expected_count - rc)); - TEST_ASSERT_MESSAGE( std::abs(expected_count - rc) <= ten_percent, "There was more than 10 percent variance in number of rise cycles seen and number expected."); - TEST_ASSERT_MESSAGE( std::abs(expected_count - rc) <= five_percent,"There was more than 5 percent variance in number of rise cycles seen and number expected."); - //TEST_ASSERT_MESSAGE( std::abs(expected_count - rc) <= one_percent, "There was more than 1 percent variance in number of rise cycles seen and number expected."); - - DEBUG_PRINTF("\r\n abs(expected-fc) = %d\r\n*****\r\n",std::abs(expected_count - fc)); - TEST_ASSERT_MESSAGE( std::abs(expected_count - fc) <= ten_percent, "There was more than 10 percent variance in number of fall cycles seen and number expected."); - TEST_ASSERT_MESSAGE( std::abs(expected_count - fc) <= five_percent,"There was more than 5 percent variance in number of fall cycles seen and number expected."); - //TEST_ASSERT_MESSAGE( std::abs(expected_count - fc) <= one_percent, "There was more than 1 percent variance in number of fall cycles seen and number expected."); -} - -// test if software constructor / destructor works -void pwm_define_test() -{ - PwmOut pwm0(MBED_CONF_APP_PWM_0); - PwmOut pwm1(MBED_CONF_APP_PWM_1); - PwmOut pwm2(MBED_CONF_APP_PWM_2); - PwmOut pwm3(MBED_CONF_APP_PWM_3); - - pwm0.period(1.0f); - pwm1.period(1.0f); - pwm2.period(1.0f); - pwm3.period(1.0f); - - pwm0.write(0.5f); - pwm1.write(0.5f); - pwm2.write(0.5f); - pwm3.write(0.5f); - - TEST_ASSERT_MESSAGE(true,"The fact that it hasnt errored out proves this passes the sniff test"); -} - -utest::v1::status_t test_setup(const size_t number_of_cases) -{ - // Setup Greentea using a reasonable timeout in seconds - GREENTEA_SETUP(200, "default_auto"); - return verbose_test_setup_handler(number_of_cases); -} - -// Handle test failures, keep testing, dont stop -utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) -{ - greentea_case_failure_abort_handler(source, reason); - return STATUS_CONTINUE; -} - -// Test cases -// TODO: take pin names from config file or generate from pinmap file -Case cases[] = { - // Test Creat PwmOut Objects - Case("Pwm object definable", pwm_define_test,greentea_failure_handler), // test pwm object constructor works - - // Test Frequency length by counting rise / fall ticks - Case("PWM_0 Frequency 10ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 10, 1000 >, greentea_failure_handler), // Test at 10ms 100 times, default 50%duty cycle - Case("PWM_0 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle - Case("PWM_0 Frequency 100ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 100, 100 >, greentea_failure_handler), // Test at 100ms 100 times, default 50%duty cycle - //Case("PWM_0 Frequency 500ms", PWM_Period_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 500, 20 >, greentea_failure_handler), // Test at 500ms 20 times, default 50%duty cycle - Case("PWM_1 Frequency 10ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 10, 1000 >, greentea_failure_handler), // Test at 10ms 100 times, default 50%duty cycle - Case("PWM_1 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle - Case("PWM_1 Frequency 100ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 100, 100 >, greentea_failure_handler), // Test at 100ms 100 times, default 50%duty cycle - //Case("PWM_1 Frequency 500ms", PWM_Period_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 500, 20 >, greentea_failure_handler), // Test at 500ms 20 times, default 50%duty cycle - Case("PWM_2 Frequency 10ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 10, 1000 >, greentea_failure_handler), // Test at 10ms 100 times, default 50%duty cycle - Case("PWM_2 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle - Case("PWM_2 Frequency 100ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 100, 100 >, greentea_failure_handler), // Test at 100ms 100 times, default 50%duty cycle - //Case("PWM_2 Frequency 500ms", PWM_Period_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 500, 20 >, greentea_failure_handler), // Test at 500ms 20 times, default 50%duty cycle - Case("PWM_3 Frequency 10ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 10, 1000 >, greentea_failure_handler), // Test at 10ms 100 times, default 50%duty cycle - Case("PWM_3 Frequency 30ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 30, 100 >, greentea_failure_handler), // Test at 30ms 100 times, default 50%duty cycle - Case("PWM_3 Frequency 100ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 100, 100 >, greentea_failure_handler), // Test at 100ms 100 times, default 50%duty cycle - //Case("PWM_3 Frequency 500ms", PWM_Period_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 500, 20 >, greentea_failure_handler), // Test at 500ms 20 times, default 50%duty cycle - - // Test Duty Cycle width (10%->90%) - Case("PWM_0 Duty Cycle 10ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 10 >, greentea_failure_handler), // Test 10ms Frequency with 10% to 90% duty cycle - Case("PWM_0 Duty Cycle 30ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 30 >, greentea_failure_handler), // Test 30ms Frequency with 10% to 90% duty cycle - Case("PWM_0 Duty Cycle 100ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 100>, greentea_failure_handler), // Test 100ms Frequency with 10% to 90% duty cycle - //Case("PWM_0 Duty Cycle 500ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_0, MBED_CONF_APP_DIO_2, 500 >, greentea_failure_handler), // Test 500ms Frequency with 10% to 90% duty cycle - Case("PWM_1 Duty Cycle 10ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 10 >, greentea_failure_handler), // Test 10ms Frequency with 10% to 90% duty cycle - Case("PWM_1 Duty Cycle 30ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 30 >, greentea_failure_handler), // Test 30ms Frequency with 10% to 90% duty cycle - Case("PWM_1 Duty Cycle 100ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 100>, greentea_failure_handler), // Test 100ms Frequency with 10% to 90% duty cycle - //Case("PWM_1 Duty Cycle 500ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_1, MBED_CONF_APP_DIO_4, 500>, greentea_failure_handler), // Test 500ms Frequency with 10% to 90% duty cycle - Case("PWM_2 Duty Cycle 10ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 10 >, greentea_failure_handler), // Test 10ms Frequency with 10% to 90% duty cycle - Case("PWM_2 Duty Cycle 30ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 30 >, greentea_failure_handler), // Test 30ms Frequency with 10% to 90% duty cycle - Case("PWM_2 Duty Cycle 100ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 100>, greentea_failure_handler), // Test 100ms Frequency with 10% to 90% duty cycle - //Case("PWM_2 Duty Cycle 500ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_2, MBED_CONF_APP_DIO_7, 500>, greentea_failure_handler), // Test 500ms Frequency with 10% to 90% duty cycle - Case("PWM_3 Duty Cycle 10ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 10 >, greentea_failure_handler), // Test 10ms Frequency with 10% to 90% duty cycle - Case("PWM_3 Duty Cycle 30ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 30 >, greentea_failure_handler), // Test 30ms Frequency with 10% to 90% duty cycle - Case("PWM_3 Duty Cycle 100ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 100>, greentea_failure_handler), // Test 100ms Frequency with 10% to 90% duty cycle - //Case("PWM_3 Duty Cycle 500ms", PWM_DutyCycle_Test< MBED_CONF_APP_PWM_3, MBED_CONF_APP_DIO_8, 500>, greentea_failure_handler), // Test 500ms Frequency with 10% to 90% duty cycle -}; - -Specification specification(test_setup, cases); - -// Entry point into the tests -int main() -{ - return !Harness::run(specification); -} diff --git a/TESTS/concurrent/Comms/Comms.cpp b/TESTS/concurrent/Comms/Comms.cpp new file mode 100644 index 0000000..de61d48 --- /dev/null +++ b/TESTS/concurrent/Comms/Comms.cpp @@ -0,0 +1,217 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#if !DEVICE_SPI // check if SPI is supported on this device + #error [NOT_SUPPORTED] SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. + +#elif !DEVICE_I2C // check if I2C is supported on this device + #error [NOT_SUPPORTED] I2C not supported on this platform, add 'DEVICE_I2C' definition to your platform. + +#endif // !DEVICE_SPI or !DEVICE_I2C + + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" +#include "FATFileSystem.h" +#include "SDBlockDevice.h" +#include + +using namespace utest::v1; + +#define TEST_STRING_MAX 128 + +Thread Thread_I2C; // thread used in multithread tests +Thread Thread_SPI; // thread used in multithread tests +osThreadId Multi_Thread_ID; // thread id for main function controlling multithread tests +char Test_String[TEST_STRING_MAX] = {0}; // reference string used in testing + +// Fill array with random characters. TODO: make this string a randomly generated thing +void init_string() +{ + for(int x = 0; x < TEST_STRING_MAX-1; x++){ + Test_String[x] = 'A' + (rand() % 26); + } + Test_String[TEST_STRING_MAX-1] = 0; + + DEBUG_PRINTF("\r\n****\r\n Test_String Size(Bytes) = %d\r\n Test_String = %s\r\n****\r\n",TEST_STRING_MAX,Test_String); +} + + +// test I2C API by writting and reading from EEPROM +void test_I2C() +{ + // initialize variables and API + int address = 0; // starting address to write to + int num_read = 0; // will report number of bytes read + int num_written = 0; // will report number of bytes written + volatile char read_string[TEST_STRING_MAX] = {0}; // string that will be updated from reading EEPROM + I2CEeprom memory(MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + + // write to EEPROM + num_written = memory.write(address,Test_String,TEST_STRING_MAX); + + // read back from EEPROM + num_read = memory.read(address,(char *)read_string,TEST_STRING_MAX); + + // test for equality + TEST_ASSERT_EQUAL_STRING_MESSAGE(Test_String,(char *)read_string,"String read does not match the string written"); // test that strings match + TEST_ASSERT_EQUAL_MESSAGE(num_written,num_read,"Number of bytes written does not match the number of bytes read"); + DEBUG_PRINTF("\r\n****\r\n I2C TEST:\r\n Address = `%d`\r\n Num Bytes Written = `%d` \r\n Num Bytes Read = `%d` \r\n String written = `%s` \r\n String read = `%s` \r\n****\r\n",address,num_written,num_read,Test_String,read_string); + osSignalSet(Multi_Thread_ID, 0x1); // signal completion of thread +} + + +// test SPI API by writing and reading from SD card +void test_SPI() +{ + // initialze SD hardware, filesystem, and variables + SDBlockDevice sd(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_CS); + FATFileSystem fs("sd", &sd); + sd.init(); + fs.mount(&sd); + FILE *File = fopen("/sd/test_sd_w.txt", "w"); + TEST_ASSERT_MESSAGE(File != NULL,"SD Card is not present. Please insert an SD Card."); + volatile char read_string[TEST_STRING_MAX] = {0}; + + // write data to SD card + int error = fprintf(File, Test_String); // write data + TEST_ASSERT_MESSAGE(error > 0,"Writing file to sd card failed"); // error checking + fclose(File); // close file on SD + + // read data from SD card + File = fopen("/sd/test_sd_w.txt", "r"); + fgets((char *)read_string,TEST_STRING_MAX,File); // read string from the file + + // test for equality + TEST_ASSERT_EQUAL_STRING_MESSAGE(Test_String,(char *)read_string,"String read does not match the string written"); // test that strings match + DEBUG_PRINTF("\r\n****\r\n SPI TEST:\r\n String written = `%s` \r\n String read = `%s` \r\n****\r\n",Test_String,read_string); + + // close, unmount, and deinitialize + fclose(File); // close file on SD + fs.unmount(); + sd.deinit(); + osSignalSet(Multi_Thread_ID, 0x2); // signal completion of thread +} + + +// test I2C and SPI APIs concurrently in multiple threads +void test_multiple_threads() +{ + Multi_Thread_ID = Thread::gettid(); // update thread id for this thread + Thread_I2C.start(callback(test_I2C)); // kick off threads + Thread_SPI.start(callback(test_SPI)); // kick off threads + wait(0.1); // allow time for debug print statements to complete. + + // Use this to wait for both signaling events to occur + // Internaly the code is doing something like this: + // if ((signal1 | signal2) & 0x3 == 0x3) then exit, else wait + osSignalWait(0x3, osWaitForever); +} + + +// test I2C and SPI APIs concurrently in a single thread +void test_single_thread() +{ + // ******************************* + // Initialize variables and APIs + // ******************************* + + // I2C test initializations + int address = 0; // starting address to write to in EEPROM + int num_read = 0; // will report number of bytes read + int num_written = 0; // will report number of bytes written + volatile char read_string_i2c[TEST_STRING_MAX] = {0}; // string that will be updated from reading EEPROM + I2CEeprom memory(MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + + // SPI test initializations + volatile char read_string_spi[TEST_STRING_MAX] = {0}; // string that will be updated from reading SD card + SDBlockDevice sd(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_CS); + FATFileSystem fs("sd", &sd); + sd.init(); + fs.mount(&sd); + FILE *File = fopen("/sd/test_sd_w.txt", "w"); + TEST_ASSERT_MESSAGE(File != NULL,"SD Card is not present. Please insert an SD Card."); + + // ****************************** + // Begin concurrent API testing + // ****************************** + // write to EEPROM using I2C + num_written = memory.write(address,Test_String,TEST_STRING_MAX); + + // write to SD card using SPI + int error = fprintf(File, Test_String); // write data + TEST_ASSERT_MESSAGE(error > 0,"Writing file to sd card failed"); // error checking + fclose(File); // close file on SD + + // read back from EEPROM + num_read = memory.read(address,(char *)read_string_i2c,TEST_STRING_MAX); + + // read data from SD card + File = fopen("/sd/test_sd_w.txt", "r"); + fgets((char *)read_string_spi,TEST_STRING_MAX,File); // read string from the file + + // ****************************** + // Check results + // ****************************** + + // test results for I2C + TEST_ASSERT_EQUAL_STRING_MESSAGE(Test_String,(char *)read_string_i2c,"String read does not match the string written"); // test that strings match + TEST_ASSERT_EQUAL_MESSAGE(num_written,num_read,"Number of bytes written does not match the number of bytes read"); + DEBUG_PRINTF("\r\n****\r\n I2C TEST:\r\n Address = `%d`\r\n Num Bytes Written = `%d` \r\n Num Bytes Read = `%d` \r\n String written = `%s` \r\n String read = `%s` \r\n****\r\n",address,num_written,num_read,Test_String,read_string_i2c); + + // test results for SPI + TEST_ASSERT_EQUAL_STRING_MESSAGE(Test_String,(char *)read_string_spi,"String read does not match the string written"); // test that strings match + DEBUG_PRINTF("\r\n****\r\n SPI TEST:\r\n String written = `%s` \r\n String read = `%s` \r\n****\r\n",Test_String,read_string_spi); + fclose(File); // close file on SD + fs.unmount(); // unmount + sd.deinit(); // deinitialize SD +} + + +utest::v1::status_t test_setup(const size_t number_of_cases) +{ + // Setup Greentea using a reasonable timeout in seconds + GREENTEA_SETUP(40, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + + +// Handle test failures, keep testing, dont stop +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) +{ + greentea_case_failure_abort_handler(source, reason); + return STATUS_CONTINUE; +} + + +// Test cases +Case cases[] = { + Case("Concurrent testing of I2C and SPI in a single thread",test_single_thread,greentea_failure_handler), + Case("Concurrent testing of I2C and SPI in multiple threads",test_multiple_threads,greentea_failure_handler), +}; + + +Specification specification(test_setup, cases); + +// // Entry point into the tests +int main() { + init_string(); + return !Harness::run(specification); +} diff --git a/TESTS/concurrent/GPIO/GPIO.cpp b/TESTS/concurrent/GPIO/GPIO.cpp new file mode 100755 index 0000000..13b6266 --- /dev/null +++ b/TESTS/concurrent/GPIO/GPIO.cpp @@ -0,0 +1,145 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#if !DEVICE_ANALOGIN + #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. +#endif + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" + +using namespace utest::v1; + +volatile bool Result = false; + +// Callback for all InterruptInput functions +void cbfn(void) +{ + Result = true; +} + + +// Template to test DigitalIO, AnalogIn, and InterruptIn pins. Meant to be re-used multiple times +template + + +void GPIO_Test() +{ + // *********************** + // Initialize API pins + // *********************** + DEBUG_PRINTF("Initializing API pins\n"); + // Pins for DIO test + DigitalOut d_out(digitalOut_pin); + DigitalIn d_in(digitalIn_pin); + + // Pins for AnalogIn test + AnalogIn a_in(analogIn_pin); + BusInOut aBus_outputs(analogBus_pin1,analogBus_pin2,analogBus_pin3,analogBus_pin4,analogBus_pin5); + + // Pins for InterruptIn test + InterruptIn int_in(interruptIn_pin); + DigitalOut int_out(interruptOut_pin); + + // *********************** + // Begin concurrent API testing + // *********************** + DEBUG_PRINTF("Begining concurrent API testing\n"); + aBus_outputs.output(); + int analogOut_value= 0; + aBus_outputs = 0; + float prev_analog_value = 0; + for(int iter = 0; iter<5; iter++) { + // DigitalIO test + d_out = 0; // test 0 + TEST_ASSERT_MESSAGE(0 == d_in.read(),"Expected value to be 0, read value was not zero"); + d_out = 1; // test 1 + TEST_ASSERT_MESSAGE(1 == d_in.read(),"Expected value to be 1, read value was not one"); + + // AnalogIn test + prev_analog_value = a_in.read(); + analogOut_value = (analogOut_value << 1) + 1; + aBus_outputs = analogOut_value; + TEST_ASSERT_MESSAGE(a_in.read() > prev_analog_value,"Analog Input did not increment."); + + // Rising Edge InterruptIn test + Result = false; + int_out = 0; + int_in.rise(cbfn); + int_out = 1; + wait(0); // dummy wait to get volatile result value + TEST_ASSERT_MESSAGE(Result,"cbfn was not triggered on rising edge of pin"); + + // Falling Edge InterruptIn test + Result = false; + int_out = 1; + int_in.fall(cbfn); + int_out = 0; + wait(0); // dummy wait to get volatile result value + TEST_ASSERT_MESSAGE(Result,"cbfn was not triggered on falling edge of pin"); + } +} + + +utest::v1::status_t test_setup(const size_t number_of_cases) +{ + // Setup Greentea using a reasonable timeout in seconds + GREENTEA_SETUP(30, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + + +// Handle test failures, keep testing, dont stop +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) +{ + greentea_case_failure_abort_handler(source, reason); + return STATUS_CONTINUE; +} + + +// Test cases +// Runs three different APIs concurrently, DIO, AnalogIn, and InterruptIn +Case cases[] = { + Case("Concurrent testing of DIO(D2,D3), AnalogIn(A0), and InterruptIn(D4,D5)",GPIO_Test,greentea_failure_handler), + + Case("Concurrent testing of DIO(D3,D2), AnalogIn(A1), and InterruptIn(D5,D4)",GPIO_Test,greentea_failure_handler), + + Case("Concurrent testing of DIO(D4,D5), AnalogIn(A2), and InterruptIn(D6,D7)",GPIO_Test,greentea_failure_handler), + + Case("Concurrent testing of DIO(D5,D4), AnalogIn(A3), and InterruptIn(D7,D6)",GPIO_Test,greentea_failure_handler), + + Case("Concurrent testing of DIO(D6,D7), AnalogIn(A4), and InterruptIn(D8,D9)",GPIO_Test,greentea_failure_handler), + + Case("Concurrent testing of DIO(D7,D6), AnalogIn(A5), and InterruptIn(D9,D8)",GPIO_Test,greentea_failure_handler), + + Case("Concurrent testing of DIO(D8,D9), AnalogIn(A5), and InterruptIn(D2,D3)",GPIO_Test,greentea_failure_handler), + + Case("Concurrent testing of DIO(D9,D8), AnalogIn(A5), and InterruptIn(D3,D2)",GPIO_Test,greentea_failure_handler), +}; + + +Specification specification(test_setup, cases); + + +// Entry point into the tests +int main() +{ + return !Harness::run(specification); +} diff --git a/TESTS/concurrent/Mixed/Mixed.cpp b/TESTS/concurrent/Mixed/Mixed.cpp new file mode 100644 index 0000000..f7ee86b --- /dev/null +++ b/TESTS/concurrent/Mixed/Mixed.cpp @@ -0,0 +1,331 @@ +/* + * Copyright (c) 2016 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + + +#if !DEVICE_SPI // check if SPI is supported on this device + #error [NOT_SUPPORTED] SPI is not supported on this platform, add 'DEVICE_SPI' definition to your platform. + +#elif !DEVICE_I2C // check if I2C is supported on this device + #error [NOT_SUPPORTED] I2C not supported on this platform, add 'DEVICE_I2C' definition to your platform. + +#elif !DEVICE_ANALOGIN + #error [NOT_SUPPORTED] AnalogIn not supported on this platform, add 'DEVICE_ANALOGIN' definition to your platform. + +#endif // !DEVICE_SPI or !DEVICE_I2C or !DEVICE_ANALOGIN + + +#include "mbed.h" +#include "greentea-client/test_env.h" +#include "unity.h" +#include "utest.h" +#include "ci_test_config.h" +#include "FATFileSystem.h" +#include "SDBlockDevice.h" +#include + +using namespace utest::v1; + +#define TEST_STRING_MAX 128 + +Thread Thread_I2C; // thread used in multithread tests +Thread Thread_SPI; // thread used in multithread tests +Thread Thread_GPIO; // thread used in multithread tests +osThreadId Multi_Thread_ID; // thread id for main function controlling multithread tests +char Test_String[TEST_STRING_MAX] = {0}; // reference string used in testing +volatile bool GPIO_Result = false; // flag used in GPIO testing + +// Fill array with random characters. TODO: make this string a randomly generated thing +void init_string() +{ + for(int x = 0; x < TEST_STRING_MAX-1; x++){ + Test_String[x] = 'A' + (rand() % 26); + } + Test_String[TEST_STRING_MAX-1] = 0; +} + + +// test I2C API by writting and reading from EEPROM +void test_I2C() +{ + // initialize variables and API + int address = 0; // starting address to write to + int num_read = 0; // will report number of bytes read + int num_written = 0; // will report number of bytes written + volatile char read_string[TEST_STRING_MAX] = {0}; // string that will be updated from reading EEPROM + I2CEeprom memory(MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + + // write to EEPROM + num_written = memory.write(address,Test_String,TEST_STRING_MAX); + + // read back from EEPROM + num_read = memory.read(address,(char *)read_string,TEST_STRING_MAX); + + // test for equality + TEST_ASSERT_EQUAL_STRING_MESSAGE(Test_String,(char *)read_string,"String read does not match the string written"); // test that strings match + TEST_ASSERT_EQUAL_MESSAGE(num_written,num_read,"Number of bytes written does not match the number of bytes read"); + DEBUG_PRINTF("\r\n****\r\n I2C thread test:\r\n Address = `%d`\r\n Num Bytes Written = `%d` \r\n Num Bytes Read = `%d` \r\n String written = `%s` \r\n String read = `%s` \r\n****\r\n",address,num_written,num_read,Test_String,read_string); + osSignalSet(Multi_Thread_ID, 0x1); // signal completion of thread +} + + +// test SPI API by writing and reading from SD card +void test_SPI() +{ + // initialze SD hardware, filesystem, and variables + SDBlockDevice sd(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_CS); + FATFileSystem fs("sd", &sd); + sd.init(); + fs.mount(&sd); + FILE *File = fopen("/sd/test_sd_w.txt", "w"); + TEST_ASSERT_MESSAGE(File != NULL,"SD Card is not present. Please insert an SD Card."); + volatile char read_string[TEST_STRING_MAX] = {0}; + + // write data to SD card + int error = fprintf(File, Test_String); // write data + TEST_ASSERT_MESSAGE(error > 0,"Writing file to sd card failed"); // error checking + fclose(File); // close file on SD + + // read data from SD card + File = fopen("/sd/test_sd_w.txt", "r"); + fgets((char *)read_string,TEST_STRING_MAX,File); // read string from the file + + // test for equality + TEST_ASSERT_EQUAL_STRING_MESSAGE(Test_String,(char *)read_string,"String read does not match the string written"); // test that strings match + DEBUG_PRINTF("\r\n****\r\n SPI thread test:\r\n String written = `%s` \r\n String read = `%s` \r\n****\r\n",Test_String,read_string); + + // close, unmount, and deinitialize + fclose(File); // close file on SD + fs.unmount(); + sd.deinit(); + osSignalSet(Multi_Thread_ID, 0x2); // signal completion of thread +} + + +// Callback for all InterruptInput functions +void cbfn(void) +{ + GPIO_Result = true; +} + + +void test_GPIO() +{ + // *********************** + // Initialize GPIO pins + // *********************** + DEBUG_PRINTF("\r\n****\r\n GPIO thread test\r\n****\r\n"); + // Pins for DIO test + DigitalOut d_out(MBED_CONF_APP_DIO_2); + DigitalIn d_in(MBED_CONF_APP_DIO_3); + + // Pins for AnalogIn test + AnalogIn a_in(MBED_CONF_APP_AIN_0); + BusInOut aBus_outputs(MBED_CONF_APP_AIN_1,MBED_CONF_APP_AIN_2,MBED_CONF_APP_AIN_3,MBED_CONF_APP_AIN_4,MBED_CONF_APP_AIN_5); + + // Pins for InterruptIn test + InterruptIn int_in(MBED_CONF_APP_DIO_4); + DigitalOut int_out(MBED_CONF_APP_DIO_5); + + // *********************** + // Begin concurrent GPIO testing + // *********************** + aBus_outputs.output(); + int analogOut_value= 0; + aBus_outputs = 0; + float prev_analog_value = 0; + for(int iter = 0; iter<5; iter++) { + // DigitalIO test + d_out = 0; // test 0 + TEST_ASSERT_MESSAGE(0 == d_in.read(),"Expected value to be 0, read value was not zero"); + d_out = 1; // test 1 + TEST_ASSERT_MESSAGE(1 == d_in.read(),"Expected value to be 1, read value was not one"); + + // AnalogIn test + prev_analog_value = a_in.read(); + analogOut_value = (analogOut_value << 1) + 1; + aBus_outputs = analogOut_value; + TEST_ASSERT_MESSAGE(a_in.read() > prev_analog_value,"Analog Input did not increment."); + + // Rising Edge InterruptIn test + GPIO_Result = false; + int_out = 0; + int_in.rise(cbfn); + int_out = 1; + wait(0); // dummy wait to get volatile result value + TEST_ASSERT_MESSAGE(GPIO_Result,"cbfn was not triggered on rising edge of pin"); + + // Falling Edge InterruptIn test + GPIO_Result = false; + int_out = 1; + int_in.fall(cbfn); + int_out = 0; + wait(0); // dummy wait to get volatile result value + TEST_ASSERT_MESSAGE(GPIO_Result,"cbfn was not triggered on falling edge of pin"); + } + osSignalSet(Multi_Thread_ID, 0x4); // signal completion of thread +} + + +// Test Comms and GPIO concurrently in multiple threads. Note, when working with multiple threads, the debugging print statments called by the below threads may get garbled together due to context switches mid exection of a thread. + +void test_multiple_threads() +{ + Multi_Thread_ID = Thread::gettid(); // update thread id for this thread + Thread_I2C.start(callback(test_I2C)); // kick off threads + Thread_SPI.start(callback(test_SPI)); // kick off threads + Thread_GPIO.start(callback(test_GPIO)); // kick off threads + wait(0.1); // allow time for debug print statements to complete. + + // Use this to wait for both signaling events to occur + // Internaly the code is doing something like this: + // if ((signal3 | signal2 | signal1) & 0x7 == 0x7) then exit, else wait + osSignalWait(0x7, osWaitForever); +} + + +// Test Comms and GPIO concurrently in a single thread. +void test_single_thread() +{ + // ******************************* + // Initialize variables and APIs + // ******************************* + + // DIO test initializations + DigitalOut d_out(MBED_CONF_APP_DIO_2); + DigitalIn d_in(MBED_CONF_APP_DIO_3); + + // AnalogIn test initializations + AnalogIn a_in(MBED_CONF_APP_AIN_0); + BusInOut aBus_outputs(MBED_CONF_APP_AIN_1,MBED_CONF_APP_AIN_2,MBED_CONF_APP_AIN_3,MBED_CONF_APP_AIN_4,MBED_CONF_APP_AIN_5); + aBus_outputs.output(); + int analogOut_value= 0; + aBus_outputs = 0; + float prev_analog_value = 0; + + // InterruptIn test initializations + InterruptIn int_in(MBED_CONF_APP_DIO_4); + DigitalOut int_out(MBED_CONF_APP_DIO_5); + + // I2C test initializations + int address = 0; // starting address to write to in EEPROM + int num_read = 0; // will report number of bytes read + int num_written = 0; // will report number of bytes written + volatile char read_string_i2c[TEST_STRING_MAX] = {0}; // string that will be updated from reading EEPROM + I2CEeprom memory(MBED_CONF_APP_I2C_SDA,MBED_CONF_APP_I2C_SCL,MBED_CONF_APP_I2C_EEPROM_ADDR,32,0); + + // SPI test initializations + volatile char read_string_spi[TEST_STRING_MAX] = {0}; // string that will be updated from reading SD card + SDBlockDevice sd(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_CS); + FATFileSystem fs("sd", &sd); + sd.init(); + + // ****************************** + // Begin concurrent API testing + // ****************************** + for(int iter = 0; iter<5; iter++) { + DEBUG_PRINTF("\r\n****\r\n Single thread test loop #%d\r\n****\r\n",iter); + + // DigitalIO test + d_out = 0; // test 0 + TEST_ASSERT_MESSAGE(0 == d_in.read(),"Expected value to be 0, read value was not zero"); + d_out = 1; // test 1 + TEST_ASSERT_MESSAGE(1 == d_in.read(),"Expected value to be 1, read value was not one"); + + // AnalogIn test + prev_analog_value = a_in.read(); + analogOut_value = (analogOut_value << 1) + 1; + aBus_outputs = analogOut_value; + TEST_ASSERT_MESSAGE(a_in.read() > prev_analog_value,"Analog Input did not increment."); + + // Rising Edge InterruptIn test + GPIO_Result = false; + int_out = 0; + int_in.rise(cbfn); + int_out = 1; + wait(0); // dummy wait to get volatile result value + TEST_ASSERT_MESSAGE(GPIO_Result,"cbfn was not triggered on rising edge of pin"); + + // Falling Edge InterruptIn test + GPIO_Result = false; + int_out = 1; + int_in.fall(cbfn); + int_out = 0; + wait(0); // dummy wait to get volatile result value + TEST_ASSERT_MESSAGE(GPIO_Result,"cbfn was not triggered on falling edge of pin"); + + // Write to EEPROM using I2C + num_written = memory.write(address,Test_String,TEST_STRING_MAX); + + // Write to SD card using SPI + fs.mount(&sd); + FILE *File = fopen("/sd/test_sd_w.txt", "w"); + TEST_ASSERT_MESSAGE(File != NULL,"SD Card is not present. Please insert an SD Card."); + int error = fprintf(File, Test_String); // write data + TEST_ASSERT_MESSAGE(error > 0,"Writing file to sd card failed"); // error checking + fclose(File); // close file on SD + + // Read back from EEPROM + num_read = memory.read(address,(char *)read_string_i2c,TEST_STRING_MAX); + + // Read back from SD card + File = fopen("/sd/test_sd_w.txt", "r"); + fgets((char *)read_string_spi,TEST_STRING_MAX,File); // read string from the file + + // Test results for I2C + TEST_ASSERT_EQUAL_STRING_MESSAGE(Test_String,(char *)read_string_i2c,"String read does not match the string written"); // test that strings match + TEST_ASSERT_EQUAL_MESSAGE(num_written,num_read,"Number of bytes written does not match the number of bytes read"); + + // Test results for SPI + TEST_ASSERT_EQUAL_STRING_MESSAGE(Test_String,(char *)read_string_spi,"String read does not match the string written"); // test that strings match + + // Close file and unmount SD card + fclose(File); // close file on SD + fs.unmount(); // unmount + sd.deinit(); // deinitialize SD + } +} + + +utest::v1::status_t test_setup(const size_t number_of_cases) +{ + // Setup Greentea using a reasonable timeout in seconds + GREENTEA_SETUP(40, "default_auto"); + return verbose_test_setup_handler(number_of_cases); +} + + +// Handle test failures, keep testing, dont stop +utest::v1::status_t greentea_failure_handler(const Case *const source, const failure_t reason) +{ + greentea_case_failure_abort_handler(source, reason); + return STATUS_CONTINUE; +} + + +// Test cases +Case cases[] = { + Case("Concurrent testing of Comms and GPIO in a single thread",test_single_thread,greentea_failure_handler), + Case("Concurrent testing of Comms and GPIO in multiple threads",test_multiple_threads,greentea_failure_handler), +}; + + +Specification specification(test_setup, cases); + +// Entry point into the tests +int main() { + init_string(); + return !Harness::run(specification); +}