diff --git a/rfcMgr/rdk_debug.h b/rfcMgr/rdk_debug.h new file mode 100644 index 00000000..d2747dff --- /dev/null +++ b/rfcMgr/rdk_debug.h @@ -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 + + +// Try to include the real RDK logger if available +#ifdef RDK_LOGGER + // First try to include the real RDK logger header + #if __has_include() + #include + #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_ diff --git a/rfcMgr/rfc_manager.cpp b/rfcMgr/rfc_manager.cpp index 0430f639..1280c63c 100644 --- a/rfcMgr/rfc_manager.cpp +++ b/rfcMgr/rfc_manager.cpp @@ -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"; + 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 */ + }; + + if (rdk_logger_ext_init(&config) != RDK_SUCCESS) { + printf("RFC : ERROR - Extended logger init failed\n"); + } +#endif +#endif /* Initialize IARM Bus */ InitializeIARM(); } diff --git a/run_l2.sh b/run_l2.sh index 96a9484b..be746ca9 100644 --- a/run_l2.sh +++ b/run_l2.sh @@ -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 diff --git a/test/functional-tests/tests/rfc_test_helper.py b/test/functional-tests/tests/rfc_test_helper.py index 1f9fa3ee..0ec00a88 100644 --- a/test/functional-tests/tests/rfc_test_helper.py +++ b/test/functional-tests/tests/rfc_test_helper.py @@ -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" diff --git a/test/functional-tests/tests/test_rfc_unknown_accountid.py b/test/functional-tests/tests/test_rfc_unknown_accountid.py index aeee3013..7025d072 100644 --- a/test/functional-tests/tests/test_rfc_unknown_accountid.py +++ b/test/functional-tests/tests/test_rfc_unknown_accountid.py @@ -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}"