This is an automated email from the ASF dual-hosted git repository. sandreoli pushed a commit to branch issue7-schnorr-python-wrapper in repository https://gitbox.apache.org/repos/asf/incubator-milagro-MPC.git
commit 25e11170b886b97338bb590641cee9085b6e8034 Author: Samuele Andreoli <[email protected]> AuthorDate: Tue Feb 18 14:03:07 2020 +0000 Refactor tests --- Dockerfile | 2 +- python/CMakeLists.txt | 35 +------------------------- python/amcl/CMakeLists.txt | 2 +- python/test/CMakeLists.txt | 53 +++++++++++++++++++++++++++++++++++++++ python/test/context.py | 25 ++++++++++++++++++ python/{ => test}/test_ecdsa.py | 3 ++- python/{ => test}/test_mta.py | 5 ++-- python/{ => test}/test_r.py | 4 +-- python/{ => test}/test_s.py | 4 +-- python/{ => test}/test_schnorr.py | 2 +- 10 files changed, 91 insertions(+), 44 deletions(-) diff --git a/Dockerfile b/Dockerfile index fb02245..465d617 100755 --- a/Dockerfile +++ b/Dockerfile @@ -26,7 +26,7 @@ FROM ubuntu:bionic -MAINTAINER [email protected] +LABEL maintainer="[email protected]" WORKDIR /root diff --git a/python/CMakeLists.txt b/python/CMakeLists.txt index c53f313..55b719c 100644 --- a/python/CMakeLists.txt +++ b/python/CMakeLists.txt @@ -18,37 +18,4 @@ cmake_minimum_required(VERSION 3.1 FATAL_ERROR) include(PythonSiteDirs) add_subdirectory(amcl) - -file(COPY test_mta.py DESTINATION "${PROJECT_BINARY_DIR}/python/") -file(COPY test_r.py DESTINATION "${PROJECT_BINARY_DIR}/python/") -file(COPY test_s.py DESTINATION "${PROJECT_BINARY_DIR}/python/") -file(COPY test_ecdsa.py DESTINATION "${PROJECT_BINARY_DIR}/python/") -file(COPY test_schnorr.py DESTINATION "${PROJECT_BINARY_DIR}/python/") - -file(COPY "${PROJECT_SOURCE_DIR}/testVectors/mpc/MTA.json" DESTINATION "${PROJECT_BINARY_DIR}/python/") -file(COPY "${PROJECT_SOURCE_DIR}/testVectors/mpc/R.json" DESTINATION "${PROJECT_BINARY_DIR}/python/") -file(COPY "${PROJECT_SOURCE_DIR}/testVectors/mpc/S.json" DESTINATION "${PROJECT_BINARY_DIR}/python/") - -file(GLOB SCHNORR_TV "${PROJECT_SOURCE_DIR}/testVectors/schnorr/*.json") -file(COPY ${SCHNORR_TV} DESTINATION "${PROJECT_BINARY_DIR}/python/schnorr/") - -if(NOT CMAKE_BUILD_TYPE STREQUAL "ASan") - add_test(test_python_mpc_mta python3 test_mta.py) - add_test(test_python_mpc_r python3 test_r.py) - add_test(test_python_mpc_s python3 test_s.py) - add_test(test_python_mpc_ecdsa python3 test_ecdsa.py) - add_test(test_python_mpc_schnorr python3 test_schnorr.py) -endif(NOT CMAKE_BUILD_TYPE STREQUAL "ASan") - -# Set the LD_LIBRARY_PATH or equivalent to the libraries can be loaded when -# running the test. -#if(CMAKE_SYSTEM_NAME MATCHES "Darwin") -# set(ld_library_path_var "DYLD_LIBRARY_PATH") -#elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") -# set(ld_library_path_var "LD_LIBRARY_PATH") -#elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") -# set(ld_library_path_var "PATH") -#endif() -#set_tests_properties(test_python_mpc_mta PROPERTIES ENVIRONMENT -# "${ld_library_path_var}=${CMAKE_LIBRARY_OUTPUT_DIRECTORY}") - +add_subdirectory(test) diff --git a/python/amcl/CMakeLists.txt b/python/amcl/CMakeLists.txt index b92ebd8..ca45bda 100644 --- a/python/amcl/CMakeLists.txt +++ b/python/amcl/CMakeLists.txt @@ -16,4 +16,4 @@ file(GLOB SRCS *.py) file(COPY ${SRCS} DESTINATION "${PROJECT_BINARY_DIR}/python/amcl") -install(FILES ${SRCS} DESTINATION ${PYTHON_SITE_PACKAGES}/amcl) +install(FILES ${SRCS} DESTINATION ${PYTHON_SITE_PACKAGES}/amcl) diff --git a/python/test/CMakeLists.txt b/python/test/CMakeLists.txt new file mode 100644 index 0000000..a01ddf4 --- /dev/null +++ b/python/test/CMakeLists.txt @@ -0,0 +1,53 @@ +# Licensed to the Apache Software Foundation (ASF) under one or more contributor +# license agreements. See the NOTICE file distributed with this work for +# additional information regarding copyright ownership. The ASF licenses this +# file to you under the Apache License, Version 2.0 (the "License"); you may not +# use this file except in compliance with the License. You may obtain a copy of +# the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations under +# the License. + +# Set the LD_LIBRARY_PATH or equivalent to the libraries can be loaded when +# running the test. +if(CMAKE_SYSTEM_NAME MATCHES "Darwin") + set(ld_library_path_var "DYLD_LIBRARY_PATH") +elseif(CMAKE_SYSTEM_NAME MATCHES "Linux") + set(ld_library_path_var "LD_LIBRARY_PATH") +elseif(CMAKE_SYSTEM_NAME MATCHES "Windows") + set(ld_library_path_var "PATH") +endif() + +# Prepend the env dynamic library path with the mpc path +set(dynamic_library_path ${PROJECT_BINARY_DIR}/src:$ENV{${ld_library_path_var}}) + +function(add_python_test name source) + add_test(${name} python3 ${source}) + + set_tests_properties(${name} PROPERTIES ENVIRONMENT "${ld_library_path_var}=${dynamic_library_path}") +endfunction() + +# Tests +file(GLOB TESTS *.py) +file(COPY ${TESTS} DESTINATION "${PROJECT_BINARY_DIR}/python/test") + +# MPC test vectors +file(GLOB MPC_TV "${PROJECT_SOURCE_DIR}/testVectors/mpc/*.json") +file(COPY ${MPC_TV} DESTINATION "${PROJECT_BINARY_DIR}/python/test/mpc/") + +# Schnorr test vectors +file(GLOB SCHNORR_TV "${PROJECT_SOURCE_DIR}/testVectors/schnorr/*.json") +file(COPY ${SCHNORR_TV} DESTINATION "${PROJECT_BINARY_DIR}/python/test/schnorr/") + +if(NOT CMAKE_BUILD_TYPE STREQUAL "ASan") + add_python_test(test_python_mpc_mta test_mta.py) + add_python_test(test_python_mpc_r test_r.py) + add_python_test(test_python_mpc_s test_s.py) + add_python_test(test_python_mpc_ecdsa test_ecdsa.py) + add_python_test(test_python_mpc_schnorr test_schnorr.py) +endif(NOT CMAKE_BUILD_TYPE STREQUAL "ASan") diff --git a/python/test/context.py b/python/test/context.py new file mode 100644 index 0000000..c7a9ac2 --- /dev/null +++ b/python/test/context.py @@ -0,0 +1,25 @@ +""" +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +""" + +import os +import sys + +sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) + +from amcl import mpc, schnorr diff --git a/python/test_ecdsa.py b/python/test/test_ecdsa.py similarity index 99% rename from python/test_ecdsa.py rename to python/test/test_ecdsa.py index 1c60bfd..8a118be 100755 --- a/python/test_ecdsa.py +++ b/python/test/test_ecdsa.py @@ -18,10 +18,11 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + import unittest import json import os -from amcl import mpc +from context import mpc class TestECDSA(unittest.TestCase): diff --git a/python/test_mta.py b/python/test/test_mta.py similarity index 96% rename from python/test_mta.py rename to python/test/test_mta.py index 8a74971..dea53ae 100755 --- a/python/test_mta.py +++ b/python/test/test_mta.py @@ -18,16 +18,17 @@ KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. """ + import unittest import json -from amcl import mpc +from context import mpc class TestMtA(unittest.TestCase): """Tests MPC MtA""" def setUp(self): - with open("MTA.json", "r") as f: + with open("mpc/MTA.json", "r") as f: self.tv = json.load(f) for vector in self.tv: diff --git a/python/test_r.py b/python/test/test_r.py similarity index 97% rename from python/test_r.py rename to python/test/test_r.py index 2b53ca6..0a8034d 100755 --- a/python/test_r.py +++ b/python/test/test_r.py @@ -21,14 +21,14 @@ under the License. import unittest import json -from amcl import mpc +from context import mpc class TestR(unittest.TestCase): """Tests MPC R""" def setUp(self): - with open("R.json", "r") as f: + with open("mpc/R.json", "r") as f: self.tv = json.load(f) for vector in self.tv: diff --git a/python/test_s.py b/python/test/test_s.py similarity index 98% rename from python/test_s.py rename to python/test/test_s.py index ed07453..526e7fb 100755 --- a/python/test_s.py +++ b/python/test/test_s.py @@ -21,14 +21,14 @@ under the License. import unittest import json -from amcl import mpc +from context import mpc class TestS(unittest.TestCase): """Tests MPC S""" def setUp(self): - with open("S.json", "r") as f: + with open("mpc/S.json", "r") as f: self.tv = json.load(f) for vector in self.tv: diff --git a/python/test_schnorr.py b/python/test/test_schnorr.py similarity index 99% rename from python/test_schnorr.py rename to python/test/test_schnorr.py index e6b1b84..a232ac5 100755 --- a/python/test_schnorr.py +++ b/python/test/test_schnorr.py @@ -21,7 +21,7 @@ under the License. import unittest import json -from amcl import schnorr +from context import schnorr class TestCommit(unittest.TestCase):
