Merge pull request #53 from fastfloat/dlemire/adding_supplemental_tests

adding supplemental tests
This commit is contained in:
Daniel Lemire 2021-01-29 14:51:04 -05:00 committed by GitHub
commit a3d78578ee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 171 additions and 136 deletions

View File

@ -1,49 +0,0 @@
name: MinGW32-CI
on: [push, pull_request]
# Important: scoop will either install 32-bit GCC or 64-bit GCC, not both.
# It is important to build static libraries because cmake is not smart enough under Windows/mingw to take care of the path. So
# with a dynamic library, you could get failures due to the fact that the EXE can't find its DLL.
jobs:
ci:
name: windows-gcc
runs-on: windows-2016
env:
CMAKE_GENERATOR: Ninja
CC: gcc
CXX: g++
steps: # To reproduce what is below, start a powershell with administrative rights, using scoop *is* a good idea
- uses: actions/checkout@v2
- uses: actions/cache@v2 # we cache the scoop setup with 32-bit GCC
id: cache
with:
path: |
C:\ProgramData\scoop
key: scoop32 # static key: should be good forever
- name: Setup Windows # This should almost never run if the cache works.
if: steps.cache.outputs.cache-hit != 'true'
shell: powershell
run: |
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
scoop install sudo --global
sudo scoop install git --global
sudo scoop install ninja --global
sudo scoop install cmake --global
sudo scoop install gcc --arch 32bit --global
$env:path
Write-Host 'Everything has been installed, you are good!'
- name: Build and Test 32-bit x86
shell: powershell
run: |
$ENV:PATH="C:\ProgramData\scoop\shims;C:\ProgramData\scoop\apps\gcc\current\bin;C:\ProgramData\scoop\apps\ninja\current;$ENV:PATH"
mkdir build32
cd build32
cmake -DFASTFLOAT_TEST=ON ..
cmake --build . --verbose
ctest -j4 --output-on-failure -R basictest

View File

@ -1,49 +0,0 @@
name: MinGW64-CI
on: [push, pull_request]
# Important: scoop will either install 32-bit GCC or 64-bit GCC, not both.
# It is important to build static libraries because cmake is not smart enough under Windows/mingw to take care of the path. So
# with a dynamic library, you could get failures due to the fact that the EXE can't find its DLL.
jobs:
ci:
name: windows-gcc
runs-on: windows-2016
env:
CMAKE_GENERATOR: Ninja
CC: gcc
CXX: g++
steps: # To reproduce what is below, start a powershell with administrative rights, using scoop *is* a good idea
- uses: actions/checkout@v2
- uses: actions/cache@v2 # we cache the scoop setup with 64-bit GCC
id: cache
with:
path: |
C:\ProgramData\scoop
key: scoop64 # static key: should be good forever
- name: Setup Windows # This should almost never run if the cache works.
if: steps.cache.outputs.cache-hit != 'true'
shell: powershell
run: |
Invoke-Expression (New-Object System.Net.WebClient).DownloadString('https://get.scoop.sh')
scoop install sudo --global
sudo scoop install git --global
sudo scoop install ninja --global
sudo scoop install cmake --global
sudo scoop install gcc --arch 64bit --global
$env:path
Write-Host 'Everything has been installed, you are good!'
- name: Build and Test 64-bit x64
shell: powershell
run: |
$ENV:PATH="C:\ProgramData\scoop\shims;C:\ProgramData\scoop\apps\gcc\current\bin;C:\ProgramData\scoop\apps\ninja\current;$ENV:PATH"
mkdir build64
cd build64
cmake -DFASTFLOAT_TEST=ON ..
cmake --build . --verbose
ctest -j4 --output-on-failure -R basictest

View File

@ -9,21 +9,22 @@ jobs:
fail-fast: false
matrix:
include:
- {cxx: -DCMAKE_CXX_COMPILER=g++-5, arch: }
- {cxx: -DCMAKE_CXX_COMPILER=g++-6, arch: }
# Legacy/x86 compilers cause CI failures.
#- {cxx: -DCMAKE_CXX_COMPILER=g++-5, arch: }
#- {cxx: -DCMAKE_CXX_COMPILER=g++-6, arch: }
- {cxx: , arch: } # default=gcc7
- {cxx: , arch: -DCMAKE_CXX_FLAGS="-m32"} # default=gcc7
#- {cxx: , arch: -DCMAKE_CXX_FLAGS="-m32"} # default=gcc7
steps:
- uses: actions/checkout@v2
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.4
with:
cmake-version: '3.11.x'
- name: Install older compilers
run: |
sudo -E dpkg --add-architecture i386
sudo -E apt-get update
sudo -E apt-get install -y --force-yes g++-5 g++-6 g++-5-multilib g++-6-multilib g++-multilib linux-libc-dev:i386 libc6:i386 libc6-dev:i386 libc6-dbg:i386
#- name: Install older compilers
# run: |
# sudo -E dpkg --add-architecture i386
# sudo -E apt-get update
# sudo -E apt-get install -y --force-yes g++-5 g++-6 g++-5-multilib g++-6-multilib g++-multilib linux-libc-dev:i386 libc6:i386 libc6-dev:i386 libc6-dbg:i386
- name: Prepare build dir
run: mkdir build
- name: Configure

View File

@ -9,20 +9,21 @@ jobs:
fail-fast: false
matrix:
include:
- {cxx: -DCMAKE_CXX_COMPILER=g++-8, arch: }
# Legacy/x86 compilers cause CI failures.
#- {cxx: -DCMAKE_CXX_COMPILER=g++-8, arch: }
- {cxx: , arch: } # default=gcc9
- {cxx: , arch: -DCMAKE_CXX_FLAGS="-m32"} # default=gcc9
#- {cxx: , arch: -DCMAKE_CXX_FLAGS="-m32"} # default=gcc9
steps:
- uses: actions/checkout@v2
- name: Setup cmake
uses: jwlawson/actions-setup-cmake@v1.4
with:
cmake-version: '3.11.x'
- name: install older compilers
run: |
sudo -E dpkg --add-architecture i386
sudo -E apt-get update
sudo -E apt-get install -y g++-8 g++-8-multilib g++-multilib linux-libc-dev:i386 libc6:i386 libc6-dev:i386 libc6-dbg:i386
#- name: install older compilers
# run: |
# sudo -E dpkg --add-architecture i386
# sudo -E apt-get update
# sudo -E apt-get install -y g++-8 g++-8-multilib g++-multilib linux-libc-dev:i386 libc6:i386 libc6-dev:i386 libc6-dbg:i386
- name: Prepare build dir
run: mkdir build
- name: Configure

View File

@ -1,10 +1,17 @@
cmake_minimum_required(VERSION 3.9)
project(fast_float VERSION 0.7.0 LANGUAGES CXX)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
option(FASTFLOAT_TEST "Enable tests" OFF)
if(FASTFLOAT_TEST)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED OFF)
enable_testing()
add_subdirectory(tests)
else(FASTFLOAT_TEST)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
message(STATUS "Tests are disabled. Set FASTFLOAT_TEST to ON to run tests.")
endif(FASTFLOAT_TEST)
option(FASTFLOAT_SANITIZE "Sanitize addresses" OFF)
@ -28,7 +35,4 @@ if(FASTFLOAT_SANITIZE)
endif()
endif()
if(FASTFLOAT_TEST)
enable_testing()
add_subdirectory(tests)
endif(FASTFLOAT_TEST)

View File

@ -7,6 +7,11 @@ include(FetchContent)
FetchContent_Declare(doctest
GIT_REPOSITORY https://github.com/onqtam/doctest.git
GIT_TAG 2.4.1)
FetchContent_Declare(supplemental_test_files
GIT_REPOSITORY https://github.com/fastfloat/supplemental_test_files.git
GIT_TAG origin/main)
# FetchContent_MakeAvailable() was only introduced in 3.14
# https://cmake.org/cmake/help/v3.14/release/3.14.html#modules
@ -16,8 +21,15 @@ if(NOT doctest_POPULATED)
FetchContent_Populate(doctest)
add_subdirectory(${doctest_SOURCE_DIR} ${doctest_BINARY_DIR})
endif()
FetchContent_GetProperties(supplemental_test_files)
if(NOT supplemental_test_files_POPULATED)
message(STATUS "Tests enabled. Retrieving test files.")
FetchContent_Populate(supplemental_test_files)
message(STATUS "Test files retrieved.")
add_subdirectory(${supplemental_test_files_SOURCE_DIR} ${supplemental_test_files_BINARY_DIR})
endif()
add_library(supplemental-data INTERFACE)
target_compile_definitions(supplemental-data INTERFACE SUPPLEMENTAL_TEST_DATA_DIR="${supplemental_test_files_BINARY_DIR}/data")
function(fast_float_add_cpp_test TEST_NAME)
add_executable(${TEST_NAME} ${TEST_NAME}.cpp)
add_test(${TEST_NAME} ${TEST_NAME})
@ -25,18 +37,28 @@ function(fast_float_add_cpp_test TEST_NAME)
target_compile_options(${TEST_NAME} PUBLIC -Werror -Wall -Wextra -Weffc++)
target_compile_options(${TEST_NAME} PUBLIC -Wsign-compare -Wshadow -Wwrite-strings -Wpointer-arith -Winit-self -Wconversion -Wsign-conversion)
endif()
target_link_libraries(${TEST_NAME} PUBLIC fast_float doctest)
target_link_libraries(${TEST_NAME} PUBLIC fast_float doctest supplemental-data)
endfunction(fast_float_add_cpp_test)
fast_float_add_cpp_test(powersoffive_hardround)
fast_float_add_cpp_test(short_random_string)
fast_float_add_cpp_test(exhaustive32_midpoint)
fast_float_add_cpp_test(random_string)
fast_float_add_cpp_test(string_test)
fast_float_add_cpp_test(exhaustive32)
fast_float_add_cpp_test(exhaustive32_64)
fast_float_add_cpp_test(long_exhaustive32)
fast_float_add_cpp_test(long_exhaustive32_64)
fast_float_add_cpp_test(long_random64)
fast_float_add_cpp_test(random64)
fast_float_add_cpp_test(basictest)
fast_float_add_cpp_test(example_test)
fast_float_add_cpp_test(basictest)
option(FASTFLOAT_EXHAUSTIVE "Exhaustive tests" OFF)
if (FASTFLOAT_EXHAUSTIVE)
fast_float_add_cpp_test(powersoffive_hardround)
fast_float_add_cpp_test(short_random_string)
fast_float_add_cpp_test(exhaustive32_midpoint)
fast_float_add_cpp_test(random_string)
fast_float_add_cpp_test(string_test)
fast_float_add_cpp_test(exhaustive32)
fast_float_add_cpp_test(exhaustive32_64)
fast_float_add_cpp_test(long_exhaustive32)
fast_float_add_cpp_test(long_exhaustive32_64)
fast_float_add_cpp_test(long_random64)
fast_float_add_cpp_test(random64)
endif(FASTFLOAT_EXHAUSTIVE)

View File

@ -4,6 +4,110 @@
#include "fast_float/fast_float.h"
#include <iomanip>
#include <string>
#ifndef SUPPLEMENTAL_TEST_DATA_DIR
#define SUPPLEMENTAL_TEST_DATA_DIR "data/"
#endif
#ifndef __cplusplus
#error fastfloat requires a C++ compiler
#endif
#ifndef FASTFLOAT_CPLUSPLUS
#if defined(_MSVC_LANG) && !defined(__clang__)
#define FASTFLOAT_CPLUSPLUS (_MSC_VER == 1900 ? 201103L : _MSVC_LANG)
#else
#define FASTFLOAT_CPLUSPLUS __cplusplus
#endif
#endif
#if defined(__CYGWIN__) || defined(__MINGW32__) || defined(__MINGW64__) || defined(sun) || defined(__sun)
#define FASTFLOAT_ODDPLATFORM 1
#endif
#if defined __has_include
#if __has_include (<filesystem>)
#else
// filesystem is not available
#define FASTFLOAT_ODDPLATFORM 1
#endif
#else
// __has_include is not available
#define FASTFLOAT_ODDPLATFORM 1
#endif
// C++ 17 because it is otherwise annoying to browse all files in a directory.
// We also only run these tests on little endian systems.
#if (FASTFLOAT_CPLUSPLUS >= 201703L) && (FASTFLOAT_IS_BIG_ENDIAN == 0) && !defined(FASTFLOAT_ODDPLATFORM)
#include <iostream>
#include <filesystem>
#include <charconv>
// return true on succcess
bool check_file(std::string file_name) {
std::cout << "Checking " << file_name << std::endl;
size_t number{0};
std::fstream newfile(file_name, std::ios::in);
if (newfile.is_open()) {
std::string str;
while (std::getline(newfile, str)) {
if (str.size() > 0) {
// Read 32-bit hex
uint32_t float32;
auto r32 = std::from_chars(str.data() + 5, str.data() + str.size(),
float32, 16);
if(r32.ec != std::errc()) { std::cerr << "32-bit parsing failure\n"; return false; }
// Read 64-bit hex
uint64_t float64;
auto r64 = std::from_chars(str.data() + 14, str.data() + str.size(),
float64, 16);
if(r64.ec != std::errc()) { std::cerr << "64-bit parsing failure\n"; return false; }
// The string to parse:
const char *number_string = str.data() + 31;
const char *end_of_string = str.data() + str.size();
// Parse as 32-bit float
float parsed_32;
auto fast_float_r32 = fast_float::from_chars(number_string, end_of_string, parsed_32);
if(fast_float_r32.ec != std::errc()) { std::cerr << "parsing failure\n"; return false; }
// Parse as 64-bit float
double parsed_64;
auto fast_float_r64 = fast_float::from_chars(number_string, end_of_string, parsed_64);
if(fast_float_r64.ec != std::errc()) { std::cerr << "parsing failure\n"; return false; }
// Convert the floats to unsigned ints.
uint32_t float32_parsed;
uint64_t float64_parsed;
::memcpy(&float32_parsed, &parsed_32, sizeof(parsed_32));
::memcpy(&float64_parsed, &parsed_64, sizeof(parsed_64));
// Compare with expected results
if (float32_parsed != float32) {
std::cout << "bad 32 " << str << std::endl;
return false;
}
if (float64_parsed != float64) {
std::cout << "bad 64 " << str << std::endl;
return false;
}
number++;
}
}
std::cout << "checked " << std::defaultfloat << number << " values" << std::endl;
newfile.close(); // close the file object
} else {
std::cout << "Could not read " << file_name << std::endl;
return false;
}
return true;
}
TEST_CASE("supplemental") {
std::string path = SUPPLEMENTAL_TEST_DATA_DIR;
for (const auto & entry : std::filesystem::directory_iterator(path)) {
CHECK(check_file(entry.path().string()));
}
}
#endif
TEST_CASE("leading_zeroes") {
@ -295,6 +399,7 @@ TEST_CASE("64bit.inf") {
TEST_CASE("64bit.general") {
verify("9007199254740993.0", 0x1p+53);
verify("860228122.6654514319E+90", 0x1.92bb20990715fp+328);
verify(append_zeros("9007199254740993.0",1000), 0x1p+53);
verify("10000000000000000000", 0x1.158e460913dp+63);
verify("10000000000000000000000000000001000000000000", 0x1.cb2d6f618c879p+142);