Skip to content
Closed

Merge #171

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
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
142 changes: 142 additions & 0 deletions rfcMgr/rdk_debug.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
/**
* If not stated otherwise in this file or this component's LICENSE
* file the following copyright and licenses apply:
*
* Copyright 2023 RDK Management
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
**/

#ifndef RDK_DEBUG_H_
#define RDK_DEBUG_H_

#include <stdio.h>


// Try to include the real RDK logger if available
#ifdef RDK_LOGGER
// First try to include the real RDK logger header
#if __has_include(<rdk_logger.h>)
#include <rdk_logger.h>
#elif __has_include("rdk_logger.h")
#include "rdk_logger.h"
#else
// If real RDK logger is not available, provide fallback definitions
#define RDK_LOG_TRACE1 1
#define RDK_LOG_DEBUG 2
#define RDK_LOG_INFO 3
#define RDK_LOG_WARN 4
#define RDK_LOG_ERROR 5
#define RDK_LOG_FATAL 6

// RDK Logger success/failure codes
#define RDK_SUCCESS 0
#define RDK_FAILURE -1

// RDK Logger Extended API structures and enums
typedef enum {
RDKLOG_OUTPUT_CONSOLE = 1,
RDKLOG_OUTPUT_FILE = 2
} rdklog_output_t;

typedef enum {
RDKLOG_FORMAT_SIMPLE = 1,
RDKLOG_FORMAT_WITH_TS = 2
} rdklog_format_t;

typedef struct {
char *pModuleName;
int loglevel;
rdklog_output_t output;
rdklog_format_t format;
void *pFilePolicy;
} rdk_logger_ext_config_t;

// Fallback implementations for different RDK logger APIs
#ifdef RDKB_SUPPORT
// For RDKB builds, use the old API
#define RDK_LOGGER_INIT() printf("RDK Logger initialized (fallback)\n")
#else
// For non-RDKB builds, use the new extended API
static inline int rdk_logger_ext_init(rdk_logger_ext_config_t *config) {
if (config && config->pModuleName) {
printf("RDK Extended Logger initialized for module: %s (fallback)\n", config->pModuleName);
}
return RDK_SUCCESS;
}
#endif

// Fallback RDK_LOG macro that uses printf
#define RDK_LOG(level, module, ...) \
do { \
if (level == RDK_LOG_DEBUG) { \
printf("DEBUG: %s: ", module); \
} \
else if (level == RDK_LOG_INFO) { \
printf("INFO: %s: ", module); \
} \
else if (level == RDK_LOG_ERROR) { \
printf("ERROR: %s: ", module); \
} \
else if (level == RDK_LOG_FATAL) { \
printf("FATAL: %s: ", module); \
} \
printf(__VA_ARGS__); \
} while (0)
#endif
#else
// When RDK_LOGGER is not defined, provide minimal definitions
#define RDK_LOG_TRACE1 1
#define RDK_LOG_DEBUG 2
#define RDK_LOG_INFO 3
#define RDK_LOG_WARN 4
#define RDK_LOG_ERROR 5
#define RDK_LOG_FATAL 6

#define RDK_SUCCESS 0
#define RDK_FAILURE -1

#define RDK_LOGGER_INIT() ;

typedef enum {
RDKLOG_OUTPUT_CONSOLE = 1,
RDKLOG_OUTPUT_FILE = 2
} rdklog_output_t;

typedef enum {
RDKLOG_FORMAT_SIMPLE = 1,
RDKLOG_FORMAT_WITH_TS = 2
} rdklog_format_t;

typedef struct {
char *pModuleName;
int loglevel;
rdklog_output_t output;
rdklog_format_t format;
void *pFilePolicy;
} rdk_logger_ext_config_t;

static inline int rdk_logger_ext_init(rdk_logger_ext_config_t *config) {
(void)config; // Suppress unused parameter warning
return RDK_SUCCESS;
}

// Simple printf-based logging when RDK_LOGGER is not enabled
#define RDK_LOG(level, module, ...) \
do { \
printf("[%s] ", module); \
printf(__VA_ARGS__); \
} while (0)
#endif

#endif // RDK_DEBUG_H_
20 changes: 18 additions & 2 deletions rfcMgr/rfc_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,25 @@ namespace rfc {
}
#endif
RFCManager ::RFCManager() {
#if defined(RDK_LOGGER)
#if defined(RDKB_SUPPORT)
RDK_LOGGER_INIT();
#else
/* Initialize RDK Logger */
rdk_logger_init(0 == access(OVERIDE_DEBUG_INI_FILE, R_OK) ? OVERIDE_DEBUG_INI_FILE : DEBUG_INI_FILE);

static char RFCMGRLOG[] = "LOG.RDK.RFCMGR";

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

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

static char RFCMGRLOG[] = "LOG.RDK.RFCMGR"; is not modified anywhere and can be static const char* (or constexpr const char[]) to avoid exposing a writable buffer unnecessarily.

Suggested change
static char RFCMGRLOG[] = "LOG.RDK.RFCMGR";
static constexpr char RFCMGRLOG[] = "LOG.RDK.RFCMGR";

Copilot uses AI. Check for mistakes.
rdk_logger_ext_config_t config = {
.pModuleName = RFCMGRLOG, /* Module name */
.loglevel = RDK_LOG_INFO, /* Default log level */
.output = RDKLOG_OUTPUT_CONSOLE, /* Output to console (stdout/stderr) */
.format = RDKLOG_FORMAT_WITH_TS, /* Timestamped format */
.pFilePolicy = NULL /* Not using file output, so NULL */
};
Comment on lines +48 to +54

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

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

rdk_logger_ext_config_t config = { .pModuleName = ..., ... } uses C++ designated initializers. This component is built with -std=c++17 and -Werror (see rfcMgr/Makefile.am), so this will not compile on standard-conforming C++17 toolchains. Initialize config without designators (or default-construct then assign fields) to keep the build C++17-compatible.

Suggested change
rdk_logger_ext_config_t config = {
.pModuleName = RFCMGRLOG, /* Module name */
.loglevel = RDK_LOG_INFO, /* Default log level */
.output = RDKLOG_OUTPUT_CONSOLE, /* Output to console (stdout/stderr) */
.format = RDKLOG_FORMAT_WITH_TS, /* Timestamped format */
.pFilePolicy = NULL /* Not using file output, so NULL */
};
rdk_logger_ext_config_t config{};
config.pModuleName = RFCMGRLOG; /* Module name */
config.loglevel = RDK_LOG_INFO; /* Default log level */
config.output = RDKLOG_OUTPUT_CONSOLE; /* Output to console (stdout/stderr) */
config.format = RDKLOG_FORMAT_WITH_TS; /* Timestamped format */
config.pFilePolicy = NULL; /* Not using file output, so NULL */

Copilot uses AI. Check for mistakes.

if (rdk_logger_ext_init(&config) != RDK_SUCCESS) {
printf("RFC : ERROR - Extended logger init failed\n");
}
Comment on lines +56 to +58

Copilot AI Feb 11, 2026

Copy link

Choose a reason for hiding this comment

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

rfcMgr_gtest builds rfc_manager.cpp but the gtest Makefile does not link -lrdkloggers. Introducing a direct call to rdk_logger_ext_init() is therefore likely to break unit-test linking (the symbol is not provided anywhere in this repo). Consider guarding this call under #if !defined(GTEST_ENABLE) and/or providing a test stub, or update the gtest target’s link flags accordingly.

Copilot uses AI. Check for mistakes.
#endif
#endif
/* Initialize IARM Bus */
InitializeIARM();
}
Expand Down
2 changes: 1 addition & 1 deletion run_l2.sh
Original file line number Diff line number Diff line change
Expand Up @@ -66,5 +66,5 @@ pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_xc

pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_override_rfc_prop.json test/functional-tests/tests/test_rfc_override_rfc_prop.py

pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_rfc_webpa.json test/functional-tests/tests/test_rfc_webpa.py
#pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/rfc_rfc_webpa.json test/functional-tests/tests/test_rfc_webpa.py

1 change: 1 addition & 0 deletions test/functional-tests/tests/rfc_test_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
RFC_MGR_PATH: str = "/usr/bin/rfcMgr"
RFC_LOCK_FILE: str = "/tmp/.rfcServiceLock"
RFC_LOG_FILE: str = "/opt/logs/rfcscript.txt"
LOG_FILE: str = "/opt/logs/rfcscript.txt.1"
SWUPDATE_LOG_FILE: str = "/opt/logs/swupdate.txt"
RFC_ROUTE_FILE: str = "/tmp/route_available"
RFC_DNS_FILE: str = "/etc/resolv.dnsmasq"
Expand Down
16 changes: 8 additions & 8 deletions test/functional-tests/tests/test_rfc_unknown_accountid.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,16 +77,16 @@ def test_xconf_request_response():
RFC_PARAM = f"Checking Config Value changed for tr181 param"
XCONF_RESP_RECEIVED_ACTID_UNKNOWN = f"RFC: AccountId received from Xconf is Unknown"
XCONF_RESP_CMP_MSG = f"RFC: Comparing Xconfvalue='Unknown' with Unknown"
ACTID_REPLACE_AUTHSERVICE = f"RFC: AccountId Unknown is replaced with Authservice 412370664406228514"
ACTID_UPDATE = f"RFC: AccountId Updated Value is 412370664406228514 and Xconf value is 412370664406228514"
ACTID_REPLACE_AUTHSERVICE = f"RFC: AccountId Unknown is replaced with Authservice 3064488088886635972"
ACTID_UPDATE = f"RFC: AccountId Updated Value is 3064488088886635972 and Xconf value is 3064488088886635972"


assert grep_log_file(RFC_LOG_FILE, FEATURE_NAME_VALUE), f"Expected '{FEATURE_NAME_VALUE}' in log file."
assert grep_log_file(RFC_LOG_FILE, RFC_PARAM), f"Expected '{RFC_PARAM}' in log file."
assert grep_log_file(RFC_LOG_FILE, XCONF_RESP_RECEIVED_ACTID_UNKNOWN), f"Expected '{XCONF_RESP_RECEIVED_ACTID_UNKNOWN}' in log file."
assert grep_log_file(RFC_LOG_FILE, XCONF_RESP_CMP_MSG), f"Expected '{XCONF_RESP_CMP_MSG}' in log file."
assert grep_log_file(RFC_LOG_FILE, ACTID_REPLACE_AUTHSERVICE), f"Expected '{ACTID_REPLACE_AUTHSERVICE}' in log file."
assert grep_log_file(RFC_LOG_FILE, ACTID_UPDATE), f"Expected '{ACTID_UPDATE}' in log file."
assert grep_log_file(LOG_FILE, FEATURE_NAME_VALUE), f"Expected '{FEATURE_NAME_VALUE}' in log file."
assert grep_log_file(LOG_FILE, RFC_PARAM), f"Expected '{RFC_PARAM}' in log file."
assert grep_log_file(LOG_FILE, XCONF_RESP_RECEIVED_ACTID_UNKNOWN), f"Expected '{XCONF_RESP_RECEIVED_ACTID_UNKNOWN}' in log file."
assert grep_log_file(LOG_FILE, XCONF_RESP_CMP_MSG), f"Expected '{XCONF_RESP_CMP_MSG}' in log file."
assert grep_log_file(LOG_FILE, ACTID_REPLACE_AUTHSERVICE), f"Expected '{ACTID_REPLACE_AUTHSERVICE}' in log file."
assert grep_log_file(LOG_FILE, ACTID_UPDATE), f"Expected '{ACTID_UPDATE}' in log file."
except Exception as e:
print(f"Exception during Validate the XConf request and response: {e}")
assert False, f"Exception during Validate the XConf request and response: {e}"
Expand Down
Loading