-
Notifications
You must be signed in to change notification settings - Fork 18
RDK-60072: Adding L1 unit test cases to improve code coverage #219
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
Conversation
Reason for change: Adding L1 unit test cases to improve code coverage Test Procedure: Tested and verified Risks: Medium Priority: P1 Signed-off-by: Rose Mary Benny <RoseMary_Benny@comcast.com>
f751e71 to
28c7881
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This pull request adds L1 (Level 1) unit test cases to improve code coverage for the t2parser module. The PR introduces a new test file for testing XConf configuration parsing and extends existing tests with additional coverage for trigger condition verification, encoding settings, and protocol configuration. These tests aim to exercise error paths and edge cases to improve overall test coverage.
Key Changes
- New test file
t2parserxconfTest.cppwith 3 test cases covering XConf configuration processing, including missing required fields, default schedule handling, and slash-pattern schedule parsing - Extended
t2parserTest.cppwith 13 new test cases for trigger condition verification, encoding/protocol settings, adding comprehensive coverage for validation logic - Updated build configuration in
Makefile.amto include the new test file
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 9 comments.
| File | Description |
|---|---|
| source/test/t2parser/t2parserxconfTest.cpp | New test file with 3 test cases for processConfigurationXConf function covering error cases (missing fields) and valid configurations (default schedule and slash schedule patterns) |
| source/test/t2parser/t2parserTest.cpp | Added extern C declarations for internal functions and 13 new test cases for verifyTriggerCondition (7 tests), addTriggerCondition (1 test), encodingSet (1 test), protocolSet (2 tests), plus 2 commented-out tests for time_param_Reporting_Adjustments_valid_set; fixed minor formatting issues by removing blank lines and replacing an incorrect parameter |
| source/test/t2parser/Makefile.am | Updated SOURCES variable to include new test file t2parserxconfTest.cpp in the build |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| /* time_param_Reporting_Adjustments_valid_set: set values when generateNow is false */ | ||
| TEST(T2ParserTimeParam, ReportingAdjustmentsApplied) | ||
| { | ||
| Profile p; | ||
| memset(&p, 0, sizeof(p)); | ||
| p.generateNow = false; | ||
| p.activationTimeoutPeriod = 1000; | ||
| p.reportingInterval = 60; | ||
|
|
||
| cJSON* jReportingInterval = cJSON_CreateNumber(120); | ||
| cJSON* jActivationTimeout = cJSON_CreateNumber(400); | ||
| cJSON* jTimeReference = cJSON_CreateString("2025-01-01T00:00:00Z"); | ||
|
|
||
| cJSON* jReportingAdjustments = cJSON_CreateObject(); | ||
| cJSON* jReportOnUpdate = cJSON_CreateTrue(); | ||
| cJSON_AddItemToObject(jReportingAdjustments, "ReportOnUpdate", jReportOnUpdate); | ||
| cJSON* jFirstReportingInterval = cJSON_CreateNumber(10); | ||
| cJSON_AddItemToObject(jReportingAdjustments, "FirstReportingInterval", jFirstReportingInterval); | ||
| cJSON* jMaxUploadLatency = cJSON_CreateNumber(2000); | ||
| cJSON_AddItemToObject(jReportingAdjustments, "MaxUploadLatency", jMaxUploadLatency); | ||
|
|
||
| // call the function (note: signature expects separate args - pass firstReportingInterval/maxUploadLatency separately) | ||
| time_param_Reporting_Adjustments_valid_set(&p, jReportingInterval, jActivationTimeout, jTimeReference, jReportOnUpdate, jFirstReportingInterval, jMaxUploadLatency); | ||
|
|
||
| // reportingInterval should be set from jReportingInterval | ||
| EXPECT_EQ(120, p.reportingInterval); | ||
| // activationTimeoutPeriod should be set from jActivationTimeout by surrounding callers; here we check timeRef was set | ||
| if (p.timeRef) { | ||
| EXPECT_STREQ("2025-01-01T00:00:00Z", p.timeRef); | ||
| free(p.timeRef); | ||
| p.timeRef = NULL; | ||
| } | ||
| // ReportOnUpdate should be true | ||
| EXPECT_EQ(true, p.reportOnUpdate); | ||
| // First reporting interval set | ||
| EXPECT_EQ(10, p.firstReportingInterval); | ||
| // MaxUploadLatency set | ||
| EXPECT_EQ(2000, p.maxUploadLatency); | ||
|
|
||
| // cleanup | ||
| cJSON_Delete(jReportingAdjustments); | ||
| cJSON_Delete(jReportingInterval); | ||
| cJSON_Delete(jActivationTimeout); | ||
| cJSON_Delete(jTimeReference); | ||
| } | ||
| #endif |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out code block (lines 911-976) should either be removed or enabled with a clear explanation. Leaving large blocks of commented code reduces code maintainability. If this test is not ready, consider removing it entirely or documenting why it's disabled.
| /* time_param_Reporting_Adjustments_valid_set: set values when generateNow is false */ | |
| TEST(T2ParserTimeParam, ReportingAdjustmentsApplied) | |
| { | |
| Profile p; | |
| memset(&p, 0, sizeof(p)); | |
| p.generateNow = false; | |
| p.activationTimeoutPeriod = 1000; | |
| p.reportingInterval = 60; | |
| cJSON* jReportingInterval = cJSON_CreateNumber(120); | |
| cJSON* jActivationTimeout = cJSON_CreateNumber(400); | |
| cJSON* jTimeReference = cJSON_CreateString("2025-01-01T00:00:00Z"); | |
| cJSON* jReportingAdjustments = cJSON_CreateObject(); | |
| cJSON* jReportOnUpdate = cJSON_CreateTrue(); | |
| cJSON_AddItemToObject(jReportingAdjustments, "ReportOnUpdate", jReportOnUpdate); | |
| cJSON* jFirstReportingInterval = cJSON_CreateNumber(10); | |
| cJSON_AddItemToObject(jReportingAdjustments, "FirstReportingInterval", jFirstReportingInterval); | |
| cJSON* jMaxUploadLatency = cJSON_CreateNumber(2000); | |
| cJSON_AddItemToObject(jReportingAdjustments, "MaxUploadLatency", jMaxUploadLatency); | |
| // call the function (note: signature expects separate args - pass firstReportingInterval/maxUploadLatency separately) | |
| time_param_Reporting_Adjustments_valid_set(&p, jReportingInterval, jActivationTimeout, jTimeReference, jReportOnUpdate, jFirstReportingInterval, jMaxUploadLatency); | |
| // reportingInterval should be set from jReportingInterval | |
| EXPECT_EQ(120, p.reportingInterval); | |
| // activationTimeoutPeriod should be set from jActivationTimeout by surrounding callers; here we check timeRef was set | |
| if (p.timeRef) { | |
| EXPECT_STREQ("2025-01-01T00:00:00Z", p.timeRef); | |
| free(p.timeRef); | |
| p.timeRef = NULL; | |
| } | |
| // ReportOnUpdate should be true | |
| EXPECT_EQ(true, p.reportOnUpdate); | |
| // First reporting interval set | |
| EXPECT_EQ(10, p.firstReportingInterval); | |
| // MaxUploadLatency set | |
| EXPECT_EQ(2000, p.maxUploadLatency); | |
| // cleanup | |
| cJSON_Delete(jReportingAdjustments); | |
| cJSON_Delete(jReportingInterval); | |
| cJSON_Delete(jActivationTimeout); | |
| cJSON_Delete(jTimeReference); | |
| } | |
| #endif | |
| /* The following test for time_param_Reporting_Adjustments_valid_set was removed due to lack of documentation and being commented out. | |
| If this test is needed in the future, please restore it with a clear explanation for its status and readiness. */ |
| // clean up: free internal structures created by addTriggerCondition | ||
| // We don't have a public destructor here; best-effort free for the test's allocations: | ||
| // iterate vector if available (Vector API may provide size/get functions in the project), | ||
| // but to stay robust, simply free profile memory fields that addTriggerCondition could set. | ||
| // For safety, reset pointer to avoid double-free during test teardown. | ||
| // (The CI process reclaims process memory after tests.) | ||
| cJSON_Delete(arr); | ||
| } |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: The triggerConditionList allocated by addTriggerCondition is not properly cleaned up. While the comment mentions "best-effort free" and "CI process reclaims", tests should properly clean up their allocations to avoid masking real memory leaks and to follow good testing practices.
| free(p.jsonEncoding); | ||
| cJSON_Delete(jEncodingType); | ||
| cJSON_Delete(jJSONReportFormat); | ||
| cJSON_Delete(jJSONReportTimestamp); | ||
| } |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: The Profile structure members (jsonEncoding, name) are allocated but never freed. Add proper cleanup at the end of the test to prevent memory leaks.
| free(p.t2HTTPDest); | ||
| free(p.name); | ||
| cJSON_Delete(jProtocol); | ||
| cJSON_Delete(jHTTP); | ||
| } |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: The Profile structure members (t2HTTPDest, name) are allocated but never freed. Add proper cleanup at the end of the test to prevent memory leaks.
| free(p.t2RBUSDest); | ||
| free(p.name); | ||
| cJSON_Delete(jProtocol); | ||
| cJSON_Delete(jRBUS); | ||
| } |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: The Profile structure members (t2RBUSDest, name) are allocated but never freed. Add proper cleanup at the end of the test to prevent memory leaks.
| // minimal cleanup (full deep-free is not attempted here) | ||
| // tests rely on process teardown to reclaim memory in CI runs |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: The profile structure and its internal allocations (t2HTTPDest->URL, name, etc.) allocated during processConfigurationXConf are not freed. Consider adding proper cleanup using a profile destructor/free function or at minimum free the profile and its allocated members before test completion.
| // Ensure the profile name got set | ||
| EXPECT_STREQ("SlashSched", profile->name ? profile->name : ""); |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Memory leak: The profile structure and its internal allocations (t2HTTPDest->URL, name, etc.) allocated during processConfigurationXConf are not freed. Consider adding proper cleanup using a profile destructor/free function or at minimum free the profile and its allocated members before test completion.
| char h1[] = "hash1"; | ||
| EXPECT_EQ(T2ERROR_FAILURE, processConfiguration(&data, "hash1", h1, &profile)); |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use spaces instead of tab character for indentation to maintain consistency with the codebase style.
| // tell C++ about the C function defined in t2parser.c | ||
| T2ERROR verifyTriggerCondition(cJSON *jprofileTriggerCondition); | ||
| T2ERROR addTriggerCondition(Profile *profile, cJSON *jprofileTriggerCondition); | ||
| //void time_param_Reporting_Adjustments_valid_set(Profile *profile, cJSON *jprofileReportingInterval, cJSON *jprofileActivationTimeout, cJSON *jprofileTimeReference, cJSON *jprofileReportOnUpdate, cJSON *jprofilefirstReportingInterval, cJSON *jprofilemaxUploadLatency, cJSON* jprofileReportingAdjustments); |
Copilot
AI
Dec 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commented-out function declaration. If time_param_Reporting_Adjustments_valid_set is not being tested (see #if 0 block at lines 911-976), this declaration should be removed. Otherwise, uncomment and use it in the tests.
| //void time_param_Reporting_Adjustments_valid_set(Profile *profile, cJSON *jprofileReportingInterval, cJSON *jprofileActivationTimeout, cJSON *jprofileTimeReference, cJSON *jprofileReportOnUpdate, cJSON *jprofilefirstReportingInterval, cJSON *jprofilemaxUploadLatency, cJSON* jprofileReportingAdjustments); |
Reason for change: Adding L1 unit test cases to improve code coverage
Test Procedure: Tested and verified
Risks: Medium
Priority: P1
Signed-off-by: Rose Mary Benny RoseMary_Benny@comcast.com