Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
93fa87b
Update usb_log_validation.h
Abhinavpv28 Feb 20, 2026
3a561b2
Update usb_log_validation_gtest.cpp
Abhinavpv28 Feb 20, 2026
2348d03
Add conditional compilation for GTEST_ENABLE
Abhinavpv28 Feb 23, 2026
8e0faaa
Update Makefile.am
Abhinavpv28 Feb 23, 2026
7ca8df1
Update Makefile.am
Abhinavpv28 Feb 23, 2026
fafcdb8
Update usb_log_validation_gtest.cpp
Abhinavpv28 Feb 23, 2026
210f256
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 23, 2026
806dd7e
Update usb_log_main_gtest.cpp
Abhinavpv28 Feb 23, 2026
df811f3
Update unit_test.sh
Abhinavpv28 Feb 23, 2026
17de9ff
Update unit_test.sh
Abhinavpv28 Feb 24, 2026
96c4b9d
Update unit_test.sh
Abhinavpv28 Feb 24, 2026
56670aa
Update unit_test.sh
Abhinavpv28 Feb 24, 2026
75604ac
Update unit_test.sh
Abhinavpv28 Feb 24, 2026
c1585ab
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
cc12250
Update directory path for unit tests
Abhinavpv28 Feb 25, 2026
7b533c3
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
20d0301
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
e72dba1
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
78678fa
Create configure.ac
Abhinavpv28 Feb 25, 2026
1504714
Update Makefile.am
Abhinavpv28 Feb 25, 2026
dfdc0bd
Update Makefile.am
Abhinavpv28 Feb 25, 2026
d78399d
Update Makefile.am
Abhinavpv28 Feb 25, 2026
18a6948
Update Makefile.am
Abhinavpv28 Feb 25, 2026
254e48c
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 25, 2026
131b615
Update usb_log_main_gtest.cpp
Abhinavpv28 Feb 25, 2026
1089a56
Update usb_log_main_gtest.cpp
Abhinavpv28 Feb 25, 2026
519cf24
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 25, 2026
a21a5c7
Update usb_log_main_gtest.cpp
Abhinavpv28 Feb 25, 2026
6821e5f
Update usb_log_main_gtest.cpp
Abhinavpv28 Feb 25, 2026
0ca2a37
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
b370575
Update Makefile.am
Abhinavpv28 Feb 25, 2026
edb3c1a
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
1c3073f
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
c6345e0
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 25, 2026
1b9819f
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
fa39b09
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 25, 2026
17b90d5
Update Makefile.am
Abhinavpv28 Feb 25, 2026
b7936c2
Update Makefile.am
Abhinavpv28 Feb 25, 2026
e0b3505
Update Makefile.am
Abhinavpv28 Feb 25, 2026
29a984a
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 25, 2026
f821841
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 25, 2026
6a33370
Update Makefile.am
Abhinavpv28 Feb 25, 2026
c65f987
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 25, 2026
3f29a1f
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 25, 2026
e1ea0bf
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 25, 2026
6bcffab
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
62aad49
Create usb_log_archive_gtest.cpp
Abhinavpv28 Feb 25, 2026
80b482c
Update Makefile.am
Abhinavpv28 Feb 25, 2026
03e3c26
Update Makefile.am
Abhinavpv28 Feb 25, 2026
b818fe9
Implement unit tests for usb_log_utils
Abhinavpv28 Feb 25, 2026
d79e1f5
Update Makefile.am
Abhinavpv28 Feb 25, 2026
d96f7ab
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
8418acb
Remove unnecessary empty line in unit_test.sh
Abhinavpv28 Feb 25, 2026
57b9f76
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
995120d
Update unit_test.sh
Abhinavpv28 Feb 25, 2026
aad24c0
Remove echo command from unit_test.sh
Abhinavpv28 Feb 25, 2026
8c25027
Update unit_test.sh to set RDK_PROFILE
Abhinavpv28 Feb 25, 2026
e826ce4
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 26, 2026
553c5ba
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 26, 2026
51888c5
Remove usb_log_main_gtest from unit tests
Abhinavpv28 Feb 26, 2026
01546fd
Update usb_log_file_manager_gtest.cpp
Abhinavpv28 Feb 26, 2026
8cea413
Update usb_log_validation_gtest.cpp
Abhinavpv28 Feb 26, 2026
d39cee0
Update usb_log_validation_gtest.cpp
Abhinavpv28 Feb 26, 2026
6bf0533
Update usb_log_validation_gtest.cpp
Abhinavpv28 Feb 26, 2026
4940298
Enable coverage options in unit_test.sh
Abhinavpv28 Feb 27, 2026
f159ad9
Remove lcov list command from coverage report
Abhinavpv28 Mar 2, 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
26 changes: 21 additions & 5 deletions unit_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
## SPDX-License-Identifier: Apache-2.0
#

ENABLE_COV=false
ENABLE_COV=true

if [ "x$1" = "x--enable-cov" ]; then
echo "Enabling coverage options"
Expand All @@ -29,7 +29,8 @@ if [ "x$1" = "x--enable-cov" ]; then
fi
export TOP_DIR=`pwd`
export top_srcdir=`pwd`

export LD_LIBRARY_PATH="/usr/local/lib:$TOP_DIR/uploadstblogs/src/.libs:$LD_LIBRARY_PATH"
echo "RDK_PROFILE=TV" >> /etc/device.properties

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unit_test.sh appends RDK_PROFILE=TV to /etc/device.properties unconditionally. This can create duplicate entries on repeated runs and makes test setup non-idempotent. Follow the pattern used elsewhere in the repo (grep before append, and create the file if missing) to keep the environment stable.

Suggested change
echo "RDK_PROFILE=TV" >> /etc/device.properties
if [ ! -f /etc/device.properties ]; then
touch /etc/device.properties
fi
if ! grep -q '^RDK_PROFILE=TV$' /etc/device.properties 2>/dev/null; then
echo "RDK_PROFILE=TV" >> /etc/device.properties
fi

Copilot uses AI. Check for mistakes.
cd unittest/
cp mocks/mockrbus.h /usr/local/include
cp ../uploadstblogs/include/*.h /usr/local/include
Expand All @@ -42,6 +43,9 @@ make clean
make

cd ../uploadstblogs/unittest
cd ../..
sh cov_build.sh

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new call to sh cov_build.sh introduces a supply-chain risk because cov_build.sh clones and executes remote GitHub repositories (e.g., rdkcentral/iarmmgrs, rdkcentral/rdk_logger, rdkcentral/telemetry, rdkcentral/common_utilities) using mutable branches without any integrity or version pinning. If any of those upstream repositories or the network path is compromised, an attacker could execute arbitrary code in your CI/test environment and potentially access secrets or tamper with build artifacts. To mitigate this, pin git clone operations to specific commit hashes or verified release tags and/or vendor the required build artifacts instead of executing unpinned remote code during the test run.

Copilot uses AI. Check for mistakes.
cd -
Comment on lines +46 to +48

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cov_build.sh is invoked unconditionally. This script clones/builds dependencies and adds network + time cost to every unit test run, even when coverage isn’t requested. Consider gating this behind the coverage flag (or a separate explicit option) and/or caching dependencies in CI.

Copilot uses AI. Check for mistakes.
git clone https://github.com/rdkcentral/iarmmgrs.git
cp iarmmgrs/sysmgr/include/sysMgr.h /usr/local/include
cp iarmmgrs/maintenance/include/maintenanceMGR.h /usr/local/include
Expand All @@ -55,9 +59,18 @@ autoreconf --install

make clean
make
pwd
cd ../../usbLogUpload/unittest
automake --add-missing
autoreconf --install

./configure

make clean
make
echo "RDK_PROFILE=TV" >> /etc/device.properties
fail=0
cd -
cd $TOP_DIR/unittest/

for test in \
./dcm_utils_gtest \
Expand All @@ -81,7 +94,11 @@ for test in \
./../uploadstblogs/unittest/retry_logic_gtest \
./../uploadstblogs/unittest/strategies_gtest \
./../uploadstblogs/unittest/strategy_handler_gtest \
./../uploadstblogs/unittest/uploadlogsnow_gtest
./../uploadstblogs/unittest/uploadlogsnow_gtest \
./../usbLogUpload/unittest/usb_log_file_manager_gtest \
./../usbLogUpload/unittest/usb_log_validation_gtest \
./../usbLogUpload/unittest/usb_log_utils_gtest \
./../usbLogUpload/unittest/usb_log_archive_gtest

do
$test
Expand All @@ -107,5 +124,4 @@ if [ "$ENABLE_COV" = true ]; then
lcov --capture --directory . --output-file coverage.info
lcov --remove coverage.info '/usr/*' --output-file coverage.info
lcov --remove coverage.info "${PWD}/*" --output-file coverage.info
lcov --list coverage.info
fi
9 changes: 0 additions & 9 deletions usbLogUpload/include/usb_log_validation.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,6 @@ extern "C" {
*/
int validate_usb_mount_point(const char *mount_point);

/**
* @brief Validate system prerequisites
*
* Checks that all required system components and utilities are available.
*
* @return int 0 if all prerequisites met, negative error code otherwise
*/
int validate_system_prerequisites(void);

/**
* @brief Validate input parameters
*
Expand Down
2 changes: 2 additions & 0 deletions usbLogUpload/src/usb_log_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <time.h>
#include <string.h>

#ifndef GTEST_ENABLE
/**
* @brief Main application entry point
*
Expand Down Expand Up @@ -66,6 +67,7 @@ int main(int argc, char *argv[])

return ret;
}
#endif

/**
* @brief Execute USB log upload operation
Expand Down
31 changes: 26 additions & 5 deletions usbLogUpload/unittest/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ AUTOMAKE_OPTIONS = subdir-objects
ACLOCAL_AMFLAGS = -I m4

# Define the test executables
bin_PROGRAMS = usb_log_file_manager_gtest usb_log_main_gtest usb_log_validation_gtest
bin_PROGRAMS = usb_log_file_manager_gtest usb_log_main_gtest usb_log_validation_gtest usb_log_archive_gtest usb_log_utils_gtest

# Common include directories
COMMON_CPPFLAGS = -I/usr/include/gtest -I/usr/local/include -I/usr/local/include/gtest \
Expand All @@ -29,9 +29,11 @@ COMMON_CPPFLAGS = -I/usr/include/gtest -I/usr/local/include -I/usr/local/include

AM_CPPFLAGS = $(COMMON_CPPFLAGS)
AM_CXXFLAGS = -std=c++14
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH="$TOP_DIR/uploadstblogs/src/.libs:$LD_LIBRARY_PATH"

Comment on lines +32 to 34

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The export LD_LIBRARY_PATH=... lines are not valid/portable in this form for Automake: the second assignment uses shell-style $TOP_DIR (Make will treat $T as a Make variable) and includes quotes, so the resulting value is likely incorrect. Since unit_test.sh already sets LD_LIBRARY_PATH before running the binaries, consider removing these lines or using an Automake-supported approach (e.g., AM_TESTS_ENVIRONMENT / wrapper script) with proper Make variables like $(top_builddir).

Suggested change
export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export LD_LIBRARY_PATH="$TOP_DIR/uploadstblogs/src/.libs:$LD_LIBRARY_PATH"

Copilot uses AI. Check for mistakes.
# Common libraries
COMMON_LDADD = -lgtest -lgmock -lpthread -lcurl -lcjson -lssl -lcrypto -lgcov
COMMON_LDADD = -lgtest -lgmock -lpthread -lcurl -lcjson -lssl -lcrypto -lgcov -lrdkloggers -lfwutils -L/usr/local/lib -luploadstblogs

# Common compiler flags
COMMON_CXXFLAGS = -fprofile-arcs -ftest-coverage -fpermissive -Wno-write-strings -Wno-unused-result
Expand All @@ -40,7 +42,7 @@ COMMON_CXXFLAGS = -fprofile-arcs -ftest-coverage -fpermissive -Wno-write-strings

# USB Log File Manager GTest
usb_log_file_manager_gtest_SOURCES = usb_log_file_manager_gtest.cpp \
../src/usb_log_file_manager.c
../src/usb_log_file_manager.c ../src/usb_log_utils.c ../../uploadstblogs/unittest/mocks/mock_file_operations.cpp

usb_log_file_manager_gtest_CPPFLAGS = $(COMMON_CPPFLAGS)
usb_log_file_manager_gtest_LDADD = $(COMMON_LDADD)
Expand All @@ -53,10 +55,11 @@ usb_log_main_gtest_SOURCES = usb_log_main_gtest.cpp \
../src/usb_log_validation.c \
../src/usb_log_file_manager.c \
../src/usb_log_archive.c \
../src/usb_log_utils.c
../src/usb_log_utils.c \
../../uploadstblogs/unittest/mocks/mock_file_operations.cpp

usb_log_main_gtest_CPPFLAGS = $(COMMON_CPPFLAGS)
usb_log_main_gtest_LDADD = $(COMMON_LDADD)
usb_log_main_gtest_LDADD = $(COMMON_LDADD) -L/usr/local/lib -luploadstblogs
usb_log_main_gtest_CXXFLAGS = $(COMMON_CXXFLAGS)
usb_log_main_gtest_CFLAGS = $(COMMON_CXXFLAGS)

Expand All @@ -70,3 +73,21 @@ usb_log_validation_gtest_LDADD = $(COMMON_LDADD)
usb_log_validation_gtest_CXXFLAGS = $(COMMON_CXXFLAGS)
usb_log_validation_gtest_CFLAGS = $(COMMON_CXXFLAGS)

# USB Log Archive GTest
usb_log_archive_gtest_SOURCES = usb_log_archive_gtest.cpp \
../src/usb_log_archive.c \
../../uploadstblogs/unittest/mocks/mock_file_operations.cpp

usb_log_archive_gtest_CPPFLAGS = $(COMMON_CPPFLAGS)
usb_log_archive_gtest_LDADD = $(COMMON_LDADD)
usb_log_archive_gtest_CXXFLAGS = $(COMMON_CXXFLAGS)
usb_log_archive_gtest_CFLAGS = $(COMMON_CXXFLAGS)

# USB Log Utils GTest
usb_log_utils_gtest_SOURCES = usb_log_utils_gtest.cpp \
../src/usb_log_utils.c

usb_log_utils_gtest_CPPFLAGS = $(COMMON_CPPFLAGS)
usb_log_utils_gtest_LDADD = $(COMMON_LDADD)
usb_log_utils_gtest_CXXFLAGS = $(COMMON_CXXFLAGS)
usb_log_utils_gtest_CFLAGS = $(COMMON_CXXFLAGS)
25 changes: 25 additions & 0 deletions usbLogUpload/unittest/configure.ac
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
AC_INIT([usbLogUpload-unittest], [1.0], [support@example.com])
AM_INIT_AUTOMAKE([foreign subdir-objects])
AC_CONFIG_SRCDIR([Makefile.am])
AC_CONFIG_HEADERS([config.h])

# Checks for programs.
AC_PROG_CC
AC_PROG_CXX
AC_PROG_INSTALL

# Checks for libraries.
AC_CHECK_LIB([pthread], [pthread_create])
AC_CHECK_LIB([cjson], [cJSON_Parse])
AC_CHECK_LIB([curl], [curl_easy_init])
AC_CHECK_LIB([ssl], [SSL_library_init])
AC_CHECK_LIB([crypto], [CRYPTO_new_ex_data])
AC_CHECK_LIB([gtest], [main])
AC_CHECK_LIB([gmock], [main])

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configure.ac does not check for some libraries that the unit test Makefile.am links against (notably rdkloggers, fwutils, and uploadstblogs). This can let ./configure succeed but fail later at link time. Add AC_CHECK_LIB (or PKG_CHECK_MODULES) entries for the libraries required by COMMON_LDADD.

Suggested change
AC_CHECK_LIB([gmock], [main])
AC_CHECK_LIB([gmock], [main])
AC_CHECK_LIB([rdkloggers], [main])
AC_CHECK_LIB([fwutils], [main])
AC_CHECK_LIB([uploadstblogs], [main])

Copilot uses AI. Check for mistakes.

# Checks for header files.
AC_CHECK_HEADERS([stdio.h stdlib.h string.h unistd.h sys/types.h sys/stat.h])

# Output files
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
59 changes: 59 additions & 0 deletions usbLogUpload/unittest/usb_log_archive_gtest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// Copyright 2026
// Unit tests for usb_log_archive.c
#include <gtest/gtest.h>
#include "usb_log_archive.h"
#include <string>
#include <cstdio>
#include <sys/stat.h>

// Mocks and stubs for dependencies
extern "C" {
int get_current_timestamp(char *buf, size_t len) {
strncpy(buf, "01/01/26-12:00:00", len-1);
buf[len-1] = '\0';
Comment on lines +8 to +13

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses strncpy in the stubbed get_current_timestamp() but does not include <cstring>/<string.h>. Some toolchains will fail to compile due to a missing declaration. Add the appropriate header (and consider using std::strncpy when including <cstring>).

Suggested change
// Mocks and stubs for dependencies
extern "C" {
int get_current_timestamp(char *buf, size_t len) {
strncpy(buf, "01/01/26-12:00:00", len-1);
buf[len-1] = '\0';
#include <cstring>
// Mocks and stubs for dependencies
extern "C" {
int get_current_timestamp(char *buf, size_t len) {
std::strncpy(buf, "01/01/26-12:00:00", len - 1);
buf[len - 1] = '\0';

Copilot uses AI. Check for mistakes.
return 0;
}
int copy_file_and_delete(const char *src, const char *dst) {
// Simulate successful copy
return 0;
}
Comment on lines +16 to +19

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy_file_and_delete() is stubbed to always succeed without creating the destination file or deleting the source. This means the success test doesn’t verify the primary output (archive_path exists) and can leave files behind in temp_dir. Update the stub to mimic the real side effects and assert that archive_path exists on success.

Copilot uses AI. Check for mistakes.
void RDK_LOG(int level, int module, const char *fmt, ...) {}
}

class UsbLogArchiveTest : public ::testing::Test {
protected:
std::string temp_dir;
void SetUp() override {
temp_dir = "./test_usb_log_dir";
mkdir(temp_dir.c_str(), 0777);
}
void TearDown() override {
rmdir(temp_dir.c_str());
}
Comment on lines +30 to +32

Copilot AI Mar 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TearDown() uses rmdir(temp_dir) but the test can leave files inside temp_dir (e.g., archives created by create_archive()), causing cleanup to silently fail and potentially break later test runs. Remove files recursively (or use a unique temporary directory and ensure it’s fully deleted).

Copilot uses AI. Check for mistakes.
};

TEST_F(UsbLogArchiveTest, CreateUsbLogArchive_Success) {
char archive_path[256] = "./test_usb_log_dir/test_archive.tar.gz";
int ret = create_usb_log_archive(temp_dir.c_str(), archive_path, "00:11:22:33:44:55");
EXPECT_EQ(ret, 0);
}

TEST_F(UsbLogArchiveTest, CreateUsbLogArchive_InvalidParams) {
char archive_path[256] = "./test_usb_log_dir/test_archive.tar.gz";
EXPECT_EQ(create_usb_log_archive(nullptr, archive_path, "00:11:22:33:44:55"), -1);
EXPECT_EQ(create_usb_log_archive(temp_dir.c_str(), nullptr, "00:11:22:33:44:55"), -1);
EXPECT_EQ(create_usb_log_archive(temp_dir.c_str(), archive_path, nullptr), -1);
}

TEST_F(UsbLogArchiveTest, CreateUsbLogArchive_SourceDirMissing) {
char archive_path[256] = "./test_usb_log_dir/test_archive.tar.gz";
std::string missing_dir = "./does_not_exist";
EXPECT_EQ(create_usb_log_archive(missing_dir.c_str(), archive_path, "00:11:22:33:44:55"), -2);
}
int main(int argc, char** argv) {
::testing::InitGoogleTest(&argc, argv);
int result = RUN_ALL_TESTS();

return result;
}

Loading
Loading