samedi 10 juin 2017

how to write unit tests for a Server running with the hardware and CAN bus

I am running code on two Raspberry pis, one is a tester for testing the server, other one is a server who receives message from the testing one. This is the code on the testing side:

#include <cstdlib>
#include <unistd.h>

#include "isotp_socket.h"

using namespace std;

int main(int argc, char** argv) 
{

string device = "vcan0";
if (argc > 1)
{
    device = argv[1];
}

// test ecu
IsoTpSocket tester(0x200,0x100, device.c_str());
tester.openSender();

constexpr array<uint8_t, 3> ReadDataByIdentifier01 = { 0x22, 0xf1, 0x90 };
constexpr array<uint8_t, 3> ReadDataByIdentifier02 = { 0x22, 0xf1, 0x24 };
constexpr array<uint8_t, 3> ReadDataByIdentifier03 = { 0x22, 0x1e, 0x23 };
constexpr array<uint8_t, 3> ReadDataByIdentifier04 = { 0x22, 0x00, 0x00 };
constexpr array<uint8_t, 2> security_access01 = { 0x27, 0x01 };
constexpr array<uint8_t, 4> security_access02 = { 0x27, 0x02, 0x00, 0x00 };
constexpr array<uint8_t, 2> diagnostic_session01 = { 0x10, 0x01 };

tester.sendData(ReadDataByIdentifier01.data(), ReadDataByIdentifier01.size());
usleep(2000);
tester.sendData(ReadDataByIdentifier02.data(), ReadDataByIdentifier02.size());
usleep(2000);
tester.sendData(ReadDataByIdentifier03.data(), ReadDataByIdentifier03.size());
usleep(2000);
tester.sendData(ReadDataByIdentifier04.data(), ReadDataByIdentifier04.size());
usleep(2000);
tester.sendData(security_access01.data(), security_access01.size());
usleep(2000);
tester.sendData(security_access02.data(), security_access01.size());
usleep(2000);
tester.sendData(diagnostic_session01.data(), diagnostic_session01.size());
usleep(2000);

tester.closeSender();
return 0;

}

I want to add some assert()s in this code, but the problem is, I want to test it on the real hardware, I mean with the CAN shield connecting the two Raspberry Pis. Although I can see the data transport on the terminal: whether the server has the right message receives, and whether the server has the right message responses to the testing Raspberry Pi..But that's not a test.

And another problem is that I highly doubt that it's a unit test, because it involves not only a tester and a server but also the real CAN bus.

So guys, do you have any ideas how can I write tests for this case and which kind of test it should be?

Thanks

Aucun commentaire:

Enregistrer un commentaire