Skip to content

src/corelibs/spi: Added the 3wire test with the TLE5012. #55

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ test_wifi_udp_server: TESTS=-DTEST_WIFI_UDP_SERVER
test_spi_connected1_loopback: TESTS=-DTEST_SPI_CONNECTED1_LOOPBACK
test_spi_connected2_masterpingpong: TESTS=-DTEST_SPI_CONNECTED2_MASTERPINGPONG
test_spi_connected2_slavepingpong: TESTS=-DTEST_SPI_CONNECTED2_SLAVEPINGPONG
test_spi_3wire: TESTS=-DTEST_SPI_3WIRE

## Tone tests targets
test_tone_no_tone: TESTS=-DTEST_TONE_NO_TONE
Expand Down
68 changes: 68 additions & 0 deletions src/corelibs/spi/test_spi_3wire.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/* test_spi_3wire.cpp
*
* This test is used to verify if the TLE5012 sensor is responding using 3-wire SPI communication.
*/

// std includes
#include <tlx5012-arduino.hpp>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to check if we can test the 3Wire SPI without depending on the library...
Otherwise this test is out of scope of arduino-core-test.

#include "test_common_includes.h"

// Use the tle5012 namespace
using namespace tle5012;

// TLE5012 sensor instance and variables
static Tle5012Ino Tle5012Sensor = Tle5012Ino();
static errorTypes checkError;

// Test group definition
TEST_GROUP(spi_3wire);

TEST_SETUP(spi_3wire) {
// Initialize the TLE5012 sensor

checkError = Tle5012Sensor.begin();
}

TEST_TEAR_DOWN(spi_3wire) {
// Cleanup if necessary
}

// Test case: Verify if the sensor is responding
TEST(spi_3wire, test_sensor_response) {
TEST_ASSERT_EQUAL(tle5012::NO_ERROR, checkError); // Check if initialization was successful
}


// Test case: Request data from the sensor using 3-wire SPI
TEST(spi_3wire, test_3wire_request) {
double command = 0.0; // Example command to request data from the sensor
int response = 0;

// Use the sendReceiveSPI function to perform 3-wire SPI communication
response = Tle5012Sensor.getAngleValue(command);

// Verify the response (this is an example; adjust based on expected behavior)
TEST_ASSERT_NOT_EQUAL(1, response); // Ensure the response is not an error
TEST_ASSERT_TRUE(response >= -180.0 && response <= 180.0); // Ensure the angle is within a valid range
}

// Test case: Request temperature data from the sensor
TEST(spi_3wire, test_temperature_request) {
double temperature = 0.0;
int result = 0;

// Use the getTemperature function to request temperature data from the sensor
result = Tle5012Sensor.getTemperature(temperature);

Serial.print(temperature);
// Verify the response
TEST_ASSERT_EQUAL(tle5012::NO_ERROR, result); // Ensure the request was successful
TEST_ASSERT_TRUE(temperature >= -40.0 && temperature <= 150.0); // Ensure the temperature is within a valid range
}

// Define test runner for the SPI 3-wire test group
TEST_GROUP_RUNNER(spi_3wire) {
RUN_TEST_CASE(spi_3wire, test_sensor_response);
RUN_TEST_CASE(spi_3wire, test_3wire_request);
RUN_TEST_CASE(spi_3wire, test_temperature_request);
}
6 changes: 6 additions & 0 deletions src/test_main.ino
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ void RunAllTests(void)

#endif

#ifdef TEST_SPI_3WIRE

RUN_TEST_GROUP(spi_3wire);

#endif

#ifdef TEST_TONE_NO_TONE

RUN_TEST_GROUP(tone_no_tone);
Expand Down