Cant get the unit test work with custom unity_config.h

Hi ,

I want to perform a unit test for arduino based stm32 device. The serial output of the test device need to port to hardware serial .

Before platformio core 6.0 it was working fine with unittest_transport.h

which the code is ::

#ifndef UNITTEST_TRANSPORT_H
#define UNITTEST_TRANSPORT_H
#include <Arduino.h>
#define TESTING_SERIAL Serial1

HardwareSerial Serial1(UART4);

void unittest_uart_begin() {
/* default test_speed value */
TESTING_SERIAL.setRx(PC11);
TESTING_SERIAL.setTx(PC10);
TESTING_SERIAL.begin(115200);
}

void unittest_uart_putchar(char c) {
TESTING_SERIAL.print(c);
}

void unittest_uart_flush() {
TESTING_SERIAL.flush();
}

void unittest_uart_end() {
}
#endif

After 6.0 I had to rename the folder or file start with “test_” and need to replace unittest_transport.h with unity_config.h and unity_config.cpp according to @ivankravets .

I made the changes as below ,
unity_config.h

#ifndef UNITY_CONFIG_H
#define UNITY_CONFIG_H
#include <Arduino.h>

#ifndef NULL
#ifndef __cplusplus
#define NULL (void*)0
#else
#define NULL 0
#endif
#endif
#ifdef __cplusplus
extern “C”
{
#endif
void unityOutputStart();
void unityOutputChar(char);
void unityOutputFlush();
void unityOutputComplete();

#define UNITY_OUTPUT_START() unityOutputStart()
#define UNITY_OUTPUT_CHAR(c) unityOutputChar(c)
#define UNITY_OUTPUT_FLUSH() unityOutputFlush()
#define UNITY_OUTPUT_COMPLETE() unityOutputComplete()
#ifdef __cplusplus
}

#endif /* extern “C” /
#endif /
UNITY_CONFIG_H */

and unity_config.cpp is ,

#include “unity_config.h”
#define TESTING_SERIAL Serial1

HardwareSerial Serial1(UART4);

void unityOutputStart()
{
Serial1.begin(115200);
}

void unityOutputChar(char c)
{
Serial1.print(c);
}

void unityOutputFlush()
{
Serial1.flush();
}

void unityOutputComplete()
{
}

and I’m getting the following error ,

Any idea of why this error occurs ?

Thanks,
Sam.

All you’re missing is the setUp() and tearDown() functions. Even if they are empty, they must be in the test source code.

1 Like

Thank you @maxgerhardt cheers!

Hi @maxgerhardt I just add those function to my test.cpp file and it’s outputting the results now. However,
it doesn’t print any test output as what it was used to .

My test.cpp is,

#include <Arduino.h>
#include <unity.h>
#include <ArduinoECCX08.h>
#include <utility/ECCX08JWS.h>
#include <utility/ECCX08DefaultTLSConfig.h>

TwoWire Wire2(PF0, PF1);
ECCX08Class ECCX08(Wire2, 0x60);

void setUp(void) {
// set stuff up here
}

void tearDown(void) {
// clean stuff up here
}

void test_provision()
{
TEST_ASSERT_MESSAGE(ECCX08.begin(), “ATECC608 not present”);
// print serial number (to be used as device ID)
String serialNum = ECCX08.serialNumber();
TEST_ASSERT_MESSAGE(serialNum && serialNum != “”, “Failed to get serial number”);
TEST_MESSAGE(String(“Device ID: M” + serialNum).c_str()); // prepend with M
bool wasLocked = ECCX08.locked();
if (!wasLocked) {
// lock device with default TLS configuration
TEST_ASSERT_MESSAGE(ECCX08.writeConfiguration(ECCX08_DEFAULT_TLS_CONFIG), “Failed to write config”);
TEST_ASSERT_MESSAGE(ECCX08.lock(), “Failed to lock ATECC608”);
}

String publicKeyPem = ECCX08JWS.publicKey(0, !wasLocked);

TEST_ASSERT_MESSAGE(publicKeyPem && publicKeyPem != “”, “Failed to generate/get private and/or public key”);
TEST_MESSAGE(publicKeyPem.c_str());

}

void setup()
{
delay(2000);
UNITY_BEGIN();
RUN_TEST(test_provision);
UNITY_END();
}

void loop()
{
}

This is the output without any message ,

Not sure I put those two functions in the right place or that causing to not to print any message ,appreciate your help .
Samson.

1 Like

Thank you for your help !,cheers!