-
Notifications
You must be signed in to change notification settings - Fork 20
RDK-60519: Adding L1 unit test cases for scheduler #238
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
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 PR adds L1 (Level 1) unit test cases for the scheduler component to increase code coverage. The changes primarily add new test cases covering edge cases, error handling paths, and various function behaviors that were previously untested.
Changes:
- Added 20+ new test cases covering getLapsedTime, registerProfileWithScheduler, unregisterProfileFromScheduler, SendInterruptToTimeoutThread, uninitScheduler, TimeoutThread, and freeSchedulerProfile functions
- Modified an existing test (TIMEOUTTHREAD/TEST1) to use non-zero timeRefinSec value
- Added a callback function wrapper in scheduler.c for indirect function pointer testing under GTEST_ENABLE flag
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 16 comments.
| File | Description |
|---|---|
| source/test/scheduler/schedulerTest.cpp | Adds comprehensive L1 unit test cases for scheduler functions, including edge cases, error conditions, and branch coverage tests |
| source/scheduler/scheduler.c | Adds test-only callback function wrapper for getSchdInSec to enable indirect function pointer testing |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b7ee61c to
e91d02b
Compare
e91d02b to
14d2460
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
Copilot reviewed 2 out of 2 changed files in this pull request and generated 12 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Reason for change: Adding L1 unit test cases for scheduler Test Procedure: Tested and verified Risks: Medium Priority: P1 Signed-off-by: Rose Mary Benny <RoseMary_Benny@comcast.com>
14d2460 to
fcf7e4c
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
Copilot reviewed 2 out of 2 changed files in this pull request and generated 8 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| typedef unsigned int (*getSchdInSec_fn)(char*); | ||
| getSchdInSec_fn getSchdInSec_fnCallback(void); | ||
| } | ||
| TEST(getSchdInSec, IndirectCall) | ||
| { | ||
| getSchdInSec_fn fn = getSchdInSec_fnCallback(); |
Copilot
AI
Jan 20, 2026
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.
Duplicate typedef definition. The typedef for getSchdInSec_fn is defined identically in both the test file (line 439) and the source file (line 683). This duplication violates the DRY principle and could lead to maintenance issues if the signature needs to change. Consider defining this typedef in a shared header file that both files can include when GTEST_ENABLE is defined.
| typedef unsigned int (*getSchdInSec_fn)(char*); | |
| getSchdInSec_fn getSchdInSec_fnCallback(void); | |
| } | |
| TEST(getSchdInSec, IndirectCall) | |
| { | |
| getSchdInSec_fn fn = getSchdInSec_fnCallback(); | |
| unsigned int (*getSchdInSec_fnCallback(void))(char*); | |
| } | |
| TEST(getSchdInSec, IndirectCall) | |
| { | |
| auto fn = getSchdInSec_fnCallback(); |
| { | ||
| initScheduler((TimeoutNotificationCB)ReportProfiles_ToutCb, (ActivationTimeoutCB)ReportProfiles_ActivationToutCb, (NotifySchedulerstartCB)NotifySchedulerstartCb); | ||
|
|
||
|
|
Copilot
AI
Jan 20, 2026
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.
Excessive blank lines. There are two consecutive blank lines (306-307) which is inconsistent with the rest of the codebase where single blank lines are used for separation. Remove one of these blank lines for consistency.
| time1.tv_nsec = 200000000; // 2.1 seconds in nanoseconds | ||
| time2.tv_sec = 10; | ||
| time2.tv_nsec = 100000000; // 0.001 seconds in nanoseconds |
Copilot
AI
Jan 20, 2026
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.
The comment at line 170 is inaccurate. The value 100000000 nanoseconds equals 0.1 seconds, not 0.001 seconds.
| time1.tv_nsec = 200000000; // 2.1 seconds in nanoseconds | |
| time2.tv_sec = 10; | |
| time2.tv_nsec = 100000000; // 0.001 seconds in nanoseconds | |
| time1.tv_nsec = 200000000; // 0.2 seconds in nanoseconds | |
| time2.tv_sec = 10; | |
| time2.tv_nsec = 100000000; // 0.1 seconds in nanoseconds |
| pthread_mutex_init(&sch->tMutex, NULL); | ||
| pthread_cond_init(&sch->tCond, NULL); | ||
| pthread_t threadId; | ||
| ASSERT_EQ(0, pthread_create(&threadId, NULL, DummySchedulerThread, NULL)); |
Copilot
AI
Jan 20, 2026
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.
Inconsistent whitespace in ASSERT_EQ call. The line has trailing whitespace after the semicolon that should be removed for consistency with the rest of the codebase.
| ASSERT_EQ(0, pthread_create(&threadId, NULL, DummySchedulerThread, NULL)); | |
| ASSERT_EQ(0, pthread_create(&threadId, NULL, DummySchedulerThread, NULL)); |
| pthread_mutex_init(&sch->tMutex, NULL); | ||
| pthread_cond_init(&sch->tCond, NULL); | ||
| pthread_t threadId; | ||
| ASSERT_EQ(0, pthread_create(&threadId, NULL, DummySchedulerThread, NULL)); |
Copilot
AI
Jan 20, 2026
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.
Potential resource leak. The test creates a thread with pthread_create but never joins or properly cleans it up. The thread is created but not associated with the SchedulerProfile structure (sch->tId is not set), and the DummySchedulerThread returns immediately. While freeSchedulerProfile calls pthread_detach, it detaches sch->tId which was never initialized, not the threadId variable that was actually created. This could lead to undefined behavior or resource leaks. Either properly set sch->tId = threadId before calling freeSchedulerProfile, or join/detach the threadId before the test ends.
| ASSERT_EQ(0, pthread_create(&threadId, NULL, DummySchedulerThread, NULL)); | |
| ASSERT_EQ(0, pthread_create(&threadId, NULL, DummySchedulerThread, NULL)); | |
| sch->tId = threadId; |
| char timeRef[] = "2022-12-20T11:05:56Z"; | ||
| // Call via function pointer | ||
| unsigned int result = fn(timeRef); | ||
| EXPECT_GE(result, 0u); |
Copilot
AI
Jan 20, 2026
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.
Redundant assertion. The assertion EXPECT_GE(result, 0u) is always true for an unsigned int, as unsigned integers cannot be negative by definition. This assertion provides no value and should be removed.
| EXPECT_GE(result, 0u); |
| // Make time1->tv_nsec - time2->tv_nsec > 1,000,000,000 | ||
| time1.tv_sec = 10; | ||
| time1.tv_nsec = 200000000; // 2.1 seconds in nanoseconds | ||
| time2.tv_sec = 10; | ||
| time2.tv_nsec = 100000000; // 0.001 seconds in nanoseconds |
Copilot
AI
Jan 20, 2026
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.
The comment at line 168 is inaccurate. The value 200000000 nanoseconds equals 0.2 seconds, not 2.1 seconds. For reference, 1 second = 1,000,000,000 nanoseconds.
| // Make time1->tv_nsec - time2->tv_nsec > 1,000,000,000 | |
| time1.tv_sec = 10; | |
| time1.tv_nsec = 200000000; // 2.1 seconds in nanoseconds | |
| time2.tv_sec = 10; | |
| time2.tv_nsec = 100000000; // 0.001 seconds in nanoseconds | |
| // Make time1->tv_nsec greater than time2->tv_nsec to exercise the carry/borrow logic | |
| time1.tv_sec = 10; | |
| time1.tv_nsec = 200000000; // 0.2 seconds in nanoseconds | |
| time2.tv_sec = 10; | |
| time2.tv_nsec = 100000000; // 0.1 seconds in nanoseconds |
| SchedulerProfile *tProfile = (SchedulerProfile *)malloc(sizeof(SchedulerProfile)); | ||
| tProfile->name = strdup("RDKB_Profile"); | ||
| tProfile->timeRefinSec = 0; | ||
| tProfile->timeRef = NULL; |
Copilot
AI
Jan 20, 2026
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.
Trailing whitespace after the NULL assignment. This line has unnecessary trailing whitespace that should be removed for code cleanliness.
| tProfile->timeRef = NULL; | |
| tProfile->timeRef = NULL; |
Reason for change: Adding L1 unit test cases for scheduler
Test Procedure: Tested and verified
Risks: Medium
Priority: P1