Skip to content

RDKB-63834: Add unit tests for empty config file detection and fprintf failure paths in persistence.c#285

Merged
shibu-kv merged 2 commits intotopic/RDKB-63834from
copilot/sub-pr-284
Mar 17, 2026
Merged

RDKB-63834: Add unit tests for empty config file detection and fprintf failure paths in persistence.c#285
shibu-kv merged 2 commits intotopic/RDKB-63834from
copilot/sub-pr-284

Conversation

Copy link
Contributor

Copilot AI commented Mar 13, 2026

Code review on the persistence corruption-handling changes requested test coverage for two new branches: empty-file skipping in fetchLocalConfigs() and fprintf failure handling in saveConfigToFile().

Test additions (UtilsTest.cpp)

  • FETCHLOCALCONFIGS_EMPTY_FILE — uses an Invoke lambda on the fstat mock to set st_size = 0, asserts unlink is called via removeProfileFromDisk and the config list stays empty
  • SAVECONFITOFILE_FPRINTF_FAILURE — mocks fprintf returning -1, asserts fclose and unlink are both called and the return is T2ERROR_FAILURE
  • SAVECONFITOFILE_SUCCESS — covers the previously untested full success path
  • Removes the stale /* SAVECONFITOFILE2 */ commented-out block

Mock fix (FileioMock.cpp)

With FORTIFY_SOURCE active (default on Ubuntu), the compiler replaces fprintf with an inline call to __fprintf_chk, bypassing the existing extern "C" int fprintf(...) override entirely. Added a matching __fprintf_chk interception that delegates to the same g_fileIOMock->fprintf() method:

extern "C" int __fprintf_chk(FILE* stream, int /*flag*/, const char* format, ...) {
    va_list args;
    va_start(args, format);
    int result = g_fileIOMock ? g_fileIOMock->fprintf(stream, format, args)
                              : vfprintf(stream, format, args);
    va_end(args);
    return result;
}

Misc

  • Added .gitignore covering autotools and build artifacts.

💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

… persistence.c

Co-authored-by: shibu-kv <89052442+shibu-kv@users.noreply.github.com>
Copilot AI changed the title [WIP] [RDKB-63834] Reject and remove corrupted config files in persistence RDKB-63834: Add unit tests for empty config file detection and fprintf failure paths in persistence.c Mar 13, 2026
Copilot AI requested a review from shibu-kv March 13, 2026 14:51
@shibu-kv shibu-kv marked this pull request as ready for review March 17, 2026 19:48
@shibu-kv shibu-kv requested a review from a team as a code owner March 17, 2026 19:48
Copilot AI review requested due to automatic review settings March 17, 2026 19:48
@shibu-kv shibu-kv merged commit 0f54a26 into topic/RDKB-63834 Mar 17, 2026
4 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Mar 17, 2026
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.

2 participants