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

About Serial.print() and Serial1.print() in ESP32 projects #52

Open
joellozano30 opened this issue Sep 19, 2023 · 1 comment
Open

About Serial.print() and Serial1.print() in ESP32 projects #52

joellozano30 opened this issue Sep 19, 2023 · 1 comment

Comments

@joellozano30
Copy link

I'm starting a embedded project wich uses ESP32 microcontroller using the Arduino Framework and some modules like a Sigfox Module. I want to test a function which send messages via Sigfox:

void sigfoxSendMsg(String buf_tx)
{
    //Adding line break
    buf_tx += "\n";

    //******************************
    //Enable Sigfox Module
    digitalWrite(SIGFOX_ENABLE, HIGH);
    delay(1000);

    #ifndef TEST
    //Channel reset to ensure correct frequency
    Serial1.print("AT$RC\n");
    
    //******************************
    //Sending data on Sigfox
    Serial1.print(buf_tx);
    #else

    Serial.print("AT$RC\n");
    Serial.print(buf_tx);
    #endif


    #ifdef SIGFOX_DEBUG
        #ifndef TEST
        Serial.print(buf_tx);
        #endif
    #endif
    delay(3000);

    //disable sigfox module
    digitalWrite(SIGFOX_ENABLE, LOW);
}

But when I test it with my test function:

void test_sigfoxSendMsg_should_beAbleTo_SendMessagesCorrectly(){
    String packedMessage = "AT$SF=d63c1042"; //Data

    When(Method(ArduinoFake(), digitalWrite)).AlwaysReturn();
    When(Method(ArduinoFake(), delay)).AlwaysReturn();

    When(OverloadedMethod(ArduinoFake(Serial), print, size_t(char))).AlwaysReturn();
 
    sigfoxSendMsg(packedMessage);

    Verify(Method(ArduinoFake(), digitalWrite).Using(SIGFOX_ENABLE, HIGH));
    Verify(Method(ArduinoFake(), digitalWrite).Using(SIGFOX_ENABLE, LOW));
}

The result of the test show me how the function Serial.print() wasn't mocked:

Building...
Testing...
Program errored with 3221225477 code

How can i fix these errors? I believe that I'am mocking Serial.print() wrongly. Additionaly, there is a way to use Serial1.print() instead of Serial.print() with ArduinoFake? It would help me to other functions that I want to adapt to test also.

@FabioBatSilva
Copy link
Owner

If you run with --verbose should get a bit more info platformio test -e native -v
But the error is likely BC Serial1 is not implemented.

There are some some instructions here https://github.com/FabioBatSilva/ArduinoFake/blob/master/CONTRIBUTING.md
on how to add in case you wanna give it a go.

I think for this one is mostly reusing the what is already in place for Serial

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants