From 7b6379a356363bc99a04edf4050b6213db82d1f8 Mon Sep 17 00:00:00 2001 From: "James E. King III" Date: Wed, 16 May 2018 13:50:17 +0000 Subject: [PATCH] Add CI framework used in a number of other repositories: - travis with valgrind, cppcheck, ubsan, codecov, covscan (future) - appveyor with MSVC 2010 through 2017, cygwin 32/64, mingw 32/64 - README, LICENSE, etc. --- .travis.yml | 165 ++++++++++++++++++++++++++++++++ Jamfile | 14 ++- LICENSE | 23 +++++ README.md | 34 +++++++ appveyor.yml | 98 +++++++++++++++++++ test/Jamfile.v2 | 26 +++-- test/bitset_test.hpp | 28 +++++- test/dyn_bitset_unit_tests4.cpp | 21 ++-- 8 files changed, 387 insertions(+), 22 deletions(-) create mode 100644 .travis.yml create mode 100644 LICENSE create mode 100644 README.md create mode 100644 appveyor.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..173a768 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,165 @@ +# Copyright 2016 Peter Dimov +# Copyright 2017, 2018 James E. King III +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) + +# +# Generic Travis CI build script for boostorg repositories +# +# Instructions for customizing this script for your library: +# +# 1. Customize the compilers and language levels you want. +# 2. If you have move than include/, src/, test/, example/, examples/, +# benchmark/ or tools/ directories, set the environment variable DEPINST. +# For example if your build uses code in "bench/" and "fog/" directories: +# - DEPINST="--include bench --include fog" +# 3. If you want to enable Coverity Scan, you need to provide the environment +# variables COVERITY_SCAN_TOKEN and COVERITY_SCAN_NOTIFICATION_EMAIL in +# your github settings. +# 4. Enable pull request builds in your boostorg/ account. +# 5. The default language level is C++03, you can change CXXSTD to modify it. +# +# That's it - the scripts will do everything else for you. +# + +sudo: false +dist: trusty +language: cpp + +env: + global: + # see: http://www.boost.org/build/doc/html/bbv2/overview/invocation.html#bbv2.overview.invocation.properties + # to use the default for a given environment, comment it out; recommend you build debug and release however.. + # - B2_ADDRESS_MODEL=address-model=64,32 + # - B2_LINK=link=shared,static + # - B2_THREADING=threading=multi,single + - B2_VARIANT=variant=release,debug + # - CXXSTD=03 + # - DEPINST="--include other" + +install: + - git clone https://github.com/jeking3/boost-ci.git boost-ci + - cp -pr boost-ci/ci boost-ci/.codecov.yml . + - source ci/travis/install.sh + +addons: + apt: + packages: + - binutils-gold + - gdb + - libc6-dbg + +branches: + only: + - develop + - master + +script: + - cd $BOOST_ROOT/libs/$SELF + - ci/travis/build.sh + +jobs: + include: + #################### Jobs to run on every pull request #################### + - os: linux + env: + - COMMENT="C++03" + - TOOLSET=gcc,gcc-7,clang + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + - os: linux + env: + - COMMENT="C++11" + - TOOLSET=gcc,gcc-7,clang + - CXXSTD=11 + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + - os: linux + env: + - COMMENT=valgrind + - TOOLSET=clang + - B2_VARIANT=variant=debug + - TESTFLAGS=testing.launcher=valgrind + - VALGRIND_OPTS=--error-exitcode=1 + addons: + apt: + packages: + - clang-5.0 + - libstdc++-7-dev + - valgrind + sources: + - llvm-toolchain-trusty-5.0 + - ubuntu-toolchain-r-test + + - os: linux + env: + - COMMENT=cppcheck + script: + - cd $BOOST_ROOT/libs/$SELF + - ci/travis/cppcheck.sh + + - os: linux + env: + - COMMENT=UBSAN + - B2_VARIANT=variant=debug + - TOOLSET=gcc-7 + - CXXFLAGS="cxxflags=-fno-omit-frame-pointer cxxflags=-fsanitize=undefined cxxflags=-fno-sanitize-recover=undefined" + - LINKFLAGS="linkflags=-fsanitize=undefined linkflags=-fno-sanitize-recover=undefined linkflags=-fuse-ld=gold" + - UBSAN_OPTIONS=print_stacktrace=1 + addons: + apt: + packages: + - g++-7 + sources: + - ubuntu-toolchain-r-test + + - os: linux + env: + - COMMENT=CodeCov + - TOOLSET=gcc-7 + addons: + apt: + packages: + - gcc-7 + - g++-7 + sources: + - ubuntu-toolchain-r-test + script: + - pushd /tmp && git clone https://github.com/linux-test-project/lcov.git && cd lcov && sudo make install && which lcov && lcov --version && popd + - cd $BOOST_ROOT/libs/$SELF + - ci/travis/codecov.sh + + # does not work with sourced install shell yet: see + # https://travis-ci.org/jeking3/tokenizer/jobs/384903189 + # for a typical failure + # - os: osx + # osx_image: xcode9 + # env: + # - TOOLSET=clang + # - CXXSTD=03,11 + + #################### Jobs to run on pushes to master, develop ################### + + # Coverity Scan + - os: linux + if: (env(COVERITY_SCAN_NOTIFICATION_EMAIL) IS present) AND (branch IN (develop, master)) AND (type IN (cron, push)) + env: + - COMMENT="Coverity Scan" + - TOOLSET=gcc + script: + - echo -n | openssl s_client -connect scan.coverity.com:443 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' | sudo tee -a /etc/ssl/certs/ca- + - cd $BOOST_ROOT/libs/$SELF + - ci/travis/coverity.sh + +notifications: + email: + false + diff --git a/Jamfile b/Jamfile index cf5eb61..8f6db43 100644 --- a/Jamfile +++ b/Jamfile @@ -1,3 +1,11 @@ -# Empty Jamfile because the super project still expects one to appear here. -# Can be deleted once 'status/Jamfile.v2' has been updated in the super -# project. +# Boost.DynamicBitset Library Jamfile +# +# Copyright (c) 2018 James E. King III +# +# Use, modification, and distribution are subject to the +# Boost Software License, Version 1.0. (See accompanying file +# LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) + +# please order by name to ease maintenance +build-project example ; +build-project test ; diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..36b7cd9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +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, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..8f3fd8c --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +DynamicBitset, part of collection of the [Boost C++ Libraries](http://github.com/boostorg), is similar to std::bitset however the size is specified at run-time instead of at compile-time. + +### License + +Distributed under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). + +### Properties + +* C++03 +* Header-only + +### Build Status + +Branch | Travis | Appveyor | Coverity Scan | codecov.io | Deps | Docs | Tests | +:-------------: | ------ | -------- | ------------- | ---------- | ---- | ---- | ----- | +[`master`](https://github.com/boostorg/dynamic_bitset/tree/master) | [![Build Status](https://travis-ci.org/boostorg/dynamic_bitset.svg?branch=master)](https://travis-ci.org/boostorg/dynamic_bitset) | [![Build status](https://ci.appveyor.com/api/projects/status/keyn57y5d3sl1gw5/branch/master?svg=true)](https://ci.appveyor.com/project/jeking3/dynamic_bitset-jv17p/branch/master) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/99999/badge.svg)](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [![codecov](https://codecov.io/gh/boostorg/dynamic_bitset/branch/master/graph/badge.svg)](https://codecov.io/gh/boostorg/dynamic_bitset/branch/master)| [![Deps](https://img.shields.io/badge/deps-master-brightgreen.svg)](https://pdimov.github.io/boostdep-report/master/dynamic_bitset.html) | [![Documentation](https://img.shields.io/badge/docs-master-brightgreen.svg)](http://www.boost.org/doc/libs/master/doc/html/dynamic_bitset.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-master-brightgreen.svg)](http://www.boost.org/development/tests/master/developer/dynamic_bitset.html) +[`develop`](https://github.com/boostorg/dynamic_bitset/tree/develop) | [![Build Status](https://travis-ci.org/boostorg/dynamic_bitset.svg?branch=develop)](https://travis-ci.org/boostorg/dynamic_bitset) | [![Build status](https://ci.appveyor.com/api/projects/status/keyn57y5d3sl1gw5/branch/develop?svg=true)](https://ci.appveyor.com/project/jeking3/dynamic_bitset-jv17p/branch/develop) | [![Coverity Scan Build Status](https://scan.coverity.com/projects/99999/badge.svg)](https://scan.coverity.com/projects/boostorg-dynamic_bitset) | [![codecov](https://codecov.io/gh/boostorg/dynamic_bitset/branch/develop/graph/badge.svg)](https://codecov.io/gh/boostorg/dynamic_bitset/branch/develop) | [![Deps](https://img.shields.io/badge/deps-develop-brightgreen.svg)](https://pdimov.github.io/boostdep-report/develop/dynamic_bitset.html) | [![Documentation](https://img.shields.io/badge/docs-develop-brightgreen.svg)](http://www.boost.org/doc/libs/develop/doc/html/dynamic_bitset.html) | [![Enter the Matrix](https://img.shields.io/badge/matrix-develop-brightgreen.svg)](http://www.boost.org/development/tests/develop/developer/dynamic_bitset.html) + +### Directories + +| Name | Purpose | +| ----------- | ------------------------------ | +| `example` | examples | +| `doc` | documentation | +| `include` | headers | +| `test` | unit tests | + +### More information + +* [Ask questions](http://stackoverflow.com/questions/ask?tags=c%2B%2B,boost,boost-dynamic_bitset) +* [Report bugs](https://github.com/boostorg/dynamic_bitset/issues): Be sure to mention Boost version, platform and compiler you're using. A small compilable code sample to reproduce the problem is always good as well. +* Submit your patches as pull requests against **develop** branch. Note that by submitting patches you agree to license your modifications under the [Boost Software License, Version 1.0](http://www.boost.org/LICENSE_1_0.txt). +* Discussions about the library are held on the [Boost developers mailing list](http://www.boost.org/community/groups.html#main). Be sure to read the [discussion policy](http://www.boost.org/community/policy.html) before posting and add the `[dynamic_bitset]` tag at the beginning of the subject line. + diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..e10b9e0 --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,98 @@ +# Copyright 2016, 2017 Peter Dimov +# Copyright (C) 2017, 2018 James E. King III +# Distributed under the Boost Software License, Version 1.0. +# (See accompanying file LICENSE_1_0.txt or copy at http://boost.org/LICENSE_1_0.txt) + +# +# Generic Appveyor build script for boostorg repositories +# +# Instructions for customizing this script for your library: +# +# 1. Customize the compilers and language levels you want. +# 2. If you have move than include/, src/, test/, example/, examples/, +# benchmark/ or tools/ directories, set the environment variable DEPINST. +# For example if your build uses code in "bench/" and "fog/" directories: +# - DEPINST: --include bench --include fog +# 3. Enable pull request builds in your boostorg/ account. +# 4. The default language level is C++03, you can change CXXSTD to modify it. +# +# That's it - the scripts will do everything else for you. +# + +version: 1.0.{build}-{branch} + +shallow_clone: true + +branches: + only: + - develop + - master + +matrix: + allow_failures: + - MAYFAIL: true + +environment: + global: + # see: http://www.boost.org/build/doc/html/bbv2/overview/invocation.html#bbv2.overview.invocation.properties + # to use the default for a given environment, comment it out; recommend you build debug and release however.. + # on Windows it is important to exercise all the possibilities, especially shared vs static + # B2_ADDRESS_MODEL: address-model=64,32 + # B2_LINK: link=shared,static + # B2_THREADING: threading=multi,single + B2_VARIANT: variant=release,debug + CXXSTD: 03 + # DEPINST: --include otherdir + + matrix: + - FLAVOR: Visual Studio 2017 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + TOOLSET: msvc-14.1 + B2_ADDRESS_MODEL: address-model=64,32 + - FLAVOR: Visual Studio 2015 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015 + TOOLSET: msvc-14.0 + B2_ADDRESS_MODEL: address-model=64,32 + - FLAVOR: Visual Studio 2010, 2012, 2013 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013 + TOOLSET: msvc-10.0,msvc-11.0,msvc-12.0 + - FLAVOR: cygwin (32-bit) + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + ADDPATH: C:\cygwin\bin; + B2_ADDRESS_MODEL: address-model=32 + # https://github.com/boostorg/test/issues/144 + DEFINES: define=_POSIX_C_SOURCE=200112L + THREADING: threadapi=pthread + TOOLSET: gcc + - FLAVOR: cygwin (64-bit) + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + ADDPATH: C:\cygwin64\bin; + B2_ADDRESS_MODEL: address-model=64 + # https://github.com/boostorg/test/issues/144 + DEFINES: define=_POSIX_C_SOURCE=200112L + THREADING: threadapi=pthread + TOOLSET: gcc + - FLAVOR: mingw32 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + ARCH: i686 + B2_ADDRESS_MODEL: address-model=32 + SCRIPT: ci\appveyor\mingw.bat + - FLAVOR: mingw64 + APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017 + ARCH: x86_64 + B2_ADDRESS_MODEL: address-model=64 + SCRIPT: ci\appveyor\mingw.bat + +install: + - set SELF=%APPVEYOR_PROJECT_NAME:-=_% + - git clone https://github.com/jeking3/boost-ci.git C:\boost-ci + - xcopy /s /e /q /i C:\boost-ci\ci .\ci + - ci\appveyor\install.bat + +build: off + +test_script: + - set SELF=%APPVEYOR_PROJECT_NAME:-=_% + - PATH=%ADDPATH%%PATH% + - IF DEFINED SCRIPT (call libs\%SELF%\%SCRIPT%) ELSE (b2 libs/%SELF% toolset=%TOOLSET% cxxstd=%CXXSTD% %CXXFLAGS% %DEFINES% %THREADING% %B2_ADDRESS_MODEL% %B2_LINK% %B2_THREADING% %B2_VARIANT% -j3) + diff --git a/test/Jamfile.v2 b/test/Jamfile.v2 index 98eaefa..1076436 100644 --- a/test/Jamfile.v2 +++ b/test/Jamfile.v2 @@ -4,13 +4,27 @@ # Distributed under the Boost Software License, Version 1.0. # (See accompanying file LICENSE_1_0.txt or copy at # http://www.boost.org/LICENSE_1_0.txt) +# + +import os ; test-suite dynamic_bitset : - [ run dyn_bitset_unit_tests1.cpp ] - [ run dyn_bitset_unit_tests2.cpp ] - [ run dyn_bitset_unit_tests3.cpp ] - [ run dyn_bitset_unit_tests4.cpp ] - [ run dyn_bitset_unit_tests5.cpp /boost/serialization//boost_serialization - : : : _SCL_SECURE_NO_WARNINGS=1 ] + [ run dyn_bitset_unit_tests1.cpp : : : /boost/system//boost_system ] + [ run dyn_bitset_unit_tests2.cpp : : : /boost/system//boost_system ] + [ run dyn_bitset_unit_tests3.cpp : : : /boost/system//boost_system ] + [ run dyn_bitset_unit_tests4.cpp : : : /boost/filesystem//boost_filesystem + /boost/system//boost_system ] ; + +# due to https://github.com/boostorg/serialization/issues/108 +if ! [ os.environ UBSAN_OPTIONS ] +{ + test-suite dynamic_bitset_serialization : + + [ run dyn_bitset_unit_tests5.cpp + : : : _SCL_SECURE_NO_WARNINGS=1 + /boost/serialization//boost_serialization + /boost/system//boost_system ] + ; +} diff --git a/test/bitset_test.hpp b/test/bitset_test.hpp index 64dbe9c..d81c364 100644 --- a/test/bitset_test.hpp +++ b/test/bitset_test.hpp @@ -27,10 +27,12 @@ #include "boost/limits.hpp" #include "boost/dynamic_bitset/dynamic_bitset.hpp" #include "boost/test/minimal.hpp" +#include "boost/filesystem.hpp" template inline bool nth_bit(Block num, std::size_t n) { +#ifndef NDEBUG #ifdef __BORLANDC__ // Borland deduces Block as a const qualified type, // and thus finds numeric_limits to be zero :( @@ -40,8 +42,9 @@ inline bool nth_bit(Block num, std::size_t n) #else int block_width = std::numeric_limits::digits; #endif - assert(n < (std::size_t) block_width); +#endif + return (num >> n) & 1; } @@ -61,10 +64,27 @@ std::string get_long_string() return std::string(p); } -const char * test_file_name() +class scoped_temp_file { - return "boost_dynamic_bitset_tests"; -} +public: + scoped_temp_file() + : m_path(boost::filesystem::unique_path()) + { + } + + ~scoped_temp_file() + { + boost::filesystem::remove(m_path); + } + + const boost::filesystem::path& path() const + { + return m_path; + } + +private: + boost::filesystem::path m_path; +}; #if defined BOOST_OLD_IOSTREAMS || defined BOOST_NO_STD_LOCALE template diff --git a/test/dyn_bitset_unit_tests4.cpp b/test/dyn_bitset_unit_tests4.cpp index c7d8ba5..ef40c37 100644 --- a/test/dyn_bitset_unit_tests4.cpp +++ b/test/dyn_bitset_unit_tests4.cpp @@ -125,13 +125,13 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) } { // test 1a - file stream + scoped_temp_file stf; bitset_type b(strings[si]); - std::ofstream file(test_file_name(), std::ios::trunc); + std::ofstream file(stf.path().string().c_str(), std::ios::trunc); file.width(w); file.fill(fill_chars[ci]); file.exceptions(masks[mi]); - Tests::stream_inserter(b, file, test_file_name()); - + Tests::stream_inserter(b, file, stf.path().string().c_str()); } { //NOTE: there are NO string stream tests @@ -139,12 +139,13 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) #if !defined (BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS) { // test 1b - wide file stream + scoped_temp_file stf; bitset_type b(strings[si]); - std::wofstream file(test_file_name()); + std::wofstream file(stf.path().string().c_str()); file.width(w); file.fill(fill_chars[ci]); file.exceptions(masks[mi]); - Tests::stream_inserter(b, file, test_file_name()); + Tests::stream_inserter(b, file, stf.path().string().c_str()); } #endif } @@ -257,13 +258,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) } // test 1a - (narrow) file stream { + scoped_temp_file stf; bitset_type b(1, 255ul); { - std::ofstream f(test_file_name()); + std::ofstream f(stf.path().string().c_str()); f << strings[si]; } - std::ifstream f(test_file_name()); + std::ifstream f(stf.path().string().c_str()); f.width(w); f.exceptions(masks[mi]); Tests::stream_extractor(b, f, strings[si]); @@ -282,14 +284,15 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) #if !defined(BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS) // test 1b - wchar_t file stream { + scoped_temp_file stf; std::wstring wstr = widen_string(strings[si]); bitset_type b(1, 255ul); { - std::basic_ofstream of(test_file_name()); + std::basic_ofstream of(stf.path().string().c_str()); of << wstr; } - std::basic_ifstream f(test_file_name()); + std::basic_ifstream f(stf.path().string().c_str()); f.width(w); f.exceptions(masks[mi]); Tests::stream_extractor(b, f, wstr);