Skip to content

Commit

Permalink
Unify ports for unit tests (IntelLabs#92)
Browse files Browse the repository at this point in the history
* Unify ports for unit tests
* Fic gcov error
  • Loading branch information
cwlacewe authored Mar 15, 2023
1 parent 55fd710 commit 3e822bb
Show file tree
Hide file tree
Showing 19 changed files with 161 additions and 145 deletions.
24 changes: 14 additions & 10 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,16 @@ jobs:
docker stop $(docker ps -aqf "name=${{ matrix.container_name }}") || true
docker rm $(docker ps -aqf "name=${{ matrix.container_name }}") || true
# docker build -f docker/check-in/Dockerfile -t ${{ matrix.container_tag }} .
sed -i 's|"numpy>=1.23.2" gcovr|"numpy>=1.23.2" "gcovr>=5.2"|g' docker/check-in/Dockerfile
# REMOVE MAVEN AFTER MERGE
docker build --build-arg MAVEN_OPTS=${{ secrets.MAVEN_OPTS }} \
-f docker/check-in/Dockerfile -t ${{ matrix.container_tag }} .
# Corrections for target until merged
sed -i 's|/vdms/build/CMakeFiles|/vdms/build -e /vdms/tests --gcov-ignore-errors=no_working_dir_found|g' docker/check-in/run_coverage_cpp.sh
sed -i 's|\"/vdms/client/.*\.cc\" \-f \"/vdms/ext/.*\.cc\" \-f \"/vdms/src/.*\.cc\"|\"/vdms/.*/.*\.cc\"|g' docker/check-in/run_coverage_cpp.sh
sed -i '/src\/SearchExpression.cc/d' docker/check-in/run_coverage_cpp.sh
docker run -d --name ${{ matrix.container_name }} ${{ matrix.container_tag }}
docker build --rm -f docker/check-in/Dockerfile -t ${{ matrix.container_tag }} .
docker run --rm -d --name ${{ matrix.container_name }} ${{ matrix.container_tag }}
- name: Get ${{ matrix.coverage_type }} Coverage
shell: bash
Expand All @@ -89,20 +92,21 @@ jobs:
echo "${{ matrix.container_name }}"
docker exec ${{ matrix.container_name }} bash -c "cd / && ./run_coverage_cpp.sh && cd / && ./run_coverage_py.sh"
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/c_coverage_report.txt coverage/c_coverage_report_target.txt
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/c_coverage_report.xml coverage/c_coverage_report_target.xml
docker cp ${{ matrix.container_name }}:/vdms/tests/coverage_report/c_coverage_report.txt coverage/c_coverage_report_target.txt
docker cp ${{ matrix.container_name }}:/vdms/tests/coverage_report/c_coverage_report.xml coverage/c_coverage_report_target.xml
echo "coverage_value_cpp=$(cat coverage/c_coverage_report_target.xml | grep -oP 'coverage line-rate="([-+]?\d*\.\d+|\d+)"' | grep -oP "[-+]?\d*\.\d+|\d+" | awk '{print $1*100}')" >> $GITHUB_ENV
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/py_coverage_report.txt coverage/py_coverage_report_target.txt || true
docker cp $(docker ps -a | grep ${{ matrix.container_name }} | awk '{print $1}'):/vdms/tests/coverage_report/py_coverage_report.xml coverage/py_coverage_report_target.xml || true
docker cp ${{ matrix.container_name }}:/vdms/tests/coverage_report/py_coverage_report.txt coverage/py_coverage_report_target.txt || true
docker cp ${{ matrix.container_name }}:/vdms/tests/coverage_report/py_coverage_report.xml coverage/py_coverage_report_target.xml || true
if [ ! -f coverage/py_coverage_report_target.xml ] && [ "${{ matrix.coverage_type }}" == "Target" ]; then
echo "coverage_value_py=0" >> $GITHUB_ENV
else
echo "coverage_value_py=$(cat coverage/py_coverage_report_target.xml | grep "coverage version" | grep -oP 'line-rate="([-+]?\d*\.\d+|\d+)"' | grep -oP "[-+]?\d*\.\d+|\d+"| awk '{print $1*100}')" >> $GITHUB_ENV
fi
docker ps -aqf "name=${{ matrix.container_name }}" | xargs docker stop
docker ps -aqf "name=${{ matrix.container_name }}" | xargs docker rm
# docker ps -aqf "name=${{ matrix.container_name }}" | xargs docker rm
docker rmi $(docker images | grep '<none>' | awk '{print $3}') || true
- name: Report ${{ matrix.coverage_type }} Coverage
Expand Down
4 changes: 2 additions & 2 deletions docker/check-in/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ RUN apt-get update && apt-get install -y --no-install-recommends software-proper
libleveldb-dev liblmdb-dev liblz4-dev libopenblas-dev libopenmpi-dev \
libpng-dev librdkafka-dev libsnappy-dev libssl-dev libswscale-dev libtbb-dev \
libtbb2 libtiff-dev libtiff5-dev libtool mpich openjdk-11-jdk-headless \
pkg-config python3-dev python3-pip unzip lcov && \
pkg-config python3-dev python3-pip unzip lcov gdb && \
apt-get clean && rm -rf /var/lib/apt/lists/* && \
update-alternatives --install /usr/bin/python python /usr/bin/python3 1 && \
pip3 install --no-cache-dir "numpy>=1.23.2" gcovr
pip3 install --no-cache-dir "numpy>=1.23.2" "gcovr>=5.2"

# Pull and Install Dependencies
WORKDIR /dependencies
Expand Down
5 changes: 2 additions & 3 deletions docker/check-in/run_coverage_cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@ chmod +x run_tests.sh
./run_tests.sh

gcovr --root /vdms \
-e /vdms/src/pmgd -e /vdms/build/CMakeFiles \
-f "/vdms/client/.*\.cc" -f "/vdms/ext/.*\.cc" -f "/vdms/src/.*\.cc" \
-f src/SearchExpression.cc \
-e /vdms/src/pmgd -e /vdms/build -e /vdms/tests --gcov-ignore-errors=no_working_dir_found \
-f "/vdms/.*/.*\.cc" \
--exclude-unreachable-branches \
--txt=/vdms/tests/coverage_report/c_coverage_report.txt \
--xml-pretty --xml=/vdms/tests/coverage_report/c_coverage_report.xml
Expand Down
6 changes: 3 additions & 3 deletions tests/cleandbs.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
rm -r jsongraph qhgraph simpleAdd_db simpleAddx10_db simpleUpdate_db entitycheck_db datatypecheck_db db_backup test_db_1
rm -r jsongraph qhgraph simpleAdd_db simpleAddx10_db simpleUpdate_db
rm -r entitycheck_db datatypecheck_db db_backup test_db_1
rm -r tests_log.log tests_screen.log

rm -r tdb
rm -r dbs
rm -r db dbs test_db_client
rm -r temp
rm -r videos_tests
rm -r vdms
rm test_images/tdb_to_jpg.jpg
rm test_images/tdb_to_png.png
rm test_images/test_image.jpg
rm test_images/test_image.jpg
rm -r backups
7 changes: 2 additions & 5 deletions tests/python/TestCommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,22 +24,19 @@
# THE SOFTWARE.
#

import sys
import os
import urllib
import time
import json
import unittest
import vdms


class TestCommand(unittest.TestCase):

def __init__(self, *args, **kwargs):
super(TestCommand, self).__init__(*args, **kwargs)

# VDMS Server Info
self.hostname = "localhost"
self.port = 55558
self.port = 55565

db_up = False
attempts = 0
Expand Down
2 changes: 1 addition & 1 deletion tests/python/config-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Sets database paths and other parameters
{
// Network
"port": 55558,
"port": 55565,
"db_root_path": "test_db",

"more-info": "github.com/IntelLabs/vdms"
Expand Down
18 changes: 13 additions & 5 deletions tests/python/run_python_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,25 @@
# THE SOFTWARE.
#

rm log.log screen.log
rm -r test_db

TEST_DIR=${PWD}
base_dir=$(dirname $(dirname $PWD))
client_path=${base_dir}/client/python
export PYTHONPATH=$client_path:${PYTHONPATH}

# Uncomment to re-generate queryMessage_pb2.py
# python3 -m grpc_tools.protoc -I=${base_dir}/utils/src/protobuf --python_out=${client_path}/vdms ${base_dir}/utils/src/protobuf/queryMessage.proto

cd ${TEST_DIR}
rm -rf test_db log.log screen.log
mkdir -p test_db

./../../build/vdms -cfg config-tests.json > screen.log 2> log.log &
python3 -m coverage run --include="../../*" --omit="../*" -m unittest discover --pattern=Test*.py -v
py_unittest_pid=$!

sleep 1
pkill vdms

echo 'Running Python tests...'
python3 -m coverage run --include="../../*" --omit="../*" -m unittest discover --pattern=Test*.py -v

rm -rf test_db log.log screen.log
kill -9 $py_unittest_pid
9 changes: 4 additions & 5 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ mkdir backups
# Start server for client test
./../build/vdms -cfg unit_tests/config-tests.json > tests_screen.log 2> tests_log.log &

./../build/vdms -cfg unit_tests/config-client-tests.json > tests_screen.log 2> tests_log.log &

echo 'not the vdms application - this file is needed for shared key' > vdms

# Gets coverage for files in ../src and ../include
# OMIT Descriptors_Add.add_1by1_and_search_1k due to duration
echo 'Running C++ tests...'
./../build/tests/unit_tests \
--gtest_filter=-ImageTest.CreateNameTDB:ImageTest.NoMetadata:VideoTest.CreateUnique:Descriptors_Add.add_1by1_and_search_1k

# echo 'Running Python tests...'
# cd python
# sh run_python_tests.sh
# kill -9 $cpp_unittest_pid $client_test_pid
# sh cleandbs.sh
2 changes: 1 addition & 1 deletion tests/server/config-add10-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Sets database paths and other parameters
{
// Network
"port": 55555,
"port": 55557,

// Database paths
"pmgd_path": "simpleAddx10_db"
Expand Down
2 changes: 1 addition & 1 deletion tests/server/config-addfind-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Sets database paths and other parameters
{
// Network
"port": 55555,
"port": 55557,

// Database paths
"pmgd_path": "jsongraph"
Expand Down
2 changes: 1 addition & 1 deletion tests/server/config-auto-replicate-tests.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"port": 55555,
"port": 55557,
"autoreplicate_interval":5,
"unit":"s",
"max_simultaneous_clients": 100,
Expand Down
2 changes: 1 addition & 1 deletion tests/server/config-datatype-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Sets database paths and other parameters
{
// Network
"port": 55555,
"port": 55557,

// Database paths
"pmgd_path": "datatypecheck_db"
Expand Down
2 changes: 1 addition & 1 deletion tests/server/config-emptyresult-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Sets database paths and other parameters
{
// Network
"port": 55555,
"port": 55557,

// Database paths
"pmgd_path": "entitycheck_db"
Expand Down
2 changes: 1 addition & 1 deletion tests/server/config-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Sets database paths and other parameters
{
// Network
"port": 55555,
"port": 55557,

// Database paths
"pmgd_path": "simpleAdd_db",
Expand Down
2 changes: 1 addition & 1 deletion tests/server/config-update-tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// Sets database paths and other parameters
{
// Network
"port": 55555,
"port": 55557,

// Database paths
"pmgd_path": "simpleUpdate_db",
Expand Down
2 changes: 1 addition & 1 deletion tests/server/json_queries.cc
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ TEST( AutoReplicate, default_replicate)
QueryHandler::init();
std::string backup_path ="backups";
std::string db_path="db_backup";
int port =55555;
int port =55557;

QueryHandler qh_base;
qh_base.regualar_run_autoreplicate(backup_path, db_path, port); // set flag to show autodelete queue has been initialized
Expand Down
10 changes: 10 additions & 0 deletions tests/unit_tests/config-client-tests.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// VDMS Config File
// This is the run-time config file
// Sets database paths and other parameters
{

"port": 55558,
"db_root_path": "test_db_client",

"more-info": "github.com/IntelLabs/vdms"
}
Loading

0 comments on commit 3e822bb

Please sign in to comment.