From 3e822bbec46ed538ac0ff293996bf496973aeca3 Mon Sep 17 00:00:00 2001 From: "Chaunte W. Lacewell" Date: Wed, 15 Mar 2023 11:06:43 -0700 Subject: [PATCH] Unify ports for unit tests (#92) * Unify ports for unit tests * Fic gcov error --- .github/workflows/coverage.yml | 24 ++- docker/check-in/Dockerfile | 4 +- docker/check-in/run_coverage_cpp.sh | 5 +- tests/cleandbs.sh | 6 +- tests/python/TestCommand.py | 7 +- tests/python/config-tests.json | 2 +- tests/python/run_python_tests.sh | 18 +- tests/run_tests.sh | 9 +- tests/server/config-add10-tests.json | 2 +- tests/server/config-addfind-tests.json | 2 +- tests/server/config-auto-replicate-tests.json | 2 +- tests/server/config-datatype-tests.json | 2 +- tests/server/config-emptyresult-tests.json | 2 +- tests/server/config-tests.json | 2 +- tests/server/config-update-tests.json | 2 +- tests/server/json_queries.cc | 2 +- tests/unit_tests/config-client-tests.json | 10 + tests/unit_tests/meta_data.cc | 189 +++++++++--------- tests/unit_tests/meta_data_helper.h | 16 +- 19 files changed, 161 insertions(+), 145 deletions(-) create mode 100644 tests/unit_tests/config-client-tests.json diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml index 3f29ba78..0ce5f087 100644 --- a/.github/workflows/coverage.yml +++ b/.github/workflows/coverage.yml @@ -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 @@ -89,12 +92,13 @@ 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 @@ -102,7 +106,7 @@ jobs: 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 '' | awk '{print $3}') || true - name: Report ${{ matrix.coverage_type }} Coverage diff --git a/docker/check-in/Dockerfile b/docker/check-in/Dockerfile index e24bcaf8..134e2db5 100644 --- a/docker/check-in/Dockerfile +++ b/docker/check-in/Dockerfile @@ -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 diff --git a/docker/check-in/run_coverage_cpp.sh b/docker/check-in/run_coverage_cpp.sh index 82082b0f..029d2c01 100644 --- a/docker/check-in/run_coverage_cpp.sh +++ b/docker/check-in/run_coverage_cpp.sh @@ -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 diff --git a/tests/cleandbs.sh b/tests/cleandbs.sh index 8515a264..8e2bf9f8 100755 --- a/tests/cleandbs.sh +++ b/tests/cleandbs.sh @@ -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 diff --git a/tests/python/TestCommand.py b/tests/python/TestCommand.py index bb1e0e3b..37a4b23f 100644 --- a/tests/python/TestCommand.py +++ b/tests/python/TestCommand.py @@ -24,14 +24,11 @@ # 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): @@ -39,7 +36,7 @@ def __init__(self, *args, **kwargs): # VDMS Server Info self.hostname = "localhost" - self.port = 55558 + self.port = 55565 db_up = False attempts = 0 diff --git a/tests/python/config-tests.json b/tests/python/config-tests.json index 4c6961b7..30141207 100644 --- a/tests/python/config-tests.json +++ b/tests/python/config-tests.json @@ -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" diff --git a/tests/python/run_python_tests.sh b/tests/python/run_python_tests.sh index 28c31a1b..b5e34dbb 100755 --- a/tests/python/run_python_tests.sh +++ b/tests/python/run_python_tests.sh @@ -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 diff --git a/tests/run_tests.sh b/tests/run_tests.sh index af26bfa0..4f3df5e6 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -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 \ No newline at end of file +# kill -9 $cpp_unittest_pid $client_test_pid +# sh cleandbs.sh diff --git a/tests/server/config-add10-tests.json b/tests/server/config-add10-tests.json index 0fa2bb15..acdee217 100644 --- a/tests/server/config-add10-tests.json +++ b/tests/server/config-add10-tests.json @@ -3,7 +3,7 @@ // Sets database paths and other parameters { // Network - "port": 55555, + "port": 55557, // Database paths "pmgd_path": "simpleAddx10_db" diff --git a/tests/server/config-addfind-tests.json b/tests/server/config-addfind-tests.json index e243bcec..8452e1ab 100644 --- a/tests/server/config-addfind-tests.json +++ b/tests/server/config-addfind-tests.json @@ -3,7 +3,7 @@ // Sets database paths and other parameters { // Network - "port": 55555, + "port": 55557, // Database paths "pmgd_path": "jsongraph" diff --git a/tests/server/config-auto-replicate-tests.json b/tests/server/config-auto-replicate-tests.json index d37dfcff..9d283df1 100755 --- a/tests/server/config-auto-replicate-tests.json +++ b/tests/server/config-auto-replicate-tests.json @@ -1,5 +1,5 @@ { - "port": 55555, + "port": 55557, "autoreplicate_interval":5, "unit":"s", "max_simultaneous_clients": 100, diff --git a/tests/server/config-datatype-tests.json b/tests/server/config-datatype-tests.json index 69f2762a..5373514d 100644 --- a/tests/server/config-datatype-tests.json +++ b/tests/server/config-datatype-tests.json @@ -3,7 +3,7 @@ // Sets database paths and other parameters { // Network - "port": 55555, + "port": 55557, // Database paths "pmgd_path": "datatypecheck_db" diff --git a/tests/server/config-emptyresult-tests.json b/tests/server/config-emptyresult-tests.json index e52ceb4c..e66ff24c 100644 --- a/tests/server/config-emptyresult-tests.json +++ b/tests/server/config-emptyresult-tests.json @@ -3,7 +3,7 @@ // Sets database paths and other parameters { // Network - "port": 55555, + "port": 55557, // Database paths "pmgd_path": "entitycheck_db" diff --git a/tests/server/config-tests.json b/tests/server/config-tests.json index 2d158362..cf28e646 100644 --- a/tests/server/config-tests.json +++ b/tests/server/config-tests.json @@ -3,7 +3,7 @@ // Sets database paths and other parameters { // Network - "port": 55555, + "port": 55557, // Database paths "pmgd_path": "simpleAdd_db", diff --git a/tests/server/config-update-tests.json b/tests/server/config-update-tests.json index 8765c8c4..189607ec 100644 --- a/tests/server/config-update-tests.json +++ b/tests/server/config-update-tests.json @@ -3,7 +3,7 @@ // Sets database paths and other parameters { // Network - "port": 55555, + "port": 55557, // Database paths "pmgd_path": "simpleUpdate_db", diff --git a/tests/server/json_queries.cc b/tests/server/json_queries.cc index b6077871..d20b2f29 100644 --- a/tests/server/json_queries.cc +++ b/tests/server/json_queries.cc @@ -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 diff --git a/tests/unit_tests/config-client-tests.json b/tests/unit_tests/config-client-tests.json new file mode 100644 index 00000000..17dcc1bc --- /dev/null +++ b/tests/unit_tests/config-client-tests.json @@ -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" +} \ No newline at end of file diff --git a/tests/unit_tests/meta_data.cc b/tests/unit_tests/meta_data.cc index 9ddb3b84..e4f51340 100644 --- a/tests/unit_tests/meta_data.cc +++ b/tests/unit_tests/meta_data.cc @@ -1,9 +1,9 @@ #include "meta_data_helper.h" Meta_Data::Meta_Data(){ - - + } + Json::Value Meta_Data::construct_Flinng_Set( std::string& name, int& dim ){ Json::Value descriptor_set; @@ -20,13 +20,12 @@ Json::Value Meta_Data::construct_Flinng_Set( std::string& name, int& dim ){ descriptor_set["flinng_sub_hash_bits"]=2; descriptor_set["flinng_cut_off"]=6; set_query["AddDescriptorSet"] = descriptor_set; - + return set_query; - + } + Json::Value Meta_Data::construct_flinng_descriptor(){ - - Json::Value tuple; std::shared_ptr test_aclient; std::string name="flinng_test_2060"; @@ -35,10 +34,10 @@ Json::Value Meta_Data::construct_flinng_descriptor(){ test_aclient.reset ( new VDMS::VDMSClient(get_server(), get_port())); VDMS::Response response =test_aclient->query(_fastwriter.write(tuple)); Json::Value result; - _reader.parse(response.json.c_str(), result); + _reader.parse(response.json.c_str(), result); Json::Value AddDesc; Json::Value Desc; - + Desc["set"] ="flinng_test_2060"; Desc["label"] ="Person"; Desc["_ref"]=1; @@ -47,9 +46,6 @@ Json::Value Meta_Data::construct_flinng_descriptor(){ AddDesc["AddDescriptor"] = Desc; tuple.append(AddDesc); return tuple; - - - } Json::Value Meta_Data::construct_descriptor(){ @@ -64,10 +60,10 @@ Json::Value Meta_Data::construct_descriptor(){ test_aclient.reset ( new VDMS::VDMSClient(get_server(), get_port())); VDMS::Response response =test_aclient->query(_fastwriter.write(tuple)); Json::Value result; - _reader.parse(response.json.c_str(), result); + _reader.parse(response.json.c_str(), result); Json::Value AddDesc; Json::Value Desc; - + Desc["set"] ="features_vectors_store1"; Desc["label"] ="Person"; Desc["_ref"]=1; @@ -76,49 +72,46 @@ Json::Value Meta_Data::construct_descriptor(){ AddDesc["AddDescriptor"] = Desc; tuple.append(AddDesc); return tuple; - - } Json::Value Meta_Data::construct_find_descriptor() { - Json::Value FindDesc; - Json::Value Desc; - Json::Value tuple; -// Desc["results"]["count"] = ""; - // Desc["constraints"]["id"][0] =">="; - // Desc["constraints"]["id"][1] =100; - Desc["results"]["list"][0] = "_distance"; - Desc["results"]["list"][1] = "id"; - Desc["set"]= "features_vectors_store1"; - Desc["k_neighbors"]=5; -// Desc["blob"] =true; - FindDesc["FindDescriptor"] = Desc; - tuple.append(FindDesc); - FindDesc.clear(); - Desc.clear(); -return tuple; + Json::Value FindDesc; + Json::Value Desc; + Json::Value tuple; + // Desc["results"]["count"] = ""; + // Desc["constraints"]["id"][0] =">="; + // Desc["constraints"]["id"][1] =100; + Desc["results"]["list"][0] = "_distance"; + Desc["results"]["list"][1] = "id"; + Desc["set"]= "features_vectors_store1"; + Desc["k_neighbors"]=5; + // Desc["blob"] =true; + FindDesc["FindDescriptor"] = Desc; + tuple.append(FindDesc); + FindDesc.clear(); + Desc.clear(); + return tuple; } Json::Value Meta_Data::construct_find_flinng_descriptor() { - Json::Value FindDesc; - Json::Value Desc; - Json::Value tuple; - Desc["results"]["list"][0] = "_distance"; - Desc["results"]["list"][1] = "id"; - Desc["set"]= "flinng_test_2060"; - Desc["k_neighbors"]=5; -// Desc["blob"] =true; - FindDesc["FindDescriptor"] = Desc; - tuple.append(FindDesc); - FindDesc.clear(); - Desc.clear(); -return tuple; + Json::Value FindDesc; + Json::Value Desc; + Json::Value tuple; + Desc["results"]["list"][0] = "_distance"; + Desc["results"]["list"][1] = "id"; + Desc["set"]= "flinng_test_2060"; + Desc["k_neighbors"]=5; + // Desc["blob"] =true; + FindDesc["FindDescriptor"] = Desc; + tuple.append(FindDesc); + FindDesc.clear(); + Desc.clear(); + return tuple; } - Json::Value Meta_Data::constuct_image(bool add_operation, Json::Value operations){ Json::Value image; @@ -154,30 +147,38 @@ Json::Value Meta_Data::constuct_image(bool add_operation, Json::Value operations add_video["AddVideo"]=video; tuple.append(add_video); return tuple; - } +} - Json::Value Meta_Data::construct_find_image(){ +Json::Value Meta_Data::construct_find_image(){ + Json::Value tuple; + + Json::Value cons; + cons["Name"][0] = "=="; + cons["Name"][1] = "sample-image"; + + Json::Value results; + results["blob"] = false; + results["list"][0] = "Name"; + results["list"][1] = "ID"; Json::Value image; - Json::Value find_image; - Json::Value tuple; - Json::Value result; - - image["constraints"] ["Name"][0] = "=="; - image["constraints"] ["Name"][1] = "sample-image"; image["_ref"]=1; - result["list"][0] = "Name"; - image["results"]=result; + image["constraints"] = cons; + image["results"]=results; + + Json::Value find_image; find_image["FindImage"]=image; + tuple.append(find_image); return tuple; - } +} + std::string* Meta_Data::read_blob(std::string& fname){ - std::string video; + std::string video; std::ifstream video_file(fname, - std::ios::in | std::ios::binary | std::ios::ate); + std::ios::in | std::ios::binary | std::ios::ate); video.resize(video_file.tellg()); @@ -185,11 +186,11 @@ std::string* Meta_Data::read_blob(std::string& fname){ if( !video_file.read(&video[ 0 ], video.size())) std::cout << "error" << std::endl; std::string* bytes_str =new std::string(video); - // std::cout << *bytes_str < #include #include -#include +#include #include #include @@ -22,14 +22,14 @@ class Meta_Data{ public: std::shared_ptr _aclient; std::string _server_name="localhost"; - int _port =55555; - - Json::FastWriter _fastwriter; + int _port =55558; + + Json::FastWriter _fastwriter; Json::Reader _reader; - Json::Value _result; + Json::Value _result; Meta_Data (); - + Json::Value construct_add_query(int ref, bool const_on, bool experiation); Json::Value construct_add_area(int ref, bool const_on); @@ -53,6 +53,6 @@ class Meta_Data{ - -}; + +}; \ No newline at end of file