Skip to content

Add unit tests for isSecureDbgSrvUnlocked and getDeviceTypeRFC to increase line coverage#227

Draft
Copilot wants to merge 3 commits into
topic/RDKEMW-13335from
copilot/add-additional-unit-tests
Draft

Add unit tests for isSecureDbgSrvUnlocked and getDeviceTypeRFC to increase line coverage#227
Copilot wants to merge 3 commits into
topic/RDKEMW-13335from
copilot/add-additional-unit-tests

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 18, 2026

PR #205 introduced isSecureDbgSrvUnlocked and getDeviceTypeRFC but left several branches uncovered. This adds 10 targeted tests across both test files to close those gaps.

isSecureDbgSrvUnlockedunittest/deviceutils/device_api_gtest.cpp

  • eUNKNOWNfalse (skips both branches entirely)
  • eDEVtrue (non-prod fast path)
  • eQAtrue (non-prod fast path)
  • ePROD + labsigned=true + deviceType=prodfalse (hits else "unable to enable debug services" branch; prior tests only covered deviceType=test with dbgServices=false)
  • ePROD + labsigned=""false (hits "LABSIGNED_ENABLED not enabled" log path with empty string vs prior "false")

getDeviceTypeRFCunittest/fwdl_interface_gtest.cpp

  • "PROD" / "TEST" / "Prod""prod" / "test" / "prod" (exercises strncasecmp case-insensitivity; existing tests only used lowercase)
  • buffer size = 1"" (verifies strncpy(dst, type, 0) + forced NUL at dst[0])
  • empty string from RFC"unknown" (neither strncasecmp branch matches)

Housekeeping

  • Added .gitignore covering autotools and gcov build artifacts (*.Po, *.gcno, Makefile, configure, autom4te.cache/, etc.)
Original prompt

Overview

PR #205 introduces two new functions:

  1. isSecureDbgSrvUnlocked(BUILDTYPE eBuildType) in src/deviceutils/device_api.c — determines whether secure debug services may be enabled for the given build type.
  2. getDeviceTypeRFC(char *deviceType, size_t size) in src/rfcInterface/rfcinterface.c — reads the device type RFC value and copies it into the provided buffer.

PR #205 already includes some unit tests for these, but coverage is incomplete. The task is to add additional unit tests to maximize line coverage of these two new functions and the modified GetServURL() function.

Source code to be tested

isSecureDbgSrvUnlocked in src/deviceutils/device_api.c (lines 55-100):

bool isSecureDbgSrvUnlocked(BUILDTYPE eBuildType)
{ 
	char deviceType[16] = {0};
    bool isDebugServicesUnlocked = false;
	char labsigned[8] = {0};
	int ret = -1;

    if ((eBuildType != ePROD) && (eBuildType != eUNKNOWN)) {
        isDebugServicesUnlocked = true;
    }

    else if (eBuildType == ePROD) 
	{
		bool dbgServices = isDebugServicesEnabled();
		getDeviceTypeRFC(deviceType, sizeof(deviceType));
        ret = getDevicePropertyData("LABSIGNED_ENABLED", labsigned, sizeof(labsigned));
        if (ret == UTILS_SUCCESS)
	    {
            if (0 == strncmp(labsigned, "true", 4))
		    {
		        if ((strcmp(deviceType, "test") == 0) && dbgServices)
		        {
                     isDebugServicesUnlocked = true;
                }   
		        else
		        {
		             SWLOG_INFO("isSecureDbgSrvUnlocked: unable to enable debug services...\n");
                }
            }
            else
            {
                SWLOG_INFO("LABSIGNED_ENABLED not enabled (value: %s); debug services remain locked\n", labsigned);
            }
        } 
	    else 
	    {
            SWLOG_ERROR("%s: getDevicePropertyData() for LABSIGNED_ENABLED failed\n", __FUNCTION__);
        }
		SWLOG_INFO("isSecureDbgSrvUnlocked: dbgServices=%s, deviceType=%s, LABSIGNED_ENABLED=%s\n", dbgServices ? "true" : "false", deviceType, labsigned);	
		if(isDebugServicesUnlocked){
			SWLOG_INFO("isSecureDbgSrvUnlocked: Enabling debug services...\n");
			t2ValNotify("SYST_INFO_FW_DbgSrv", "true");
		}
	}
    return isDebugServicesUnlocked;
}

getDeviceTypeRFC in src/rfcInterface/rfcinterface.c (lines 298-323):

void getDeviceTypeRFC(char *deviceType, size_t size ){
	if (deviceType == NULL || size == 0){
        SWLOG_ERROR("%s: Invalid Arguments Passed...\n", __FUNCTION__);
		return;
	}
	const char* type = "unknown";
    char rfc_data[RFC_VALUE_BUF_SIZE] = {0};
    int ret = read_RFCProperty("DEVICETYPE", RFC_DEVICETYPE, rfc_data, sizeof(rfc_data));
    if (ret == -1) {
        SWLOG_ERROR("%s: Failed to read device type\n", __FUNCTION__);
	}
    SWLOG_INFO("%s: RFC device type = %s\n", __FUNCTION__, rfc_data);
    if (strncasecmp(rfc_data, "prod", 4) == 0) {
        type = "prod";
    } else if (strncasecmp(rfc_data, "test", 4) == 0) {
        type = "test";
    } 
	strncpy(deviceType, type, size - 1);
    deviceType[size - 1] = '\0';
}

Modified GetServURL in src/deviceutils/device_api.c now calls isSecureDbgSrvUnlocked(eBuildType) instead of the old (eBuildType != ePROD) || (dbgServices == true) pattern.

Existing test infrastructure

Test file for device_api: unittest/deviceutils/device_api_gtest.cpp

  • Uses DeviceApiTestFixture test fixture class
  • Has mock object g_DeviceUtilsMock of type DeviceUtilsMock*
  • Already has tests for isSecureDbgSrvUnlocked covering: eVBN (non-prod), ePROD with various labsigned/deviceType/dbgServices combos, and getDevicePropertyData failure case
  • Already has GetServURL tests with new mock expectations

Test file for rfcinterface: unittest/fwdl_interface_gtest.cpp

  • Uses InterfaceTestFixture test fixture class
  • Has mock object g_InterfaceMock of type FwDlInterfaceMock*
  • Already has tests for getDeviceTypeRFC covering: NULL args, read failure, prod, test, unknown/staging

Mock class: unittest/mocks/deviceutils_mock.h

  • DeviceUtilsMock has these relevant mock methods:
    • MOCK_METHOD(bool, isDebugServicesEnabled, (), ())
    • MOCK_METHOD(void, getDeviceTypeRFC, (char*, size_t), ())
    • MOCK_METHOD(int, getDevicePropertyData, (const char *model, char *data, int size), ())
    • MOCK_METHOD(void, t2ValNotify, (char *marker, char* value), ())
    • MOCK_METHOD(bool, isInStateRed, (), ())
    • MOCK_METHOD(int, filePresentCheck, (const char *filename), ())
    • MOCK_METHOD(int, read_RFCProperty, (char* type, const char* key, char *out_value, size_t datasize), ())

Build types available: eUNKNOWN, eDEV, eVBN, ePROD, eQA

Requirements

Add additional tests to unittest/deviceutils/device_api_gtest.cpp to increase line coverage for the new code. Specifically, add the following missing test scenarios:

For isSecureDbgSrvUnlocked:

  1. eUNKNOWN build type — should return false (neither non-p...

This pull request was created from Copilot chat.


🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.

Copilot AI and others added 2 commits March 18, 2026 04:40
Co-authored-by: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com>
Co-authored-by: KTirumalaSrihari <102281309+KTirumalaSrihari@users.noreply.github.com>
Copilot AI changed the title [WIP] Add additional unit tests for new functions Add unit tests for isSecureDbgSrvUnlocked and getDeviceTypeRFC to increase line coverage Mar 18, 2026
Copilot AI requested a review from KTirumalaSrihari March 18, 2026 04:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants