Skip to content
Open
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
90031b5
add sleep in destructor of test
preeja33 Aug 20, 2025
0c277fd
Update MiracastServiceImplementation.cpp
preeja33 Aug 20, 2025
c361e04
Update L1-tests.yml
preeja33 Aug 20, 2025
ed8950a
Update MiracastController.cpp
preeja33 Aug 20, 2025
6d1817d
Update MiracastController.cpp
preeja33 Aug 20, 2025
d7c93e9
Update MiracastController.cpp
preeja33 Aug 20, 2025
b960740
Update MiracastP2P.cpp
preeja33 Aug 21, 2025
256de6d
Update MiracastController.cpp
preeja33 Aug 21, 2025
b6616ae
Update MiracastP2P.cpp
preeja33 Aug 21, 2025
18377be
Update MiracastCommon.cpp
preeja33 Aug 21, 2025
97bf9d1
Update MiracastLogger.cpp
preeja33 Aug 21, 2025
5b72bc0
Update MiracastP2P.cpp
preeja33 Aug 21, 2025
4834db8
Update MiracastController.cpp
preeja33 Aug 21, 2025
c431142
Update MiracastController.cpp
preeja33 Aug 21, 2025
2cfd0c0
Update MiracastCommon.cpp
preeja33 Aug 21, 2025
e4b52b9
Update MiracastController.cpp
preeja33 Aug 21, 2025
d07c743
Update MiracastCommon.cpp
preeja33 Aug 21, 2025
052b64c
Update MiracastCommon.cpp
preeja33 Aug 21, 2025
a6c22d8
Update MiracastCommon.cpp
preeja33 Aug 21, 2025
32d7992
Update MiracastCommon.cpp
preeja33 Aug 21, 2025
cd44116
Update MiracastCommon.cpp
preeja33 Aug 21, 2025
7eaab09
Update MiracastController.cpp
preeja33 Aug 21, 2025
82774d1
Update MiracastController.cpp
preeja33 Aug 21, 2025
b64725b
Update MiracastController.cpp
preeja33 Aug 21, 2025
5739a01
Update MiracastController.cpp
preeja33 Aug 21, 2025
2088ce2
Update MiracastController.cpp
preeja33 Aug 21, 2025
5a9936a
Update MiracastCommon.cpp
preeja33 Aug 21, 2025
b4fa0eb
Update MiracastCommon.cpp
preeja33 Aug 21, 2025
1a0e2bf
Update MiracastCommon.cpp
preeja33 Aug 22, 2025
7979434
Update MiracastCommon.cpp
preeja33 Aug 22, 2025
a2fa25c
Update MiracastController.cpp
preeja33 Aug 22, 2025
fa8e4bf
Update MiracastServiceImplementation.cpp
preeja33 Aug 22, 2025
07cb92a
Update test_MiracastService.cpp
preeja33 Aug 22, 2025
c5339da
Update test_MiracastService.cpp
preeja33 Aug 22, 2025
85ccdca
Update test_MiracastService.cpp
preeja33 Aug 22, 2025
e83e97f
Update test_MiracastService.cpp
preeja33 Aug 22, 2025
93329d9
Update MiracastServiceImplementation.cpp
preeja33 Aug 27, 2025
873d70d
remove sleep hack
preeja33 Aug 27, 2025
85d314d
comment plyaer test
preeja33 Aug 27, 2025
a07917b
Update test_MiracastPlayer.cpp
preeja33 Aug 27, 2025
f2b9040
Update MiracastService.cpp
preeja33 Aug 28, 2025
8f933c6
Update MiracastServiceImplementation.cpp
preeja33 Aug 28, 2025
c908a60
Update MiracastServiceImplementation.cpp
preeja33 Aug 28, 2025
829410b
Update MiracastService.cpp
preeja33 Aug 28, 2025
09fe767
Update MiracastService.cpp
preeja33 Aug 28, 2025
682f835
Update MiracastService.cpp
preeja33 Aug 28, 2025
5286bc1
Update MiracastService.cpp
preeja33 Aug 28, 2025
43653bb
Update MiracastService.cpp
preeja33 Aug 28, 2025
e379875
Update MiracastController.cpp
preeja33 Aug 29, 2025
11728ad
Update MiracastService.cpp
balav08 Aug 29, 2025
70c35a2
Update test_MiracastService.cpp
balav08 Aug 29, 2025
f18129e
Update MiracastServiceImplementation.cpp
preeja33 Aug 29, 2025
fae9ae2
Update MiracastService.cpp
preeja33 Aug 29, 2025
ce3b0ee
Merge branch 'develop' into test_malloc
preeja33 Sep 4, 2025
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
2 changes: 1 addition & 1 deletion .github/workflows/L1-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ jobs:
with:
repository: rdkcentral/entservices-casting
path: entservices-casting
ref: develop
ref: test_malloc

- name: Checkout googletest
if: steps.cache.outputs.cache-hit != 'true'
Expand Down
44 changes: 26 additions & 18 deletions Miracast/MiracastService/MiracastController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,15 @@ MiracastController *MiracastController::getInstance(MiracastError &error_code, M

void MiracastController::destroyInstance()
{
MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("Entering...");
if (nullptr != m_miracast_ctrl_obj)
{
m_miracast_ctrl_obj->destroy_ControllerFramework();
delete m_miracast_ctrl_obj;
m_miracast_ctrl_obj = nullptr;
}
MIRACASTLOG_TRACE("Exiting...");

MIRACASTLOG_INFO("Exiting...");
}

MiracastController::MiracastController(void)
Expand All @@ -71,7 +72,7 @@ MiracastController::MiracastController(void)

MiracastController::~MiracastController()
Copy link
Contributor

@rdkcmf-jenkins rdkcmf-jenkins Aug 21, 2025

Choose a reason for hiding this comment

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

Coverity issue no longer present as of: undefined

Show issue

Coverity Issue - Uncaught exception

An exception of type "std::regex_error" is thrown but the exception specification "/implicit/noexcept" doesn't allow it to be thrown. This will result in a call to terminate().

Medium Impact, CWE-248
UNCAUGHT_EXCEPT

{
MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("Entering...");

while (!m_deviceInfoList.empty())
{
Expand All @@ -85,13 +86,17 @@ MiracastController::~MiracastController()
m_groupInfo = nullptr;
}

MIRACASTLOG_TRACE("Exiting...");


// ControllerThreadCallback(this);
//destroy_ControllerFramework();
MIRACASTLOG_INFO("Exiting...");
}

MiracastError MiracastController::create_ControllerFramework(std::string p2p_ctrl_iface)
{
MiracastError ret_code = MIRACAST_OK;
MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("Entering...start controller thread");

m_controller_thread = new MiracastThread(CONTROLLER_THREAD_NAME,
CONTROLLER_THREAD_STACK,
Expand Down Expand Up @@ -503,7 +508,7 @@ void MiracastController::event_handler(P2P_EVENTS eventId, void *data, size_t le
std::string event_buffer;
MIRACASTLOG_TRACE("Entering...");

event_buffer = (char *)data;
event_buffer = static_cast<char*>(data);
free(data);

if ( false == m_start_discovering_enabled )
Expand All @@ -518,8 +523,8 @@ void MiracastController::event_handler(P2P_EVENTS eventId, void *data, size_t le
controller_msgq_data.state = convertP2PtoSessionActions(eventId);
strncpy(controller_msgq_data.msg_buffer, event_buffer.c_str(), sizeof(controller_msgq_data.msg_buffer));
controller_msgq_data.msg_buffer[sizeof(controller_msgq_data.msg_buffer) - 1] = '\0';

MIRACASTLOG_INFO("event_handler to Controller Action[%#08X] buffer:%s ", controller_msgq_data.state, event_buffer.c_str());
MIRACASTLOG_INFO("event_handler to Controller Action[%#08X] buffer:%s len %d", controller_msgq_data.state, event_buffer.c_str(),len);
Copy link
Contributor

Choose a reason for hiding this comment

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

Coverity Issue - Invalid type in argument to printf format specifier

Argument "len" to format specifier "%d" was expected to have type "int" but has type "unsigned long".

Medium Impact, CWE-686
PRINTF_ARGS

m_controller_thread->send_message(&controller_msgq_data, sizeof(controller_msgq_data));
MIRACASTLOG_VERBOSE("event received : %d buffer:%s ", eventId, event_buffer.c_str());
}
Expand Down Expand Up @@ -642,7 +647,7 @@ bool MiracastController::get_connection_status()
void MiracastController::create_DeviceCacheData(std::string deviceMAC,std::string authType,std::string modelName,std::string deviceType, bool force_overwrite)
{
bool new_device_entry = false;
MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("Entering...");
DeviceInfo *cur_device_info_ptr = MiracastController::get_device_details(deviceMAC);

// Allocate memory and update the device cache info
Expand All @@ -651,7 +656,7 @@ void MiracastController::create_DeviceCacheData(std::string deviceMAC,std::strin
cur_device_info_ptr = new DeviceInfo;
new_device_entry = true;
force_overwrite = true;
MIRACASTLOG_VERBOSE("#### Creating Device Cache ####");
MIRACASTLOG_INFO("#### Creating Device Cache ####");
}

if (( nullptr != cur_device_info_ptr ) && (force_overwrite))
Expand All @@ -673,24 +678,25 @@ void MiracastController::create_DeviceCacheData(std::string deviceMAC,std::strin
{
m_deviceInfoList.push_back(cur_device_info_ptr);
}
MIRACASTLOG_TRACE("Exiting...");
MIRACASTLOG_INFO("Exiting...");
}

DeviceInfo *MiracastController::get_device_details(std::string MAC)
{
DeviceInfo *deviceInfo = nullptr;
std::size_t found;
MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("Entering...");
for (auto device : m_deviceInfoList)
{
MIRACASTLOG_INFO("Entering device info list");
found = device->deviceMAC.find(MAC);
if (found != std::string::npos)
{
deviceInfo = device;
break;
}
}
MIRACASTLOG_TRACE("Exiting...");
MIRACASTLOG_INFO("Exiting...");
return deviceInfo;
}

Expand Down Expand Up @@ -784,19 +790,19 @@ void MiracastController::Controller_Thread(void *args)
session_restart_required = false,
p2p_group_instance_alive = false;

MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("Entering...");

while (nullptr != m_controller_thread)
{
std::string event_buffer;
event_buffer.clear();

MIRACASTLOG_TRACE("!!! Waiting for Event !!!\n");
MIRACASTLOG_INFO("!!! Waiting for Event !!!\n");
m_controller_thread->receive_message(&controller_msgq_data, CONTROLLER_MSGQ_SIZE, THREAD_RECV_MSG_INDEFINITE_WAIT);

event_buffer = controller_msgq_data.msg_buffer;

MIRACASTLOG_TRACE("!!! Received Action[%#08X]Data[%s] !!!\n", controller_msgq_data.state, event_buffer.c_str());
MIRACASTLOG_INFO("!!! Received Action[%#08X]Data[%s] !!!\n", controller_msgq_data.state, event_buffer.c_str());

if (CONTROLLER_SELF_ABORT == controller_msgq_data.state)
{
Expand Down Expand Up @@ -1099,6 +1105,7 @@ void MiracastController::Controller_Thread(void *args)
else
{
error_code = WPEFramework::Exchange::IMiracastService::REASON_CODE_GENERIC_FAILURE;
MIRACASTLOG_INFO("predebug session restart");
session_restart_required = true;
MIRACASTLOG_ERROR("!!!! Unable to get the Source Device IP and Terminating Group Here !!!!");
remove_P2PGroupInstance();
Expand Down Expand Up @@ -1247,6 +1254,7 @@ void MiracastController::Controller_Thread(void *args)
}
new_thunder_req_client_connection_sent = false;
another_thunder_req_client_connection_sent = false;
MIRACASTLOG_INFO("predebug session_restart_required\n");
session_restart_required = true;
p2p_group_instance_alive = false;
m_connect_req_notified = false;
Expand Down Expand Up @@ -1605,10 +1613,10 @@ void ControllerThreadCallback(void *args)
{
MiracastController *miracast_ctrler_obj = (MiracastController *)args;
MIRACASTLOG_TRACE("Entering...");
sleep(1);
// sleep(1);
if ( nullptr != miracast_ctrler_obj )
{
miracast_ctrler_obj->Controller_Thread(nullptr);
}
MIRACASTLOG_TRACE("Exiting...");
}
}
5 changes: 3 additions & 2 deletions Miracast/MiracastService/MiracastServiceImplementation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ namespace WPEFramework
m_SystemPluginObj = nullptr;
}

MIRACASTLOG_INFO("Disconnect from the COM-RPC socket");
MIRACASTLOG_INFO("predebug Disconnect from the COM-RPC socket");

if (m_isServiceInitialized)
{
Expand All @@ -114,6 +114,7 @@ namespace WPEFramework
}
MIRACAST::logger_deinit();
MiracastServiceImplementation::_instance = nullptr;
MIRACASTLOG_INFO("predebug destruction done");
}

/**
Expand Down Expand Up @@ -1233,4 +1234,4 @@ namespace WPEFramework
/* Internal Timer Callback and methods End */
/* ------------------------------------------------------------------------------------------------------- */
} // namespace Plugin
} // namespace WPEFramework
} // namespace WPEFramework
9 changes: 5 additions & 4 deletions Miracast/MiracastService/P2P/MiracastP2P.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -361,16 +361,17 @@ int MiracastP2P::p2pExecute(char *cmd, enum INTERFACE iface, char *ret_buf, size

MiracastError MiracastP2P::executeCommand(std::string command, int interface, std::string &retBuffer)
{
MIRACASTLOG_TRACE("Entering..");

MIRACASTLOG_INFO("Executing P2P command %s", command.c_str());
MIRACASTLOG_INFO("Entering..");
MIRACASTLOG_INFO("Executing P2P command %s", command.c_str());
{
char ret_buffer[2048] = {0};
p2pExecute((char *)command.c_str(), static_cast<P2P_INTERFACE>(interface), ret_buffer,sizeof(ret_buffer));
retBuffer = ret_buffer;
MIRACASTLOG_INFO("command return buffer is - %s", retBuffer.c_str());
}
MIRACASTLOG_TRACE("Exiting..");

MIRACASTLOG_INFO("Exiting..");
return MIRACAST_OK;
}

Expand Down
51 changes: 42 additions & 9 deletions Miracast/common/MiracastCommon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,15 @@ MiracastThread::MiracastThread(std::string thread_name, size_t stack_size, size_

MiracastThread::~MiracastThread()
{
MIRACASTLOG_TRACE("Entering...");
MIRACASTLOG_INFO("Entering...");

if ( 0 != m_pthread_id ){
// Join thread
pthread_join(m_pthread_id, nullptr);
int ret = pthread_join(m_pthread_id, nullptr);
if (ret !=0) {
MIRACASTLOG_INFO("pthread join failed");
}
MIRACASTLOG_INFO("Exit from joining...");
m_pthread_id = 0;
pthread_attr_destroy(&m_pthread_attr);
}
Expand All @@ -63,7 +67,7 @@ MiracastThread::~MiracastThread()
sem_destroy(&m_empty_msgq_sem_obj);
m_g_queue = nullptr;
}
MIRACASTLOG_TRACE("Exiting...");
MIRACASTLOG_INFO("Exiting...");
}

MiracastError MiracastThread::start(void)
Expand All @@ -84,20 +88,35 @@ MiracastError MiracastThread::start(void)
void MiracastThread::send_message(void *message, size_t msg_size)
{
MIRACASTLOG_TRACE("Entering...");

if (nullptr != m_g_queue){
void *buffer = malloc(msg_size);
if (nullptr == buffer)

#if 0
MIRACASTLOG_TRACE("msg size %d", msg_size);

void *buffer = malloc(msg_size);
if (nullptr == buffer)
{
MIRACASTLOG_ERROR("Memory Allocation Failed for %u\n", msg_size);
MIRACASTLOG_TRACE("Exiting...");
return;
}
memset(buffer, 0x00, msg_size);
// Send message to queue

MIRACASTLOG_TRACE("");
memcpy(buffer, message, msg_size);
g_async_queue_push(m_g_queue, buffer);
MIRACASTLOG_TRACE("copied");
#endif
auto buffer = std::make_shared<std::vector<char>>((char*)message, (char*)message + msg_size);


// Allocate wrapper and push to queue
auto* wrapper = new std::shared_ptr<std::vector<char>>(buffer);
Copy link
Contributor

@rdkcmf-jenkins rdkcmf-jenkins Aug 21, 2025

Choose a reason for hiding this comment

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

Coverity issue no longer present as of: undefined

Show issue

Coverity Issue - Variable copied when it could be moved

"buffer" is passed-by-value as parameter to "std::shared_ptr<std::vector<char, std::allocator > >::shared_ptr(std::shared_ptr<std::vector<char, std::allocator > > const &) /explicit =default/", when it could be moved instead.

Low Impact, CWE-none
COPY_INSTEAD_OF_MOVE

How to fix

Use "std::move(""buffer"")" instead of "buffer".

g_async_queue_push(m_g_queue, wrapper);
MIRACASTLOG_TRACE("pushed");
sem_post(&m_empty_msgq_sem_obj);
MIRACASTLOG_TRACE("sempost");

}
MIRACASTLOG_TRACE("Exiting...");
}
Expand All @@ -113,6 +132,7 @@ int8_t MiracastThread::receive_message(void *message, size_t msg_size, int sem_w
int count = 0;
sem_getvalue(&m_empty_msgq_sem_obj,&count);
if ((0 < count ) || (THREAD_RECV_MSG_INDEFINITE_WAIT == sem_wait_timedout)){

sem_wait(&m_empty_msgq_sem_obj);
status = true;
}
Expand All @@ -135,14 +155,27 @@ int8_t MiracastThread::receive_message(void *message, size_t msg_size, int sem_w

if (true == status)
{
void *data_ptr = static_cast<void *>(g_async_queue_pop(m_g_queue));
auto* buffer_ptr = static_cast<std::shared_ptr<std::vector<char>>*>(data_ptr);
if (buffer_ptr && *buffer_ptr) {
std::shared_ptr<std::vector<char>> buffer = *buffer_ptr;
memcpy(message, buffer->data(), buffer->size());
}
delete buffer_ptr; // Clean up the wrapper

}

#if 0
void *data_ptr = static_cast<void *>(g_async_queue_pop(m_g_queue));
if ((nullptr != message) && (nullptr != data_ptr))
{
MIRACASTLOG_TRACE("dequeue...");
memcpy(message, data_ptr, msg_size);
free(data_ptr);
}
#endif
}
}

MIRACASTLOG_TRACE("Exiting...");
return status;
}
Expand Down Expand Up @@ -398,4 +431,4 @@ void MessageQueue::detachQueue(void)
m_condNotFull.notify_all();

MIRACASTLOG_TRACE("Exiting...");
}
}
2 changes: 1 addition & 1 deletion Miracast/common/MiracastLogger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ namespace MIRACAST
setvbuf(stdout, NULL, _IOLBF, 0);
}

static int gDefaultLogLevel = INFO_LEVEL;
static int gDefaultLogLevel = TRACE_LEVEL;
static std::string service_name = "NOT-DEFINED";

void logger_init(const char* module_name)
Expand Down
9 changes: 7 additions & 2 deletions Tests/L1Tests/tests/test_MiracastService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace
#define TEST_LOG(FMT, ...) log(__func__, __FILE__, __LINE__, syscall(__NR_gettid),FMT,##__VA_ARGS__)

//Commented out the functions below because some test cases that use them have also been commented out. Since those test cases are disabled, these functions are now unused.
#if 0
#if 1
static void removeFile(const char* fileName)
{
if (std::remove(fileName) != 0)
Expand Down Expand Up @@ -252,14 +252,19 @@ class MiracastServiceEventTest : public MiracastServiceTest {
dispatcher->Release();

PluginHost::IFactories::Assign(nullptr);
TEST_LOG("predebug Before destructor sleep ");
//Wait for all the previous destructor process to complete
std::this_thread::sleep_for(std::chrono::milliseconds(3000));
TEST_LOG("predebug After destructor sleep ");

}
};

TEST_F(MiracastServiceTest, GetInformation)
{
EXPECT_EQ("This MiracastService Plugin Facilitates Peer-to-Peer Control and WFD Source Device Discovery", plugin->Information());
}
#if 0
#if 1
TEST_F(MiracastServiceTest, P2PCtrlInterfaceNameNotFound)
{
removeEntryFromFile("/etc/device.properties","WIFI_P2P_CTRL_INTERFACE=p2p0");
Expand Down
Loading