Skip to content

Commit a79b716

Browse files
author
Bibhuprasad Singh
committed
Adding script to execute sonic-framework/tests
1 parent 14eb980 commit a79b716

File tree

4 files changed

+356
-0
lines changed

4 files changed

+356
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Steps to run tests_script.sh
2+
3+
1. Build the workspace, incase the workspace is not built using following commands.
4+
5+
cd /sonic-buildiamge
6+
7+
make init
8+
9+
NOJESSIE=1 NOSTRETCH=1 NOBUSTER=1 NOBULLSEYE=1 SONIC_BUILD_JOBS=12 make configure PLATFORM=vs
10+
11+
NOJESSIE=1 NOSTRETCH=1 NOBUSTER=1 NOBULLSEYE=1 SONIC_BUILD_JOBS=12 make target/sonic-vs.img.gz
12+
13+
14+
2. Create a virtual environment using following steps.
15+
16+
Run create_virtualenv.sh script to create a virtual environment.
17+
18+
sh create_virtualenv.sh ./
19+
20+
21+
3. Run test_script.sh inside the virtual envirment to execute the UT test cases
22+
23+
sh test_script.sh ./
24+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/bin/bash
2+
3+
# read virtual environment name
4+
read -p "Enter the name of the virtual environment: " venv
5+
6+
# Install virtual env
7+
sudo apt-get install python3-pip
8+
9+
sudo apt-get install virtualenv
10+
11+
# Create a virtual environment
12+
virtualenv $venv
13+
echo
14+
echo
15+
echo "To activate the virtualenv, run:"
16+
17+
echo " source $venv/bin/activate"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"INSTANCES": {
3+
"redis": {
4+
"hostname": "127.0.0.1",
5+
"port": 6379,
6+
"unix_socket_path": "/var/run/redis/redis.sock"
7+
},
8+
"redis_chassis": {
9+
"hostname": "redis_chassis.server",
10+
"port": 6380,
11+
"unix_socket_path": "/var/run/redis/redis_chassis.sock"
12+
}
13+
},
14+
"DATABASES": {
15+
"APPL_DB": {
16+
"id": 0,
17+
"separator": ":",
18+
"instance": "redis"
19+
},
20+
"ASIC_DB": {
21+
"id": 1,
22+
"separator": ":",
23+
"instance": "redis"
24+
},
25+
"COUNTERS_DB": {
26+
"id": 2,
27+
"separator": ":",
28+
"instance": "redis"
29+
},
30+
"LOGLEVEL_DB": {
31+
"id": 3,
32+
"separator": ":",
33+
"instance": "redis"
34+
},
35+
"CONFIG_DB": {
36+
"id": 4,
37+
"separator": "|",
38+
"instance": "redis"
39+
},
40+
"PFC_WD_DB": {
41+
"id": 5,
42+
"separator": ":",
43+
"instance": "redis"
44+
},
45+
"FLEX_COUNTER_DB": {
46+
"id": 5,
47+
"separator": ":",
48+
"instance": "redis"
49+
},
50+
"STATE_DB": {
51+
"id": 6,
52+
"separator": "|",
53+
"instance": "redis"
54+
},
55+
"SNMP_OVERLAY_DB": {
56+
"id": 7,
57+
"separator": "|",
58+
"instance": "redis"
59+
},
60+
"RESTAPI_DB": {
61+
"id": 8,
62+
"separator": "|",
63+
"instance": "redis"
64+
},
65+
"GB_ASIC_DB": {
66+
"id": 9,
67+
"separator": ":",
68+
"instance": "redis"
69+
},
70+
"GB_COUNTERS_DB": {
71+
"id": 10,
72+
"separator": ":",
73+
"instance": "redis"
74+
},
75+
"GB_FLEX_COUNTER_DB": {
76+
"id": 11,
77+
"separator": ":",
78+
"instance": "redis"
79+
},
80+
"CHASSIS_APP_DB": {
81+
"id": 12,
82+
"separator": "|",
83+
"instance": "redis_chassis"
84+
},
85+
"CHASSIS_STATE_DB": {
86+
"id": 13,
87+
"separator": "|",
88+
"instance": "redis_chassis"
89+
},
90+
"APPL_STATE_DB": {
91+
"id": 14,
92+
"separator": ":",
93+
"instance": "redis"
94+
}
95+
},
96+
"VERSION": "1.0"
97+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
#!/bin/bash
2+
3+
# All the following steps need to be executed inside virtual Environment.
4+
# From /sonic-buildimage path.
5+
#
6+
# Getting the absolute path for script and sonic-buildimage.
7+
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
8+
cd $SCRIPT_DIR/../../../..
9+
BUILD_DIR="$(pwd)"
10+
11+
# Creating a temperary directory inside /tmp and
12+
# Downloading required libhiredis packages to that folder.
13+
mkdir /tmp/new
14+
cd /tmp/new
15+
16+
if curl -O https://ftp.debian.org/debian/pool/main/h/hiredis/libhiredis0.14_0.14.1-3_amd64.deb
17+
then echo "Download Request for libhiredis0.14_0.14.1-3_amd64.deb was successful"
18+
else echo "CURL Request for libhiredis0.14_0.14.1-3_amd64.deb failed !"
19+
exit 1
20+
fi
21+
22+
if curl -O https://ftp.debian.org/debian/pool/main/h/hiredis/libhiredis-dev_0.14.1-3_amd64.deb
23+
then echo "Download Request for libhiredis-dev_0.14.1-3_amd64.deb was successful"
24+
else echo "CURL Request for libhiredis-dev_0.14.1-3_amd64.deb failed !"
25+
exit 1
26+
fi
27+
28+
# Installing all the required dependencies/pkgs
29+
# Present in target/debs/bookworm and /tmp/new path.
30+
cd $BUILD_DIR/target/debs/bookworm
31+
32+
sudo dpkg -r libhiredis-dev
33+
sudo apt remove libhiredis0.14
34+
sudo dpkg -r libhiredis1.1.0
35+
36+
if sudo dpkg -i /tmp/new/libhiredis0.14_0.14.1-3_amd64.deb
37+
then echo "Successfully installed libhiredis0.14_0.14.1-3_amd64.deb"
38+
else echo "libhiredis0.14_0.14.1-3_amd64.deb installtion failed !"
39+
exit 1
40+
fi
41+
42+
if sudo dpkg -i /tmp/new/libhiredis-dev_0.14.1-3_amd64.deb
43+
then echo "Successfully installed libhiredis-dev_0.14.1-3_amd64.deb"
44+
else echo "libhiredis-dev_0.14.1-3_amd64.deb installtion failed !"
45+
exit 1
46+
fi
47+
48+
if sudo dpkg -i libnl-3-200_*.deb
49+
then echo "Successfully installed libnl-3-200_*.deb"
50+
else echo "libnl-3-200_*.deb installtion failed !"
51+
exit 1
52+
fi
53+
54+
if sudo dpkg -i libnl-3-dev_*.deb
55+
then echo "Successfully installed libnl-3-dev_*.deb"
56+
else echo "libnl-3-dev_*.deb installtion failed !"
57+
exit 1
58+
fi
59+
60+
if sudo dpkg -i libnl-genl-3-200_*.deb
61+
then echo "Successfully installed libnl-genl-3-200_*.deb"
62+
else echo "libnl-genl-3-200_*.deb installtion failed !"
63+
exit 1
64+
fi
65+
66+
if sudo dpkg -i libnl-genl-3-dev_*.deb
67+
then echo "Successfully installed libnl-genl-3-dev_*.deb"
68+
else echo "libnl-genl-3-dev_*.deb installtion failed !"
69+
exit 1
70+
fi
71+
72+
if sudo dpkg -i libnl-route-3-200_*.deb
73+
then echo "Successfully installed libnl-route-3-200_*.deb"
74+
else echo "libnl-route-3-200_*.deb installtion failed !"
75+
exit 1
76+
fi
77+
78+
if sudo dpkg -i libnl-route-3-dev_*.deb
79+
then echo "Successfully installed libnl-route-3-dev_*.deb"
80+
else echo "libnl-route-3-dev_*.deb installtion failed !"
81+
exit 1
82+
fi
83+
84+
if sudo dpkg -i libnl-nf-3-200_*.deb
85+
then echo "Successfully installed libnl-nf-3-200_*.deb"
86+
else echo "libnl-nf-3-200_*.deb installtion failed !"
87+
exit 1
88+
fi
89+
90+
if sudo dpkg -i libnl-nf-3-dev_*.deb
91+
then echo "Successfully installed libnl-nf-3-dev_*.deb"
92+
else echo "libnl-nf-3-dev_*.deb installtion failed !"
93+
exit 1
94+
fi
95+
96+
if sudo dpkg -i libnl-cli-3-200_*.deb
97+
then echo "Successfully installed libnl-cli-3-200_*.deb"
98+
else echo "libnl-cli-3-200_*.deb installtion failed !"
99+
exit 1
100+
fi
101+
102+
if sudo dpkg -i libnl-cli-3-dev_*.deb
103+
then echo "Successfully installed libnl-cli-3-dev_*.deb"
104+
else echo "libnl-cli-3-dev_*.deb installtion failed !"
105+
exit 1
106+
fi
107+
108+
if sudo dpkg -i libyang_*.deb
109+
then echo "Successfully installed libyang_*.deb"
110+
else echo "libyang_*.deb installtion failed !"
111+
exit 1
112+
fi
113+
114+
if sudo dpkg -i libyang-*.deb
115+
then echo "Successfully installed libyang-*.deb"
116+
else echo "libyang-*.deb installtion failed !"
117+
exit 1
118+
fi
119+
120+
if sudo dpkg -i libswsscommon_1.0.0_amd64.deb
121+
then echo "Successfully installed libswsscommon_1.0.0_amd64.deb"
122+
else echo "libswsscommon_1.0.0_amd64.deb installtion failed !"
123+
exit 1
124+
fi
125+
126+
if sudo dpkg -i libswsscommon-dev_1.0.0_amd64.deb
127+
then echo "Successfully installed libswsscommon-dev_1.0.0_amd64.deb"
128+
else echo "libswsscommon-dev_1.0.0_amd64.deb installtion failed !"
129+
exit 1
130+
fi
131+
132+
# Cleaning/removing temprary folder created inside /tmp.
133+
rm -rf /tmp/new
134+
135+
# Installing pip and add base-tooling-requirement.text
136+
sudo apt-get update
137+
pip install --upgrade pip
138+
139+
touch base-tooling-requirements.txt
140+
sudo echo "Pympler ==0.8 --hash=sha256:f74cd2982c5cd92ded55561191945616f2bb904a0ae5cdacdb566c6696bdb922" >>base-tooling-requirements.txt
141+
142+
pip install --require-hashes -r base-tooling-requirements.txt
143+
144+
# Installing required redis-tools inside virtualenv
145+
sudo apt install redis-server redis-tools
146+
sudo sed -i 's/notify-keyspace-events ""/notify-keyspace-events AKE/' /etc/redis/redis.conf
147+
sudo sed -ri 's/^# unixsocket/unixsocket/' /etc/redis/redis.conf
148+
sudo sed -ri 's/^unixsocketperm .../unixsocketperm 777/' /etc/redis/redis.conf
149+
sudo sed -ri 's/redis-server.sock/redis.sock/' /etc/redis/redis.conf
150+
151+
# Restarting redis-server :
152+
sudo service redis-server restart &
153+
if [[ $? -ne 0 ]]; then
154+
echo "Redis service restart failed!"
155+
exit 1
156+
fi
157+
158+
# Installing all required dependencies to execute tests
159+
# Installing gtest :
160+
sudo apt-get install -y libgtest-dev
161+
if [[ $? -ne 0 ]]; then
162+
echo "libgtest-dev installation failed!"
163+
exit 1
164+
fi
165+
166+
# Installing gmock :
167+
sudo apt-get install -y libgmock-dev
168+
if [[ $? -ne 0 ]]; then
169+
echo "libgmock-dev installation failed!"
170+
exit 1
171+
fi
172+
173+
# Installing libjansson-dev
174+
sudo apt-get install libjansson-dev
175+
if [[ $? -ne 0 ]]; then
176+
echo "libjansson-dev installation failed!"
177+
exit 1
178+
fi
179+
180+
# Installing protobuf-compiler
181+
sudo apt install protobuf-compiler
182+
if [[ $? -ne 0 ]]; then
183+
echo "protobuf-compiler installation failed!"
184+
exit 1
185+
fi
186+
187+
# Installing libdbus-c++-bin
188+
sudo apt install libdbus-c++-bin
189+
if [[ $? -ne 0 ]]; then
190+
echo "libdbus-c++-bin installation failed!"
191+
exit 1
192+
fi
193+
194+
# Installing libdbus-c++-dev
195+
sudo apt install libdbus-c++-dev
196+
if [[ $? -ne 0 ]]; then
197+
echo "libdbus-c++-dev installation failed!"
198+
exit 1
199+
fi
200+
201+
# Creating Directory: /var/run/redis/sonic-db
202+
# Copying database_config.json file to /var/run/redis/sonic-db path.
203+
sudo mkdir -p /var/run/redis/sonic-db
204+
sudo cp $SCRIPT_DIR/database_config.json /var/run/redis/sonic-db/
205+
206+
#Building the sonic-fraework/tests.
207+
cd $BUILD_DIR/src/sonic-framework/
208+
./autogen.sh
209+
./configure
210+
make
211+
cd tests
212+
make
213+
214+
#executin the sonic-framework tests.
215+
./tests
216+
./tests_asan
217+
./tests_tsan
218+
./tests_usan

0 commit comments

Comments
 (0)