Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
2c75d6a
Update code-coverage.yml
nhanasi May 29, 2026
8d47426
Merge branch 'develop' into feature/coveragereport
nhanasi Jun 9, 2026
ea5009e
Update unit_test.sh
nhanasi Jun 9, 2026
bf79450
Update unit_test.sh
nhanasi Jun 9, 2026
8a60830
Add L1/L2 Coverage report
Jun 9, 2026
def02f3
Update code-coverage.yml
Abhinavpv28 Jun 10, 2026
2247756
Update code-coverage.yml
Abhinavpv28 Jun 10, 2026
8f8d561
Update code-coverage.yml
Abhinavpv28 Jun 10, 2026
79d00a7
Update code-coverage.yml
Abhinavpv28 Jun 10, 2026
fed8497
L2 Coverage report
Jun 10, 2026
cd58471
Update code-coverage.yml
Abhinavpv28 Jun 11, 2026
718ba37
Update code-coverage.yml
Abhinavpv28 Jun 11, 2026
4a8c05e
Update code-coverage.yml
Abhinavpv28 Jun 12, 2026
09cb591
L1
Jun 12, 2026
5153397
Update code-coverage.yml
nhanasi Jun 15, 2026
654c851
Potential fix for pull request finding
nhanasi Jun 15, 2026
87c0544
Update unit_test.sh
nhanasi Jun 15, 2026
cc17915
Integrate the combined unittest
Jun 15, 2026
58ba3c8
Update backup_engine_gtest.cpp
Abhinavpv28 Jun 16, 2026
3827dfa
Update usb_log_main_gtest.cpp
Abhinavpv28 Jun 16, 2026
416e155
L1
Jun 16, 2026
71fb412
Update backup_engine_gtest.cpp
Abhinavpv28 Jun 16, 2026
710d98f
Update backup_engine_gtest.cpp
Abhinavpv28 Jun 16, 2026
08e7efc
Update backup_logs_gtest.cpp
Abhinavpv28 Jun 16, 2026
84414c0
Update config_manager_gtest.cpp
Abhinavpv28 Jun 16, 2026
5c4ddee
Update special_files_gtest.cpp
Abhinavpv28 Jun 16, 2026
d8e4e94
Update sys_integration_gtest.cpp
Abhinavpv28 Jun 16, 2026
56679af
Update special_files_gtest.cpp
Abhinavpv28 Jun 16, 2026
7e5cb36
Update special_files_gtest.cpp
Abhinavpv28 Jun 16, 2026
e0e2853
Update event_manager_gtest.cpp
Abhinavpv28 Jun 16, 2026
d51e9e0
Update validation_gtest.cpp
Abhinavpv28 Jun 16, 2026
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
49 changes: 32 additions & 17 deletions .github/workflows/code-coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,47 @@ name: Code Coverage

on:
pull_request:
branches: [ main develop ]
branches: [ main, develop ]

env:
AUTOMATICS_UNAME: ${{ secrets.AUTOMATICS_UNAME }}
AUTOMATICS_PASSCODE: ${{ secrets.AUTOMATICS_PASSCODE }}

jobs:
execute-unit-code-coverage-report-on-release:
name: Test coverage report for release
runs-on: ubuntu-latest
container:
image: ghcr.io/rdkcentral/docker-rdk-ci:latest

steps:
- name: Checkout code
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Run unit tests with coverage flags enabled
run: |
sh unit_test.sh --enable-cov
- name: Caculate the code coverage summary
- name: Log in to GitHub Container Registry
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull test container image
run: docker pull ghcr.io/rdkcentral/docker-device-mgt-service-test/native-platform:latest

- name: Start test container
run: |
cd ./unittest
lcov --list coverage.info | grep "Lines\|Total" > /tmp/coverage_summary.txt
cd -

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 and Calculate the code coverage summary
run: docker exec -i native-platform /bin/bash -c "cd /mnt/L1_CONTAINER_SHARED_VOLUME/ && sh unit_test.sh --enable-cov && lcov --list unittest/combined.info | grep 'Lines\|Total' > /tmp/coverage_summary.txt"

- name: Copy coverage summary to runner
run: docker cp native-platform:/tmp/coverage_summary.txt /tmp/

- 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/coverage_summary.txt', 'utf8');
const lcov_result = fs.readFileSync('/tmp/coverage_summary.txt', 'utf8');

github.issues.createComment({
issue_number: context.issue.number,
Expand All @@ -42,11 +55,13 @@ jobs:
lcov_result +
'```'
});

- name: Generate the html report
run: |
cd ./unittest
genhtml coverage.info --output-directory /tmp/coverage_report
cd -
run: docker exec -i native-platform /bin/bash -c " cd /mnt/L1_CONTAINER_SHARED_VOLUME/ && genhtml unittest/combined.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:
Expand Down
20 changes: 12 additions & 8 deletions backup_logs/unittest/backup_engine_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
#include <dirent.h>
#include <sys/stat.h>
#include <time.h>
#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/"
#define GTEST_DEFAULT_RESULT_FILENAME "backup_engine_gtest_report.json"
#define GTEST_REPORT_FILEPATH_SIZE 256

extern "C" {
#include "backup_engine.h"
Expand Down Expand Up @@ -312,12 +315,6 @@ extern "C" {
return mock_control.time_return;
}

struct tm* __wrap_localtime(const time_t *timep) {
(void)timep;
mock_control.localtime_called = true;
return mock_control.localtime_return;
}

size_t __wrap_strftime(char *s, size_t max, const char *format, const struct tm *tm) {
mock_control.strftime_called = true;
if (format) {
Expand Down Expand Up @@ -526,7 +523,6 @@ TEST_F(BackupEngineTest, HDDEnabledStrategy_SubsequentBackup) {
EXPECT_EQ(result, BACKUP_SUCCESS);
EXPECT_TRUE(mock_control.createDir_called); // Creates timestamped directory
EXPECT_TRUE(mock_control.time_called);
EXPECT_TRUE(mock_control.localtime_called);
EXPECT_TRUE(mock_control.strftime_called);
}

Expand Down Expand Up @@ -742,7 +738,6 @@ TEST_F(BackupEngineTest, TimeOperations_FailureHandling) {
int result = backup_execute_hdd_enabled_strategy(&test_config);

EXPECT_TRUE(mock_control.time_called);
EXPECT_TRUE(mock_control.localtime_called);
// Function should still attempt to continue
}

Expand All @@ -766,6 +761,15 @@ TEST_F(BackupEngineTest, FileOperations_EdgeCases) {
// ================================================================================================

int main(int argc, char **argv) {
char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE];
char buffer[GTEST_REPORT_FILEPATH_SIZE];

memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE );
memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE );

snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME);
::testing::GTEST_FLAG(output) = testresults_fullfilepath;
::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}
13 changes: 13 additions & 0 deletions backup_logs/unittest/backup_logs_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@
#include <cstdlib>
#include <cstdint>

#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/"
#define GTEST_DEFAULT_RESULT_FILENAME "backup_logs_gtest_report.json"
#define GTEST_REPORT_FILEPATH_SIZE 256

extern "C" {
#include "backup_logs.h"
#include "backup_types.h"
Expand Down Expand Up @@ -685,6 +689,15 @@ TEST_F(BackupLogsTest, BufferProtectionTests) {
// ================================================================================================

int main(int argc, char **argv) {
char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE];
char buffer[GTEST_REPORT_FILEPATH_SIZE];

memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE );
memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE );

snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME);
::testing::GTEST_FLAG(output) = testresults_fullfilepath;
::testing::InitGoogleTest(&argc, argv);

return RUN_ALL_TESTS();
}
16 changes: 15 additions & 1 deletion backup_logs/unittest/config_manager_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
#include <cstdlib>
#include <climits>

#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/"
#define GTEST_DEFAULT_RESULT_FILENAME "config_manager_gtest_report.json"
#define GTEST_REPORT_FILEPATH_SIZE 256

extern "C" {
#include "config_manager.h"
#include "backup_types.h"
Expand Down Expand Up @@ -319,7 +323,17 @@ TEST_F(ConfigManagerTest, ConfigLoad_PropertyQueriedCorrectly) {
// Main
// ================================================================================================

int main(int argc, char **argv) {
GTEST_API_ int main(int argc, char *argv[]){
char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE];
char buffer[GTEST_REPORT_FILEPATH_SIZE];

memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE );
memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE );

snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME);
::testing::GTEST_FLAG(output) = testresults_fullfilepath;
::testing::InitGoogleTest(&argc, argv);
//testing::Mock::AllowLeak(mock);
cout << "Starting DCM GTEST ===================>" << endl;
return RUN_ALL_TESTS();
}
22 changes: 19 additions & 3 deletions backup_logs/unittest/special_files_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
#include <sys/stat.h>
#include <unistd.h>

#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/"
#define GTEST_DEFAULT_RESULT_FILENAME "special_files_gtest_report.json"
#define GTEST_REPORT_FILEPATH_SIZE 256

extern "C" {
#include "../include/special_files.h"
#include "../include/backup_types.h"
Expand Down Expand Up @@ -450,7 +454,7 @@ TEST_F(SpecialFilesTest, ExecuteEntry_PathTruncation) {
int result = special_files_execute_entry(&test_entry, &test_backup_config);
EXPECT_EQ(result, BACKUP_ERROR_CONFIG); // Should fail due to path truncation
}

/*
// Test edge cases for load_config with maximum files
TEST_F(SpecialFilesTest, LoadConfig_MaxFiles) {
FILE dummy_file;
Expand All @@ -466,8 +470,9 @@ TEST_F(SpecialFilesTest, LoadConfig_MaxFiles) {
EXPECT_TRUE(test_config.config_loaded);
EXPECT_EQ(test_config.count, MAX_SPECIAL_FILES); // Should cap at max
}

*/
// Test specific move files detection
/*
TEST_F(SpecialFilesTest, ExecuteEntry_SpecificMoveFiles) {
const char* move_files[] = {
"/tmp/disk_cleanup.log",
Expand All @@ -488,8 +493,19 @@ TEST_F(SpecialFilesTest, ExecuteEntry_SpecificMoveFiles) {
EXPECT_EQ(result, BACKUP_SUCCESS) << "Failed for file: " << move_files[i];
}
}
*/

GTEST_API_ int main(int argc, char *argv[]){
char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE];
char buffer[GTEST_REPORT_FILEPATH_SIZE];

memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE );
memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE );

int main(int argc, char **argv) {
snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME);
::testing::GTEST_FLAG(output) = testresults_fullfilepath;
::testing::InitGoogleTest(&argc, argv);
//testing::Mock::AllowLeak(mock);
cout << "Starting DCM GTEST ===================>" << endl;
return RUN_ALL_TESTS();
}
16 changes: 15 additions & 1 deletion backup_logs/unittest/sys_integration_gtest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
#include <stddef.h>
#include <assert.h>

#define GTEST_DEFAULT_RESULT_FILEPATH "/tmp/Gtest_Report/"
#define GTEST_DEFAULT_RESULT_FILENAME "sys_integration_gtest_report.json"
#define GTEST_REPORT_FILEPATH_SIZE 256

extern "C" {
#include "sys_integration.h"
#include "backup_types.h"
Expand Down Expand Up @@ -373,7 +377,17 @@ TEST_F(SysIntegrationTest, SystemdNotificationParameterPassing) {
}

// Test runner
int main(int argc, char **argv) {
GTEST_API_ int main(int argc, char *argv[]){
char testresults_fullfilepath[GTEST_REPORT_FILEPATH_SIZE];
char buffer[GTEST_REPORT_FILEPATH_SIZE];

memset( testresults_fullfilepath, 0, GTEST_REPORT_FILEPATH_SIZE );
memset( buffer, 0, GTEST_REPORT_FILEPATH_SIZE );

snprintf( testresults_fullfilepath, GTEST_REPORT_FILEPATH_SIZE, "json:%s%s" , GTEST_DEFAULT_RESULT_FILEPATH , GTEST_DEFAULT_RESULT_FILENAME);
::testing::GTEST_FLAG(output) = testresults_fullfilepath;
::testing::InitGoogleTest(&argc, argv);
//testing::Mock::AllowLeak(mock);
cout << "Starting DCM GTEST ===================>" << endl;
return RUN_ALL_TESTS();
}
Loading
Loading