From 34dd874c3b10734bfb24f46e8094150432abb6f9 Mon Sep 17 00:00:00 2001 From: Gayathri Date: Tue, 29 Jan 2019 14:05:26 +0530 Subject: [PATCH 1/3] Added support of OnBoarding logging --- CHANGELOG.md | 1 + src/CMakeLists.txt | 11 ++++- src/cimplog-onboarding.c | 86 ++++++++++++++++++++++++++++++++++++++++ src/cimplog.c | 1 - src/cimplog.h | 9 +++++ src/main.c | 39 ++++++++++++++++++ tests/CMakeLists.txt | 2 +- tests/onboardingTest.sh | 6 +++ tests/simple.c | 9 +++++ 9 files changed, 160 insertions(+), 4 deletions(-) create mode 100644 src/cimplog-onboarding.c create mode 100644 src/main.c create mode 100755 tests/onboardingTest.sh diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c03c86..feedbef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Fixes for building in MacOS - Reverted generic API to log messages into an additional module other than the primary module of a component - Added support for overriding debug.ini file location in RDK code +- Added support of onboard logging ## [1.0.0] - 2017-10-11 ### Added diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 277455d..1075531 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -16,9 +16,9 @@ set(PROJ_CIMPL cimplog) file(GLOB HEADERS cimplog.h cimplog.h) if (RDK_LOGGER) -set(SOURCES cimplog-rdk-logger.c) +set(SOURCES cimplog-rdk-logger.c cimplog-onboarding.c) else (RDK_LOGGER) -set(SOURCES cimplog.c) +set(SOURCES cimplog.c cimplog-onboarding.c) endif (RDK_LOGGER) add_library(${PROJ_CIMPL} STATIC ${HEADERS} ${SOURCES}) @@ -43,3 +43,10 @@ install (TARGETS ${PROJ_CIMPL} install (TARGETS ${PROJ_CIMPL} DESTINATION lib${LIB_SUFFIX}) install (TARGETS ${PROJ_CIMPL}.shared DESTINATION lib${LIB_SUFFIX}) install (FILES cimplog.h DESTINATION include/${PROJ_CIMPL}) + +#------------------------------------------------------------------------------- +# onboarding_log cli +#------------------------------------------------------------------------------- +set(BIN_SOURCES cimplog-onboarding.c main.c) +add_executable(onboarding_log ${BIN_SOURCES} ${HEADERS}) +install (TARGETS onboarding_log DESTINATION bin) diff --git a/src/cimplog-onboarding.c b/src/cimplog-onboarding.c new file mode 100644 index 0000000..76167c3 --- /dev/null +++ b/src/cimplog-onboarding.c @@ -0,0 +1,86 @@ +/** + * Copyright 2016 Comcast Cable Communications Management, LLC + * + * 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. + * + */ +#include +#include +#include +#include +#include "cimplog.h" + +#define MAX_BUF_SIZE 1024 + +#ifdef XB3_ARM +#define ONBOARDING_FILE "/rdklogs/logs/OnBoardingLog_Arm.txt.0" +#elif XB3_ATOM +#define ONBOARDING_FILE "/rdklogs/logs/OnBoardingLog_Atom.txt.0" +#else +#define ONBOARDING_FILE "/rdklogs/logs/OnBoardingLog.txt.0" +#endif + +void __cimplog_generic(const char *module, const char *msg, ...) +{ + va_list arg_ptr; + char buf[MAX_BUF_SIZE]; + int nbytes; + struct sysinfo l_sSysInfo; + struct tm * l_sTimeInfo; + char l_cLocalTime[32] = {0}; + time_t l_sNowTime; + FILE *l_fOnBoardingLogFile = NULL; + + sysinfo(&l_sSysInfo); + time(&l_sNowTime); + l_sTimeInfo = localtime(&l_sNowTime); + + strftime(l_cLocalTime,32, "%y%m%d-%X",l_sTimeInfo); + va_start(arg_ptr, msg); + nbytes = vsnprintf(buf, MAX_BUF_SIZE, msg, arg_ptr); + va_end(arg_ptr); + + if( nbytes >= MAX_BUF_SIZE ) + { + buf[ MAX_BUF_SIZE - 1 ] = '\0'; + } + else + { + buf[nbytes] = '\0'; + } + + l_fOnBoardingLogFile = fopen(ONBOARDING_FILE, "a+"); + if (NULL != l_fOnBoardingLogFile) + { + if(module != NULL) + { + fprintf(l_fOnBoardingLogFile, "%s [%s] %s", l_cLocalTime, module, buf); + } + else + { + fprintf(l_fOnBoardingLogFile, "%s %s", l_cLocalTime, buf); + } + fclose(l_fOnBoardingLogFile); + } + else //fopen of on boarding file failed atleast write on the console + { + if(module != NULL) + { + printf("%s [%s] %s", l_cLocalTime, module, buf); + } + else + { + printf("%s %s", l_cLocalTime, buf); + } + } +} diff --git a/src/cimplog.c b/src/cimplog.c index 23178ea..fe2dd13 100644 --- a/src/cimplog.c +++ b/src/cimplog.c @@ -57,4 +57,3 @@ void __cimplog(const char *module, int level, const char *msg, ...) printf("[%09ld][%s][%s]: %s", ts.tv_sec, module, _level[0x3 & level], buf); } } - diff --git a/src/cimplog.h b/src/cimplog.h index 6f9bc1a..0e98bc5 100644 --- a/src/cimplog.h +++ b/src/cimplog.h @@ -27,6 +27,8 @@ #define cimplog_info(module, ...) __cimplog(module, LEVEL_INFO, __VA_ARGS__) #define cimplog_debug(module, ...) __cimplog(module, LEVEL_DEBUG, __VA_ARGS__) +#define onboarding_log(module, ...) __cimplog_generic(module, __VA_ARGS__) + /** * @brief handle log message based on log level * @@ -36,4 +38,11 @@ */ void __cimplog(const char *module, int level, const char *msg, ...); +/** +* @brief log message into an additional module other than the primary module of a component +* +* @param module string identifying library/module +* @param msg message +*/ +void __cimplog_generic(const char *module, const char *msg, ...); #endif diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..14207fd --- /dev/null +++ b/src/main.c @@ -0,0 +1,39 @@ +/** + * Copyright 2016 Comcast Cable Communications Management, LLC + * + * 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. + */ + +#include +#include +#include +#include "cimplog.h" + +#define MAX_BUF_SIZE 1024 + +int main( int argc, char **argv) +{ + char msg[MAX_BUF_SIZE]; + if(argc > 2 && (NULL != argv[1]) && (NULL != argv[2])) + { + sprintf(msg, "%s\n", argv[2]); + onboarding_log(argv[1], msg); + } + else if(argc > 1 && (NULL != argv[1])) + { + sprintf(msg, "%s\n", argv[1]); + onboarding_log(NULL, msg); + } + + return 0; +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 9911d6d..07c10d4 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,7 +20,7 @@ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-cov # simple #------------------------------------------------------------------------------- add_test(NAME Simple COMMAND simple) -add_executable(simple simple.c ../src/cimplog.c) +add_executable(simple simple.c ../src/cimplog.c ../src/cimplog-onboarding.c) set_property(TARGET simple PROPERTY C_STANDARD 99) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux") diff --git a/tests/onboardingTest.sh b/tests/onboardingTest.sh new file mode 100755 index 0000000..f567a74 --- /dev/null +++ b/tests/onboardingTest.sh @@ -0,0 +1,6 @@ +#!/bin/sh +ONBOARDING_LOG=../build/src/onboarding_log +$ONBOARDING_LOG "TEST" "Simple onboarding log with module" +$ONBOARDING_LOG "Simple onboarding log without module" +ARGS="arguments" +$ONBOARDING_LOG "Simple onboarding log with $ARGS" diff --git a/tests/simple.c b/tests/simple.c index 4657794..34e5ac1 100644 --- a/tests/simple.c +++ b/tests/simple.c @@ -31,10 +31,19 @@ void test_cimplog() cimplog_debug(mod3, "Sample debug\n"); } +void test_onBoarding() +{ + char mod2[] = "Module2"; + char *msg = "arguments"; + onboarding_log("Module1", "Sample OnBoarding Log\n"); + onboarding_log(mod2, "Sample OnBoarding Log with %s\n",msg); + onboarding_log(NULL, "Sample debug\n"); +} void add_suites( CU_pSuite *suite ) { *suite = CU_add_suite( "cimplog tests", NULL, NULL ); CU_add_test( *suite, "Test cimplog logging\n", test_cimplog ); + CU_add_test( *suite, "Test onboard logging\n", test_onBoarding ); } /*----------------------------------------------------------------------------*/ From 598117db173bd93dbb849589b8358373c5c7df8d Mon Sep 17 00:00:00 2001 From: Gayathri Date: Tue, 5 Feb 2019 14:47:37 +0530 Subject: [PATCH 2/3] Add OnBoarded check for onboard logging --- src/cimplog-onboarding.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/cimplog-onboarding.c b/src/cimplog-onboarding.c index 76167c3..d9ac5a5 100644 --- a/src/cimplog-onboarding.c +++ b/src/cimplog-onboarding.c @@ -18,8 +18,8 @@ #include #include #include +#include #include "cimplog.h" - #define MAX_BUF_SIZE 1024 #ifdef XB3_ARM @@ -30,6 +30,8 @@ #define ONBOARDING_FILE "/rdklogs/logs/OnBoardingLog.txt.0" #endif +#define DEVICE_ONBOARDED "/nvram/.device_onboarded" + void __cimplog_generic(const char *module, const char *msg, ...) { va_list arg_ptr; @@ -41,6 +43,11 @@ void __cimplog_generic(const char *module, const char *msg, ...) time_t l_sNowTime; FILE *l_fOnBoardingLogFile = NULL; + if (access(DEVICE_ONBOARDED, F_OK) != -1) + { + return; + } + sysinfo(&l_sSysInfo); time(&l_sNowTime); l_sTimeInfo = localtime(&l_sNowTime); From 4c65ab7ab7fe9e282716d6b74ef2a8e5649cf882 Mon Sep 17 00:00:00 2001 From: Gayathri Date: Wed, 13 Mar 2019 17:12:09 +0530 Subject: [PATCH 3/3] Added RDK_LOGGER check of onboard logging --- src/CMakeLists.txt | 4 +++- src/cimplog.c | 6 ++++++ tests/CMakeLists.txt | 2 +- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1075531..61b95c2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -18,7 +18,7 @@ file(GLOB HEADERS cimplog.h cimplog.h) if (RDK_LOGGER) set(SOURCES cimplog-rdk-logger.c cimplog-onboarding.c) else (RDK_LOGGER) -set(SOURCES cimplog.c cimplog-onboarding.c) +set(SOURCES cimplog.c) endif (RDK_LOGGER) add_library(${PROJ_CIMPL} STATIC ${HEADERS} ${SOURCES}) @@ -44,9 +44,11 @@ install (TARGETS ${PROJ_CIMPL} DESTINATION lib${LIB_SUFFIX}) install (TARGETS ${PROJ_CIMPL}.shared DESTINATION lib${LIB_SUFFIX}) install (FILES cimplog.h DESTINATION include/${PROJ_CIMPL}) +if (RDK_LOGGER) #------------------------------------------------------------------------------- # onboarding_log cli #------------------------------------------------------------------------------- set(BIN_SOURCES cimplog-onboarding.c main.c) add_executable(onboarding_log ${BIN_SOURCES} ${HEADERS}) install (TARGETS onboarding_log DESTINATION bin) +endif (RDK_LOGGER) diff --git a/src/cimplog.c b/src/cimplog.c index fe2dd13..4880c20 100644 --- a/src/cimplog.c +++ b/src/cimplog.c @@ -57,3 +57,9 @@ void __cimplog(const char *module, int level, const char *msg, ...) printf("[%09ld][%s][%s]: %s", ts.tv_sec, module, _level[0x3 & level], buf); } } + +void __cimplog_generic(const char *module, const char *msg, ...) +{ + (void) module; + (void) msg; +} diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 07c10d4..9911d6d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -20,7 +20,7 @@ set (CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -fprofile-arcs -ftest-cov # simple #------------------------------------------------------------------------------- add_test(NAME Simple COMMAND simple) -add_executable(simple simple.c ../src/cimplog.c ../src/cimplog-onboarding.c) +add_executable(simple simple.c ../src/cimplog.c) set_property(TARGET simple PROPERTY C_STANDARD 99) if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")