From 6a7f0d44f07945630217aa261c168ba3c599beaf Mon Sep 17 00:00:00 2001 From: Daniel Donenfeld Date: Wed, 6 Feb 2019 17:40:57 -0800 Subject: [PATCH] Change asm generation to be on by default. Augment add_gsl_test to generate ASM when requested. --- tests/CMakeLists.txt | 79 ++++++++++++++++++++++++------------- tests/span_compile_only.cpp | 65 ++++++++++++++++++++++++++++++ 2 files changed, 117 insertions(+), 27 deletions(-) create mode 100644 tests/span_compile_only.cpp diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 6b28415..69efd7d 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -69,6 +69,15 @@ target_compile_definitions(gsl_tests_config INTERFACE GSL_THROW_ON_CONTRACT_VIOLATION ) +# Set the location asm files are output into +if(DEFINED GSL_ASM_FOLDER) + set(ASM_LOCATION ${CMAKE_SOURCE_DIR}\\asm\\${GSL_ASM_FOLDER}) +else() + set(ASM_LOCATION ${CMAKE_SOURCE_DIR}\\asm\\${CMAKE_GENERATOR}) +endif() + +file(MAKE_DIRECTORY ${ASM_LOCATION}) + # create the main executable for each test. this reduces the compile time # of each test by pre-compiling catch. add_library(test_catch STATIC test.cpp) @@ -79,13 +88,33 @@ target_link_libraries(test_catch add_dependencies(test_catch catch) set_property(TARGET test_catch PROPERTY FOLDER "GSL_tests") -function(add_gsl_test name) +function(add_gsl_test name gen_asm) add_executable(${name} ${name}.cpp) + + #Set the asm options if used + if(${gen_asm}) + add_library(${name}_asm INTERFACE) + target_compile_options(${name}_asm INTERFACE + $<$: + $<$: + /FA + /Fa${ASM_LOCATION}\\${name}.asm + > + $<$>: + -S + -o ${ASM_LOCATION}\\${name}.s + > + > + ) + endif() + target_link_libraries(${name} GSL test_catch gsl_tests_config + $<$:${name}_asm> ) + add_dependencies(${name} catch) add_test( ${name} @@ -95,19 +124,19 @@ function(add_gsl_test name) set_property(TARGET ${name} PROPERTY FOLDER "GSL_tests") endfunction() -add_gsl_test(span_tests) -add_gsl_test(multi_span_tests) -add_gsl_test(strided_span_tests) -add_gsl_test(string_span_tests) -add_gsl_test(at_tests) -add_gsl_test(bounds_tests) -add_gsl_test(notnull_tests) -add_gsl_test(assertion_tests) -add_gsl_test(utils_tests) -add_gsl_test(owner_tests) -add_gsl_test(byte_tests) -add_gsl_test(algorithm_tests) -add_gsl_test(sloppy_notnull_tests) +add_gsl_test(span_tests TRUE) +add_gsl_test(multi_span_tests FALSE) +add_gsl_test(strided_span_tests FALSE) +add_gsl_test(string_span_tests FALSE) +add_gsl_test(at_tests FALSE) +add_gsl_test(bounds_tests FALSE) +add_gsl_test(notnull_tests FALSE) +add_gsl_test(assertion_tests FALSE) +add_gsl_test(utils_tests FALSE) +add_gsl_test(owner_tests FALSE) +add_gsl_test(byte_tests FALSE) +add_gsl_test(algorithm_tests FALSE) +add_gsl_test(sloppy_notnull_tests FALSE) # No exception tests @@ -172,23 +201,18 @@ endfunction() add_gsl_test_noexcept(no_exception_throw_tests) add_gsl_test_noexcept(no_exception_ensure_tests) -set(ASM_LOCATION ${CMAKE_SOURCE_DIR}\\asm\\${CMAKE_GENERATOR}) -file(MAKE_DIRECTORY ${ASM_LOCATION}) - -add_custom_target(asm_tests) - function(add_gsl_asm_test name) add_library(${name}_asm ${name}.cpp) - target_compile_options(${name}_asm PRIVATE + add_library(${name}_asm_options INTERFACE) + target_compile_options(${name}_asm_options INTERFACE $<$: /FA - /Fa${ASM_LOCATION}\\${name}_asm.asm + /Fa${ASM_LOCATION}\\${name}.asm > - ${GSL_CPLUSPLUS_OPT} $<$>: -S - -o ${ASM_LOCATION}\${name}.s + -o ${ASM_LOCATION}\\${name}.s > ) @@ -196,11 +220,12 @@ function(add_gsl_asm_test name) GSL test_catch gsl_tests_config + ${name}_asm_options ) + add_dependencies(${name}_asm catch) - add_dependencies(asm_tests ${name}_asm) - # group all tests under GSL_tests - set_property(TARGET ${name}_asm PROPERTY FOLDER "GSL_tests") + # group all tests under GSL_asm_tests + set_property(TARGET ${name}_asm PROPERTY FOLDER "GSL_asm_tests") endfunction() -add_gsl_asm_test(span_tests) \ No newline at end of file +add_gsl_asm_test(span_compile_only) \ No newline at end of file diff --git a/tests/span_compile_only.cpp b/tests/span_compile_only.cpp new file mode 100644 index 0000000..9eb27b0 --- /dev/null +++ b/tests/span_compile_only.cpp @@ -0,0 +1,65 @@ +/////////////////////////////////////////////////////////////////////////////// +// +// Copyright (c) 2015 Microsoft Corporation. All rights reserved. +// +// This code is licensed under the MIT License (MIT). +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +// +/////////////////////////////////////////////////////////////////////////////// + + +#include // for AssertionHandler, StringRef, CHECK, TEST_... + +#include // for byte +#include // for narrow_cast, at +#include // for span, span_iterator, operator==, operator!= + +#include // for array +#include // for ptrdiff_t +#include // for reverse_iterator, operator-, operator== +#include // for unique_ptr, shared_ptr, make_unique, allo... +#include // for match_results, sub_match, match_results<>... +#include // for ptrdiff_t +#include // for string +#include // for integral_constant<>::value, is_default_co... +#include // for vector + +namespace gsl { +struct fail_fast; +} // namespace gsl + +using namespace std; +using namespace gsl; + +namespace +{ +struct BaseClass +{ +}; +struct DerivedClass : BaseClass +{ +}; +struct AddressOverloaded +{ + AddressOverloaded operator&() const { return {}; } +}; +} + +GSL_SUPPRESS(con.4) // NO-FORMAT: attribute +TEST_CASE("default_constructor") +{ + { + span s; + CHECK((s.size() == 0 && s.data() == nullptr)); + + span cs; + CHECK((cs.size() == 0 && cs.data() == nullptr)); + } +}