Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
66 changes: 66 additions & 0 deletions .github/workflows/L2-tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: L2 Integration Tests for systemtimemgr

on:
pull_request:
branches: [ develop, feature/RDK-48831-sysTimeMgr-L2 ]

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"
1 change: 1 addition & 0 deletions cov_build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH
export LDFLAGS="-L/usr/local/lib -lpthread -lsystimerfactory -lrdkloggers -lsecure_wrapper"

./configure --prefix=${INSTALL_DIR} && make && make install
ls -l /usr/local/bin
38 changes: 38 additions & 0 deletions run_l2.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/sh
####################################################################################
# If not stated otherwise in this file or this component's Licenses.txt file the
# following copyright and licenses apply:
#
# Copyright 2024 RDK Management
#
# Licensed under the Apache License, Version 2.0 (the "License");

Check failure on line 8 in run_l2.sh

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'run_l2.sh' (Match: tink-crypto/tink/1.0.0, 11 lines, url: https://github.com/tink-crypto/tink/archive/v1.0.0.tar.gz, file: kokoro/macos_external/presubmit.sh)
# 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

rm -rf /opt/logs/systimemgr.log*

# Run L2 Test cases
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_single_instance.json test/functional-tests/tests/test_systemtimemgr_single_instance.py
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_initialisation.json test/functional-tests/tests/test_systemtimemgr_initialisation.py
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_set_time.json test/functional-tests/tests/test_systemtimemgr_set_time.py
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_get_time.json test/functional-tests/tests/test_systemtimemgr_get_time.py
pytest --json-report --json-report-summary --json-report-file $RESULT_DIR/systimemgr_check_logs.json test/functional-tests/tests/test_systemtimemgr_check_logs.py

Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
####################################################################################
# If not stated otherwise in this file or this component's Licenses.txt file the
# following copyright and licenses apply:
#
# Copyright 2024 RDK Management
#
# Licensed under the Apache License, Version 2.0 (the "License");

Check failure on line 7 in test/functional-tests/features/systemtimemgr_single_instance.feature

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'test/functional-tests/features/systemtimemgr_single_instance.feature' (Match: tink-crypto/tink/1.0.0, 11 lines, url: https://github.com/tink-crypto/tink/archive/v1.0.0.tar.gz, file: kokoro/macos_external/presubmit.sh)
# 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
74 changes: 74 additions & 0 deletions test/functional-tests/tests/helper_functions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
##########################################################################

Check failure on line 1 in test/functional-tests/tests/helper_functions.py

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'test/functional-tests/tests/helper_functions.py' (Match: lgirdk/ccsp-wifi-agent/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb, 17 lines, url: https://github.com/lgirdk/ccsp-wifi-agent/archive/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb.tar.gz, file: scripts/mesh_status.sh)
# 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"

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 != ""
37 changes: 37 additions & 0 deletions test/functional-tests/tests/test_systemtimemgr_check_logs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
##########################################################################

Check failure on line 1 in test/functional-tests/tests/test_systemtimemgr_check_logs.py

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'test/functional-tests/tests/test_systemtimemgr_check_logs.py' (Match: lgirdk/ccsp-wifi-agent/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb, 17 lines, url: https://github.com/lgirdk/ccsp-wifi-agent/archive/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb.tar.gz, file: scripts/mesh_status.sh)
# 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 helper_functions import *

def test_check_and_start_systemtimemgr():
kill_sysTimeMgr()
remove_logfile()
print("Starting systemtimemgr 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"


sleep(5)

QUERY_MSG = "Quality ="
assert QUERY_MSG in grep_sysTimeMgrlogs(QUERY_MSG)


33 changes: 33 additions & 0 deletions test/functional-tests/tests/test_systemtimemgr_get_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@

##########################################################################

Check failure on line 2 in test/functional-tests/tests/test_systemtimemgr_get_time.py

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'test/functional-tests/tests/test_systemtimemgr_get_time.py' (Match: lgirdk/ccsp-wifi-agent/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb, 17 lines, url: https://github.com/lgirdk/ccsp-wifi-agent/archive/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb.tar.gz, file: scripts/mesh_status.sh)
# 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");

Check failure on line 8 in test/functional-tests/tests/test_systemtimemgr_get_time.py

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'test/functional-tests/tests/test_systemtimemgr_get_time.py' (Match: thu-coai/DA-Transformer/2d068411ae1ba3717be33e45a6e5281c78c8d48c, 13 lines, url: https://github.com/thu-coai/DA-Transformer/archive/2d068411ae1ba3717be33e45a6e5281c78c8d48c.tar.gz, file: fs_plugins/custom_ops/dag_loss.py)
# 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 os
from datetime import datetime

CLOCK_FILE = "/opt/secure/clock.txt"


def get_last_known_time():
    if os.path.exists(CLOCK_FILE):
        with open(CLOCK_FILE, 'r') as file:
            last_time = file.read().strip()
            return last_time
    else:
        return None
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
##########################################################################

Check failure on line 1 in test/functional-tests/tests/test_systemtimemgr_initialisation.py

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'test/functional-tests/tests/test_systemtimemgr_initialisation.py' (Match: lgirdk/ccsp-wifi-agent/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb, 17 lines, url: https://github.com/lgirdk/ccsp-wifi-agent/archive/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb.tar.gz, file: scripts/mesh_status.sh)
# 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.
##########################################################################

def is_systimemgr_running():
command_to_check = "ps aux | grep sysTimeMgr | grep -v grep"
result = run_shell_command(command_to_check)
return result != ""
30 changes: 30 additions & 0 deletions test/functional-tests/tests/test_systemtimemgr_set_time.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@

##########################################################################

Check failure on line 2 in test/functional-tests/tests/test_systemtimemgr_set_time.py

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'test/functional-tests/tests/test_systemtimemgr_set_time.py' (Match: lgirdk/ccsp-wifi-agent/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb, 17 lines, url: https://github.com/lgirdk/ccsp-wifi-agent/archive/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb.tar.gz, file: scripts/mesh_status.sh)
# 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");

Check failure on line 8 in test/functional-tests/tests/test_systemtimemgr_set_time.py

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'test/functional-tests/tests/test_systemtimemgr_set_time.py' (Match: thu-coai/DA-Transformer/2d068411ae1ba3717be33e45a6e5281c78c8d48c, 13 lines, url: https://github.com/thu-coai/DA-Transformer/archive/2d068411ae1ba3717be33e45a6e5281c78c8d48c.tar.gz, file: fs_plugins/custom_ops/dag_loss.py)
# 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 os
from datetime import datetime

CLOCK_FILE = "/opt/secure/clock.txt"

def write_time():
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
with open(CLOCK_FILE, 'w') as file:
file.write(current_time)

Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
##########################################################################

Check failure on line 1 in test/functional-tests/tests/test_systemtimemgr_single_instance.py

View workflow job for this annotation

GitHub Actions / call-fossid-workflow / Fossid Annotate PR

FossID License Issue Detected

Source code with 'Apache-2.0' license found in local file 'test/functional-tests/tests/test_systemtimemgr_single_instance.py' (Match: lgirdk/ccsp-wifi-agent/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb, 17 lines, url: https://github.com/lgirdk/ccsp-wifi-agent/archive/cf04a1c4000061c1f52d9a6dbd9f44ac1f612edb.tar.gz, file: scripts/mesh_status.sh)
# 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_systemtimemgr_is_starting():
kill_sysTimeMgr()
remove_logfile()
print("Starting systemtimemgr 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_second_systemtimemgr_instance_is_not_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")
else:
command_to_start = "nohup /usr/local/bin/sysTimeMgr > /dev/null 2>&1 &"
run_shell_silent(command_to_start)
sleep(2)

pid2 = run_shell_command(command_to_get_pid)
assert pid1 == pid2, "A second instance of sysTimeMgr was started."

def test_tear_down():
command_to_stop = "kill -9 `pidof sysTimeMgr`"
run_shell_command(command_to_stop)
command_to_get_pid = "pidof sysTimeMgr"
remove_logfile()
pid = run_shell_command(command_to_get_pid)
assert pid == ""
Loading