From 75dcc81c571c835280e7efef213190713fc870b8 Mon Sep 17 00:00:00 2001 From: "Lacewell, Chaunte W" Date: Tue, 23 Jul 2024 08:34:13 -0700 Subject: [PATCH] Remove non-2.9 files --- tests/python/TestEngineDescriptors.py | 221 ------- tests/python/TestEntitiesBlobs.py | 141 ----- tests/python/TestFindDescriptorSet.py | 55 -- tests/python/TestFindDescriptors.py | 650 -------------------- tests/python/prep.py | 147 ----- tests/remote_function_test/requirements.txt | 5 - tests/tls_test/prep-tls-tests.py | 238 ------- tests/udf_test/requirements.txt | 2 - utils/include/chrono/Chrono.h | 186 ------ utils/src/chrono/Chrono.cc | 235 ------- 10 files changed, 1880 deletions(-) delete mode 100644 tests/python/TestEngineDescriptors.py delete mode 100644 tests/python/TestEntitiesBlobs.py delete mode 100644 tests/python/TestFindDescriptorSet.py delete mode 100644 tests/python/TestFindDescriptors.py delete mode 100644 tests/python/prep.py delete mode 100644 tests/remote_function_test/requirements.txt delete mode 100644 tests/tls_test/prep-tls-tests.py delete mode 100644 tests/udf_test/requirements.txt delete mode 100644 utils/include/chrono/Chrono.h delete mode 100644 utils/src/chrono/Chrono.cc diff --git a/tests/python/TestEngineDescriptors.py b/tests/python/TestEngineDescriptors.py deleted file mode 100644 index 670fa7a9..00000000 --- a/tests/python/TestEngineDescriptors.py +++ /dev/null @@ -1,221 +0,0 @@ -# -# The MIT License -# -# @copyright Copyright (c) 2017 Intel Corporation -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, -# merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -import TestCommand -import numpy as np - - -class TestDescriptors(TestCommand.TestCommand): - def addSet(self, name, dim, metric, engine): - db = self.create_connection() - - all_queries = [] - - descriptor_set = {} - descriptor_set["name"] = name - descriptor_set["dimensions"] = dim - descriptor_set["metric"] = metric - descriptor_set["engine"] = engine - - query = {} - query["AddDescriptorSet"] = descriptor_set - - all_queries.append(query) - - response, img_array = db.query(all_queries) - - # Check success - self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0) - self.disconnect(db) - - @TestCommand.TestCommand.shouldSkipRemotePythonTest() - def test_addDifferentSets(self): - self.addSet("128-L2-FaissFlat", 128, "L2", "FaissFlat") - self.addSet("128-IP-FaissFlat", 128, "IP", "FaissFlat") - self.addSet("128-L2-FaissIVFFlat", 128, "L2", "FaissIVFFlat") - self.addSet("128-IP-FaissIVFFlat", 128, "IP", "FaissIVFFlat") - self.addSet("128-L2-TileDBDense", 128, "L2", "TileDBDense") - self.addSet("128-L2-TileDBSparse", 128, "L2", "TileDBSparse") - self.addSet("128-L2-FLINNG", 128, "L2", "Flinng") - self.addSet("128-IP-FLINNG", 128, "IP", "Flinng") - - self.addSet("4075-L2-FaissFlat", 4075, "L2", "FaissFlat") - self.addSet("4075-IP-FaissFlat", 4075, "IP", "FaissFlat") - self.addSet("4075-L2-FaissIVFFlat", 4075, "L2", "FaissIVFFlat") - self.addSet("4075-IP-FaissIVFFlat", 4075, "IP", "FaissIVFFlat") - self.addSet("4075-L2-TileDBDense", 4075, "L2", "TileDBDense") - self.addSet("4075-L2-FLINNG", 4075, "L2", "Flinng") - self.addSet("4075-IP-FLINNG", 4075, "IP", "Flinng") - - def test_addDescriptorsx1000FaissIVFFlat(self): - db = self.create_connection() - - all_queries = [] - - # Add Set - set_name = "faissivfflat_ip_128dx1000" - dims = 128 - descriptor_set = {} - descriptor_set["name"] = set_name - descriptor_set["dimensions"] = dims - descriptor_set["metric"] = "IP" - descriptor_set["engine"] = "FaissIVFFlat" - - query = {} - query["AddDescriptorSet"] = descriptor_set - - all_queries.append(query) - - response, img_array = db.query(all_queries) - self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0) - - all_queries = [] - descriptor_blob = [] - - total = 2 - - for i in range(1, total): - x = np.ones(dims) - x[2] = 2.34 + i * 20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - descriptor = {} - descriptor["set"] = set_name - descriptor["label"] = "classX" - - query = {} - query["AddDescriptor"] = descriptor - - all_queries.append(query) - - response, img_array = db.query(all_queries, [descriptor_blob]) - - # Check success - for x in range(0, total - 1): - self.assertEqual(response[x]["AddDescriptor"]["status"], 0) - self.disconnect(db) - - @TestCommand.TestCommand.shouldSkipRemotePythonTest() - def test_addDescriptorsx1000TileDBSparse(self): - db = self.create_connection() - - all_queries = [] - - # Add Set - set_name = "tiledbsparse_l2_128dx1000" - dims = 128 - descriptor_set = {} - descriptor_set["name"] = set_name - descriptor_set["dimensions"] = dims - descriptor_set["metric"] = "L2" - descriptor_set["engine"] = "TileDBSparse" - - query = {} - query["AddDescriptorSet"] = descriptor_set - - all_queries.append(query) - - response, img_array = db.query(all_queries) - self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0) - - all_queries = [] - descriptor_blob = [] - - total = 2 - - for i in range(1, total): - x = np.ones(dims) - x[2] = 2.34 + i * 20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - descriptor = {} - descriptor["set"] = set_name - descriptor["label"] = "classX" - - query = {} - query["AddDescriptor"] = descriptor - - all_queries.append(query) - - response, img_array = db.query(all_queries, [descriptor_blob]) - - # Check success - for x in range(0, total - 1): - self.assertEqual(response[x]["AddDescriptor"]["status"], 0) - self.disconnect(db) - - @TestCommand.TestCommand.shouldSkipRemotePythonTest() - def test_addDescriptorsx1000TileDBDense(self): - db = self.create_connection() - - all_queries = [] - - # Add Set - set_name = "tiledbdense_l2_128dx1000" - dims = 128 - descriptor_set = {} - descriptor_set["name"] = set_name - descriptor_set["dimensions"] = dims - descriptor_set["metric"] = "L2" - descriptor_set["engine"] = "TileDBDense" - - query = {} - query["AddDescriptorSet"] = descriptor_set - - all_queries.append(query) - - response, img_array = db.query(all_queries) - # print(json.dumps(all_queries, indent=4, sort_keys=False)) - self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0) - - all_queries = [] - descriptor_blob = [] - - total = 2 - - for i in range(1, total): - x = np.ones(dims) - x[2] = 2.34 + i * 20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - descriptor = {} - descriptor["set"] = set_name - descriptor["label"] = "classX" - - query = {} - query["AddDescriptor"] = descriptor - - all_queries.append(query) - - response, img_array = db.query(all_queries, [descriptor_blob]) - - # Check success - for x in range(0, total - 1): - self.assertEqual(response[x]["AddDescriptor"]["status"], 0) - self.disconnect(db) diff --git a/tests/python/TestEntitiesBlobs.py b/tests/python/TestEntitiesBlobs.py deleted file mode 100644 index bcfe76f1..00000000 --- a/tests/python/TestEntitiesBlobs.py +++ /dev/null @@ -1,141 +0,0 @@ -# -# The MIT License -# -# @copyright Copyright (c) 2017 Intel Corporation -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, -# merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -import TestCommand - - -class TestEntitiesBlob(TestCommand.TestCommand): - def test_addEntityWithBlob(self, thID=0): - db = self.create_connection() - - props = {} - props["name"] = "Luis" - props["lastname"] = "Ferro" - props["age"] = 27 - props["threadid"] = thID - - addEntity = {} - addEntity["properties"] = props - addEntity["class"] = "AwesomePeople" - addEntity["blob"] = True - - query = {} - query["AddEntity"] = addEntity - - all_queries = [] - all_queries.append(query) - - blob_arr = [] - fd = open("../test_images/brain.png", "rb") - blob_arr.append(fd.read()) - fd.close() - - response, res_arr = db.query(all_queries, [blob_arr]) - - self.assertEqual(response[0]["AddEntity"]["status"], 0) - self.disconnect(db) - - def test_addEntityWithBlobNoBlob(self, thID=0): - db = self.create_connection() - - props = {} - props["name"] = "Luis" - props["lastname"] = "Ferro" - props["age"] = 27 - props["threadid"] = thID - - addEntity = {} - addEntity["properties"] = props - addEntity["class"] = "AwesomePeople" - addEntity["blob"] = True - - query = {} - query["AddEntity"] = addEntity - - all_queries = [] - all_queries.append(query) - - response, res_arr = db.query(all_queries) - - self.assertEqual(response[0]["status"], -1) - self.assertEqual(response[0]["info"], "Expected blobs: 1. Received blobs: 0") - self.disconnect(db) - - def test_addEntityWithBlobAndFind(self, thID=0): - db = self.create_connection() - - props = {} - props["name"] = "Tom" - props["lastname"] = "Slash" - props["age"] = 27 - props["id"] = 45334 - - addEntity = {} - addEntity["properties"] = props - addEntity["class"] = "NotSoAwesome" - addEntity["blob"] = True - - query = {} - query["AddEntity"] = addEntity - - all_queries = [] - all_queries.append(query) - - blob_arr = [] - fd = open("../test_images/brain.png", "rb") - blob_arr.append(fd.read()) - fd.close() - - response, res_arr = db.query(all_queries, [blob_arr]) - - self.assertEqual(response[0]["AddEntity"]["status"], 0) - - constraints = {} - constraints["id"] = ["==", 45334] - - results = {} - results["blob"] = True - results["list"] = ["name"] - - FindEntity = {} - FindEntity["constraints"] = constraints - FindEntity["class"] = "NotSoAwesome" - FindEntity["results"] = results - - query = {} - query["FindEntity"] = FindEntity - - all_queries = [] - all_queries.append(query) - - response, res_arr = db.query(all_queries) - - self.assertEqual(response[0]["FindEntity"]["entities"][0]["blob"], True) - - self.assertEqual(len(res_arr), len(blob_arr)) - self.assertEqual(len(res_arr[0]), len(blob_arr[0])) - self.assertEqual((res_arr[0]), (blob_arr[0])) - self.disconnect(db) diff --git a/tests/python/TestFindDescriptorSet.py b/tests/python/TestFindDescriptorSet.py deleted file mode 100644 index ea6df170..00000000 --- a/tests/python/TestFindDescriptorSet.py +++ /dev/null @@ -1,55 +0,0 @@ -import TestCommand - - -class TestFindDescriptorSet(TestCommand.TestCommand): - def addSet(self, name, dim, metric, engine): - db = self.create_connection() - - all_queries = [] - descriptor_set = {} - descriptor_set["name"] = name - descriptor_set["dimensions"] = dim - descriptor_set["metric"] = metric - descriptor_set["engine"] = engine - - query = {} - query["AddDescriptorSet"] = descriptor_set - - all_queries.append(query) - - # Execute the query - response, img_array = db.query(all_queries) - - # Check if the query was successful (you can add your own checks here) - if "AddDescriptorSet" in response[0]: - status = response[0]["AddDescriptorSet"].get("status") - self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0) - - def test_findDescriptorSet(self): - db = self.create_connection() - name = "testFindDescriptorSet-new" - dim = 128 - engine = "FaissFlat" - metric = "L2" - - self.addSet(name, dim, metric, engine) - - all_queries = [] - - storeIndex = True - - descriptor_set = {} - descriptor_set["set"] = name - descriptor_set["storeIndex"] = storeIndex - - query = {} - - query["FindDescriptorSet"] = descriptor_set - - all_queries.append(query) - - # Execute the query - response, img_array = db.query(all_queries) - - self.assertEqual(response[0]["FindDescriptorSet"]["status"], 0) - self.assertEqual(response[0]["FindDescriptorSet"]["returned"], 1) diff --git a/tests/python/TestFindDescriptors.py b/tests/python/TestFindDescriptors.py deleted file mode 100644 index fd424882..00000000 --- a/tests/python/TestFindDescriptors.py +++ /dev/null @@ -1,650 +0,0 @@ -# -# The MIT License -# -# @copyright Copyright (c) 2017 Intel Corporation -# -# Permission is hereby granted, free of charge, to any person obtaining a copy -# of this software and associated documentation files (the "Software"), -# to deal in the Software without restriction, -# including without limitation the rights to use, copy, modify, -# merge, publish, distribute, sublicense, and/or sell -# copies of the Software, and to permit persons to whom the Software is -# furnished to do so, subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in -# all copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -# ARISING FROM, -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -# THE SOFTWARE. -# - -import TestCommand -import numpy as np -import unittest - - -class TestFindDescriptors(TestCommand.TestCommand): - def create_set_and_insert(self, set_name, dims, total, labels=True): - db = self.create_connection() - - all_queries = [] - - # Add Set - descriptor_set = {} - descriptor_set["name"] = set_name - descriptor_set["dimensions"] = dims - - query = {} - query["AddDescriptorSet"] = descriptor_set - - all_queries.append(query) - - response, img_array = db.query(all_queries) - self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0) - - all_queries = [] - descriptor_blob = [] - - class_counter = -1 - for i in range(0, total): - if (i % 4) == 0: - class_counter += 1 - - x = np.ones(dims) - x[2] = 2.34 + i * 20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - descriptor = {} - descriptor["set"] = set_name - - if labels: - descriptor["label"] = "class" + str(class_counter) - - props = {} - props["myid"] = i + 200 - descriptor["properties"] = props - - query = {} - query["AddDescriptor"] = descriptor - - all_queries.append(query) - - response, img_array = db.query(all_queries, [descriptor_blob]) - - # Check success - for x in range(0, total): - self.assertEqual(response[x]["AddDescriptor"]["status"], 0) - - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByConstraints(self): - # Add Set - set_name = "features_128d_4_findbyConst" - dims = 128 - total = 5 - self.create_set_and_insert(set_name, dims, total) - - db = self.create_connection() - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - - constraints = {} - constraints["myid"] = ["==", 202] - finddescriptor["constraints"] = constraints - - results = {} - results["list"] = [ - "myid", - ] - finddescriptor["results"] = results - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - response, img_array = db.query(all_queries) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], 1) - self.assertEqual(response[0]["FindDescriptor"]["entities"][0]["myid"], 202) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescUnusedRef(self): - # Add Set - set_name = "features_128d_4_findunusedRef" - dims = 128 - total = 5 - self.create_set_and_insert(set_name, dims, total) - - db = self.create_connection() - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - - constraints = {} - constraints["myid"] = ["==", 202] - finddescriptor["constraints"] = constraints - - results = {} - results["list"] = ["myid"] - finddescriptor["results"] = results - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - response, blob_array = db.query(all_queries) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], 1) - self.assertEqual(response[0]["FindDescriptor"]["entities"][0]["myid"], 202) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByConst_get_id(self): - # Add Set - set_name = "features_128d_4_findDescriptors_id" - dims = 128 - total = 5 - self.create_set_and_insert(set_name, dims, total) - - db = self.create_connection() - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - - constraints = {} - constraints["myid"] = ["==", 202] - finddescriptor["constraints"] = constraints - - results = {} - results["list"] = ["myid", "_label", "_id"] - finddescriptor["results"] = results - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - response, img_array = db.query(all_queries) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], 1) - self.assertEqual(response[0]["FindDescriptor"]["entities"][0]["myid"], 202) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByConst_blobTrue(self): - # Add Set - set_name = "features_128d_4_findDescriptors_id_blob" - dims = 128 - total = 5 - self.create_set_and_insert(set_name, dims, total) - - db = self.create_connection() - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - - constraints = {} - constraints["myid"] = ["==", 202] - finddescriptor["constraints"] = constraints - - results = {} - results["list"] = ["myid", "_label", "_id"] - results["blob"] = True - finddescriptor["results"] = results - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - response, fv_array = db.query(all_queries) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], 1) - self.assertEqual(response[0]["FindDescriptor"]["entities"][0]["myid"], 202) - self.assertEqual(len(fv_array), 1) - self.assertEqual(len(fv_array[0]), dims * 4) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByConst_multiple_blobTrue(self): - # Add Set - set_name = "features_128d_4_findDescriptors_m_blob" - dims = 128 - total = 5 - self.create_set_and_insert(set_name, dims, total) - - db = self.create_connection() - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - - constraints = {} - constraints["myid"] = ["<=", 202] - finddescriptor["constraints"] = constraints - - results = {} - results["list"] = ["myid"] - results["sort"] = "myid" - results["blob"] = True - finddescriptor["results"] = results - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - response, fv_array = db.query(all_queries) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], 3) - self.assertEqual(response[0]["FindDescriptor"]["entities"][1]["myid"], 201) - self.assertEqual(len(fv_array), 3) - self.assertEqual(len(fv_array[0]), dims * 4) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByBlob(self): - # Add Set - set_name = "findwith_blob" - dims = 128 - total = 5 - self.create_set_and_insert(set_name, dims, total) - - db = self.create_connection() - - kn = 3 - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - - results = {} - results["list"] = ["myid", "_id", "_distance"] - results["blob"] = True - finddescriptor["results"] = results - finddescriptor["k_neighbors"] = kn - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - descriptor_blob = [] - x = np.ones(dims) - x[2] = x[2] = 2.34 + 1 * 20 # 2.34 + 1*20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - response, blob_array = db.query(all_queries, [descriptor_blob]) - - self.assertEqual(len(blob_array), kn) - self.assertEqual(descriptor_blob[0], blob_array[0]) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], kn) - self.assertEqual(response[0]["FindDescriptor"]["entities"][0]["_distance"], 0) - self.assertEqual(response[0]["FindDescriptor"]["entities"][1]["_distance"], 400) - self.assertEqual(response[0]["FindDescriptor"]["entities"][2]["_distance"], 400) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByBlobNoLabels(self): - # Add Set - set_name = "findwith_blob_no_labels" - dims = 128 - total = 5 - self.create_set_and_insert(set_name, dims, total, labels=False) - - db = self.create_connection() - - kn = 3 - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - finddescriptor["_ref"] = 1 - - results = {} - results["blob"] = True - finddescriptor["results"] = results - finddescriptor["k_neighbors"] = kn - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - descriptor_blob = [] - x = np.ones(dims) - x[2] = 2.34 + 1 * 20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - response, blob_array = db.query(all_queries, [descriptor_blob]) - - self.assertEqual(len(blob_array), kn) - self.assertEqual(descriptor_blob[0], blob_array[0]) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], kn) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByBlobNoResults(self): - # Add Set - set_name = "findwith_blobNoResults" - dims = 128 - total = 1 - self.create_set_and_insert(set_name, dims, total) - - db = self.create_connection() - - kn = 1 - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - - results = {} - results["blob"] = True - finddescriptor["results"] = results - finddescriptor["k_neighbors"] = kn - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - descriptor_blob = [] - x = np.ones(dims) - x[2] = 2.34 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - response, blob_array = db.query(all_queries, [descriptor_blob]) - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], 1) - self.assertEqual(len(blob_array), kn) - self.assertEqual(descriptor_blob[0], blob_array[0]) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByBlobUnusedRef(self): - # Add Set - set_name = "findwith_blobUnusedRef" - dims = 50 - total = 3 - self.create_set_and_insert(set_name, dims, total) - - db = self.create_connection() - - kn = 3 - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - finddescriptor["_ref"] = 1 - - results = {} - results["blob"] = True - finddescriptor["results"] = results - finddescriptor["k_neighbors"] = kn - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - descriptor_blob = [] - x = np.ones(dims) - x[2] = 2.34 + 1 * 20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - response, blob_array = db.query(all_queries, [descriptor_blob]) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], kn) - self.assertEqual(len(blob_array), kn) - self.assertEqual(descriptor_blob[0], blob_array[0]) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByBlobAndConstraints(self): - # Add Set - set_name = "findwith_blob_const" - dims = 128 - total = 5 - self.create_set_and_insert(set_name, dims, total) - - db = self.create_connection() - - kn = 3 - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - finddescriptor["k_neighbors"] = kn - - results = {} - results["list"] = ["myid", "_id", "_distance"] - results["blob"] = True - finddescriptor["results"] = results - - constraints = {} - constraints["myid"] = ["==", 202] - finddescriptor["constraints"] = constraints - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries = [] - all_queries.append(query) - - descriptor_blob = [] - x = np.ones(dims) - x[2] = 2.34 + 2 * 20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - response, blob_array = db.query(all_queries, [descriptor_blob]) - - self.assertEqual(len(blob_array), 1) - self.assertEqual(descriptor_blob[0], blob_array[0]) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], 1) - - self.assertEqual(response[0]["FindDescriptor"]["entities"][0]["_distance"], 0) - self.disconnect(db) - - # @unittest.skip("Skipping class until fixed") - def test_findDescByBlobWithLink(self): - # Add Set - set_name = "findwith_blob_link" - dims = 128 - total = 3 - - db = self.create_connection() - - all_queries = [] - - # Add Set - descriptor_set = {} - descriptor_set["name"] = set_name - descriptor_set["dimensions"] = dims - - query = {} - query["AddDescriptorSet"] = descriptor_set - - all_queries.append(query) - - response, img_array = db.query(all_queries) - self.assertEqual(response[0]["AddDescriptorSet"]["status"], 0) - - all_queries = [] - descriptor_blob = [] - - class_counter = -1 - for i in range(0, total): # -1): - if (i % 4) == 0: - class_counter += 1 - - reference = i + 2 - - x = np.ones(dims) - x[2] = 2.34 + i * 20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - descriptor = {} - descriptor["set"] = set_name - descriptor["label"] = "class" + str(class_counter) - - props = {} - props["myid"] = i + 200 - descriptor["properties"] = props - descriptor["_ref"] = reference - - query = {} - query["AddDescriptor"] = descriptor - - all_queries.append(query) - - props = {} - props["entity_prop"] = i + 200 - - addEntity = {} - addEntity["properties"] = props - addEntity["class"] = "randomentity" - - link = {} - link["ref"] = reference - addEntity["link"] = link - - query = {} - query["AddEntity"] = addEntity - - all_queries.append(query) - - response, img_array = db.query(all_queries, [descriptor_blob]) - - # Check success - for x in range(0, total - 1, 2): - self.assertEqual(response[x]["AddDescriptor"]["status"], 0) - self.assertEqual(response[x + 1]["AddEntity"]["status"], 0) - - kn = 3 - reference = 102 # because I can - - all_queries = [] - - finddescriptor = {} - finddescriptor["set"] = set_name - - results = {} - results["list"] = ["myid", "_id", "_distance"] - results["blob"] = True - finddescriptor["results"] = results - finddescriptor["k_neighbors"] = kn - finddescriptor["_ref"] = reference - - query = {} - query["FindDescriptor"] = finddescriptor - - all_queries.append(query) - - descriptor_blob = [] - x = np.ones(dims) - x[2] = 2.34 + 1 * 20 - x = x.astype("float32") - descriptor_blob.append(x.tobytes()) - - results = {} - results["list"] = ["entity_prop"] - results["sort"] = "entity_prop" - - link = {} - link["ref"] = reference - - findEntity = {} - findEntity["results"] = results - findEntity["class"] = "randomentity" - findEntity["link"] = link - - query = {} - query["FindEntity"] = findEntity - - all_queries.append(query) - - response, blob_array = db.query(all_queries, [descriptor_blob]) - - self.assertEqual(len(blob_array), kn) - # This checks that the received blobs is the same as the inserted. - self.assertEqual(descriptor_blob[0], blob_array[0]) - - # Check success - self.assertEqual(response[0]["FindDescriptor"]["status"], 0) - self.assertEqual(response[0]["FindDescriptor"]["returned"], kn) - - self.assertEqual(response[0]["FindDescriptor"]["entities"][0]["_distance"], 0) - self.assertEqual(response[0]["FindDescriptor"]["entities"][1]["_distance"], 400) - self.assertEqual(response[0]["FindDescriptor"]["entities"][2]["_distance"], 400) - - self.assertEqual(response[1]["FindEntity"]["status"], 0) - self.assertEqual(response[1]["FindEntity"]["returned"], kn) - - self.assertEqual(response[1]["FindEntity"]["entities"][0]["entity_prop"], 200) - self.assertEqual(response[1]["FindEntity"]["entities"][1]["entity_prop"], 201) - self.assertEqual(response[1]["FindEntity"]["entities"][2]["entity_prop"], 202) - self.disconnect(db) diff --git a/tests/python/prep.py b/tests/python/prep.py deleted file mode 100644 index 0813243d..00000000 --- a/tests/python/prep.py +++ /dev/null @@ -1,147 +0,0 @@ -from cryptography import x509 -from cryptography.x509.oid import NameOID -from cryptography.hazmat.primitives import hashes -from cryptography.hazmat.primitives.asymmetric import rsa -from cryptography.hazmat.primitives.serialization import ( - Encoding, - PrivateFormat, - BestAvailableEncryption, - NoEncryption, -) -from cryptography.hazmat.backends import default_backend -import datetime -import os - - -def generate_private_key(): - return rsa.generate_private_key( - public_exponent=65537, key_size=2048, backend=default_backend() - ) - - -def generate_ca_certificate(subject_name, private_key): - subject = issuer = x509.Name( - [ - x509.NameAttribute(NameOID.COUNTRY_NAME, "US"), - x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "Oregon"), - x509.NameAttribute(NameOID.LOCALITY_NAME, "Hillsboro"), - x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Intel Corporation"), - x509.NameAttribute(NameOID.COMMON_NAME, subject_name), - ] - ) - - certificate = ( - x509.CertificateBuilder() - .subject_name(subject) - .issuer_name(issuer) - .public_key(private_key.public_key()) - .serial_number(x509.random_serial_number()) - .not_valid_before(datetime.datetime.utcnow()) - .not_valid_after( - # Our certificate will be valid for 10 days - datetime.datetime.utcnow() - + datetime.timedelta(days=10) - ) - .add_extension( - x509.BasicConstraints(ca=True, path_length=None), - critical=True, - ) - .sign(private_key, hashes.SHA256(), default_backend()) - ) - - return certificate - - -def generate_signed_certificate( - subject_name, issuer_certificate, issuer_private_key, subject_private_key -): - subject = x509.Name( - [ - x509.NameAttribute(NameOID.COUNTRY_NAME, "US"), - x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "Oregon"), - x509.NameAttribute(NameOID.LOCALITY_NAME, "Hillsboro"), - x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Intel Corporation"), - x509.NameAttribute(NameOID.COMMON_NAME, subject_name), - ] - ) - - issuer = issuer_certificate.subject - - certificate = ( - x509.CertificateBuilder() - .subject_name(subject) - .issuer_name(issuer) - .public_key(subject_private_key.public_key()) - .serial_number(x509.random_serial_number()) - .not_valid_before(datetime.datetime.utcnow()) - .not_valid_after( - # Our certificate will be valid for 10 days - datetime.datetime.utcnow() - + datetime.timedelta(days=10) - ) - .add_extension( - x509.BasicConstraints(ca=False, path_length=None), - critical=True, - ) - .add_extension( - x509.SubjectAlternativeName([x509.DNSName(subject_name)]), - critical=False, - ) - .sign(issuer_private_key, hashes.SHA256(), default_backend()) - ) - - return certificate - - -def write_to_disk(directory, name, key, cert): - with open(os.path.join(directory, f"{name}_key.pem"), "wb") as f: - f.write(key.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption())) - - with open(os.path.join(directory, f"{name}_cert.pem"), "wb") as f: - f.write(cert.public_bytes(Encoding.PEM)) - - -if __name__ == "__main__": - - ##################################################################################### - # GENERATE TRUSTED CERTS AND KEYS - ##################################################################################### - # Generate CA key and certificate - trusted_ca_key = generate_private_key() - trusted_ca_cert = generate_ca_certificate("ca.vdms.local", trusted_ca_key) - - # Generate server key and certificate signed by CA - server_key = generate_private_key() - server_cert = generate_signed_certificate( - "localhost", trusted_ca_cert, trusted_ca_key, server_key - ) - - # Generate client key and certificate signed by CA - trusted_client_key = generate_private_key() - trusted_client_cert = generate_signed_certificate( - "client.vdms.local", trusted_ca_cert, trusted_ca_key, trusted_client_key - ) - - # Write keys and certificates to disk - write_to_disk("/tmp", "trusted_ca", trusted_ca_key, trusted_ca_cert) - write_to_disk("/tmp", "trusted_server", server_key, server_cert) - write_to_disk("/tmp", "trusted_client", trusted_client_key, trusted_client_cert) - - ##################################################################################### - # GENERATE UNTRUSTED CERTS AND KEYS TO ENSURE UNTRUSTED CLIENT CERTS AREN'T ACCEPTED - ##################################################################################### - # Generate CA key and certificate - untrusted_ca_key = generate_private_key() - untrusted_ca_cert = generate_ca_certificate("ca.vdms.local", untrusted_ca_key) - - # Generate client key and certificate signed by CA - untrusted_client_key = generate_private_key() - untrusted_client_cert = generate_signed_certificate( - "client.vdms.local", untrusted_ca_cert, untrusted_ca_key, untrusted_client_key - ) - - # Write keys and certificates to disk - write_to_disk("/tmp", "untrusted_ca", untrusted_ca_key, untrusted_ca_cert) - write_to_disk( - "/tmp", "untrusted_client", untrusted_client_key, untrusted_client_cert - ) diff --git a/tests/remote_function_test/requirements.txt b/tests/remote_function_test/requirements.txt deleted file mode 100644 index 60864807..00000000 --- a/tests/remote_function_test/requirements.txt +++ /dev/null @@ -1,5 +0,0 @@ -opencv-python==4.5.5.64 -flask==3.0.2 -numpy==1.26.4 -sk-video==1.1.10 -imutils==0.5.4 \ No newline at end of file diff --git a/tests/tls_test/prep-tls-tests.py b/tests/tls_test/prep-tls-tests.py deleted file mode 100644 index 6e9409fc..00000000 --- a/tests/tls_test/prep-tls-tests.py +++ /dev/null @@ -1,238 +0,0 @@ -from cryptography import x509 -from cryptography.x509.oid import NameOID -from cryptography.hazmat.primitives import hashes -from cryptography.hazmat.primitives.asymmetric import rsa -from cryptography.hazmat.primitives.serialization import ( - Encoding, - PrivateFormat, - BestAvailableEncryption, - NoEncryption, -) -from cryptography.hazmat.backends import default_backend -import datetime -import os -import socket -import ssl -import time - - -def print_and_flush(message): - print(message, flush=True) - - -class TLSClient: - def __init__(self, ca_cert_path, client_cert_path, client_key_path, timeout=1800): - self.ca_cert_path = ca_cert_path - self.client_cert_path = client_cert_path - self.client_key_path = client_key_path - self.timeout = timeout - self.host = "localhost" - self.port = 43445 - - def create_connection(self): - context = ssl.create_default_context( - ssl.Purpose.SERVER_AUTH, cafile=self.ca_cert_path - ) - context.load_cert_chain( - certfile=self.client_cert_path, keyfile=self.client_key_path - ) - - start_time = time.time() - end_time = start_time + self.timeout - - while time.time() < end_time: - try: - with socket.create_connection( - (self.host, self.port), timeout=self.timeout - ) as sock: - with context.wrap_socket(sock, server_hostname=self.host) as ssock: - print_and_flush("Connection established.") - self.handle_connection(ssock) - return - except (ConnectionRefusedError, socket.timeout) as e: - time.sleep( - 0.1 - ) # wait a bit before retrying to avoid flooding with attempts - - elapsed_time = time.time() - start_time - print( - f"Connection attempts failed. Timed out after {elapsed_time:.2f} seconds." - ) - - def handle_connection(self, ssock): - try: - # Read data from server, if any - size_data = ssock.read(4) - recv_size = int.from_bytes(size_data, byteorder="little") - print_and_flush(f"Received size: {recv_size}") - - buffer = b"" - while len(buffer) < recv_size: - data = ssock.read(1024) - print_and_flush(f"Received data: {data}") - if data == "": - print_and_flush("socket connection broken") - break - buffer += data - - print_and_flush(f"Received from server: {buffer.decode()}") - - # Send response to the server - msg = b"client sends some random data" - send_size = len(msg) - ssock.write(send_size.to_bytes(4, byteorder="little")) - print_and_flush(f"Sent size: {send_size}") - - bytes_sent = 0 - while bytes_sent < send_size: - sent = ssock.write(msg[bytes_sent:]) - print_and_flush(f"Sent {sent} bytes to the server.") - if sent == 0: - print_and_flush("socket connection broken") - raise RuntimeError("socket connection broken") - bytes_sent += sent - print_and_flush("Sent response to the server.") - except Exception as e: - print_and_flush(f"Error during communication: {e}") - - -def generate_private_key(): - return rsa.generate_private_key( - public_exponent=65537, key_size=2048, backend=default_backend() - ) - - -def generate_ca_certificate(subject_name, private_key): - subject = issuer = x509.Name( - [ - x509.NameAttribute(NameOID.COUNTRY_NAME, "US"), - x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "Oregon"), - x509.NameAttribute(NameOID.LOCALITY_NAME, "Hillsboro"), - x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Intel Corporation"), - x509.NameAttribute(NameOID.COMMON_NAME, subject_name), - ] - ) - - certificate = ( - x509.CertificateBuilder() - .subject_name(subject) - .issuer_name(issuer) - .public_key(private_key.public_key()) - .serial_number(x509.random_serial_number()) - .not_valid_before(datetime.datetime.utcnow()) - .not_valid_after( - # Our certificate will be valid for 10 days - datetime.datetime.utcnow() - + datetime.timedelta(days=10) - ) - .add_extension( - x509.BasicConstraints(ca=True, path_length=None), - critical=True, - ) - .sign(private_key, hashes.SHA256(), default_backend()) - ) - - return certificate - - -def generate_signed_certificate( - subject_name, issuer_certificate, issuer_private_key, subject_private_key -): - subject = x509.Name( - [ - x509.NameAttribute(NameOID.COUNTRY_NAME, "US"), - x509.NameAttribute(NameOID.STATE_OR_PROVINCE_NAME, "Oregon"), - x509.NameAttribute(NameOID.LOCALITY_NAME, "Hillsboro"), - x509.NameAttribute(NameOID.ORGANIZATION_NAME, "Intel Corporation"), - x509.NameAttribute(NameOID.COMMON_NAME, subject_name), - ] - ) - - issuer = issuer_certificate.subject - - certificate = ( - x509.CertificateBuilder() - .subject_name(subject) - .issuer_name(issuer) - .public_key(subject_private_key.public_key()) - .serial_number(x509.random_serial_number()) - .not_valid_before(datetime.datetime.utcnow()) - .not_valid_after( - # Our certificate will be valid for 10 days - datetime.datetime.utcnow() - + datetime.timedelta(days=10) - ) - .add_extension( - x509.BasicConstraints(ca=False, path_length=None), - critical=True, - ) - .add_extension( - x509.SubjectAlternativeName([x509.DNSName(subject_name)]), - critical=False, - ) - .sign(issuer_private_key, hashes.SHA256(), default_backend()) - ) - - return certificate - - -def write_to_disk(directory, name, key, cert): - with open(os.path.join(directory, f"{name}_key.pem"), "wb") as f: - f.write(key.private_bytes(Encoding.PEM, PrivateFormat.PKCS8, NoEncryption())) - - with open(os.path.join(directory, f"{name}_cert.pem"), "wb") as f: - f.write(cert.public_bytes(Encoding.PEM)) - - -if __name__ == "__main__": - - ##################################################################################### - # GENERATE TRUSTED CERTS AND KEYS - ##################################################################################### - # Generate CA key and certificate - trusted_ca_key = generate_private_key() - trusted_ca_cert = generate_ca_certificate("ca.vdms.local", trusted_ca_key) - - # Generate server key and certificate signed by CA - server_key = generate_private_key() - server_cert = generate_signed_certificate( - "localhost", trusted_ca_cert, trusted_ca_key, server_key - ) - - # Generate client key and certificate signed by CA - trusted_client_key = generate_private_key() - trusted_client_cert = generate_signed_certificate( - "client.vdms.local", trusted_ca_cert, trusted_ca_key, trusted_client_key - ) - - # Write keys and certificates to disk - write_to_disk("/tmp", "trusted_ca", trusted_ca_key, trusted_ca_cert) - write_to_disk("/tmp", "trusted_server", server_key, server_cert) - write_to_disk("/tmp", "trusted_client", trusted_client_key, trusted_client_cert) - - ##################################################################################### - # GENERATE UNTRUSTED CERTS AND KEYS TO ENSURE UNTRUSTED CLIENT CERTS AREN'T ACCEPTED - ##################################################################################### - # Generate CA key and certificate - untrusted_ca_key = generate_private_key() - untrusted_ca_cert = generate_ca_certificate("ca.vdms.local", untrusted_ca_key) - - # Generate client key and certificate signed by CA - untrusted_client_key = generate_private_key() - untrusted_client_cert = generate_signed_certificate( - "client.vdms.local", untrusted_ca_cert, untrusted_ca_key, untrusted_client_key - ) - - # Write keys and certificates to disk - write_to_disk("/tmp", "untrusted_ca", untrusted_ca_key, untrusted_ca_cert) - write_to_disk( - "/tmp", "untrusted_client", untrusted_client_key, untrusted_client_cert - ) - - tls_client = TLSClient( - ca_cert_path="/tmp/trusted_ca_cert.pem", - client_cert_path="/tmp/trusted_client_cert.pem", - client_key_path="/tmp/trusted_client_key.pem", - timeout=1800, - ) - tls_client.create_connection() diff --git a/tests/udf_test/requirements.txt b/tests/udf_test/requirements.txt deleted file mode 100644 index 23c96db1..00000000 --- a/tests/udf_test/requirements.txt +++ /dev/null @@ -1,2 +0,0 @@ -opencv-python==4.5.5.64 -zmq==0.0.0 \ No newline at end of file diff --git a/utils/include/chrono/Chrono.h b/utils/include/chrono/Chrono.h deleted file mode 100644 index 098cd505..00000000 --- a/utils/include/chrono/Chrono.h +++ /dev/null @@ -1,186 +0,0 @@ -/** - * @section LICENSE - * - * The MIT License - * - * @copyright Copyright (c) 2017 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, - * merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#ifndef CHRONO_H_ -#define CHRONO_H_ - -#include -#include -#include -#include - -#include - -// Apple OSX -#ifdef __MACH__ -#include -#include -#endif - -#ifdef CHRONO_TIMING -#define CHRONO_TIC(NAME) NAME.tic(); -#define CHRONO_TAC(NAME) NAME.tac(); -#define CHRONO_PRINT_LAST_MS(NAME) NAME.printLastTime_ms(); -#else -#define CHRONO_TIC(NAME) -#define CHRONO_TAC(NAME) -#define CHRONO_PRINT_LAST_MS(NAME) -#endif - -// *************************************************************************** -// Chrono Base class -// *************************************************************************** -class Chrono { -public: - Chrono(const std::string &name, const bool asyncEnabled = false); - Chrono(); - virtual ~Chrono(void); - - void tic(void); - void tac(void); - void reset(void); - void setEnabled(const bool val); - - struct ChronoStats { - std::string name; - uint32_t counter; - float totalTime_ms; - float totalSquaredTime_ms2; - float averageTime_ms; - float stdDevTime_ms; - float lastTime_ms; - float minTime_ms; - float maxTime_ms; - }; - - const Chrono::ChronoStats &getElapsedStats(void) const { - return elapsedStats; - } - - const Chrono::ChronoStats &getPeriodStats(void) const { return periodStats; } - - uint32_t getTotalTime_ms(void) const { return elapsedStats.totalTime_ms; } - - uint32_t getTotalTime_us(void) const { - return elapsedStats.totalTime_ms * 1000.0f; - } - - uint32_t getLastTime_ms(void) const { return elapsedStats.lastTime_ms; } - - uint32_t getLastTime_us(void) const { - return elapsedStats.lastTime_ms * 1000.0f; - } - - uint32_t getAvgTime_ms(void) const { return elapsedStats.averageTime_ms; } - - uint32_t getAvgTime_us(void) const { - return elapsedStats.averageTime_ms * 1000.0f; - } - - uint32_t getSTD_ms(void) const { return elapsedStats.stdDevTime_ms; } - - uint32_t getSTD_us(void) const { - return elapsedStats.stdDevTime_ms * 1000.0f; - } - - void printTotalTime_ms(void) const { - std::cout << name << ": " << getTotalTime_ms() << " [ms]" << std::endl; - } - - void printTotalTime_us(void) const { - std::cout << name << ": " << getTotalTime_us() << " [us]" << std::endl; - } - - void printLastTime_ms(void) const { - std::cout << name << ": " << getLastTime_ms() << " [ms]" << std::endl; - } - - void printLastTime_us(void) const { - std::cout << name << ": " << getLastTime_us() << " [us]" << std::endl; - } - - void printAvgTime_ms(void) const { - std::cout << name << ": " << getAvgTime_ms() << " [ms]" << std::endl; - } - - void printAvgTime_us(void) const { - std::cout << name << ": " << getAvgTime_us() << " [us]" << std::endl; - } - - std::ostream &printStats(const Chrono::ChronoStats &stats, - std::ostream &os) const; - std::ostream &printAvgTime(const Chrono::ChronoStats &stats, - std::ostream &os) const; - std::ostream &printAvgTime(const Chrono::ChronoStats &stats, std::ostream &os, - const float ref) const; - -protected: - std::string name; - - bool enabled; - bool ticIdle; - uint32_t errors; - - ChronoStats elapsedStats; - ChronoStats periodStats; - - void resetStats(ChronoStats &stats); - void updateStats(ChronoStats &stats); - - virtual void doTic(void) = 0; - virtual void doTac(void) = 0; -}; - -// *************************************************************************** -// Chrono Cpu Implementation -// *************************************************************************** - -class ChronoCpu : public Chrono { -public: - ChronoCpu(const std::string &name); - ChronoCpu(); - ~ChronoCpu(void); - -protected: - timespec lastTicTime; - timespec ticTime; - timespec tacTime; - -#ifdef __MACH__ - clock_serv_t cclock; - mach_timespec_t mts; -#endif - - uint32_t ticCounter; - - virtual void doTic(void); - virtual void doTac(void); -}; - -#endif // CHRONO_H_ diff --git a/utils/src/chrono/Chrono.cc b/utils/src/chrono/Chrono.cc deleted file mode 100644 index 97462f29..00000000 --- a/utils/src/chrono/Chrono.cc +++ /dev/null @@ -1,235 +0,0 @@ -/** - * @section LICENSE - * - * The MIT License - * - * @copyright Copyright (c) 2017 Intel Corporation - * - * Permission is hereby granted, free of charge, to any person obtaining a copy - * of this software and associated documentation files (the "Software"), - * to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, - * merge, publish, distribute, sublicense, and/or sell - * copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in - * all copies or substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, - * ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN - * THE SOFTWARE. - * - */ - -#include -#include -#include - -#include - -#include "Chrono.h" - -using namespace std; - -// ***************************************************************************** -// Public methods definitions -// ***************************************************************************** -Chrono::Chrono(const string &name, const bool asyncEnabled) - : name(name), enabled(true) { - elapsedStats.name = "elapsedStats"; - periodStats.name = "periodStats"; - reset(); -} - -Chrono::Chrono() : Chrono("no_name") {} - -Chrono::~Chrono(void) {} - -void Chrono::tic(void) { - if (!enabled) { - return; - } - - if (ticIdle) { - ticIdle = false; - doTic(); - } else { - ++errors; - cerr << "Chrono::tic - " << name - << ": Calling Chrono::tic with no matching Chrono::tag!" << endl; - } -} - -void Chrono::tac(void) { - if (!enabled) { - return; - } - - if (!ticIdle) { - ticIdle = true; - doTac(); - } else { - ++errors; - cerr << "Chrono::tac - " << name - << ": Calling Chrono::tac with no matching Chrono::tic!" << endl; - } -} - -void Chrono::reset(void) { - ticIdle = true; - errors = 0; - resetStats(elapsedStats); - resetStats(periodStats); -} - -void Chrono::setEnabled(const bool val) { enabled = val; } - -std::ostream &Chrono::printStats(const Chrono::ChronoStats &stats, - std::ostream &os) const { - os.precision(2); - os << fixed; - os << name << ": " << stats.name << endl; - os << "\terrors: " << errors << endl; - os << "\ttotalTime: " << stats.totalTime_ms << " [ms]" << endl; - os << "\taverageTime: " << stats.averageTime_ms << " [ms]" << endl; - os << "\tstdDevTime: " << stats.stdDevTime_ms << " [ms]" << endl; - os << "\tlastTime: " << stats.lastTime_ms << " [ms]" << endl; - os << "\tminTime: " << stats.minTime_ms << " [ms]" << endl; - os << "\tmaxTime: " << stats.maxTime_ms << " [ms]" << endl; - - return os; -} - -std::ostream &Chrono::printAvgTime(const Chrono::ChronoStats &stats, - std::ostream &os) const { - os.precision(2); - os << fixed; - os << name << ": " << stats.name << " -> " - << "averageTime: " << stats.averageTime_ms << " [ms]" << endl; - - return os; -} - -std::ostream &Chrono::printAvgTime(const Chrono::ChronoStats &stats, - std::ostream &os, const float ref) const { - os.precision(2); - os << fixed; - os << name << ": " << stats.name << " -> " - << "averageTime: " << stats.averageTime_ms << " [ms] ("; - os << (stats.averageTime_ms / ref * 100.0f) << "%)" << endl; - - return os; -} - -// ***************************************************************************** -// Private/Protected methods definitions -// ***************************************************************************** -void Chrono::resetStats(ChronoStats &stats) { - stats.counter = 0; - stats.totalTime_ms = 0.0f; - stats.totalSquaredTime_ms2 = 0.0f; - stats.averageTime_ms = 0.0f; - stats.stdDevTime_ms = 0.0f; - stats.lastTime_ms = 0.0f; - stats.minTime_ms = 0.0f; - stats.maxTime_ms = 0.0f; -} - -void Chrono::updateStats(ChronoStats &stats) { - ++stats.counter; - stats.totalTime_ms += stats.lastTime_ms; - stats.totalSquaredTime_ms2 += stats.lastTime_ms * stats.lastTime_ms; - stats.averageTime_ms = stats.totalTime_ms / (float)stats.counter; - stats.stdDevTime_ms = - sqrtf(stats.totalSquaredTime_ms2 / (float)stats.counter - - stats.averageTime_ms * stats.averageTime_ms); - if (stats.counter > 1) { - stats.maxTime_ms = max(stats.lastTime_ms, stats.maxTime_ms); - stats.minTime_ms = min(stats.lastTime_ms, stats.minTime_ms); - } else { - stats.maxTime_ms = stats.lastTime_ms; - stats.minTime_ms = stats.lastTime_ms; - } -} - -// ***************************************************************************** -// ChronoCpu Implementation -// ***************************************************************************** - -ChronoCpu::ChronoCpu(const string &name) : Chrono(name), ticCounter(0) { - memset((void *)&lastTicTime, 0, sizeof(lastTicTime)); - memset((void *)&ticTime, 0, sizeof(ticTime)); - memset((void *)&tacTime, 0, sizeof(tacTime)); - -#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time - host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); -#endif -} - -ChronoCpu::~ChronoCpu(void) { -#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time - mach_port_deallocate(mach_task_self(), cclock); -#endif -} - -ChronoCpu::ChronoCpu() : ChronoCpu("no_name") {} - -// ***************************************************************************** -// Private/Protected methods definitions -// ***************************************************************************** -void ChronoCpu::doTic(void) { - lastTicTime = ticTime; - -#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time - clock_get_time(cclock, &mts); - ticTime.tv_sec = mts.tv_sec; - ticTime.tv_nsec = mts.tv_nsec; -#else - if (clock_gettime(CLOCK_REALTIME, &ticTime) != 0) { - ++errors; - cerr << "ChronoCpu::doTic - " << name << ": clock_gettime() failed!" - << endl; - return; - } -#endif - - ++ticCounter; - - if (ticCounter > 1) { - float period_s = (float)(ticTime.tv_sec - lastTicTime.tv_sec); - float period_ns = (float)(ticTime.tv_nsec - lastTicTime.tv_nsec); - periodStats.lastTime_ms = period_s * 1e3f + period_ns / 1e6f; - updateStats(periodStats); - } -} - -void ChronoCpu::doTac(void) { -#ifdef __MACH__ // OS X does not have clock_gettime, use clock_get_time - clock_serv_t cclock; - mach_timespec_t mts; - host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock); - clock_get_time(cclock, &mts); - mach_port_deallocate(mach_task_self(), cclock); - tacTime.tv_sec = mts.tv_sec; - tacTime.tv_nsec = mts.tv_nsec; - -#else - if (clock_gettime(CLOCK_REALTIME, &tacTime) != 0) { - ++errors; - cerr << "ChronoCpu::doTac - " << name << ": clock_gettime() failed!" - << endl; - return; - } -#endif - - float elapsed_s = (float)(tacTime.tv_sec - ticTime.tv_sec); - float elapsed_ns = (float)(tacTime.tv_nsec - ticTime.tv_nsec); - elapsedStats.lastTime_ms = elapsed_s * 1e3f + elapsed_ns / 1e6f; - updateStats(elapsedStats); -}