Skip to content

Commit

Permalink
Adding script to execute sonic-framework/tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Bibhuprasad Singh committed Jan 10, 2025
1 parent 14eb980 commit c7c48ff
Show file tree
Hide file tree
Showing 4 changed files with 227 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/sonic-framework/tests/test_scripts/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Steps to run tests_script.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. Run test_script.sh inside the virtual envirment to execute the UT test cases

sh test_script.sh ./
17 changes: 17 additions & 0 deletions src/sonic-framework/tests/test_scripts/create_virtualenv.sh
Original file line number Diff line number Diff line change
@@ -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"
99 changes: 99 additions & 0 deletions src/sonic-framework/tests/test_scripts/database_config.json
Original file line number Diff line number Diff line change
@@ -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"
}


88 changes: 88 additions & 0 deletions src/sonic-framework/tests/test_scripts/tests_script.sh
Original file line number Diff line number Diff line change
@@ -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 ../../../src/sonic-framework/tests/test_scripts/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

0 comments on commit c7c48ff

Please sign in to comment.