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

Level testing formatting and updates. #66

Open
wants to merge 21 commits into
base: level-testing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
866b019
Removed print statement from Level1/AnalogIn that I added earlier for…
Jul 14, 2017
104ea91
Fixed bug in BusInOut where it was calling level2 framework instead o…
Jul 14, 2017
f3c2521
added ifdef guards to TestFramework.cpp, so that it can compile with …
Jul 17, 2017
d095c54
changed printf to use hex instead if decimal when printing pin names
Jul 17, 2017
6a07ee1
Added #ifdef check in map_pins() so that it no longer adds ADC intern…
Jul 17, 2017
f13f524
Debug printf calls now report as hex instead of decimal for pin names…
Jul 17, 2017
451b3a6
Fixed typo in DigitalIO.cpp. Turned of Debug mode in mbed_app.json
Jul 17, 2017
5e0b680
Formatted Level0 code per Martin Kojtal's request.
Aug 4, 2017
a7cd92c
Formatted Level1 code per Martin Kojtal's requested format.
Aug 7, 2017
a421cff
Formatted TestFramework code per Martin Kojtal's requested format.
Aug 7, 2017
53f3bce
Modified Level1/I2C. Removed assert testing on write and then read of…
Aug 7, 2017
7c2dbb9
Updated assert checking for SPI and I2C Level1 tests, ensuring that A…
Aug 11, 2017
5fc551f
Formatted Level2 tests to match mbed style guide.
Aug 14, 2017
ff9724d
Finished testing and updating Level2 AnalogIn.
Aug 14, 2017
b438c4c
Updated level1-spi test so that it no longer checks the cs pin in the…
Aug 16, 2017
b59a54f
Updated level2-spi and level3-spi tests so that they no longer checks…
Aug 16, 2017
da446dc
Level2-DIO test was only running 6 tests on the K64F instead of the i…
Aug 17, 2017
4260250
Finished testing level2/i2c. The logic used to test if write and read…
Aug 17, 2017
ebf68a6
Removed the UART pins from DIO since having DEVICE_SERIAL defined, do…
Aug 17, 2017
cbffcaa
Finished testing level2-pwm
Aug 17, 2017
7fd4207
Finished testing level2/Spi. Should be finished testing all of level…
Aug 18, 2017
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
15 changes: 10 additions & 5 deletions TESTS/Level0/AnalogIn/AnalogIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,27 @@ std::vector<unsigned int> TestFramework::pin_iterators(TS_NC);
// Initialize a test framework object
TestFramework test_framework;

utest::v1::control_t test_level0_analogin(const size_t call_count) {

utest::v1::control_t test_level0_analogin(const size_t call_count)
{
PinMap pin = test_framework.get_increment_pin(TestFramework::AnalogInput);
DEBUG_PRINTF("Running analog input constructor on pin %d\n", pin.pin);
TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC");
DEBUG_PRINTF("Running analog input constructor on pin %#x\n", pin.pin);
TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC");

AnalogIn ain(pin.pin);

return test_framework.reset_iterator(TestFramework::AnalogInput);
}


Case cases[] = {
Case("Level 0 - Analog Input Constructor", test_level0_analogin, TestFramework::greentea_failure_handler),
};

int main() {

int main()
{
// Formulate a specification and run the tests based on the Case array
Specification specification(TestFramework::test_setup<30>, cases);
return !Harness::run(specification);
return !Harness::run(specification);
}
15 changes: 10 additions & 5 deletions TESTS/Level0/AnalogOut/AnalogOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,27 @@ std::vector<unsigned int> TestFramework::pin_iterators(TS_NC);
// Initialize a test framework object
TestFramework test_framework;

utest::v1::control_t test_level0_analogout(const size_t call_count) {

utest::v1::control_t test_level0_analogout(const size_t call_count)
{
PinMap pin = test_framework.get_increment_pin(TestFramework::AnalogOutput);
DEBUG_PRINTF("Running analog output constructor on pin %d\n", pin.pin);
TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC");
DEBUG_PRINTF("Running analog output constructor on pin %#x\n", pin.pin);
TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC");

AnalogOut ain(pin.pin);

return test_framework.reset_iterator(TestFramework::AnalogOutput);
}


Case cases[] = {
Case("Level 0 - Analog Output Constructor", test_level0_analogout, TestFramework::greentea_failure_handler),
};

int main() {

int main()
{
// Formulate a specification and run the tests based on the Case array
Specification specification(TestFramework::test_setup<30>, cases);
return !Harness::run(specification);
return !Harness::run(specification);
}
23 changes: 13 additions & 10 deletions TESTS/Level0/BusInOut/BusInOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ std::vector<unsigned int> TestFramework::pin_iterators(TS_NC);
// Initialize a test framework object
TestFramework test_framework;

utest::v1::control_t test_level0_businout(const size_t call_count) {

utest::v1::control_t test_level0_businout(const size_t call_count)
{
DEBUG_PRINTF("Running bus input/output constructor\n");

std::vector<PinName> pins; // vector of pins that the bus will contain
Expand All @@ -45,18 +47,18 @@ utest::v1::control_t test_level0_businout(const size_t call_count) {
if(TestFramework::check_size(TestFramework::BusIO)) {
// fetch new pin
pins.push_back(test_framework.get_increment_pin(TestFramework::BusIO).pin);
}
}

// if no more suitable pins are available, then add No-Connects until bus is full
else{
// if no more suitable pins are available, then add No-Connects until bus is full
else {
pins.push_back((PinName)NC);
}
}
}

DEBUG_PRINTF("Pins assigned to bus:\n pin[0] = %d\n pin[1] = %d\n pin[2] = %d\n pin[3] = %d\n pin[4] = %d\n pin[5] = %d\n pin[6] = %d\n pin[7] = %d\n pin[8] = %d\n pin[9] = %d\n pin[10] = %d\n pin[11] = %d\n pin[12] = %d\n pin[13] = %d\n pin[14] = %d\n pin[15] = %d\n",pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]);
DEBUG_PRINTF("Pins assigned to bus:\n pin[0] = %#x\n pin[1] = %#x\n pin[2] = %#x\n pin[3] = %#x\n pin[4] = %#x\n pin[5] = %#x\n pin[6] = %#x\n pin[7] = %#x\n pin[8] = %#x\n pin[9] = %#x\n pin[10] = %#x\n pin[11] = %#x\n pin[12] = %#x\n pin[13] = %#x\n pin[14] = %#x\n pin[15] = %#x\n",pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]);

// construct the bus with assigned pins
BusInOut bio(pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]);
// construct the bus with assigned pins
BusInOut bio(pins[0],pins[1],pins[2],pins[3],pins[4],pins[5],pins[6],pins[7],pins[8],pins[9],pins[10],pins[11],pins[12],pins[13],pins[14],pins[15]);

return test_framework.reset_iterator(TestFramework::BusIO);
}
Expand All @@ -65,8 +67,9 @@ Case cases[] = {
Case("Level 0 - Bus Input/Output Constructor", test_level0_businout, TestFramework::greentea_failure_handler),
};

int main() {
int main()
{
// Formulate a specification and run the tests based on the Case array
Specification specification(TestFramework::test_setup<30>, cases);
return !Harness::run(specification);
return !Harness::run(specification);
}
15 changes: 10 additions & 5 deletions TESTS/Level0/DigitalIO/DigitalIO.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,23 +34,28 @@ std::vector<unsigned int> TestFramework::pin_iterators(TS_NC);
// Initialize a test framework object
TestFramework test_framework;

utest::v1::control_t test_level0_digitalio(const size_t call_count) {

utest::v1::control_t test_level0_digitalio(const size_t call_count)
{
PinMap pin = test_framework.get_increment_pin(TestFramework::DigitalIO);
DEBUG_PRINTF("Running digital io constructor on pin %d\n", pin.pin);
TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC");
DEBUG_PRINTF("Running digital io constructor on pin %#x\n", pin.pin);
TEST_ASSERT_MESSAGE(pin.pin != NC, "Pin is NC");

DigitalOut dout(pin.pin);
DigitalIn din(pin.pin);

return test_framework.reset_iterator(TestFramework::DigitalIO);
}


Case cases[] = {
Case("Level 0 - DigitalIO Constructor", test_level0_digitalio, TestFramework::greentea_failure_handler),
};

int main() {

int main()
{
// Formulate a specification and run the tests based on the Case array
Specification specification(TestFramework::test_setup<30>, cases);
return !Harness::run(specification);
return !Harness::run(specification);
}
23 changes: 15 additions & 8 deletions TESTS/Level0/I2C/I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,31 @@ std::vector<unsigned int> TestFramework::pin_iterators(TS_NC);
// Initialize a test framework object
TestFramework test_framework;

void construct_i2c(PinName sda, PinName scl) {
DEBUG_PRINTF("Running I2C Constructor on SDA pin %d and SCL pin %d\n", sda, scl);
TEST_ASSERT_MESSAGE(sda != NC, "SDA Pin is NC");
TEST_ASSERT_MESSAGE(scl != NC, "SCL Pin is NC");

I2C i2c(sda, scl);
void construct_i2c(PinName sda, PinName scl)
{
DEBUG_PRINTF("Running I2C Constructor on SDA pin %#x and SCL pin %#x\n", sda, scl);
TEST_ASSERT_MESSAGE(sda != NC, "SDA Pin is NC");
TEST_ASSERT_MESSAGE(scl != NC, "SCL Pin is NC");

I2C i2c(sda, scl);
}

utest::v1::control_t test_level0_i2c(const size_t call_count) {

utest::v1::control_t test_level0_i2c(const size_t call_count)
{
return TestFramework::run_i2c(&construct_i2c);
}


Case cases[] = {
Case("Level 0 - I2C Constructor", test_level0_i2c, TestFramework::greentea_failure_handler),
};

int main() {

int main()
{
// Formulate a specification and run the tests based on the Case array
Specification specification(TestFramework::test_setup<30>, cases);
return !Harness::run(specification);
return !Harness::run(specification);
}
19 changes: 12 additions & 7 deletions TESTS/Level0/Pwm/Pwm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,29 @@ std::vector<unsigned int> TestFramework::pin_iterators(TS_NC);
// Initialize a test framework object
TestFramework test_framework;

utest::v1::control_t test_level0_pwm(const size_t call_count) {

utest::v1::control_t test_level0_pwm(const size_t call_count)
{
PinMap pin = test_framework.get_increment_pin(TestFramework::PWM);
DEBUG_PRINTF("Running pwm constructor on pin %d\n", pin.pin);
TEST_ASSERT_MESSAGE(pin.pin != NC, "pin is NC");
DEBUG_PRINTF("Running PWM constructor on pin %#x\n", pin.pin);
TEST_ASSERT_MESSAGE(pin.pin != NC, "pin is NC");

PwmOut pwm(pin.pin);
pwm.period(1.0f);
pwm.write(0.5f);
pwm.period(1.0f);
pwm.write(0.5f);

return test_framework.reset_iterator(TestFramework::PWM);
}


Case cases[] = {
Case("Level 0 - PWM Constructor", test_level0_pwm, TestFramework::greentea_failure_handler),
};

int main() {

int main()
{
// Formulate a specification and run the tests based on the Case array
Specification specification(TestFramework::test_setup<30>, cases);
return !Harness::run(specification);
return !Harness::run(specification);
}
29 changes: 18 additions & 11 deletions TESTS/Level0/SPI/SPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,34 @@ std::vector<unsigned int> TestFramework::pin_iterators(TS_NC);
// Initialize a test framework object
TestFramework test_framework;

void construct_spi(PinName pin_clk, PinName pin_miso, PinName pin_mosi, PinName pin_cs) {
DEBUG_PRINTF("Running SPI constructor on CLK pin %d, MISO pin %d, MOSI pin %d, and CS pin %d\n", pin_clk, pin_miso, pin_mosi, pin_cs);
TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC");
TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC");
TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC");
TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC");

SPI(pin_mosi, pin_miso, pin_clk);
DigitalOut cs(pin_cs);
void construct_spi(PinName pin_clk, PinName pin_miso, PinName pin_mosi, PinName pin_cs)
{
DEBUG_PRINTF("Running SPI constructor on CLK pin %#x, MISO pin %#x, MOSI pin %#x, and CS pin %#x\n", pin_clk, pin_miso, pin_mosi, pin_cs);
TEST_ASSERT_MESSAGE(pin_clk != NC, "SPI CLK pin is NC");
TEST_ASSERT_MESSAGE(pin_mosi != NC, "SPI MOSI Pin is NC");
TEST_ASSERT_MESSAGE(pin_miso != NC, "SPI MISO Pin is NC");
TEST_ASSERT_MESSAGE(pin_cs != NC, "SPI CS Pin is NC");

SPI(pin_mosi, pin_miso, pin_clk);
DigitalOut cs(pin_cs);
}

utest::v1::control_t test_level0_spi(const size_t call_count) {

utest::v1::control_t test_level0_spi(const size_t call_count)
{
return test_framework.run_spi(&construct_spi);
}


Case cases[] = {
Case("Level 0 - SPI Constructor", test_level0_spi, TestFramework::greentea_failure_handler),
};

int main() {

int main()
{
// Formulate a specification and run the tests based on the Case array
Specification specification(TestFramework::test_setup<60>, cases);
return !Harness::run(specification);
return !Harness::run(specification);
}
95 changes: 50 additions & 45 deletions TESTS/Level1/AnalogIn/AnalogIn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#include "TestFramework.hpp"
#include <vector>

#define BUS_SIZE 5

using namespace utest::v1;

// Static variables for managing the dynamic list of pins
Expand All @@ -38,66 +40,69 @@ std::vector<unsigned int> TestFramework::pin_iterators(TS_NC);
// Initialize a test framework object
TestFramework test_framework;

void test_analogin_execute(PinName pin, float tolerance, int iterations) {
DEBUG_PRINTF("Running analog input range test on pin %d\n", pin);
TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC");
void test_analogin_execute(PinName pin, float tolerance, int iterations)
{
DEBUG_PRINTF("Running analog input range test on pin %#x\n", pin);
TEST_ASSERT_MESSAGE(pin != NC, "Pin is NC");

// Find all pins on the resistor ladder that are not the current pin
// Find all pins on the resistor ladder that are not the current pin
std::vector<PinName> resistor_ladder_pins = TestFramework::find_resistor_ladder_pins(pin);
if (resistor_ladder_pins.size() < 5)
TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins");
if (resistor_ladder_pins.size() < BUS_SIZE){
TEST_ASSERT_MESSAGE(false, "Error finding the resistor ladder pins");
}

// Create a bus with all of these pins
BusInOut outputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]);
BusInOut outputs(resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]);
outputs.output();

DEBUG_PRINTF("Creating a resistive ladder bus with the following pins:\n pin[0] = %d\n pin[1] = %d\n pin[2] = %d\n pin[3] = %d\n pin[4] = %d\n", resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]);
DEBUG_PRINTF("Creating a resistive ladder bus with the following pins:\n pin[0] = %#x\n pin[1] = %#x\n pin[2] = %#x\n pin[3] = %#x\n pin[4] = %#x\n", resistor_ladder_pins[0],resistor_ladder_pins[1],resistor_ladder_pins[2],resistor_ladder_pins[3],resistor_ladder_pins[4]);

// construct designated analogIn pin
// construct designated analogIn pin
AnalogIn ain(pin);

for (unsigned int i=0; i<iterations; i++) {

// Initialization
int x = 0;
int y= 0;
outputs = 0;
float prev_value = 0;
float new_value = 0;
float test_value = 0;

// Iterate through each of the bus pins
for(x = 0; x<5; x++) {

// Read the previous value, and turn another pin on in the resistor ladder
prev_value = ain.read();
y = (y<<1) + 1;
outputs = y;

// Read the new value to make sure the voltage increased
new_value = ain.read();
DEBUG_PRINTF("new_value on bus = %d\n", new_value);
TEST_ASSERT_MESSAGE(new_value > prev_value,"Analog Input did not increment. Check that you have assigned valid pins in mbed_app.json file")

// Repeat the read multiple times to verify the output is not fluctuating
for (unsigned int j = 0; j<iterations; j++) {
test_value = ain.read();
TEST_ASSERT_MESSAGE(abs(test_value - new_value) < tolerance, "Analog Input fluctuated past the tolerance");
}
}
for (unsigned int i=0; i<iterations; i++) {
// Initialization
int x = 0;
int y= 0;
outputs = 0;
float prev_value = 0;
float new_value = 0;
float test_value = 0;

// Iterate through each of the bus pins
for(x = 0; x<BUS_SIZE; x++) {

// Read the previous value, and turn another pin on in the resistor ladder
prev_value = ain.read();
y = (y<<1) + 1;
outputs = y;

// Read the new value to make sure the voltage increased
new_value = ain.read();
TEST_ASSERT_MESSAGE(new_value > prev_value,"Analog Input did not increment. Check that you have assigned valid pins in mbed_app.json file")

// Repeat the read multiple times to verify the output is not fluctuating
for (unsigned int j = 0; j<iterations; j++) {
test_value = ain.read();
TEST_ASSERT_MESSAGE(abs(test_value - new_value) < tolerance, "Analog Input fluctuated past the tolerance");
}
}
}
}

utest::v1::control_t test_level1_analogin(const size_t call_count) {
return TestFramework::test_level1_framework(TestFramework::AnalogInput, TestFramework::CITS_AnalogInput, &test_analogin_execute, 0.05, 10);

utest::v1::control_t test_level1_analogin(const size_t call_count)
{
return TestFramework::test_level1_framework(TestFramework::AnalogInput, TestFramework::CITS_AnalogInput, &test_analogin_execute, 0.05, 10);
}

Case cases[] = {
Case("Level 1 - Analog Input Range test (single pin)", test_level1_analogin, TestFramework::greentea_failure_handler),
Case("Level 1 - Analog Input Range test (single pin)", test_level1_analogin, TestFramework::greentea_failure_handler),
};

int main() {
// Formulate a specification and run the tests based on the Case array
Specification specification(TestFramework::test_setup<30>, cases);
return !Harness::run(specification);
int main()
{
// Formulate a specification and run the tests based on the Case array
Specification specification(TestFramework::test_setup<30>, cases);
return !Harness::run(specification);
}
Loading