Skip to content

Cellular: fix ATHandler destructor possible crash on delete #10684

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

Merged
merged 1 commit into from
Sep 4, 2019
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ set(unittest-test-sources
stubs/ATHandler_stub.cpp
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,6 @@ set(unittest-test-sources
stubs/CellularContext_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/SocketAddress_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ set(unittest-test-sources
stubs/SerialBase_stub.cpp
stubs/CellularStateMachine_stub.cpp
stubs/CellularContext_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)

# defines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@ set(unittest-test-sources
stubs/EventQueue_stub.cpp
stubs/FileHandle_stub.cpp
stubs/mbed_assert_stub.c
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,6 @@ set(unittest-test-sources
stubs/mbed_assert_stub.c
stubs/SocketAddress_stub.cpp
stubs/randLIB_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,7 @@ set(unittest-test-sources
stubs/us_ticker_stub.cpp
stubs/mbed_assert_stub.c
stubs/ThisThread_stub.cpp
stubs/mbed_wait_api_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,6 @@ set(unittest-test-sources
stubs/SocketAddress_stub.cpp
stubs/mbed_assert_stub.c
stubs/ThisThread_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class TestATHandler : public testing::Test {
urc_callback_count = 0;
CellularUtil_stub::char_ptr = NULL;
CellularUtil_stub::char_pos = 0;
filehandle_stub_short_value_counter = 0;
}

void TearDown()
Expand Down Expand Up @@ -352,6 +353,7 @@ TEST_F(TestATHandler, test_ATHandler_cmd_start)
{
EventQueue que;
FileHandle_stub fh1;
fh1.short_value = 0;

ATHandler at(&fh1, que, 0, ",");
mbed_poll_stub::revents_value = POLLOUT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

# Add test specific include paths
set(unittest-includes ${unittest-includes}
features/cellular/framework/common/util
../platform
../features/cellular/framework/common/util
../features/cellular/framework/common
../features/cellular/framework/AT
../features/frameworks/mbed-client-randlib/mbed-client-randlib

)

# Source files
Expand All @@ -31,6 +33,10 @@ set(unittest-test-sources
stubs/ThisThread_stub.cpp
stubs/randLIB_stub.cpp
stubs/CellularUtil_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
stubs/mbed_rtos_rtx_stub.c
stubs/rtx_mutex_stub.c
)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_CELLULAR_DEBUG_AT=true -DOS_STACK_SIZE=2048")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ set(unittest-test-sources
stubs/CellularDevice_stub.cpp
stubs/equeue_stub.c
stubs/ThisThread_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)

# defines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ set(unittest-test-sources
stubs/NetworkInterface_stub.cpp
stubs/NetworkInterfaceDefaults_stub.cpp
stubs/CellularContext_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)

# defines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ set(unittest-test-sources
stubs/EventQueue_stub.cpp
stubs/equeue_stub.c
stubs/CellularContext_stub.cpp
stubs/ConditionVariable_stub.cpp
stubs/Mutex_stub.cpp
)

# defines
Expand Down
5 changes: 4 additions & 1 deletion UNITTESTS/features/lorawan/loramac/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,13 @@ set(unittest-test-sources
stubs/LoRaWANTimer_stub.cpp
stubs/LoRaMacCommand_stub.cpp
stubs/EventQueue_stub.cpp

stubs/Mutex_stub.cpp
)

# defines
#set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_RTOS_PRESENT=1")
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_RTOS_PRESENT=1")

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -DMBED_CONF_LORA_ADR_ON=true -DMBED_CONF_LORA_PUBLIC_NETWORK=true -DMBED_CONF_LORA_NB_TRIALS=2 -DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMBED_CONF_LORA_ADR_ON=true -DMBED_CONF_LORA_PUBLIC_NETWORK=true -DMBED_CONF_LORA_NB_TRIALS=2 -DMBED_CONF_LORA_DOWNLINK_PREAMBLE_LENGTH=5")

Expand Down
1 change: 1 addition & 0 deletions UNITTESTS/features/lorawan/lorawaninterface/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ set(unittest-test-sources
stubs/LoRaWANTimer_stub.cpp
stubs/LoRaMacCommand_stub.cpp
stubs/LoRaPHYEU868_stub.cpp
stubs/Mutex_stub.cpp
)

# defines
Expand Down
2 changes: 1 addition & 1 deletion UNITTESTS/features/lorawan/lorawanstack/unittest.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ set(unittest-test-sources
stubs/LoRaMacCommand_stub.cpp
stubs/EventQueue_stub.cpp
stubs/equeue_stub.c

stubs/Mutex_stub.cpp
)

# defines
Expand Down
3 changes: 3 additions & 0 deletions UNITTESTS/stubs/ATHandler_stub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,9 @@ void ATHandler_stub::debug_call_count_clear()

ATHandler::ATHandler(FileHandle *fh, EventQueue &queue, uint32_t timeout, const char *output_delimiter, uint16_t send_delay) :
_nextATHandler(0),
#if defined AT_HANDLER_MUTEX && defined MBED_CONF_RTOS_PRESENT
_oobCv(_fileHandleMutex),
#endif
_fileHandle(fh),
_queue(queue),
_ref_count(1),
Expand Down
55 changes: 55 additions & 0 deletions UNITTESTS/stubs/ConditionVariable_stub.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Copyright (c) 2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_OS_UNITTESTS_STUBS_CONDITIONVARIABLE_STUB_CPP_
#define MBED_OS_UNITTESTS_STUBS_CONDITIONVARIABLE_STUB_CPP_

#include "ConditionVariable_stub.h"
#include "mbed_error.h"
#include "mbed_assert.h"

bool ConditionVariable_stub::time_out = false;
#ifdef MBED_CONF_RTOS_PRESENT
using namespace rtos;

ConditionVariable::ConditionVariable(Mutex &mutex): _mutex(mutex), _wait_list(0)
{
// No initialization to do
}

ConditionVariable::~ConditionVariable()
{
}

void ConditionVariable::notify_one()
{

}

void ConditionVariable::wait()
{
}

bool ConditionVariable::wait_for(uint32_t millisec)
{
return ConditionVariable_stub::time_out;
}

void ConditionVariable::notify_all()
{
}
#endif
#endif /* MBED_OS_UNITTESTS_STUBS_CONDITIONVARIABLE_STUB_CPP_ */
27 changes: 27 additions & 0 deletions UNITTESTS/stubs/ConditionVariable_stub.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (c) 2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MBED_OS_UNITTESTS_STUBS_CONDITIONVARIABLE_STUB_H_
#define MBED_OS_UNITTESTS_STUBS_CONDITIONVARIABLE_STUB_H_

#include "rtos/ConditionVariable.h"

namespace ConditionVariable_stub {
extern bool time_out;
}


#endif /* MBED_OS_UNITTESTS_STUBS_CONDITIONVARIABLE_STUB_H_ */
20 changes: 20 additions & 0 deletions UNITTESTS/stubs/mbed_rtos_rtx_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright (c) 2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "cmsis_os2.h"

osMutexId_t singleton_mutex_id;
28 changes: 28 additions & 0 deletions UNITTESTS/stubs/rtx_mutex_stub.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (c) 2019, Arm Limited and affiliates.
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#include "cmsis_os2.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

code files need license on top of them, please add to all new files

Copy link
Contributor

Choose a reason for hiding this comment

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

Added license where it was missing.


osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout)
{
return osOK;
}

osStatus_t osMutexRelease(osMutexId_t mutex_id)
{
return osOK;
}
36 changes: 33 additions & 3 deletions UNITTESTS/target_h/cmsis_os2.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
#ifndef __CMSIS_OS2_H__
#define __CMSIS_OS2_H__

#ifdef __cplusplus
extern "C"
{
#endif

#include <inttypes.h>

//If conflicts, then remove these, copied from cmsis_os.h
typedef int32_t osStatus;

#define osOK 0
#define osErrorNoMemory -5


//These are from cmsis_os2.h
typedef void *osSemaphoreId_t;
Expand All @@ -37,13 +39,27 @@ typedef struct {
uint32_t cb_size; ///< size of provided memory for control block
} osSemaphoreAttr_t;

/// Status code values returned by CMSIS-RTOS functions.
typedef enum {
osOK = 0, ///< Operation completed successfully.
osError = -1, ///< Unspecified RTOS error: run-time error but no other error message fits.
osErrorTimeout = -2, ///< Operation not completed within the timeout period.
osErrorResource = -3, ///< Resource not available.
osErrorParameter = -4, ///< Parameter error.
osErrorNoMemory = -5, ///< System is out of memory: it was impossible to allocate or reserve memory for the operation.
osErrorISR = -6, ///< Not allowed in ISR context: the function cannot be called from interrupt service routines.
osStatusReserved = 0x7FFFFFFF ///< Prevents enum down-size compiler optimization.
} osStatus_t;

//Thread
typedef enum {
osPriorityNormal = 24 ///< Priority: normal
} osPriority_t;

typedef void *osThreadId_t;

typedef void *osMutexId_t;

typedef void *osEventFlagsId_t;

/// Attributes structure for thread.
Expand Down Expand Up @@ -74,5 +90,19 @@ typedef struct {
#define osMutexPrioInherit 0x00000002U ///< Priority inherit protocol.
#define osMutexRobust 0x00000008U ///< Robust mutex.

/// Acquire a Mutex or timeout if it is locked.
/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
/// \param[in] timeout \ref CMSIS_RTOS_TimeOutValue or 0 in case of no time-out.
/// \return status code that indicates the execution status of the function.
osStatus_t osMutexAcquire(osMutexId_t mutex_id, uint32_t timeout);

/// Release a Mutex that was acquired by \ref osMutexAcquire.
/// \param[in] mutex_id mutex ID obtained by \ref osMutexNew.
/// \return status code that indicates the execution status of the function.
osStatus_t osMutexRelease(osMutexId_t mutex_id);

#ifdef __cplusplus
}
#endif

#endif
Loading