Skip to content

Conversation

@rosemarybennyy
Copy link
Contributor

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

@rosemarybennyy rosemarybennyy requested a review from a team as a code owner December 5, 2025 04:40
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>
Copy link

Copilot AI left a 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.cpp with 3 test cases covering XConf configuration processing, including missing required fields, default schedule handling, and slash-pattern schedule parsing
  • Extended t2parserTest.cpp with 13 new test cases for trigger condition verification, encoding/protocol settings, adding comprehensive coverage for validation logic
  • Updated build configuration in Makefile.am to 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.

Comment on lines 931 to 976
/* 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
Copy link

Copilot AI Dec 5, 2025

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.

Suggested change
/* 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. */

Copilot uses AI. Check for mistakes.
Comment on lines +903 to +910
// 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);
}
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 993 to 997
free(p.jsonEncoding);
cJSON_Delete(jEncodingType);
cJSON_Delete(jJSONReportFormat);
cJSON_Delete(jJSONReportTimestamp);
}
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 1027 to 1031
free(p.t2HTTPDest);
free(p.name);
cJSON_Delete(jProtocol);
cJSON_Delete(jHTTP);
}
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 1058 to 1062
free(p.t2RBUSDest);
free(p.name);
cJSON_Delete(jProtocol);
cJSON_Delete(jRBUS);
}
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +48 to +49
// minimal cleanup (full deep-free is not attempted here)
// tests rely on process teardown to reclaim memory in CI runs
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines +88 to +89
// Ensure the profile name got set
EXPECT_STREQ("SlashSched", profile->name ? profile->name : "");
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
Comment on lines 155 to 156
char h1[] = "hash1";
EXPECT_EQ(T2ERROR_FAILURE, processConfiguration(&data, "hash1", h1, &profile));
Copy link

Copilot AI Dec 5, 2025

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.

Copilot uses AI. Check for mistakes.
// 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);
Copy link

Copilot AI Dec 5, 2025

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.

Suggested change
//void time_param_Reporting_Adjustments_valid_set(Profile *profile, cJSON *jprofileReportingInterval, cJSON *jprofileActivationTimeout, cJSON *jprofileTimeReference, cJSON *jprofileReportOnUpdate, cJSON *jprofilefirstReportingInterval, cJSON *jprofilemaxUploadLatency, cJSON* jprofileReportingAdjustments);

Copilot uses AI. Check for mistakes.
@shibu-kv shibu-kv merged commit a272470 into develop Dec 18, 2025
15 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Dec 18, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants