Skip to content

Commit

Permalink
Merge pull request LLNL#290 from LLNL/feature/weiss27/format-tests
Browse files Browse the repository at this point in the history
Formats blt's internal and smoke tests with astyle
  • Loading branch information
kennyweiss authored Jul 17, 2019
2 parents e18a889 + b4610d5 commit 9383457
Show file tree
Hide file tree
Showing 51 changed files with 973 additions and 836 deletions.
1 change: 1 addition & 0 deletions cmake/SetupCodeChecks.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ macro(blt_add_astyle_target)
execute_process(
COMMAND ${ASTYLE_EXECUTABLE} --version
OUTPUT_VARIABLE _version_str
ERROR_VARIABLE _version_str
OUTPUT_STRIP_TRAILING_WHITESPACE )
string(REGEX MATCH "([0-9]+(\\.)?)+$" _astyle_version ${_version_str})

Expand Down
118 changes: 96 additions & 22 deletions tests/internal/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,35 @@
#
# SPDX-License-Identifier: (BSD-3-Clause)

################################
#------------------------------------------------------------------------------
# BLT Internal Testing Project
################################
#------------------------------------------------------------------------------

cmake_minimum_required(VERSION 3.8)

project(blt-example LANGUAGES C CXX)

###############################################################################
#------------------------------------------------------------------------------
# Setup BLT
###############################################################################
#------------------------------------------------------------------------------
# Set BLT_SOURCE_DIR to default location, if not set by user
if(NOT BLT_SOURCE_DIR)
set(BLT_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../..")
endif()

include(${BLT_SOURCE_DIR}/SetupBLT.cmake)

################################
#------------------------------------------------------------------------------
# Project options
################################
#------------------------------------------------------------------------------
option(TEST_GIT_MACROS
"Toggle smoke tests for git macros. Off by default since it requires a modified git repo."
OFF)


################################
#------------------------------------------------------------------------------
# Add a library
################################
#------------------------------------------------------------------------------

blt_add_library( NAME example
SOURCES "src/Example.cpp"
Expand All @@ -43,25 +43,25 @@ if(WIN32 AND BUILD_SHARED_LIBS)
endif()

if(ENABLE_GTEST)
################################
#------------------------------------------------------
# Add an executable
# (which happens to be a test)
################################
#------------------------------------------------------
blt_add_executable(
NAME t_example_smoke
SOURCES "src/t_example_smoke.cpp"
DEPENDS_ON example gtest)

################################
#------------------------------------------------------
# Register our test w/ ctest
################################
#------------------------------------------------------
blt_add_test(NAME t_example_smoke
COMMAND t_example_smoke)


####################
#------------------------------------------------------
# Header-only test
####################
#------------------------------------------------------

blt_add_library(NAME blt_header_only
HEADERS "src/HeaderOnly.hpp")
Expand All @@ -76,10 +76,10 @@ if(ENABLE_GTEST)
blt_add_test(NAME t_header_only_smoke
COMMAND t_header_only_smoke)

####################################################
#------------------------------------------------------
# Tests blt_combine_static_libs macro
# Note: Does not currently work on Windows or BGQ
####################################################
#------------------------------------------------------
set(_try_combine_static_libs ON)

if(CMAKE_HOST_WIN32)
Expand All @@ -94,9 +94,9 @@ if(ENABLE_GTEST)
add_subdirectory( src/combine_static_library_test )
endif ()

####################
#------------------------------------------------------
# Git Macros test
####################
#------------------------------------------------------
if ( GIT_FOUND AND TEST_GIT_MACROS)

blt_is_git_repo( OUTPUT_STATE is_git_repo
Expand Down Expand Up @@ -152,17 +152,17 @@ if(ENABLE_GTEST)

endif() # endif Git_FOUND

################
#------------------------------------------------------
# CUDA tests
#################
#------------------------------------------------------
if (ENABLE_CUDA)
add_subdirectory(src/test_cuda_device_call_from_kernel)
endif()

########################################################
#------------------------------------------------------
# Tests blt_add_target_definitions macro
# Four variants of a test with a list of two definitions
########################################################
#------------------------------------------------------
set(_variant_1 A=1 B) # neither use '-D'
set(_variant_2 -DA=1 -DB) # both uses '-D'
set(_variant_3 "A=1;-DB") # list passed in as string
Expand Down Expand Up @@ -198,3 +198,77 @@ add_subdirectory(src/object_library_test)
if(ENABLE_CLANGQUERY)
add_subdirectory(src/static_analysis)
endif()

#------------------------------------------------------------------------------
# Format the testing code using AStyle
#------------------------------------------------------------------------------
if(ASTYLE_FOUND)

set(smoke_tests_srcs
../smoke/blt_cuda_mpi_smoke.cpp
../smoke/blt_cuda_openmp_smoke.cpp
../smoke/blt_cuda_runtime_smoke.cpp
../smoke/blt_cuda_smoke.cpp
../smoke/blt_fruit_smoke.f90
../smoke/blt_gbenchmark_smoke.cpp
../smoke/blt_gmock_smoke.cpp
../smoke/blt_gtest_smoke.cpp
../smoke/blt_hcc_runtime_smoke.cpp
../smoke/blt_hcc_smoke.cpp
../smoke/blt_hip_runtime_smoke.cpp
../smoke/blt_hip_smoke.cpp
../smoke/blt_mpi_smoke.cpp
../smoke/blt_openmp_smoke.cpp
../smoke/fortran_driver.cpp
)

set(internal_tests_srcs
src/Example.cpp
src/Example.hpp
src/Example_Exports.h
src/HeaderOnly.hpp

src/combine_static_library_test/Foo1.cpp
src/combine_static_library_test/Foo1.hpp
src/combine_static_library_test/Foo2.cpp
src/combine_static_library_test/Foo2.hpp
src/combine_static_library_test/Foo3.cpp
src/combine_static_library_test/Foo3.hpp
src/combine_static_library_test/blt_combine_static_libraries_shared_smoke.cpp
src/combine_static_library_test/blt_combine_static_libraries_static_smoke.cpp
src/combine_static_library_test/dummy.cpp
src/combine_static_library_test/main.cpp

src/object_library_test/base_object.cpp
src/object_library_test/base_object.hpp

src/object_library_test/inherited_base/inherited_base.cpp
src/object_library_test/inherited_base/inherited_base.hpp
src/object_library_test/main.cpp
src/object_library_test/object.cpp
src/object_library_test/object.hpp

src/static_analysis/well_analyzed_source.cpp
src/t_example_compile_definitions.cpp
src/t_example_smoke.cpp
src/t_header_only_smoke.cpp

src/test_cuda_device_call_from_kernel/Child.cpp
src/test_cuda_device_call_from_kernel/Child.hpp
src/test_cuda_device_call_from_kernel/CudaTests.cpp
src/test_cuda_device_call_from_kernel/Parent.cpp
src/test_cuda_device_call_from_kernel/Parent.hpp
)

blt_add_code_checks(
PREFIX smoke_tests
SOURCES ${smoke_tests_srcs}
ASTYLE_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/astyle.cfg )

blt_add_code_checks(
PREFIX internal_tests
SOURCES ${internal_tests_srcs}
ASTYLE_CFG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/astyle.cfg )


endif()
13 changes: 13 additions & 0 deletions tests/internal/astyle.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--style=allman
--indent=spaces=2
--max-code-length=80
--keep-one-line-statements
--keep-one-line-blocks
--indent-preproc-block
--indent-preproc-cond
--indent-preproc-define
--indent-col1-comments
--indent-labels
--add-brackets
--convert-tabs
--preserve-date
11 changes: 5 additions & 6 deletions tests/internal/src/Example.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,25 @@
// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and
// other BLT Project Developers. See the top-level COPYRIGHT file for details
//
//
// SPDX-License-Identifier: (BSD-3-Clause)

#include "Example.hpp"

//------------------------------------------------------------------------------
Example::Example()
{
// empty
// empty
}

//------------------------------------------------------------------------------
Example::~Example()
{
// empty
// empty
}

//------------------------------------------------------------------------------
bool
Example::ReturnTrue()
bool Example::ReturnTrue()
{
return true;
return true;
}

12 changes: 6 additions & 6 deletions tests/internal/src/Example.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and
// other BLT Project Developers. See the top-level COPYRIGHT file for details
//
//
// SPDX-License-Identifier: (BSD-3-Clause)

#ifndef _EXAMPLE_HPP_
Expand All @@ -11,10 +11,10 @@
//------------------------------------------------------------------------------
class EXAMPLE_API Example
{
public:
Example();
~Example();
bool ReturnTrue();
public:
Example();
~Example();

bool ReturnTrue();
};
#endif
44 changes: 22 additions & 22 deletions tests/internal/src/Example_Exports.h
Original file line number Diff line number Diff line change
@@ -1,38 +1,38 @@
// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and
// other BLT Project Developers. See the top-level COPYRIGHT file for details
//
//
// SPDX-License-Identifier: (BSD-3-Clause)

#ifndef _EXAMPLE_EXPORTS_H_
#define _EXAMPLE_EXPORTS_H_

//-----------------------------------------------------------------------------
// -- define proper lib exports for various platforms --
// -- define proper lib exports for various platforms --
//-----------------------------------------------------------------------------
#if defined(_WIN32)
#if defined(WIN32_SHARED_LIBS)
#if defined(EXAMPLE_EXPORTS) || defined(example_EXPORTS)
#define EXAMPLE_API __declspec(dllexport)
#else
#define EXAMPLE_API __declspec(dllimport)
#endif
#if defined(WIN32_SHARED_LIBS)
#if defined(EXAMPLE_EXPORTS) || defined(example_EXPORTS)
#define EXAMPLE_API __declspec(dllexport)
#else
#define EXAMPLE_API /* not needed for static on windows */
#endif
#if defined(_MSC_VER)
/* Turn off warning about lack of DLL interface */
#pragma warning(disable:4251)
/* Turn off warning non-dll class is base for dll-interface class. */
#pragma warning(disable:4275)
/* Turn off warning about identifier truncation */
#pragma warning(disable:4786)
#define EXAMPLE_API __declspec(dllimport)
#endif
#else
#define EXAMPLE_API /* not needed for static on windows */
#endif
#if defined(_MSC_VER)
/* Turn off warning about lack of DLL interface */
#pragma warning(disable:4251)
/* Turn off warning non-dll class is base for dll-interface class. */
#pragma warning(disable:4275)
/* Turn off warning about identifier truncation */
#pragma warning(disable:4786)
#endif
#else
# if __GNUC__ >= 4 && (defined(EXAMPLE_EXPORTS) || defined(example_EXPORTS))
# define EXAMPLE_API __attribute__ ((visibility("default")))
# else
# define EXAMPLE_API /* hidden by default */
# endif
#if __GNUC__ >= 4 && (defined(EXAMPLE_EXPORTS) || defined(example_EXPORTS))
#define EXAMPLE_API __attribute__ ((visibility("default")))
#else
#define EXAMPLE_API /* hidden by default */
#endif
#endif

#endif
10 changes: 6 additions & 4 deletions tests/internal/src/HeaderOnly.hpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and
// other BLT Project Developers. See the top-level COPYRIGHT file for details
//
//
// SPDX-License-Identifier: (BSD-3-Clause)

#ifndef BLT_HEADER_ONLY_HPP
#define BLT_HEADER_ONLY_HPP

namespace blt {
namespace blt
{

inline bool ReturnTrue() {
return true;
inline bool ReturnTrue()
{
return true;
}

} // end of namespace blt
Expand Down
2 changes: 1 addition & 1 deletion tests/internal/src/combine_static_library_test/Foo1.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and
// other BLT Project Developers. See the top-level COPYRIGHT file for details
//
//
// SPDX-License-Identifier: (BSD-3-Clause)

#include <iostream>
Expand Down
4 changes: 2 additions & 2 deletions tests/internal/src/combine_static_library_test/Foo1.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and
// other BLT Project Developers. See the top-level COPYRIGHT file for details
//
//
// SPDX-License-Identifier: (BSD-3-Clause)

#ifndef TESTS_INTERNAL_SRC_COMBINE_STATIC_LIBRARY_TEST_FOO1_HPP_
Expand All @@ -16,7 +16,7 @@ class Foo1
public:
Foo1();
~Foo1();

std::string output();
};

Expand Down
2 changes: 1 addition & 1 deletion tests/internal/src/combine_static_library_test/Foo2.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Copyright (c) 2017-2019, Lawrence Livermore National Security, LLC and
// other BLT Project Developers. See the top-level COPYRIGHT file for details
//
//
// SPDX-License-Identifier: (BSD-3-Clause)

#include "Foo2.hpp"
Expand Down
Loading

0 comments on commit 9383457

Please sign in to comment.