diff --git a/.github/workflows/code-coverage.yml b/.github/workflows/code-coverage.yml index dca9e7e0..5ad3ac07 100644 --- a/.github/workflows/code-coverage.yml +++ b/.github/workflows/code-coverage.yml @@ -2,7 +2,7 @@ name: Code Coverage on: pull_request: - branches: [ main, develop] + branches: [ main] env: AUTOMATICS_UNAME: ${{ secrets.AUTOMATICS_UNAME }} @@ -31,32 +31,18 @@ jobs: run: | docker run -d --name native-platform -v ${{ github.workspace }}:/mnt/L1_CONTAINER_SHARED_VOLUME ghcr.io/rdkcentral/docker-device-mgt-service-test/native-platform:latest - - name: Run unit tests with coverage flags enabled - run: docker exec -i native-platform /bin/bash -c "cd /mnt/L1_CONTAINER_SHARED_VOLUME/ && sh test/run_ut.sh --enable-cov" + - name: Run unit tests with coverage flags enabled and Caculate the code coverage summary + run: docker exec -i native-platform /bin/bash -c "cd /mnt/L1_CONTAINER_SHARED_VOLUME/ && sh test/run_ut.sh --enable-cov && lcov --list coverage.info | grep 'Lines\|Total' > /tmp/coverage_summary.txt" - - name: Caculate the code coverage summary - run: | - lcov --list coverage.info | grep "Lines\|Total" > /tmp/Gtest_Report/coverage_summary.txt - - - name: Copy the code coverage to runner - run: | - docker cp native-platform:/tmp/Gtest_Report/ /tmp/Gtest_Report/ + - name: Copy coverage summary to runner + run: docker cp native-platform:/tmp/coverage_summary.txt /tmp/ - upload-test-results: - name: Upload L1 coverage reports - needs: execute-unit-code-coverage-report-on-release - runs-on: ubuntu-latest - container: - image: ghcr.io/rdkcentral/docker-rdk-ci:latest - volumes: - - /tmp/Gtest_Report:/tmp/Gtest_Report - steps: - name: Update the coverage report to Pull request using actions uses: actions/github-script@v4 with: script: | const fs = require('fs'); - const lcov_result = fs.readFileSync('/tmp/Gtest_Report/coverage_summary.txt', 'utf8'); + const lcov_result = fs.readFileSync('/tmp/coverage_summary.txt', 'utf8'); github.issues.createComment({ issue_number: context.issue.number, @@ -71,12 +57,13 @@ jobs: }); - name: Generate the html report - run: | - genhtml coverage.info --output-directory /tmp/coverage_report + run: docker exec -i native-platform /bin/bash -c " cd /mnt/L1_CONTAINER_SHARED_VOLUME/ && genhtml coverage.info --output-directory /tmp/coverage_report" + + - name: Copy html report to runner + run: docker cp native-platform:/tmp/coverage_report /tmp/ - name: Upload the coverage report to Pull request using actions uses: actions/upload-artifact@v4 with: name: coverage-report path: /tmp/coverage_report - diff --git a/CHANGELOG.md b/CHANGELOG.md index 63fd521a..b2d73cc3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,15 +4,25 @@ All notable changes to this project will be documented in this file. Dates are d Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). +#### [1.6.5](https://github.com/rdkcentral/telemetry/compare/1.6.4...1.6.5) + +- ISSUE-76 : Fix race condition during aggressive reloads [`#189`](https://github.com/rdkcentral/telemetry/pull/189) +- Add "REPORT_TYPE":"CACHED" to cache reports [`#154`](https://github.com/rdkcentral/telemetry/pull/154) +- RDKB-62050 : Telemetry report upload failed while using Red Recovery [`#191`](https://github.com/rdkcentral/telemetry/pull/191) +- Resolve code coverage hang issue in develop [`#185`](https://github.com/rdkcentral/telemetry/pull/185) + #### [1.6.4](https://github.com/rdkcentral/telemetry/compare/1.6.3...1.6.4) -- RDKB-61931: Removing Openssl Engine setup/override logic in Telemetry [`#186`](https://github.com/rdkcentral/telemetry/pull/186) +> 6 October 2025 + +- Removing Openssl Engine setup/override logic in Telemetry [`#186`](https://github.com/rdkcentral/telemetry/pull/186) - RDK-59038: Improve L1 test coverage [`#176`](https://github.com/rdkcentral/telemetry/pull/176) - Deploy fossid_integration_stateless_diffscan_target_repo action [`#182`](https://github.com/rdkcentral/telemetry/pull/182) - ISSUE-76: Ensure Signal Handler in not preempted [`#181`](https://github.com/rdkcentral/telemetry/pull/181) - Deploy cla action [`#123`](https://github.com/rdkcentral/telemetry/pull/123) -- RDKB-61783: Update curlinterface.c [`3ef7367`](https://github.com/rdkcentral/telemetry/commit/3ef73672d79760e15ce39485d76749398b31dc91) -- RDKB-61783: Update xconfclient.c [`3a53047`](https://github.com/rdkcentral/telemetry/commit/3a530471dc93df0ef94b3f15bc7f696271fb2e03) +- Changelog updates for release 1.6.4 - Correct libcurl SSL api usage [`73fb221`](https://github.com/rdkcentral/telemetry/commit/73fb22121d8554880a684ff079e1d2dec2b251fb) +- Update curlinterface.c [`3ef7367`](https://github.com/rdkcentral/telemetry/commit/3ef73672d79760e15ce39485d76749398b31dc91) +- Update xconfclient.c [`3a53047`](https://github.com/rdkcentral/telemetry/commit/3a530471dc93df0ef94b3f15bc7f696271fb2e03) #### [1.6.3](https://github.com/rdkcentral/telemetry/compare/1.6.2...1.6.3) diff --git a/source/bulkdata/profile.c b/source/bulkdata/profile.c index 6d7c094e..f2d27eac 100644 --- a/source/bulkdata/profile.c +++ b/source/bulkdata/profile.c @@ -686,6 +686,8 @@ static void* CollectAndReport(void* data) Vector_RemoveItem(profile->cachedReportList, (void*) thirdCachedReport, NULL); free(thirdCachedReport); } + // Before caching the report, add "REPORT_TYPE": "CACHED" + tagReportAsCached(&jsonReport); Vector_PushBack(profile->cachedReportList, jsonReport); T2Info("Report Cached, No. of reportes cached = %lu\n", (unsigned long )Vector_Size(profile->cachedReportList)); diff --git a/source/bulkdata/profilexconf.c b/source/bulkdata/profilexconf.c index d101020e..08d35f00 100644 --- a/source/bulkdata/profilexconf.c +++ b/source/bulkdata/profilexconf.c @@ -220,6 +220,11 @@ static void* CollectAndReportXconf(void* data) do { T2Info("%s while Loop -- START \n", __FUNCTION__); + if(singleProfile == NULL) + { + T2Error("%s is called with empty profile, profile reload might be in-progress, skip the request\n", __FUNCTION__); + goto reportXconfThreadEnd; + } profile = singleProfile; Vector *profileParamVals = NULL; Vector *grepResultList = NULL; @@ -349,6 +354,8 @@ static void* CollectAndReportXconf(void* data) Vector_RemoveItem(profile->cachedReportList, (void*) thirdCachedReport, NULL); free(thirdCachedReport); } + // Before caching the report, add "REPORT_TYPE": "CACHED" + // tagReportAsCached(&jsonReport); Vector_PushBack(profile->cachedReportList, strdup(jsonReport)); profile->reportInProgress = false; /* CID 187010: Dereference before null check */ @@ -419,6 +426,8 @@ static void* CollectAndReportXconf(void* data) Vector_RemoveItem(profile->cachedReportList, (void*) thirdCachedReport, NULL); free(thirdCachedReport); } + // Before caching the report, add "REPORT_TYPE": "CACHED" + tagReportAsCached(&jsonReport); Vector_PushBack(profile->cachedReportList, strdup(jsonReport)); T2Info("Report Cached, No. of reportes cached = %lu\n", (unsigned long)Vector_Size(profile->cachedReportList)); @@ -494,7 +503,6 @@ static void* CollectAndReportXconf(void* data) //pthread_mutex_unlock(&plMutex); reportXconfThreadEnd : T2Info("%s while Loop -- END \n", __FUNCTION__); - T2Info("%s --out\n", __FUNCTION__); pthread_cond_wait(&reuseThread, &plMutex); } while(initialized); @@ -592,7 +600,6 @@ T2ERROR ProfileXConf_uninit() pthread_cond_signal(&reuseThread); pthread_mutex_unlock(&plMutex); pthread_join(singleProfile->reportThread, NULL); - reportThreadExits = false; singleProfile->reportInProgress = false ; T2Info("Final report is completed, releasing profile memory\n"); } @@ -727,21 +734,13 @@ T2ERROR ProfileXConf_delete(ProfileXConf *profile) if(singleProfile->reportInProgress) { - T2Info("Waiting for CollectAndReport to be complete : %s\n", singleProfile->name); - pthread_mutex_lock(&plMutex); - initialized = false; - T2Info("Sending signal to reuse Thread in CollectAndReportXconf\n"); - pthread_cond_signal(&reuseThread); - pthread_mutex_unlock(&plMutex); - pthread_join(singleProfile->reportThread, NULL); - T2Info("reportThread exits and initialising the profile list\n"); - reportThreadExits = false; - initialized = true; - singleProfile->reportInProgress = false ; + T2Info("Waiting for CollectAndReportXconf to be complete : %s\n", singleProfile->name); } pthread_mutex_lock(&plMutex); + profile->reportThread = singleProfile->reportThread; + size_t count = Vector_Size(singleProfile->cachedReportList); // Copy any cached message present in previous single profile to new profile if(isNameEqual) @@ -1009,9 +1008,14 @@ T2ERROR ProfileXConf_terminateReport() T2ERROR ret = T2ERROR_FAILURE; + pthread_mutex_lock(&plMutex); + if(!singleProfile) { T2Error("Xconf profile is not set.\n"); + + pthread_mutex_unlock(&plMutex); + return ret; } @@ -1039,6 +1043,8 @@ T2ERROR ProfileXConf_terminateReport() T2Info("No report generation in progress. No further action required for abort.\n"); } + pthread_mutex_unlock(&plMutex); + return ret; } diff --git a/source/protocol/http/curlinterface.c b/source/protocol/http/curlinterface.c index 04937374..c88be56d 100644 --- a/source/protocol/http/curlinterface.c +++ b/source/protocol/http/curlinterface.c @@ -250,10 +250,12 @@ static T2ERROR setPayload(CURL *curl, const char* payload, childResponse *childC return T2ERROR_SUCCESS; } #ifdef LIBRDKCERTSEL_BUILD +#if defined(ENABLE_RED_RECOVERY_SUPPORT) bool isStateRedEnabled(void) { return access("/tmp/stateRedEnabled", F_OK) == 0; } +#endif void curlCertSelectorFree() { rdkcertselector_free(&curlCertSelector); @@ -269,7 +271,10 @@ void curlCertSelectorFree() } static void curlCertSelectorInit() { - bool state_red_enable = isStateRedEnabled(); + bool state_red_enable = false; +#if defined(ENABLE_RED_RECOVERY_SUPPORT) + state_red_enable = isStateRedEnabled(); +#endif if (state_red_enable && curlRcvryCertSelector == NULL ) { curlRcvryCertSelector = rdkcertselector_new( NULL, NULL, "RCVRY" ); @@ -338,9 +343,10 @@ T2ERROR sendReportOverHTTP(char *httpUrl, char *payload, pid_t* outForkedPid) } #ifdef LIBRDKCERTSEL_BUILD curlCertSelectorInit(); +#if defined(ENABLE_RED_RECOVERY_SUPPORT) state_red_enable = isStateRedEnabled(); T2Info("%s: state_red_enable: %d\n", __func__, state_red_enable ); - +#endif if (state_red_enable) { thisCertSel = curlRcvryCertSelector; diff --git a/source/reportgen/reportgen.c b/source/reportgen/reportgen.c index ea8a0fa0..f4249b13 100644 --- a/source/reportgen/reportgen.c +++ b/source/reportgen/reportgen.c @@ -876,3 +876,61 @@ char *prepareHttpUrl(T2HTTP *http) return httpUrl; } + +void tagReportAsCached(char **jsonReport) +{ + if (!jsonReport) + { + T2Error("jsonReport is NULL\n"); + return; + } + + cJSON *jsonReportObj = cJSON_Parse(*jsonReport); + if (!jsonReportObj) + { + T2Error("Failed to parse JSON report\n"); + return; + } + + cJSON *reportTypeEntry = cJSON_CreateObject(); + if (!reportTypeEntry) + { + T2Error("Failed to create REPORT_TYPE object\n"); + destroyJSONReport(jsonReportObj); + return; + } + cJSON_AddStringToObject(reportTypeEntry, "REPORT_TYPE", "CACHED"); + cJSON *searchResult = cJSON_GetObjectItemCaseSensitive(jsonReportObj, "searchResult"); + if (searchResult && cJSON_IsArray(searchResult)) + { + T2Info("Inserting REPORT_TYPE: CACHED at index 1 of searchResult array\n"); + cJSON_InsertItemInArray(searchResult, 1, reportTypeEntry); + } + else + { + cJSON *reportArray = cJSON_GetObjectItemCaseSensitive(jsonReportObj, "Report"); + if (reportArray && cJSON_IsArray(reportArray)) + { + T2Info("Inserting REPORT_TYPE: CACHED at beginning of Report array\n"); + cJSON_InsertItemInArray(reportArray, 0, reportTypeEntry); + } + else + { + T2Error("Neither 'searchResult' nor 'Report' arrays found in the JSON\n"); + destroyJSONReport(reportTypeEntry); + destroyJSONReport(jsonReportObj); + return; + } + } + + char *updatedJsonReport = cJSON_PrintUnformatted(jsonReportObj); + if (updatedJsonReport) + { + free(*jsonReport); // Freeing the old report only after the new one is generated + *jsonReport = updatedJsonReport; + } + + destroyJSONReport(jsonReportObj); +} + + diff --git a/source/reportgen/reportgen.h b/source/reportgen/reportgen.h index f0e1d916..2f9f66a5 100644 --- a/source/reportgen/reportgen.h +++ b/source/reportgen/reportgen.h @@ -79,4 +79,6 @@ T2ERROR prepareJSONReport(cJSON* jsonObj, char** reportBuff); char *prepareHttpUrl(T2HTTP *http); +void tagReportAsCached(char **jsonReport); + #endif /* _REPORTGEN_H_ */ diff --git a/source/test/bulkdata/datamodelTest.cpp b/source/test/bulkdata/datamodelTest.cpp index 133c9184..07f20ca4 100644 --- a/source/test/bulkdata/datamodelTest.cpp +++ b/source/test/bulkdata/datamodelTest.cpp @@ -141,11 +141,10 @@ TEST_F(datamodelTestFixture, datamodel_processProfile_RP) "\"HTTP\":{\"URL\":\"https://stbrtl.r53.xcal.tv/\",\"Compression\":\"None\",\"Method\":\"POST\"," "\"RequestURIParameter\":[{\"Name\":\"reportName\",\"Reference\":\"Profile.Name\"}]}," "\"JSONEncoding\":{\"ReportFormat\":\"NameValuePair\",\"ReportTimestamp\":\"None\"}}}]}"; - EXPECT_CALL(*g_datamodelMock, ReportProfiles_ProcessReportProfilesBlob(_, _)) .Times(1); EXPECT_EQ(T2ERROR_SUCCESS, datamodel_processProfile((char*)testJson, T2_RP)); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } //datamodel_processProfile success test @@ -171,7 +170,7 @@ TEST_F(datamodelTestFixture, datamodel_processProfile_TRP) EXPECT_CALL(*g_datamodelMock, ReportProfiles_ProcessReportProfilesBlob(_, _)) .Times(1); EXPECT_EQ(T2ERROR_SUCCESS, datamodel_processProfile((char*)testJson, T2_TEMP_RP)); - std::this_thread::sleep_for(std::chrono::milliseconds(100)); + std::this_thread::sleep_for(std::chrono::milliseconds(1000)); } //datamodel_processProfile failure test diff --git a/source/test/bulkdata/profileTest.cpp b/source/test/bulkdata/profileTest.cpp index b4632c1b..3041e7ae 100644 --- a/source/test/bulkdata/profileTest.cpp +++ b/source/test/bulkdata/profileTest.cpp @@ -7,6 +7,8 @@ #include #include #include +#include +#include #include "test/mocks/SystemMock.h" #include "test/mocks/FileioMock.h" @@ -1302,11 +1304,10 @@ TEST_F(ProfileTest, InitFailures) { */ TEST_F(ProfileTest, StartDispatchThread_Normal) { - //EREnabled = true; - //stopDispatchThread = true; T2ERROR res = T2ER_StartDispatchThread(); - //ASSERT_EQ(res, T2ERROR_FAILURE); + ASSERT_EQ(res, T2ERROR_SUCCESS); + std::this_thread::sleep_for(std::chrono::milliseconds(100)); // Stop the thread after starting it } #if 0 @@ -1430,308 +1431,9 @@ TEST_F(ProfileTest, VectorMockDemo_PushBack_Success) { #endif -#if 0 -//comment -//==================================== datamodel.c =================== - -TEST_F(ProfileTest, Init_Success) -{ - EXPECT_EQ(datamodel_init(), T2ERROR_SUCCESS); -} - -TEST_F(ProfileTest, processProfile_ValidJson_RP) { - //char json[] = "{\"profiles\":[]}"; - char json[] = "{ \"profiles\": [ { \"name\": \"TR_AC732\", \"hash\": \"Hash732\", \"value\": { \"Name\": \"RDKB_Profile_3\", \"Description\": \"RDKB_Profile\", \"Version\": \"0.1\", \"Protocol\": \"RBUS_METHOD\", \"EncodingType\": \"JSON\", \"ActivationTimeout\": 3600, \"ReportingInterval\": 20, \"GenerateNow\": false, \"RootName\": \"FR2_US_TC3\", \"Parameter\": [ { \"type\": \"event\", \"eventName\": \"TEST_EVENT_MARKER_1\", \"component\": \"sysint\", \"use\": \"count\" }, { \"type\": \"event\", \"eventName\": \"TEST_EVENT_MARKER_2\", \"component\": \"sysint\", \"use\": \"accumulate\", \"reportTimestamp\":\"Unix-Epoch\" }, { \"type\": \"grep\", \"marker\": \"SYS_INFO_CrashPortalUpload_success\", \"search\": \"Success loading\", \"logFile\": \"core_log.txt\", \"use\": \"count\", \"reportEmpty\":true } ], \"ReportingAdjustments\": [ { \"ReportOnUpdate\": false, \"FirstReportingInterval\": 15, \"MaxUploadLatency\": 20000 } ], \"RBUS_METHOD\":{\"Method\":\"Device.X_RDK_Xmidt.SendData\",\"Parameters\":[{\"name\":\"msg_type\",\"value\":\"event\"},{\"name\":\"source\",\"value\":\"telemetry2\"},{\"name\":\"dest\",\"value\":\"event:/profile-report/LTE-report\"},{\"name\":\"content_type\",\"value\":\"application/json\"},{\"name\":\"qos\",\"value\":\"75\"}]}, \"JSONEncoding\": { \"ReportFormat\": \"NameValuePair\", \"ReportTimestamp\": \"None\" } } } ] }"; - EXPECT_EQ(datamodel_processProfile(json, T2_RP), T2ERROR_SUCCESS); -} - -#if 0 -TEST_F(ProfileTest, processProfile_ValidJson_TEMP_RP) { - //char json[] = "{\"profiles\":[]}"; - char json[] = "{ \"profiles\": [ { \"name\": \"TR_Temp\", \"hash\": \"HashTemp\", \"value\": { \"Name\": \"RDKB_Profile_3\", \"Description\": \"RDKB_Profile\", \"Version\": \"0.1\", \"Protocol\": \"RBUS_METHOD\", \"EncodingType\": \"JSON\", \"ActivationTimeout\": 3600, \"ReportingInterval\": 20, \"GenerateNow\": false, \"RootName\": \"FR2_US_TC3\", \"Parameter\": [ { \"type\": \"event\", \"eventName\": \"TEST_EVENT_MARKER_1\", \"component\": \"sysint\", \"use\": \"count\" }, { \"type\": \"event\", \"eventName\": \"TEST_EVENT_MARKER_2\", \"component\": \"sysint\", \"use\": \"accumulate\", \"reportTimestamp\":\"Unix-Epoch\" }, { \"type\": \"grep\", \"marker\": \"SYS_INFO_CrashPortalUpload_success\", \"search\": \"Success loading\", \"logFile\": \"core_log.txt\", \"use\": \"count\", \"reportEmpty\":true } ], \"ReportingAdjustments\": [ { \"ReportOnUpdate\": false, \"FirstReportingInterval\": 15, \"MaxUploadLatency\": 20000 } ], \"RBUS_METHOD\":{\"Method\":\"Device.X_RDK_Xmidt.SendData\",\"Parameters\":[{\"name\":\"msg_type\",\"value\":\"event\"},{\"name\":\"source\",\"value\":\"telemetry2\"},{\"name\":\"dest\",\"value\":\"event:/profile-report/LTE-report\"},{\"name\":\"content_type\",\"value\":\"application/json\"},{\"name\":\"qos\",\"value\":\"75\"}]}, \"JSONEncoding\": { \"ReportFormat\": \"NameValuePair\", \"ReportTimestamp\": \"None\" } } } ] }"; - EXPECT_EQ(datamodel_processProfile(json, T2_TEMP_RP), T2ERROR_SUCCESS); -} -#endif - -TEST_F(ProfileTest, processProfile_InvalidJson) { - char json[] = "fail"; - EXPECT_EQ(datamodel_processProfile(json, T2_RP), T2ERROR_FAILURE); -} - -TEST_F(ProfileTest, processProfile_MissingProfiles) { - char json[] = "missing_profiles"; - EXPECT_EQ(datamodel_processProfile(json, T2_RP), T2ERROR_FAILURE); -} - -#if 0 -//Hanginf because unable to get the rp lock -TEST_F(ProfileTest, processProfile_StopProcessingTrue) { - char json[] = "{\"profiles\":[]}"; - EXPECT_EQ(datamodel_processProfile(json, T2_RP), T2ERROR_SUCCESS); -} -#endif - -TEST_F(ProfileTest, getSavedJsonProfilesasString_EmptyVector) { - char* result = nullptr; - //gVector.configs.clear(); - EXPECT_CALL(*g_vectorMock, Vector_Size(_)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(0)); - EXPECT_CALL(*g_vectorMock, Vector_Create(_)) - .Times(::testing::AtMost(1)) // 1 for local test configlist, 1 for global profileList, 1 for configList in loadReportProfilesFromDisk - .WillRepeatedly(Return(T2ERROR_SUCCESS)); - EXPECT_CALL(*g_vectorMock, Vector_Destroy(_, _)) - .Times(::testing::AtMost(1)) // 1 for local test configlist, 1 for configList in loadReportProfilesFromDisk - .WillRepeatedly(Return(T2ERROR_SUCCESS)); - datamodel_getSavedJsonProfilesasString(&result); - // Result should be a valid JSON string - //ASSERT_NE(result, nullptr); - ASSERT_EQ(result, nullptr); - free(result); -} - -TEST_F(ProfileTest, getSavedJsonProfilesasString_WithConfigs) { - //Config conf; - //strcpy(conf.name, "test"); - //conf.configData = strdup("{\"Hash\":\"abc123\"}"); - //gVector.configs = { &conf }; - char* result = nullptr; - EXPECT_CALL(*g_vectorMock, Vector_Size(_)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(0)); - EXPECT_CALL(*g_vectorMock, Vector_Create(_)) - .Times(::testing::AtMost(1)) // 1 for local test configlist, 1 for global profileList, 1 for configList in loadReportProfilesFromDisk - .WillRepeatedly(Return(T2ERROR_SUCCESS)); - EXPECT_CALL(*g_vectorMock, Vector_Destroy(_, _)) - .Times(::testing::AtMost(1)) // 1 for local test configlist, 1 for configList in loadReportProfilesFromDisk - .WillRepeatedly(Return(T2ERROR_SUCCESS)); - datamodel_getSavedJsonProfilesasString(&result); - //ASSERT_NE(result, nullptr); - ASSERT_EQ(result, nullptr); - //free(conf.configData); - free(result); -} -/* -TEST_F(ProfileTest, getSavedMsgpackProfilesasString_FileNotFound) { - char* result = nullptr; - ASSERT_EQ(datamodel_getSavedMsgpackProfilesasString(&result), 0); - ASSERT_EQ(result, nullptr); -} - -*/ -TEST_F(ProfileTest, MsgpackProcessProfile_Success) { - char* blob = (char*)malloc(10); - int size = 10; - EXPECT_EQ(datamodel_MsgpackProcessProfile(blob, size), T2ERROR_SUCCESS); -} -#endif - -#if 0 -TEST_F(ProfileTest, NotifySchedulerstart) { - EXPECT_CALL(*g_vectorMock, Vector_Size(_)).Times(::testing::AtMost(1)).WillRepeatedly(Return(0)); - NotifySchedulerstart("profileY", true); -} -#endif - -#if 0 -TEST_F(ProfileTest, ReportProfiles_setProfileXConf) { - ProfileXConf profile; - EXPECT_CALL(*g_schedulerMock, registerProfileWithScheduler(_, _, _, _, _, _, _, _)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(T2ERROR_SUCCESS)); - - EXPECT_CALL(*g_rbusMock, rbus_checkStatus()) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(RBUS_ENABLED)); - - EXPECT_CALL(*g_rbusMock, rbus_registerLogHandler(_)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(RBUS_ERROR_SUCCESS)); - - EXPECT_CALL(*g_rbusMock, rbus_open(_, _)) - .Times(::testing::AtMost(2)) - .WillRepeatedly(Return(RBUS_ERROR_SUCCESS)); - - // Mock successful parameter retrieval - EXPECT_CALL(*g_rbusMock, rbus_get(_, _, _)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(RBUS_ERROR_SUCCESS)); - - EXPECT_CALL(*g_rbusMock, rbusValue_GetType(_)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(RBUS_STRING)); - - EXPECT_CALL(*g_rbusMock, rbusValue_ToString(_, _, _)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(strdup("test_value"))); - - EXPECT_CALL(*g_rbusMock, rbusValue_Release(_)) - .Times(::testing::AtMost(1)); - EXPECT_CALL(*g_vectorMock, Vector_Size(_)) - .Times(::testing::AtMost(2)) - .WillRepeatedly(Return(0)); // Return 1 to indicate only one profile (no duplicates) - - EXPECT_CALL(*g_rbusMock, rbus_checkStatus()) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(RBUS_ENABLED)); - - EXPECT_CALL(*g_rbusMock, rbus_open(_, _)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(RBUS_ERROR_SUCCESS)); - - EXPECT_CALL(*g_rbusMock, rbusObject_Init(_, _)) - .Times(::testing::AtMost(1)); - - EXPECT_CALL(*g_rbusMock, rbusValue_Init(_)) - .Times(::testing::AtMost(1)); - - EXPECT_CALL(*g_rbusMock, rbusValue_SetString(_, _)) - .Times(::testing::AtMost(1)); - - EXPECT_CALL(*g_rbusMock, rbusObject_SetValue(_, _, _)) - .Times(::testing::AtMost(1)); - - EXPECT_CALL(*g_rbusMock, rbusValue_Release(_)) - .Times(::testing::AtMost(1)); - - EXPECT_CALL(*g_rbusMock, rbusEvent_Publish(_,_)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(RBUS_ERROR_SUCCESS)); - - EXPECT_CALL(*g_rbusMock, rbusObject_Release(_)) - .Times(::testing::AtMost(1)); - EXPECT_EQ(ReportProfiles_setProfileXConf(&profile), T2ERROR_SUCCESS); -} -#endif - -#if 0 -TEST_F(ProfileTest, ClearMarkerComponentMapShouldRemoveEntries) { - EXPECT_CALL(*g_vectorMock, Vector_Destroy(_, _)).Times(::testing::AtMost(2)) - .WillRepeatedly(Return(T2ERROR_SUCCESS)); - EXPECT_EQ(clearT2MarkerComponentMap(), T2ERROR_SUCCESS); -} -#endif - -/* -TEST_F(ProfileTest, destroyT2MarkerComponentMap) { - EXPECT_CALL(*g_vectorMock, Vector_Destroy(_, _)).Times(::testing::AtMost(2)) - .WillRepeatedly(Return(T2ERROR_SUCCESS)); - EXPECT_EQ(clearT2MarkerComponentMap(), T2ERROR_SUCCESS); -} -*/ - -#if 0 -TEST_F(ProfileTest, updateEventMap) { - T2Marker t2Marker; - EXPECT_EQ(updateEventMap("marker1", &t2Marker), T2ERROR_SUCCESS); -} -#endif - -TEST_F(ProfileTest, getComponentsWithEventMarkers) { - Vector *profileList = nullptr; - //Vector_Create(&profileList); - - getComponentsWithEventMarkers(&profileList); -} - -TEST_F(ProfileTest, getMarkerProfileList) { - Vector *profileList = nullptr; - EXPECT_EQ(getMarkerProfileList("SYS_INFO_TEST_MARKER", &profileList), T2ERROR_FAILURE); -} - -/*TEST_F(ProfileTest, getComponentMarkerList) { - EXPECT_CALL(*g_vectorMock, Vector_Create(_)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(T2ERROR_SUCCESS)); -}*/ TEST_F(ProfileTest, createComponentDataElements) { EXPECT_CALL(*g_vectorMock, Vector_Size(_)).Times(::testing::AtMost(1)).WillRepeatedly(Return(0)); createComponentDataElements(); } -#if 0 -//CRASH on pthread_join -TEST_F(ProfileTest, T2ER_Uninit) { - EXPECT_CALL(*g_vectorMock, Vector_Destroy(_, _)).Times(::testing::AtMost(2)) - .WillRepeatedly(Return(T2ERROR_SUCCESS)); - T2ER_Uninit(); -} -#endif - -#if 0 -//CollectAndReport to be implemented through NotifyTimeout -TEST_F(ProfileTest, NotifyTimeout_reportInProgress) -{ - //profile to be returned by Vector_At mock call - Profile *profile = (Profile*)malloc(sizeof(Profile)); - profile->name = strdup("Profile1"); - profile->enable = true; - profile->reportInProgress = true; - - EXPECT_CALL(*g_vectorMock, Vector_Size(_)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(1)); - - EXPECT_CALL(*g_vectorMock, Vector_At(_, 0)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(profile)); - - NotifyTimeout("Profile1", true); -} - -TEST_F(ProfileTest, NotifyTimeout_ThreadFalse) -{ - //profile to be returned by Vector_At mock call - GrepSeekProfile *grepSeekProfile = (GrepSeekProfile*)malloc(sizeof(GrepSeekProfile)); - grepSeekProfile->execCounter= 0; - - Profile *profile = (Profile*)malloc(sizeof(Profile)); - profile->name = strdup("Profile1"); - profile->enable = true; - profile->reportInProgress = false; - profile->threadExists = false; - profile->grepSeekProfile = grepSeekProfile; - profile->encodingType = nullptr; - - EXPECT_CALL(*g_vectorMock, Vector_Size(_)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(1)); - - EXPECT_CALL(*g_vectorMock, Vector_At(_, 0)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(profile)); - - // NotifyTimeout may call CollectAndReport which calls getLapsedTime - EXPECT_CALL(*g_schedulerMock, getLapsedTime(_, _, _)) - .Times(::testing::AtMost(1)); // Not called because profile list is not initialized - - NotifyTimeout("Profile1", true); - sleep(50); -} - -TEST_F(ProfileTest, NotifyTimeout_ThreadTrue) -{ - //profile to be returned by Vector_At mock call - Profile *profile = (Profile*)malloc(sizeof(Profile)); - profile->name = strdup("Profile1"); - profile->enable = true; - profile->reportInProgress = false; - profile->threadExists = true; - - EXPECT_CALL(*g_vectorMock, Vector_Size(_)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(1)); - - EXPECT_CALL(*g_vectorMock, Vector_At(_, 0)) - .Times(::testing::AtMost(1)) - .WillRepeatedly(Return(profile)); - - // NotifyTimeout may call CollectAndReport which calls getLapsedTime - EXPECT_CALL(*g_schedulerMock, getLapsedTime(_, _, _)) - .Times(::testing::AtMost(1)); // Not called because profile list is not initialized - - NotifyTimeout("Profile1", true); -} - -#endif diff --git a/source/test/bulkdata/profilexconfTest.cpp b/source/test/bulkdata/profilexconfTest.cpp index 3e40ccae..08da294d 100644 --- a/source/test/bulkdata/profilexconfTest.cpp +++ b/source/test/bulkdata/profilexconfTest.cpp @@ -572,10 +572,11 @@ TEST_F(profileXconfTestFixture, ProfileXConf_notifyTimeout) //Vector_Create(&outparamlist); return outparamlist; }); + EXPECT_CALL(*g_profileXConfMock, encodeParamResultInJSON(_, _)) .Times(1) .WillOnce(Return(T2ERROR_SUCCESS)); - + EXPECT_CALL(*g_profileXConfMock, processTopPattern(_,_,_,_)) .Times(1) .WillOnce(Return(0)); @@ -585,6 +586,7 @@ TEST_F(profileXconfTestFixture, ProfileXConf_notifyTimeout) .WillOnce([](GrepSeekProfile **GSP, Vector *markerList, Vector **grepResultList, bool isClearSeekMap, bool check_rotated, char *customLogPath) { return T2ERROR_SUCCESS; }); + EXPECT_CALL(*g_profileXConfMock, encodeGrepResultInJSON(_, _)) .Times(1) .WillOnce(Return(T2ERROR_SUCCESS)); @@ -606,8 +608,8 @@ TEST_F(profileXconfTestFixture, ProfileXConf_notifyTimeout) .Times(1); ProfileXConf_notifyTimeout(false, true); std::this_thread::sleep_for(std::chrono::milliseconds(20000)); -} -*/ +}*/ + //Test the deletion of xconf profile TEST_F(profileXconfTestFixture, ProfileXConf_deleteProfile) { diff --git a/source/test/ccspinterface/ccspinterfaceTest.cpp b/source/test/ccspinterface/ccspinterfaceTest.cpp index f6350a7c..4bbca42c 100755 --- a/source/test/ccspinterface/ccspinterfaceTest.cpp +++ b/source/test/ccspinterface/ccspinterfaceTest.cpp @@ -461,7 +461,7 @@ TEST_F(CcspInterfaceTest, regDEforProfileDataModelTest) } //Test the t2PropertyDataSetHandler function to handle set requests for event markers -TEST_F(CcspInterfaceTest, t2PropertyDataSetHandler_Success) { +/*TEST_F(CcspInterfaceTest, t2PropertyDataSetHandler_Success) { rbusHandle_t handle; rbusSetHandlerOptions_t* options = NULL; rbusValue_t value; @@ -503,12 +503,12 @@ TEST_F(CcspInterfaceTest, t2PropertyDataSetHandler_Success) { .Times(::testing::AtMost(1)) .WillRepeatedly(Return(strdup("test_value"))); - EXPECT_EQ(t2PropertyDataSetHandler(handle, prop1, options), RBUS_ERROR_SUCCESS); + EXPECT_EQ(t2PropertyDataSetHandler(handle, prop1, options), RBUS_ERROR_INVALID_INPUT); EXPECT_CALL(*g_rbusMock, rbusValue_Release(_)) .Times(::testing::AtMost(1)); EXPECT_CALL(*g_rbusMock, rbusProperty_Release(_)) .Times(::testing::AtMost(1)); -} +}*/ //Test the t2PropertyDataGetHandler function to handle get requests for Reportpeofiles set TEST_F(CcspInterfaceTest, t2PropertyDataGetHandler_Success_7) diff --git a/source/test/commonlib/TelemetryBusMsgSender.cpp b/source/test/commonlib/TelemetryBusMsgSender.cpp index 766a93f3..36a06923 100644 --- a/source/test/commonlib/TelemetryBusMsgSender.cpp +++ b/source/test/commonlib/TelemetryBusMsgSender.cpp @@ -87,6 +87,7 @@ TEST_F(TelemetryBusmessageSenderTest, SendStringEvent_NullComponent) { } // Negative test: t2_event_s with NULL marker +/* TEST_F(TelemetryBusmessageSenderTest, SendStringEvent_NullMarker) { t2_init((char*)"test_component"); EXPECT_CALL(*g_systemMock, access(_,_)) @@ -108,7 +109,7 @@ TEST_F(TelemetryBusmessageSenderTest, SendStringEvent_NullValue) { EXPECT_EQ(err, T2ERROR_FAILURE); } - +*/ // Negative test: t2_event_s with empty string value (should not send, returns success) TEST_F(TelemetryBusmessageSenderTest, SendStringEvent_EmptyValue) { t2_init((char*)"test_component"); @@ -128,6 +129,7 @@ TEST_F(TelemetryBusmessageSenderTest, SendStringEvent_ZeroValue) { } // Negative test: t2_event_f with NULL marker +/* TEST_F(TelemetryBusmessageSenderTest, SendDoubleEvent_NullMarker) { t2_init((char*)"test_component"); EXPECT_CALL(*g_systemMock, access(_,_)) @@ -137,14 +139,14 @@ TEST_F(TelemetryBusmessageSenderTest, SendDoubleEvent_NullMarker) { T2ERROR err = t2_event_f(NULL, 3.14); EXPECT_EQ(err, T2ERROR_FAILURE); } - +*/ // Negative test: t2_event_f with NULL component TEST_F(TelemetryBusmessageSenderTest, SendDoubleEvent_NullComponent) { t2_uninit(); EXPECT_CALL(*g_systemMock, access(_,_)) .Times(2) .WillOnce(Return(-1)) - .WillOnce(Return(-1));\ + .WillOnce(Return(-1)); EXPECT_CALL(*g_fileIOMock, getpid()) .Times(1) .WillOnce(Return(1234)); @@ -153,6 +155,7 @@ TEST_F(TelemetryBusmessageSenderTest, SendDoubleEvent_NullComponent) { } // Negative test: t2_event_d with NULL marker +/* TEST_F(TelemetryBusmessageSenderTest, SendIntEvent_NullMarker) { t2_init((char*)"test_component"); EXPECT_CALL(*g_systemMock, access(_,_)) @@ -162,7 +165,7 @@ TEST_F(TelemetryBusmessageSenderTest, SendIntEvent_NullMarker) { T2ERROR err = t2_event_d(NULL, 123); EXPECT_EQ(err, T2ERROR_FAILURE); } - +*/ // Negative test: t2_event_d with value 0 (should not send, returns success) TEST_F(TelemetryBusmessageSenderTest, SendIntEvent_Zero) { t2_init((char*)"test_component");