diff --git a/.github/workflows/L2-tests.yml b/.github/workflows/L2-tests.yml new file mode 100644 index 00000000..e13e4507 --- /dev/null +++ b/.github/workflows/L2-tests.yml @@ -0,0 +1,60 @@ +name: L2 Integration Tests for systemtimemgr + +on: + pull_request: + branches: [ develop , main ] + +env: + AUTOMATICS_UNAME: ${{ secrets.AUTOMATICS_UNAME }} + AUTOMATICS_PASSCODE: ${{ secrets.AUTOMATICS_PASSCODE }} + +jobs: + execute-l2-tests-on-pr: + name: Execute L2 Test in L2 Container Environment + runs-on: ubuntu-latest + + steps: + - name: Checkout systemtimemgr Code + uses: actions/checkout@v4 + + - name: Log in to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v1 + + - name: Pull Mock XConf, Native Platform, and Docker RDK CI Images + run: | + docker pull ghcr.io/rdkcentral/docker-device-mgt-service-test/mockxconf:latest + docker pull ghcr.io/rdkcentral/docker-device-mgt-service-test/native-platform:latest + docker pull ghcr.io/rdkcentral/docker-rdk-ci:latest + - name: Start mock-xconf service + run: | + docker run -d --name mockxconf -p 50050:50050 -p 50051:50051 -p 50052:50052 -p 50053:50053 -v ${{ github.workspace }}:/mnt/L2_CONTAINER_SHARED_VOLUME ghcr.io/rdkcentral/docker-device-mgt-service-test/mockxconf:latest + - name: Start l2-container service + run: | + docker run -d --name native-platform --link mockxconf -v ${{ github.workspace }}:/mnt/L2_CONTAINER_SHARED_VOLUME ghcr.io/rdkcentral/docker-device-mgt-service-test/native-platform:latest + - name: Build systemtimemgr and Run L2 inside Native Platform Container + run: | + docker exec -i native-platform /bin/bash -c "cd /mnt/L2_CONTAINER_SHARED_VOLUME/ && sh cov_build.sh && export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/x86_64-linux-gnu:/lib/aarch64-linux-gnu:/usr/local/lib && sh run_l2.sh" + - name: Copy L2 Test report to Host Runner + run: | + docker cp native-platform:/tmp/l2_test_report /tmp/L2_TEST_RESULTS + ls -lh /tmp/L2_TEST_RESULTS + - name: Setup Docker Buildx + uses: docker/setup-buildx-action@v1 + with: + install: true + + - name: Run RDK CI Container + run: | + docker run -d --name ci-container -e AUTOMATICS_UNAME=${{ secrets.AUTOMATICS_UNAME }} -e AUTOMATICS_PASSCODE=${{ secrets.AUTOMATICS_PASSCODE }} -v /tmp/L2_TEST_RESULTS:/tmp/L2_TEST_RESULTS ghcr.io/rdkcentral/docker-rdk-ci:latest tail -f /dev/null + - name: Upload Results to Automatics + if: github.repository_owner == 'rdkcentral' + run: | + docker cp /tmp/L2_TEST_RESULTS ci-container:/tmp/L2_TEST_RESULTS + docker exec -i ci-container bash -c "echo 'Contents in workspace directory' && ls -l && echo '===============================' && echo 'Contents in /tmp/L2_TEST_RESULTS' && ls -l /tmp/L2_TEST_RESULTS && echo '===============================' && git config --global --add safe.directory /mnt/L2_CONTAINER_SHARED_VOLUME && gtest-json-result-push.py /tmp/L2_TEST_RESULTS https://rdkeorchestrationservice.apps.cloud.comcast.net/rdke_orchestration_api/push_unit_test_results /mnt/L2_CONTAINER_SHARED_VOLUME" diff --git a/cov_build.sh b/cov_build.sh index 6b9cd5da..1cecb74d 100644 --- a/cov_build.sh +++ b/cov_build.sh @@ -34,7 +34,7 @@ export top_srcdir=`pwd` export top_builddir=`pwd` autoreconf --install -export CXXFLAGS="-I./interface/ -I./systimerfactory/" +export CXXFLAGS="-I./interface/ -I./systimerfactory/ -DIARM_SUPPORT_DISABLED" export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH export LDFLAGS="-L/usr/local/lib -lpthread -lsystimerfactory -lrdkloggers -lsecure_wrapper" diff --git a/run_l2.sh b/run_l2.sh new file mode 100644 index 00000000..db99c70b --- /dev/null +++ b/run_l2.sh @@ -0,0 +1,57 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## + +RESULT_DIR="/tmp/l2_test_report" +mkdir -p "$RESULT_DIR" + +apt-get update && apt-get install -y libjsonrpccpp-dev + +touch /usr/local/bin/journalctl +chmod -R 777 /usr/local/bin/journalctl +ln -s /usr/local/bin/journalctl /usr/bin/journalctl + +echo "timesrc ntp /ntp" > /etc/systimemgr.conf +echo "timesrc dtt /dtt" >> /etc/systimemgr.conf +echo "timesync rdkdefault /clock_time" >> /etc/systimemgr.conf + +mkdir /tmp/systimemgr +touch ntp + +rm -rf /opt/logs/systimemgr.log* + +#/usr/local/bin/sysTimeMgr & + +#ps -eaf +#ls -l /opt/logs/ + +#cat /opt/logs/systimemgr.log.0 +#cat /etc/debug.ini +#sleep 1m + +# Run L2 Test cases +pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_single_instance.json test/functional-tests/tests/test_systimemgr_single_instance.py + +ps -eaf +ls -l /opt/logs +cat /opt/logs/systimemgr.log.0 +pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_initialisation.json test/functional-tests/tests/test_systimemgr_initialisation.py +pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_get_time.json test/functional-tests/tests/test_systimemgr_get_time.py +pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_check_file.json test/functional-tests/tests/test_systimemgr_check_file.py +pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_time_quality.json test/functional-tests/tests/test_systimemgr_time_quality.py +pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_bootup_flow.json test/functional-tests/tests/test_systimemgr_bootup_flow.py diff --git a/systimemgr.cpp b/systimemgr.cpp index aca60db3..8c9edb27 100644 --- a/systimemgr.cpp +++ b/systimemgr.cpp @@ -103,7 +103,7 @@ void SysTimeMgr::initialize() //m_timerSrc.push_back(createTimeSrc("regular","/tmp/clock.txt")); //m_timerSync.push_back(createTimeSync("test","/tmp/clock1.txt")); - +#if !defined(IARM_SUPPORT_DISABLED) m_publish = createPublish("iarm",IARM_BUS_SYSTIME_MGR_NAME); RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:createSubscriber IARM_BUS_SYSTIME_MGR_NAME TIMER_STATUS_MSG Invoke\n",__FUNCTION__,__LINE__); m_tmrsubscriber = createSubscriber("iarm",IARM_BUS_SYSTIME_MGR_NAME,TIMER_STATUS_MSG); @@ -113,7 +113,18 @@ void SysTimeMgr::initialize() m_tmrsubscriber->subscribe(TIMER_STATUS_MSG,SysTimeMgr::getTimeStatus); RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:IpowerControllerSubscriber or IarmPowerSubscriber Invoke \n",__FUNCTION__,__LINE__); m_subscriber->subscribe(POWER_CHANGE_MSG,SysTimeMgr::powerhandler); - +#else + m_publish = createPublish("test",IARM_BUS_SYSTIME_MGR_NAME); + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:createSubscriber IARM_BUS_SYSTIME_MGR_NAME TIMER_STATUS_MSG Invoke\n",__FUNCTION__,__LINE__); + m_tmrsubscriber = createSubscriber("test",IARM_BUS_SYSTIME_MGR_NAME,TIMER_STATUS_MSG); + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:createSubscriber IARM_BUS_SYSTIME_MGR_NAME POWER_CHANGE_MSG Invoke\n",__FUNCTION__,__LINE__); + m_subscriber = createSubscriber("test",IARM_BUS_SYSTIME_MGR_NAME,POWER_CHANGE_MSG); + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:IarmTimerStatusSubscriber Invoke \n",__FUNCTION__,__LINE__); + m_tmrsubscriber->subscribe(TIMER_STATUS_MSG,SysTimeMgr::getTimeStatus); + RDK_LOG(RDK_LOG_INFO,LOG_SYSTIME,"[%s:%d]:IpowerControllerSubscriber or IarmPowerSubscriber Invoke \n",__FUNCTION__,__LINE__); + m_subscriber->subscribe(POWER_CHANGE_MSG,SysTimeMgr::powerhandler); +#endif + //Initialize Path Event Map m_pathEventMap.insert(pair("ntp",eSYSMGR_EVENT_NTP_AVAILABLE)); //Keeping the NTP available event for stt as well. Source is different but no need to have separate event. diff --git a/test/functional-tests/features/systimemgr_bootupflow.feature b/test/functional-tests/features/systimemgr_bootupflow.feature new file mode 100644 index 00000000..dbf818fa --- /dev/null +++ b/test/functional-tests/features/systimemgr_bootupflow.feature @@ -0,0 +1,57 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## + +Feature: Ensures SystemTimeManager Bootup Flow + + Scenario: Ensures SystemTimeManager Initialization + Given the SystemTimeManager is not already running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be started + + Scenario: Check if systemTimeManager is Running + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be running + + Scenario: Verify SystemTimeManager Log file exists + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager LogFile should get generated + + Scenario: Verify SystemTimeManager Instance is created + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager Instance should get created + + Scenario: Verify SystemTimeManager Initializes timeSrc and timeSync + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should initializes TimeSrc[NTP,DTT] and TimeSync[clocktime] + + Scenario: Verify SystemTimeManager returns the last known good time + Given the SystemTimeManager is running + When the SystemTimeManager registers for IARM events + Then the SystemTimeManager should return the last known good time + And the log file should contain "Returning Last Known Good Time" + + Scenario: Verify SystemTimeManager Sends info about time Quality + Given the SystemTimeManager is running + When the SystemTimeManager returns the last known good time + Then the SystemTimeManager should Send broadcast msg about the time quality + And the log file should contain "Info:" diff --git a/test/functional-tests/features/systimemgr_check_file.feature b/test/functional-tests/features/systimemgr_check_file.feature new file mode 100644 index 00000000..22bcdd0c --- /dev/null +++ b/test/functional-tests/features/systimemgr_check_file.feature @@ -0,0 +1,40 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## + +Feature: Ensures SystemTimeManager generates /opt/secure/clock.txt File + + Scenario: Ensures SystemTimeManager Initialization + Given the SystemTimeManager is not already running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be started + + Scenario: Check if systemTimeManager is Running + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be running + + Scenario: Verify SystemTimeManager Log file exists + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager LogFile should get generated + + Scenario: Verify SystemTimeManager generates clock.txt File + Given the SystemTimeManager is running + When the SystemTimeManager returns the last known time + Then the SystemTimeManager should update the clock.txt File diff --git a/test/functional-tests/features/systimemgr_get_time.feature b/test/functional-tests/features/systimemgr_get_time.feature new file mode 100644 index 00000000..777cebb7 --- /dev/null +++ b/test/functional-tests/features/systimemgr_get_time.feature @@ -0,0 +1,40 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## + +Feature: Ensures SystemTimeManager Returns the Last known Good time + + Scenario: Ensures SystemTimeManager Initialization + Given the SystemTimeManager is not already running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be started + + Scenario: Check if systemTimeManager is Running + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be running + + Scenario: Verify SystemTimeManager Log file exists + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager LogFile should get generated + + Scenario: Verify SystemTimeManager Captured Last known Good time + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should update the lastknown Good time diff --git a/test/functional-tests/features/systimemgr_initialisation.feature b/test/functional-tests/features/systimemgr_initialisation.feature new file mode 100644 index 00000000..ed50c2c9 --- /dev/null +++ b/test/functional-tests/features/systimemgr_initialisation.feature @@ -0,0 +1,40 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## + +Feature: Ensures SystemTimeManager Initialization + + Scenario: Ensures SystemTimeManager Initialization + Given the SystemTimeManager is not already running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be started + + Scenario: Check if systemTimeManager is Running + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be running + + Scenario: Verify SystemTimeManager Log file exists + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager LogFile should get generated + + Scenario: Verify SystemTimeManager TimeSRC and TimeSYNC are Initialized + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the TimeSources and TimeSyncs should be Initialized diff --git a/test/functional-tests/features/systimemgr_single_instance.feature b/test/functional-tests/features/systimemgr_single_instance.feature new file mode 100644 index 00000000..11f55559 --- /dev/null +++ b/test/functional-tests/features/systimemgr_single_instance.feature @@ -0,0 +1,27 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## + +Feature: SystemTimeManager runs only one instance + + Scenario: SystemTimeManager exits if another instance is invoked + Given the SystemTimeManager is not already running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be started + And when the SystemTimeManager is attempted to be started again + Then the SystemTimeManager should not start another instance diff --git a/test/functional-tests/features/systimemgr_time_quality.feature b/test/functional-tests/features/systimemgr_time_quality.feature new file mode 100644 index 00000000..c6cad21f --- /dev/null +++ b/test/functional-tests/features/systimemgr_time_quality.feature @@ -0,0 +1,45 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## + +Feature: Ensures SystemTimeManager Broadcasting Time Quality Messages + + Scenario: Ensures SystemTimeManager Initialization + Given the SystemTimeManager is not already running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be started + + Scenario: Check if systemTimeManager is Running + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should be running + + Scenario: Verify SystemTimeManager Log file exists + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager LogFile should get generated + + Scenario: Verify SystemTimeManager should sent time quality Poor when NTP failed + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should sent time quality Poor Msg Initially since NTP Failed + + Scenario: Verify SystemTimeManager should sent time quality Good when NTP is synced + Given the SystemTimeManager is running + When the SystemTimeManager binary is invoked + Then the SystemTimeManager should sent time quality Good When NTP is synced diff --git a/test/functional-tests/tests/helper_functions.py b/test/functional-tests/tests/helper_functions.py new file mode 100644 index 00000000..db05f78f --- /dev/null +++ b/test/functional-tests/tests/helper_functions.py @@ -0,0 +1,77 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## + +import subprocess +import requests +import os +import time +import re +import signal +import shutil +from time import sleep + +LOG_FILE = "/opt/logs/systimemgr.log.0" + +def remove_logfile(): + try: + if os.path.exists(LOG_FILE): + os.remove(LOG_FILE) + print(f"Log file {LOG_FILE} removed.") + else: + print(f"Log file {LOG_FILE} does not exist.") + except Exception as e: + print(f"Could not remove log file {LOG_FILE}: {e}") + +def kill_sysTimeMgr(signal: int=9): + print(f"Received Signal to kill systimemgr {signal} with pid {get_pid('sysTimeMgr')}") + resp = subprocess.run(f"kill -{signal} {get_pid('sysTimeMgr')}", shell=True, capture_output=True) + print(resp.stdout.decode('utf-8')) + print(resp.stderr.decode('utf-8')) + return "" + +def grep_sysTimeMgrlogs(search: str): + search_result = "" + search_pattern = re.compile(re.escape(search), re.IGNORECASE) + try: + with open(LOG_FILE, 'r', encoding='utf-8', errors='ignore') as file: + for line_number, line in enumerate(file, start=1): + if search_pattern.search(line): + search_result = search_result + " \n" + line + except Exception as e: + print(f"Could not read file {LOG_FILE}: {e}") + return search_result + +def get_pid(name: str): + return subprocess.run(f"pidof {name}", shell=True, capture_output=True).stdout.decode('utf-8').strip() + +def run_shell_silent(command): + subprocess.run(command, shell=True, capture_output=False, text=False) + return + +def run_shell_command(command): + result = subprocess.run(command, shell=True, capture_output=True, text=True) + return result.stdout.strip() + +def is_systemtimemgr_running(): + command_to_check = "ps aux | grep sysTimeMgr | grep -v grep" + result = run_shell_command(command_to_check) + return result != "" + +def check_file_exists(file_path): + return os.path.isfile(file_path) diff --git a/test/functional-tests/tests/test_systimemgr_bootup_flow.py b/test/functional-tests/tests/test_systimemgr_bootup_flow.py new file mode 100644 index 00000000..d8cf4f9f --- /dev/null +++ b/test/functional-tests/tests/test_systimemgr_bootup_flow.py @@ -0,0 +1,51 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## +from time import sleep +from helper_functions import * + +def test_is_systimemgr_running(): + command_to_check = "pidof sysTimeMgr" + result = run_shell_command(command_to_check) + assert result != "", "sysTimeMgr process did not start" + +def test_check_systimemgr_log_file(): + log_file_path = LOG_FILE + assert check_file_exists(log_file_path), f"Log File '{log_file_path}' does not exist." + +def test_bootup_flow(): + CREATE_INSTANCE_MSG = "Created New Instance" + assert CREATE_INSTANCE_MSG in grep_sysTimeMgrlogs(CREATE_INSTANCE_MSG) + + CHECK_INITIALIZATION_MSG_NTP = "Initializing Src and Syncs. Category = timesrc, Type = ntp, Args = /ntp" + assert CHECK_INITIALIZATION_MSG_NTP in grep_sysTimeMgrlogs(CHECK_INITIALIZATION_MSG_NTP) + + CHECK_INITIALIZATION_MSG_DTT = "Initializing Src and Syncs. Category = timesrc, Type = dtt, Args = /dtt" + assert CHECK_INITIALIZATION_MSG_DTT in grep_sysTimeMgrlogs(CHECK_INITIALIZATION_MSG_DTT) + + CHECK_INITIALIZATION_MSG_RDKDEFAULT = "Initializing Src and Syncs. Category = timesync, Type = rdkdefault, Args = /clock_time" + assert CHECK_INITIALIZATION_MSG_RDKDEFAULT in grep_sysTimeMgrlogs(CHECK_INITIALIZATION_MSG_RDKDEFAULT) + + CHECK_LAST_GOOD_TIME_MSG = "Returning Last Known Good Time, time =" + assert CHECK_LAST_GOOD_TIME_MSG in grep_sysTimeMgrlogs(CHECK_LAST_GOOD_TIME_MSG) + + CHECK_TIME_QUALITY_POOR_MSG = "Info: MsgType = 0, Quality = 0, Message = Poor" + assert CHECK_TIME_QUALITY_POOR_MSG in grep_sysTimeMgrlogs(CHECK_TIME_QUALITY_POOR_MSG) + + CHECK_TIME_QUALITY_GOOD_MSG = "Info: MsgType = 2, Quality = 1, Message = Good" + assert CHECK_TIME_QUALITY_GOOD_MSG in grep_sysTimeMgrlogs(CHECK_TIME_QUALITY_GOOD_MSG) diff --git a/test/functional-tests/tests/test_systimemgr_check_file.py b/test/functional-tests/tests/test_systimemgr_check_file.py new file mode 100644 index 00000000..daec474c --- /dev/null +++ b/test/functional-tests/tests/test_systimemgr_check_file.py @@ -0,0 +1,37 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## +from time import sleep +from helper_functions import * + +def test_is_systimemgr_running(): + command_to_check = "pidof sysTimeMgr" + result = run_shell_command(command_to_check) + assert result != "", "sysTimeMgr process did not start" + +def test_check_systimemgr_log_file(): + log_file_path = LOG_FILE + assert check_file_exists(log_file_path), f"Log File '{log_file_path}' does not exist." + +def test_check_clock_file_exists(): + clock_file = "/opt/secure/clock.txt" + assert check_file_exists(clock_file), f"clock.txt File '{clock_file}' does not exist." + +def test_check_file_updated(): + UPDATE_FILE = "Updating Time in file" + assert UPDATE_FILE in grep_sysTimeMgrlogs(UPDATE_FILE) diff --git a/test/functional-tests/tests/test_systimemgr_get_time.py b/test/functional-tests/tests/test_systimemgr_get_time.py new file mode 100644 index 00000000..e608e2f1 --- /dev/null +++ b/test/functional-tests/tests/test_systimemgr_get_time.py @@ -0,0 +1,54 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## +from time import sleep +from helper_functions import * + +def test_is_systimemgr_running(): + command_to_check = "pidof sysTimeMgr" + result = run_shell_command(command_to_check) + assert result != "", "sysTimeMgr process did not start" + +def test_check_systimemgr_log_file(): + log_file_path = LOG_FILE + assert check_file_exists(log_file_path), f"Log File '{log_file_path}' does not exist." + +def test_last_known_time(): + GET_TIME = "Returning Last Known Good Time" + assert GET_TIME in grep_sysTimeMgrlogs(GET_TIME) + +def parse_log_time(pattern, clock_file): + with open(LOG_FILE, "r") as log_file: + for line in log_file: + match = re.search(pattern, line) + if match: + timestamp = match.group(1).strip() + with open(clock_file, 'w') as out_file: + out_file.write(timestamp) + return timestamp + return None + +def test_parse_log_time(): + clock_file = '/opt/secure/clock_test.txt' + + pattern = r"Returning Last Known Good Time, *time\s* = \s*(.+)" + time_str = parse_log_time(pattern, clock_file) + + assert time_str != "" + + assert check_file_exists(clock_file), f"clock Test file '{clock_file}' not generated" diff --git a/test/functional-tests/tests/test_systimemgr_initialisation.py b/test/functional-tests/tests/test_systimemgr_initialisation.py new file mode 100644 index 00000000..0c51bc3d --- /dev/null +++ b/test/functional-tests/tests/test_systimemgr_initialisation.py @@ -0,0 +1,33 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## +from time import sleep +from helper_functions import * + +def test_is_systimemgr_running(): + command_to_check = "pidof sysTimeMgr" + result = run_shell_command(command_to_check) + assert result != "", "sysTimeMgr process did not start" + +def test_check_systimemgr_log_file(): + log_file_path = LOG_FILE + assert check_file_exists(log_file_path), f"Log File '{log_file_path}' does not exist." + +def test_Initialization(): + INITIALIZATION_MSG = "Initializing Src and Syncs" + assert INITIALIZATION_MSG in grep_sysTimeMgrlogs(INITIALIZATION_MSG) diff --git a/test/functional-tests/tests/test_systimemgr_single_instance.py b/test/functional-tests/tests/test_systimemgr_single_instance.py new file mode 100644 index 00000000..da3106d8 --- /dev/null +++ b/test/functional-tests/tests/test_systimemgr_single_instance.py @@ -0,0 +1,37 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## + +from time import sleep +from helper_functions import * + +def test_check_and_start_sysTimeMgr(): + kill_sysTimeMgr() + print("Starting sysTimeMgr process") + command_to_start = "nohup /usr/local/bin/sysTimeMgr > /dev/null 2>&1 &" + run_shell_silent(command_to_start) + command_to_get_pid = "pidof sysTimeMgr" + pid = run_shell_command(command_to_get_pid) + assert pid != "", "sysTimeMgr process did not start" + +def test_systemtimemgr_instance_is_started(): + command_to_get_pid = "pidof sysTimeMgr" + pid1 = run_shell_command(command_to_get_pid) + + if is_systemtimemgr_running(): + print("systemtimemgr process is already running") diff --git a/test/functional-tests/tests/test_systimemgr_time_quality.py b/test/functional-tests/tests/test_systimemgr_time_quality.py new file mode 100644 index 00000000..45df6385 --- /dev/null +++ b/test/functional-tests/tests/test_systimemgr_time_quality.py @@ -0,0 +1,36 @@ +########################################################################## +# If not stated otherwise in this file or this component's LICENSE +# file the following copyright and licenses apply: +# +# Copyright 2018 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. +########################################################################## +from time import sleep +from helper_functions import * + +def test_is_systimemgr_running(): + command_to_check = "pidof sysTimeMgr" + result = run_shell_command(command_to_check) + assert result != "", "sysTimeMgr process did not start" + +def test_check_systimemgr_log_file(): + log_file_path = LOG_FILE + assert check_file_exists(log_file_path), f"Log File '{log_file_path}' does not exist." + +def test_time_quality(): + TIMEQUALITY_MSG_POOR = "Info: MsgType = 0, Quality = 0, Message = Poor" + assert TIMEQUALITY_MSG_POOR in grep_sysTimeMgrlogs(TIMEQUALITY_MSG_POOR) + + TIMEQUALITY_MSG_GOOD = "Info: MsgType = 2, Quality = 1, Message = Good" + assert TIMEQUALITY_MSG_GOOD in grep_sysTimeMgrlogs(TIMEQUALITY_MSG_GOOD)