From 5a130006c2de2b194a61afbeca8f4b955c2bf622 Mon Sep 17 00:00:00 2001 From: Roland Schulz Date: Tue, 17 Jul 2018 18:39:01 -0700 Subject: [PATCH] Enable clang tidy/warnings for tests Also move check configuration into .clang-tidy file to allow running clang-tidy seperately from the build to apply automatic fixes. Also relaxes some scalar tests. Commit b9057925955f changed contants and relaxed SIMD tests without also relaxing scalar tests. Change-Id: Ia895e219502b665db7ca0effaa03af3d3d380256 --- docs/dev-manual/tools.rst | 28 +++++--- src/.clang-tidy | 12 ++++ src/CMakeLists.txt | 43 +++++++++++ src/external/.clang-tidy | 1 + .../include/gmock/gmock-spec-builders.h | 4 +- src/gromacs/CMakeLists.txt | 54 +------------- src/gromacs/analysisdata/tests/datatest.h | 2 +- src/gromacs/awh/tests/bias.cpp | 7 +- src/gromacs/awh/tests/biasstate.cpp | 7 +- src/gromacs/awh/tests/grid.cpp | 6 +- .../commandline/tests/cmdlinehelpmodule.cpp | 3 +- .../tests/cmdlineprogramcontext.cpp | 3 +- src/gromacs/compat/tests/make_unique.cpp | 6 +- .../correlationfunctions/tests/autocorr.cpp | 5 +- .../correlationfunctions/tests/expfit.cpp | 3 +- src/gromacs/ewald/tests/pmebsplinetest.cpp | 6 +- src/gromacs/ewald/tests/pmegathertest.cpp | 20 +++--- src/gromacs/ewald/tests/pmesolvetest.cpp | 6 +- .../ewald/tests/pmesplinespreadtest.cpp | 22 +++--- src/gromacs/ewald/tests/pmetestcommon.cpp | 4 +- .../ewald/tests/testhardwarecontexts.cpp | 1 - src/gromacs/fileio/tests/readinp.cpp | 4 +- src/gromacs/fileio/tests/tngio.cpp | 2 +- src/gromacs/gmxpreprocess/tests/genconf.cpp | 4 +- src/gromacs/gmxpreprocess/tests/readir.cpp | 4 +- src/gromacs/gmxpreprocess/tests/solvate.cpp | 4 +- src/gromacs/linearalgebra/.clang-tidy | 1 + src/gromacs/math/tests/functions.cpp | 9 +-- src/gromacs/math/tests/vectypes.cpp | 4 +- src/gromacs/mdlib/nbnxn_kernels/.clang-tidy | 3 - src/gromacs/mdlib/tests/mdebin.cpp | 4 +- .../mdrunutility/tests/threadaffinitytest.cpp | 3 +- src/gromacs/options/tests/treesupport.cpp | 4 +- .../random/tests/exponentialdistribution.cpp | 3 +- .../random/tests/gammadistribution.cpp | 3 +- .../random/tests/normaldistribution.cpp | 3 +- .../tests/tabulatednormaldistribution.cpp | 3 + src/gromacs/random/tests/threefry.cpp | 1 + .../random/tests/uniformintdistribution.cpp | 3 +- .../random/tests/uniformrealdistribution.cpp | 4 +- src/gromacs/selection/parser_internal.h | 6 +- src/gromacs/selection/tests/nbsearch.cpp | 6 +- src/gromacs/selection/tests/poscalc.cpp | 16 +---- src/gromacs/selection/tests/toputils.cpp | 2 +- src/gromacs/simd/tests/CMakeLists.txt | 3 +- src/gromacs/simd/tests/base.cpp | 6 +- src/gromacs/simd/tests/base.h | 12 +++- src/gromacs/simd/tests/data.cpp | 71 ------------------- src/gromacs/simd/tests/data.h | 24 +++---- src/gromacs/simd/tests/scalar.cpp | 24 ++++--- src/gromacs/simd/tests/simd.h | 10 +-- src/gromacs/simd/tests/simd4.h | 8 +-- src/gromacs/simd/tests/simd4_math.cpp | 13 ++-- src/gromacs/simd/tests/simd_math.cpp | 53 +++++++------- src/gromacs/tables/tests/splinetable.cpp | 2 +- .../trajectoryanalysis/tests/surfacearea.cpp | 13 +--- src/gromacs/utility/bitmask.h | 18 ++--- .../utility/tests/alignedallocator-impl.h | 8 +-- src/gromacs/utility/tests/arrayref.cpp | 4 +- src/gromacs/utility/tests/bitmask.h | 12 ++-- src/gromacs/utility/tests/mutex.cpp | 4 +- src/programs/mdrun/mdrun.cpp | 12 ++-- src/programs/mdrun/tests/energyreader.cpp | 2 +- .../mdrun/tests/initialconstraints.cpp | 2 +- src/programs/mdrun/tests/moduletest.cpp | 12 ++-- src/programs/mdrun/tests/multisimtest.cpp | 4 +- src/programs/mdrun/tests/rerun.cpp | 4 +- .../tests/tabulated_bonded_interactions.cpp | 14 ++-- src/programs/mdrun/tests/tpitest.cpp | 2 +- src/testutils/TestMacros.cmake | 7 ++ src/testutils/cmdlinetest.cpp | 4 +- src/testutils/cmdlinetest.h | 4 +- src/testutils/conftest.cpp | 4 +- src/testutils/interactivetest.cpp | 3 +- src/testutils/refdata-checkers.h | 10 +-- src/testutils/refdata-impl.h | 5 +- src/testutils/refdata.cpp | 6 +- src/testutils/refdata.h | 4 +- src/testutils/testasserts.cpp | 7 +- src/testutils/testasserts.h | 8 +-- src/testutils/testinit.cpp | 5 +- src/testutils/testoptions.h | 12 ++-- 82 files changed, 344 insertions(+), 411 deletions(-) create mode 100644 src/external/.clang-tidy create mode 100644 src/gromacs/linearalgebra/.clang-tidy delete mode 100644 src/gromacs/mdlib/nbnxn_kernels/.clang-tidy delete mode 100644 src/gromacs/simd/tests/data.cpp diff --git a/docs/dev-manual/tools.rst b/docs/dev-manual/tools.rst index 404898d23a..9da071e6e5 100644 --- a/docs/dev-manual/tools.rst +++ b/docs/dev-manual/tools.rst @@ -82,18 +82,24 @@ unit testing (CTest) regression tests clang-tidy - `clang-tidy ` + `clang-tidy `_ is used for static code analysis. clang-tidy is easy to install. It is contained in - the llvm binary `package `. Only - version 6.0 is supported. Others might miss tests or give false positives. - It is run automatically on Jenkins for each commit. To run it manually, configure - with ``cmake -DGMX_CLANG_TIDY=ON -DGMX_OPENMP=no -DCMAKE_BUILD_TYPE=Debug`` and then run make - normally (for ``CMAKE_BUILD_TYPE`` any type which enables asserts (e.g. ASAN) works). - The name of the clang-tidy executable that CMake should search for be set with - ``-DCLANG_TIDY=...`, and the full path to it can be set with ``-DCLANG_TIDY_EXE=...``. - Many checks have fixes which automatically get applied when building with clang-tidy - enabled, so you may want to run this tool locally to apply the fixes before - you upload to Gerrit. + the llvm binary `package `_. Only + version 6.0.* is supported. Others might miss tests or give false positives. + It is run automatically on Jenkins for each commit. Many checks have fixes which can automatically be + applied. To run it, the build has to be configured with + ``cmake -DGMX_CLANG_TIDY=ON -DGMX_OPENMP=no -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=on``. + Any ``CMAKE_BUILD_TYPE`` which enables asserts (e.g. ASAN) works. Such a configured build will + run both the compiler as well as clang-tidy when building. The name of the clang-tidy executable is set with +``-DCLANG_TIDY=...``, and the full path to it can be set with ``-DCLANG_TIDY_EXE=...``. + To apply the automatic fixes to the issue identified clang-tidy should be run sepereately (running clang-tidy + with ``-fix`` as part of the build can corrupt header files). To fix a specific file run + ``clang-tidy -fix -header-filter '.*' {file}``, to fix all files in parallel + ``run-clang-tidy.py -fix -header-filter '.*' '(?AddNewExpectation( + return function_mocker_->AddNewExpectation( // NOLINT file, line, source_text, matchers_); } @@ -1469,7 +1469,7 @@ class FunctionMockerBase : public UntypedFunctionMockerBase { MutexLock l(&g_gmock_mutex); VerifyAndClearExpectationsLocked(); Mock::UnregisterLocked(this); - ClearDefaultActionsLocked(); + ClearDefaultActionsLocked(); // NOLINT } // Returns the ON_CALL spec that matches this mock function with the diff --git a/src/gromacs/CMakeLists.txt b/src/gromacs/CMakeLists.txt index 9022e5c4b6..a1b441d44c 100644 --- a/src/gromacs/CMakeLists.txt +++ b/src/gromacs/CMakeLists.txt @@ -269,32 +269,6 @@ set_target_properties(libgromacs PROPERTIES gmx_manage_lmfit() target_link_libraries(libgromacs PRIVATE lmfit) -set(IGNORED_CLANG_ALL_WARNINGS - "-Wno-c++98-compat -Wno-c++98-compat-pedantic" #No intention of C++98 compability - "-Wno-source-uses-openmp" #Don't warn for no-omp build - "-Wno-c++17-extensions" #Allowed in attributes (compilers are required to ignore unknown attributes) - "-Wno-documentation-unknown-command" #Custom commands are used - "-Wno-covered-switch-default" #GCC gives maybe-uninitialized without default label and checks for illegal enum values. - "-Wno-switch-enum" # default statement for enum is OK - - #Following ones are undecided/TODO - "-Wno-disabled-macro-expansion" - "-Wno-reserved-id-macro" - "-Wno-global-constructors" - "-Wno-exit-time-destructors" - "-Wno-unused-macros" - "-Wno-weak-vtables" - "-Wno-conditional-uninitialized" - "-Wno-format-nonliteral" - "-Wno-shadow" - "-Wno-cast-qual" - "-Wno-documentation" - "-Wno-used-but-marked-unused" - "-Wno-padded" - "-Wno-float-equal" - "-Wno-conversion" - "-Wno-double-promotion") -string(REPLACE " " ";" IGNORED_CLANG_ALL_WARNINGS "${IGNORED_CLANG_ALL_WARNINGS}") if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION MATCHES "^6\.0") target_compile_options(libgromacs PRIVATE $<$:-Weverything ${IGNORED_CLANG_ALL_WARNINGS}>) endif() @@ -325,34 +299,10 @@ if (CMAKE_CXX_COMPILER_ID STREQUAL "MSVC") > ) endif() + if (GMX_CLANG_TIDY) - set(CLANG_TIDY "clang-tidy" CACHE STRING "Name of clang-tidy executable") - find_program(CLANG_TIDY_EXE NAMES "${CLANG_TIDY}" - DOC "Path to clang-tidy executable") - if(NOT CLANG_TIDY_EXE) - message(FATAL_ERROR "clang-tidy not found.") - endif() - if(CMAKE_VERSION VERSION_LESS "3.6") - message(FATAL_ERROR "clang-tidy support requires cmake 3.6.") - endif() - set(CLANG_TIDY_CHECKS - "-clang-analyzer-security.insecureAPI.strcpy" - "bugprone-*" "misc-*" "readability-*" "performance-*" "mpi-*" - "-misc-incorrect-roundings" #TODO: #2562 - "-readability-else-after-return" - "-readability-inconsistent-declaration-parameter-name" - "-readability-implicit-bool-conversion" #TODO: Remove gmx_bool - "modernize-use-nullptr" "modernize-use-emplace" - "modernize-make-unique" "modernize-make-shared" - "google-readability-casting" - "cppcoreguidelines-*" "-cppcoreguidelines-pro-*" - "-cppcoreguidelines-owning-memory" - "-cppcoreguidelines-no-malloc" - "-cppcoreguidelines-special-member-functions" #in conflict with Wunused-member-function - ) - string(REPLACE ";" "," CLANG_TIDY_CHECKS "${CLANG_TIDY_CHECKS}") set_target_properties(libgromacs PROPERTIES CXX_CLANG_TIDY - "${CLANG_TIDY_EXE};--checks=${CLANG_TIDY_CHECKS};-warnings-as-errors=*;-header-filter=.*") + "${CLANG_TIDY_EXE};-warnings-as-errors=*;-header-filter=.*") endif() gmx_write_installed_header_list() diff --git a/src/gromacs/analysisdata/tests/datatest.h b/src/gromacs/analysisdata/tests/datatest.h index 2117124b88..8111d1e481 100644 --- a/src/gromacs/analysisdata/tests/datatest.h +++ b/src/gromacs/analysisdata/tests/datatest.h @@ -454,7 +454,7 @@ class AnalysisDataTestFixture : public ::testing::Test void addReferenceCheckerModule(const char *id, AbstractAnalysisData *source); - protected: + private: /*! \brief * Reference data object used for the reference checker modules. * diff --git a/src/gromacs/awh/tests/bias.cpp b/src/gromacs/awh/tests/bias.cpp index 51fb32b0b8..86e28c0cf0 100644 --- a/src/gromacs/awh/tests/bias.cpp +++ b/src/gromacs/awh/tests/bias.cpp @@ -47,6 +47,7 @@ #include "gromacs/awh/correlationgrid.h" #include "gromacs/awh/pointstate.h" +#include "gromacs/compat/make_unique.h" #include "gromacs/mdtypes/awh-params.h" #include "gromacs/utility/stringutil.h" @@ -107,7 +108,7 @@ static AwhTestParameters getAwhTestParameters(int eawhgrowth, double k = 1000; int64_t seed = 93471803; - params.dimParams.push_back(DimParams(convFactor, k, params.beta)); + params.dimParams.emplace_back(convFactor, k, params.beta); AwhParams &awhParams = params.awhParams; @@ -202,7 +203,7 @@ class BiasTest : public ::testing::TestWithParam int numSamples = coordinates_.size() - 1; // No sample taken at step 0 GMX_RELEASE_ASSERT(numSamples % params.awhParams.numSamplesUpdateFreeEnergy == 0, "This test is intended to reproduce the situation when the might need to write output during a normal AWH run, therefore the number of samples should be a multiple of the free-energy update interval (but the test should also runs fine without this condition)."); - bias_ = std::unique_ptr(new Bias(-1, params.awhParams, params.awhBiasParams, params.dimParams, params.beta, mdTimeStep, 1, "", Bias::ThisRankWillDoIO::No, disableUpdateSkips)); + bias_ = gmx::compat::make_unique(-1, params.awhParams, params.awhBiasParams, params.dimParams, params.beta, mdTimeStep, 1, "", Bias::ThisRankWillDoIO::No, disableUpdateSkips); } }; @@ -211,7 +212,7 @@ TEST_P(BiasTest, ForcesBiasPmf) gmx::test::TestReferenceData data; gmx::test::TestReferenceChecker checker(data.rootChecker()); - Bias &bias = *bias_.get(); + Bias &bias = *bias_; /* Make strings with the properties we expect to be different in the tests. * These also helps to interpret the reference data. diff --git a/src/gromacs/awh/tests/biasstate.cpp b/src/gromacs/awh/tests/biasstate.cpp index 68465bfc34..1ba40d7c54 100644 --- a/src/gromacs/awh/tests/biasstate.cpp +++ b/src/gromacs/awh/tests/biasstate.cpp @@ -46,6 +46,7 @@ #include "gromacs/awh/grid.h" #include "gromacs/awh/pointstate.h" +#include "gromacs/compat/make_unique.h" #include "gromacs/math/functions.h" #include "gromacs/mdtypes/awh-params.h" #include "gromacs/utility/smalloc.h" @@ -136,11 +137,11 @@ class BiasStateTest : public ::testing::TestWithParam const AwhParams &awhParams = params.awhParams; const AwhBiasParams &awhBiasParams = awhParams.awhBiasParams[0]; std::vector dimParams; - dimParams.push_back(DimParams(1.0, 15.0, params.beta)); - dimParams.push_back(DimParams(1.0, 15.0, params.beta)); + dimParams.emplace_back(1.0, 15.0, params.beta); + dimParams.emplace_back(1.0, 15.0, params.beta); Grid grid(dimParams, awhBiasParams.dimParams); BiasParams biasParams(awhParams, awhBiasParams, dimParams, 1.0, 1.0, BiasParams::DisableUpdateSkips::no, 1, grid.axis(), 0); - biasState_ = std::unique_ptr(new BiasState(awhBiasParams, 1.0, dimParams, grid)); + biasState_ = gmx::compat::make_unique(awhBiasParams, 1.0, dimParams, grid); // Here we initialize the grid point state using the input file std::string filename = gmx::test::TestFileManager::getInputFilePath(GetParam()); diff --git a/src/gromacs/awh/tests/grid.cpp b/src/gromacs/awh/tests/grid.cpp index 8cc7a87291..e1a883746c 100644 --- a/src/gromacs/awh/tests/grid.cpp +++ b/src/gromacs/awh/tests/grid.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2017, by the GROMACS development team, led by + * Copyright (c) 2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -84,8 +84,8 @@ TEST(gridTest, neighborhood) /* Set up dimParams to get about 15 points along each dimension */ std::vector dimParams; - dimParams.push_back(DimParams(conversionFactor, 1/(beta*0.7*0.7), beta)); - dimParams.push_back(DimParams(conversionFactor, 1/(beta*0.1*0.1), beta)); + dimParams.emplace_back(conversionFactor, 1/(beta*0.7*0.7), beta); + dimParams.emplace_back(conversionFactor, 1/(beta*0.1*0.1), beta); Grid grid(dimParams, awhDimParams.data()); diff --git a/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp b/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp index a959670afe..15f036bc8d 100644 --- a/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp +++ b/src/gromacs/commandline/tests/cmdlinehelpmodule.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015, by the GROMACS development team, led by + * Copyright (c) 2015,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -61,7 +61,6 @@ namespace using gmx::test::CommandLine; using gmx::test::MockHelpTopic; -using gmx::test::MockModule; using gmx::test::MockOptionsModule; //! Test fixture for the tests. diff --git a/src/gromacs/commandline/tests/cmdlineprogramcontext.cpp b/src/gromacs/commandline/tests/cmdlineprogramcontext.cpp index 0bb6864c6e..4cdf6d1f8b 100644 --- a/src/gromacs/commandline/tests/cmdlineprogramcontext.cpp +++ b/src/gromacs/commandline/tests/cmdlineprogramcontext.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -57,7 +57,6 @@ #include "testutils/cmdlinetest.h" -using gmx::test::CommandLine; using gmx::Path; #if GMX_NATIVE_WINDOWS || GMX_CYGWIN diff --git a/src/gromacs/compat/tests/make_unique.cpp b/src/gromacs/compat/tests/make_unique.cpp index a99dff7481..72cc32ca7e 100644 --- a/src/gromacs/compat/tests/make_unique.cpp +++ b/src/gromacs/compat/tests/make_unique.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2017, by the GROMACS development team, led by + * Copyright (c) 2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -57,11 +57,11 @@ struct dummy dummy() : foo {0}, bar {0} - {}; + {} dummy(const char a, const char b) : foo {a}, bar {b} - {}; + {} }; TEST(CompatibilityHelper, MakeUniqueCompiles) diff --git a/src/gromacs/correlationfunctions/tests/autocorr.cpp b/src/gromacs/correlationfunctions/tests/autocorr.cpp index 2d7053b4d9..f5b5f2733a 100644 --- a/src/gromacs/correlationfunctions/tests/autocorr.cpp +++ b/src/gromacs/correlationfunctions/tests/autocorr.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -50,6 +50,7 @@ #include +#include "gromacs/compat/make_unique.h" #include "gromacs/correlationfunctions/expfit.h" #include "gromacs/fft/fft.h" #include "gromacs/utility/gmxassert.h" @@ -97,7 +98,7 @@ class AutocorrTest : public ::testing::Test { int n = 0; std::string fileName = "testCOS3.xvg"; - data_ = CorrelationDataSetPointer(new CorrelationDataSet(fileName)); + data_ = gmx::compat::make_unique(fileName); nrFrames_ = data_->getNrLines(); tempArgs_ = add_acf_pargs(&n, nullptr); } diff --git a/src/gromacs/correlationfunctions/tests/expfit.cpp b/src/gromacs/correlationfunctions/tests/expfit.cpp index 5d5bd967df..4f365f0a35 100644 --- a/src/gromacs/correlationfunctions/tests/expfit.cpp +++ b/src/gromacs/correlationfunctions/tests/expfit.cpp @@ -63,7 +63,7 @@ namespace gmx namespace { - +#if HAVE_LMFIT class ExpfitData { public: @@ -156,7 +156,6 @@ std::vector ExpfitTest::data_; // TODO calling test() leads to a fatal error, which we could in // principle test for. -#if HAVE_LMFIT TEST_F (ExpfitTest, EffnEXP1) { double param[] = {25}; diff --git a/src/gromacs/ewald/tests/pmebsplinetest.cpp b/src/gromacs/ewald/tests/pmebsplinetest.cpp index 14308bb5eb..7549d1aa23 100644 --- a/src/gromacs/ewald/tests/pmebsplinetest.cpp +++ b/src/gromacs/ewald/tests/pmebsplinetest.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2016,2017, by the GROMACS development team, led by + * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -142,7 +142,7 @@ const int sanePmeOrder = 4; //! Sane grid size const IVec saneGridSize = {32, 25, 47}; /*! \brief Hand-picked invalid input for the exception tests */ -static std::vector const invalidInputs +std::vector const invalidInputs { /* Invalid grid sizes */ BSplineModuliInputParameters { @@ -175,7 +175,7 @@ INSTANTIATE_TEST_CASE_P(InsaneInput, PmeBSplineModuliFailureTest, ::testing::Val /* Valid input instances */ //! A couple of valid inputs for grid sizes. It is good to test both even and odd dimensions. -static std::vector const sampleGridSizes +std::vector const sampleGridSizes { IVec { 64, 32, 64 diff --git a/src/gromacs/ewald/tests/pmegathertest.cpp b/src/gromacs/ewald/tests/pmegathertest.cpp index 6d1286f794..34219cb845 100644 --- a/src/gromacs/ewald/tests/pmegathertest.cpp +++ b/src/gromacs/ewald/tests/pmegathertest.cpp @@ -64,7 +64,7 @@ namespace /* Valid input instances */ //! A couple of valid inputs for boxes. -static std::vector const c_sampleBoxes +std::vector const c_sampleBoxes { // normal box Matrix3x3 {{ @@ -81,7 +81,7 @@ static std::vector const c_sampleBoxes }; //! A couple of valid inputs for grid sizes -static std::vector const c_sampleGridSizes +std::vector const c_sampleGridSizes { IVec { 16, 12, 14 @@ -91,13 +91,13 @@ static std::vector const c_sampleGridSizes } }; //! Random charges -static std::vector const c_sampleChargesFull +std::vector const c_sampleChargesFull { 4.95f, 3.11f, 3.97f, 1.08f, 2.09f, 1.1f, 4.13f, 3.31f, 2.8f, 5.83f, 5.09f, 6.1f, 2.86f, 0.24f, 5.76f, 5.19f, 0.72f }; //! All the input atom gridline indices -static std::vector const c_sampleGridLineIndicesFull +std::vector const c_sampleGridLineIndicesFull { IVec { 4, 2, 6 @@ -156,7 +156,7 @@ static std::vector const c_sampleGridLineIndicesFull // but that should not affect the reproducibility, which we're after //! A lot of bogus input spline values - should have at list (max PME order = 5) * (DIM = 3) * (total unique atom number in all test cases = 16) values -static std::vector const c_sampleSplineValuesFull +std::vector const c_sampleSplineValuesFull { 0.12f, 0.81f, 0.29f, 0.22f, 0.13f, 0.19f, 0.12f, 0.8f, 0.44f, 0.38f, 0.32f, 0.36f, 0.27f, 0.11f, 0.17f, 0.94f, 0.07f, 0.9f, 0.98f, 0.96f, 0.07f, 0.94f, 0.77f, 0.24f, 0.84f, 0.16f, 0.77f, 0.57f, 0.52f, 0.27f, 0.39f, 0.45f, 0.6f, 0.59f, 0.44f, 0.91f, 0.97f, 0.43f, 0.24f, 0.52f, 0.73f, 0.55f, 0.99f, 0.39f, 0.97f, 0.35f, 0.1f, 0.68f, 0.19f, 0.1f, 0.77f, 0.2f, 0.43f, 0.69f, 0.76f, 0.32f, 0.31f, 0.94f, 0.53f, 0.6f, 0.93f, 0.57f, 0.94f, 0.88f, 0.75f, 0.77f, 0.91f, 0.72f, 0.07f, 0.78f, 0.09f, 0.02f, 0.48f, 0.97f, 0.89f, 0.39f, 0.48f, 0.19f, 0.02f, 0.92f, 0.8f, 0.41f, 0.53f, 0.32f, 0.38f, 0.58f, 0.36f, 0.46f, 0.92f, 0.91f, 0.01f, 0.86f, 0.54f, 0.86f, 0.94f, 0.37f, 0.35f, 0.81f, 0.89f, 0.48f, 0.34f, 0.18f, 0.11f, 0.02f, 0.87f, 0.95f, 0.66f, 0.67f, 0.38f, 0.45f, 0.04f, 0.94f, 0.54f, 0.76f, 0.58f, 0.83f, 0.31f, 0.73f, 0.71f, 0.06f, 0.35f, 0.32f, 0.35f, 0.61f, 0.27f, 0.98f, 0.83f, 0.11f, 0.3f, 0.42f, 0.95f, 0.69f, 0.58f, 0.29f, 0.1f, 0.68f, 0.94f, 0.62f, 0.51f, 0.47f, 0.04f, 0.47f, 0.34f, 0.71f, 0.52f, 0.19f, 0.69f, 0.5f, 0.59f, 0.05f, 0.74f, 0.11f, 0.4f, 0.81f, 0.24f, 0.53f, 0.71f, 0.07f, 0.17f, 0.41f, 0.23f, 0.78f, 0.27f, 0.1f, 0.71f, 0.36f, 0.67f, 0.6f, 0.94f, 0.69f, 0.19f, 0.58f, 0.68f, 0.5f, 0.62f, 0.38f, 0.29f, 0.44f, 0.04f, 0.89f, 0.0f, 0.76f, 0.22f, 0.16f, 0.08f, 0.62f, 0.51f, 0.62f, 0.83f, 0.72f, 0.96f, 0.99f, 0.4f, 0.79f, 0.83f, 0.21f, 0.43f, 0.32f, 0.44f, 0.72f, @@ -165,7 +165,7 @@ static std::vector const c_sampleSplineValuesFull }; //! A lot of bogus input spline derivatives - should have at list (max PME order = 5) * (DIM = 3) * (total unique atom number in all test cases = 16) values -static std::vector const c_sampleSplineDerivativesFull +std::vector const c_sampleSplineDerivativesFull { 0.82f, 0.88f, 0.83f, 0.11f, 0.93f, 0.32f, 0.71f, 0.37f, 0.69f, 0.88f, 0.11f, 0.38f, 0.25f, 0.5f, 0.36f, 0.81f, 0.78f, 0.31f, 0.66f, 0.32f, 0.27f, 0.35f, 0.53f, 0.83f, 0.08f, 0.08f, 0.94f, 0.71f, 0.65f, 0.24f, 0.13f, 0.01f, 0.33f, 0.65f, 0.24f, 0.53f, 0.45f, 0.84f, 0.33f, 0.97f, 0.31f, 0.7f, 0.03f, 0.31f, 0.41f, 0.76f, 0.12f, 0.3f, 0.57f, 0.65f, 0.87f, 0.99f, 0.42f, 0.97f, 0.32f, 0.39f, 0.73f, 0.23f, 0.03f, 0.67f, 0.97f, 0.57f, 0.42f, 0.38f, 0.54f, 0.17f, 0.53f, 0.54f, 0.18f, 0.8f, 0.76f, 0.13f, 0.29f, 0.83f, 0.77f, 0.56f, 0.4f, 0.87f, 0.36f, 0.18f, 0.59f, 0.04f, 0.05f, 0.61f, 0.26f, 0.91f, 0.62f, 0.16f, 0.89f, 0.23f, 0.26f, 0.59f, 0.33f, 0.2f, 0.49f, 0.41f, 0.25f, 0.4f, 0.16f, 0.83f, 0.44f, 0.82f, 0.21f, 0.95f, 0.14f, 0.8f, 0.37f, 0.31f, 0.41f, 0.53f, 0.15f, 0.85f, 0.78f, 0.17f, 0.92f, 0.03f, 0.13f, 0.2f, 0.03f, 0.33f, 0.87f, 0.38f, 0, 0.08f, 0.79f, 0.36f, 0.53f, 0.05f, 0.07f, 0.94f, 0.23f, 0.85f, 0.13f, 0.27f, 0.23f, 0.22f, 0.26f, 0.38f, 0.15f, 0.48f, 0.18f, 0.33f, 0.23f, 0.62f, 0.1f, 0.36f, 0.99f, 0.07f, 0.02f, 0.04f, 0.09f, 0.29f, 0.52f, 0.29f, 0.83f, 0.97f, 0.61f, 0.81f, 0.49f, 0.56f, 0.08f, 0.09f, 0.03f, 0.65f, 0.46f, 0.1f, 0.06f, 0.06f, 0.39f, 0.29f, 0.04f, 0.03f, 0.1f, 0.83f, 0.94f, 0.59f, 0.97f, 0.82f, 0.2f, 0.66f, 0.23f, 0.11f, 0.03f, 0.16f, 0.27f, 0.53f, 0.94f, 0.46f, 0.43f, 0.29f, 0.97f, 0.64f, 0.46f, 0.37f, 0.43f, 0.48f, 0.37f, 0.93f, 0.5f, 0.2f, @@ -174,7 +174,7 @@ static std::vector const c_sampleSplineDerivativesFull }; //! 2 c_sample grids - only non-zero values have to be listed -static std::vector const c_sampleGrids +std::vector const c_sampleGrids { SparseRealGridValuesInput {{ IVec { @@ -248,7 +248,7 @@ static std::vector const c_sampleGrids }; //! Input forces for reduction -static std::vector const c_sampleForcesFull { +std::vector const c_sampleForcesFull { RVec { 0.02f, 0.87f, 0.95f }, RVec { @@ -284,11 +284,11 @@ static std::vector const c_sampleForcesFull { }; //! PME orders to test -static std::vector const pmeOrders { +std::vector const pmeOrders { 3, 4, 5 }; //! Atom counts to test -static std::vector const atomCounts { +std::vector const atomCounts { 1, 2, 13 }; diff --git a/src/gromacs/ewald/tests/pmesolvetest.cpp b/src/gromacs/ewald/tests/pmesolvetest.cpp index 532ba51bb9..32a296e2ce 100644 --- a/src/gromacs/ewald/tests/pmesolvetest.cpp +++ b/src/gromacs/ewald/tests/pmesolvetest.cpp @@ -250,7 +250,7 @@ TEST_P(PmeSolveTest, ReproducesOutputs) /* Valid input instances */ //! A couple of valid inputs for boxes. -static std::vector const c_sampleBoxes +std::vector const c_sampleBoxes { // normal box Matrix3x3 {{ @@ -267,7 +267,7 @@ static std::vector const c_sampleBoxes }; //! A couple of valid inputs for grid sizes -static std::vector const c_sampleGridSizes +std::vector const c_sampleGridSizes { IVec { 16, 12, 28 @@ -283,7 +283,7 @@ const auto c_inputBoxes = ::testing::ValuesIn(c_sampleBoxes); const auto c_inputGridSizes = ::testing::ValuesIn(c_sampleGridSizes); //! 2 sample complex grids - only non-zero values have to be listed -static std::vector const c_sampleGrids +std::vector const c_sampleGrids { SparseComplexGridValuesInput {{ IVec { diff --git a/src/gromacs/ewald/tests/pmesplinespreadtest.cpp b/src/gromacs/ewald/tests/pmesplinespreadtest.cpp index 01df43ed82..aca761a393 100644 --- a/src/gromacs/ewald/tests/pmesplinespreadtest.cpp +++ b/src/gromacs/ewald/tests/pmesplinespreadtest.cpp @@ -211,7 +211,7 @@ class PmeSplineAndSpreadTest : public ::testing::TestWithParam(ceil(sqrt(atomCount))); /* 2 is empiric; sqrt(atomCount) assumes all the input charges may spread onto the same cell */ SCOPED_TRACE(formatString("Testing grid values with tolerance of %ld", ulpToleranceGrid)); if (!gridValuesSizeAssigned) @@ -245,7 +245,7 @@ TEST_P(PmeSplineAndSpreadTest, ReproducesOutputs) /* Valid input instances */ //! A couple of valid inputs for boxes. -static std::vector const c_sampleBoxes +std::vector const c_sampleBoxes { // normal box Matrix3x3 {{ @@ -262,7 +262,7 @@ static std::vector const c_sampleBoxes }; //! A couple of valid inputs for grid sizes. -static std::vector const c_sampleGridSizes +std::vector const c_sampleGridSizes { IVec { 16, 12, 14 @@ -273,19 +273,19 @@ static std::vector const c_sampleGridSizes }; //! Random charges -static std::vector const c_sampleChargesFull +std::vector const c_sampleChargesFull { 4.95f, 3.11f, 3.97f, 1.08f, 2.09f, 1.1f, 4.13f, 3.31f, 2.8f, 5.83f, 5.09f, 6.1f, 2.86f, 0.24f, 5.76f, 5.19f, 0.72f }; //! 1 charge -static auto const c_sampleCharges1 = ChargesVector(c_sampleChargesFull).subArray(0, 1); +auto const c_sampleCharges1 = ChargesVector(c_sampleChargesFull).subArray(0, 1); //! 2 charges -static auto const c_sampleCharges2 = ChargesVector(c_sampleChargesFull).subArray(1, 2); +auto const c_sampleCharges2 = ChargesVector(c_sampleChargesFull).subArray(1, 2); //! 13 charges -static auto const c_sampleCharges13 = ChargesVector(c_sampleChargesFull).subArray(3, 13); +auto const c_sampleCharges13 = ChargesVector(c_sampleChargesFull).subArray(3, 13); //! Random coordinate vectors -static CoordinatesVector const c_sampleCoordinatesFull +CoordinatesVector const c_sampleCoordinatesFull { { 5.59f, 1.37f, 0.95f @@ -324,11 +324,11 @@ static CoordinatesVector const c_sampleCoordinatesFull } }; //! 1 coordinate vector -static CoordinatesVector const c_sampleCoordinates1(c_sampleCoordinatesFull.begin(), c_sampleCoordinatesFull.begin() + 1); +CoordinatesVector const c_sampleCoordinates1(c_sampleCoordinatesFull.begin(), c_sampleCoordinatesFull.begin() + 1); //! 2 coordinate vectors -static CoordinatesVector const c_sampleCoordinates2(c_sampleCoordinatesFull.begin() + 1, c_sampleCoordinatesFull.begin() + 3); +CoordinatesVector const c_sampleCoordinates2(c_sampleCoordinatesFull.begin() + 1, c_sampleCoordinatesFull.begin() + 3); //! 13 coordinate vectors -static CoordinatesVector const c_sampleCoordinates13(c_sampleCoordinatesFull.begin() + 3, c_sampleCoordinatesFull.begin() + 16); +CoordinatesVector const c_sampleCoordinates13(c_sampleCoordinatesFull.begin() + 3, c_sampleCoordinatesFull.begin() + 16); //! moved out from instantiantions for readability auto c_inputBoxes = ::testing::ValuesIn(c_sampleBoxes); diff --git a/src/gromacs/ewald/tests/pmetestcommon.cpp b/src/gromacs/ewald/tests/pmetestcommon.cpp index 8faab8c2af..9bcd6e1704 100644 --- a/src/gromacs/ewald/tests/pmetestcommon.cpp +++ b/src/gromacs/ewald/tests/pmetestcommon.cpp @@ -245,7 +245,7 @@ static void pmeGetComplexGridSizesInternal(const gmx_pme_t *pme, } //! Getting the PME grid memory buffer and its sizes - template definition -template static void pmeGetGridAndSizesInternal(const gmx_pme_t *, CodePath, ValueType * &, IVec &, IVec &) +template static void pmeGetGridAndSizesInternal(const gmx_pme_t * /*unused*/, CodePath /*unused*/, ValueType * & /*unused*/, IVec & /*unused*/, IVec & /*unused*/) { GMX_THROW(InternalError("Deleted function call")); // explicitly deleting general template does not compile in clang/icc, see https://llvm.org/bugs/show_bug.cgi?id=17537 @@ -259,7 +259,7 @@ template<> void pmeGetGridAndSizesInternal(const gmx_pme_t *pme, CodePath } //! Getting the PME complex grid memory buffer and its sizes -template<> void pmeGetGridAndSizesInternal(const gmx_pme_t *pme, CodePath, t_complex * &grid, IVec &gridSize, IVec &paddedGridSize) +template<> void pmeGetGridAndSizesInternal(const gmx_pme_t *pme, CodePath /*unused*/, t_complex * &grid, IVec &gridSize, IVec &paddedGridSize) { grid = pmeGetComplexGridInternal(pme); pmeGetComplexGridSizesInternal(pme, gridSize, paddedGridSize); diff --git a/src/gromacs/ewald/tests/testhardwarecontexts.cpp b/src/gromacs/ewald/tests/testhardwarecontexts.cpp index b3c95b29eb..ddea887712 100644 --- a/src/gromacs/ewald/tests/testhardwarecontexts.cpp +++ b/src/gromacs/ewald/tests/testhardwarecontexts.cpp @@ -71,7 +71,6 @@ const char *codePathToString(CodePath codePath) default: GMX_THROW(NotImplementedError("This CodePath should support codePathToString")); } - return ""; } /* Implements the "construct on first use" idiom to avoid any static diff --git a/src/gromacs/fileio/tests/readinp.cpp b/src/gromacs/fileio/tests/readinp.cpp index e3d764ce8c..9206ac3493 100644 --- a/src/gromacs/fileio/tests/readinp.cpp +++ b/src/gromacs/fileio/tests/readinp.cpp @@ -57,8 +57,8 @@ class ReadTest : public ::testing::Test { public: ReadTest() : inputField_ {{(t_inpfile(0, 0, false, false, false, "test", ""))}}, - wi_(), - wiGuard_() + wi_() + { wi_ = init_warning(FALSE, 0); wiGuard_.reset(wi_); diff --git a/src/gromacs/fileio/tests/tngio.cpp b/src/gromacs/fileio/tests/tngio.cpp index 21610568ac..77ca67b573 100644 --- a/src/gromacs/fileio/tests/tngio.cpp +++ b/src/gromacs/fileio/tests/tngio.cpp @@ -66,7 +66,7 @@ class TngTest : public ::testing::Test TEST_F(TngTest, CanOpenTngFile) { gmx_tng_trajectory_t tng; - gmx_tng_open(fileManager_.getInputFilePath("spc2-traj.tng").c_str(), + gmx_tng_open(gmx::test::TestFileManager::getInputFilePath("spc2-traj.tng").c_str(), 'r', &tng); gmx_tng_close(&tng); diff --git a/src/gromacs/gmxpreprocess/tests/genconf.cpp b/src/gromacs/gmxpreprocess/tests/genconf.cpp index 20831a85a5..15dc632af0 100644 --- a/src/gromacs/gmxpreprocess/tests/genconf.cpp +++ b/src/gromacs/gmxpreprocess/tests/genconf.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -59,7 +59,7 @@ class GenconfTest : public gmx::test::CommandLineTestBase public: GenconfTest() { - std::string confFileName = fileManager().getInputFilePath("spc-and-methanol.gro"); + std::string confFileName = gmx::test::TestFileManager::getInputFilePath("spc-and-methanol.gro"); commandLine().addOption("-f", confFileName); commandLine().addOption("-seed", "1993"); // make random operations reproducible setOutputFile("-o", "out.gro", ExactTextMatch()); diff --git a/src/gromacs/gmxpreprocess/tests/readir.cpp b/src/gromacs/gmxpreprocess/tests/readir.cpp index 6c07d2eab4..b6a721a36d 100644 --- a/src/gromacs/gmxpreprocess/tests/readir.cpp +++ b/src/gromacs/gmxpreprocess/tests/readir.cpp @@ -71,8 +71,8 @@ namespace test class GetIrTest : public ::testing::Test { public: - GetIrTest() : fileManager_(), ir_(), mdModules_(), opts_(), - wi_(init_warning(FALSE, 0)), wiGuard_(wi_) + GetIrTest() : opts_(), + wi_(init_warning(FALSE, 0)), wiGuard_(wi_) { snew(opts_.include, STRLEN); diff --git a/src/gromacs/gmxpreprocess/tests/solvate.cpp b/src/gromacs/gmxpreprocess/tests/solvate.cpp index f1858fc9b5..6c4c032974 100644 --- a/src/gromacs/gmxpreprocess/tests/solvate.cpp +++ b/src/gromacs/gmxpreprocess/tests/solvate.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2013,2014,2015,2017, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -105,7 +105,7 @@ TEST_F(SolvateTest, cs_cp_p_Works) setInputFile("-cp", "spc-and-methanol.gro"); // TODO: Consider adding a convenience method for this. - std::string topFileName = fileManager().getInputFilePath("spc-and-methanol.top"); + std::string topFileName = gmx::test::TestFileManager::getInputFilePath("spc-and-methanol.top"); std::string modifiableTopFileName = fileManager().getTemporaryFilePath(".top"); gmx_file_copy(topFileName.c_str(), modifiableTopFileName.c_str(), true); commandLine().addOption("-p", modifiableTopFileName); diff --git a/src/gromacs/linearalgebra/.clang-tidy b/src/gromacs/linearalgebra/.clang-tidy new file mode 100644 index 0000000000..de0482b721 --- /dev/null +++ b/src/gromacs/linearalgebra/.clang-tidy @@ -0,0 +1 @@ +Checks: -* diff --git a/src/gromacs/math/tests/functions.cpp b/src/gromacs/math/tests/functions.cpp index b5306392a6..abe2d076b3 100644 --- a/src/gromacs/math/tests/functions.cpp +++ b/src/gromacs/math/tests/functions.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -144,7 +144,7 @@ TEST(FunctionTest, InvsqrtDouble) gmx::test::TestReferenceChecker checker(data.rootChecker()); std::vector result; - for (double f = 1.0; f < 10.0; f += 1.0) + for (double f = 1.0; f < 10.0; f += 1.0) // NOLINT(clang-analyzer-security.FloatLoopCounter) { result.push_back(gmx::invsqrt(f)); } @@ -223,7 +223,7 @@ TEST(FunctionTest, SixthrootDouble) gmx::test::TestReferenceChecker checker(data.rootChecker()); std::vector result; - for (double d = 0; d < 10.0; d += 1.0) + for (double d = 0; d < 10.0; d += 1.0) // NOLINT(clang-analyzer-security.FloatLoopCounter) { result.push_back(gmx::sixthroot(d)); } @@ -236,6 +236,7 @@ TEST(FunctionTest, SixthrootInteger) gmx::test::TestReferenceChecker checker(data.rootChecker()); std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(gmx::sixthroot(i)); @@ -262,7 +263,7 @@ TEST(FunctionTest, InvsixthrootDouble) gmx::test::TestReferenceChecker checker(data.rootChecker()); std::vector result; - for (double d = 1.0; d < 10.0; d += 1.0) + for (double d = 1.0; d < 10.0; d += 1.0) // NOLINT(clang-analyzer-security.FloatLoopCounter) { result.push_back(gmx::invsixthroot(d)); } diff --git a/src/gromacs/math/tests/vectypes.cpp b/src/gromacs/math/tests/vectypes.cpp index 279f0535db..1c2e22b892 100644 --- a/src/gromacs/math/tests/vectypes.cpp +++ b/src/gromacs/math/tests/vectypes.cpp @@ -153,7 +153,7 @@ TEST(RVecTest, CopyAssignmentWorks) TEST(RVecTest, MoveConstructorWorks) { RVec v(1, 2, 3); - RVec copy(std::move(v)); + RVec copy(v); EXPECT_EQ(1, copy[XX]); EXPECT_EQ(2, copy[YY]); EXPECT_EQ(3, copy[ZZ]); @@ -163,7 +163,7 @@ TEST(RVecTest, MoveAssignmentWorks) { RVec v(1, 2, 3); RVec copy; - copy = std::move(v); + copy = v; EXPECT_EQ(1, copy[XX]); EXPECT_EQ(2, copy[YY]); EXPECT_EQ(3, copy[ZZ]); diff --git a/src/gromacs/mdlib/nbnxn_kernels/.clang-tidy b/src/gromacs/mdlib/nbnxn_kernels/.clang-tidy deleted file mode 100644 index c05e99a967..0000000000 --- a/src/gromacs/mdlib/nbnxn_kernels/.clang-tidy +++ /dev/null @@ -1,3 +0,0 @@ -CheckOptions: - - key: readability-function-size.StatementThreshold - value: 2000 diff --git a/src/gromacs/mdlib/tests/mdebin.cpp b/src/gromacs/mdlib/tests/mdebin.cpp index 6b2cba8415..7cae684b62 100644 --- a/src/gromacs/mdlib/tests/mdebin.cpp +++ b/src/gromacs/mdlib/tests/mdebin.cpp @@ -80,9 +80,9 @@ class PrintEbin : public ::testing::Test TestReferenceChecker checker_; PrintEbin() : ebin_ {0}, ebinGuard_(&ebin_), mdebin_ {0}, - fileManager_(), logFilename_(fileManager_.getTemporaryFilePath(".log")), + logFilename_(fileManager_.getTemporaryFilePath(".log")), log_(std::fopen(logFilename_.c_str(), "w")), logFileGuard_(log_), - refData_ {}, checker_(refData_.rootChecker()) + checker_(refData_.rootChecker()) { mdebin_.ebin = &ebin_; } diff --git a/src/gromacs/mdrunutility/tests/threadaffinitytest.cpp b/src/gromacs/mdrunutility/tests/threadaffinitytest.cpp index 4e9524c411..3510be85c0 100644 --- a/src/gromacs/mdrunutility/tests/threadaffinitytest.cpp +++ b/src/gromacs/mdrunutility/tests/threadaffinitytest.cpp @@ -40,6 +40,7 @@ #include +#include "gromacs/compat/make_unique.h" #include "gromacs/hardware/hardwaretopology.h" #include "gromacs/mdtypes/commrec.h" #include "gromacs/utility/basenetwork.h" @@ -86,7 +87,7 @@ ThreadAffinityTestHelper::~ThreadAffinityTestHelper() void ThreadAffinityTestHelper::setLogicalProcessorCount(int logicalProcessorCount) { - hwTop_.reset(new HardwareTopology(logicalProcessorCount)); + hwTop_ = gmx::compat::make_unique(logicalProcessorCount); } } // namespace test diff --git a/src/gromacs/options/tests/treesupport.cpp b/src/gromacs/options/tests/treesupport.cpp index b827643893..5ff24135c2 100644 --- a/src/gromacs/options/tests/treesupport.cpp +++ b/src/gromacs/options/tests/treesupport.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2016,2017, by the GROMACS development team, led by + * Copyright (c) 2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -359,7 +359,7 @@ class TreeValueSupportTest : public ::testing::Test std::string formatBuffer(const std::vector &buffer) { - return gmx::formatAndJoin(buffer, " ", [](char c) { return gmx::formatString("%02x", (unsigned char)c); }); + return gmx::formatAndJoin(buffer, " ", [](char c) { return gmx::formatString("%02x", static_cast(c)); }); } }; diff --git a/src/gromacs/random/tests/exponentialdistribution.cpp b/src/gromacs/random/tests/exponentialdistribution.cpp index 684242433c..759a2c17ee 100644 --- a/src/gromacs/random/tests/exponentialdistribution.cpp +++ b/src/gromacs/random/tests/exponentialdistribution.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -64,6 +64,7 @@ TEST(ExponentialDistributionTest, Output) gmx::ExponentialDistribution dist(5.0); std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(dist(rng)); diff --git a/src/gromacs/random/tests/gammadistribution.cpp b/src/gromacs/random/tests/gammadistribution.cpp index 2d3ce20c76..4cee2ca2a2 100644 --- a/src/gromacs/random/tests/gammadistribution.cpp +++ b/src/gromacs/random/tests/gammadistribution.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -64,6 +64,7 @@ TEST(GammaDistributionTest, Output) gmx::GammaDistribution dist(2.0, 5.0); std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(dist(rng)); diff --git a/src/gromacs/random/tests/normaldistribution.cpp b/src/gromacs/random/tests/normaldistribution.cpp index a6d5022ce1..3ad6af4ab7 100644 --- a/src/gromacs/random/tests/normaldistribution.cpp +++ b/src/gromacs/random/tests/normaldistribution.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -64,6 +64,7 @@ TEST(NormalDistributionTest, Output) gmx::NormalDistribution dist(2.0, 5.0); std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(dist(rng)); diff --git a/src/gromacs/random/tests/tabulatednormaldistribution.cpp b/src/gromacs/random/tests/tabulatednormaldistribution.cpp index 0d02da7f02..6693d875b4 100644 --- a/src/gromacs/random/tests/tabulatednormaldistribution.cpp +++ b/src/gromacs/random/tests/tabulatednormaldistribution.cpp @@ -64,6 +64,7 @@ TEST(TabulatedNormalDistributionTest, Output14) gmx::TabulatedNormalDistribution<> dist(2.0, 5.0); // Use default 14-bit resolution std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(dist(rng)); @@ -80,6 +81,7 @@ TEST(TabulatedNormalDistributionTest, Output16) gmx::TabulatedNormalDistribution dist(2.0, 5.0); // Use larger 16-bit table std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(dist(rng)); @@ -96,6 +98,7 @@ TEST(TabulatedNormalDistributionTest, OutputDouble14) gmx::TabulatedNormalDistribution dist(2.0, 5.0); std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(dist(rng)); diff --git a/src/gromacs/random/tests/threefry.cpp b/src/gromacs/random/tests/threefry.cpp index 0930892b39..6552fec98a 100644 --- a/src/gromacs/random/tests/threefry.cpp +++ b/src/gromacs/random/tests/threefry.cpp @@ -174,6 +174,7 @@ TEST_F(ThreeFry2x64Test, InternalCounterSequence) gmx::ThreeFry2x64<66> rngA(123456, gmx::RandomDomain::Other); std::vector result; + result.reserve(16); for (int i = 0; i < 16; i++) { result.push_back(rngA()); diff --git a/src/gromacs/random/tests/uniformintdistribution.cpp b/src/gromacs/random/tests/uniformintdistribution.cpp index 40e99f0140..b7cd01ef61 100644 --- a/src/gromacs/random/tests/uniformintdistribution.cpp +++ b/src/gromacs/random/tests/uniformintdistribution.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -64,6 +64,7 @@ TEST(UniformIntDistributionTest, Output) gmx::UniformIntDistribution dist(1, 1000); std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(dist(rng)); diff --git a/src/gromacs/random/tests/uniformrealdistribution.cpp b/src/gromacs/random/tests/uniformrealdistribution.cpp index 6121eb463e..599d89ebea 100644 --- a/src/gromacs/random/tests/uniformrealdistribution.cpp +++ b/src/gromacs/random/tests/uniformrealdistribution.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -63,6 +63,7 @@ TEST(UniformRealDistributionTest, GenerateCanonical) gmx::ThreeFry2x64<8> rng(123456, gmx::RandomDomain::Other); std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(gmx::generateCanonical::digits>(rng)); @@ -79,6 +80,7 @@ TEST(UniformRealDistributionTest, Output) gmx::UniformRealDistribution dist(1.0, 10.0); std::vector result; + result.reserve(10); for (int i = 0; i < 10; i++) { result.push_back(dist(rng)); diff --git a/src/gromacs/selection/parser_internal.h b/src/gromacs/selection/parser_internal.h index ee2fc57029..b8e489f6e3 100644 --- a/src/gromacs/selection/parser_internal.h +++ b/src/gromacs/selection/parser_internal.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2012,2014,2015,2017, by the GROMACS development team, led by + * Copyright (c) 2012,2014,2015,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -82,7 +82,7 @@ yyerror(YYLTYPE *location, yyscan_t scanner, char const *s) //! Logic for computing the location of the output of Bison reduction. #define YYLLOC_DEFAULT(Current, Rhs, N) \ do { \ - if (N != 0) \ + if ((N) != 0) \ { \ (Current).startIndex = YYRHSLOC(Rhs, 1).startIndex; \ (Current).endIndex = YYRHSLOC(Rhs, N).endIndex; \ @@ -218,7 +218,7 @@ void set_empty(ValueType * &dest) */ #define CHECK_SEL(sel) \ if (!*(sel)) { \ - delete sel; \ + delete (sel); \ YYERROR; \ } diff --git a/src/gromacs/selection/tests/nbsearch.cpp b/src/gromacs/selection/tests/nbsearch.cpp index 4e0c86802d..e3afd50051 100644 --- a/src/gromacs/selection/tests/nbsearch.cpp +++ b/src/gromacs/selection/tests/nbsearch.cpp @@ -168,11 +168,7 @@ class NeighborhoodSearchTestData const std::vector &refPairs = testPositions_[testIndex].refPairs; std::vector::const_iterator foundRefPair = std::lower_bound(refPairs.begin(), refPairs.end(), pair); - if (foundRefPair == refPairs.end() || foundRefPair->refIndex != pair.refIndex) - { - return false; - } - return true; + return !(foundRefPair == refPairs.end() || foundRefPair->refIndex != pair.refIndex); } // Return a tolerance that accounts for the magnitudes of the coordinates diff --git a/src/gromacs/selection/tests/poscalc.cpp b/src/gromacs/selection/tests/poscalc.cpp index 7daa1b4fb1..a7fb303f1d 100644 --- a/src/gromacs/selection/tests/poscalc.cpp +++ b/src/gromacs/selection/tests/poscalc.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -109,20 +109,6 @@ class PositionCalculationTest : public ::testing::Test { } - // Default move constructor and assignment. Only needed for old compilers. - PositionTest(PositionTest &&o) - : pos(std::move(o.pos)), pc(o.pc), name(o.name) - { - } - - PositionTest &operator= (PositionTest &&o) - { - pos = std::move(o.pos); - pc = o.pc; - name = o.name; - return *this; - } - PositionPointer pos; gmx_ana_poscalc_t *pc; const char *name; diff --git a/src/gromacs/selection/tests/toputils.cpp b/src/gromacs/selection/tests/toputils.cpp index f294aa179e..5d1ed80ed6 100644 --- a/src/gromacs/selection/tests/toputils.cpp +++ b/src/gromacs/selection/tests/toputils.cpp @@ -68,7 +68,7 @@ namespace test { TopologyManager::TopologyManager() - : mtop_(), frame_(nullptr) + : frame_(nullptr) { } diff --git a/src/gromacs/simd/tests/CMakeLists.txt b/src/gromacs/simd/tests/CMakeLists.txt index b41ba5614c..78730cef42 100644 --- a/src/gromacs/simd/tests/CMakeLists.txt +++ b/src/gromacs/simd/tests/CMakeLists.txt @@ -1,7 +1,7 @@ # # This file is part of the GROMACS molecular simulation package. # -# Copyright (c) 2014,2015,2016,2017, by the GROMACS development team, led by +# Copyright (c) 2014,2015,2016,2017,2018, by the GROMACS development team, led by # Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, # and including many others, as listed in the AUTHORS file in the # top-level source directory and at http://www.gromacs.org. @@ -35,7 +35,6 @@ gmx_add_unit_test(SimdUnitTests simd-test bootstrap_loadstore.cpp base.cpp - data.cpp simd.cpp simd_floatingpoint.cpp simd_floatingpoint_util.cpp diff --git a/src/gromacs/simd/tests/base.cpp b/src/gromacs/simd/tests/base.cpp index 41825a9b38..bc16427175 100644 --- a/src/gromacs/simd/tests/base.cpp +++ b/src/gromacs/simd/tests/base.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -97,7 +97,7 @@ SimdBaseTest::compareVectorRealUlp(const char * refExpr, const char * tstExpr, for (i = 0, allOk = true; i < tst.size(); i++) { - absDiff[i] = fabs(ref[i]-tst[i]); + absDiff[i] = std::abs(ref[i]-tst[i]); conv0.r = ref[i]; conv1.r = tst[i]; ulpDiff[i] = llabs(conv0.i-conv1.i); @@ -106,7 +106,7 @@ SimdBaseTest::compareVectorRealUlp(const char * refExpr, const char * tstExpr, allOk = allOk && ( ( absDiff[i] < absTol_ ) || ( ( ref[i]*tst[i] >= 0 ) && (ulpDiff[i] <= ulpTol_) ) ); } - if (allOk == true) + if (allOk) { return ::testing::AssertionSuccess(); } diff --git a/src/gromacs/simd/tests/base.h b/src/gromacs/simd/tests/base.h index 77d4a3dcba..2f85847a59 100644 --- a/src/gromacs/simd/tests/base.h +++ b/src/gromacs/simd/tests/base.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -114,6 +114,16 @@ class SimdBaseTest : public ::testing::Test /*! \brief Adjust ulp tolerance from the default 10 (float) or 255 (double). */ void setUlpTol(std::int64_t newTol) { ulpTol_ = newTol; } + /*! \brief Adjust ulp tolerance for single accuracy functions. */ + void setUlpTolSingleAccuracy(std::int64_t newTol) + { +#if GMX_DOUBLE + setUlpTol(newTol * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); +#else + setUlpTol(newTol); +#endif + } + /*! \brief Adjust the absolute tolerance from the default 0. * * If values are closer than the absolute tolerance, the test will pass diff --git a/src/gromacs/simd/tests/data.cpp b/src/gromacs/simd/tests/data.cpp deleted file mode 100644 index 1e3ab7ba07..0000000000 --- a/src/gromacs/simd/tests/data.cpp +++ /dev/null @@ -1,71 +0,0 @@ -/* - * This file is part of the GROMACS molecular simulation package. - * - * Copyright (c) 2014,2015,2016,2017, by the GROMACS development team, led by - * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, - * and including many others, as listed in the AUTHORS file in the - * top-level source directory and at http://www.gromacs.org. - * - * GROMACS is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public License - * as published by the Free Software Foundation; either version 2.1 - * of the License, or (at your option) any later version. - * - * GROMACS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with GROMACS; if not, see - * http://www.gnu.org/licenses, or write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - * - * If you want to redistribute modifications to GROMACS, please - * consider that scientific software is very special. Version - * control is crucial - bugs must be traceable. We will be happy to - * consider code for inclusion in the official distribution, but - * derived work must not be called official GROMACS. Details are found - * in the README & COPYING files - if they are missing, get the - * official version at http://www.gromacs.org. - * - * To help us fund GROMACS development, we humbly ask that you cite - * the research papers on the package. Check out http://www.gromacs.org. - */ -#include "gmxpre.h" - -#include "data.h" - -#include "gromacs/utility/real.h" - - -namespace gmx -{ -namespace test -{ - -/*! \cond internal */ -/*! \addtogroup module_simd */ -/*! \{ */ - -// Common test data constants used both for SIMD, SIMD4, and scalar tests. -// We both want numbers that are easy to identify with integer part from 0 to 9, -// and to fill all digits in the mantissa and avoid identical differences -// between adjacent numbers we add a fraction of primes. -const real czero = 0.0; -const real c0 = 0.0 + 1.0/3.0; -const real c1 = 1.0 + 5.0/7.0; -const real c2 = 2.0 + 9.0/13.0; -const real c3 = 3.0 + 17.0/19.0; -const real c4 = 4.0 + 23.0/29.0; -const real c5 = 5.0 + 31.0/37.0; -const real c6 = 6.0 + 41.0/43.0; -const real c7 = 7.0 + 47.0/53.0; -const real c8 = 8.0 + 59.0/61.0; - -/*! \} */ -/*! \endcond */ - -} // namespace test - -} // namespace gmx diff --git a/src/gromacs/simd/tests/data.h b/src/gromacs/simd/tests/data.h index b66abcece7..c1074ebac6 100644 --- a/src/gromacs/simd/tests/data.h +++ b/src/gromacs/simd/tests/data.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -61,18 +61,16 @@ namespace test /*! \cond internal */ /*! \addtogroup module_simd */ /*! \{ */ -extern const real czero; //!< Value 0.0 in real precision -extern const real c0; //!< Random fp value using entire mantissa -extern const real c1; //!< Random fp value using entire mantissa -extern const real c2; //!< Random fp value using entire mantissa -extern const real c3; //!< Random fp value using entire mantissa -extern const real c4; //!< Random fp value using entire mantissa -extern const real c5; //!< Random fp value using entire mantissa -extern const real c5; //!< Random fp value using entire mantissa -extern const real c6; //!< Random fp value using entire mantissa -extern const real c7; //!< Random fp value using entire mantissa -extern const real c8; //!< Random fp value using entire mantissa -extern const real c9; //!< Random fp value using entire mantissa +constexpr real czero = 0.0; //!< zero +constexpr real c0 = 0.0 + 1.0/3.0; //!< test constant +constexpr real c1 = 1.0 + 5.0/7.0; //!< test constant +constexpr real c2 = 2.0 + 9.0/13.0; //!< test constant +constexpr real c3 = 3.0 + 17.0/19.0; //!< test constant +constexpr real c4 = 4.0 + 23.0/29.0; //!< test constant +constexpr real c5 = 5.0 + 31.0/37.0; //!< test constant +constexpr real c6 = 6.0 + 41.0/43.0; //!< test constant +constexpr real c7 = 7.0 + 47.0/53.0; //!< test constant +constexpr real c8 = 8.0 + 59.0/61.0; //!< test constant /*! \} */ /*! \endcond */ diff --git a/src/gromacs/simd/tests/scalar.cpp b/src/gromacs/simd/tests/scalar.cpp index cfd77f153b..2b3f9f9e6a 100644 --- a/src/gromacs/simd/tests/scalar.cpp +++ b/src/gromacs/simd/tests/scalar.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -42,6 +42,8 @@ #include "gromacs/utility/basedefinitions.h" #include "gromacs/utility/real.h" +#include "testutils/testasserts.h" + #include "data.h" namespace gmx @@ -109,40 +111,40 @@ TEST(SimdScalarTest, andNot) TEST(SimdScalarTest, fma) { - EXPECT_EQ(c1*c2+c3, fma(real(c1), real(c2), real(c3))); + EXPECT_REAL_EQ_TOL(c1*c2+c3, fma(real(c1), real(c2), real(c3)), defaultRealTolerance()); } TEST(SimdScalarTest, fms) { - EXPECT_EQ(c1*c2-c3, fms(c1, c2, c3)); + EXPECT_REAL_EQ_TOL(c1*c2-c3, fms(c1, c2, c3), defaultRealTolerance()); } TEST(SimdScalarTest, fnma) { - EXPECT_EQ(-c1*c2+c3, fnma(c1, c2, c3)); + EXPECT_REAL_EQ_TOL(-c1*c2+c3, fnma(c1, c2, c3), defaultRealTolerance()); } TEST(SimdScalarTest, fnms) { - EXPECT_EQ(-c1*c2-c3, fnms(c1, c2, c3)); + EXPECT_REAL_EQ_TOL(-c1*c2-c3, fnms(c1, c2, c3), defaultRealTolerance()); } TEST(SimdScalarTest, maskAdd) { - EXPECT_EQ(c1, maskAdd(c1, c2, false)); - EXPECT_EQ(c1+c2, maskAdd(c1, c2, true)); + EXPECT_REAL_EQ_TOL(c1, maskAdd(c1, c2, false), defaultRealTolerance()); + EXPECT_REAL_EQ_TOL(c1+c2, maskAdd(c1, c2, true), defaultRealTolerance()); } TEST(SimdScalarTest, maskzMul) { - EXPECT_EQ(czero, maskzMul(c1, c2, false)); - EXPECT_EQ(c1*c2, maskzMul(c1, c2, true)); + EXPECT_REAL_EQ_TOL(czero, maskzMul(c1, c2, false), defaultRealTolerance()); + EXPECT_REAL_EQ_TOL(c1*c2, maskzMul(c1, c2, true), defaultRealTolerance()); } TEST(SimdScalarTest, maskzFma) { - EXPECT_EQ(czero, maskzFma(c1, c2, c3, false)); - EXPECT_EQ(c1*c2+c3, maskzFma(c1, c2, c3, true)); + EXPECT_REAL_EQ_TOL(czero, maskzFma(c1, c2, c3, false), defaultRealTolerance()); + EXPECT_REAL_EQ_TOL(c1*c2+c3, maskzFma(c1, c2, c3, true), defaultRealTolerance()); } TEST(SimdScalarTest, abs) diff --git a/src/gromacs/simd/tests/simd.h b/src/gromacs/simd/tests/simd.h index b4d08f4c58..60fb2ba2e8 100644 --- a/src/gromacs/simd/tests/simd.h +++ b/src/gromacs/simd/tests/simd.h @@ -189,7 +189,7 @@ class SimdTest : public SimdBaseTest ::testing::AssertionResult compareSimdRealUlp(const char * refExpr, const char * tstExpr, - const SimdReal ref, const SimdReal tst); + SimdReal ref, SimdReal tst); /*! \brief Compare two real SIMD variables for exact equality. * @@ -205,7 +205,7 @@ class SimdTest : public SimdBaseTest */ ::testing::AssertionResult compareSimdEq(const char * refExpr, const char * tstExpr, - const SimdReal ref, const SimdReal tst); + SimdReal ref, SimdReal tst); /*! \brief Compare two 32-bit integer SIMD variables. * @@ -221,7 +221,7 @@ class SimdTest : public SimdBaseTest */ ::testing::AssertionResult compareSimdEq(const char * refExpr, const char * tstExpr, - const SimdInt32 ref, const SimdInt32 tst); + SimdInt32 ref, SimdInt32 tst); #endif }; @@ -230,7 +230,7 @@ class SimdTest : public SimdBaseTest * * The returned vector will have the same length as the SIMD width. */ -std::vector simdReal2Vector(const SimdReal simd); +std::vector simdReal2Vector(SimdReal simd); /*! \brief Return floating-point SIMD value from std::vector. * @@ -268,7 +268,7 @@ SimdReal setSimdRealFrom1R(real value); * * The returned vector will have the same length as the SIMD width. */ -std::vector simdInt2Vector(const SimdInt32 simd); +std::vector simdInt2Vector(SimdInt32 simd); /*! \brief Return 32-bit integer SIMD value from std::vector. * diff --git a/src/gromacs/simd/tests/simd4.h b/src/gromacs/simd/tests/simd4.h index 4d4eecde53..b7971035dd 100644 --- a/src/gromacs/simd/tests/simd4.h +++ b/src/gromacs/simd/tests/simd4.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015,2017, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -122,7 +122,7 @@ class Simd4Test : public SimdBaseTest */ ::testing::AssertionResult compareSimd4RealUlp(const char * refExpr, const char * tstExpr, - const Simd4Real ref, const Simd4Real tst); + Simd4Real ref, Simd4Real tst); /*! \brief Compare two real SIMD4 variables for exact equality. * @@ -138,14 +138,14 @@ class Simd4Test : public SimdBaseTest */ ::testing::AssertionResult compareSimd4RealEq(const char * refExpr, const char * tstExpr, - const Simd4Real ref, const Simd4Real tst); + Simd4Real ref, Simd4Real tst); }; /*! \brief Convert SIMD4 real to std::vector. * * The returned vector will have the same length as the SIMD4 width. */ -std::vector simd4Real2Vector(const Simd4Real simd4); +std::vector simd4Real2Vector(Simd4Real simd4); /*! \brief Return floating-point SIMD4 value from std::vector. * diff --git a/src/gromacs/simd/tests/simd4_math.cpp b/src/gromacs/simd/tests/simd4_math.cpp index d1f7aacccf..989eca2800 100644 --- a/src/gromacs/simd/tests/simd4_math.cpp +++ b/src/gromacs/simd/tests/simd4_math.cpp @@ -36,6 +36,7 @@ #include "config.h" +#include #include #include @@ -124,17 +125,17 @@ Simd4MathTest::compareSimd4MathFunction(const char * refFuncExpr, const char *si vtst = simd4Real2Vector(simd4Func(vector2Simd4Real(vx))); bool eq = true, signOk = true; - for (int i = 0; i < GMX_SIMD4_WIDTH && eq == true; i++) + for (int i = 0; i < GMX_SIMD4_WIDTH && eq; i++) { - eq = eq && ( fabs(vref[i]-vtst[i]) < absTol_ ); + eq = eq && ( std::abs(vref[i]-vtst[i]) < absTol_ ); signOk = signOk && ( vref[i]*vtst[i] >= 0 ); } - if (eq == true) + if (eq) { // Go to next point if everything within absolute tolerance continue; } - else if (signOk == false) + else if (!signOk) { return ::testing::AssertionFailure() << "Failing SIMD4 math function comparison due to sign differences." << std::endl @@ -195,7 +196,7 @@ namespace /*! \{ */ /*! \brief Function wrapper to evaluate reference 1/sqrt(x) */ -static real +real refInvsqrt(real x) { return 1.0/std::sqrt(x); @@ -211,7 +212,7 @@ TEST_F(Simd4MathTest, invsqrtSingleaccuracy) { setRange(1e-10, 1e10); /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); GMX_EXPECT_SIMD4_FUNC_NEAR(refInvsqrt, invsqrtSingleAccuracy); } diff --git a/src/gromacs/simd/tests/simd_math.cpp b/src/gromacs/simd/tests/simd_math.cpp index 7c1e65195a..a62d893a9a 100644 --- a/src/gromacs/simd/tests/simd_math.cpp +++ b/src/gromacs/simd/tests/simd_math.cpp @@ -162,7 +162,7 @@ SimdMathTest::compareSimdMathFunction(const char * refFuncExpr, } } - absDiff = fabs(vref[i]-vtst[i]); + absDiff = std::abs(vref[i]-vtst[i]); absOk = absOk && ( absDiff < absTol_ ); signOk = signOk && ( (vref[i] >= 0 && vtst[i] >= 0) || (vref[i] <= 0 && vtst[i] <= 0)); @@ -186,7 +186,7 @@ SimdMathTest::compareSimdMathFunction(const char * refFuncExpr, } } } - if ( (absOk == false) && (signOk == false) ) + if ( (!absOk) && (!signOk) ) { return ::testing::AssertionFailure() << "Failing SIMD math function comparison due to sign differences." << std::endl @@ -241,7 +241,7 @@ TEST_F(SimdMathTest, copysign) } /*! \brief Function wrapper to evaluate reference 1/sqrt(x) */ -static real +real refInvsqrt(real x) { return 1.0/std::sqrt(x); @@ -291,15 +291,14 @@ TEST_F(SimdMathTest, invsqrtPair) } /*! \brief Function wrapper to evaluate reference sqrt(x) */ -static real +real refSqrt(real x) { return std::sqrt(x); } /*! \brief Dummy function returning 0.0 to test function ranges that should be zero */ -gmx_unused static real -refZero(real gmx_unused x) +gmx_unused real refZero(real gmx_unused x) { return 0.0; } @@ -664,7 +663,7 @@ TEST_F(SimdMathTest, pmePotentialCorrection) TEST_F(SimdMathTest, invsqrtSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); setRange(1.01*GMX_FLOAT_MIN, GMX_FLOAT_MAX); GMX_EXPECT_SIMD_FUNC_NEAR(refInvsqrt, invsqrtSingleAccuracy); @@ -691,7 +690,7 @@ tst_invsqrt_SingleAccuracy_pair1(SimdReal x) TEST_F(SimdMathTest, invsqrtPairSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); setRange(1.01*GMX_FLOAT_MIN, GMX_FLOAT_MAX); GMX_EXPECT_SIMD_FUNC_NEAR(refInvsqrt, tst_invsqrt_SingleAccuracy_pair0); @@ -701,7 +700,7 @@ TEST_F(SimdMathTest, invsqrtPairSingleAccuracy) TEST_F(SimdMathTest, sqrtSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); // First test that 0.0 and a few other values works GMX_EXPECT_SIMD_REAL_NEAR(setSimdRealFrom3R(0, std::sqrt(c0), std::sqrt(c1)), sqrtSingleAccuracy(setSimdRealFrom3R(0, c0, c1))); @@ -721,7 +720,7 @@ TEST_F(SimdMathTest, sqrtSingleAccuracy) TEST_F(SimdMathTest, sqrtSingleAccuracyUnsafe) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); // Test the full range setRange(GMX_FLOAT_MIN, GMX_FLOAT_MAX); @@ -731,7 +730,7 @@ TEST_F(SimdMathTest, sqrtSingleAccuracyUnsafe) TEST_F(SimdMathTest, invSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); // test <0 setRange(-1e10, -1e-10); @@ -743,7 +742,7 @@ TEST_F(SimdMathTest, invSingleAccuracy) TEST_F(SimdMathTest, logSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); setRange(1e-30, 1e30); GMX_EXPECT_SIMD_FUNC_NEAR(std::log, logSingleAccuracy); @@ -752,7 +751,7 @@ TEST_F(SimdMathTest, logSingleAccuracy) TEST_F(SimdMathTest, exp2SingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); #if GMX_DOUBLE setRange(-1022.49, 1023.49); @@ -780,7 +779,7 @@ TEST_F(SimdMathTest, exp2SingleAccuracy) TEST_F(SimdMathTest, exp2SingleAccuracyUnsafe) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); #if GMX_DOUBLE setRange(-1022.49, 1023.49); @@ -793,7 +792,7 @@ TEST_F(SimdMathTest, exp2SingleAccuracyUnsafe) TEST_F(SimdMathTest, expSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); #if GMX_DOUBLE setRange(-708.7, 709.4); @@ -823,7 +822,7 @@ TEST_F(SimdMathTest, expSingleAccuracy) TEST_F(SimdMathTest, expSingleAccuracyUnsafe) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); #if GMX_DOUBLE setRange(-708.7, 709.4); @@ -836,7 +835,7 @@ TEST_F(SimdMathTest, expSingleAccuracyUnsafe) TEST_F(SimdMathTest, erfSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); setRange(-9, 9); setAbsTol(GMX_REAL_MIN); @@ -846,7 +845,7 @@ TEST_F(SimdMathTest, erfSingleAccuracy) TEST_F(SimdMathTest, erfcSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); setRange(-9, 9); setAbsTol(GMX_REAL_MIN); @@ -859,7 +858,7 @@ TEST_F(SimdMathTest, erfcSingleAccuracy) TEST_F(SimdMathTest, sinSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); setRange(-8*M_PI, 8*M_PI); GMX_EXPECT_SIMD_FUNC_NEAR(std::sin, sinSingleAccuracy); @@ -872,7 +871,7 @@ TEST_F(SimdMathTest, sinSingleAccuracy) TEST_F(SimdMathTest, cosSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); setRange(-8*M_PI, 8*M_PI); GMX_EXPECT_SIMD_FUNC_NEAR(std::cos, cosSingleAccuracy); @@ -884,7 +883,7 @@ TEST_F(SimdMathTest, cosSingleAccuracy) TEST_F(SimdMathTest, tanSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); // Tan(x) is a little sensitive due to the division in the algorithm. // Rather than using lots of extra FP operations, we accept the algorithm @@ -899,7 +898,7 @@ TEST_F(SimdMathTest, tanSingleAccuracy) TEST_F(SimdMathTest, asinSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); // Our present asin(x) algorithm achieves 2-3 ulp accuracy setRange(-1, 1); @@ -909,7 +908,7 @@ TEST_F(SimdMathTest, asinSingleAccuracy) TEST_F(SimdMathTest, acosSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); // Our present acos(x) algorithm achieves 2-3 ulp accuracy setRange(-1, 1); @@ -919,7 +918,7 @@ TEST_F(SimdMathTest, acosSingleAccuracy) TEST_F(SimdMathTest, atanSingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); // Our present atan(x) algorithm achieves 1 ulp accuracy setRange(-10000, 10000); @@ -929,7 +928,7 @@ TEST_F(SimdMathTest, atanSingleAccuracy) TEST_F(SimdMathTest, atan2SingleAccuracy) { /* Increase the allowed error by the difference between the actual precision and single */ - setUlpTol(ulpTol_ * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(ulpTol_); // test each quadrant GMX_EXPECT_SIMD_REAL_NEAR(setSimdRealFrom3R(std::atan2(c0, c3), std::atan2(c1, c4), std::atan2(c2, c5)), @@ -961,7 +960,7 @@ TEST_F(SimdMathTest, pmeForceCorrectionSingleAccuracy) // The PME corrections will be added to ~1/r2, so absolute tolerance of EPS is fine. // Pme correction only needs to be ~1e-6 accuracy single. // Then increase the allowed error by the difference between the actual precision and single. - setUlpTol( (std::int64_t(5e-6/GMX_FLOAT_EPS)) * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(std::int64_t(5e-6/GMX_FLOAT_EPS)); setRange(0.15, 4); setAbsTol(GMX_FLOAT_EPS); @@ -973,7 +972,7 @@ TEST_F(SimdMathTest, pmePotentialCorrectionSingleAccuracy) // The PME corrections will be added to ~1/r, so absolute tolerance of EPS is fine. // Pme correction only needs to be ~1e-6 accuracy single. // Then increase the allowed error by the difference between the actual precision and single. - setUlpTol( (std::int64_t(5e-6/GMX_FLOAT_EPS)) * (1LL << (std::numeric_limits::digits-std::numeric_limits::digits))); + setUlpTolSingleAccuracy(std::int64_t(5e-6/GMX_FLOAT_EPS)); setRange(0.15, 4); setAbsTol(GMX_FLOAT_EPS); diff --git a/src/gromacs/tables/tests/splinetable.cpp b/src/gromacs/tables/tests/splinetable.cpp index afb40706b0..44c7061b93 100644 --- a/src/gromacs/tables/tests/splinetable.cpp +++ b/src/gromacs/tables/tests/splinetable.cpp @@ -135,7 +135,7 @@ SplineTableTest::testSplineTableAgainstFunctions(const std::string FloatingPointTolerance funcTolerance(relativeToleranceAsFloatingPoint(0.0, tolerance_)); - for (real x = testRange.first; x < testRange.second; x += dx) + for (real x = testRange.first; x < testRange.second; x += dx) // NOLINT(clang-analyzer-security.FloatLoopCounter) { real h = std::sqrt(GMX_REAL_EPS); real secondDerivative = (refDer(x+h)-refDer(x))/h; diff --git a/src/gromacs/trajectoryanalysis/tests/surfacearea.cpp b/src/gromacs/trajectoryanalysis/tests/surfacearea.cpp index cdc64442bc..73a874e620 100644 --- a/src/gromacs/trajectoryanalysis/tests/surfacearea.cpp +++ b/src/gromacs/trajectoryanalysis/tests/surfacearea.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -104,17 +104,6 @@ class SurfaceAreaTest : public ::testing::Test *radius = 1.5*dist(rng_) + 0.5; } - void addDummySpheres(int count) - { - for (int i = 0; i < count; ++i) - { - rvec x; - real radius; - generateRandomPosition(x, &radius); - addSphere(x[XX], x[YY], x[ZZ], radius, false); - } - } - void generateRandomPositions(int count) { x_.reserve(count); diff --git a/src/gromacs/utility/bitmask.h b/src/gromacs/utility/bitmask.h index 40b897bff3..d0e3c09572 100644 --- a/src/gromacs/utility/bitmask.h +++ b/src/gromacs/utility/bitmask.h @@ -48,6 +48,8 @@ #include +#include + #include "gromacs/utility/basedefinitions.h" /*! \brief Size of bitmask. Has to be 32 or multiple of 64. */ @@ -121,34 +123,34 @@ inline static void bitmask_union(gmx_bitmask_t* a, gmx_bitmask_t b) } #else #define BITMASK_ALEN (BITMASK_SIZE/64) -typedef uint64_t gmx_bitmask_t[BITMASK_ALEN]; +using gmx_bitmask_t = std::array; inline static void bitmask_clear(gmx_bitmask_t* m) { - memset(*m, 0, BITMASK_SIZE/8); + m->fill(0); } inline static void bitmask_set_bit(gmx_bitmask_t* m, int b) { - (*m)[b/64] |= ((uint64_t)1 << (b%64)); + (*m)[b/64] |= (static_cast(1) << (b%64)); } inline static void bitmask_init_bit(gmx_bitmask_t* m, int b) { bitmask_clear(m); - (*m)[b/64] = ((uint64_t)1 << (b%64)); + (*m)[b/64] = (static_cast(1) << (b%64)); } inline static void bitmask_init_low_bits(gmx_bitmask_t* m, int b) { - memset(*m, 255, b/64*8); - (*m)[b/64] = ((uint64_t)1 << (b%64)) - 1; - memset(&(*m)[b/64+1], 0, (BITMASK_ALEN-b/64-1)*8); + memset(m->data(), 255, b/64*8); + (*m)[b/64] = (static_cast(1) << (b%64)) - 1; + memset(&(m->data())[b/64+1], 0, (BITMASK_ALEN-b/64-1)*8); } inline static bool bitmask_is_set(gmx_bitmask_t m, int b) { - return (m[b/64] & ((uint64_t)1 << (b%64))) != 0; + return (m[b/64] & (static_cast(1) << (b%64))) != 0; } inline static bool bitmask_is_disjoint(gmx_bitmask_t a, gmx_bitmask_t b) diff --git a/src/gromacs/utility/tests/alignedallocator-impl.h b/src/gromacs/utility/tests/alignedallocator-impl.h index d592288200..1982c1a874 100644 --- a/src/gromacs/utility/tests/alignedallocator-impl.h +++ b/src/gromacs/utility/tests/alignedallocator-impl.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2017, by the GROMACS development team, led by + * Copyright (c) 2015,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -80,7 +80,7 @@ class AllocatorTest : public ::testing::Test // NB need to use this->mask() because of GoogleTest quirks -TYPED_TEST(AllocatorTest, AllocatorAlignAllocatesWithAlignment) +TYPED_TEST(AllocatorTest, AllocatorAlignAllocatesWithAlignment) //NOLINT(misc-definitions-in-headers) { using pointer = typename TypeParam::pointer; TypeParam a; @@ -91,7 +91,7 @@ TYPED_TEST(AllocatorTest, AllocatorAlignAllocatesWithAlignment) } -TYPED_TEST(AllocatorTest, VectorAllocatesAndResizesWithAlignment) +TYPED_TEST(AllocatorTest, VectorAllocatesAndResizesWithAlignment) //NOLINT(misc-definitions-in-headers) { using value_type = typename TypeParam::value_type; std::vector v(10); @@ -107,7 +107,7 @@ TYPED_TEST(AllocatorTest, VectorAllocatesAndResizesWithAlignment) } } -TYPED_TEST(AllocatorTest, VectorAllocatesAndReservesWithAlignment) +TYPED_TEST(AllocatorTest, VectorAllocatesAndReservesWithAlignment) //NOLINT(misc-definitions-in-headers) { using value_type = typename TypeParam::value_type; std::vector v(10); diff --git a/src/gromacs/utility/tests/arrayref.cpp b/src/gromacs/utility/tests/arrayref.cpp index f6f98fcabc..99153f5b5d 100644 --- a/src/gromacs/utility/tests/arrayref.cpp +++ b/src/gromacs/utility/tests/arrayref.cpp @@ -147,7 +147,7 @@ TYPED_TEST_CASE(ArrayRefTest, ArrayRefTypes); static_cast(2.4), \ static_cast(3.1) \ }; \ - size_t (aSize) = sizeof((a)) / sizeof(typename TestFixture::ValueType); + size_t aSize = sizeof((a)) / sizeof(typename TestFixture::ValueType); #define DEFINE_NON_CONST_ARRAY(a, aSize) \ typename TestFixture::NonConstValueType (a)[] = { \ @@ -155,7 +155,7 @@ TYPED_TEST_CASE(ArrayRefTest, ArrayRefTypes); static_cast(2.4), \ static_cast(3.1) \ }; \ - size_t (aSize) = sizeof((a)) / sizeof(typename TestFixture::ValueType); + size_t aSize = sizeof((a)) / sizeof(typename TestFixture::ValueType); TYPED_TEST(ArrayRefTest, MakeWithAssignmentWorks) diff --git a/src/gromacs/utility/tests/bitmask.h b/src/gromacs/utility/tests/bitmask.h index 3cc5376b1f..9fb0dd0c9e 100644 --- a/src/gromacs/utility/tests/bitmask.h +++ b/src/gromacs/utility/tests/bitmask.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2014, by the GROMACS development team, led by + * Copyright (c) 2014,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -58,7 +58,7 @@ class BITMASK_CLASSNAME(BITMASK_SIZE) : public ::testing::TestWithParam { }; -BITMASK_TEST_P(SetAndClear) +BITMASK_TEST_P(SetAndClear) //NOLINT(misc-definitions-in-headers) { gmx_bitmask_t m; int i = GetParam(); @@ -74,7 +74,7 @@ BITMASK_TEST_P(SetAndClear) EXPECT_TRUE(bitmask_is_zero(m)); } -BITMASK_TEST_P(InitBit) +BITMASK_TEST_P(InitBit) //NOLINT(misc-definitions-in-headers) { gmx_bitmask_t m1, m2; int i = GetParam(); @@ -85,7 +85,7 @@ BITMASK_TEST_P(InitBit) EXPECT_TRUE(bitmask_is_equal(m1, m2)); } -BITMASK_TEST_P(InitLowBits) +BITMASK_TEST_P(InitLowBits) //NOLINT(misc-definitions-in-headers) { gmx_bitmask_t m; int i = GetParam(); @@ -96,7 +96,7 @@ BITMASK_TEST_P(InitLowBits) } } -BITMASK_TEST_P(Disjoint) +BITMASK_TEST_P(Disjoint) //NOLINT(misc-definitions-in-headers) { gmx_bitmask_t m1, m2; int i = GetParam(); @@ -107,7 +107,7 @@ BITMASK_TEST_P(Disjoint) EXPECT_TRUE(bitmask_is_disjoint(m1, m2)); } -BITMASK_TEST_P(Union) +BITMASK_TEST_P(Union) //NOLINT(misc-definitions-in-headers) { gmx_bitmask_t m1, m2; int i = GetParam(); diff --git a/src/gromacs/utility/tests/mutex.cpp b/src/gromacs/utility/tests/mutex.cpp index 4fbc0ad947..2cc6990c15 100644 --- a/src/gromacs/utility/tests/mutex.cpp +++ b/src/gromacs/utility/tests/mutex.cpp @@ -94,9 +94,9 @@ TEST(MutexBasicTest, CanBeUsedInLockGuard) } //! A shared value for a mutex to protect -static int g_sharedValue; +int g_sharedValue; //! A mutex to protect a shared value -static Mutex g_sharedValueMutex; +Mutex g_sharedValueMutex; //! Function type for asynchronous tasks. using TaskType = std::function; diff --git a/src/programs/mdrun/mdrun.cpp b/src/programs/mdrun/mdrun.cpp index 8a5c3278a2..1d56da89b9 100644 --- a/src/programs/mdrun/mdrun.cpp +++ b/src/programs/mdrun/mdrun.cpp @@ -215,8 +215,8 @@ int Mdrunner::mainFunction(int argc, char *argv[]) "exceeds [TT]-maxh[tt]\\*0.99 hours. This option is particularly useful in", "combination with setting [TT]nsteps[tt] to -1 either in the mdp or using the", "similarly named command line option. This results in an infinite run,", - "terminated only when the time limit set by [TT]-maxh[tt] is reached (if any)" - "or upon receiving a signal." + "terminated only when the time limit set by [TT]-maxh[tt] is reached (if any)", + "or upon receiving a signal.", "[PAR]", "When [TT]mdrun[tt] receives a TERM or INT signal (e.g. when ctrl+C is", "pressed), it will stop at the next neighbor search step or at the", @@ -239,7 +239,7 @@ int Mdrunner::mainFunction(int argc, char *argv[]) "IMD remote can be turned on by [TT]-imdpull[tt].", "The port [TT]mdrun[tt] listens to can be altered by [TT]-imdport[tt].The", "file pointed to by [TT]-if[tt] contains atom indices and forces if IMD", - "pulling is used." + "pulling is used.", "[PAR]", "When [TT]mdrun[tt] is started with MPI, it does not run niced by default." }; @@ -499,9 +499,9 @@ int Mdrunner::mainFunction(int argc, char *argv[]) domdecOptions.rankOrder = static_cast(nenum(ddrank_opt_choices)); domdecOptions.dlbOption = static_cast(nenum(dddlb_opt_choices)); - domdecOptions.numCells[XX] = (int)(realddxyz[XX] + 0.5); - domdecOptions.numCells[YY] = (int)(realddxyz[YY] + 0.5); - domdecOptions.numCells[ZZ] = (int)(realddxyz[ZZ] + 0.5); + domdecOptions.numCells[XX] = static_cast(realddxyz[XX] + 0.5); + domdecOptions.numCells[YY] = static_cast(realddxyz[YY] + 0.5); + domdecOptions.numCells[ZZ] = static_cast(realddxyz[ZZ] + 0.5); nbpu_opt = nbpu_opt_choices[0]; pme_opt = pme_opt_choices[0]; diff --git a/src/programs/mdrun/tests/energyreader.cpp b/src/programs/mdrun/tests/energyreader.cpp index 2069aaaeb7..91a742424f 100644 --- a/src/programs/mdrun/tests/energyreader.cpp +++ b/src/programs/mdrun/tests/energyreader.cpp @@ -94,7 +94,7 @@ openEnergyFileToReadFields(const std::string &filename, auto requiredEnergy = std::find_if(std::begin(namesOfRequiredEnergyFields), std::end(namesOfRequiredEnergyFields), [name](const std::string &n){ - return 0 == n.compare(name); + return name == n; }); if (requiredEnergy != namesOfRequiredEnergyFields.end()) { diff --git a/src/programs/mdrun/tests/initialconstraints.cpp b/src/programs/mdrun/tests/initialconstraints.cpp index 8441ef7a73..9b3e4c1afe 100644 --- a/src/programs/mdrun/tests/initialconstraints.cpp +++ b/src/programs/mdrun/tests/initialconstraints.cpp @@ -124,7 +124,7 @@ TEST_P(InitialConstraintsTest, Works) } //! Integrators with energy conservation to test -static const EnergyIntegratorType c_integratorsToTest [] = {"md", "md-vv", "md-vv-avek"}; +const EnergyIntegratorType c_integratorsToTest [] = {"md", "md-vv", "md-vv-avek"}; INSTANTIATE_TEST_CASE_P(Checking, InitialConstraintsTest, ::testing::ValuesIn(c_integratorsToTest)); diff --git a/src/programs/mdrun/tests/moduletest.cpp b/src/programs/mdrun/tests/moduletest.cpp index de04f7f7b9..aeed2e7cf3 100644 --- a/src/programs/mdrun/tests/moduletest.cpp +++ b/src/programs/mdrun/tests/moduletest.cpp @@ -92,10 +92,6 @@ GMX_TEST_OPTIONS(MdrunTestOptions, options) } SimulationRunner::SimulationRunner(TestFileManager *fileManager) : - topFileName_(), - groFileName_(), - fullPrecisionTrajectoryFileName_(), - ndxFileName_(), mdpOutputFileName_(fileManager->getTemporaryFilePath("output.mdp")), tprFileName_(fileManager->getTemporaryFilePath(".tpr")), logFileName_(fileManager->getTemporaryFilePath(".log")), @@ -143,15 +139,15 @@ SimulationRunner::useStringAsNdxFile(const char *ndxString) void SimulationRunner::useTopGroAndNdxFromDatabase(const char *name) { - topFileName_ = fileManager_.getInputFilePath((std::string(name) + ".top").c_str()); - groFileName_ = fileManager_.getInputFilePath((std::string(name) + ".gro").c_str()); - ndxFileName_ = fileManager_.getInputFilePath((std::string(name) + ".ndx").c_str()); + topFileName_ = gmx::test::TestFileManager::getInputFilePath((std::string(name) + ".top").c_str()); + groFileName_ = gmx::test::TestFileManager::getInputFilePath((std::string(name) + ".gro").c_str()); + ndxFileName_ = gmx::test::TestFileManager::getInputFilePath((std::string(name) + ".ndx").c_str()); } void SimulationRunner::useGroFromDatabase(const char *name) { - groFileName_ = fileManager_.getInputFilePath((std::string(name) + ".gro").c_str()); + groFileName_ = gmx::test::TestFileManager::getInputFilePath((std::string(name) + ".gro").c_str()); } int diff --git a/src/programs/mdrun/tests/multisimtest.cpp b/src/programs/mdrun/tests/multisimtest.cpp index bfa3378a3f..add40e2a6d 100644 --- a/src/programs/mdrun/tests/multisimtest.cpp +++ b/src/programs/mdrun/tests/multisimtest.cpp @@ -68,8 +68,8 @@ namespace test MultiSimTest::MultiSimTest() : size_(gmx_node_num()), rank_(gmx_node_rank()), - mdrunCaller_(new CommandLine), - fileManager_() + mdrunCaller_(new CommandLine) + { const char *directoryNameFormat = "sim_%d"; diff --git a/src/programs/mdrun/tests/rerun.cpp b/src/programs/mdrun/tests/rerun.cpp index 84368cee16..598828cf4f 100644 --- a/src/programs/mdrun/tests/rerun.cpp +++ b/src/programs/mdrun/tests/rerun.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2013,2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -68,7 +68,7 @@ TEST_P(MdrunRerun, WithDifferentInputFormats) runner_.useTopGroAndNdxFromDatabase("spc2"); EXPECT_EQ(0, runner_.callGrompp()); - std::string rerunFileName = fileManager_.getInputFilePath(GetParam()); + std::string rerunFileName = gmx::test::TestFileManager::getInputFilePath(GetParam()); ::gmx::test::CommandLine rerunCaller; rerunCaller.append("mdrun"); diff --git a/src/programs/mdrun/tests/tabulated_bonded_interactions.cpp b/src/programs/mdrun/tests/tabulated_bonded_interactions.cpp index 4e18b667f8..794b342666 100644 --- a/src/programs/mdrun/tests/tabulated_bonded_interactions.cpp +++ b/src/programs/mdrun/tests/tabulated_bonded_interactions.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2016, by the GROMACS development team, led by + * Copyright (c) 2016,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -57,7 +57,7 @@ namespace test { //! Format string for building a configurable .top file -const char *g_butaneTopFileFormatString = "\ +static const char *g_butaneTopFileFormatString = "\ [ defaults ]\n\ ; nbfunc comb-rule gen-pairs fudgeLJ fudgeQQ\n\ 1 1 no 1.0 1.0\n\ @@ -98,8 +98,8 @@ class BondedInteractionsTest : public gmx::test::MdrunTestFixture { runner_.topFileName_ = fileManager_.getTemporaryFilePath("butane1.top"); TextWriter::writeFileFromString(runner_.topFileName_, formatString(g_butaneTopFileFormatString, interaction)); - runner_.groFileName_ = fileManager_.getInputFilePath("butane1.gro"); - runner_.ndxFileName_ = fileManager_.getInputFilePath("butane1.ndx"); + runner_.groFileName_ = gmx::test::TestFileManager::getInputFilePath("butane1.gro"); + runner_.ndxFileName_ = gmx::test::TestFileManager::getInputFilePath("butane1.ndx"); /* TODO Now that Verlet is the default, change the implementation of useEmptyMdpFile() to do that. */ runner_.useStringAsMdpFile(""); @@ -142,7 +142,7 @@ TEST_F(BondedInteractionsTest, TabulatedBondWorks) EXPECT_EQ(0, runner_.callGrompp()); test::CommandLine rerunCaller = setupMdrun(); - std::string tableFileName = fileManager_.getInputFilePath("butane_b0.xvg"); + std::string tableFileName = gmx::test::TestFileManager::getInputFilePath("butane_b0.xvg"); rerunCaller.addOption("-tableb", tableFileName); ASSERT_EQ(0, runner_.callMdrun(rerunCaller)); checkMdrun(); @@ -170,7 +170,7 @@ TEST_F(BondedInteractionsTest, TabulatedAngleWorks) EXPECT_EQ(0, runner_.callGrompp()); test::CommandLine rerunCaller = setupMdrun(); - std::string tableFileName = fileManager_.getInputFilePath("butane_a0.xvg"); + std::string tableFileName = gmx::test::TestFileManager::getInputFilePath("butane_a0.xvg"); rerunCaller.addOption("-tableb", tableFileName); ASSERT_EQ(0, runner_.callMdrun(rerunCaller)); checkMdrun(); @@ -198,7 +198,7 @@ TEST_F(BondedInteractionsTest, TabulatedDihedralWorks) EXPECT_EQ(0, runner_.callGrompp()); test::CommandLine rerunCaller = setupMdrun(); - std::string tableFileName = fileManager_.getInputFilePath("butane_d0.xvg"); + std::string tableFileName = gmx::test::TestFileManager::getInputFilePath("butane_d0.xvg"); rerunCaller.addOption("-tableb", tableFileName); ASSERT_EQ(0, runner_.callMdrun(rerunCaller)); checkMdrun(); diff --git a/src/programs/mdrun/tests/tpitest.cpp b/src/programs/mdrun/tests/tpitest.cpp index 70a56342a9..db16d0c93b 100644 --- a/src/programs/mdrun/tests/tpitest.cpp +++ b/src/programs/mdrun/tests/tpitest.cpp @@ -75,7 +75,7 @@ void TpiTest::runTest() runner_.ndxFileName_ = ""; ASSERT_EQ(0, runner_.callGrompp()); - auto rerunFileName = fileManager_.getInputFilePath("spc216.gro"); + auto rerunFileName = gmx::test::TestFileManager::getInputFilePath("spc216.gro"); CommandLine commandLine; commandLine.append("-rerun"); commandLine.append(rerunFileName); diff --git a/src/testutils/TestMacros.cmake b/src/testutils/TestMacros.cmake index 4204f7a7cd..9fc88f3c98 100644 --- a/src/testutils/TestMacros.cmake +++ b/src/testutils/TestMacros.cmake @@ -83,6 +83,13 @@ function (gmx_add_gtest_executable EXENAME) APPEND PROPERTY COMPILE_DEFINITIONS "${GMOCK_COMPILE_DEFINITIONS}") set_property(TARGET ${EXENAME} APPEND PROPERTY COMPILE_DEFINITIONS "${EXTRA_COMPILE_DEFINITIONS}") + if(GMX_CLANG_TIDY) + set_target_properties(${EXENAME} PROPERTIES CXX_CLANG_TIDY + "${CLANG_TIDY_EXE};-warnings-as-errors=*;-header-filter=.*") + endif() + if (CMAKE_CXX_COMPILER_ID MATCHES "Clang" AND CMAKE_CXX_COMPILER_VERSION MATCHES "^6\.0") + target_compile_options(${EXENAME} PRIVATE $<$:-Weverything ${IGNORED_CLANG_ALL_WARNINGS} -Wno-gnu-zero-variadic-macro-arguments -Wno-zero-as-null-pointer-constant -Wno-missing-variable-declarations>) + endif() endif() endfunction() diff --git a/src/testutils/cmdlinetest.cpp b/src/testutils/cmdlinetest.cpp index b88b3138bb..c2cdc40520 100644 --- a/src/testutils/cmdlinetest.cpp +++ b/src/testutils/cmdlinetest.cpp @@ -319,8 +319,8 @@ int CommandLineTestHelper::runModuleDirect( // static int CommandLineTestHelper::runModuleFactory( - std::function()> factory, - CommandLine *commandLine) + const std::function()> &factory, + CommandLine *commandLine) { return runModuleDirect(factory(), commandLine); } diff --git a/src/testutils/cmdlinetest.h b/src/testutils/cmdlinetest.h index 7d9204625f..c488dc6af1 100644 --- a/src/testutils/cmdlinetest.h +++ b/src/testutils/cmdlinetest.h @@ -258,8 +258,8 @@ class CommandLineTestHelper * module. */ static int - runModuleFactory(std::function()> factory, - CommandLine *commandLine); + runModuleFactory(const std::function()> &factory, + CommandLine *commandLine); /*! \brief * Initializes an instance. diff --git a/src/testutils/conftest.cpp b/src/testutils/conftest.cpp index dc591eea3a..e98dfd0cc8 100644 --- a/src/testutils/conftest.cpp +++ b/src/testutils/conftest.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2017, by the GROMACS development team, led by + * Copyright (c) 2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -83,7 +83,7 @@ class ConfMatcher : public ITextBlockMatcher void checkConfFile(TextInputStream *input, TestReferenceChecker *checker, - const ConfMatchSettings &) + const ConfMatchSettings & /*unused*/) { TestReferenceChecker groChecker(checker->checkCompound("GroFile", "Header")); diff --git a/src/testutils/interactivetest.cpp b/src/testutils/interactivetest.cpp index 0944b066db..5874e9dc91 100644 --- a/src/testutils/interactivetest.cpp +++ b/src/testutils/interactivetest.cpp @@ -44,6 +44,7 @@ #include "interactivetest.h" #include +#include #include #include @@ -83,7 +84,7 @@ class InteractiveTestHelper::Impl { public: explicit Impl(TestReferenceChecker checker) - : checker_(checker), bLastNewline_(true), + : checker_(std::move(checker)), bLastNewline_(true), currentLine_(0), bHasOutput_(false) { using ::testing::_; diff --git a/src/testutils/refdata-checkers.h b/src/testutils/refdata-checkers.h index 9a5c4fd0a4..2b35b9283b 100644 --- a/src/testutils/refdata-checkers.h +++ b/src/testutils/refdata-checkers.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -78,9 +78,9 @@ class IReferenceDataEntryChecker class NullChecker : public IReferenceDataEntryChecker { public: - virtual void fillEntry(ReferenceDataEntry *) const {} + virtual void fillEntry(ReferenceDataEntry * /*entry*/) const {} virtual ::testing::AssertionResult - checkEntry(const ReferenceDataEntry &, const std::string &) const + checkEntry(const ReferenceDataEntry & /*entry*/, const std::string & /*fullId*/) const { return ::testing::AssertionSuccess(); } @@ -240,12 +240,12 @@ class ValueExtractor : public IReferenceDataEntryChecker { } - virtual void fillEntry(ReferenceDataEntry *) const + virtual void fillEntry(ReferenceDataEntry * /*entry*/) const { GMX_THROW(TestException("Extracting value from non-existent reference data entry")); } virtual ::testing::AssertionResult - checkEntry(const ReferenceDataEntry &entry, const std::string &) const + checkEntry(const ReferenceDataEntry &entry, const std::string & /*fullId*/) const { extractValue(entry.value()); return ::testing::AssertionSuccess(); diff --git a/src/testutils/refdata-impl.h b/src/testutils/refdata-impl.h index 144668763c..440607dc58 100644 --- a/src/testutils/refdata-impl.h +++ b/src/testutils/refdata-impl.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -46,6 +46,7 @@ #include #include +#include "gromacs/compat/make_unique.h" #include "gromacs/utility/gmxassert.h" namespace gmx @@ -62,7 +63,7 @@ class ReferenceDataEntry static EntryPointer createRoot() { - return EntryPointer(new ReferenceDataEntry("", "")); + return gmx::compat::make_unique("", ""); } ReferenceDataEntry(const char *type, const char *id) diff --git a/src/testutils/refdata.cpp b/src/testutils/refdata.cpp index 8cdd31cb35..e0526def22 100644 --- a/src/testutils/refdata.cpp +++ b/src/testutils/refdata.cpp @@ -199,7 +199,7 @@ class ReferenceDataTestEventListener : public ::testing::EmptyTestEventListener } } - virtual void OnTestProgramEnd(const ::testing::UnitTest &) + virtual void OnTestProgramEnd(const ::testing::UnitTest & /*unused*/) { // Could be used e.g. to free internal buffers allocated by an XML parsing library } @@ -726,13 +726,13 @@ TestReferenceChecker::TestReferenceChecker(const TestReferenceChecker &other) { } -TestReferenceChecker::TestReferenceChecker(TestReferenceChecker &&other) +TestReferenceChecker::TestReferenceChecker(TestReferenceChecker &&other) noexcept : impl_(std::move(other.impl_)) { } TestReferenceChecker & -TestReferenceChecker::operator=(TestReferenceChecker &&other) +TestReferenceChecker::operator=(TestReferenceChecker &&other) noexcept { impl_ = std::move(other.impl_); return *this; diff --git a/src/testutils/refdata.h b/src/testutils/refdata.h index fb4dd712a1..f6a12445f3 100644 --- a/src/testutils/refdata.h +++ b/src/testutils/refdata.h @@ -252,13 +252,13 @@ class TestReferenceChecker //! Creates a deep copy of the other checker. explicit TestReferenceChecker(const TestReferenceChecker &other); //! Moves the checker. - TestReferenceChecker(TestReferenceChecker &&other); + TestReferenceChecker(TestReferenceChecker &&other) noexcept; ~TestReferenceChecker(); //! Prevents implicit copying during assignment. TestReferenceChecker &operator=(const TestReferenceChecker &) = delete; //! Assigns a test reference checker. - TestReferenceChecker &operator=(TestReferenceChecker &&other); + TestReferenceChecker &operator=(TestReferenceChecker &&other) noexcept; //! Returns whether the checker is initialized. bool isValid() const; diff --git a/src/testutils/testasserts.cpp b/src/testutils/testasserts.cpp index 1d8be9cd7d..c7990838d4 100644 --- a/src/testutils/testasserts.cpp +++ b/src/testutils/testasserts.cpp @@ -279,12 +279,7 @@ bool FloatingPointTolerance::isWithin( const uint64_t ulpTolerance = difference.isDouble() ? doubleUlpTolerance_ : singleUlpTolerance_; - if (ulpTolerance < UINT64_MAX && difference.asUlps() <= ulpTolerance) - { - return true; - } - - return false; + return ulpTolerance < UINT64_MAX && difference.asUlps() <= ulpTolerance; } std::string FloatingPointTolerance::toString(const FloatingPointDifference &difference) const diff --git a/src/testutils/testasserts.h b/src/testutils/testasserts.h index 2add34ba13..8e6b2e4d97 100644 --- a/src/testutils/testasserts.h +++ b/src/testutils/testasserts.h @@ -486,10 +486,10 @@ relativeToleranceAsUlp(double magnitude, uint64_t ulpDiff) return relativeToleranceAsPrecisionDependentUlp(magnitude, ulpDiff, ulpDiff); } -namespace +namespace detail { //! Default tolerance in ULPs for two floating-point values to compare equal. -static uint64_t g_defaultUlpTolerance = 4; +constexpr uint64_t g_defaultUlpTolerance = 4; } /*! \brief @@ -499,7 +499,7 @@ static uint64_t g_defaultUlpTolerance = 4; */ static inline FloatingPointTolerance defaultRealTolerance() { - return relativeToleranceAsUlp(1.0, g_defaultUlpTolerance); + return relativeToleranceAsUlp(1.0, detail::g_defaultUlpTolerance); } @@ -515,7 +515,7 @@ static inline FloatingPointTolerance defaultRealTolerance() static inline FloatingPointTolerance defaultFloatTolerance() { return relativeToleranceAsPrecisionDependentUlp - (1.0, g_defaultUlpTolerance, g_defaultUlpTolerance * (GMX_FLOAT_EPS / GMX_DOUBLE_EPS)); + (1.0, detail::g_defaultUlpTolerance, detail::g_defaultUlpTolerance * (GMX_FLOAT_EPS / GMX_DOUBLE_EPS)); } /*! \name Assertions for floating-point comparison diff --git a/src/testutils/testinit.cpp b/src/testutils/testinit.cpp index e7a2e90ba2..882931b128 100644 --- a/src/testutils/testinit.cpp +++ b/src/testutils/testinit.cpp @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2012,2013,2014,2015,2016,2017, by the GROMACS development team, led by + * Copyright (c) 2012,2013,2014,2015,2016,2017,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -56,6 +56,7 @@ #include "gromacs/commandline/cmdlineinit.h" #include "gromacs/commandline/cmdlineparser.h" #include "gromacs/commandline/cmdlineprogramcontext.h" +#include "gromacs/compat/make_unique.h" #include "gromacs/math/utilities.h" #include "gromacs/options/basicoptions.h" #include "gromacs/options/options.h" @@ -185,7 +186,7 @@ void initTestUtils(const char *dataPath, const char *tempPath, bool usesMpi, { callAddGlobalTestEnvironment(); } - g_testContext.reset(new TestProgramContext(context)); + g_testContext = gmx::compat::make_unique(context); setProgramContext(g_testContext.get()); // Use the default finder that does not respect GMXLIB, since the tests // generally can only get confused by a different set of data files. diff --git a/src/testutils/testoptions.h b/src/testutils/testoptions.h index 62dd76926f..553baffe92 100644 --- a/src/testutils/testoptions.h +++ b/src/testutils/testoptions.h @@ -1,7 +1,7 @@ /* * This file is part of the GROMACS molecular simulation package. * - * Copyright (c) 2012,2013,2014,2015, by the GROMACS development team, led by + * Copyright (c) 2012,2013,2014,2015,2018, by the GROMACS development team, led by * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl, * and including many others, as listed in the AUTHORS file in the * top-level source directory and at http://www.gromacs.org. @@ -163,21 +163,21 @@ void initTestOptions(IOptionsContainer *options); */ /* *INDENT-ON* */ #define GMX_TEST_OPTIONS(name, options) \ - class name : public ::gmx::test::TestOptionsProvider \ + class name : public ::gmx::test::TestOptionsProvider /*NOLINT(misc-macro-parentheses)*/ \ { \ public: \ name() \ { \ ::gmx::test::registerTestOptions(#name, this); \ } \ - virtual void initOptions(::gmx::IOptionsContainer *options); \ + virtual void initOptions(::gmx::IOptionsContainer *(options)); \ }; \ \ static name s_ ## name ## Instance; \ \ - void name::initOptions(::gmx::IOptionsContainer *options) + void name::initOptions(::gmx::IOptionsContainer *options) //NOLINT(misc-macro-parentheses) -} // namespace test -} // namespace gmx +} // namespace test +} // namespace gmx #endif -- 2.22.0