From 2d6532da429340a24b63bc2c8ec52fa81f271ae4 Mon Sep 17 00:00:00 2001 From: Bibhuprasad Singh Date: Fri, 10 Jan 2025 08:52:37 +0000 Subject: [PATCH] Adding script to execute sonic-framework/tests --- .../tests/test_scripts/README.md | 36 +++++++ .../tests/test_scripts/create_virtualenv.sh | 17 ++++ .../tests/test_scripts/database_config.json | 99 +++++++++++++++++++ .../tests/test_scripts/tests_script.sh | 88 +++++++++++++++++ 4 files changed, 240 insertions(+) create mode 100644 src/sonic-framework/tests/test_scripts/README.md create mode 100644 src/sonic-framework/tests/test_scripts/create_virtualenv.sh create mode 100644 src/sonic-framework/tests/test_scripts/database_config.json create mode 100644 src/sonic-framework/tests/test_scripts/tests_script.sh diff --git a/src/sonic-framework/tests/test_scripts/README.md b/src/sonic-framework/tests/test_scripts/README.md new file mode 100644 index 000000000000..356f35f70d2a --- /dev/null +++ b/src/sonic-framework/tests/test_scripts/README.md @@ -0,0 +1,36 @@ +# Script tests_scrip.sh can be used to execute sonic-framework/tests UT test cases. + + +# Steps to run tests_scrip.sh + + +# 1.Build the workspace, incase the workspace is not built using following commands. + + cd /sonic-buildiamge + + make init + + NOJESSIE=1 NOSTRETCH=1 NOBUSTER=1 NOBULLSEYE=1 SONIC_BUILD_JOBS=12 make configure PLATFORM=vs + + NOJESSIE=1 NOSTRETCH=1 NOBUSTER=1 NOBULLSEYE=1 SONIC_BUILD_JOBS=12 make target/sonic-vs.img.gz + + +# 2. Create a virtual environment using following steps. + + Run create_virtualenv.sh script to create a virtual environment. + + sh create_virtualenv.sh ./ + + +# 3. Copy database_config.json to /tmp directory. + + cp sonic-buildimage/src/sonic-framework/tests/test_scripts/database_config.json /tmp + + +# 4. Run test_script.sh inside the virtual envirment to execute the UT test cases + + sh test_script.sh ./ + + + + diff --git a/src/sonic-framework/tests/test_scripts/create_virtualenv.sh b/src/sonic-framework/tests/test_scripts/create_virtualenv.sh new file mode 100644 index 000000000000..c534ece44ac2 --- /dev/null +++ b/src/sonic-framework/tests/test_scripts/create_virtualenv.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +# read virtual environment name +read -p "Enter the name of the virtual environment: " venv + +# Install virtual env +sudo apt-get install python3-pip + +sudo apt-get install virtualenv + +# Create a virtual environment +virtualenv $venv +echo +echo +echo "To activate the virtualenv, run:" + +echo " source $venv/bin/activate" diff --git a/src/sonic-framework/tests/test_scripts/database_config.json b/src/sonic-framework/tests/test_scripts/database_config.json new file mode 100644 index 000000000000..886fc5220312 --- /dev/null +++ b/src/sonic-framework/tests/test_scripts/database_config.json @@ -0,0 +1,99 @@ +{ + "INSTANCES": { + "redis":{ + "hostname" : "127.0.0.1", + "port" : 6379, + "unix_socket_path" : "/var/run/redis/redis.sock" + }, + "redis_chassis":{ + "hostname" : "redis_chassis.server", + "port" : 6380, + "unix_socket_path" : "/var/run/redis/redis_chassis.sock" + } + }, + "DATABASES" : { + "APPL_DB" : { + "id" : 0, + "separator": ":", + "instance" : "redis" + }, + "ASIC_DB" : { + "id" : 1, + "separator": ":", + "instance" : "redis" + }, + "COUNTERS_DB" : { + "id" : 2, + "separator": ":", + "instance" : "redis" + }, + "LOGLEVEL_DB" : { + "id" : 3, + "separator": ":", + "instance" : "redis" + }, + "CONFIG_DB" : { + "id" : 4, + "separator": "|", + "instance" : "redis" + }, + "PFC_WD_DB" : { + "id" : 5, + "separator": ":", + "instance" : "redis" + }, + "FLEX_COUNTER_DB" : { + "id" : 5, + "separator": ":", + "instance" : "redis" + }, + "STATE_DB" : { + "id" : 6, + "separator": "|", + "instance" : "redis" + }, + "SNMP_OVERLAY_DB" : { + "id" : 7, + "separator": "|", + "instance" : "redis" + }, + "RESTAPI_DB" : { + "id" : 8, + "separator": "|", + "instance" : "redis" + }, + "GB_ASIC_DB" : { + "id" : 9, + "separator": ":", + "instance" : "redis" + }, + "GB_COUNTERS_DB" : { + "id" : 10, + "separator": ":", + "instance" : "redis" + }, + "GB_FLEX_COUNTER_DB" : { + "id" : 11, + "separator": ":", + "instance" : "redis" + }, + "CHASSIS_APP_DB" : { + "id" : 12, + "separator": "|", + "instance" : "redis_chassis" + }, + "CHASSIS_STATE_DB" : { + "id" : 13, + "separator": "|", + "instance" : "redis_chassis" + }, + "APPL_STATE_DB" : { + "id" : 14, + "separator": ":", + "instance" : "redis" + } + }, + "VERSION" : "1.0" +} + + diff --git a/src/sonic-framework/tests/test_scripts/tests_script.sh b/src/sonic-framework/tests/test_scripts/tests_script.sh new file mode 100644 index 000000000000..ae956c61cc38 --- /dev/null +++ b/src/sonic-framework/tests/test_scripts/tests_script.sh @@ -0,0 +1,88 @@ +#!/bin/bash + +# execute all the steps inside virtual Environment. +# From /sonic-buildimage path. +# +# Creating a new folder inside /tmp and +# Downloading libhiredis packages to /tmp/new path. +mkdir /tmp/new +cd /tmp/new +curl -O https://ftp.debian.org/debian/pool/main/h/hiredis/libhiredis0.14_0.14.1-3_amd64.deb +curl -O https://ftp.debian.org/debian/pool/main/h/hiredis/libhiredis-dev_0.14.1-3_amd64.deb + +# Install all the dependencies/pkgs +# which are present in target/debs/bookworm path. +cd - +cd ../../../../target/debs/bookworm + +sudo dpkg -r libhiredis-dev +sudo apt remove libhiredis0.14 +sudo dpkg -r libhiredis1.1.0 +sudo dpkg -i /tmp/new/libhiredis0.14_0.14.1-3_amd64.deb +sudo dpkg -i /tmp/new/libhiredis-dev_0.14.1-3_amd64.deb +sudo dpkg -i libnl-3-200_*.deb +sudo dpkg -i libnl-3-dev_*.deb +sudo dpkg -i libnl-genl-3-200_*.deb +sudo dpkg -i libnl-genl-3-dev_*.deb +sudo dpkg -i libnl-route-3-200_*.deb +sudo dpkg -i libnl-route-3-dev_*.deb +sudo dpkg -i libnl-nf-3-200_*.deb +sudo dpkg -i libnl-nf-3-dev_*.deb +sudo dpkg -i libnl-cli-3-200_*.deb +sudo dpkg -i libnl-cli-3-dev_*.deb +sudo dpkg -i libyang_*.deb +sudo dpkg -i libyang-*.deb +sudo dpkg -i libswsscommon_1.0.0_amd64.deb +sudo dpkg -i libswsscommon-dev_1.0.0_amd64.deb + +# Install pip and add base-tooling-requirement.text +sudo apt-get update +sudo pip install --upgrade pip + +touch base-tooling-requirements.txt +sudo echo "Pympler ==0.8 --hash=sha256:f74cd2982c5cd92ded55561191945616f2bb904a0ae5cdacdb566c6696bdb922" >> base-tooling-requirements.txt + +pip install --require-hashes -r base-tooling-requirements.txt + + +# Install redis-tools inside virtualenv +sudo apt install redis-server redis-tools +sudo sed -i 's/notify-keyspace-events ""/notify-keyspace-events AKE/' /etc/redis/redis.conf +sudo sed -ri 's/^# unixsocket/unixsocket/' /etc/redis/redis.conf +sudo sed -ri 's/^unixsocketperm .../unixsocketperm 777/' /etc/redis/redis.conf +sudo sed -ri 's/redis-server.sock/redis.sock/' /etc/redis/redis.conf + +# Start redis-server : +sudo service redis-server restart& + +# Install gtest and gmock +sudo apt-get install -y libgtest-dev +sudo apt-get install -y libgmock-dev + +# Install dependencies need to execute tests +sudo apt-get install libjansson-dev +sudo apt install protobuf-compiler +sudo apt install libdbus-c++-bin +sudo apt install libdbus-c++-dev + +# Create /var/run/redis/sonic-db folder. +# copy the database_config.json file to /var/run/redis/sonic-db path. +sudo mkdir -p /var/run/redis/sonic-db +sudo cp /tmp/database_config.json /var/run/redis/sonic-db/ + + +#Build the sonic-fraework/tests. +cd ../../../src/sonic-framework/ +./autogen.sh +./configure +make + +cd tests +make + +#execure the sonic-framework tests. +./tests +./tests_asan +./tests_tsan +./tests_usan +