From f8fb54faef6b40c40e2710248a5a2a8852d0fe56 Mon Sep 17 00:00:00 2001 From: Mamy Ratsimbazafy Date: Sun, 7 Jun 2020 19:39:34 +0200 Subject: [PATCH] Build and run tests in parallel (#41) * Build and run tests in parallel * Workaround travis OSX Homebrew bug * semicolons ... * Don't auto-update before installing homebrew packages --- .gitignore | 3 ++ .travis.yml | 8 +++- azure-pipelines.yml | 2 +- constantine.nimble | 106 +++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 112 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index 79130a5..0f21d03 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,6 @@ build/ # Sage *.sage.py + +# Tests +test_*.txt diff --git a/.travis.yml b/.travis.yml index d172ad6..aa55f63 100644 --- a/.travis.yml +++ b/.travis.yml @@ -51,11 +51,17 @@ addons: apt: packages: - libgmp-dev + - parallel homebrew: packages: - gmp + # Travis `bundle` bug: https://travis-ci.community/t/macos-build-fails-because-of-homebrew-bundle-unknown-command/7296/28 + # - parallel before_install: + - if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then + HOMEBREW_NO_AUTO_UPDATE=1 brew install parallel; + fi - | if [ "${CHANNEL}" = stable ]; then BRANCH="v$(curl https://nim-lang.org/channels/stable)" @@ -92,7 +98,7 @@ before_script: script: - nimble refresh - nimble install gmp stew - - nimble test + - nimble test_parallel branches: except: - gh-pages diff --git a/azure-pipelines.yml b/azure-pipelines.yml index c379eaa..38ed9d4 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -185,7 +185,7 @@ steps: - bash: | echo "PATH=${PATH}" export ucpu=${UCPU} - nimble test + nimble test_parallel displayName: 'Testing the package (including GMP)' condition: ne(variables['Agent.OS'], 'Windows_NT') diff --git a/constantine.nimble b/constantine.nimble index 01f43bd..e718117 100644 --- a/constantine.nimble +++ b/constantine.nimble @@ -8,8 +8,12 @@ srcDir = "src" ### Dependencies requires "nim >= 1.1.0" +const buildParallel = "test_parallel.txt" + ### Helper functions -proc test(flags, path: string) = +proc test(flags, path: string, commandFile = false) = + # commandFile should be a "file" but Nimscript doesn't support IO + # TODO: use a proper runner if not dirExists "build": mkDir "build" # Compilation language is controlled by WEAVE_TEST_LANG @@ -21,10 +25,16 @@ proc test(flags, path: string) = if existsEnv"CC": cc = " --cc:" & getEnv"CC" - echo "\n========================================================================================" - echo "Running [flags: ", flags, "] ", path - echo "========================================================================================" - exec "nim " & lang & cc & " " & flags & " --verbosity:0 --outdir:build -r --hints:off --warnings:off " & path + let command = "nim " & lang & cc & " " & flags & " --verbosity:0 --outdir:build -r --hints:off --warnings:off " & path + + if not commandFile: + echo "\n========================================================================================" + echo "Running [flags: ", flags, "] ", path + echo "========================================================================================" + exec command + else: + # commandFile.writeLine command + exec "echo \'" & command & "\' >> " & buildParallel proc runBench(benchName: string, compiler = "") = if not dirExists "build": @@ -174,6 +184,92 @@ task test_no_gmp, "Run tests that don't require GMP": runBench("bench_fp12") runBench("bench_ec_swei_proj_g1") +task test_parallel, "Run all tests in parallel (via GNU parallel)": + # -d:testingCurves is configured in a *.nim.cfg for convenience + let cmdFile = true # open(buildParallel, mode = fmWrite) # Nimscript doesn't support IO :/ + exec "> " & buildParallel + + # Primitives + test "", "tests/test_primitives.nim", cmdFile + + # Big ints + test "", "tests/test_io_bigints.nim", cmdFile + test "", "tests/test_bigints.nim", cmdFile + test "", "tests/test_bigints_multimod.nim", cmdFile + + test "", "tests/test_bigints_vs_gmp.nim", cmdFile + + # Field + test "", "tests/test_io_fields", cmdFile + test "", "tests/test_finite_fields.nim", cmdFile + test "", "tests/test_finite_fields_mulsquare.nim", cmdFile + test "", "tests/test_finite_fields_sqrt.nim", cmdFile + test "", "tests/test_finite_fields_powinv.nim", cmdFile + + test "", "tests/test_finite_fields_vs_gmp.nim", cmdFile + + # Towers of extension fields + test "", "tests/test_fp2.nim", cmdFile + test "", "tests/test_fp6.nim", cmdFile + test "", "tests/test_fp12.nim", cmdFile + + # Elliptic curve arithmetic + test "", "tests/test_ec_weierstrass_projective_g1.nim", cmdFile + test "", "tests/test_ec_bn254.nim", cmdFile + test "", "tests/test_ec_bls12_381.nim", cmdFile + + # cmdFile.close() + # Execute everything in parallel with GNU parallel + exec "parallel --keep-order --group < " & buildParallel + + exec "> " & buildParallel + + if sizeof(int) == 8: # 32-bit tests on 64-bit arch + # Primitives + test "-d:Constantine32", "tests/test_primitives.nim", cmdFile + + # Big ints + test "-d:Constantine32", "tests/test_io_bigints.nim", cmdFile + test "-d:Constantine32", "tests/test_bigints.nim", cmdFile + test "-d:Constantine32", "tests/test_bigints_multimod.nim", cmdFile + + test "-d:Constantine32", "tests/test_bigints_vs_gmp.nim", cmdFile + + # Field + test "-d:Constantine32", "tests/test_io_fields", cmdFile + test "-d:Constantine32", "tests/test_finite_fields.nim", cmdFile + test "-d:Constantine32", "tests/test_finite_fields_mulsquare.nim", cmdFile + test "-d:Constantine32", "tests/test_finite_fields_sqrt.nim", cmdFile + test "-d:Constantine32", "tests/test_finite_fields_powinv.nim", cmdFile + + test "-d:Constantine32", "tests/test_finite_fields_vs_gmp.nim", cmdFile + + # Towers of extension fields + test "-d:Constantine32", "tests/test_fp2.nim", cmdFile + test "-d:Constantine32", "tests/test_fp6.nim", cmdFile + test "-d:Constantine32", "tests/test_fp12.nim", cmdFile + + # Elliptic curve arithmetic + test "-d:Constantine32", "tests/test_ec_weierstrass_projective_g1.nim", cmdFile + test "-d:Constantine32", "tests/test_ec_bn254.nim", cmdFile + test "-d:Constantine32", "tests/test_ec_bls12_381.nim", cmdFile + + # cmdFile.close() + # Execute everything in parallel with GNU parallel + exec "parallel --keep-order --group < " & buildParallel + + # Now run the benchmarks + # + # Benchmarks compile and run + # ignore Windows 32-bit for the moment + # Ensure benchmarks stay relevant. Ignore Windows 32-bit at the moment + if not defined(windows) or not (existsEnv"UCPU" or getEnv"UCPU" == "i686"): + runBench("bench_fp") + runBench("bench_fp2") + runBench("bench_fp6") + runBench("bench_fp12") + runBench("bench_ec_swei_proj_g1") + task bench_fp, "Run benchmark 𝔽p with your default compiler": runBench("bench_fp")