Skip to content

Commit

Permalink
test: Fix function does not return a value warnings
Browse files Browse the repository at this point in the history
Many test stub functions are meant to return a value, but weren't. Clang
would generate a warning for each instance where we weren't returning
anything in a function that was meant to return a value.

    warning: non-void function does not return a value [-Wreturn-type]

For a specific example, my_radio::time_on_air() is supposed to return a
uint32_t, but wasn't returning anything. We'll return a zero instead of
relying on undefined behavior.

Without this, clang 11.0.1 was generating a virtual function
implementation with a `ud2` instruction to abort at run-time, causing
some execution of some unit tests to abort.

    Running main() from gmock_main.cc
    [==========] Running 10 tests from 1 test suite.
    [----------] Global test environment set-up.
    [----------] 10 tests from Test_LoRaPHYUS915
    [ RUN      ] Test_LoRaPHYUS915.constructor
    [       OK ] Test_LoRaPHYUS915.constructor (0 ms)
    [ RUN      ] Test_LoRaPHYUS915.restore_default_channels
    [       OK ] Test_LoRaPHYUS915.restore_default_channels (0 ms)
    [ RUN      ] Test_LoRaPHYUS915.rx_config
    [       OK ] Test_LoRaPHYUS915.rx_config (0 ms)
    [ RUN      ] Test_LoRaPHYUS915.tx_config
    Process 35669 stopped
    * thread ARMmbed#1, name = 'lorawan-loraphy-', stop reason = signal SIGILL: privileged instruction
        frame #0: 0x0000000000276f73 lorawan-loraphy-us915-unittest`my_radio::time_on_air(this=0x0000000800c2b048, modem=MODEM_LORA, pkt_len='\0') at Test_LoRaPHYUS915.cpp:90:5
       87       };
       88
       89       virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
    -> 90       {
       91       };
       92
       93       virtual bool perform_carrier_sense(radio_modems_t modem,
    (lldb) disassemble --pc
    lorawan-loraphy-us915-unittest`my_radio::time_on_air:
    ->  0x276f73 <+67>: ud2
        0x276f75:       int3
        0x276f76:       int3
        0x276f77:       int3
    (lldb)
  • Loading branch information
Patater committed May 26, 2021
1 parent cfd9e76 commit 5341e8c
Show file tree
Hide file tree
Showing 16 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions UNITTESTS/stubs/FileHandle_stub.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class FileHandle_stub : public FileHandle {

virtual int close()
{
return 0;
}

virtual short poll(short events) const
Expand Down
1 change: 1 addition & 0 deletions UNITTESTS/stubs/connectivity/AT_CellularDevice_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ ATHandler *AT_CellularDevice::get_at_handler()

CellularContext *create_context(const char *apn)
{
return NULL;
}

void delete_context(CellularContext *context)
Expand Down
1 change: 1 addition & 0 deletions UNITTESTS/stubs/connectivity/LoRaMac_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ void LoRaMac::post_process_mlme_ind()

lorawan_time_t LoRaMac::get_current_time(void)
{
return 0;
}

rx_slot_t LoRaMac::get_current_slot(void)
Expand Down
1 change: 1 addition & 0 deletions UNITTESTS/stubs/drivers/BufferedSerial_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ ssize_t BufferedSerial::write_unbuffered(const char *buf_ptr, size_t length)

bool BufferedSerial::hup() const
{
return false;
}

void BufferedSerial::wake()
Expand Down
2 changes: 1 addition & 1 deletion UNITTESTS/stubs/events/equeue_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void equeue_background(equeue_t *queue,

int equeue_chain(equeue_t *queue, equeue_t *target)
{

return 0;
}

int equeue_call_in(equeue_t *q, int ms, void (*cb)(void *), void *data)
Expand Down
1 change: 1 addition & 0 deletions UNITTESTS/stubs/storage/EmulatedSD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ int EmulatedSD::deinit()
{
fclose(_p->fs);
_p->fs = nullptr;
return 0;
}

int EmulatedSD::read(void *buffer, bd_addr_t addr, bd_size_t size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,8 @@ class my_AT_CTXIPV6 : public AT_CellularContext {
if (!_stack) {
_stack = new my_stack(_at, *get_device());
}

return _stack;
}
virtual uint32_t get_timeout_for_operation(ContextOperation op) const
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ TEST_F(Test_LoRaMac, post_process_mlme_ind)

uint8_t batt_cb()
{

return 100;
}

TEST_F(Test_LoRaMac, set_batterylevel_callback)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t random(void)
{
return 4;
};

virtual uint8_t get_status(void)
Expand All @@ -105,6 +106,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
{
return 0;
};

virtual bool perform_carrier_sense(radio_modems_t modem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t random(void)
{
return 4;
};

virtual uint8_t get_status(void)
Expand All @@ -88,6 +89,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
{
return 0;
};

virtual bool perform_carrier_sense(radio_modems_t modem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t random(void)
{
return 4;
};

virtual uint8_t get_status(void)
Expand All @@ -88,6 +89,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
{
return 0;
};

virtual bool perform_carrier_sense(radio_modems_t modem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t random(void)
{
return 4;
};

virtual uint8_t get_status(void)
Expand All @@ -88,6 +89,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
{
return 0;
};

virtual bool perform_carrier_sense(radio_modems_t modem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ class my_radio : public LoRaRadio {

virtual uint32_t random(void)
{
return 4;
};

virtual uint8_t get_status(void)
{
return 0;
};

virtual void set_max_payload_length(radio_modems_t modem, uint8_t max)
Expand All @@ -87,6 +89,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
{
return 0;
};

virtual bool perform_carrier_sense(radio_modems_t modem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t random(void)
{
return 4;
};

virtual uint8_t get_status(void)
Expand All @@ -88,6 +89,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
{
return 0;
};

virtual bool perform_carrier_sense(radio_modems_t modem,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ class my_radio : public LoRaRadio {

virtual uint32_t random(void)
{
return 4;
};

virtual uint8_t get_status(void)
{
return 0;
};

virtual void set_max_payload_length(radio_modems_t modem, uint8_t max)
Expand All @@ -86,13 +88,15 @@ class my_radio : public LoRaRadio {

virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
{
return 0;
};

virtual bool perform_carrier_sense(radio_modems_t modem,
uint32_t freq,
int16_t rssi_threshold,
uint32_t max_carrier_sense_time)
{
return true;
};

virtual void start_cad(void)
Expand All @@ -101,6 +105,7 @@ class my_radio : public LoRaRadio {

virtual bool check_rf_frequency(uint32_t frequency)
{
return true;
};

virtual void set_tx_continuous_wave(uint32_t freq, int8_t power, uint16_t time)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t random(void)
{
return 4;
};

virtual uint8_t get_status(void)
Expand All @@ -114,6 +115,7 @@ class my_radio : public LoRaRadio {

virtual uint32_t time_on_air(radio_modems_t modem, uint8_t pkt_len)
{
return 0;
};

virtual bool perform_carrier_sense(radio_modems_t modem,
Expand Down

0 comments on commit 5341e8c

Please sign in to comment.