Merge branch 'master' into reset-invalid-image-flags
This commit is contained in:
@ -7,6 +7,7 @@ add_subdirectory(c-library)
|
||||
add_subdirectory(cplusplus)
|
||||
add_subdirectory(fortran)
|
||||
add_subdirectory(python)
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(force-styles)
|
||||
|
||||
find_package(ClangFormat 8.0)
|
||||
|
||||
20
unittest/README.md
Normal file
20
unittest/README.md
Normal file
@ -0,0 +1,20 @@
|
||||
Unit test collection
|
||||
====================
|
||||
|
||||
This part of the LAMMPS distribution contains scripts and inputs to run
|
||||
unit tests for different parts of the package. The tests are organized
|
||||
into folders based on which part of the distribution they are testing.
|
||||
|
||||
|
||||
* c-library: tests of the C-library interface
|
||||
* commands: tests for simple LAMMPS input commands
|
||||
* cplusplus: tests for using the LAMMPS library from C++
|
||||
* force-styles: tests for styles that compute or modify forces
|
||||
i.e pair, bond, angle, kspace styles and some fixes.
|
||||
* formats: tests related to file formats: atom styles, dump styles
|
||||
tokenizers potential file readers, dump styles
|
||||
* fortran: tests for the LAMMPS Fortran 03 module
|
||||
* python: tests for the LAMMPS Python module and python command
|
||||
* testing: convenience and support functions for test tools
|
||||
* tools: tests for tools form the tools folder
|
||||
* utils: tests for utility functions, e.g. from the utils namespace
|
||||
@ -105,7 +105,7 @@ TEST_F(LibraryConfig, style_count)
|
||||
EXPECT_GT(lammps_style_count(lmp, "dihedral"), 1);
|
||||
EXPECT_GT(lammps_style_count(lmp, "improper"), 1);
|
||||
EXPECT_GT(lammps_style_count(lmp, "pair"), 1);
|
||||
EXPECT_GT(lammps_style_count(lmp, "kspace"), 1);
|
||||
EXPECT_GE(lammps_style_count(lmp, "kspace"), 0);
|
||||
EXPECT_GT(lammps_style_count(lmp, "compute"), 1);
|
||||
EXPECT_GT(lammps_style_count(lmp, "fix"), 1);
|
||||
EXPECT_GT(lammps_style_count(lmp, "region"), 1);
|
||||
|
||||
@ -198,6 +198,13 @@ TEST_F(LibraryProperties, setting)
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lammps_command(lmp, "dimension 3");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "ntypes"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "nbondtypes"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "nangletypes"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "ndihedraltypes"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "nimpropertypes"), 0);
|
||||
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "molecule_flag"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "q_flag"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "mu_flag"), 0);
|
||||
@ -217,10 +224,22 @@ TEST_F(LibraryProperties, setting)
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "nghost"), 518);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "nall"), 547);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "nmax"), 16384);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "ntypes"), 5);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "nbondtypes"), 5);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "nangletypes"), 4);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "ndihedraltypes"), 5);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "nimpropertypes"), 2);
|
||||
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "molecule_flag"), 1);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "q_flag"), 1);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "mu_flag"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "rmass_flag"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "radius_flag"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "sphere_flag"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "ellipsoid_flag"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "omega_flag"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "torque_flag"), 0);
|
||||
EXPECT_EQ(lammps_extract_setting(lmp, "angmom_flag"), 0);
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lammps_command(lmp, "change_box all triclinic");
|
||||
lammps_command(lmp, "fix rmass all property/atom rmass ghost yes");
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
@ -12,6 +12,7 @@
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "test_main.h"
|
||||
#include "pointers.h"
|
||||
#include "utils.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -26,7 +26,7 @@ TEST(ErrorStats, test)
|
||||
|
||||
std::stringstream out;
|
||||
out << stats;
|
||||
ASSERT_EQ(out.str(), "Average: 5.800e-01 StdDev: 7.305e-01 MaxErr: 2.000e+00 @ item: 3.0");
|
||||
ASSERT_EQ(out.str(), "Average: 5.800e-01 StdDev: 7.305e-01 MaxErr: 2.000e+00 @ item: 3");
|
||||
|
||||
stats.reset();
|
||||
ASSERT_EQ(stats.has_data(), false);
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
@ -14,6 +14,7 @@
|
||||
#include "test_main.h"
|
||||
#include "test_config.h"
|
||||
#include "test_config_reader.h"
|
||||
#include "pointers.h"
|
||||
#include "utils.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,3 +1,15 @@
|
||||
# Test calling Python from LAMMPS (and importing the LAMMPS module
|
||||
# inside those functions). This can do an "anonymous" import of symbols
|
||||
# from the executable, so the shared library is not needed. The
|
||||
# availability of the PYTHON package is tested for inside the tester.
|
||||
|
||||
set(TEST_INPUT_FOLDER ${CMAKE_CURRENT_SOURCE_DIR})
|
||||
add_executable(test_python_package test_python_package.cpp)
|
||||
target_link_libraries(test_python_package PRIVATE lammps GTest::GMock GTest::GTest)
|
||||
target_compile_definitions(test_python_package PRIVATE -DTEST_INPUT_FOLDER=${TEST_INPUT_FOLDER})
|
||||
add_test(NAME PythonPackage COMMAND test_python_package WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
|
||||
set_tests_properties(PythonPackage PROPERTIES ENVIRONMENT "LAMMPS_POTENTIALS=${LAMMPS_POTENTIALS_DIR};PYTHONPATH=${CMAKE_CURRENT_BINARY_DIR}:${LAMMPS_PYTHON_DIR}:$ENV{PYTHONPATH}")
|
||||
|
||||
# we must have shared libraries enabled for testing the python module
|
||||
if(NOT BUILD_SHARED_LIBS)
|
||||
message(STATUS "Skipping Tests for the LAMMPS Python Module: must enable BUILD_SHARED_LIBS")
|
||||
|
||||
18
unittest/python/func.py
Normal file
18
unittest/python/func.py
Normal file
@ -0,0 +1,18 @@
|
||||
|
||||
from __future__ import print_function
|
||||
|
||||
def square(val):
|
||||
return val*val
|
||||
|
||||
def printnum():
|
||||
print("2.25")
|
||||
|
||||
def printtxt():
|
||||
print("sometext")
|
||||
|
||||
def getidxvar(lmpptr):
|
||||
from lammps import lammps, LMP_VAR_EQUAL
|
||||
lmp = lammps(ptr=lmpptr)
|
||||
|
||||
val = lmp.extract_variable("idx",None,LMP_VAR_EQUAL)
|
||||
print(val)
|
||||
146
unittest/python/test_python_package.cpp
Normal file
146
unittest/python/test_python_package.cpp
Normal file
@ -0,0 +1,146 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
DE-AC04-94AL85000 with Sandia Corporation, the U.S. Government retains
|
||||
certain rights in this software. This software is distributed under
|
||||
the GNU General Public License.
|
||||
|
||||
See the README file in the top-level LAMMPS directory.
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "atom.h"
|
||||
#include "info.h"
|
||||
#include "input.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
// location of '*.py' files required by tests
|
||||
#define STRINGIFY(val) XSTR(val)
|
||||
#define XSTR(val) #val
|
||||
std::string INPUT_FOLDER = STRINGIFY(TEST_INPUT_FOLDER);
|
||||
|
||||
// whether to print verbose output (i.e. not capturing LAMMPS screen output).
|
||||
bool verbose = false;
|
||||
|
||||
using LAMMPS_NS::utils::split_words;
|
||||
|
||||
namespace LAMMPS_NS {
|
||||
using ::testing::StrEq;
|
||||
using ::testing::MatchesRegex;
|
||||
|
||||
class PythonPackageTest : public ::testing::Test {
|
||||
protected:
|
||||
LAMMPS *lmp;
|
||||
Info *info;
|
||||
|
||||
void SetUp() override
|
||||
{
|
||||
const char *args[] = {"PythonPackageTest", "-log", "none", "-echo", "screen", "-nocite"};
|
||||
char **argv = (char **)args;
|
||||
int argc = sizeof(args) / sizeof(char *);
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp = new LAMMPS(argc, argv, MPI_COMM_WORLD);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
ASSERT_NE(lmp, nullptr);
|
||||
info = new Info(lmp);
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp->input->one("units real");
|
||||
lmp->input->one("dimension 3");
|
||||
lmp->input->one("region box block -4 4 -4 4 -4 4");
|
||||
lmp->input->one("create_box 1 box");
|
||||
lmp->input->one("create_atoms 1 single 0.0 0.0 0.0 units box");
|
||||
lmp->input->one("create_atoms 1 single 1.9 -1.9 1.9999 units box");
|
||||
lmp->input->one("pair_style zero 2.0");
|
||||
lmp->input->one("pair_coeff * *");
|
||||
lmp->input->one("mass * 1.0");
|
||||
lmp->input->one("variable input_dir index " + INPUT_FOLDER);
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
|
||||
void TearDown() override
|
||||
{
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
delete lmp;
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
}
|
||||
};
|
||||
|
||||
TEST_F(PythonPackageTest, python_invoke)
|
||||
{
|
||||
if (!info->has_style("command","python")) GTEST_SKIP();
|
||||
// execute python function from file
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp->input->one("python printnum file ${input_dir}/func.py");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp->input->one("python printnum invoke");
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
if (verbose) std::cout << output;
|
||||
ASSERT_THAT(output, MatchesRegex("python.*2.25.*"));
|
||||
|
||||
// execute another python function from same file
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp->input->one("python printtxt exists");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp->input->one("python printtxt invoke");
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
if (verbose) std::cout << output;
|
||||
ASSERT_THAT(output, MatchesRegex("python.*sometext.*"));
|
||||
|
||||
// execute python function that uses the LAMMPS python module
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp->input->one("variable idx equal 2.25");
|
||||
lmp->input->one("python getidxvar input 1 SELF format p exists");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp->input->one("python getidxvar invoke");
|
||||
output = ::testing::internal::GetCapturedStdout();
|
||||
if (verbose) std::cout << output;
|
||||
ASSERT_THAT(output, MatchesRegex("python.*2.25.*"));
|
||||
}
|
||||
|
||||
TEST_F(PythonPackageTest, python_variable)
|
||||
{
|
||||
if (!info->has_style("command","python")) GTEST_SKIP();
|
||||
if (!verbose) ::testing::internal::CaptureStdout();
|
||||
lmp->input->one("variable sq python square");
|
||||
lmp->input->one("variable val index 1.5");
|
||||
lmp->input->one("python square input 1 v_val return v_sq format ff file ${input_dir}/func.py");
|
||||
if (!verbose) ::testing::internal::GetCapturedStdout();
|
||||
::testing::internal::CaptureStdout();
|
||||
lmp->input->one("print \"${sq}\"");
|
||||
std::string output = ::testing::internal::GetCapturedStdout();
|
||||
if (verbose) std::cout << output;
|
||||
ASSERT_THAT(output, MatchesRegex("print.*2.25.*"));
|
||||
}
|
||||
|
||||
} // namespace LAMMPS_NS
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
MPI_Init(&argc, &argv);
|
||||
::testing::InitGoogleMock(&argc, argv);
|
||||
|
||||
// handle arguments passed via environment variable
|
||||
if (const char *var = getenv("TEST_ARGS")) {
|
||||
std::vector<std::string> env = split_words(var);
|
||||
for (auto arg : env) {
|
||||
if (arg == "-v") {
|
||||
verbose = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if ((argc > 1) && (strcmp(argv[1], "-v") == 0)) verbose = true;
|
||||
|
||||
int rv = RUN_ALL_TESTS();
|
||||
MPI_Finalize();
|
||||
return rv;
|
||||
}
|
||||
20
unittest/tools/CMakeLists.txt
Normal file
20
unittest/tools/CMakeLists.txt
Normal file
@ -0,0 +1,20 @@
|
||||
|
||||
# we use python 3's subprocess module to run the tools and check the output
|
||||
if(CMAKE_VERSION VERSION_LESS 3.12)
|
||||
find_package(PythonInterp 3.5) # Deprecated since version 3.12
|
||||
if(PYTHONINTERP_FOUND)
|
||||
set(Python_EXECUTABLE ${PYTHON_EXECUTABLE})
|
||||
endif()
|
||||
else()
|
||||
find_package(Python3 COMPONENTS Interpreter)
|
||||
endif()
|
||||
|
||||
if(Python_EXECUTABLE)
|
||||
if(BUILD_LAMMPS_SHELL)
|
||||
add_test(NAME LammpsShell
|
||||
COMMAND ${Python_EXECUTABLE} -u ${CMAKE_CURRENT_SOURCE_DIR}/test_lammps_shell.py -v
|
||||
WORKING_DIRECTORY ${CMAKE_BINARY_DIR})
|
||||
endif()
|
||||
else()
|
||||
message(STATUS "Skipping Tests for LAMMPS tools: no suitable Python interpreter")
|
||||
endif()
|
||||
151
unittest/tools/test_lammps_shell.py
Normal file
151
unittest/tools/test_lammps_shell.py
Normal file
@ -0,0 +1,151 @@
|
||||
|
||||
import os, re, subprocess, unittest
|
||||
|
||||
# enable test mode
|
||||
os.putenv('LAMMPS_SHELL_TESTING','1')
|
||||
|
||||
shell_prompt_re = r"([^>]*LAMMPS Shell> ([a-z0-9_]+) *([a-z0-9_\.]+)?.*\n)+"
|
||||
cmd_group_re = r"([^>]*LAMMPS Shell> ([a-z0-9_]+) +([a-z0-9]+) +([a-z0-9]+)? *([a-z/0-9]+)?.*\n)+"
|
||||
|
||||
#
|
||||
class LammpsShell(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
self.proc = subprocess.Popen('./lammps-shell',
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
|
||||
|
||||
def tearDown(self):
|
||||
self.proc.kill()
|
||||
|
||||
|
||||
def InputRunner(self,text):
|
||||
"""Test tab expansions"""
|
||||
try:
|
||||
[outs,errs] = self.proc.communicate(input=text, timeout=10)
|
||||
self.timeout = 0
|
||||
except subprocess.TimeoutExpired:
|
||||
self.proc.kill()
|
||||
[outs,errs] = self.proc.communicate()
|
||||
self.timeout = 1
|
||||
|
||||
return outs.decode('UTF-8')
|
||||
|
||||
def testExpandClearHistory(self):
|
||||
"""Test expansion of a shell specific command"""
|
||||
matches = re.findall(shell_prompt_re, self.InputRunner(b'clear_his\t\n'), re.MULTILINE)
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"clear_history")
|
||||
|
||||
def testExpandDimension(self):
|
||||
"""Test expansion of a LAMMPS command"""
|
||||
matches = re.findall(shell_prompt_re, self.InputRunner(b'dimens\t\n'), re.MULTILINE)
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"dimension")
|
||||
|
||||
def testExpandPairStyle(self):
|
||||
"""Test expansion of a pair style"""
|
||||
matches = re.findall(shell_prompt_re, self.InputRunner(b'pair_st\t zer\t\n'), re.MULTILINE)
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"pair_style")
|
||||
self.assertEqual(matches[0][2],"zero")
|
||||
|
||||
def testExpandBondStyle(self):
|
||||
"""Test expansion of a bond style"""
|
||||
matches = re.findall(shell_prompt_re, self.InputRunner(b'bond_st\t zer\t\n'), re.MULTILINE)
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"bond_style")
|
||||
self.assertEqual(matches[0][2],"zero")
|
||||
|
||||
def testExpandAngleStyle(self):
|
||||
"""Test expansion of a angle style"""
|
||||
matches = re.findall(shell_prompt_re, self.InputRunner(b'angle_st\t zer\t\n'), re.MULTILINE)
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"angle_style")
|
||||
self.assertEqual(matches[0][2],"zero")
|
||||
|
||||
def testExpandDihedralStyle(self):
|
||||
"""Test expansion of a dihedral style"""
|
||||
matches = re.findall(shell_prompt_re, self.InputRunner(b'dihedral_st\t zer\t\n'), re.MULTILINE)
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"dihedral_style")
|
||||
self.assertEqual(matches[0][2],"zero")
|
||||
|
||||
def testExpandImproperStyle(self):
|
||||
"""Test expansion of a improper style"""
|
||||
matches = re.findall(shell_prompt_re, self.InputRunner(b'improper_st\t zer\t\n'), re.MULTILINE)
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"improper_style")
|
||||
self.assertEqual(matches[0][2],"zero")
|
||||
|
||||
def testExpandComputeGroup(self):
|
||||
"""Test expansion of a group-ID and a compute command"""
|
||||
matches = re.findall(cmd_group_re, self.InputRunner(b'compute test al\tcentro/at\t\n'), re.MULTILINE)
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"compute")
|
||||
self.assertEqual(matches[0][2],"test")
|
||||
self.assertEqual(matches[0][3],"all")
|
||||
self.assertEqual(matches[0][4],"centro/atom")
|
||||
|
||||
def testExpandFixGroup(self):
|
||||
"""Test expansion of a group-ID and a fix command"""
|
||||
matches = re.findall(cmd_group_re, self.InputRunner(b'fix test al\tcontroll\t\n'), re.MULTILINE)
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"fix")
|
||||
self.assertEqual(matches[0][2],"test")
|
||||
self.assertEqual(matches[0][3],"all")
|
||||
self.assertEqual(matches[0][4],"controller")
|
||||
|
||||
def testExpandSource(self):
|
||||
"""Test expansion of a shell command and a file name"""
|
||||
with open('.tmp.in.source', 'w') as out:
|
||||
print('units real', file=out)
|
||||
out.close()
|
||||
matches = re.findall(shell_prompt_re, self.InputRunner(b'sour\t.tmp.in.sou\t\n'), re.MULTILINE)
|
||||
os.remove('.tmp.in.source')
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
self.assertEqual(matches[0][1],"source")
|
||||
self.assertEqual(matches[0][2],".tmp.in.source")
|
||||
|
||||
def testHistory(self):
|
||||
"""Test history expansion"""
|
||||
out = self.InputRunner(b'clear_history\nunits real\ndimension 2\n!!:p\n!-3:p\n!dim:p\n!uni:p\nprint !!:$\nprint !dim:1\n')
|
||||
idx = 0
|
||||
if self.timeout:
|
||||
self.fail("Timeout")
|
||||
else:
|
||||
lines = out.splitlines()
|
||||
for line in lines:
|
||||
if line.startswith('LAMMPS Shell>'): break
|
||||
idx += 1
|
||||
|
||||
self.assertEqual(lines[idx+4],"dimension 2")
|
||||
self.assertEqual(lines[idx+6],"units real")
|
||||
self.assertEqual(lines[idx+8],"dimension 2")
|
||||
self.assertEqual(lines[idx+10],"units real")
|
||||
self.assertEqual(lines[idx+12],"real")
|
||||
self.assertEqual(lines[idx+14],"2")
|
||||
|
||||
###########################
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
/* ----------------------------------------------------------------------
|
||||
LAMMPS - Large-scale Atomic/Molecular Massively Parallel Simulator
|
||||
http://lammps.sandia.gov, Sandia National Laboratories
|
||||
https://lammps.sandia.gov/, Sandia National Laboratories
|
||||
Steve Plimpton, sjplimp@sandia.gov
|
||||
|
||||
Copyright (2003) Sandia Corporation. Under the terms of Contract
|
||||
@ -12,6 +12,7 @@
|
||||
------------------------------------------------------------------------- */
|
||||
|
||||
#include "lmptype.h"
|
||||
#include "pointers.h"
|
||||
#include "utils.h"
|
||||
#include "gmock/gmock.h"
|
||||
#include "gtest/gtest.h"
|
||||
@ -524,11 +525,26 @@ TEST(Utils, path_basename)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
ASSERT_THAT(utils::path_basename("c:\\parent\\folder\\filename"), Eq("filename"));
|
||||
ASSERT_THAT(utils::path_basename("folder\\"), Eq(""));
|
||||
ASSERT_THAT(utils::path_basename("c:/parent/folder/filename"), Eq("filename"));
|
||||
#else
|
||||
ASSERT_THAT(utils::path_basename("/parent/folder/filename"), Eq("filename"));
|
||||
ASSERT_THAT(utils::path_basename("/parent/folder/"), Eq(""));
|
||||
#endif
|
||||
}
|
||||
|
||||
TEST(Utils, path_dirname)
|
||||
{
|
||||
#if defined(_WIN32)
|
||||
ASSERT_THAT(utils::path_dirname("c:/parent/folder/filename"), Eq("c:/parent/folder"));
|
||||
ASSERT_THAT(utils::path_dirname("c:\\parent\\folder\\filename"), Eq("c:\\parent\\folder"));
|
||||
ASSERT_THAT(utils::path_dirname("c:filename"), Eq("."));
|
||||
#else
|
||||
ASSERT_THAT(utils::path_dirname("/parent/folder/filename"), Eq("/parent/folder"));
|
||||
#endif
|
||||
ASSERT_THAT(utils::path_dirname("filename"), Eq("."));
|
||||
}
|
||||
|
||||
TEST(Utils, getsyserror)
|
||||
{
|
||||
#if defined(__linux__)
|
||||
|
||||
Reference in New Issue
Block a user