├── .github └── workflows │ └── build-check.yml ├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── configuration_files ├── based_on_data_length │ ├── 1000MB.json │ ├── 100MB.json │ ├── 10MB.json │ ├── 16MB.json │ ├── 1MB.json │ ├── 250MB.json │ ├── 400MB.json │ ├── 500MB.json │ ├── 50MB.json │ ├── 75MB.json │ └── sample.json ├── default-8GB.json └── rtt-settings.json ├── libs ├── cephes │ ├── cephes.cpp │ └── cephes.h ├── easylogging │ ├── LICENSE │ └── easylogging++.h ├── moderncppjson │ ├── LICENSE.MIT │ └── json.hpp └── variant │ ├── .Rhistory │ ├── .appveyor.yml │ ├── .clang-format │ ├── .gitignore │ ├── .gitmodules │ ├── .travis.yml │ ├── CMakeLists.txt │ ├── LICENSE_1_0.txt │ ├── README.md │ ├── cmake │ └── mpark_variant-config.cmake.in │ ├── include │ └── mpark │ │ ├── in_place.hpp │ │ ├── variant.hpp │ │ └── variants │ │ ├── config.hpp │ │ └── lib.hpp │ └── test │ ├── CMakeLists.txt │ ├── README.md │ ├── access.get.cpp │ ├── access.get_if.cpp │ ├── access.holds_alternative.cpp │ ├── assign.conversion.cpp │ ├── assign.copy.cpp │ ├── assign.emplace.cpp │ ├── assign.move.cpp │ ├── cnstr.conversion.cpp │ ├── cnstr.copy.cpp │ ├── cnstr.default.cpp │ ├── cnstr.in_place.cpp │ ├── cnstr.move.cpp │ ├── dtor.cpp │ ├── hash.cpp │ ├── intro.cpp │ ├── rel.cpp │ ├── run_libcxx_tests.sh │ ├── swap.cpp │ └── visit.cpp └── rtt ├── batteries ├── batteryoutput.cpp ├── batteryoutput.h ├── configuration-batt.cpp ├── configuration-batt.h ├── dieharder │ ├── battery-dh.cpp │ ├── battery-dh.h │ ├── setting-dh.cpp │ ├── setting-dh.h │ ├── test-dh.cpp │ ├── test-dh.h │ ├── testresult-dh.cpp │ ├── testresult-dh.h │ ├── variant-dh.cpp │ └── variant-dh.h ├── ibattery-batt.cpp ├── ibattery-batt.h ├── itest-batt.cpp ├── itest-batt.h ├── itestresult-batt.cpp ├── itestresult-batt.h ├── ivariant-batt.cpp ├── ivariant-batt.h ├── niststs │ ├── battery-sts.cpp │ ├── battery-sts.h │ ├── test-sts.cpp │ ├── test-sts.h │ ├── testresult-sts.cpp │ ├── testresult-sts.h │ ├── variant-sts.cpp │ └── variant-sts.h ├── result │ ├── statistic-res.cpp │ ├── statistic-res.h │ ├── subtestresult-res.cpp │ ├── subtestresult-res.h │ ├── variantresult-res.cpp │ └── variantresult-res.h ├── testconstants.cpp ├── testconstants.h ├── testrunner-batt.cpp ├── testrunner-batt.h └── testu01 │ ├── battery-tu01.cpp │ ├── battery-tu01.h │ ├── test-tu01.cpp │ ├── test-tu01.h │ ├── testresult-tu01.cpp │ ├── testresult-tu01.h │ ├── variant-tu01.cpp │ └── variant-tu01.h ├── bugexception.h ├── clinterface ├── batteryarg.cpp ├── batteryarg.h ├── clargument.h ├── resultstoragearg.cpp ├── resultstoragearg.h ├── rttclioptions.cpp └── rttclioptions.h ├── constants.cpp ├── constants.h ├── globalcontainer.cpp ├── globalcontainer.h ├── logger.cpp ├── logger.h ├── main.cpp ├── rttexception.h ├── storage ├── create_rtt_tables.sql ├── filestorage.cpp ├── filestorage.h ├── istorage.cpp ├── istorage.h ├── mysqlstorage.cpp └── mysqlstorage.h ├── strings.cpp ├── strings.h ├── toolkitsettings.cpp ├── toolkitsettings.h ├── utils.cpp ├── utils.h ├── version.h └── version.h.in /.github/workflows/build-check.yml: -------------------------------------------------------------------------------- 1 | name: Build check 2 | 3 | on: 4 | push: 5 | pull_request: 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | 11 | steps: 12 | - uses: actions/checkout@v4 13 | - name: Install dependecies 14 | run: sudo apt-get install libmariadb-dev libmysqlcppconn-dev libboost-regex-dev 15 | - name: Compile 16 | run: make -j2 17 | - name: Compile (static) 18 | run: make -j2 static 19 | - name: make clean 20 | run: make clean 21 | - name: Compile without MySQL 22 | run: make -j2 USE_MYSQL_BACKEND=0 23 | - name: Compile without MySQL (static) 24 | run: make -j2 USE_MYSQL_BACKEND=0 static 25 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pri 2 | *.pro 3 | *.user* 4 | *.o 5 | randomness-testing-toolkit 6 | build/ 7 | cmake-build-* 8 | .idea 9 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015-2017 Centre for Research on Cryptography and Security 4 | 5 | https://github.com/crocs-muni/ 6 | https://crocs.fi.muni.cz/ 7 | 8 | Permission is hereby granted, free of charge, to any person obtaining a copy 9 | of this software and associated documentation files (the "Software"), to deal 10 | in the Software without restriction, including without limitation the rights 11 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | copies of the Software, and to permit persons to whom the Software is 13 | furnished to do so, subject to the following conditions: 14 | 15 | The above copyright notice and this permission notice shall be included in all 16 | copies or substantial portions of the Software. 17 | 18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 21 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 22 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 23 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 24 | SOFTWARE. 25 | 26 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | TOOL=randomness-testing-toolkit 2 | 3 | CC=gcc 4 | CXX=g++ 5 | CXXFLAGS += -std=c++14 -I. -O3 -g 6 | LIBS=-L/usr/lib -L. -lpthread -lboost_regex 7 | 8 | # Disable MySQL backend with USE_MYSQL_BACKEND=0 9 | ifeq ($(USE_MYSQL_BACKEND),) 10 | USE_MYSQL_BACKEND=1 11 | endif 12 | ifeq ($(USE_MYSQL_BACKEND),1) 13 | CXXFLAGS += -DUSE_MYSQL_BACKEND=1 14 | LIBS += -lmysqlcppconn 15 | STATIC_LIBS += -lmariadb 16 | endif 17 | 18 | # Debian only fixed config for now 19 | STATIC_LIBS += -lssl -lcrypto -lz -lzstd -static 20 | 21 | # === Header files === 22 | # === Source files must be in same dir as corresponding header === 23 | DEPS = \ 24 | libs/cephes/cephes.h \ 25 | rtt/constants.h \ 26 | rtt/utils.h \ 27 | rtt/version.h \ 28 | rtt/batteries/dieharder/battery-dh.h \ 29 | rtt/batteries/dieharder/test-dh.h \ 30 | rtt/batteries/niststs/battery-sts.h \ 31 | rtt/batteries/niststs/test-sts.h \ 32 | rtt/batteries/dieharder/setting-dh.h \ 33 | rtt/batteries/testu01/battery-tu01.h \ 34 | rtt/batteries/testu01/test-tu01.h \ 35 | rtt/batteries/ibattery-batt.h \ 36 | rtt/batteries/itest-batt.h \ 37 | rtt/batteries/testrunner-batt.h \ 38 | rtt/rttexception.h \ 39 | rtt/toolkitsettings.h \ 40 | rtt/bugexception.h \ 41 | rtt/batteries/configuration-batt.h \ 42 | rtt/batteries/testconstants.h \ 43 | rtt/globalcontainer.h \ 44 | libs/easylogging/easylogging++.h \ 45 | rtt/logger.h \ 46 | rtt/strings.h \ 47 | rtt/batteries/batteryoutput.h \ 48 | libs/moderncppjson/json.hpp \ 49 | rtt/storage/istorage.h \ 50 | rtt/storage/filestorage.h \ 51 | rtt/batteries/ivariant-batt.h \ 52 | rtt/batteries/niststs/variant-sts.h \ 53 | rtt/batteries/dieharder/variant-dh.h \ 54 | rtt/batteries/testu01/variant-tu01.h \ 55 | rtt/batteries/result/pvalueset-res.h \ 56 | rtt/batteries/result/subtestresult-res.h \ 57 | rtt/batteries/result/variantresult-res.h \ 58 | rtt/storage/mysqlstorage.h \ 59 | rtt/batteries/itestresult-batt.h \ 60 | rtt/batteries/testu01/testresult-tu01.h \ 61 | rtt/batteries/niststs/testresult-sts.h \ 62 | rtt/batteries/dieharder/testresult-dh.h \ 63 | rtt/batteries/result/statistic-res.h \ 64 | libs/variant/include/mpark/variants/config.hpp \ 65 | libs/variant/include/mpark/variants/lib.hpp \ 66 | libs/variant/include/mpark/in_place.hpp \ 67 | libs/variant/include/mpark/variant.hpp \ 68 | rtt/clinterface/clargument.h \ 69 | rtt/clinterface/batteryarg.h \ 70 | rtt/clinterface/resultstoragearg.h \ 71 | rtt/clinterface/rttclioptions.h 72 | 73 | # === Target object files === 74 | OBJ = \ 75 | cephes.o \ 76 | constants.o \ 77 | main.o \ 78 | utils.o \ 79 | battery-dh.o \ 80 | test-dh.o \ 81 | battery-sts.o \ 82 | test-sts.o \ 83 | setting-dh.o \ 84 | battery-tu01.o \ 85 | test-tu01.o \ 86 | ibattery-batt.o \ 87 | itest-batt.o \ 88 | testrunner-batt.o \ 89 | toolkitsettings.o \ 90 | configuration-batt.o \ 91 | testconstants.o \ 92 | globalcontainer.o \ 93 | logger.o \ 94 | strings.o \ 95 | batteryoutput.o \ 96 | istorage.o \ 97 | filestorage.o \ 98 | ivariant-batt.o \ 99 | variant-sts.o \ 100 | variant-dh.o \ 101 | variant-tu01.o \ 102 | subtestresult-res.o \ 103 | variantresult-res.o \ 104 | mysqlstorage.o \ 105 | itestresult-batt.o \ 106 | testresult-dh.o \ 107 | testresult-sts.o \ 108 | testresult-tu01.o \ 109 | statistic-res.o \ 110 | batteryarg.o \ 111 | resultstoragearg.o \ 112 | rttclioptions.o 113 | 114 | # === All paths inside project directory === 115 | # === Ugly but works === 116 | VPATH = \ 117 | rtt:\ 118 | rtt/batteries:\ 119 | rtt/batteries/dieharder:\ 120 | rtt/batteries/niststs:\ 121 | rtt/batteries/testu01:\ 122 | rtt/batteries/result:\ 123 | rtt/clinterface:\ 124 | rtt/storage:\ 125 | libs:\ 126 | libs/cephes:\ 127 | libs/easylogging:\ 128 | libs/moderncppjson:\ 129 | libs/variant:\ 130 | libs/variant/include:\ 131 | libs/variant/include/mpark:\ 132 | libs/variant/include/mpark/variants 133 | 134 | %.o: %.cpp $(DEPS) 135 | $(CXX) -c -o $@ $< $(CXXFLAGS) 136 | 137 | $(TOOL): $(OBJ) 138 | $(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS) 139 | 140 | $(TOOL).static: $(OBJ) 141 | $(CXX) -o $@ $^ $(CXXFLAGS) $(LIBS) $(STATIC_LIBS) 142 | 143 | static: $(TOOL).static 144 | 145 | .PHONY: clean 146 | 147 | clean: 148 | rm -f *.o $(TOOL) $(TOOL).static 149 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Randomness Testing Toolkit 2 | Randomness testing toolkit (RTT) is a tool that unites execution of various statistical batteries used for testing that random data generated are without significant defects. It aims to detect non-randomness in given binary data in simple, automated manner while providing support for both small-scale testing and massive high-speed testing. RTT also post-processes outputs of batteries so one does not need to cope vith various output formats these batteries use. 3 | 4 | RTT currently implements support for the following statistical tools: 5 | * **NIST Statistical Test Suite** [home page](http://csrc.nist.gov/groups/ST/toolkit/rng/documentation_software.html) 6 | * **Dieharder: A Random Number Test Suite** [home page](http://www.phy.duke.edu/~rgb/General/dieharder.php) 7 | * **TestU01** [home page](http://simul.iro.umontreal.ca/testu01/tu01.html) 8 | 9 | To be implemented in the future: 10 | * **BoolTest** [home page](https://github.com/ph4r05/polynomial-distinguishers) 11 | 12 | ## Related repositories 13 | This repository contains backend part of Randomness Testing Toolkit. For other parts see following repositories. 14 | 15 | * **Statistical batteries** [GitHub](https://github.com/crocs-muni/rtt-statistical-batteries) 16 | Set of updated and modified statistical batteries compatible with RTT. 17 | * **Service deployment automation** [GitHub](https://github.com/crocs-muni/rtt-deployment) 18 | RTT can be deployed on single or multiple servers as a service. Scripts in this repository automates the process of deployment. 19 | * **Web interface** [GitHub](https://github.com/crocs-muni/RTTWebInterface) 20 | The web interface is working on top of the deployed service and allow users to analyze data and view the analysis results through their browsers. 21 | 22 | ## Installation and usage 23 | For instructions on how to install and use Randomness Testing Toolkit, please refer to our [wiki](https://github.com/crocs-muni/randomness-testing-toolkit/wiki). 24 | 25 | ## Future plans 26 | We run RTT for several years connected to high-speed computational resource called Metacentrum and used during various research activities. RTT is now very close to be dockerized for easy deployment locally if you want to just interactively upload one file for analysis. 27 | 28 | ## Authors 29 | The framework is developed at the [Centre for Research on Cryptography and Security (formerly Laboratory of Security and Applied Cryptography)](https://www.fi.muni.cz/research/crocs/), [Masaryk University](http://www.muni.cz/), Brno, Czech Republic since 2015, with parts of randomness testing reaching well back to 2005. 30 | 31 | ## License 32 | Randomness Testing Toolkit is licenced under MIT Licence, Copyright (c) 2015-2017 Centre for Research on Cryptography and Security. For details on MIT Licence, see file LICENSE. 33 | 34 | ## Third party libraries 35 | Some sub-parts of the project have their own licencing conditions. The brief list of such sub-parts follows. 36 | 37 | * **Easylogging++** [Home page](https://github.com/muflihun/easyloggingpp) 38 | Simple header C++ logging library. Released under MIT license. 39 | 40 | * **JSON for modern C++** [Home page](https://github.com/nlohmann/json) 41 | JSON parser for C++. Released under MIT license. 42 | 43 | * **C++17 std::variant for C++11/14/17** [Home page](https://github.com/mpark/variant) 44 | Implementation of variant object from C++17 standard. 45 | 46 | -------------------------------------------------------------------------------- /configuration_files/rtt-settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "toolkit-settings": { 3 | "logger": { 4 | "dir-prefix": "results/logs", 5 | "run-log-dir": "run-logs", 6 | "dieharder-dir": "dieharder", 7 | "nist-sts-dir": "niststs", 8 | "tu01-smallcrush-dir": "testu01/smallcrush", 9 | "tu01-crush-dir": "testu01/crush", 10 | "tu01-bigcrush-dir": "testu01/bigcrush", 11 | "tu01-rabbit-dir": "testu01/rabbit", 12 | "tu01-alphabit-dir": "testu01/alphabit", 13 | "tu01-blockalphabit-dir": "testu01/blockalphabit" 14 | }, 15 | 16 | "result-storage": { 17 | "file": { 18 | "main-file": "results/testbed-table.txt", 19 | "dir-prefix": "results/reports", 20 | "dieharder-dir": "dieharder", 21 | "nist-sts-dir": "niststs", 22 | "tu01-smallcrush-dir": "testu01/smallcrush", 23 | "tu01-crush-dir": "testu01/crush", 24 | "tu01-bigcrush-dir": "testu01/bigcrush", 25 | "tu01-rabbit-dir": "testu01/rabbit", 26 | "tu01-alphabit-dir": "testu01/alphabit", 27 | "tu01-blockalphabit-dir": "testu01/blockalphabit" 28 | }, 29 | 30 | "mysql-db": { 31 | "address": "", 32 | "name": "", 33 | "port": "", 34 | "credentials-file": "" 35 | } 36 | }, 37 | 38 | "binaries": { 39 | "nist-sts": "", 40 | "dieharder": "", 41 | "testu01": "" 42 | }, 43 | 44 | "miscellaneous": { 45 | "nist-sts": { 46 | "main-result-dir": "experiments/AlgorithmTesting/" 47 | } 48 | }, 49 | 50 | "execution": { 51 | "max-parallel-tests": 8, 52 | "test-timeout-seconds": 3600 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /libs/cephes/cephes.h: -------------------------------------------------------------------------------- 1 | #ifndef CEPHES_H 2 | #define CEPHES_H 3 | 4 | class Cephes { 5 | public: 6 | static double cephes_igamc(double a, double x); 7 | static double cephes_igam(double a, double x); 8 | static double cephes_lgam(double x); 9 | static double cephes_p1evl(double x, double *coef, int N); 10 | static double cephes_polevl(double x, double *coef, int N); 11 | static double cephes_erf(double x); 12 | static double cephes_erfc(double x); 13 | static double cephes_normal(double x); 14 | }; 15 | 16 | #endif /* _CEPHES_H_ */ 17 | -------------------------------------------------------------------------------- /libs/easylogging/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2017 muflihun.com 4 | 5 | https://github.com/muflihun/ 6 | https://muflihun.github.io 7 | https://muflihun.com 8 | 9 | Permission is hereby granted, free of charge, to any person obtaining a copy of 10 | this software and associated documentation files (the "Software"), to deal in 11 | the Software without restriction, including without limitation the rights to 12 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 13 | the Software, and to permit persons to whom the Software is furnished to do so, 14 | subject to the following conditions: 15 | 16 | The above copyright notice and this permission notice shall be included in all 17 | copies or substantial portions of the Software. 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 21 | FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 22 | COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 23 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 24 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 | -------------------------------------------------------------------------------- /libs/moderncppjson/LICENSE.MIT: -------------------------------------------------------------------------------- 1 | The library is licensed under the MIT License 2 | : 3 | 4 | Copyright (c) 2013-2016 Niels Lohmann 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy of 7 | this software and associated documentation files (the "Software"), to deal in 8 | the Software without restriction, including without limitation the rights to 9 | use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies 10 | of the Software, and to permit persons to whom the Software is furnished to do 11 | so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in all 14 | copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 22 | SOFTWARE. 23 | -------------------------------------------------------------------------------- /libs/variant/.Rhistory: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crocs-muni/randomness-testing-toolkit/09b6ea10d9126cf679679fa710f0954105c53ee6/libs/variant/.Rhistory -------------------------------------------------------------------------------- /libs/variant/.appveyor.yml: -------------------------------------------------------------------------------- 1 | image: Visual Studio 2015 2 | 3 | build: 4 | verbosity: detailed 5 | 6 | clone_depth: 1 7 | 8 | install: 9 | - cmd: git submodule -q update --init 10 | 11 | platform: 12 | - x86 13 | - x64 14 | 15 | configuration: 16 | - Debug 17 | - Release 18 | 19 | build_script: 20 | - mkdir build 21 | - cd build 22 | - set GENERATOR=Visual Studio 14 2015 23 | - if "%PLATFORM%" == "x64" set GENERATOR=%GENERATOR% Win64 24 | - cmake -G "%GENERATOR%" 25 | -T "LLVM-vs2014" 26 | -DCMAKE_C_COMPILER=clang-cl 27 | -DCMAKE_CXX_COMPILER=clang-cl 28 | -DMPARK_VARIANT_INCLUDE_TESTS="mpark" .. 29 | - cmake --build . --config %CONFIGURATION% 30 | - ctest -V 31 | -------------------------------------------------------------------------------- /libs/variant/.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files 2 | *.slo 3 | *.lo 4 | *.o 5 | *.obj 6 | 7 | # Precompiled Headers 8 | *.gch 9 | *.pch 10 | 11 | # Compiled Dynamic libraries 12 | *.so 13 | *.dylib 14 | *.dll 15 | 16 | # Fortran module files 17 | *.mod 18 | 19 | # Compiled Static libraries 20 | *.lai 21 | *.la 22 | *.a 23 | *.lib 24 | 25 | # Executables 26 | *.exe 27 | *.out 28 | *.app 29 | 30 | # build 31 | /build 32 | -------------------------------------------------------------------------------- /libs/variant/.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "3rdparty/googletest"] 2 | path = 3rdparty/googletest 3 | url = https://github.com/google/googletest.git 4 | -------------------------------------------------------------------------------- /libs/variant/.travis.yml: -------------------------------------------------------------------------------- 1 | language: cpp 2 | 3 | git: 4 | depth: 1 5 | 6 | matrix: 7 | include: 8 | # ubuntu 14.04, gcc-5, debug 9 | - env: VERSION=5 BUILD_TYPE=Debug 10 | compiler: gcc 11 | os: linux 12 | dist: trusty 13 | sudo: required 14 | addons: &gcc5 15 | apt: 16 | packages: 17 | - g++-5 18 | sources: 19 | - ubuntu-toolchain-r-test 20 | # ubuntu 14.04, gcc-5, release 21 | - env: VERSION=5 BUILD_TYPE=Release 22 | compiler: gcc 23 | os: linux 24 | dist: trusty 25 | sudo: required 26 | addons: *gcc5 27 | # ubuntu 14.04, gcc-6, debug 28 | - env: VERSION=6 BUILD_TYPE=Debug 29 | compiler: gcc 30 | os: linux 31 | dist: trusty 32 | sudo: required 33 | addons: &gcc6 34 | apt: 35 | packages: 36 | - g++-6 37 | sources: 38 | - ubuntu-toolchain-r-test 39 | # ubuntu 14.04, gcc-6, release 40 | - env: VERSION=6 BUILD_TYPE=Release 41 | compiler: gcc 42 | os: linux 43 | dist: trusty 44 | sudo: required 45 | addons: *gcc6 46 | # ubuntu 14.04, clang-3.5, debug 47 | - env: VERSION=3.5 BUILD_TYPE=Debug 48 | compiler: clang 49 | os: linux 50 | dist: trusty 51 | sudo: required 52 | addons: &libcxx 53 | apt: 54 | packages: 55 | - libc++-dev 56 | # ubuntu 14.04, clang-3.5, release 57 | - env: VERSION=3.5 BUILD_TYPE=Release 58 | compiler: clang 59 | os: linux 60 | dist: trusty 61 | sudo: required 62 | addons: *libcxx 63 | # ubuntu 14.04, clang-3.6, debug 64 | - env: VERSION=3.6 BUILD_TYPE=Debug 65 | compiler: clang 66 | os: linux 67 | dist: trusty 68 | sudo: required 69 | addons: *libcxx 70 | # ubuntu 14.04, clang-3.6, release 71 | - env: VERSION=3.6 BUILD_TYPE=Release 72 | compiler: clang 73 | os: linux 74 | dist: trusty 75 | sudo: required 76 | addons: *libcxx 77 | # ubuntu 14.04, clang-3.7, debug 78 | - env: VERSION=3.7 BUILD_TYPE=Debug 79 | compiler: clang 80 | os: linux 81 | dist: trusty 82 | sudo: required 83 | addons: *libcxx 84 | # ubuntu 14.04, clang-3.7, release 85 | - env: VERSION=3.7 BUILD_TYPE=Release 86 | compiler: clang 87 | os: linux 88 | dist: trusty 89 | sudo: required 90 | addons: *libcxx 91 | # ubuntu 14.04, clang-3.8, debug 92 | - env: VERSION=3.8 BUILD_TYPE=Debug 93 | compiler: clang 94 | os: linux 95 | dist: trusty 96 | sudo: required 97 | addons: *libcxx 98 | # ubuntu 14.04, clang-3.8, release 99 | - env: VERSION=3.8 BUILD_TYPE=Release 100 | compiler: clang 101 | os: linux 102 | dist: trusty 103 | sudo: required 104 | addons: *libcxx 105 | # ubuntu 14.04, clang-3.9, debug 106 | - env: VERSION=3.9 BUILD_TYPE=Debug 107 | compiler: clang 108 | os: linux 109 | dist: trusty 110 | sudo: required 111 | addons: *libcxx 112 | # ubuntu 14.04, clang-3.9, release 113 | - env: VERSION=3.9 BUILD_TYPE=Release 114 | compiler: clang 115 | os: linux 116 | dist: trusty 117 | sudo: required 118 | addons: *libcxx 119 | # OS X Yosemite 10.10, Apple Clang, debug 120 | - env: BUILD_TYPE=Debug 121 | compiler: clang 122 | os: osx 123 | osx_image: xcode6.4 124 | # OS X Yosemite 10.10, Apple Clang, release 125 | - env: BUILD_TYPE=Release 126 | compiler: clang 127 | os: osx 128 | osx_image: xcode6.4 129 | # OS X El Capitan 10.11, Apple Clang, debug 130 | - env: BUILD_TYPE=Debug 131 | compiler: clang 132 | os: osx 133 | osx_image: xcode7.3 134 | # OS X El Capitan 10.11, apple-clang-8, release 135 | - env: BUILD_TYPE=Release 136 | compiler: clang 137 | os: osx 138 | osx_image: xcode7.3 139 | # OS X Sierra 10.12, apple-clang-8, debug 140 | - env: BUILD_TYPE=Debug 141 | compiler: clang 142 | os: osx 143 | osx_image: xcode8.2 144 | # OS X Sierra 10.12, apple-clang-8, release 145 | - env: BUILD_TYPE=Release 146 | compiler: clang 147 | os: osx 148 | osx_image: xcode8.2 149 | 150 | before_install: 151 | # Install the newest `cmake`. 152 | - if [ "${TRAVIS_OS_NAME}" = "osx" ]; then 153 | brew update; 154 | brew uninstall cmake; 155 | brew install cmake; 156 | elif [ "${TRAVIS_OS_NAME}" = "linux" ]; then 157 | wget https://cmake.org/files/v3.7/cmake-3.7.1-Linux-x86_64.sh; 158 | chmod u+x cmake-3.7.1-Linux-x86_64.sh; 159 | sudo ./cmake-3.7.1-Linux-x86_64.sh --skip-license --prefix=/usr/local; 160 | fi 161 | # Install a specific clang version. 162 | - if [ "${TRAVIS_OS_NAME}" = "linux" ] && [ "${CC}" = "clang" ] && [ -n "${VERSION}" ]; then 163 | wget -nv -O - http://llvm.org/apt/llvm-snapshot.gpg.key | sudo apt-key add -; 164 | sudo apt-add-repository -y "deb http://llvm.org/apt/trusty llvm-toolchain-trusty-${VERSION} main"; 165 | sudo apt-get update -qq; 166 | sudo apt-get install -qq -y "clang-${VERSION}"; 167 | fi 168 | # Set the correct `CXXFLAGS` environment variable. 169 | - if [ "${TRAVIS_OS_NAME}" = "linux" ] && [ "${CC}" = "clang" ]; then 170 | export CXXFLAGS="${CXXFLAGS} -stdlib=libc++"; 171 | fi 172 | # Set the correct `CC` and `CXX` environment variables. 173 | - if [ -n "${VERSION}" ]; then 174 | export CC="${CC}-${VERSION}"; 175 | export CXX="${CXX}-${VERSION}"; 176 | fi 177 | - ${CXX} --version 178 | 179 | install: 180 | - mkdir build 181 | - cd build 182 | - cmake -DCMAKE_BUILD_TYPE=${BUILD_TYPE} 183 | -DMPARK_VARIANT_INCLUDE_TESTS="mpark;libc++" .. 184 | - cmake --build . 185 | 186 | script: 187 | - ctest -V 188 | 189 | notifications: 190 | email: false 191 | -------------------------------------------------------------------------------- /libs/variant/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # MPark.Variant 2 | # 3 | # Copyright Michael Park, 2015-2017 4 | # 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # (See accompanying file LICENSE_1_0.txt or copy at 7 | # http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | cmake_minimum_required(VERSION 3.6.3) 10 | 11 | project(MPark.Variant VERSION 1.0.0 LANGUAGES CXX) 12 | 13 | # Option. 14 | set(MPARK_VARIANT_INCLUDE_TESTS 15 | "" CACHE STRING 16 | "Semicolon-separated list of tests to build. \ 17 | Possible values are `mpark` and `libc++`.") 18 | 19 | # Target. 20 | add_library(mpark_variant INTERFACE) 21 | target_include_directories(mpark_variant INTERFACE 22 | $ 23 | $) 24 | 25 | # Config. 26 | include(CMakePackageConfigHelpers) 27 | 28 | configure_package_config_file( 29 | cmake/mpark_variant-config.cmake.in 30 | "${CMAKE_CURRENT_BINARY_DIR}/cmake/mpark_variant-config.cmake" 31 | INSTALL_DESTINATION lib/cmake/mpark_variant 32 | NO_CHECK_REQUIRED_COMPONENTS_MACRO) 33 | 34 | write_basic_package_version_file( 35 | "${CMAKE_CURRENT_BINARY_DIR}/cmake/mpark_variant-config-version.cmake" 36 | COMPATIBILITY AnyNewerVersion) 37 | 38 | # Export. 39 | export( 40 | TARGETS mpark_variant 41 | FILE "${CMAKE_CURRENT_BINARY_DIR}/cmake/mpark_variant-targets.cmake") 42 | 43 | # Install. 44 | install(TARGETS mpark_variant EXPORT mpark_variant) 45 | 46 | install( 47 | EXPORT mpark_variant 48 | FILE mpark_variant-targets.cmake 49 | DESTINATION lib/cmake/mpark_variant) 50 | 51 | install(DIRECTORY include/mpark DESTINATION include) 52 | 53 | install( 54 | FILES 55 | "${CMAKE_CURRENT_BINARY_DIR}/cmake/mpark_variant-config.cmake" 56 | "${CMAKE_CURRENT_BINARY_DIR}/cmake/mpark_variant-config-version.cmake" 57 | DESTINATION lib/cmake/mpark_variant) 58 | 59 | # Test. 60 | list(REMOVE_DUPLICATES MPARK_VARIANT_INCLUDE_TESTS) 61 | 62 | list(FIND MPARK_VARIANT_INCLUDE_TESTS "mpark" MPARK_VARIANT_INDEX) 63 | if(NOT MPARK_VARIANT_INDEX EQUAL -1) 64 | set(MPARK_VARIANT_INCLUDE_MPARK_TESTS ON) 65 | list(REMOVE_AT MPARK_VARIANT_INCLUDE_TESTS MPARK_VARIANT_INDEX) 66 | endif() 67 | 68 | list(FIND MPARK_VARIANT_INCLUDE_TESTS "libc++" MPARK_VARIANT_INDEX) 69 | if(NOT MPARK_VARIANT_INDEX EQUAL -1) 70 | set(MPARK_VARIANT_INCLUDE_LIBCXX_TESTS ON) 71 | list(REMOVE_AT MPARK_VARIANT_INCLUDE_TESTS MPARK_VARIANT_INDEX) 72 | endif() 73 | 74 | list(LENGTH MPARK_VARIANT_INCLUDE_TESTS MPARK_VARIANT_LENGTH) 75 | if(MPARK_VARIANT_LENGTH GREATER 0) 76 | message(FATAL_ERROR 77 | "The following values in `MPARK_VARIANT_INCLUDE_TESTS` are not one of " 78 | "the possible values, `mpark` and `libc++`: ${MPARK_VARIANT_INCLUDE_TESTS}") 79 | endif() 80 | 81 | if(MPARK_VARIANT_INCLUDE_MPARK_TESTS) 82 | if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" AND 83 | "${CMAKE_CXX_SIMULATE_ID}" STREQUAL "MSVC") 84 | add_compile_options(-Qunused-arguments) 85 | add_compile_options(-Wno-deprecated-declarations) 86 | add_compile_options(-Wno-unknown-argument) 87 | endif() 88 | 89 | add_subdirectory(3rdparty/googletest/googletest) 90 | config_compiler_and_linker() 91 | endif() 92 | 93 | if(MPARK_VARIANT_INCLUDE_MPARK_TESTS OR MPARK_VARIANT_INCLUDE_LIBCXX_TESTS) 94 | enable_testing() 95 | add_subdirectory(test) 96 | endif() 97 | -------------------------------------------------------------------------------- /libs/variant/LICENSE_1_0.txt: -------------------------------------------------------------------------------- 1 | Boost Software License - Version 1.0 - August 17th, 2003 2 | 3 | Permission is hereby granted, free of charge, to any person or organization 4 | obtaining a copy of the software and accompanying documentation covered by 5 | this license (the "Software") to use, reproduce, display, distribute, 6 | execute, and transmit the Software, and to prepare derivative works of the 7 | Software, and to permit third-parties to whom the Software is furnished to 8 | do so, all subject to the following: 9 | 10 | The copyright notices in the Software and this entire statement, including 11 | the above license grant, this restriction and the following disclaimer, 12 | must be included in all copies of the Software, in whole or in part, and 13 | all derivative works of the Software, unless such copies or derivative 14 | works are solely in the form of machine-executable object code generated by 15 | a source language processor. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT 20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE 21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, 22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | DEALINGS IN THE SOFTWARE. 24 | -------------------------------------------------------------------------------- /libs/variant/README.md: -------------------------------------------------------------------------------- 1 | # MPark.Variant 2 | 3 | > __C++17__ `std::variant` as a standalone __C++14__ library. 4 | 5 | [![stability][badge.stability]][stability] 6 | [![travis][badge.travis]][travis] 7 | [![appveyor][badge.appveyor]][appveyor] 8 | [![license][badge.license]][license] 9 | [![gitter][badge.gitter]][gitter] 10 | [![wandbox][badge.wandbox]][wandbox] 11 | 12 | [badge.stability]: https://img.shields.io/badge/stability-stable-brightgreen.svg 13 | [badge.travis]: https://travis-ci.org/mpark/variant.svg?branch=master 14 | [badge.appveyor]: https://ci.appveyor.com/api/projects/status/github/mpark/variant?branch=master&svg=true 15 | [badge.license]: http://img.shields.io/badge/license-boost-blue.svg 16 | [badge.gitter]: https://badges.gitter.im/mpark/variant.svg 17 | [badge.wandbox]: https://img.shields.io/badge/try%20it-on%20wandbox-green.svg 18 | 19 | [stability]: http://github.com/badges/stability-badges 20 | [travis]: https://travis-ci.org/mpark/variant 21 | [appveyor]: https://ci.appveyor.com/project/mpark/variant 22 | [license]: https://github.com/mpark/variant/blob/master/LICENSE_1_0.txt 23 | [gitter]: https://gitter.im/mpark/variant 24 | [wandbox]: https://wandbox.org/permlink/b4NDy4VupqPWkjva 25 | 26 | ## Introduction 27 | 28 | __MPark.Variant__ provides an implementation of __C++17__ `std::variant` as a standalone __C++14__ library. 29 | 30 | The implementation is based on my [implementation of `std::variant` for __libc++__][libcxx-impl] 31 | and is continously tested against __libc++__ `std::variant` test suite. 32 | 33 | ## Documentation 34 | 35 | Refer to [`std::variant` - cppreference.com][cppreference] for the `std::variant` 36 | components of __MPark.Variant__. 37 | 38 | [cppreference]: http://en.cppreference.com/w/cpp/utility/variant 39 | 40 | ## CMake Variables 41 | 42 | - __`MPARK_VARIANT_INCLUDE_TESTS`__:`STRING` (__default__: `""`) 43 | 44 | Semicolon-separated list of tests to build. Possible values are `mpark` and `libc++`. 45 | 46 | __NOTE__: The __libc++__ `std::variant` tests are built with `-std=c++1z`. 47 | 48 | ## Requirements 49 | 50 | This library requires a standard conformant __C++14__ compiler. 51 | The following compilers are continously tested: 52 | 53 | | Compiler | Operating System | Version String | 54 | |------------------------------------|---------------------------------------------|-----------------------------------------------------------------------------------------| 55 | | GCC 5.4.1 | Ubuntu 14.04.5 LTS | g++-5 (Ubuntu 5.4.1-2ubuntu1~14.04) 5.4.1 20160904 | 56 | | GCC 6.2.0 | Ubuntu 14.04.5 LTS | g++-6 (Ubuntu 6.2.0-3ubuntu11~14.04) 6.2.0 20160901 | 57 | | Clang 3.5.2 | Ubuntu 14.04.5 LTS | Ubuntu clang version 3.5.2-svn232544-1~exp1 (branches/release_35) (based on LLVM 3.5.2) | 58 | | Clang 3.6.2 | Ubuntu 14.04.5 LTS | Ubuntu clang version 3.6.2-svn240577-1~exp1 (branches/release_36) (based on LLVM 3.6.2) | 59 | | Clang 3.7.1 | Ubuntu 14.04.5 LTS | Ubuntu clang version 3.7.1-svn253742-1~exp1 (branches/release_37) (based on LLVM 3.7.1) | 60 | | Clang 3.8.0 | Ubuntu 14.04.5 LTS | clang version 3.8.0-2ubuntu3~trusty4 (tags/RELEASE_380/final) | 61 | | Clang 3.9.1 | Ubuntu 14.04.5 LTS | clang version 3.9.1-svn288847-1~exp1 (branches/release_39) | 62 | | Clang Xcode 6.4 | Darwin Kernel Version 14.5.0 (OS X 10.10.3) | Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn) | 63 | | Clang Xcode 7.3 | Darwin Kernel Version 15.6.0 (OS X 10.10.5) | Apple LLVM version 7.3.0 (clang-703.0.31) | 64 | | Clang Xcode 8.2 | Darwin Kernel Version 16.1.0 (OS X 10.12.1) | Apple LLVM version 8.0.0 (clang-800.0.42.1) | 65 | | Visual Studio 14 2015 (Clang/LLVM) | Visual Studio Community 2015 with Update 3 | Microsoft (R) Build Engine version 14.0.25420.1 | 66 | 67 | __NOTE__: Enabling __libc++__ `std::variant` tests require `-std=c++1z` support. 68 | 69 | ## Unit Tests 70 | 71 | Refer to [test/README.md](test/README.md). 72 | 73 | [libcxx-impl]: https://reviews.llvm.org/rL288547 74 | -------------------------------------------------------------------------------- /libs/variant/cmake/mpark_variant-config.cmake.in: -------------------------------------------------------------------------------- 1 | # MPark.Variant 2 | # 3 | # Copyright Michael Park, 2015-2017 4 | # 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # (See accompanying file LICENSE_1_0.txt or copy at 7 | # http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | # Config file for MPark.Variant 10 | # 11 | # `MPARK_VARIANT_INCLUDE_DIRS` - include directories 12 | # `MPARK_VARIANT_LIBRARIES` - libraries to link against 13 | # 14 | # The following `IMPORTED` target is also defined: 15 | # 16 | # `mpark_variant` 17 | 18 | @PACKAGE_INIT@ 19 | 20 | include("${CMAKE_CURRENT_LIST_DIR}/mpark_variant-targets.cmake") 21 | 22 | get_target_property( 23 | MPARK_VARIANT_INCLUDE_DIRS 24 | mpark_variant INTERFACE_INCLUDE_DIRECTORIES) 25 | 26 | set_and_check(MPARK_VARIANT_INCLUDE_DIRS "${MPARK_VARIANT_INCLUDE_DIRS}") 27 | set(MPARK_VARIANT_LIBRARIES mpark_variant) 28 | -------------------------------------------------------------------------------- /libs/variant/include/mpark/in_place.hpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef MPARK_IN_PLACE_HPP 10 | #define MPARK_IN_PLACE_HPP 11 | 12 | #include 13 | 14 | namespace mpark { 15 | 16 | struct in_place_t { 17 | explicit in_place_t() = default; 18 | }; 19 | 20 | constexpr in_place_t in_place{}; 21 | 22 | template 23 | struct in_place_index_t { 24 | explicit in_place_index_t() = default; 25 | }; 26 | 27 | template 28 | constexpr in_place_index_t in_place_index{}; 29 | 30 | template 31 | struct in_place_type_t { 32 | explicit in_place_type_t() = default; 33 | }; 34 | 35 | template 36 | constexpr in_place_type_t in_place_type{}; 37 | 38 | } // namespace mpark 39 | 40 | #endif // MPARK_IN_PLACE_HPP 41 | -------------------------------------------------------------------------------- /libs/variant/include/mpark/variants/config.hpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #ifndef MPARK_VARIANTS_CONFIG_HPP 10 | #define MPARK_VARIANTS_CONFIG_HPP 11 | 12 | #ifndef __has_builtin 13 | #define __has_builtin(x) 0 14 | #endif 15 | 16 | #if __has_builtin(__builtin_addressof) || __GNUC__ >= 7 17 | #define MPARK_BUILTIN_ADDRESSOF 18 | #endif 19 | 20 | #if __has_builtin(__type_pack_element) 21 | #define MPARK_TYPE_PACK_ELEMENT 22 | #endif 23 | 24 | #endif // MPARK_VARIANTS_CONFIG_HPP 25 | -------------------------------------------------------------------------------- /libs/variant/test/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # MPark.Variant 2 | # 3 | # Copyright Michael Park, 2015-2017 4 | # 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # (See accompanying file LICENSE_1_0.txt or copy at 7 | # http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | cmake_minimum_required(VERSION 3.6.3) 10 | 11 | set(CMAKE_CXX_STANDARD 14) 12 | set(CMAKE_CXX_STANDARD_REQUIRED ON) 13 | set(CMAKE_CXX_EXTENSIONS OFF) 14 | 15 | if(MPARK_VARIANT_INCLUDE_MPARK_TESTS) 16 | 17 | function(add_gtest name) 18 | add_executable(${name} ${name}.cpp) 19 | set_target_properties(${name} PROPERTIES COMPILE_FLAGS "${cxx_strict}") 20 | target_link_libraries(${name} gtest_main mpark_variant) 21 | add_test(${name} ${name} --gtest_color=yes) 22 | endfunction(add_gtest) 23 | 24 | add_gtest(access.get) 25 | add_gtest(access.get_if) 26 | add_gtest(access.holds_alternative) 27 | add_gtest(assign.copy) 28 | add_gtest(assign.conversion) 29 | add_gtest(assign.emplace) 30 | add_gtest(assign.move) 31 | add_gtest(cnstr.copy) 32 | add_gtest(cnstr.conversion) 33 | add_gtest(cnstr.default) 34 | add_gtest(cnstr.in_place) 35 | add_gtest(cnstr.move) 36 | add_gtest(dtor) 37 | add_gtest(hash) 38 | add_gtest(intro) 39 | add_gtest(rel) 40 | add_gtest(swap) 41 | add_gtest(visit) 42 | 43 | endif() 44 | 45 | if(MPARK_VARIANT_INCLUDE_LIBCXX_TESTS) 46 | 47 | include(ExternalProject) 48 | 49 | set(MPARK_VARIANT_LLVM_SOURCE_DIR ${CMAKE_CURRENT_BINARY_DIR}/llvm) 50 | set(MPARK_VARIANT_LLVM_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR}/llvm-build) 51 | 52 | ExternalProject_Add(llvm 53 | GIT_REPOSITORY http://llvm.org/git/llvm.git 54 | GIT_SHALLOW 1 55 | CMAKE_ARGS "-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}" 56 | "-DCMAKE_CXX_FLAGS=${CMAKE_CXX_FLAGS}" 57 | SOURCE_DIR ${MPARK_VARIANT_LLVM_SOURCE_DIR} 58 | BINARY_DIR ${MPARK_VARIANT_LLVM_BINARY_DIR} 59 | BUILD_COMMAND ${CMAKE_COMMAND} --build . --target cxx 60 | COMMAND ${CMAKE_COMMAND} --build . --target cxxabi 61 | COMMAND ${CMAKE_COMMAND} --build . --target cxx_experimental 62 | INSTALL_COMMAND "" # Disable install step 63 | STEP_TARGETS download 64 | ) 65 | 66 | set(MPARK_VARIANT_LIBCXX_SOURCE_DIR ${MPARK_VARIANT_LLVM_SOURCE_DIR}/projects/libcxx) 67 | set(MPARK_VARIANT_LIBCXX_BINARY_DIR ${MPARK_VARIANT_LLVM_BINARY_DIR}/projects/libcxx) 68 | 69 | ExternalProject_Add(libcxx-download 70 | GIT_REPOSITORY http://llvm.org/git/libcxx.git 71 | GIT_SHALLOW 1 72 | DEPENDS llvm-download 73 | SOURCE_DIR ${MPARK_VARIANT_LIBCXX_SOURCE_DIR} 74 | BINARY_DIR ${MPARK_VARIANT_LIBCXX_BINARY_DIR} 75 | CONFIGURE_COMMAND "" # Disable configure step 76 | BUILD_COMMAND "" # Disable build step 77 | INSTALL_COMMAND "" # Disable install step 78 | ) 79 | 80 | set(MPARK_VARIANT_LIBCXXABI_SOURCE_DIR ${MPARK_VARIANT_LLVM_SOURCE_DIR}/projects/libcxxabi) 81 | set(MPARK_VARIANT_LIBCXXABI_BINARY_DIR ${MPARK_VARIANT_LLVM_BINARY_DIR}/projects/libcxxabi) 82 | 83 | ExternalProject_Add(libcxxabi-download 84 | GIT_REPOSITORY http://llvm.org/git/libcxxabi.git 85 | GIT_SHALLOW 1 86 | DEPENDS llvm-download 87 | SOURCE_DIR ${MPARK_VARIANT_LIBCXXABI_SOURCE_DIR} 88 | BINARY_DIR ${MPARK_VARIANT_LIBCXXABI_BINARY_DIR} 89 | CONFIGURE_COMMAND "" # Disable configure step 90 | BUILD_COMMAND "" # Disable build step 91 | INSTALL_COMMAND "" # Disable install step 92 | ) 93 | 94 | ExternalProject_Add_StepDependencies(llvm configure libcxx-download libcxxabi-download) 95 | 96 | add_test(run_libcxx_tests 97 | ${CMAKE_COMMAND} -E 98 | env MPARK_VARIANT_CXX_COMPILER=${CMAKE_CXX_COMPILER} 99 | env MPARK_VARIANT_SOURCE_DIR=${CMAKE_SOURCE_DIR} 100 | env MPARK_VARIANT_LIBCXX_SOURCE_DIR=${MPARK_VARIANT_LIBCXX_SOURCE_DIR} 101 | env MPARK_VARIANT_LIBCXX_SITE_CONFIG=${MPARK_VARIANT_LIBCXX_BINARY_DIR}/test/lit.site.cfg 102 | env MPARK_VARIANT_LIT=${MPARK_VARIANT_LLVM_BINARY_DIR}/bin/llvm-lit 103 | ${CMAKE_CURRENT_SOURCE_DIR}/run_libcxx_tests.sh 104 | ) 105 | 106 | endif() 107 | -------------------------------------------------------------------------------- /libs/variant/test/README.md: -------------------------------------------------------------------------------- 1 | # MPark.Variant 2 | 3 | > __C++17__ `std::variant` as a standalone __C++14__ library. 4 | 5 | [![stability][badge.stability]][stability] 6 | [![travis][badge.travis]][travis] 7 | [![appveyor][badge.appveyor]][appveyor] 8 | [![license][badge.license]][license] 9 | [![gitter][badge.gitter]][gitter] 10 | [![wandbox][badge.wandbox]][wandbox] 11 | 12 | [badge.stability]: https://img.shields.io/badge/stability-stable-brightgreen.svg 13 | [badge.travis]: https://travis-ci.org/mpark/variant.svg?branch=master 14 | [badge.appveyor]: https://ci.appveyor.com/api/projects/status/github/mpark/variant?branch=master&svg=true 15 | [badge.license]: http://img.shields.io/badge/license-boost-blue.svg 16 | [badge.gitter]: https://badges.gitter.im/mpark/variant.svg 17 | [badge.wandbox]: https://img.shields.io/badge/try%20it-on%20wandbox-green.svg 18 | 19 | [stability]: http://github.com/badges/stability-badges 20 | [travis]: https://travis-ci.org/mpark/variant 21 | [appveyor]: https://ci.appveyor.com/project/mpark/variant 22 | [license]: https://github.com/mpark/variant/blob/master/LICENSE_1_0.txt 23 | [gitter]: https://gitter.im/mpark/variant 24 | [wandbox]: https://wandbox.org/permlink/fHVxfQg3rm4YWIav 25 | 26 | ## Test 27 | 28 | This directory contains the tests for __MPark.Variant__. 29 | 30 | ### Building and Running Tests 31 | 32 | Execute the following commands from the top-level directory: 33 | 34 | ```bash 35 | mkdir build 36 | cd build 37 | cmake -DMPARK_VARIANT_INCLUDE_TESTS="mpark;libc++" .. 38 | cmake --build . 39 | ctest -V 40 | ``` 41 | -------------------------------------------------------------------------------- /libs/variant/test/access.get.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | enum Qual { Ptr, ConstPtr, LRef, ConstLRef, RRef, ConstRRef }; 14 | 15 | constexpr Qual get_qual(int *) { return Ptr; } 16 | constexpr Qual get_qual(const int *) { return ConstPtr; } 17 | constexpr Qual get_qual(int &) { return LRef; } 18 | constexpr Qual get_qual(const int &) { return ConstLRef; } 19 | constexpr Qual get_qual(int &&) { return RRef; } 20 | constexpr Qual get_qual(const int &&) { return ConstRRef; } 21 | 22 | TEST(Access_Get, MutVarMutType) { 23 | mpark::variant v(42); 24 | EXPECT_EQ(42, mpark::get(v)); 25 | // Check qualifier. 26 | EXPECT_EQ(LRef, get_qual(mpark::get(v))); 27 | EXPECT_EQ(RRef, get_qual(mpark::get(std::move(v)))); 28 | } 29 | 30 | #if 0 31 | TEST(Access_Get, MutVarMutTypeRef) { 32 | int expected = 42; 33 | mpark::variant v(expected); 34 | EXPECT_EQ(expected, mpark::get(v)); 35 | EXPECT_EQ(&expected, &mpark::get(v)); 36 | // Check qualifier. 37 | EXPECT_EQ(LRef, get_qual(mpark::get(v))); 38 | EXPECT_EQ(LRef, get_qual(mpark::get(std::move(v)))); 39 | } 40 | #endif 41 | 42 | TEST(Access_Get, MutVarConstType) { 43 | mpark::variant v(42); 44 | EXPECT_EQ(42, mpark::get(v)); 45 | // Check qualifier. 46 | EXPECT_EQ(ConstLRef, get_qual(mpark::get(v))); 47 | EXPECT_EQ(ConstRRef, get_qual(mpark::get(std::move(v)))); 48 | } 49 | 50 | #if 0 51 | TEST(Access_Get, MutVarConstTypeRef) { 52 | int expected = 42; 53 | mpark::variant v(expected); 54 | EXPECT_EQ(expected, mpark::get(v)); 55 | EXPECT_EQ(&expected, &mpark::get(v)); 56 | // Check qualifier. 57 | EXPECT_EQ(ConstLRef, get_qual(mpark::get(v))); 58 | EXPECT_EQ(ConstLRef, get_qual(mpark::get(std::move(v)))); 59 | } 60 | #endif 61 | 62 | TEST(Access_Get, ConstVarMutType) { 63 | const mpark::variant v(42); 64 | EXPECT_EQ(42, mpark::get(v)); 65 | // Check qualifier. 66 | EXPECT_EQ(ConstLRef, get_qual(mpark::get(v))); 67 | EXPECT_EQ(ConstRRef, get_qual(mpark::get(std::move(v)))); 68 | 69 | /* constexpr */ { 70 | constexpr mpark::variant cv(42); 71 | static_assert(42 == mpark::get(cv), ""); 72 | // Check qualifier. 73 | static_assert(ConstLRef == get_qual(mpark::get(cv)), ""); 74 | static_assert(ConstRRef == get_qual(mpark::get(std::move(cv))), ""); 75 | } 76 | } 77 | 78 | #if 0 79 | TEST(Access_Get, ConstVarMutTypeRef) { 80 | int expected = 42; 81 | const mpark::variant v(expected); 82 | EXPECT_EQ(expected, mpark::get(v)); 83 | EXPECT_EQ(&expected, &mpark::get(v)); 84 | // Check qualifier. 85 | EXPECT_EQ(LRef, get_qual(mpark::get(v))); 86 | EXPECT_EQ(LRef, get_qual(mpark::get(std::move(v)))); 87 | } 88 | #endif 89 | 90 | TEST(Access_Get, ConstVarConstType) { 91 | const mpark::variant v(42); 92 | EXPECT_EQ(42, mpark::get(v)); 93 | // Check qualifier. 94 | EXPECT_EQ(ConstLRef, get_qual(mpark::get(v))); 95 | EXPECT_EQ(ConstRRef, get_qual(mpark::get(std::move(v)))); 96 | 97 | /* constexpr */ { 98 | constexpr mpark::variant cv(42); 99 | static_assert(42 == mpark::get(cv), ""); 100 | // Check qualifier. 101 | static_assert(ConstLRef == get_qual(mpark::get(cv)), ""); 102 | static_assert(ConstRRef == get_qual(mpark::get(std::move(cv))), ""); 103 | } 104 | } 105 | 106 | #if 0 107 | TEST(Access_Get, ConstVarConstTypeRef) { 108 | int expected = 42; 109 | const mpark::variant v(expected); 110 | EXPECT_EQ(expected, mpark::get(v)); 111 | EXPECT_EQ(&expected, &mpark::get(v)); 112 | // Check qualifier. 113 | EXPECT_EQ(ConstLRef, get_qual(mpark::get(v))); 114 | EXPECT_EQ(ConstLRef, get_qual(mpark::get(std::move(v)))); 115 | 116 | /* constexpr */ { 117 | static constexpr int expected = 42; 118 | constexpr mpark::variant cv(expected); 119 | static_assert(42 == mpark::get(cv), ""); 120 | // Check qualifier. 121 | static_assert(ConstLRef == get_qual(mpark::get(cv)), ""); 122 | static_assert(ConstLRef == get_qual(mpark::get(std::move(cv))), ""); 123 | } 124 | } 125 | #endif 126 | 127 | TEST(Access_Get, ValuelessByException) { 128 | struct move_thrower_t { 129 | move_thrower_t() = default; 130 | move_thrower_t(const move_thrower_t &) = default; 131 | [[noreturn]] move_thrower_t(move_thrower_t &&) { 132 | throw std::runtime_error(""); 133 | } 134 | move_thrower_t &operator=(const move_thrower_t &) = default; 135 | move_thrower_t &operator=(move_thrower_t &&) = default; 136 | }; // move_thrower_t 137 | mpark::variant v(42); 138 | EXPECT_THROW(v = move_thrower_t{}, std::runtime_error); 139 | EXPECT_TRUE(v.valueless_by_exception()); 140 | EXPECT_THROW(mpark::get(v), mpark::bad_variant_access); 141 | EXPECT_THROW(mpark::get(v), mpark::bad_variant_access); 142 | } 143 | -------------------------------------------------------------------------------- /libs/variant/test/access.get_if.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | enum Qual { Ptr, ConstPtr, LRef, ConstLRef, RRef, ConstRRef }; 14 | 15 | constexpr Qual get_qual(int *) { return Ptr; } 16 | constexpr Qual get_qual(const int *) { return ConstPtr; } 17 | constexpr Qual get_qual(int &) { return LRef; } 18 | constexpr Qual get_qual(const int &) { return ConstLRef; } 19 | constexpr Qual get_qual(int &&) { return RRef; } 20 | constexpr Qual get_qual(const int &&) { return ConstRRef; } 21 | 22 | TEST(Access_GetIf, MutVarMutType) { 23 | mpark::variant v(42); 24 | EXPECT_EQ(42, *mpark::get_if(&v)); 25 | // Check qualifier. 26 | EXPECT_EQ(Ptr, get_qual(mpark::get_if(&v))); 27 | } 28 | 29 | #if 0 30 | TEST(Access_GetIf, MutVarMutTypeRef) { 31 | int expected = 42; 32 | mpark::variant v(expected); 33 | EXPECT_EQ(expected, *mpark::get_if(&v)); 34 | EXPECT_EQ(&expected, mpark::get_if(&v)); 35 | // Check qualifier. 36 | EXPECT_EQ(Ptr, get_qual(mpark::get_if(&v))); 37 | } 38 | #endif 39 | 40 | TEST(Access_GetIf, MutVarConstType) { 41 | mpark::variant v(42); 42 | EXPECT_EQ(42, *mpark::get_if(&v)); 43 | // Check qualifier. 44 | EXPECT_EQ(ConstPtr, get_qual(mpark::get_if(&v))); 45 | } 46 | 47 | #if 0 48 | TEST(Access_GetIf, MutVarConstTypeRef) { 49 | int expected = 42; 50 | mpark::variant v(expected); 51 | EXPECT_EQ(expected, *mpark::get_if(&v)); 52 | EXPECT_EQ(&expected, mpark::get_if(&v)); 53 | // Check qualifier. 54 | EXPECT_EQ(ConstPtr, get_qual(mpark::get_if(&v))); 55 | } 56 | #endif 57 | 58 | TEST(Access_GetIf, ConstVarMutType) { 59 | const mpark::variant v(42); 60 | EXPECT_EQ(42, *mpark::get_if(&v)); 61 | // Check qualifier. 62 | EXPECT_EQ(ConstPtr, get_qual(mpark::get_if(&v))); 63 | 64 | /* constexpr */ { 65 | constexpr mpark::variant cv(42); 66 | static_assert(42 == *mpark::get_if(&cv), ""); 67 | // Check qualifier. 68 | static_assert(ConstPtr == get_qual(mpark::get_if(&cv)), ""); 69 | } 70 | } 71 | 72 | #if 0 73 | TEST(Access_GetIf, ConstVarMutTypeRef) { 74 | int expected = 42; 75 | const mpark::variant v(expected); 76 | EXPECT_EQ(expected, *mpark::get_if(&v)); 77 | EXPECT_EQ(&expected, mpark::get_if(&v)); 78 | // Check qualifier. 79 | EXPECT_EQ(Ptr, get_qual(mpark::get_if(&v))); 80 | } 81 | #endif 82 | 83 | TEST(Access_GetIf, ConstVarConstType) { 84 | const mpark::variant v(42); 85 | EXPECT_EQ(42, *mpark::get_if(&v)); 86 | // Check qualifier. 87 | EXPECT_EQ(ConstPtr, get_qual(mpark::get_if(&v))); 88 | 89 | /* constexpr */ { 90 | constexpr mpark::variant cv(42); 91 | static_assert(42 == *mpark::get_if(&cv), ""); 92 | // Check qualifier. 93 | static_assert(ConstPtr == get_qual(mpark::get_if(&cv)), ""); 94 | } 95 | } 96 | 97 | #if 0 98 | TEST(Access_GetIf, ConstVarConstTypeRef) { 99 | int expected = 42; 100 | const mpark::variant v(expected); 101 | EXPECT_EQ(expected, *mpark::get_if(&v)); 102 | EXPECT_EQ(&expected, mpark::get_if(&v)); 103 | // Check qualifier. 104 | EXPECT_EQ(ConstPtr, get_qual(mpark::get_if(&v))); 105 | 106 | /* constexpr */ { 107 | static constexpr int expected = 42; 108 | constexpr mpark::variant cv(expected); 109 | static_assert(42 == *mpark::get_if(&cv), ""); 110 | // Check qualifier. 111 | static_assert(ConstPtr == get_qual(mpark::get_if(&cv)), ""); 112 | } 113 | } 114 | #endif 115 | 116 | TEST(Access_GetIf, MoveValuelessByException) { 117 | struct move_thrower_t { 118 | move_thrower_t() = default; 119 | move_thrower_t(const move_thrower_t &) = default; 120 | [[noreturn]] move_thrower_t(move_thrower_t &&) { 121 | throw std::runtime_error(""); 122 | } 123 | move_thrower_t &operator=(const move_thrower_t &) = default; 124 | move_thrower_t &operator=(move_thrower_t &&) = default; 125 | }; // move_thrower_t 126 | mpark::variant v(42); 127 | EXPECT_THROW(v = move_thrower_t{}, std::runtime_error); 128 | EXPECT_TRUE(v.valueless_by_exception()); 129 | EXPECT_EQ(nullptr, mpark::get_if(&v)); 130 | EXPECT_EQ(nullptr, mpark::get_if(&v)); 131 | } 132 | -------------------------------------------------------------------------------- /libs/variant/test/access.holds_alternative.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | TEST(Access_HoldsAlternative, Typical) { 14 | mpark::variant v(42); 15 | EXPECT_TRUE(mpark::holds_alternative<0>(v)); 16 | EXPECT_FALSE(mpark::holds_alternative<1>(v)); 17 | EXPECT_TRUE(mpark::holds_alternative(v)); 18 | EXPECT_FALSE(mpark::holds_alternative(v)); 19 | 20 | /* constexpr */ { 21 | constexpr mpark::variant cv(42); 22 | static_assert(mpark::holds_alternative<0>(cv), ""); 23 | static_assert(!mpark::holds_alternative<1>(cv), ""); 24 | static_assert(mpark::holds_alternative(cv), ""); 25 | static_assert(!mpark::holds_alternative(cv), ""); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /libs/variant/test/assign.conversion.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | using namespace std::string_literals; 17 | 18 | TEST(Assign_Conversion, SameType) { 19 | mpark::variant v(101); 20 | EXPECT_EQ(101, mpark::get(v)); 21 | v = 202; 22 | EXPECT_EQ(202, mpark::get(v)); 23 | } 24 | 25 | TEST(Assign_Conversion, SameTypeConversion) { 26 | mpark::variant v(1.1); 27 | EXPECT_EQ(1, mpark::get(v)); 28 | v = 2.2; 29 | EXPECT_EQ(2, mpark::get(v)); 30 | } 31 | 32 | TEST(Assign_Conversion, DiffType) { 33 | mpark::variant v(42); 34 | EXPECT_EQ(42, mpark::get(v)); 35 | v = "42"s; 36 | EXPECT_EQ("42"s, mpark::get(v)); 37 | } 38 | 39 | TEST(Assign_Conversion, DiffTypeConversion) { 40 | mpark::variant v(42); 41 | EXPECT_EQ(42, mpark::get(v)); 42 | v = "42"; 43 | EXPECT_EQ("42"s, mpark::get(v)); 44 | } 45 | 46 | TEST(Assign_Conversion, ExactMatch) { 47 | mpark::variant v; 48 | v = "hello"; 49 | EXPECT_EQ("hello", mpark::get(v)); 50 | } 51 | 52 | TEST(Assign_Conversion, BetterMatch) { 53 | mpark::variant v; 54 | // `char` -> `int` is better than `char` -> `double` 55 | v = 'x'; 56 | EXPECT_EQ(static_cast('x'), mpark::get(v)); 57 | } 58 | 59 | TEST(Assign_Conversion, NoMatch) { struct x { }; 60 | static_assert(!std::is_assignable, x>{}, "variant v; v = x;"); 61 | } 62 | 63 | TEST(Assign_Conversion, Ambiguous) { 64 | static_assert(!std::is_assignable, int>{}, "variant v; v = 42;"); 65 | } 66 | 67 | TEST(Assign_Conversion, SameTypeOptimization) { 68 | mpark::variant v("hello world!"s); 69 | // Check `v`. 70 | const std::string &x = mpark::get(v); 71 | EXPECT_EQ("hello world!"s, x); 72 | // Save the "hello world!"'s capacity. 73 | auto capacity = x.capacity(); 74 | // Use `std::string::operator=(const char *)` to assign into `v`. 75 | v = "hello"; 76 | // Check `v`. 77 | const std::string &y = mpark::get(v); 78 | EXPECT_EQ("hello"s, y); 79 | // Since "hello" is shorter than "hello world!", we should have preserved the 80 | // existing capacity of the string!. 81 | EXPECT_EQ(capacity, y.capacity()); 82 | } 83 | 84 | struct CopyConstruction : std::exception {}; 85 | struct CopyAssignment : std::exception {}; 86 | struct MoveConstruction : std::exception {}; 87 | struct MoveAssignment : std::exception {}; 88 | 89 | struct copy_thrower_t { 90 | copy_thrower_t() = default; 91 | [[noreturn]] copy_thrower_t(const copy_thrower_t &) { 92 | throw CopyConstruction{}; 93 | } 94 | copy_thrower_t(copy_thrower_t &&) = default; 95 | copy_thrower_t &operator=(const copy_thrower_t &) { throw CopyAssignment{}; } 96 | copy_thrower_t &operator=(copy_thrower_t &&) = default; 97 | }; // copy_thrower_t 98 | 99 | struct move_thrower_t { 100 | move_thrower_t() = default; 101 | move_thrower_t(const move_thrower_t &) = default; 102 | [[noreturn]] move_thrower_t(move_thrower_t &&) { throw MoveConstruction{}; } 103 | move_thrower_t &operator=(const move_thrower_t &) = default; 104 | move_thrower_t &operator=(move_thrower_t &&) { throw MoveAssignment{}; } 105 | }; // move_thrower_t 106 | 107 | TEST(Assign_Conversion, ThrowOnAssignment) { 108 | mpark::variant v(mpark::in_place_type); 109 | // Since `variant` is already in `move_thrower_t`, assignment optimization 110 | // kicks and we simply invoke 111 | // `move_thrower_t &operator=(move_thrower_t &&);` which throws. 112 | EXPECT_THROW(v = move_thrower_t{}, MoveAssignment); 113 | EXPECT_FALSE(v.valueless_by_exception()); 114 | EXPECT_EQ(1u, v.index()); 115 | // We can still assign into a variant in an invalid state. 116 | v = 42; 117 | // Check `v`. 118 | EXPECT_FALSE(v.valueless_by_exception()); 119 | EXPECT_EQ(42, mpark::get(v)); 120 | } 121 | 122 | #if 0 123 | TEST(Assign_Conversion, ThrowOnTemporaryConstruction) { 124 | mpark::variant v(42); 125 | // Since `copy_thrower_t`'s copy constructor always throws, we will fail to 126 | // construct the variant. This results in our variant staying in 127 | // its original state. 128 | copy_thrower_t copy_thrower{}; 129 | EXPECT_THROW(v = copy_thrower, CopyConstruction); 130 | EXPECT_FALSE(v.valueless_by_exception()); 131 | EXPECT_EQ(0u, v.index()); 132 | EXPECT_EQ(42, mpark::get(v)); 133 | } 134 | 135 | TEST(Assign_Conversion, ThrowOnVariantConstruction) { 136 | mpark::variant v(42); 137 | // Since `move_thrower_t`'s copy constructor never throws, we successfully 138 | // construct the temporary object by copying `move_thrower_t`. We then 139 | // proceed to move the temporary object into our variant, at which point 140 | // `move_thrower_t`'s move constructor throws. This results in our `variant` 141 | // transitioning into the invalid state. 142 | move_thrower_t move_thrower; 143 | EXPECT_THROW(v = move_thrower, MoveConstruction); 144 | EXPECT_TRUE(v.valueless_by_exception()); 145 | // We can still assign into a variant in an invalid state. 146 | v = 42; 147 | // Check `v`. 148 | EXPECT_FALSE(v.valueless_by_exception()); 149 | EXPECT_EQ(42, mpark::get(v)); 150 | } 151 | #endif 152 | -------------------------------------------------------------------------------- /libs/variant/test/assign.copy.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | TEST(Assign_Copy, SameType) { 14 | struct Obj { 15 | Obj() = default; 16 | Obj(const Obj &) noexcept { EXPECT_TRUE(false); } 17 | Obj(Obj &&) = default; 18 | Obj &operator=(const Obj &) noexcept { EXPECT_TRUE(true); return *this; } 19 | Obj &operator=(Obj &&) = delete; 20 | }; 21 | // `v`, `w`. 22 | mpark::variant v, w; 23 | // copy assignment. 24 | v = w; 25 | } 26 | 27 | TEST(Assign_Copy, DiffType) { 28 | struct Obj { 29 | Obj() = default; 30 | Obj(const Obj &) noexcept { EXPECT_TRUE(true); } 31 | Obj(Obj &&) = default; 32 | Obj &operator=(const Obj &) noexcept { EXPECT_TRUE(false); return *this; } 33 | Obj &operator=(Obj &&) = delete; 34 | }; 35 | // `v`, `w`. 36 | mpark::variant v(42), w; 37 | // move assignment. 38 | v = w; 39 | } 40 | 41 | TEST(Assign_Copy, ValuelessByException) { 42 | struct move_thrower_t { 43 | move_thrower_t() = default; 44 | move_thrower_t(const move_thrower_t &) = default; 45 | move_thrower_t(move_thrower_t &&) { throw std::runtime_error(""); } 46 | move_thrower_t &operator=(const move_thrower_t &) = default; 47 | move_thrower_t &operator=(move_thrower_t &&) = default; 48 | }; // move_thrower_t 49 | mpark::variant v(42); 50 | EXPECT_THROW(v = move_thrower_t{}, std::runtime_error); 51 | EXPECT_TRUE(v.valueless_by_exception()); 52 | mpark::variant w(42); 53 | w = v; 54 | EXPECT_TRUE(w.valueless_by_exception()); 55 | } 56 | -------------------------------------------------------------------------------- /libs/variant/test/assign.emplace.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std::string_literals; 16 | 17 | TEST(Assign_Emplace, IndexDirect) { 18 | mpark::variant v; 19 | v.emplace<1>("42"s); 20 | EXPECT_EQ("42"s, mpark::get<1>(v)); 21 | } 22 | 23 | #if 0 24 | TEST(Assign_Emplace, IndexDirectRef) { 25 | int x = 42; 26 | std::ostringstream y; 27 | mpark::variant v(mpark::in_place_index<0>, x); 28 | EXPECT_EQ(&x, &mpark::get<0>(v)); 29 | v.emplace<1>(y); 30 | EXPECT_EQ(&y, &mpark::get<1>(v)); 31 | } 32 | #endif 33 | 34 | TEST(Assign_Emplace, IndexDirectDuplicate) { 35 | mpark::variant v; 36 | v.emplace<1>(42); 37 | EXPECT_EQ(42, mpark::get<1>(v)); 38 | } 39 | 40 | #if 0 41 | TEST(Assign_Emplace, IndexDirectDuplicateRef) { 42 | int x, y; 43 | mpark::variant v(mpark::in_place_index<1>, y); 44 | EXPECT_EQ(&y, &mpark::get<1>(v)); 45 | v.emplace<0>(x); 46 | EXPECT_EQ(&x, &mpark::get<0>(v)); 47 | } 48 | #endif 49 | 50 | TEST(Assign_Emplace, IndexConversion) { 51 | mpark::variant v; 52 | v.emplace<1>("42"); 53 | EXPECT_EQ("42"s, mpark::get<1>(v)); 54 | } 55 | 56 | #if 0 57 | TEST(Assign_Emplace, IndexConversionRef) { 58 | int x = 42; 59 | std::ostringstream y; 60 | mpark::variant v(mpark::in_place_index<0>, x); 61 | EXPECT_EQ(&x, &mpark::get<0>(v)); 62 | v.emplace<1>(y); 63 | EXPECT_EQ(&y, &mpark::get<1>(v)); 64 | } 65 | #endif 66 | 67 | TEST(Assign_Emplace, IndexConversionDuplicate) { 68 | mpark::variant v; 69 | v.emplace<1>(1.1); 70 | EXPECT_EQ(1, mpark::get<1>(v)); 71 | } 72 | 73 | #if 0 74 | TEST(Assign_Emplace, IndexConversionDuplicateRef) { 75 | std::ostringstream x, y; 76 | mpark::variant v(mpark::in_place_index<0>, 77 | x); 78 | EXPECT_EQ(&x, &mpark::get<0>(v)); 79 | v.emplace<1>(y); 80 | EXPECT_EQ(&y, &mpark::get<1>(v)); 81 | } 82 | #endif 83 | 84 | TEST(Assign_Emplace, IndexInitializerList) { 85 | mpark::variant v; 86 | v.emplace<1>({'4', '2'}); 87 | EXPECT_EQ("42"s, mpark::get<1>(v)); 88 | } 89 | 90 | TEST(Assign_Emplace, TypeDirect) { 91 | mpark::variant v; 92 | v.emplace("42"s); 93 | EXPECT_EQ("42"s, mpark::get(v)); 94 | } 95 | 96 | #if 0 97 | TEST(Assign_Emplace, TypeDirectRef) { 98 | int x = 42; 99 | std::ostringstream y; 100 | mpark::variant v(mpark::in_place_type, x); 101 | EXPECT_EQ(&x, &mpark::get(v)); 102 | v.emplace(y); 103 | EXPECT_EQ(&y, &mpark::get(v)); 104 | } 105 | #endif 106 | 107 | TEST(Assign_Emplace, TypeConversion) { 108 | mpark::variant v; 109 | v.emplace(1.1); 110 | EXPECT_EQ(1, mpark::get(v)); 111 | } 112 | 113 | #if 0 114 | TEST(Assign_Emplace, TypeConversionRef) { 115 | int x = 42; 116 | std::ostringstream y; 117 | mpark::variant v(x); 118 | EXPECT_EQ(&x, &mpark::get(v)); 119 | v.emplace(y); 120 | EXPECT_EQ(&y, &mpark::get(v)); 121 | } 122 | #endif 123 | 124 | TEST(Assign_Emplace, TypeInitializerList) { 125 | mpark::variant v; 126 | v.emplace({'4', '2'}); 127 | EXPECT_EQ("42"s, mpark::get(v)); 128 | } 129 | -------------------------------------------------------------------------------- /libs/variant/test/assign.move.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | TEST(Assign_Move, SameType) { 14 | struct Obj { 15 | Obj() = default; 16 | Obj(const Obj &) = delete; 17 | Obj(Obj &&) noexcept { EXPECT_TRUE(false); } 18 | Obj &operator=(const Obj &) = delete; 19 | Obj &operator=(Obj &&) noexcept { EXPECT_TRUE(true); return *this; } 20 | }; 21 | // `v`, `w`. 22 | mpark::variant v, w; 23 | // move assignment. 24 | v = std::move(w); 25 | } 26 | 27 | TEST(Assign_Move, DiffType) { 28 | struct Obj { 29 | Obj() = default; 30 | Obj(const Obj &) = delete; 31 | Obj(Obj &&) noexcept { EXPECT_TRUE(true); } 32 | Obj &operator=(const Obj &) = delete; 33 | Obj &operator=(Obj &&) noexcept { EXPECT_TRUE(false); return *this; } 34 | }; 35 | // `v`, `w`. 36 | mpark::variant v(42), w; 37 | // move assignment. 38 | v = std::move(w); 39 | } 40 | 41 | TEST(Assign_Copy, ValuelessByException) { 42 | struct move_thrower_t { 43 | move_thrower_t() = default; 44 | move_thrower_t(const move_thrower_t &) = default; 45 | [[noreturn]] move_thrower_t(move_thrower_t &&) { 46 | throw std::runtime_error(""); 47 | } 48 | move_thrower_t &operator=(const move_thrower_t &) = default; 49 | move_thrower_t &operator=(move_thrower_t &&) = default; 50 | }; // move_thrower_t 51 | mpark::variant v(42); 52 | EXPECT_THROW(v = move_thrower_t{}, std::runtime_error); 53 | EXPECT_TRUE(v.valueless_by_exception()); 54 | mpark::variant w(42); 55 | w = std::move(v); 56 | EXPECT_TRUE(w.valueless_by_exception()); 57 | } 58 | -------------------------------------------------------------------------------- /libs/variant/test/cnstr.conversion.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std::string_literals; 16 | 17 | TEST(Cnstr_Conversion, Direct) { 18 | mpark::variant v(42); 19 | EXPECT_EQ(42, mpark::get(v)); 20 | 21 | /* constexpr */ { 22 | constexpr mpark::variant cv(42); 23 | static_assert(42 == mpark::get(cv), ""); 24 | } 25 | } 26 | 27 | #if 0 28 | TEST(Cnstr_Conversion, DirectRef) { 29 | int expected = 42; 30 | mpark::variant v(expected); 31 | EXPECT_EQ(expected, mpark::get(v)); 32 | EXPECT_EQ(&expected, &mpark::get(v)); 33 | 34 | /* constexpr */ { 35 | static constexpr int expected = 42; 36 | constexpr mpark::variant cv(expected); 37 | static_assert(expected == mpark::get(cv), ""); 38 | static_assert(&expected == &mpark::get(cv), ""); 39 | } 40 | } 41 | #endif 42 | 43 | TEST(Cnstr_Conversion, DirectConversion) { 44 | mpark::variant v("42"); 45 | EXPECT_EQ("42"s, mpark::get(v)); 46 | 47 | /* constexpr */ { 48 | constexpr mpark::variant cv(1.1); 49 | static_assert(1 == mpark::get(cv), ""); 50 | } 51 | } 52 | 53 | #if 0 54 | TEST(Cnstr_Conversion, DirectConversionRef) { 55 | std::ostringstream strm; 56 | mpark::variant v(strm); 57 | EXPECT_EQ(&strm, &mpark::get(v)); 58 | } 59 | #endif 60 | 61 | TEST(Cnstr_Conversion, CopyInitialization) { 62 | mpark::variant v = 42; 63 | EXPECT_EQ(42, mpark::get(v)); 64 | 65 | /* constexpr */ { 66 | constexpr mpark::variant cv = 42; 67 | static_assert(42 == mpark::get(cv), ""); 68 | } 69 | } 70 | 71 | #if 0 72 | TEST(Cnstr_Conversion, CopyInitializationRef) { 73 | std::string expected = "42"; 74 | mpark::variant v = expected; 75 | EXPECT_EQ(expected, mpark::get(v)); 76 | EXPECT_EQ(&expected, &mpark::get(v)); 77 | } 78 | #endif 79 | 80 | TEST(Cnstr_Conversion, CopyInitializationConversion) { 81 | mpark::variant v = "42"; 82 | EXPECT_EQ("42"s, mpark::get(v)); 83 | 84 | /* constexpr */ { 85 | constexpr mpark::variant cv = 1.1; 86 | static_assert(1 == mpark::get(cv), ""); 87 | } 88 | } 89 | 90 | #if 0 91 | TEST(Cnstr_Conversion, CopyInitializationConversionRef) { 92 | std::ostringstream strm; 93 | mpark::variant v = strm; 94 | EXPECT_EQ(&strm, &mpark::get(v)); 95 | } 96 | #endif 97 | -------------------------------------------------------------------------------- /libs/variant/test/cnstr.copy.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std::string_literals; 16 | 17 | TEST(Cnstr_Copy, Value) { 18 | // `v` 19 | mpark::variant v("hello"s); 20 | EXPECT_EQ("hello"s, mpark::get(v)); 21 | // `w` 22 | mpark::variant w(v); 23 | EXPECT_EQ("hello"s, mpark::get(w)); 24 | // Check `v` 25 | EXPECT_EQ("hello"s, mpark::get(v)); 26 | 27 | /* constexpr */ { 28 | // `cv` 29 | constexpr mpark::variant cv(42); 30 | static_assert(42 == mpark::get(cv), ""); 31 | // `cw` 32 | constexpr mpark::variant cw(cv); 33 | static_assert(42 == mpark::get(cw), ""); 34 | } 35 | } 36 | 37 | #if 0 38 | TEST(Cnstr_Copy, Ref) { 39 | std::string s = "hello"s; 40 | // `v` 41 | mpark::variant v(s); 42 | EXPECT_EQ("hello"s, mpark::get(v)); 43 | EXPECT_EQ(&s, &mpark::get(v)); 44 | // `w` 45 | mpark::variant w(v); 46 | EXPECT_EQ("hello"s, mpark::get(w)); 47 | EXPECT_EQ(&s, &mpark::get(w)); 48 | // Check `v` 49 | EXPECT_EQ("hello"s, mpark::get(v)); 50 | EXPECT_EQ(&s, &mpark::get(v)); 51 | } 52 | #endif 53 | 54 | TEST(Cnstr_Copy, ValuelessByException) { 55 | struct move_thrower_t { 56 | move_thrower_t() = default; 57 | move_thrower_t(const move_thrower_t &) = default; 58 | [[noreturn]] move_thrower_t(move_thrower_t &&) { 59 | throw std::runtime_error(""); 60 | } 61 | move_thrower_t &operator=(const move_thrower_t &) = default; 62 | move_thrower_t &operator=(move_thrower_t &&) = default; 63 | }; // move_thrower_t 64 | mpark::variant v(42); 65 | EXPECT_THROW(v = move_thrower_t{}, std::runtime_error); 66 | EXPECT_TRUE(v.valueless_by_exception()); 67 | mpark::variant w(v); 68 | EXPECT_TRUE(w.valueless_by_exception()); 69 | } 70 | -------------------------------------------------------------------------------- /libs/variant/test/cnstr.default.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | TEST(Cnstr_Default, Variant) { 16 | mpark::variant v; 17 | EXPECT_EQ(0, mpark::get<0>(v)); 18 | 19 | /* constexpr */ { 20 | constexpr mpark::variant cv; 21 | static_assert(0 == mpark::get<0>(cv), ""); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /libs/variant/test/cnstr.in_place.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std::string_literals; 16 | 17 | TEST(Cnstr_InPlace, IndexDirect) { 18 | mpark::variant v(mpark::in_place_index<0>, 42); 19 | EXPECT_EQ(42, mpark::get<0>(v)); 20 | 21 | /* constexpr */ { 22 | constexpr mpark::variant cv(mpark::in_place_index<0>, 23 | 42); 24 | static_assert(42 == mpark::get<0>(cv), ""); 25 | } 26 | } 27 | 28 | TEST(Cnstr_InPlace, IndexDirectDuplicate) { 29 | mpark::variant v(mpark::in_place_index<0>, 42); 30 | EXPECT_EQ(42, mpark::get<0>(v)); 31 | 32 | /* constexpr */ { 33 | constexpr mpark::variant cv(mpark::in_place_index<0>, 42); 34 | static_assert(42 == mpark::get<0>(cv), ""); 35 | } 36 | } 37 | 38 | TEST(Cnstr_InPlace, IndexConversion) { 39 | mpark::variant v(mpark::in_place_index<1>, "42"); 40 | EXPECT_EQ("42"s, mpark::get<1>(v)); 41 | 42 | /* constexpr */ { 43 | constexpr mpark::variant cv(mpark::in_place_index<0>, 44 | 1.1); 45 | static_assert(1 == mpark::get<0>(cv), ""); 46 | } 47 | } 48 | 49 | #if 0 50 | TEST(Cnstr_InPlace, IndexConversionDuplicateRef) { 51 | std::ostringstream strm; 52 | mpark::variant v(mpark::in_place_index<0>, strm); 53 | EXPECT_EQ(&strm, &mpark::get<0>(v)); 54 | } 55 | #endif 56 | 57 | TEST(Cnstr_InPlace, IndexInitializerList) { 58 | mpark::variant v(mpark::in_place_index<1>, {'4', '2'}); 59 | EXPECT_EQ("42"s, mpark::get<1>(v)); 60 | } 61 | 62 | TEST(Cnstr_InPlace, TypeDirect) { 63 | mpark::variant v(mpark::in_place_type, "42"s); 64 | EXPECT_EQ("42"s, mpark::get(v)); 65 | 66 | /* constexpr */ { 67 | constexpr mpark::variant cv(mpark::in_place_type, 68 | 42); 69 | static_assert(42 == mpark::get(cv), ""); 70 | } 71 | } 72 | 73 | #if 0 74 | TEST(Cnstr_InPlace, TypeDirectRef) { 75 | int expected = 42; 76 | mpark::variant v(mpark::in_place_type, expected); 77 | EXPECT_EQ(expected, mpark::get(v)); 78 | EXPECT_EQ(&expected, &mpark::get(v)); 79 | } 80 | #endif 81 | 82 | TEST(Cnstr_InPlace, TypeConversion) { 83 | mpark::variant v(mpark::in_place_type, 42.5); 84 | EXPECT_EQ(42, mpark::get(v)); 85 | 86 | /* constexpr */ { 87 | constexpr mpark::variant cv(mpark::in_place_type, 88 | 42.5); 89 | static_assert(42 == mpark::get(cv), ""); 90 | } 91 | } 92 | 93 | #if 0 94 | TEST(Cnstr_InPlace, TypeConversionRef) { 95 | std::ostringstream strm; 96 | mpark::variant v(mpark::in_place_type, strm); 97 | EXPECT_EQ(&strm, &mpark::get(v)); 98 | } 99 | #endif 100 | 101 | TEST(Cnstr_InPlace, TypeInitializerList) { 102 | mpark::variant v(mpark::in_place_type, {'4', '2'}); 103 | EXPECT_EQ("42"s, mpark::get(v)); 104 | } 105 | -------------------------------------------------------------------------------- /libs/variant/test/cnstr.move.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std::string_literals; 16 | 17 | TEST(Cnstr_Move, Value) { 18 | // `v` 19 | mpark::variant v("hello"s); 20 | EXPECT_EQ("hello"s, mpark::get(v)); 21 | // `w` 22 | mpark::variant w(std::move(v)); 23 | EXPECT_EQ("hello"s, mpark::get(w)); 24 | // Check `v` 25 | EXPECT_TRUE(mpark::get(v).empty()); 26 | 27 | /* constexpr */ { 28 | // `cv` 29 | constexpr mpark::variant cv(42); 30 | static_assert(42 == mpark::get(cv), ""); 31 | // `cw` 32 | constexpr mpark::variant cw(std::move(cv)); 33 | static_assert(42 == mpark::get(cw), ""); 34 | } 35 | } 36 | 37 | #if 0 38 | TEST(Cnstr_Move, Ref) { 39 | std::string s = "hello"s; 40 | // `v` 41 | mpark::variant v(s); 42 | EXPECT_EQ("hello"s, mpark::get(v)); 43 | EXPECT_EQ(&s, &mpark::get(v)); 44 | // `w` 45 | mpark::variant w(std::move(v)); 46 | EXPECT_EQ("hello"s, mpark::get(w)); 47 | EXPECT_EQ(&s, &mpark::get(w)); 48 | // Check `v` 49 | EXPECT_EQ("hello"s, mpark::get(v)); 50 | EXPECT_EQ(&s, &mpark::get(v)); 51 | } 52 | #endif 53 | 54 | TEST(Cnstr_Move, ValuelessByException) { 55 | struct move_thrower_t { 56 | move_thrower_t() = default; 57 | move_thrower_t(const move_thrower_t &) = default; 58 | [[noreturn]] move_thrower_t(move_thrower_t &&) { 59 | throw std::runtime_error(""); 60 | } 61 | move_thrower_t &operator=(const move_thrower_t &) = default; 62 | move_thrower_t &operator=(move_thrower_t &&) = default; 63 | }; // move_thrower_t 64 | mpark::variant v(42); 65 | EXPECT_THROW(v = move_thrower_t{}, std::runtime_error); 66 | EXPECT_TRUE(v.valueless_by_exception()); 67 | mpark::variant w(std::move(v)); 68 | EXPECT_TRUE(w.valueless_by_exception()); 69 | } 70 | -------------------------------------------------------------------------------- /libs/variant/test/dtor.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | struct Obj { 14 | Obj(bool &dtor_called) : dtor_called_(dtor_called) {} 15 | ~Obj() { dtor_called_ = true; } 16 | bool &dtor_called_; 17 | }; // Obj 18 | 19 | TEST(Dtor, Value) { 20 | bool dtor_called = false; 21 | // Construct/Destruct `Obj`. 22 | { 23 | mpark::variant v(mpark::in_place_type, dtor_called); 24 | } 25 | // Check that the destructor was called. 26 | EXPECT_TRUE(dtor_called); 27 | } 28 | -------------------------------------------------------------------------------- /libs/variant/test/hash.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std::string_literals; 16 | 17 | TEST(Hash, Monostate) { 18 | mpark::variant v(mpark::monostate{}); 19 | // Construct hash function objects. 20 | std::hash monostate_hash; 21 | std::hash> variant_hash; 22 | // Check the hash. 23 | EXPECT_NE(monostate_hash(mpark::monostate{}), variant_hash(v)); 24 | } 25 | 26 | TEST(Hash, String) { 27 | mpark::variant v("hello"s); 28 | EXPECT_EQ("hello"s, mpark::get(v)); 29 | // Construct hash function objects. 30 | std::hash string_hash; 31 | std::hash> variant_hash; 32 | // Check the hash. 33 | EXPECT_NE(string_hash("hello"s), variant_hash(v)); 34 | } 35 | -------------------------------------------------------------------------------- /libs/variant/test/intro.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | 14 | #include 15 | 16 | using namespace std::string_literals; 17 | 18 | TEST(Variant, Intro) { 19 | // direct initialization. 20 | mpark::variant v("hello world!"s); 21 | 22 | // direct access via reference. 23 | EXPECT_EQ("hello world!"s, mpark::get(v)); 24 | 25 | // bad access. 26 | EXPECT_THROW(mpark::get(v), mpark::bad_variant_access); 27 | 28 | // copy construction. 29 | mpark::variant w(v); 30 | 31 | // direct access via pointer. 32 | EXPECT_FALSE(mpark::get_if(&w)); 33 | EXPECT_TRUE(mpark::get_if(&w)); 34 | 35 | // diff-type assignment. 36 | v = 42; 37 | 38 | struct unary { 39 | int operator()(int) const { return 0; } 40 | int operator()(const std::string &) const { return 1; } 41 | }; // unary 42 | 43 | // single visitation. 44 | EXPECT_EQ(0, mpark::visit(unary{}, v)); 45 | 46 | // same-type assignment. 47 | w = "hello"s; 48 | 49 | EXPECT_NE(v, w); 50 | 51 | // make `w` equal to `v`. 52 | w = 42; 53 | 54 | EXPECT_EQ(v, w); 55 | 56 | struct binary { 57 | int operator()(int, int) const { return 0; } 58 | int operator()(int, const std::string &) const { return 1; } 59 | int operator()(const std::string &, int) const { return 2; } 60 | int operator()(const std::string &, const std::string &) const { return 3; } 61 | }; // binary 62 | 63 | // binary visitation. 64 | EXPECT_EQ(0, mpark::visit(binary{}, v, w)); 65 | } 66 | -------------------------------------------------------------------------------- /libs/variant/test/run_libcxx_tests.sh: -------------------------------------------------------------------------------- 1 | # MPark.Variant 2 | # 3 | # Copyright Michael Park, 2015-2017 4 | # 5 | # Distributed under the Boost Software License, Version 1.0. 6 | # (See accompanying file LICENSE_1_0.txt or copy at 7 | # http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #!/usr/bin/env bash 10 | 11 | set -e 12 | 13 | trap "cd ${MPARK_VARIANT_LIBCXX_SOURCE_DIR} && git checkout ." EXIT 14 | 15 | cat < ${MPARK_VARIANT_LIBCXX_SOURCE_DIR}/include/variant 16 | #define mpark std 17 | $(grep -v "#include " ${MPARK_VARIANT_SOURCE_DIR}/include/mpark/variant.hpp) 18 | #undef mpark 19 | EOF 20 | 21 | ${MPARK_VARIANT_LIT} \ 22 | -v \ 23 | --param color_diagnostics \ 24 | --param compile_flags=-I${MPARK_VARIANT_SOURCE_DIR}/include \ 25 | --param cxx_under_test=${MPARK_VARIANT_CXX_COMPILER} \ 26 | --param std=c++1z \ 27 | --param libcxx_site_config=${MPARK_VARIANT_LIBCXX_SITE_CONFIG} \ 28 | ${MPARK_VARIANT_LIBCXX_SOURCE_DIR}/test/std/utilities/variant \ 29 | ${MPARK_VARIANT_LIBCXX_SOURCE_DIR}/test/libcxx/utilities/variant 30 | -------------------------------------------------------------------------------- /libs/variant/test/swap.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | 13 | #include 14 | 15 | using namespace std::string_literals; 16 | 17 | TEST(Swap, Same) { 18 | mpark::variant v("hello"s); 19 | mpark::variant w("world"s); 20 | // Check `v`. 21 | EXPECT_EQ("hello"s, mpark::get(v)); 22 | // Check `w`. 23 | EXPECT_EQ("world"s, mpark::get(w)); 24 | // Swap. 25 | using std::swap; 26 | swap(v, w); 27 | // Check `v`. 28 | EXPECT_EQ("world"s, mpark::get(v)); 29 | // Check `w`. 30 | EXPECT_EQ("hello"s, mpark::get(w)); 31 | } 32 | 33 | TEST(Swap, Different) { 34 | mpark::variant v(42); 35 | mpark::variant w("hello"s); 36 | // Check `v`. 37 | EXPECT_EQ(42, mpark::get(v)); 38 | // Check `w`. 39 | EXPECT_EQ("hello"s, mpark::get(w)); 40 | // Swap. 41 | using std::swap; 42 | swap(v, w); 43 | // Check `v`. 44 | EXPECT_EQ("hello"s, mpark::get(v)); 45 | // Check `w`. 46 | EXPECT_EQ(42, mpark::get(w)); 47 | } 48 | 49 | struct move_thrower_t { 50 | move_thrower_t() = default; 51 | move_thrower_t(const move_thrower_t &) = default; 52 | [[noreturn]] move_thrower_t(move_thrower_t &&) { 53 | throw std::runtime_error(""); 54 | } 55 | move_thrower_t &operator=(const move_thrower_t &) = default; 56 | move_thrower_t &operator=(move_thrower_t &&) = default; 57 | }; // move_thrower_t 58 | 59 | TEST(Swap, OneValuelessByException) { 60 | // `v` normal, `w` corrupted. 61 | mpark::variant v(42), w(42); 62 | EXPECT_THROW(w = move_thrower_t{}, std::runtime_error); 63 | EXPECT_EQ(42, mpark::get(v)); 64 | EXPECT_TRUE(w.valueless_by_exception()); 65 | // Swap. 66 | using std::swap; 67 | swap(v, w); 68 | // Check `v`, `w`. 69 | EXPECT_TRUE(v.valueless_by_exception()); 70 | EXPECT_EQ(42, mpark::get(w)); 71 | } 72 | 73 | TEST(Swap, BothValuelessByException) { 74 | // `v`, `w` both corrupted. 75 | mpark::variant v(42); 76 | EXPECT_THROW(v = move_thrower_t{}, std::runtime_error); 77 | mpark::variant w(v); 78 | EXPECT_TRUE(v.valueless_by_exception()); 79 | EXPECT_TRUE(w.valueless_by_exception()); 80 | // Swap. 81 | using std::swap; 82 | swap(v, w); 83 | // Check `v`, `w`. 84 | EXPECT_TRUE(v.valueless_by_exception()); 85 | EXPECT_TRUE(w.valueless_by_exception()); 86 | } 87 | 88 | TEST(Swap, DtorsSame) { 89 | struct Obj { 90 | Obj(size_t *dtor_count) : dtor_count_(dtor_count) {} 91 | Obj(const Obj &) = default; 92 | Obj(Obj &&) = default; 93 | ~Obj() { ++(*dtor_count_); } 94 | Obj &operator=(const Obj &) = default; 95 | Obj &operator=(Obj &&) = default; 96 | size_t *dtor_count_; 97 | }; // Obj 98 | size_t v_count = 0; 99 | size_t w_count = 0; 100 | { 101 | mpark::variant v{&v_count}, w{&w_count}; 102 | using std::swap; 103 | swap(v, w); 104 | // Calls `std::swap(Obj &lhs, Obj &rhs)`, with which we perform: 105 | // ``` 106 | // { 107 | // Obj temp(move(lhs)); 108 | // lhs = move(rhs); 109 | // rhs = move(temp); 110 | // } `++v_count` from `temp::~Obj()`. 111 | // ``` 112 | EXPECT_EQ(1u, v_count); 113 | EXPECT_EQ(0u, w_count); 114 | } 115 | EXPECT_EQ(2u, v_count); 116 | EXPECT_EQ(1u, w_count); 117 | } 118 | 119 | namespace detail { 120 | 121 | struct Obj { 122 | Obj(size_t *dtor_count) : dtor_count_(dtor_count) {} 123 | Obj(const Obj &) = default; 124 | Obj(Obj &&) = default; 125 | ~Obj() { ++(*dtor_count_); } 126 | Obj &operator=(const Obj &) = default; 127 | Obj &operator=(Obj &&) = default; 128 | size_t *dtor_count_; 129 | }; // Obj 130 | 131 | static void swap(Obj &lhs, Obj &rhs) { std::swap(lhs.dtor_count_, rhs.dtor_count_); } 132 | 133 | } // namespace detail 134 | 135 | TEST(Swap, DtorsSameWithSwap) { 136 | size_t v_count = 0; 137 | size_t w_count = 0; 138 | { 139 | mpark::variant v{&v_count}, w{&w_count}; 140 | using std::swap; 141 | swap(v, w); 142 | // Calls `detail::swap(Obj &lhs, Obj &rhs)`, with which doesn't call any destructors. 143 | EXPECT_EQ(0u, v_count); 144 | EXPECT_EQ(0u, w_count); 145 | } 146 | EXPECT_EQ(1u, v_count); 147 | EXPECT_EQ(1u, w_count); 148 | } 149 | 150 | TEST(Swap, DtorsDifferent) { 151 | struct V { 152 | V(size_t *dtor_count) : dtor_count_(dtor_count) {} 153 | V(const V &) = default; 154 | V(V &&) = default; 155 | ~V() { ++(*dtor_count_); } 156 | V &operator=(const V &) = default; 157 | V &operator=(V &&) = default; 158 | size_t *dtor_count_; 159 | }; // V 160 | struct W { 161 | W(size_t *dtor_count) : dtor_count_(dtor_count) {} 162 | W(const W &) = default; 163 | W(W &&) = default; 164 | ~W() { ++(*dtor_count_); } 165 | W &operator=(const W &) = default; 166 | W &operator=(W &&) = default; 167 | size_t *dtor_count_; 168 | }; // W 169 | size_t v_count = 0; 170 | size_t w_count = 0; 171 | { 172 | mpark::variant v{mpark::in_place_type, &v_count}, w{mpark::in_place_type, &w_count}; 173 | using std::swap; 174 | swap(v, w); 175 | EXPECT_EQ(1u, v_count); 176 | EXPECT_EQ(2u, w_count); 177 | } 178 | EXPECT_EQ(2u, v_count); 179 | EXPECT_EQ(3u, w_count); 180 | } 181 | -------------------------------------------------------------------------------- /libs/variant/test/visit.cpp: -------------------------------------------------------------------------------- 1 | // MPark.Variant 2 | // 3 | // Copyright Michael Park, 2015-2017 4 | // 5 | // Distributed under the Boost Software License, Version 1.0. 6 | // (See accompanying file LICENSE_1_0.txt or copy at 7 | // http://www.boost.org/LICENSE_1_0.txt) 8 | 9 | #include 10 | 11 | #include 12 | #include 13 | #include 14 | 15 | #include 16 | 17 | using namespace std::string_literals; 18 | 19 | enum Qual { LRef, ConstLRef, RRef, ConstRRef }; 20 | 21 | struct get_qual { 22 | constexpr Qual operator()(int &) const { return LRef; } 23 | constexpr Qual operator()(const int &) const { return ConstLRef; } 24 | constexpr Qual operator()(int &&) const { return RRef; } 25 | constexpr Qual operator()(const int &&) const { return ConstRRef; } 26 | }; // get_qual 27 | 28 | TEST(Visit, MutVarMutType) { 29 | mpark::variant v(42); 30 | // Check `v`. 31 | EXPECT_EQ(42, mpark::get(v)); 32 | // Check qualifier. 33 | EXPECT_EQ(LRef, mpark::visit(get_qual(), v)); 34 | EXPECT_EQ(RRef, mpark::visit(get_qual(), std::move(v))); 35 | } 36 | 37 | TEST(Visit, MutVarConstType) { 38 | mpark::variant v(42); 39 | EXPECT_EQ(42, mpark::get(v)); 40 | // Check qualifier. 41 | EXPECT_EQ(ConstLRef, mpark::visit(get_qual(), v)); 42 | EXPECT_EQ(ConstRRef, mpark::visit(get_qual(), std::move(v))); 43 | } 44 | 45 | TEST(Visit, ConstVarMutType) { 46 | const mpark::variant v(42); 47 | EXPECT_EQ(42, mpark::get(v)); 48 | // Check qualifier. 49 | EXPECT_EQ(ConstLRef, mpark::visit(get_qual(), v)); 50 | EXPECT_EQ(ConstRRef, mpark::visit(get_qual(), std::move(v))); 51 | 52 | /* constexpr */ { 53 | constexpr mpark::variant cv(42); 54 | static_assert(42 == mpark::get(cv), ""); 55 | // Check qualifier. 56 | static_assert(ConstLRef == mpark::visit(get_qual(), cv), ""); 57 | static_assert(ConstRRef == mpark::visit(get_qual(), std::move(cv)), ""); 58 | } 59 | } 60 | 61 | TEST(Visit, ConstVarConstType) { 62 | const mpark::variant v(42); 63 | EXPECT_EQ(42, mpark::get(v)); 64 | // Check qualifier. 65 | EXPECT_EQ(ConstLRef, mpark::visit(get_qual(), v)); 66 | EXPECT_EQ(ConstRRef, mpark::visit(get_qual(), std::move(v))); 67 | 68 | /* constexpr */ { 69 | constexpr mpark::variant cv(42); 70 | static_assert(42 == mpark::get(cv), ""); 71 | // Check qualifier. 72 | static_assert(ConstLRef == mpark::visit(get_qual(), cv), ""); 73 | static_assert(ConstRRef == mpark::visit(get_qual(), std::move(cv)), ""); 74 | } 75 | } 76 | 77 | TEST(Visit_Homogeneous, Double) { 78 | mpark::variant v("hello"s), w("world!"s); 79 | EXPECT_EQ("hello world!"s, 80 | mpark::visit([](const auto &lhs, const auto &rhs) { 81 | std::ostringstream strm; 82 | strm << lhs << ' ' << rhs; 83 | return strm.str(); 84 | }, v, w)); 85 | 86 | /* constexpr */ { 87 | constexpr mpark::variant cv(101), cw(202), cx("helllo"); 88 | struct add { 89 | constexpr int operator()(int lhs, int rhs) const { return lhs + rhs; } 90 | constexpr int operator()(int lhs, const char *) const { return lhs; } 91 | constexpr int operator()(const char *, int rhs) const { return rhs; } 92 | constexpr int operator()(const char *, const char *) const { return 0; } 93 | }; // add 94 | static_assert(303 == mpark::visit(add{}, cv, cw), ""); 95 | static_assert(202 == mpark::visit(add{}, cw, cx), ""); 96 | static_assert(101 == mpark::visit(add{}, cx, cv), ""); 97 | static_assert(0 == mpark::visit(add{}, cx, cx), ""); 98 | } 99 | } 100 | 101 | TEST(Visit_Homogeneous, Quintuple) { 102 | mpark::variant v(101), w("+"s), x(202), y("="s), z(303); 103 | EXPECT_EQ("101+202=303"s, 104 | mpark::visit([](const auto &... elems) { 105 | std::ostringstream strm; 106 | std::initializer_list({(strm << elems, 0)...}); 107 | return std::move(strm).str(); 108 | }, v, w, x, y, z)); 109 | } 110 | 111 | TEST(Visit_Heterogeneous, Double) { 112 | mpark::variant v("hello"s); 113 | mpark::variant w("world!"); 114 | EXPECT_EQ("hello world!"s, 115 | mpark::visit([](const auto &lhs, const auto &rhs) { 116 | std::ostringstream strm; 117 | strm << lhs << ' ' << rhs; 118 | return strm.str(); 119 | }, v, w)); 120 | } 121 | 122 | TEST(Visit_Heterogenous, Quintuple) { 123 | mpark::variant v(101); 124 | mpark::variant w("+"); 125 | mpark::variant x(202); 126 | mpark::variant y('='); 127 | mpark::variant z(303L); 128 | EXPECT_EQ("101+202=303"s, 129 | mpark::visit([](const auto &... elems) { 130 | std::ostringstream strm; 131 | std::initializer_list({(strm << elems, 0)...}); 132 | return std::move(strm).str(); 133 | }, v, w, x, y, z)); 134 | } 135 | -------------------------------------------------------------------------------- /rtt/batteries/batteryoutput.cpp: -------------------------------------------------------------------------------- 1 | #include "batteryoutput.h" 2 | 3 | namespace rtt { 4 | namespace batteries { 5 | 6 | static const boost::regex RE_ERR ("\\n\\s*([^\\n]*error[^\\n]*)\\n", boost::regex::icase); 7 | static const boost::regex RE_WARN ("\\n\\s*([^\\n]*warning[^\\n]*)\\n", boost::regex::icase); 8 | 9 | void BatteryOutput::appendStdOut(const std::string & stdOut) { 10 | detectionDone = false; 11 | 12 | this->stdOut.append(stdOut); 13 | } 14 | 15 | void BatteryOutput::appendStdErr(const std::string & stdErr) { 16 | this->stdErr.append(stdErr); 17 | } 18 | 19 | std::string BatteryOutput::getStdOut() const { 20 | return stdOut; 21 | } 22 | 23 | std::string BatteryOutput::getStdErr() const { 24 | return stdErr; 25 | } 26 | 27 | std::vector BatteryOutput::getErrors() const { 28 | return errors; 29 | } 30 | 31 | std::vector BatteryOutput::getWarnings() const { 32 | return warnings; 33 | } 34 | 35 | void BatteryOutput::doDetection() { 36 | detectErrsWarnsInStdOut(); 37 | } 38 | 39 | void BatteryOutput::detectErrsWarnsInStdOut() { 40 | if(detectionDone) 41 | return; 42 | 43 | /* Detect warnings and errors here. 44 | * Detection happens only in stdOut variable. */ 45 | 46 | 47 | boost::smatch match; 48 | auto end = boost::sregex_iterator(); 49 | auto errBegin = boost::sregex_iterator(stdOut.begin() , stdOut.end(), RE_ERR); 50 | auto warnBegin = boost::sregex_iterator(stdOut.begin() , stdOut.end(), RE_WARN); 51 | 52 | errors.clear(); 53 | warnings.clear(); 54 | 55 | for( ; errBegin != end ; ++errBegin) { 56 | match = *errBegin; 57 | errors.push_back(match[1].str()); 58 | } 59 | 60 | for( ; warnBegin != end ; ++ warnBegin) { 61 | match = *warnBegin; 62 | warnings.push_back(match[1].str()); 63 | } 64 | 65 | detectionDone = true; 66 | } 67 | 68 | } // namespace batteries 69 | } // namespace rtt 70 | 71 | -------------------------------------------------------------------------------- /rtt/batteries/batteryoutput.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_BATTERYOUTPUT_H 2 | #define RTT_BATTERIES_BATTERYOUTPUT_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | namespace rtt { 9 | namespace batteries { 10 | 11 | /** 12 | * @brief The BatteryOutput class Class for storing output from executed battery. 13 | * After calling get functions on errors and warnings, string stdOut is checked for 14 | * lines containing "error" or "warning" (case insensitive) and if any lines are found, 15 | * they are also stored in variables errors and warnings respectively. 16 | */ 17 | class BatteryOutput { 18 | public: 19 | BatteryOutput() {} 20 | 21 | /** 22 | * @brief appendStdOut Add string to standard output 23 | * @param stdOut 24 | */ 25 | void appendStdOut(const std::string & stdOut); 26 | 27 | /** 28 | * @brief appendStdErr Add string to error output 29 | * @param stdErr 30 | */ 31 | void appendStdErr(const std::string & stdErr); 32 | 33 | /** 34 | * @brief getStdErr 35 | * @return Raw error output 36 | */ 37 | std::string getStdErr() const; 38 | 39 | /** 40 | * @brief getStdOut 41 | * @return Raw standard output 42 | */ 43 | std::string getStdOut() const; 44 | 45 | /** 46 | * @brief getErrors 47 | * @return Extracted error messages 48 | */ 49 | std::vector getErrors() const; 50 | 51 | /** 52 | * @brief getWarnings 53 | * @return Extracted warning messages 54 | */ 55 | std::vector getWarnings() const; 56 | 57 | /** 58 | * @brief doDetection This will force detection. Detection is time heavy 59 | * operation and should be done inside test threads 60 | * instead of running it via getter later. 61 | */ 62 | void doDetection(); 63 | 64 | private: 65 | bool detectionDone = false; 66 | std::string stdOut; 67 | std::string stdErr; 68 | std::vector errors; 69 | std::vector warnings; 70 | 71 | void detectErrsWarnsInStdOut(); 72 | }; 73 | 74 | } // namespace batteries 75 | } // namespace rtt 76 | 77 | #endif // RTT_BATTERIES_BATTERYOUTPUT_H 78 | -------------------------------------------------------------------------------- /rtt/batteries/dieharder/battery-dh.cpp: -------------------------------------------------------------------------------- 1 | #include "rtt/batteries/dieharder/battery-dh.h" 2 | 3 | #include "rtt/batteries/itestresult-batt.h" 4 | 5 | namespace rtt { 6 | namespace batteries { 7 | namespace dieharder { 8 | 9 | std::unique_ptr Battery::getInstance(const GlobalContainer & container) { 10 | std::unique_ptr b (new Battery(container)); 11 | return b; 12 | } 13 | 14 | std::vector> Battery::getTestResults() const { 15 | if(!executed) 16 | throw RTTException(objectInfo , Strings::BATT_ERR_NO_EXEC_PROC); 17 | 18 | std::vector> results(tests.size()); 19 | std::transform(tests.begin(), tests.end(), results.begin(), 20 | [](const auto & el){ return ITestResult::getInstance({el.get()}); }); 21 | 22 | return results; 23 | } 24 | 25 | 26 | } // namespace dieharder 27 | } // namespace batteries 28 | } // namespace rtt 29 | -------------------------------------------------------------------------------- /rtt/batteries/dieharder/battery-dh.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_DIEHARDER_BATTERY_H 2 | #define RTT_BATTERIES_DIEHARDER_BATTERY_H 3 | 4 | #include "rtt/batteries/ibattery-batt.h" 5 | 6 | namespace rtt { 7 | namespace batteries { 8 | namespace dieharder { 9 | 10 | class Battery : public IBattery { 11 | public: 12 | static std::unique_ptr getInstance(const GlobalContainer & container); 13 | 14 | std::vector> getTestResults() const; 15 | 16 | private: 17 | /* 18 | =============== 19 | *** Methods *** 20 | =============== 21 | */ 22 | /* So initialization in getInstance can't be avoided */ 23 | Battery(const GlobalContainer & container) 24 | : IBattery(container) {} 25 | }; 26 | 27 | } // namespace dieharder 28 | } // namespace batteries 29 | } // namespace rtt 30 | 31 | #endif // RTT_BATTERIES_DIEHARDER_BATTERY_H 32 | -------------------------------------------------------------------------------- /rtt/batteries/dieharder/setting-dh.cpp: -------------------------------------------------------------------------------- 1 | #include "setting-dh.h" 2 | 3 | namespace rtt { 4 | namespace batteries { 5 | namespace dieharder { 6 | 7 | Setting Setting::getInstance(const std::string & arg, 8 | const std::string & value) { 9 | if(arg.empty() || value.empty()) 10 | throw std::runtime_error("neither argument nor its value" 11 | " can be empty in Dieharder"); 12 | 13 | Setting setting; 14 | if(arg == "-a") { 15 | throw std::runtime_error("option " + arg + " can't be set by user"); 16 | setting.logicName = "All tests, default options"; 17 | } else if (arg == "-d") { 18 | throw std::runtime_error("option " + arg + " can't be set by user"); 19 | setting.logicName = "Select specific test"; 20 | } else if (arg == "-f") { 21 | throw std::runtime_error("option " + arg + " can't be set by user"); 22 | setting.logicName = "Filename"; 23 | } else if (arg == "-B") { 24 | throw std::runtime_error("option " + arg + " can't be set by user"); 25 | setting.logicName = "Binary output"; 26 | } else if (arg == "-D") { 27 | throw std::runtime_error("option " + arg + " can't be set by user"); 28 | setting.logicName = "Output flag"; 29 | } else if (arg == "-F") { 30 | throw std::runtime_error("option " + arg + " can't be set by user"); 31 | setting.logicName = "Lists all output flags"; 32 | } else if (arg == "-c") { 33 | throw std::runtime_error("option " + arg + " can't be set by user"); 34 | setting.logicName = "Table separator"; 35 | } else if (arg == "-g") { 36 | throw std::runtime_error("option " + arg + " can't be set by user"); 37 | setting.logicName = "Generator number"; 38 | } else if (arg == "-h") { 39 | throw std::runtime_error("option " + arg + " can't be set by user"); 40 | setting.logicName = "Help"; 41 | } else if (arg == "-k") { 42 | throw std::runtime_error("option " + arg + " can't be set by user"); 43 | setting.logicName = "KS flag"; 44 | if(value != "0" && value != "1" && value != "2" && value != "3") 45 | throw std::runtime_error("invalid value in " + arg + " option: " + value); 46 | } else if (arg == "-l") { 47 | throw std::runtime_error("option " + arg + " can't be set by user"); 48 | setting.logicName = "Lists tests"; 49 | } else if (arg == "-L") { 50 | setting.logicName = "Overlap option"; 51 | if(value != "0" && value != "1") 52 | throw std::runtime_error("invalid value in " + arg + " option: " + value); 53 | } else if (arg == "-m") { 54 | setting.logicName = "Multiply Psamples"; 55 | } else if (arg == "-n") { 56 | setting.logicName = "N-tuple setting"; 57 | } else if (arg == "-o") { 58 | throw std::runtime_error("option " + arg + " can't be set by user"); 59 | setting.logicName = "Output generator bytes to file"; 60 | } else if (arg == "-p") { 61 | throw std::runtime_error("option " + arg + " must be set in config file"); 62 | setting.logicName = "P-samples count"; 63 | } else if (arg == "-P") { 64 | setting.logicName = "Xoff"; 65 | } else if (arg == "-S") { 66 | throw std::runtime_error("option " + arg + " can't be set by user"); 67 | setting.logicName = "Seed"; 68 | } else if (arg == "-s") { 69 | throw std::runtime_error("option " + arg + " can't be set by user"); 70 | setting.logicName = "Reseeding strategy"; 71 | } else if (arg == "-t") { 72 | setting.logicName = "Random entities in test"; 73 | } else if (arg == "-W") { 74 | setting.logicName = "Weak threshold"; 75 | float tmp = Utils::strtof(value); 76 | if(tmp < 0 || tmp > 1) 77 | throw std::runtime_error("invalid value in " + arg + " option: " + value); 78 | } else if (arg == "-X") { 79 | setting.logicName = "Fail threshold"; 80 | float tmp = Utils::strtof(value); 81 | if(tmp < 0 || tmp > 1) 82 | throw std::runtime_error("invalid value in " + arg + " option: " + value); 83 | } else if (arg == "-Y") { 84 | setting.logicName = "X-trategy - Test To Fail mode"; 85 | if(value != "0" && value != "1" && value != "2") 86 | throw std::runtime_error("invalid value in " + arg + " option: " + value); 87 | } else if (arg == "-v") { 88 | throw std::runtime_error("option " + arg + " can't be set by user"); 89 | setting.logicName = "Verbose output"; 90 | } else if (arg == "-x") { 91 | setting.logicName = "Test specific option X"; 92 | } else if (arg == "-y") { 93 | setting.logicName = "Test specific option Y"; 94 | } else if (arg == "-z") { 95 | setting.logicName = "Test specific option Z"; 96 | } else { 97 | throw std::runtime_error("unknown option used: " + arg); 98 | } 99 | /* Checking if option can be converted into float */ 100 | /* Int can be also in float format*/ 101 | Utils::strtof(value); 102 | 103 | setting.argument = arg; 104 | setting.argumentValue = value; 105 | 106 | return setting; 107 | } 108 | 109 | void Setting::getConsoleInput(std::ostream & out) const { 110 | out << argument << " " << argumentValue; 111 | } 112 | std::string Setting::getLogicName() const { 113 | return logicName; 114 | } 115 | std::string Setting::getArgument() const { 116 | return argument; 117 | } 118 | std::string Setting::getArgumentValue() const { 119 | return argumentValue; 120 | } 121 | 122 | 123 | 124 | 125 | } // namespace dieharder 126 | } // namespace batteries 127 | } // namespace rtt 128 | 129 | -------------------------------------------------------------------------------- /rtt/batteries/dieharder/setting-dh.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_DIEHARDER_SETTING_H 2 | #define RTT_BATTERIES_DIEHARDER_SETTING_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "rtt/utils.h" 9 | 10 | namespace rtt { 11 | namespace batteries { 12 | namespace dieharder { 13 | 14 | class Setting { 15 | public: 16 | static Setting getInstance(const std::string & arg , 17 | const std::string & value); 18 | 19 | void getConsoleInput(std::ostream & out) const; 20 | 21 | std::string getLogicName() const; 22 | 23 | std::string getArgument() const; 24 | 25 | std::string getArgumentValue() const; 26 | 27 | private: 28 | /* 29 | ================= 30 | *** Variables *** 31 | ================= 32 | */ 33 | /* These fields will be set after initialization in */ 34 | /* getInstance */ 35 | std::string argument; 36 | std::string argumentValue; 37 | 38 | /* Following fields will be initialized in getInstance */ 39 | /* to default values according to agrument */ 40 | std::string logicName; 41 | 42 | /* 43 | =============== 44 | *** Methods *** 45 | =============== 46 | */ 47 | /* I don't want to allow existence of Test objects */ 48 | /* without initialization that is in getInstance */ 49 | Setting() {} 50 | }; 51 | 52 | } // namespace dieharder 53 | } // namespace batteries 54 | } // namespace rtt 55 | 56 | #endif // RTT_BATTERIES_DIEHARDER_SETTING_H 57 | -------------------------------------------------------------------------------- /rtt/batteries/dieharder/test-dh.cpp: -------------------------------------------------------------------------------- 1 | #include "rtt/batteries/dieharder/test-dh.h" 2 | 3 | namespace rtt { 4 | namespace batteries { 5 | namespace dieharder { 6 | 7 | std::unique_ptr Test::getInstance(std::string battObjInf, int testIndex, 8 | const GlobalContainer & container) { 9 | std::unique_ptr t (new Test(battObjInf, testIndex, container)); 10 | 11 | /* Battery specific code goes here */ 12 | 13 | return t; 14 | } 15 | 16 | } // namespace dieharder 17 | } // namespace batteries 18 | } // namespace rtt 19 | 20 | -------------------------------------------------------------------------------- /rtt/batteries/dieharder/test-dh.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_DIEHARDER_TEST_H 2 | #define RTT_BATTERIES_DIEHARDER_TEST_H 3 | 4 | #include 5 | #include 6 | 7 | #include "rtt/batteries/itest-batt.h" 8 | 9 | namespace rtt { 10 | namespace batteries { 11 | namespace dieharder { 12 | 13 | typedef std::pair tTestInfo; 14 | 15 | class Test : public ITest { 16 | public: 17 | static std::unique_ptr getInstance(std::string battObjInf, int testId, 18 | const GlobalContainer & container); 19 | private: 20 | /* Methods */ 21 | Test(std::string battObjInf, int testIndex, 22 | const GlobalContainer & container) 23 | : ITest(battObjInf, testIndex, container) 24 | {} 25 | }; 26 | 27 | } // namespace dieharder 28 | } // namespace batteries 29 | } // namespace rtt 30 | 31 | #endif // RTT_BATTERIES_DIEHARDER_TEST_H 32 | -------------------------------------------------------------------------------- /rtt/batteries/dieharder/testresult-dh.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_DIEHARDER_TESTRESULT_H 2 | #define RTT_BATTERIES_DIEHARDER_TESTRESULT_H 3 | 4 | #include 5 | 6 | #include "rtt/batteries/itestresult-batt.h" 7 | 8 | 9 | namespace rtt { 10 | namespace batteries { 11 | namespace dieharder { 12 | 13 | class TestResult : public ITestResult { 14 | public: 15 | static std::unique_ptr getInstance( 16 | const std::vector & tests); 17 | 18 | private: 19 | TestResult(Logger * logger , std::string testName) 20 | : ITestResult(logger , testName) 21 | {} 22 | 23 | static std::vector splitIntoSubTests(const std::string & str); 24 | 25 | /* Math functions used to calculate resulting KS statistic */ 26 | double kstest(const std::vector & pvalue); 27 | 28 | double p_ks_new(int n , double d); 29 | 30 | void mMultiply(double *A,double *B,double *C,int m); 31 | 32 | void mPower(double *A,int eA,double *V,int *eV,int m,int n); 33 | }; 34 | 35 | } // namespace dieharder 36 | } // namespace batteries 37 | } // namespace rtt 38 | 39 | #endif // RTT_BATTERIES_DIEHARDER_TESTRESULT_H 40 | -------------------------------------------------------------------------------- /rtt/batteries/dieharder/variant-dh.cpp: -------------------------------------------------------------------------------- 1 | #include "variant-dh.h" 2 | 3 | namespace rtt { 4 | namespace batteries { 5 | namespace dieharder { 6 | 7 | const int Variant::OPTION_HEADER_FLAG = 197119; //66047; 8 | const int Variant::OPTION_FILE_GENERATOR = 201; 9 | 10 | std::unique_ptr Variant::getInstance(int testId, std::string testObjInf, 11 | uint variantIdx, const GlobalContainer & cont) { 12 | std::unique_ptr v (new Variant(testId, testObjInf, variantIdx, cont)); 13 | auto battConf = cont.getBatteryConfiguration(); 14 | 15 | v->pSampleCount = battConf->getTestVariantParamInt( 16 | v->battery, v->testId, variantIdx, 17 | Configuration::TAGNAME_PSAMPLES); 18 | if(v->pSampleCount == Configuration::VALUE_INT_NOT_SET) 19 | throw RTTException(v->objectInfo , Strings::TEST_ERR_PSAMPLES_NOT_SET); 20 | 21 | std::string arguments = battConf->getTestVariantParamString( 22 | v->battery, v->testId, variantIdx, 23 | Configuration::TAGNAME_ARGUMENTS); 24 | auto vArguments = Utils::split(arguments , ' '); 25 | if(vArguments.size() % 2 != 0) 26 | throw RTTException(v->objectInfo , 27 | Strings::TEST_ERR_ARGS_BAD_FORMAT_OPT_WO_VAL); 28 | for(size_t i = 0 ; i < vArguments.size() ; i += 2) { 29 | try { 30 | auto sett = Setting::getInstance( 31 | vArguments.at(i), vArguments.at(i + 1)); 32 | v->settings.push_back(std::move(sett)); 33 | } catch(std::runtime_error ex) { 34 | throw RTTException(v->objectInfo , ex.what()); 35 | } 36 | } 37 | 38 | return v; 39 | } 40 | 41 | void Variant::buildStrings() { 42 | /* Building cli arguments */ 43 | std::stringstream arguments; 44 | arguments << "dieharder "; 45 | /* Dieharder can receive single option multiple times and 46 | * will take only the last one. Therefore, first are passed 47 | * default values from config, then there are test specific 48 | * value that override default ones and lastly, options that 49 | * MUST be set for correct battery functionality are entered. */ 50 | for(const auto & it : settings) { 51 | it.getConsoleInput(arguments); 52 | arguments << " "; 53 | } 54 | /* Set psample count */ 55 | arguments << "-p " << pSampleCount << " "; 56 | /* Set also Xoff to avoid trimming p-values count */ 57 | arguments << "-P " << pSampleCount << " "; 58 | /* Specify test */ 59 | arguments << "-d " << testId << " "; 60 | /* Specify header flag */ 61 | arguments << "-D " << OPTION_HEADER_FLAG << " "; 62 | /* Specify binary file generator */ 63 | arguments << "-g " << OPTION_FILE_GENERATOR << " "; 64 | /* Specify binary input file */ 65 | arguments << "-f \"" << binaryDataPath << "\" "; 66 | /* Specify random seed and seed strategy */ 67 | arguments << "-S 0 -s 1 "; 68 | cliArguments = arguments.str(); 69 | 70 | /* Building standard input */ 71 | //no input 72 | 73 | /* Building variation user settings */ 74 | userSettings.push_back({"P-sample count", Utils::itostr(pSampleCount)}); 75 | for(const auto & setting : settings) 76 | userSettings.push_back({setting.getLogicName(), setting.getArgumentValue()}); 77 | } 78 | 79 | 80 | 81 | } // namespace dieharder 82 | } // namespace batteries 83 | } // namespace rtt 84 | -------------------------------------------------------------------------------- /rtt/batteries/dieharder/variant-dh.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_DIEHARDER_VARIANT_H 2 | #define RTT_BATTERIES_DIEHARDER_VARIANT_H 3 | 4 | #include "rtt/batteries/ivariant-batt.h" 5 | #include "rtt/batteries/dieharder/setting-dh.h" 6 | 7 | namespace rtt { 8 | namespace batteries { 9 | namespace dieharder { 10 | 11 | class Variant : public IVariant { 12 | public: 13 | static std::unique_ptr getInstance(int testId, std::string testObjInf, 14 | uint variantIdx, const GlobalContainer & cont); 15 | private: 16 | /* Test info constants */ 17 | static const int OPTION_HEADER_FLAG; 18 | static const int OPTION_FILE_GENERATOR; 19 | 20 | // Dieharder specific data 21 | std::vector settings; 22 | int pSampleCount; 23 | 24 | /* Methods */ 25 | Variant(int testId, std::string testObjInf, 26 | uint variantIdx, const GlobalContainer & cont) 27 | : IVariant(testId, testObjInf, variantIdx, cont) 28 | {} 29 | 30 | void buildStrings(); 31 | }; 32 | 33 | } // namespace dieharder 34 | } // namespace batteries 35 | } // namespace rtt 36 | 37 | #endif // RTT_BATTERIES_DIEHARDER_VARIANT_H 38 | -------------------------------------------------------------------------------- /rtt/batteries/ibattery-batt.cpp: -------------------------------------------------------------------------------- 1 | #include "ibattery-batt.h" 2 | 3 | #include "rtt/batteries/dieharder/battery-dh.h" 4 | #include "rtt/batteries/niststs/battery-sts.h" 5 | #include "rtt/batteries/testu01/battery-tu01.h" 6 | 7 | #include "rtt/batteries/testrunner-batt.h" 8 | 9 | #ifdef _WIN32 10 | #include 11 | // MSDN recommends against using getcwd & chdir names 12 | #define cwd _getcwd 13 | #define cd _chdir 14 | #else 15 | #include "unistd.h" 16 | #define cwd getcwd 17 | #define cd chdir 18 | #endif 19 | 20 | 21 | namespace rtt { 22 | namespace batteries { 23 | 24 | std::unique_ptr IBattery::getInstance(const GlobalContainer & cont) { 25 | /* Pick correct derived class */ 26 | switch(cont.getRttCliOptions()->getBatteryId()) { 27 | case Constants::BatteryID::DIEHARDER: 28 | return dieharder::Battery::getInstance(cont); 29 | case Constants::BatteryID::NIST_STS: 30 | return niststs::Battery::getInstance(cont); 31 | case Constants::BatteryID::TU01_SMALLCRUSH: 32 | case Constants::BatteryID::TU01_CRUSH: 33 | case Constants::BatteryID::TU01_BIGCRUSH: 34 | case Constants::BatteryID::TU01_RABBIT: 35 | case Constants::BatteryID::TU01_ALPHABIT: 36 | case Constants::BatteryID::TU01_BLOCK_ALPHABIT: 37 | return testu01::Battery::getInstance(cont); 38 | default: 39 | raiseBugException(Strings::ERR_INVALID_BATTERY); 40 | } 41 | } 42 | 43 | void IBattery::runTests() { 44 | if(executed) 45 | throw RTTException(objectInfo , Strings::BATT_ERR_ALREADY_EXECUTED); 46 | 47 | if (rttCliOptions->hasResultsPathPrefix()){ 48 | if (cd(rttCliOptions->getResultsPathPrefix().c_str()) != 0){ 49 | raiseBugException(std::string("Could not change dir to ") + rttCliOptions->getResultsPathPrefix()); 50 | } 51 | } 52 | 53 | logger->info(objectInfo + ": Test execution started!"); 54 | /* Tests will create output file in output directory */ 55 | Utils::createDirectory(toolkitSettings->getLoggerBatteryDir(battery)); 56 | 57 | /* Get all variations from tests and execute them parallely. */ 58 | std::vector variants; 59 | for(const auto & test : tests) { 60 | auto testVars = test->getVariants(); 61 | variants.insert(variants.end(), testVars.begin(), testVars.end()); 62 | } 63 | TestRunner::executeTests(logger, variants, 64 | toolkitSettings->getExecMaximumThreads(), 65 | toolkitSettings->getExecTestTimeout()); 66 | 67 | logger->info(objectInfo + ": Test execution finished!"); 68 | executed = true; 69 | } 70 | 71 | IBattery::IBattery(const GlobalContainer & cont) { 72 | rttCliOptions = cont.getRttCliOptions(); 73 | batteryConfiguration = cont.getBatteryConfiguration(); 74 | toolkitSettings = cont.getToolkitSettings(); 75 | logger = cont.getLogger(); 76 | 77 | creationTime = cont.getCreationTime(); 78 | battery = rttCliOptions->getBatteryArg(); 79 | objectInfo = battery.getName(); 80 | logger->info(objectInfo + Strings::BATT_INFO_PROCESSING_FILE + rttCliOptions->getInputDataPath()); 81 | 82 | std::vector testIndices = rttCliOptions->getTestConsts(); 83 | if(testIndices.empty()) 84 | testIndices = batteryConfiguration->getBatteryDefaultTests(battery); 85 | if(testIndices.empty()) 86 | throw RTTException(objectInfo , Strings::BATT_ERR_NO_TESTS); 87 | 88 | for(const int & i : testIndices) { 89 | tests.push_back(ITest::getInstance(objectInfo, i, cont)); 90 | } 91 | } 92 | 93 | } // namespace batteries 94 | } // namespace rtt 95 | -------------------------------------------------------------------------------- /rtt/batteries/ibattery-batt.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_IBATTERY_H 2 | #define RTT_IBATTERY_H 3 | 4 | #include "rtt/batteries/itest-batt.h" 5 | #include "rtt/batteries/itestresult-batt.h" 6 | 7 | namespace rtt { 8 | namespace batteries { 9 | 10 | /** 11 | * @brief The IBattery class General interface for batteries to store their settings and tests. 12 | */ 13 | class IBattery { 14 | public: 15 | /** 16 | * @brief getInstance Creates an initialized object 17 | * @param cont Global settings 18 | * @return 19 | */ 20 | static std::unique_ptr getInstance(const GlobalContainer & cont); 21 | 22 | /** 23 | * @brief runTests Executes all tests in the battery 24 | */ 25 | void runTests(); 26 | 27 | /** 28 | * @brief ~IBattery Destructor. 29 | */ 30 | virtual ~IBattery() {} 31 | 32 | /** 33 | * @brief getTestResults 34 | * @return Results of the executed tests, will throw 35 | * error if the Battery wasn't executed before. 36 | */ 37 | virtual std::vector> getTestResults() const = 0; 38 | 39 | protected: 40 | IBattery(const GlobalContainer & cont); 41 | 42 | /* Variables common for all batteries. Set in getInstance(). 43 | * Used by batteries in later stages. */ 44 | /* Objects pointing to global object storage - 45 | * many classes use these objects */ 46 | clinterface::RTTCliOptions * rttCliOptions; 47 | Configuration * batteryConfiguration; 48 | ToolkitSettings * toolkitSettings; 49 | Logger * logger; 50 | /* Variables initialized in getInstance() */ 51 | time_t creationTime; 52 | clinterface::BatteryArg battery; 53 | std::string objectInfo; 54 | /* Battery is keeping track of tests set to execution. 55 | * Test objects keep track of their settings and execution results. */ 56 | std::vector> tests; 57 | /* Set to true after execution */ 58 | bool executed = false; 59 | }; 60 | 61 | } // namespace batteries 62 | } // namespace rtt 63 | 64 | #endif // RTT_IBATTERY_H 65 | -------------------------------------------------------------------------------- /rtt/batteries/itest-batt.cpp: -------------------------------------------------------------------------------- 1 | #include "itest-batt.h" 2 | 3 | #include "rtt/batteries/niststs/test-sts.h" 4 | #include "rtt/batteries/dieharder/test-dh.h" 5 | #include "rtt/batteries/testu01/test-tu01.h" 6 | 7 | namespace rtt { 8 | namespace batteries { 9 | 10 | std::unique_ptr ITest::getInstance(std::string battObjInf, int testId, 11 | const GlobalContainer & cont) { 12 | switch(cont.getRttCliOptions()->getBatteryId()) { 13 | case Constants::BatteryID::DIEHARDER: 14 | return dieharder::Test::getInstance(battObjInf, testId, cont); 15 | case Constants::BatteryID::NIST_STS: 16 | return niststs::Test::getInstance(battObjInf, testId , cont); 17 | case Constants::BatteryID::TU01_SMALLCRUSH: 18 | case Constants::BatteryID::TU01_CRUSH: 19 | case Constants::BatteryID::TU01_BIGCRUSH: 20 | case Constants::BatteryID::TU01_RABBIT: 21 | case Constants::BatteryID::TU01_ALPHABIT: 22 | case Constants::BatteryID::TU01_BLOCK_ALPHABIT: 23 | return testu01::Test::getInstance(battObjInf, testId , cont); 24 | default: 25 | raiseBugException(Strings::ERR_INVALID_BATTERY); 26 | } 27 | } 28 | 29 | std::string ITest::getLogicName() const { 30 | return logicName; 31 | } 32 | 33 | int ITest::getTestId() const { 34 | return testId; 35 | } 36 | 37 | std::vector ITest::getVariants() const { 38 | return Utils::getRawPtrs(variants); 39 | } 40 | 41 | ITest::ITest(std::string battObjInf, int testId, const GlobalContainer & cont) { 42 | rttCliOptions = cont.getRttCliOptions(); 43 | toolkitSettings = cont.getToolkitSettings(); 44 | batteryConfiguration = cont.getBatteryConfiguration(); 45 | logger = cont.getLogger(); 46 | this->testId = testId; 47 | battery = rttCliOptions->getBatteryArg(); 48 | logicName = TestConstants::getTestLogicName(battery, testId); 49 | objectInfo = 50 | battObjInf + " - " + logicName + 51 | " (" + Utils::itostr(testId) + ")"; 52 | 53 | uint varCount = batteryConfiguration->getTestVariantsCount(battery, testId); 54 | if(varCount == 0) { 55 | variants.push_back(IVariant::getInstance(testId, objectInfo, 0, cont)); 56 | } else { 57 | for(uint varIdx = 0; varIdx < varCount; ++varIdx) 58 | variants.push_back(IVariant::getInstance(testId, objectInfo, varIdx, cont)); 59 | } 60 | } 61 | 62 | Logger * ITest::getLogger() const { 63 | return logger; 64 | } 65 | 66 | BatteryArg ITest::getBatteryArg() const { 67 | return battery; 68 | } 69 | 70 | } // namespace batteries 71 | } // namespace rtt 72 | 73 | -------------------------------------------------------------------------------- /rtt/batteries/itest-batt.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_ITEST_H 2 | #define RTT_BATTERIES_ITEST_H 3 | 4 | #include "rtt/batteries/ivariant-batt.h" 5 | #include "rtt/clinterface/rttclioptions.h" 6 | 7 | namespace rtt { 8 | namespace batteries { 9 | 10 | typedef std::vector tTestPvals; 11 | 12 | /** 13 | * @brief The ITest class Holds single test from given battery. 14 | * Can have one or multiple variants and those will be executed. 15 | */ 16 | class ITest { 17 | public: 18 | /** 19 | * @brief getInstance Creates initialized object 20 | * @param battObjInf Information about parent object used for logging 21 | * @param testId ID of the test 22 | * @param cont Global settings 23 | * @return 24 | */ 25 | static std::unique_ptr getInstance(std::string battObjInf, int testId, 26 | const GlobalContainer & cont); 27 | 28 | /** 29 | * @brief ~ITest Desctructor 30 | */ 31 | virtual ~ITest() {} 32 | 33 | /** 34 | * @brief wasExecuted 35 | * @return true if the test was executed, false otherwise 36 | */ 37 | bool wasExecuted() const; 38 | 39 | /** 40 | * @brief getTestId 41 | * @return ID of the test 42 | */ 43 | int getTestId() const; 44 | 45 | /** 46 | * @brief getLogicName 47 | * @return Human readable name of the test 48 | */ 49 | std::string getLogicName() const; 50 | 51 | /** 52 | * @brief getVariants 53 | * @return All variants of the test 54 | */ 55 | std::vector getVariants() const; 56 | 57 | /** 58 | * @brief getBattId 59 | * @return ID of the parent battery 60 | */ 61 | BatteryArg getBatteryArg() const; 62 | 63 | /** 64 | * @brief getLogger 65 | * @return pointer to logger 66 | */ 67 | Logger * getLogger() const; 68 | 69 | protected: 70 | ITest(std::string battObjInf, int testId , const GlobalContainer & cont); 71 | 72 | /* These fields will be set in the constructor */ 73 | /* Pointers to global configurations */ 74 | clinterface::RTTCliOptions * rttCliOptions; 75 | ToolkitSettings * toolkitSettings; 76 | Configuration * batteryConfiguration; 77 | Logger * logger; 78 | /* Variations of the test */ 79 | std::vector> variants; 80 | /* Test specific fields - will be set in constructor (base class) and 81 | * getInstance(derived classes) */ 82 | int testId; 83 | clinterface::BatteryArg battery; 84 | std::string logicName; 85 | std::string objectInfo; 86 | }; 87 | 88 | } // namespace batteries 89 | } // namespace rtt 90 | 91 | #endif // RTT_BATTERIES_ITEST_H 92 | -------------------------------------------------------------------------------- /rtt/batteries/itestresult-batt.cpp: -------------------------------------------------------------------------------- 1 | #include "itestresult-batt.h" 2 | 3 | #include "rtt/batteries/dieharder/testresult-dh.h" 4 | #include "rtt/batteries/niststs/testresult-sts.h" 5 | #include "rtt/batteries/testu01/testresult-tu01.h" 6 | 7 | namespace rtt { 8 | namespace batteries { 9 | 10 | std::unique_ptr ITestResult::getInstance( 11 | const std::vector & tests) { 12 | if(tests.empty()) 13 | raiseBugException("empty tests"); 14 | 15 | std::unique_ptr rval; 16 | 17 | switch(tests.at(0)->getBatteryArg().getBatteryId()) { 18 | case Constants::BatteryID::NIST_STS: 19 | rval = niststs::TestResult::getInstance(tests); 20 | break; 21 | case Constants::BatteryID::DIEHARDER: 22 | rval = dieharder::TestResult::getInstance(tests); 23 | break; 24 | case Constants::BatteryID::TU01_SMALLCRUSH: 25 | case Constants::BatteryID::TU01_CRUSH: 26 | case Constants::BatteryID::TU01_BIGCRUSH: 27 | case Constants::BatteryID::TU01_RABBIT: 28 | case Constants::BatteryID::TU01_ALPHABIT: 29 | case Constants::BatteryID::TU01_BLOCK_ALPHABIT: 30 | rval = testu01::TestResult::getInstance(tests); 31 | break; 32 | default: 33 | raiseBugException(Strings::ERR_INVALID_BATTERY); 34 | } 35 | rval->evaluateSetPassed(); 36 | return rval; 37 | } 38 | 39 | std::vector ITestResult::getVariantResults() const { 40 | return varRes; 41 | } 42 | 43 | std::pair ITestResult::getOptionalPassed() const { 44 | return optionalPassed; 45 | } 46 | 47 | std::string ITestResult::getTestName() const { 48 | return testName; 49 | } 50 | 51 | double ITestResult::getPartialAlpha() const { 52 | return partialAlpha; 53 | } 54 | 55 | void ITestResult::evaluateSetPassed() { 56 | std::vector allPValues; 57 | for(const result::VariantResult & var : varRes) { 58 | std::vector tmp = var.getSubTestStatResults(); 59 | allPValues.insert(allPValues.end(), tmp.begin(), tmp.end()); 60 | } 61 | 62 | if(allPValues.empty()) { 63 | optionalPassed.second = false; 64 | return; 65 | } 66 | 67 | optionalPassed.second = true; 68 | 69 | double exp = 1.0/(double)allPValues.size(); 70 | partialAlpha = 1.0 - (std::pow(1.0 - Constants::MATH_ALPHA, exp)); 71 | 72 | for(const double & pval : allPValues) { 73 | if(!isPValuePassing(pval)) { 74 | optionalPassed.first = false; 75 | break; 76 | } 77 | } 78 | } 79 | 80 | bool ITestResult::isPValuePassing(double pvalue) { 81 | /* Everything outside of the interval [alpha, 1) is failure. 82 | + * Note the open interval on right side - this is to fail 83 | + * full 1.0s which are often given as incorrect value by batteries */ 84 | if(pvalue < partialAlpha - Constants::MATH_EPS || 85 | pvalue > 1 - Constants::MATH_EPS) 86 | return false; 87 | 88 | return true; 89 | } 90 | 91 | } // namespace batteries 92 | } // namespace rtt 93 | -------------------------------------------------------------------------------- /rtt/batteries/itestresult-batt.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_ITESTRESULT_H 2 | #define RTT_BATTERIES_ITESTRESULT_H 3 | 4 | #include "rtt/batteries/itest-batt.h" 5 | #include "rtt/batteries/result/variantresult-res.h" 6 | 7 | namespace rtt { 8 | namespace batteries { 9 | 10 | /** 11 | * @brief The ITestResult class Holds results of one or multiple tests. 12 | * If there are multiple tests inside, the results will be bundled together 13 | */ 14 | class ITestResult { 15 | public: 16 | /** 17 | * @brief getInstance Creates instance. Tests that are to 18 | * be bundled together should be provided in a vector. 19 | * @param tests set of tests 20 | * @return initialized instance 21 | */ 22 | static std::unique_ptr getInstance( 23 | const std::vector & tests); 24 | 25 | /** 26 | * @brief getVariantResults 27 | * @return Results of all underlying variants that were contained in the tests 28 | */ 29 | std::vector getVariantResults() const; 30 | 31 | /** 32 | * @brief getOptionalPassed Returns optional bool variable. 33 | * If second bool in the pair is false, then there were no 34 | * valid results and nothing was evaluated. If it is true 35 | * then first bool can be either true or false, based on 36 | * p-values of underlying variants. 37 | * @return Information about passing of the test. 38 | */ 39 | std::pair getOptionalPassed() const; 40 | 41 | /** 42 | * @brief getTestName 43 | * @return Human readable string containing test name 44 | */ 45 | std::string getTestName() const; 46 | 47 | /** 48 | * @brief getPartialAlpha 49 | * @return Partial alpha that was used for 50 | * evaluating succes or failure of given test. 51 | */ 52 | double getPartialAlpha() const; 53 | 54 | /** 55 | * @brief isPValuePassing Evaluates given p-value 56 | * against partial alpha of the test 57 | * @param pvalue to be evaluated 58 | * @return true if p-value is passing, false otherwise 59 | */ 60 | bool isPValuePassing(double pvalue); 61 | 62 | protected: 63 | /* Variables */ 64 | Logger * logger; 65 | std::string objectInfo; 66 | std::string testName; 67 | std::vector varRes; 68 | std::pair optionalPassed = { true, false }; 69 | double partialAlpha = 0; 70 | 71 | /* Methods */ 72 | ITestResult(Logger * logger , std::string testName) 73 | : logger(logger) , testName(testName) 74 | {} 75 | 76 | void evaluateSetPassed(); 77 | }; 78 | 79 | } // namespace batteries 80 | } // namespace rtt 81 | 82 | #endif // RTT_BATTERIES_ITESTRESULT_H 83 | -------------------------------------------------------------------------------- /rtt/batteries/ivariant-batt.cpp: -------------------------------------------------------------------------------- 1 | #include "ivariant-batt.h" 2 | 3 | #include "rtt/batteries/niststs/variant-sts.h" 4 | #include "rtt/batteries/dieharder/variant-dh.h" 5 | #include "rtt/batteries/testu01/variant-tu01.h" 6 | 7 | #include "rtt/batteries/testrunner-batt.h" 8 | /* For writing output into logfile continuosly. */ 9 | std::mutex outputFile_mux; 10 | 11 | namespace rtt { 12 | namespace batteries { 13 | 14 | std::unique_ptr IVariant::getInstance(int testId, std::string testObjInf, 15 | uint variantIdx, const rtt::GlobalContainer &cont) { 16 | std::unique_ptr rval; 17 | 18 | switch(cont.getRttCliOptions()->getBatteryId()) { 19 | case Constants::BatteryID::NIST_STS: 20 | rval = niststs::Variant::getInstance(testId , testObjInf , variantIdx, cont); 21 | break; 22 | case Constants::BatteryID::DIEHARDER: 23 | rval = dieharder::Variant::getInstance(testId , testObjInf , variantIdx, cont); 24 | break; 25 | case Constants::BatteryID::TU01_SMALLCRUSH: 26 | case Constants::BatteryID::TU01_CRUSH: 27 | case Constants::BatteryID::TU01_BIGCRUSH: 28 | case Constants::BatteryID::TU01_RABBIT: 29 | case Constants::BatteryID::TU01_ALPHABIT: 30 | case Constants::BatteryID::TU01_BLOCK_ALPHABIT: 31 | rval = testu01::Variant::getInstance(testId , testObjInf , variantIdx , cont); 32 | break; 33 | default: 34 | raiseBugException(Strings::ERR_INVALID_BATTERY); 35 | } 36 | rval->buildStrings(); 37 | return rval; 38 | } 39 | 40 | void IVariant::execute() { 41 | /* This method is turned into thread. 42 | * Will deadlock if run without main thread. */ 43 | uint expExitCode = BatteryArg::getExpectedExitCode(battery.getBatteryId()); 44 | 45 | batteryOutput = TestRunner::executeBinary(logger, objectInfo, executablePath, 46 | expExitCode, cliArguments, stdInput); 47 | analyzeAndStoreBattOut(); 48 | 49 | executed = true; 50 | } 51 | 52 | std::string IVariant::getCliArguments() const { 53 | return cliArguments; 54 | } 55 | 56 | std::string IVariant::getStdInput() const { 57 | return stdInput; 58 | } 59 | 60 | 61 | BatteryOutput IVariant::getBatteryOutput() const { 62 | if(executed) 63 | return batteryOutput; 64 | 65 | throw RTTException(objectInfo, Strings::TEST_ERR_NO_EXEC_RES); 66 | } 67 | 68 | int IVariant::getTestId() const { 69 | return testId; 70 | } 71 | 72 | std::string IVariant::getObjectInfo() const { 73 | return objectInfo; 74 | } 75 | 76 | std::vector > IVariant::getUserSettings() const { 77 | return userSettings; 78 | } 79 | 80 | IVariant::IVariant(int testId, std::string testObjInf, uint variantIdx, 81 | const GlobalContainer & cont) { 82 | this->testId = testId; 83 | this->variantIdx = variantIdx; 84 | logger = cont.getLogger(); 85 | battery = cont.getRttCliOptions()->getBatteryArg(); 86 | binaryDataPath = cont.getRttCliOptions()->getInputDataPath(); 87 | executablePath = cont.getToolkitSettings()->getBinaryBattery(battery); 88 | logFilePath = 89 | Utils::getLogFilePath( 90 | cont.getCreationTime(), 91 | cont.getToolkitSettings()->getLoggerBatteryDir(battery), 92 | binaryDataPath, 93 | "", 94 | cont.getRttCliOptions()->hasJid() ? cont.getRttCliOptions()->getJid() : 0); 95 | objectInfo = 96 | testObjInf + 97 | " - variant " + Utils::itostr(variantIdx + 1); 98 | 99 | if(binaryDataPath.empty()) 100 | raiseBugException(Strings::TEST_ERR_NO_BINARY_DATA); 101 | 102 | if(executablePath.empty()) 103 | raiseBugException(Strings::TEST_ERR_NO_EXECUTABLE); 104 | } 105 | 106 | void IVariant::analyzeAndStoreBattOut() { 107 | /* Detect errors and warnings in output */ 108 | batteryOutput.doDetection(); 109 | if(!batteryOutput.getStdErr().empty()) 110 | logger->warn(objectInfo + ": execution of test produced error output."); 111 | if(!batteryOutput.getErrors().empty()) 112 | logger->warn(objectInfo + ": test output contains errors."); 113 | if(!batteryOutput.getWarnings().empty()) 114 | logger->warn(objectInfo + ": test output contains warnings."); 115 | 116 | { 117 | /* Store test output into file */ 118 | std::lock_guard l (outputFile_mux); 119 | std::stringstream stdoutStr; 120 | std::stringstream stderrStr; 121 | auto filler = "=================================================\n"; 122 | stdoutStr << "=== Standard output of thread " << std::this_thread::get_id() << " ===" << std::endl; 123 | stderrStr << "=== Error output of thread " << std::this_thread::get_id() << " ===" << std::endl; 124 | 125 | if(!batteryOutput.getStdOut().empty()) { 126 | Utils::appendStringToFile(logFilePath, filler); 127 | Utils::appendStringToFile(logFilePath, stdoutStr.str()); 128 | Utils::appendStringToFile(logFilePath, batteryOutput.getStdOut()); 129 | } else { 130 | logger->warn(objectInfo + ": standard output of test is empty."); 131 | } 132 | 133 | if(!batteryOutput.getStdErr().empty()) { 134 | Utils::appendStringToFile(logFilePath, filler); 135 | Utils::appendStringToFile(logFilePath, stderrStr.str()); 136 | Utils::appendStringToFile(logFilePath, batteryOutput.getStdErr()); 137 | } 138 | } 139 | } 140 | 141 | 142 | 143 | 144 | 145 | } // namespace batteries 146 | } // namespace rtt 147 | -------------------------------------------------------------------------------- /rtt/batteries/ivariant-batt.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_IVARIANT_H 2 | #define RTT_BATTERIES_IVARIANT_H 3 | 4 | #include "rtt/globalcontainer.h" 5 | #include "rtt/clinterface/batteryarg.h" 6 | #include "rtt/batteries/testconstants.h" 7 | #include "rtt/batteries/batteryoutput.h" 8 | 9 | namespace rtt { 10 | namespace batteries { 11 | 12 | /** 13 | * @brief The IVariant class Holds info about single variant of given test. Can and will be executed. 14 | */ 15 | class IVariant { 16 | public: 17 | /** 18 | * @brief getInstance Initializes an object 19 | * @param testId Id of the test 20 | * @param testObjInf Info about parent object, used for logging 21 | * @param variantIdx Index of the new variant 22 | * @param cont Global settings 23 | * @return Obejct 24 | */ 25 | static std::unique_ptr getInstance(int testId, std::string testObjInf, 26 | uint variantIdx, const GlobalContainer & cont); 27 | 28 | /** 29 | * @brief ~IVariant Desctructor. 30 | */ 31 | virtual ~IVariant() {} 32 | 33 | /** 34 | * @brief execute Executes the variant, should be called only 35 | * from threadManager function, otherwise non-defined behaviour 36 | */ 37 | virtual void execute(); 38 | 39 | /** 40 | * @brief getCliArguments 41 | * @return CLI arguments of the variant that will be sent to the binary 42 | */ 43 | std::string getCliArguments() const; 44 | 45 | /** 46 | * @brief getStdInput 47 | * @return Standard input that will be sent to the binary 48 | */ 49 | std::string getStdInput() const; 50 | 51 | /** 52 | * @brief getBatteryOutput 53 | * @return Output of the execution 54 | */ 55 | BatteryOutput getBatteryOutput() const; 56 | 57 | /** 58 | * @brief getTestId 59 | * @return Test ID 60 | */ 61 | int getTestId() const; 62 | 63 | /** 64 | * @brief getObjectInfo 65 | * @return Info about the object, will be used in logging 66 | */ 67 | std::string getObjectInfo() const; 68 | 69 | /** 70 | * @brief getUserSettings 71 | * @return Settings set by user in battery configuration 72 | */ 73 | std::vector > getUserSettings() const; 74 | 75 | protected: 76 | /* Set in constructor */ 77 | Logger * logger; 78 | std::string objectInfo; 79 | int testId; 80 | uint variantIdx; 81 | clinterface::BatteryArg battery; 82 | std::string binaryDataPath; 83 | std::string logFilePath; 84 | std::string executablePath; 85 | std::string cliArguments; 86 | std::string stdInput; 87 | std::vector> userSettings; 88 | 89 | /* Set after execution */ 90 | BatteryOutput batteryOutput; 91 | bool executed = false; 92 | 93 | IVariant(int testId, std::string testObjInf, 94 | uint variantIdx, const GlobalContainer & cont); 95 | 96 | virtual void buildStrings() = 0; 97 | 98 | void analyzeAndStoreBattOut(); 99 | }; 100 | 101 | } // namespace batteries 102 | } // namespace rtt 103 | 104 | #endif // RTT_BATTERIES_IVARIANT_H 105 | -------------------------------------------------------------------------------- /rtt/batteries/niststs/battery-sts.cpp: -------------------------------------------------------------------------------- 1 | #include "rtt/batteries/niststs/battery-sts.h" 2 | 3 | #include "rtt/batteries/itestresult-batt.h" 4 | 5 | namespace rtt { 6 | namespace batteries { 7 | namespace niststs { 8 | 9 | std::unique_ptr Battery::getInstance(const GlobalContainer & container) { 10 | std::unique_ptr b (new Battery(container)); 11 | return b; 12 | } 13 | 14 | std::vector> Battery::getTestResults() const { 15 | if(!executed) 16 | throw RTTException(objectInfo , Strings::BATT_ERR_NO_EXEC_PROC); 17 | 18 | std::vector> results(tests.size()); 19 | std::transform(tests.begin(), tests.end(), results.begin(), 20 | [](const auto & el){ return ITestResult::getInstance({el.get()}); }); 21 | 22 | return results; 23 | } 24 | 25 | } // namespace niststs 26 | } // namespace batteries 27 | } // namespace rtt 28 | -------------------------------------------------------------------------------- /rtt/batteries/niststs/battery-sts.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_NISTSTS_BATTERY_H 2 | #define RTT_BATTERIES_NISTSTS_BATTERY_H 3 | 4 | #include 5 | 6 | #include "libs/cephes/cephes.h" 7 | #include "rtt/batteries/ibattery-batt.h" 8 | 9 | namespace rtt { 10 | namespace batteries { 11 | namespace niststs { 12 | 13 | class Battery : public IBattery { 14 | public: 15 | static std::unique_ptr getInstance(const GlobalContainer & container); 16 | 17 | std::vector> getTestResults() const; 18 | private: 19 | /* 20 | =============== 21 | *** Methods *** 22 | =============== 23 | */ 24 | Battery(const GlobalContainer & container) 25 | : IBattery(container) {} 26 | }; 27 | 28 | } // namespace niststs 29 | } // namespace batteries 30 | } // namespace rtt 31 | 32 | #endif // RTT_BATTERIES_NISTSTS_BATTERY_H 33 | -------------------------------------------------------------------------------- /rtt/batteries/niststs/test-sts.cpp: -------------------------------------------------------------------------------- 1 | #include "test-sts.h" 2 | 3 | #include "rtt/batteries/niststs/variant-sts.h" 4 | 5 | namespace rtt { 6 | namespace batteries { 7 | namespace niststs { 8 | 9 | std::unique_ptr Test::getInstance(std::string battObjInf, int testIndex, 10 | const GlobalContainer & cont) { 11 | std::unique_ptr t (new Test(battObjInf, testIndex , cont)); 12 | 13 | /* Battery specific code goes here */ 14 | 15 | t->testDir_mux = std::make_unique(); 16 | 17 | for(const std::unique_ptr & var : t->variants) { 18 | Variant * stsVar = dynamic_cast(var.get()); 19 | stsVar->setTestDir_mux(t->testDir_mux.get()); 20 | } 21 | 22 | return t; 23 | } 24 | 25 | } // namespace niststs 26 | } // namespace batteries 27 | } // namespace rtt 28 | -------------------------------------------------------------------------------- /rtt/batteries/niststs/test-sts.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_NISTSTS_TEST_H 2 | #define RTT_BATTERIES_NISTSTS_TEST_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | #include "rtt/batteries/itest-batt.h" 12 | 13 | namespace rtt { 14 | namespace batteries { 15 | namespace niststs { 16 | 17 | class Test : public ITest { 18 | public: 19 | static std::unique_ptr getInstance(std::string battObjInf, int testId , 20 | const GlobalContainer & cont); 21 | 22 | private: 23 | /* Variables */ 24 | std::unique_ptr testDir_mux; 25 | 26 | /* Methods */ 27 | Test(std::string battObjInf, int testIndex, 28 | const GlobalContainer & container) 29 | : ITest(battObjInf, testIndex, container) 30 | {} 31 | }; 32 | 33 | } // namespace niststs 34 | } // namespace batteries 35 | } // namespace rtt 36 | 37 | #endif // RTT_BATTERIES_NISTSTS_TEST_H 38 | -------------------------------------------------------------------------------- /rtt/batteries/niststs/testresult-sts.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_NISTSTS_TESTRESULT_H 2 | #define RTT_BATTERIES_NISTSTS_TESTRESULT_H 3 | 4 | #include "rtt/batteries/itestresult-batt.h" 5 | 6 | #include "rtt/batteries/niststs/variant-sts.h" 7 | 8 | namespace rtt { 9 | namespace batteries { 10 | namespace niststs { 11 | 12 | class TestResult : public ITestResult { 13 | public: 14 | static std::unique_ptr getInstance( 15 | const std::vector & tests); 16 | private: 17 | TestResult(Logger * logger , std::string testName) 18 | : ITestResult(logger , testName) 19 | {} 20 | 21 | static std::vector> getVariantPValues( 22 | Variant * variant); 23 | 24 | static double chi2_stat(std::vector pvals); 25 | }; 26 | 27 | } // namespace niststs 28 | } // namespace batteries 29 | } // namespace rtt 30 | 31 | #endif // RTT_BATTERIES_NISTSTS_TESTRESULT_H 32 | -------------------------------------------------------------------------------- /rtt/batteries/niststs/variant-sts.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_NISTSTS_VARIANT_H 2 | #define RTT_BATTERIES_NISTSTS_VARIANT_H 3 | 4 | #include "rtt/batteries/ivariant-batt.h" 5 | #include "rtt/batteries/testrunner-batt.h" 6 | 7 | namespace rtt { 8 | namespace batteries { 9 | namespace niststs { 10 | 11 | class Variant : public IVariant { 12 | public: 13 | static std::unique_ptr getInstance(int testId, std::string testObjInf, 14 | uint variantIdx, const GlobalContainer & cont); 15 | 16 | void execute(); 17 | 18 | void setTestDir_mux(std::mutex * value); 19 | 20 | std::vector getPValueFiles() const; 21 | 22 | private: 23 | /* Variables */ 24 | std::mutex * testDir_mux; 25 | std::string resultSubDir; 26 | std::string streamSize; 27 | std::string streamCount; 28 | std::string blockLength; 29 | bool adjustableBlockLength; 30 | 31 | /* pvalues will be read into this after execution */ 32 | std::vector pValueFiles; 33 | 34 | /* Methods */ 35 | Variant(int testId, std::string testObjInf, 36 | uint variantIdx, const GlobalContainer & cont) 37 | : IVariant(testId, testObjInf, variantIdx, cont) 38 | {} 39 | 40 | void buildStrings(); 41 | 42 | void readNistStsOutFiles(); 43 | }; 44 | 45 | } // namespace niststs 46 | } // namespace batteries 47 | } // namespace rtt 48 | 49 | #endif // RTT_BATTERIES_NISTSTS_VARIANT_H 50 | -------------------------------------------------------------------------------- /rtt/batteries/result/statistic-res.cpp: -------------------------------------------------------------------------------- 1 | #include "statistic-res.h" 2 | 3 | namespace rtt { 4 | namespace batteries { 5 | namespace result { 6 | 7 | Statistic Statistic::getInstance(const std::string & name, double value) { 8 | if(name.empty()) 9 | raiseBugException("empty statistic name"); 10 | 11 | return Statistic(name, value); 12 | } 13 | 14 | std::string Statistic::getName() const { 15 | return name; 16 | } 17 | 18 | double Statistic::getValue() const { 19 | return value; 20 | } 21 | 22 | } // namespace result 23 | } // namespace batteries 24 | } // namespace rtt 25 | -------------------------------------------------------------------------------- /rtt/batteries/result/statistic-res.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_RESULT_STATISTIC_H 2 | #define RTT_BATTERIES_RESULT_STATISTIC_H 3 | 4 | #include 5 | 6 | #include "rtt/rttexception.h" 7 | 8 | namespace rtt { 9 | namespace batteries { 10 | namespace result { 11 | 12 | /** 13 | * @brief The Statistic class Small class for storing result of a single statistic. 14 | */ 15 | class Statistic { 16 | public: 17 | /** 18 | * @brief getInstance Initializes the object 19 | * @param name Human-readable name of the statistic 20 | * @param value Value of the statistic 21 | * @return instance 22 | */ 23 | static Statistic getInstance(const std::string & name, 24 | double value); 25 | 26 | /** 27 | * @brief getName 28 | * @return Name of the statistic 29 | */ 30 | std::string getName() const; 31 | 32 | /** 33 | * @brief getValue 34 | * @return Value of the statistic 35 | */ 36 | double getValue() const; 37 | 38 | private: 39 | Statistic(const std::string & name, double value) 40 | : name(name), value(value) 41 | {} 42 | 43 | std::string name; 44 | 45 | double value; 46 | }; 47 | 48 | } // namespace result 49 | } // namespace batteries 50 | } // namespace rtt 51 | 52 | #endif // RTT_BATTERIES_RESULT_STATISTIC_H 53 | -------------------------------------------------------------------------------- /rtt/batteries/result/subtestresult-res.cpp: -------------------------------------------------------------------------------- 1 | #include "subtestresult-res.h" 2 | 3 | namespace rtt { 4 | namespace batteries { 5 | namespace result { 6 | 7 | 8 | SubTestResult SubTestResult::getInstance(const std::vector & statistics) { 9 | if(statistics.empty()) 10 | raiseBugException("empty statistics"); 11 | 12 | return SubTestResult(statistics, {}); 13 | } 14 | 15 | SubTestResult SubTestResult::getInstance(const std::vector & statistics, 16 | const std::vector & pvalues) { 17 | if(statistics.empty()) 18 | raiseBugException("empty statistics"); 19 | 20 | return SubTestResult(statistics, pvalues); 21 | } 22 | 23 | std::vector > SubTestResult::getTestParameters() const { 24 | return testParameters; 25 | } 26 | 27 | void SubTestResult::setTestParameters(const std::vector > & value) { 28 | testParameters = value; 29 | } 30 | 31 | std::vector SubTestResult::getPvalues() const { 32 | return pvalues; 33 | } 34 | 35 | std::vector SubTestResult::getStatistics() const { 36 | return statistics; 37 | } 38 | 39 | std::vector SubTestResult::getStatResults() const { 40 | std::vector rval(statistics.size()); 41 | std::transform(statistics.begin(), statistics.end(), rval.begin(), 42 | [](const auto & el){ return el.getValue(); }); 43 | 44 | return rval; 45 | } 46 | 47 | } // namespace result 48 | } // namespace batteries 49 | } // namespace rtt 50 | -------------------------------------------------------------------------------- /rtt/batteries/result/subtestresult-res.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_RESULT_SUBTESTRESULT_H 2 | #define RTT_BATTERIES_RESULT_SUBTESTRESULT_H 3 | 4 | #include "rtt/batteries/result/statistic-res.h" 5 | 6 | namespace rtt { 7 | namespace batteries { 8 | namespace result { 9 | 10 | /** 11 | * @brief The SubTestResult class Class used for storing result of a single subtest. 12 | * Subtest contains at least one statistic and may or may not contain set of p-values. 13 | */ 14 | class SubTestResult { 15 | public: 16 | /** 17 | * @brief getInstance Used for initializing subtest w/out p-values 18 | * @param statistics Set of statistics of the subtest 19 | * @return instance 20 | */ 21 | static SubTestResult getInstance( 22 | const std::vector & statistics); 23 | 24 | /** 25 | * @brief getInstance Used for initializing subtest with p-values 26 | * @param statistics Set of statistics of the subtest 27 | * @param pvalues Set of p-values 28 | * @return instance 29 | */ 30 | static SubTestResult getInstance( 31 | const std::vector & statistics, 32 | const std::vector & pvalues); 33 | 34 | /** 35 | * @brief getTestParameters 36 | * @return Parameters of the subtest 37 | */ 38 | std::vector> getTestParameters() const; 39 | 40 | /** 41 | * @brief setTestParameters 42 | * @param value Parameters of the subtest 43 | */ 44 | void setTestParameters( 45 | const std::vector > & value); 46 | 47 | /** 48 | * @brief getStatResults 49 | * @return Results of all underlying statistics 50 | */ 51 | std::vector getStatResults() const; 52 | 53 | /** 54 | * @brief getPvalues 55 | * @return Set of p-values 56 | */ 57 | std::vector getPvalues() const; 58 | 59 | /** 60 | * @brief getStatistics 61 | * @return All Statistics objects of given subtest 62 | */ 63 | std::vector getStatistics() const; 64 | 65 | private: 66 | SubTestResult(const std::vector & statistics, 67 | const std::vector & pvalues) 68 | : statistics(statistics), pvalues(pvalues) 69 | {} 70 | 71 | std::vector statistics; 72 | 73 | std::vector pvalues; 74 | 75 | std::vector> testParameters; 76 | }; 77 | 78 | } // namespace result 79 | } // namespace batteries 80 | } // namespace rtt 81 | 82 | #endif // RTT_BATTERIES_RESULT_SUBTESTRESULT_H 83 | -------------------------------------------------------------------------------- /rtt/batteries/result/variantresult-res.cpp: -------------------------------------------------------------------------------- 1 | #include "variantresult-res.h" 2 | 3 | namespace rtt { 4 | namespace batteries { 5 | namespace result { 6 | 7 | VariantResult VariantResult::getInstance(const std::vector & subResults, 8 | const std::vector> & userSettings, 9 | const BatteryOutput & battOut) { 10 | return VariantResult(subResults, userSettings, battOut); 11 | } 12 | 13 | std::vector VariantResult::getSubTestStatResults() const { 14 | std::vector rval; 15 | std::vector tmp; 16 | for(const SubTestResult & subRes : subResults) { 17 | tmp = subRes.getStatResults(); 18 | rval.insert(rval.end(), tmp.begin(), tmp.end()); 19 | } 20 | return rval; 21 | } 22 | 23 | std::vector VariantResult::getSubResults() const { 24 | return subResults; 25 | } 26 | 27 | BatteryOutput VariantResult::getBatteryOutput() const { 28 | return battOut; 29 | } 30 | 31 | std::vector> VariantResult::getUserSettings() const { 32 | return userSettings; 33 | } 34 | 35 | } // namespace result 36 | } // namespace batteries 37 | } // namespace rtt 38 | -------------------------------------------------------------------------------- /rtt/batteries/result/variantresult-res.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_RESULT_VARIANTRESULT_H 2 | #define RTT_BATTERIES_RESULT_VARIANTRESULT_H 3 | 4 | #include "rtt/batteries/result/subtestresult-res.h" 5 | #include "rtt/batteries/batteryoutput.h" 6 | 7 | namespace rtt { 8 | namespace batteries { 9 | namespace result { 10 | 11 | /** 12 | * @brief The VariantResult class Used for holding results of single variant of some test 13 | */ 14 | class VariantResult { 15 | public: 16 | /** 17 | * @brief getInstance Creates initialized instance of VariantResult 18 | * @param subResults Results of subtests of this Variant 19 | * @param userSettings Settings created by user in configuration 20 | * @param battOut Output of the battery that will be processed 21 | * @return instance 22 | */ 23 | static VariantResult getInstance( 24 | const std::vector & subResults, 25 | const std::vector> & userSettings, 26 | const BatteryOutput & battOut); 27 | 28 | /** 29 | * @brief getSubTestStatResults 30 | * @return All results of statistics of underlying subtests 31 | */ 32 | std::vector getSubTestStatResults() const; 33 | 34 | /** 35 | * @brief getSubResults 36 | * @return Result objects of underlying subtests 37 | */ 38 | std::vector getSubResults() const; 39 | 40 | /** 41 | * @brief getBatteryOutput 42 | * @return Raw output of battery executable 43 | */ 44 | BatteryOutput getBatteryOutput() const; 45 | 46 | /** 47 | * @brief getUserSettings 48 | * @return Settings chosen by user in configuration file. 49 | */ 50 | std::vector > getUserSettings() const; 51 | 52 | private: 53 | VariantResult(const std::vector & subResults, 54 | const std::vector> & userSettings, 55 | const BatteryOutput & battOut) 56 | : subResults(subResults), userSettings(userSettings), 57 | battOut(battOut) 58 | {} 59 | 60 | std::vector subResults; 61 | std::vector> userSettings; 62 | BatteryOutput battOut; 63 | }; 64 | 65 | } // namespace result 66 | } // namespace batteries 67 | } // namespace rtt 68 | 69 | #endif // RTT_BATTERIES_RESULT_VARIANTRESULT_H 70 | -------------------------------------------------------------------------------- /rtt/batteries/testrunner-batt.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_TESTRUNNER_H 2 | #define RTT_BATTERIES_TESTRUNNER_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #include "rtt/logger.h" 18 | #include "rtt/batteries/ivariant-batt.h" 19 | #include "rtt/batteries/batteryoutput.h" 20 | 21 | namespace rtt { 22 | namespace batteries { 23 | 24 | /** 25 | * @brief The TestRunner class This is static class responsible for execution of given set of tests. 26 | * Multiple tests can be executed at once. 27 | */ 28 | class TestRunner { 29 | public: 30 | 31 | /* Threads overview 32 | * Main thread - Handles incoming signals about 33 | * finished processes, announces finished PIDs. 34 | * Thread manager - Handles starting and joining of process threads. 35 | * Process thread - Starts process and waits for its PID to be announced. 36 | * If PID isn't announced withit TIMEOUT, kills process. 37 | * Also starts reader thread and joins it at the end. 38 | * Reader thread - Reads process pipes. Usually is blocked by read. 39 | * It is important that this thread is running, otherwise 40 | * pipes could be filled up, blocking associated process.*/ 41 | 42 | static const int THREAD_STATE_PENDING = 0; 43 | static const int THREAD_STATE_READY = 1; 44 | static const int THREAD_STATE_DONE = 2; 45 | 46 | /** 47 | * @brief executeTests Called from battery's runTests code. This is main thread, 48 | * creates one threadManager and receives and hands out IDs of 49 | * finished child processes of RTT. 50 | * @param logger pointer to thread-safe logger object 51 | * @param variants all test variants in the battery that will be executed 52 | * @param maxThreads maximum of parallel running threads 53 | * @param testTimeout timeout of single test, after this time, the test will be killed. 54 | */ 55 | static void executeTests(Logger * logger, std::vector & variants, 56 | int maxThreads, int testTimeout); 57 | 58 | /** 59 | * @brief executeBinary Called from test code in method execute. Thread is not created 60 | * directly from this method, but from test's execute. 61 | * @param logger Logger pointer 62 | * @param objectInfo Info about caller, will be used in logging 63 | * @param binaryPath Path to battery executeble binary 64 | * @param expExitCode Expected exit code of the executable 65 | * @param arguments Arguments that will be passed to the executable 66 | * @param input Standard input that will be passed to the created process 67 | * @return Object that holds standard (error) output 68 | */ 69 | static BatteryOutput executeBinary(Logger * logger, 70 | const std::string & objectInfo, 71 | const std::string & binaryPath, 72 | uint expExitCode, 73 | const std::string & arguments, 74 | const std::string & input); 75 | private: 76 | /* Manages creation of maximum number of threads. After creation 77 | * wait for the threads to end and joins them. */ 78 | static void threadManager(std::vector & variants); 79 | 80 | static void readOutput(BatteryOutput & output, 81 | int * stdout_pipe, int * stderr_pipe); 82 | 83 | static char ** buildArgv(const std::string & arguments , int * argc); 84 | 85 | static void destroyArgv(int argc , char ** argv); 86 | }; 87 | 88 | } // namespace batteries 89 | } // namespace rtt 90 | 91 | #endif // RTT_BATTERIES_TESTRUNNER_H 92 | -------------------------------------------------------------------------------- /rtt/batteries/testu01/battery-tu01.cpp: -------------------------------------------------------------------------------- 1 | #include "rtt/batteries/testu01/battery-tu01.h" 2 | 3 | #include "rtt/batteries/itestresult-batt.h" 4 | 5 | namespace rtt { 6 | namespace batteries { 7 | namespace testu01 { 8 | 9 | std::unique_ptr Battery::getInstance(const GlobalContainer & container) { 10 | std::unique_ptr b (new Battery(container)); 11 | return b; 12 | } 13 | 14 | std::vector> Battery::getTestResults() const { 15 | if(!executed) 16 | throw RTTException(objectInfo, Strings::BATT_ERR_NO_EXEC_PROC); 17 | 18 | /* Tests with same name are considered variants of the 19 | * same test and are therefore bundled together. */ 20 | std::vector> results; 21 | std::vector testBatch; 22 | std::string currTestName; 23 | 24 | for(uint i = 0; i < tests.size(); ++i) { 25 | if(currTestName.empty()) 26 | currTestName = tests.at(i)->getLogicName(); 27 | 28 | if(currTestName == tests.at(i)->getLogicName()) { 29 | testBatch.push_back(tests.at(i).get()); 30 | } else { 31 | results.push_back(ITestResult::getInstance(testBatch)); 32 | testBatch.clear(); 33 | currTestName = tests.at(i)->getLogicName(); 34 | testBatch.push_back(tests.at(i).get()); 35 | } 36 | 37 | if(i + 1 == tests.size()) { 38 | results.push_back(ITestResult::getInstance(testBatch)); 39 | } 40 | } 41 | 42 | return results; 43 | } 44 | 45 | } // namespace testu01 46 | } // namespace batteries 47 | } // namespace rtt 48 | 49 | -------------------------------------------------------------------------------- /rtt/batteries/testu01/battery-tu01.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_TESTU01_BATTERY_H 2 | #define RTT_BATTERIES_TESTU01_BATTERY_H 3 | 4 | #include "rtt/batteries/ibattery-batt.h" 5 | 6 | namespace rtt { 7 | namespace batteries { 8 | namespace testu01 { 9 | 10 | class Battery : public IBattery { 11 | public: 12 | static std::unique_ptr getInstance(const GlobalContainer & container); 13 | 14 | std::vector> getTestResults() const; 15 | 16 | private: 17 | /* 18 | =============== 19 | *** Methods *** 20 | =============== 21 | */ 22 | /* So initialization in getInstance can't be avoided */ 23 | Battery(const GlobalContainer & container) 24 | : IBattery(container) {} 25 | }; 26 | 27 | } // namespace testu01 28 | } // namespace batteries 29 | } // namespace rtt 30 | 31 | #endif // RTT_BATTERIES_TESTU01_BATTERY_H 32 | -------------------------------------------------------------------------------- /rtt/batteries/testu01/test-tu01.cpp: -------------------------------------------------------------------------------- 1 | #include "rtt/batteries/testu01/test-tu01.h" 2 | 3 | namespace rtt { 4 | namespace batteries { 5 | namespace testu01 { 6 | 7 | std::unique_ptr Test::getInstance(std::string battObjInf, int testIndex , 8 | const GlobalContainer & container) { 9 | std::unique_ptr t (new Test(battObjInf, testIndex , container)); 10 | 11 | /* Battery specific code goes here */ 12 | 13 | return t; 14 | } 15 | 16 | } // namespace testu01 17 | } // namespace batteries 18 | } // namespace rtt 19 | 20 | -------------------------------------------------------------------------------- /rtt/batteries/testu01/test-tu01.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_TESTU01_TEST_H 2 | #define RTT_BATTERIES_TESTU01_TEST_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "rtt/batteries/itest-batt.h" 11 | 12 | namespace rtt { 13 | namespace batteries { 14 | namespace testu01 { 15 | 16 | /* Typedefs for parameter types */ 17 | typedef std::pair tParam; 18 | typedef std::vector tStringVector; 19 | 20 | class Test : public ITest { 21 | public: 22 | static std::unique_ptr getInstance(std::string battObjInf, int testId , 23 | const GlobalContainer & container); 24 | private: 25 | 26 | /* Methods */ 27 | Test(std::string battObjInf, int testIndex, 28 | const GlobalContainer & container) 29 | : ITest(battObjInf, testIndex , container) 30 | {} 31 | }; 32 | 33 | } // namespace testu01 34 | } // namespace batteries 35 | } // namespace rtt 36 | 37 | #endif // RTT_BATTERIES_TESTU01_TEST_H 38 | -------------------------------------------------------------------------------- /rtt/batteries/testu01/testresult-tu01.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_TESTU01_TESTRESULT_H 2 | #define RTT_BATTERIES_TESTU01_TESTRESULT_H 3 | 4 | #include "rtt/batteries/itestresult-batt.h" 5 | 6 | #include "rtt/batteries/testu01/variant-tu01.h" 7 | 8 | namespace rtt { 9 | namespace batteries { 10 | namespace testu01 { 11 | 12 | class TestResult : public ITestResult { 13 | public: 14 | static std::unique_ptr getInstance( 15 | const std::vector & tests); 16 | 17 | private: 18 | BatteryArg battery; 19 | 20 | TestResult(Logger * logger , std::string testName) 21 | : ITestResult(logger , testName) 22 | {} 23 | 24 | static boost::regex buildParamRegex( 25 | std::vector paramNames); 26 | 27 | static double convertStringToDouble(const std::string & num, 28 | const std::string & oneMinus); 29 | 30 | std::vector extractStatistics( 31 | const std::string & testLog, 32 | std::vector statNames); 33 | 34 | std::vector > extractTestParameters( 35 | const std::string & testLog, 36 | std::vector paramNames); 37 | 38 | std::vector extractPValues(const std::string & testLog); 39 | std::string extractProblems(const std::string & testLog); 40 | }; 41 | 42 | } // namespace testu01 43 | } // namespace batteries 44 | } // namespace rtt 45 | 46 | #endif // RTT_BATTERIES_TESTU01_TESTRESULT_H 47 | -------------------------------------------------------------------------------- /rtt/batteries/testu01/variant-tu01.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BATTERIES_TESTU01_VARIANT_H 2 | #define RTT_BATTERIES_TESTU01_VARIANT_H 3 | 4 | #include "rtt/batteries/ivariant-batt.h" 5 | 6 | namespace rtt { 7 | namespace batteries { 8 | namespace testu01 { 9 | 10 | /* Typedefs for parameter types */ 11 | typedef std::pair tParam; 12 | 13 | class Variant : public IVariant { 14 | public: 15 | static std::unique_ptr getInstance(int testId, std::string testObjInf, 16 | uint variantIdx, const GlobalContainer & cont); 17 | 18 | 19 | std::vector getStatisticNames() const; 20 | 21 | std::vector getExtractableParamNames() const; 22 | 23 | private: 24 | /* TestU01 specific */ 25 | std::vector settableParamNames; 26 | std::vector extractableParamNames; 27 | std::vector statisticNames; 28 | int repetitions; 29 | /* Only used in configuration of crush batteries */ 30 | std::vector params; 31 | /* Used in rabbit/alphabit battery */ 32 | std::string bit_nb; 33 | std::string bit_r; 34 | std::string bit_s; 35 | std::string bit_w; 36 | 37 | /* Methods */ 38 | Variant(int testId, std::string testObjInf, 39 | uint variantIdx, const GlobalContainer & cont) 40 | : IVariant(testId, testObjInf, variantIdx, cont) 41 | {} 42 | 43 | void buildStrings(); 44 | }; 45 | 46 | } // namespace testu01 47 | } // namespace batteries 48 | } // namespace rtt 49 | 50 | #endif // RTT_BATTERIES_TESTU01_VARIANT_H 51 | -------------------------------------------------------------------------------- /rtt/bugexception.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_BUGEXCEPTION 2 | #define RTT_BUGEXCEPTION 3 | 4 | #include 5 | #include 6 | 7 | #include "rtt/utils.h" 8 | 9 | /* I don't like macros either... */ 10 | #define raiseBugException(message) \ 11 | throw BugException(std::string(__FILE__) , rtt::Utils::itostr(__LINE__) , message) 12 | 13 | namespace rtt { 14 | 15 | /** 16 | * @brief The BugException class Thrown on assertions that should never 17 | * happen during normal run. Probably indicates bug caused by developer. 18 | * Should be called via macro raiseBugException that will add filename and line 19 | * into the message. 20 | */ 21 | class BugException : public std::logic_error { 22 | public: 23 | BugException(const std::string & file , 24 | const std::string & line , 25 | const std::string & message) 26 | : std::logic_error(file + ":" + line + " - " + message) 27 | {} 28 | }; 29 | 30 | } // namespace rtt 31 | 32 | #endif // RTT_BUGEXCEPTION 33 | 34 | -------------------------------------------------------------------------------- /rtt/clinterface/batteryarg.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_CLINTERFACE_BATTERYARG_H 2 | #define RTT_CLINTERFACE_BATTERYARG_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "rtt/constants.h" 9 | #include "rtt/bugexception.h" 10 | 11 | namespace rtt { 12 | namespace clinterface { 13 | 14 | /** 15 | * @brief The BatteryArg class Stores battery chosen via 16 | * command line and information about the battery such as name, 17 | * short_name (command line) and type of the battery. 18 | */ 19 | class BatteryArg { 20 | public: 21 | BatteryArg(); 22 | 23 | BatteryArg(const std::string & battery); 24 | 25 | static std::string getName(Constants::BatteryID batteryId); 26 | 27 | static std::string getShortName(Constants::BatteryID batteryId); 28 | 29 | static uint getExpectedExitCode(Constants::BatteryID batteryId); 30 | 31 | Constants::BatteryID getBatteryId() const; 32 | 33 | std::string getName() const; 34 | 35 | std::string getShortName() const; 36 | 37 | uint getExpectedExitCode() const; 38 | 39 | bool isInTU01Family() const; 40 | 41 | bool isInTU01CrushFamily() const; 42 | 43 | bool isInTU01BitFamily() const; 44 | 45 | bool isInTU01AlphabitFamily() const; 46 | 47 | friend std::istream & operator>> (std::istream & is, BatteryArg & b) { 48 | std::string battery; 49 | is >> battery; 50 | if(!is.eof() || is.fail()) 51 | return is; 52 | 53 | b.init(battery); 54 | return is; 55 | } 56 | 57 | friend std::ostream & operator<< (std::ostream & os, const BatteryArg & b) { 58 | b.initCheck(); 59 | 60 | os << b.name; 61 | return os; 62 | } 63 | 64 | private: 65 | bool initialized = false; 66 | Constants::BatteryID batteryId; 67 | std::string name; 68 | std::string shortName; 69 | uint expectedExitCode; 70 | 71 | static Constants::BatteryID getBatteryIdFromShortName(const std::string & shortName); 72 | 73 | void init(const std::string & shortName); 74 | 75 | void initCheck() const; 76 | }; 77 | 78 | } // namespace clinterface 79 | } // namespace rtt 80 | 81 | #endif // RTT_CLINTERFACE_BATTERYARG_H 82 | -------------------------------------------------------------------------------- /rtt/clinterface/clargument.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_CLINTERFACE_CLARGUMENT_H 2 | #define RTT_CLINTERFACE_CLARGUMENT_H 3 | 4 | #include 5 | 6 | #include "rtt/rttexception.h" 7 | #include "rtt/utils.h" 8 | 9 | namespace rtt { 10 | namespace clinterface { 11 | 12 | /** 13 | * @brief The ClArgument class Object for command line argument of type ArgumentType. 14 | * Stores the argument and its values. Must be set before value extraction. Can be optional. 15 | */ 16 | template 17 | class ClArgument { 18 | public: 19 | /** 20 | * @brief ClArgument Creates unset argument object 21 | * @param argName Name of the argument 22 | * @param opt Optionality 23 | */ 24 | ClArgument(std::string argName, bool opt = false); 25 | 26 | /** 27 | * @brief ClArgument Creates set argument object 28 | * @param argName Name of the argument 29 | * @param argValue Value of the argument 30 | * @param opt Optionality 31 | */ 32 | ClArgument(std::string argName, const std::string & argValue, bool opt = false); 33 | 34 | /** 35 | * @brief getArgumentValue Will return the value if was set. RTTException otherwise. 36 | * @return Value of the argument. 37 | */ 38 | ArgumentType getArgumentValue() const; 39 | 40 | /** 41 | * @brief setArgumentValue Sets the value of the argument. If the value is already set, 42 | * exception is thrown. 43 | * @param argValue 44 | */ 45 | void setArgumentValue(const std::string & argValue); 46 | 47 | /** 48 | * @brief getArgumentName 49 | * @return Name of the argument. 50 | */ 51 | std::string getArgumentName() const { 52 | return argumentName; 53 | } 54 | 55 | /** 56 | * @brief isValid 57 | * @return Will return false if the argument is neither optional nor set. True otherwise. 58 | */ 59 | bool isValid() const { 60 | return (optional || set); 61 | } 62 | 63 | /** 64 | * @brief isOptional 65 | * @return True if optional, false otherwise. 66 | */ 67 | bool isOptional() const { 68 | return optional; 69 | } 70 | 71 | /** 72 | * @brief isSet 73 | * @return True if set, false otherwise. 74 | */ 75 | bool isSet() const { 76 | return set; 77 | } 78 | 79 | private: 80 | ClArgument() {} 81 | 82 | std::string objectInfo; 83 | std::string argumentName; 84 | ArgumentType argumentValue; 85 | bool optional = false; 86 | bool set = false; 87 | }; 88 | 89 | template 90 | ClArgument::ClArgument(std::string argName, bool opt) 91 | : argumentName(argName), optional(opt) 92 | { 93 | objectInfo = "command line argument \"" + argumentName + "\""; 94 | } 95 | 96 | template 97 | ClArgument::ClArgument(std::string argName, const std::string & argValue, bool opt) 98 | : ClArgument(argName, opt) 99 | { 100 | setArgumentValue(argValue); 101 | } 102 | 103 | template 104 | ArgumentType ClArgument::getArgumentValue() const { 105 | if(set) { 106 | return argumentValue; 107 | } else { 108 | throw RTTException(objectInfo, "value is not set"); 109 | } 110 | } 111 | 112 | template 113 | static T lexical_cast(const std::string & str) { 114 | T rval; 115 | std::istringstream iss; 116 | iss.str(str); 117 | 118 | iss >> rval; 119 | 120 | if(!iss.eof() || iss.fail()) 121 | throw std::runtime_error("can't convert \"" + str + "\""); 122 | 123 | return rval; 124 | } 125 | 126 | template<> 127 | std::string lexical_cast(const std::string & str) { 128 | std::string rval; 129 | std::istringstream iss; 130 | iss.str(str); 131 | 132 | // for string, do not stop at the first whitespace 133 | std::getline(iss, rval); 134 | 135 | if(!iss.eof() || iss.fail()) 136 | throw std::runtime_error("can't convert \"" + str + "\""); 137 | 138 | return rval; 139 | } 140 | 141 | template 142 | void ClArgument::setArgumentValue(const std::string & argValue) { 143 | if(!set) { 144 | try { 145 | argumentValue = lexical_cast(argValue); 146 | set = true; 147 | } catch (std::runtime_error & e) { 148 | throw RTTException(objectInfo, e.what()); 149 | } 150 | } else { 151 | throw RTTException(objectInfo, "value can't be set multiple times"); 152 | } 153 | } 154 | 155 | 156 | } // namespace clinterface 157 | } // namespace rtt 158 | 159 | #endif // RTT_CLINTERFACE_CLARGUMENT_H 160 | -------------------------------------------------------------------------------- /rtt/clinterface/resultstoragearg.cpp: -------------------------------------------------------------------------------- 1 | #include "resultstoragearg.h" 2 | 3 | namespace rtt { 4 | namespace clinterface { 5 | 6 | ResultStorageArg::ResultStorageArg() {} 7 | 8 | ResultStorageArg::ResultStorageArg(const std::string & resultStorage) { 9 | init(resultStorage); 10 | } 11 | 12 | std::string ResultStorageArg::getName(Constants::ResultStorageID rsId) { 13 | switch(rsId) { 14 | case Constants::ResultStorageID::FILE_REPORT: 15 | return "File (report) storage"; 16 | case Constants::ResultStorageID::DB_MYSQL: 17 | return "Database (MySQL) storage"; 18 | default: 19 | raiseBugException("invalid result storage id"); 20 | } 21 | } 22 | 23 | std::string ResultStorageArg::getShortName(Constants::ResultStorageID rsId) { 24 | switch(rsId) { 25 | case Constants::ResultStorageID::FILE_REPORT: 26 | return "file_report"; 27 | case Constants::ResultStorageID::DB_MYSQL: 28 | return "db_mysql"; 29 | default: 30 | raiseBugException("invalid result storage id"); 31 | } 32 | } 33 | 34 | std::string ResultStorageArg::getDefaultShortName() { 35 | return getShortName(Constants::ResultStorageID::FILE_REPORT); 36 | } 37 | 38 | Constants::ResultStorageID ResultStorageArg::getResultStorageId() const { 39 | initCheck(); 40 | 41 | return resultStorageId; 42 | } 43 | 44 | std::string ResultStorageArg::getName() { 45 | initCheck(); 46 | 47 | return name; 48 | } 49 | 50 | std::string ResultStorageArg::getShortName() { 51 | initCheck(); 52 | 53 | return shortName; 54 | } 55 | 56 | Constants::ResultStorageID ResultStorageArg::getResultStorageIdFromShortName( 57 | const std::string & shortName) { 58 | Constants::ResultStorageID rsId; 59 | for(int i = 1; i < static_cast(Constants::ResultStorageID::LAST_ITEM); ++i) { 60 | rsId = static_cast(i); 61 | if(shortName == getShortName(rsId)) 62 | return rsId; 63 | } 64 | throw std::runtime_error("unknown result storage argument: " + shortName); 65 | } 66 | 67 | void ResultStorageArg::init(const std::string & shortName) { 68 | if(initialized) 69 | raiseBugException("ResultStorageArg is already initialized"); 70 | 71 | resultStorageId = getResultStorageIdFromShortName(shortName); 72 | this->shortName = shortName; 73 | name = getName(resultStorageId); 74 | initialized = true; 75 | } 76 | 77 | void ResultStorageArg::initCheck() const { 78 | if(!initialized) 79 | raiseBugException("ResultStorageArg is not initialized"); 80 | } 81 | 82 | } // namespace clinterface 83 | } // namespace rtt 84 | -------------------------------------------------------------------------------- /rtt/clinterface/resultstoragearg.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_CLINTERFACE_RESULTSTORAGEARG_H 2 | #define RTT_CLINTERFACE_RESULTSTORAGEARG_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "rtt/constants.h" 9 | #include "rtt/bugexception.h" 10 | 11 | namespace rtt { 12 | namespace clinterface { 13 | 14 | /** 15 | * @brief The ResultStorageArg class Stores information about the chosen storage. 16 | * Stored information: ID, name, short name (cli) 17 | */ 18 | class ResultStorageArg { 19 | public: 20 | ResultStorageArg(); 21 | 22 | ResultStorageArg(const std::string & resultStorage); 23 | 24 | static std::string getName(Constants::ResultStorageID rsId); 25 | 26 | static std::string getShortName(Constants::ResultStorageID rsId); 27 | 28 | static std::string getDefaultShortName(); 29 | 30 | Constants::ResultStorageID getResultStorageId() const; 31 | 32 | std::string getName(); 33 | 34 | std::string getShortName(); 35 | 36 | friend std::istream & operator>> (std::istream & is, ResultStorageArg & rs) { 37 | std::string resultStorage; 38 | is >> resultStorage; 39 | if(!is.eof() || is.fail()) 40 | return is; 41 | 42 | rs.init(resultStorage); 43 | return is; 44 | } 45 | 46 | friend std::ostream & operator<< (std::ostream & os, const ResultStorageArg & rs) { 47 | rs.initCheck(); 48 | 49 | os << rs.name; 50 | return os; 51 | } 52 | 53 | private: 54 | bool initialized = false; 55 | Constants::ResultStorageID resultStorageId; 56 | std::string name; 57 | std::string shortName; 58 | 59 | static Constants::ResultStorageID getResultStorageIdFromShortName( 60 | const std::string & shortName); 61 | 62 | void init(const std::string & shortName); 63 | 64 | void initCheck() const; 65 | }; 66 | 67 | } // namespace clinterface 68 | } // namespace rtt 69 | 70 | #endif // RTT_CLINTERFACE_RESULTSTORAGEARG_H 71 | -------------------------------------------------------------------------------- /rtt/constants.cpp: -------------------------------------------------------------------------------- 1 | #include "rtt/constants.h" 2 | 3 | namespace rtt { 4 | 5 | /* Constant definition */ 6 | const std::string Constants::FILE_TOOLKIT_SETTINGS = "./rtt-settings.json"; 7 | 8 | const double Constants::MATH_ALPHA = 0.01; 9 | const double Constants::MATH_EPS = 1e-8; 10 | 11 | //std::string Constants::batteryToString(Battery battId) { 12 | // switch(battId) { 13 | // case Battery::DIEHARDER: 14 | // return "Dieharder"; 15 | // case Battery::NIST_STS: 16 | // return "NIST Statistical Test Suite"; 17 | // case Battery::TU01_SMALLCRUSH: 18 | // return "TestU01 Small Crush"; 19 | // case Battery::TU01_CRUSH: 20 | // return "TestU01 Crush"; 21 | // case Battery::TU01_BIGCRUSH: 22 | // return "TestU01 Big Crush"; 23 | // case Battery::TU01_RABBIT: 24 | // return "TestU01 Rabbit"; 25 | // case Battery::TU01_ALPHABIT: 26 | // return "TestU01 Alphabit"; 27 | // case Battery::TU01_BLOCK_ALPHABIT: 28 | // return "TestU01 Block Alphabit"; 29 | // default: 30 | // raiseBugException(Strings::ERR_INVALID_BATTERY); 31 | // } 32 | //} 33 | 34 | //std::string Constants::batteryToShortString(Battery battId) { 35 | // switch(battId) { 36 | // case Battery::DIEHARDER: 37 | // return "dieharder"; 38 | // case Battery::NIST_STS: 39 | // return "nist_sts"; 40 | // case Battery::TU01_SMALLCRUSH: 41 | // return "tu01_smallcrush"; 42 | // case Battery::TU01_CRUSH: 43 | // return "tu01_crush"; 44 | // case Battery::TU01_BIGCRUSH: 45 | // return "tu01_bigcrush"; 46 | // case Battery::TU01_RABBIT: 47 | // return "tu01_rabbit"; 48 | // case Battery::TU01_ALPHABIT: 49 | // return "tu01_alphabit"; 50 | // case Battery::TU01_BLOCK_ALPHABIT: 51 | // return "tu01_blockalphabit"; 52 | // default: 53 | // raiseBugException(Strings::ERR_INVALID_BATTERY); 54 | // } 55 | //} 56 | 57 | //uint Constants::getBatteryExpExitCode(Battery battId) { 58 | // switch(battId) { 59 | // case Battery::DIEHARDER: 60 | // return 0; 61 | // case Battery::NIST_STS: 62 | // return 256; 63 | // case Battery::TU01_SMALLCRUSH: 64 | // case Battery::TU01_CRUSH: 65 | // case Battery::TU01_BIGCRUSH: 66 | // case Battery::TU01_RABBIT: 67 | // case Battery::TU01_ALPHABIT: 68 | // case Battery::TU01_BLOCK_ALPHABIT: 69 | // return 0; 70 | // default: 71 | // raiseBugException(Strings::ERR_INVALID_BATTERY); 72 | // } 73 | //} 74 | 75 | //bool Constants::isInTU01Family(Constants::Battery battId) { 76 | // switch(battId) { 77 | // case Battery::NIST_STS: 78 | // case Battery::DIEHARDER: 79 | // return false; 80 | // case Battery::TU01_SMALLCRUSH: 81 | // case Battery::TU01_CRUSH: 82 | // case Battery::TU01_BIGCRUSH: 83 | // case Battery::TU01_RABBIT: 84 | // case Battery::TU01_ALPHABIT: 85 | // case Battery::TU01_BLOCK_ALPHABIT: 86 | // return true; 87 | // default: 88 | // raiseBugException(Strings::ERR_INVALID_BATTERY); 89 | // } 90 | //} 91 | 92 | //bool Constants::isInTU01CrushFamily(Constants::Battery battId) { 93 | // switch(battId) { 94 | // case Battery::DIEHARDER: 95 | // case Battery::NIST_STS: 96 | // case Battery::TU01_RABBIT: 97 | // case Battery::TU01_ALPHABIT: 98 | // case Battery::TU01_BLOCK_ALPHABIT: 99 | // return false; 100 | // case Battery::TU01_SMALLCRUSH: 101 | // case Battery::TU01_CRUSH: 102 | // case Battery::TU01_BIGCRUSH: 103 | // return true; 104 | // default: 105 | // raiseBugException(Strings::ERR_INVALID_BATTERY); 106 | // } 107 | //} 108 | 109 | //bool Constants::isInTU01BitFamily(Constants::Battery battId) { 110 | // switch(battId) { 111 | // case Battery::DIEHARDER: 112 | // case Battery::NIST_STS: 113 | // case Battery::TU01_SMALLCRUSH: 114 | // case Battery::TU01_CRUSH: 115 | // case Battery::TU01_BIGCRUSH: 116 | // return false; 117 | // case Battery::TU01_RABBIT: 118 | // case Battery::TU01_ALPHABIT: 119 | // case Battery::TU01_BLOCK_ALPHABIT: 120 | // return true; 121 | // default: 122 | // raiseBugException(Strings::ERR_INVALID_BATTERY); 123 | // } 124 | //} 125 | 126 | //bool Constants::isinTU01AlphabitFamily(Constants::Battery battId) { 127 | // switch(battId) { 128 | // case Battery::DIEHARDER: 129 | // case Battery::NIST_STS: 130 | // case Battery::TU01_SMALLCRUSH: 131 | // case Battery::TU01_CRUSH: 132 | // case Battery::TU01_BIGCRUSH: 133 | // case Battery::TU01_RABBIT: 134 | // return false; 135 | // case Battery::TU01_ALPHABIT: 136 | // case Battery::TU01_BLOCK_ALPHABIT: 137 | // return true; 138 | // default: 139 | // raiseBugException(Strings::ERR_INVALID_BATTERY); 140 | // } 141 | //} 142 | 143 | } // namespace rtt 144 | -------------------------------------------------------------------------------- /rtt/constants.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_CONSTANTS_H 2 | #define RTT_CONSTANTS_H 3 | 4 | #include "rtt/strings.h" 5 | #include "rtt/bugexception.h" 6 | //#include "rtt/utils.h" 7 | 8 | namespace rtt { 9 | 10 | /** 11 | * @brief The Constants class contains global constants that are widely used 12 | */ 13 | class Constants { 14 | public: 15 | /* Statistical batteries constants enum */ 16 | /* Values in enum MUST NOT have assigned other than default values 17 | * (first is one). Item LAST_ITEM HAVE to be last. Always! 18 | * Additional battery item MUST be added before it. */ 19 | /* LAST_ITEM must be last because them enums are occasionally iterated 20 | * and the element serves as ending. */ 21 | enum class BatteryID { 22 | DIEHARDER = 1, 23 | NIST_STS, 24 | TU01_SMALLCRUSH, 25 | TU01_CRUSH, 26 | TU01_BIGCRUSH, 27 | TU01_RABBIT, 28 | TU01_ALPHABIT, 29 | TU01_BLOCK_ALPHABIT, 30 | LAST_ITEM 31 | }; 32 | 33 | enum class ResultStorageID { 34 | FILE_REPORT = 1, 35 | DB_MYSQL, 36 | LAST_ITEM 37 | }; 38 | 39 | /* Default files locations */ 40 | static const std::string FILE_TOOLKIT_SETTINGS; 41 | 42 | /* Math values */ 43 | static const double MATH_ALPHA; 44 | static const double MATH_EPS; 45 | 46 | /** 47 | * @brief batteryToString 48 | * @param battId 49 | * @return human readable string identifying the battery 50 | */ 51 | //static std::string batteryToString(Battery battId); 52 | 53 | /** 54 | * @brief batteryToShortString 55 | * @param battId id 56 | * @return short string identifying the battery, used in filenames 57 | */ 58 | //static std::string batteryToShortString(Battery battId); 59 | 60 | /** 61 | * @brief getBatteryExpExitCode 62 | * @param battId 63 | * @return Expected exit code of the battery executable binary 64 | */ 65 | //static uint getBatteryExpExitCode(Battery battId); 66 | 67 | /** 68 | * @brief isInTU01Family Checks whether given battery is in TestU01 family of batteries 69 | * @param battId 70 | * @return 71 | */ 72 | //static bool isInTU01Family(Battery battId); 73 | 74 | /** 75 | * @brief isInTU01CrushFamily Checks whether given battery is in TestU01 Crush family of batteries 76 | * @param battId 77 | * @return 78 | */ 79 | //static bool isInTU01CrushFamily(Battery battId); 80 | 81 | /** 82 | * @brief isInTU01BitFamily Checks whether given battery is in 83 | * TestU01 Bit (rabbit, alphabit, block alphabit) family of batteries 84 | * @param battId 85 | * @return 86 | */ 87 | //static bool isInTU01BitFamily(Battery battId); 88 | 89 | /** 90 | * @brief isinTU01AlphabitFamily Checks whether given battery is in 91 | * TestU01 Alphabit (alphabit, block alphabit) family of batteries 92 | * @param battId 93 | * @return 94 | */ 95 | //static bool isinTU01AlphabitFamily(Battery battId); 96 | 97 | private: 98 | Constants () {} 99 | }; 100 | 101 | } // namespace rtt 102 | 103 | #endif // RTT_CONSTANTS_H 104 | 105 | -------------------------------------------------------------------------------- /rtt/globalcontainer.cpp: -------------------------------------------------------------------------------- 1 | #include "globalcontainer.h" 2 | 3 | namespace rtt { 4 | 5 | 6 | void GlobalContainer::initRttCliOptions(int argc, char * argv[]) { 7 | using namespace clinterface; 8 | rttCliOptions = 9 | std::make_unique(RTTCliOptions::getInstance(argc , argv)); 10 | } 11 | 12 | void GlobalContainer::initToolkitSettings(const std::string & filename) { 13 | toolkitSettings = 14 | std::make_unique(ToolkitSettings::getInstance(filename)); 15 | } 16 | 17 | void GlobalContainer::initBatteriesConfiguration(const std::string & filename) { 18 | using namespace batteries; 19 | batteryConfiguration = 20 | std::make_unique(Configuration::getInstance(filename)); 21 | } 22 | 23 | void GlobalContainer::initLogger(const std::string & logId, bool toCout) { 24 | if(rttCliOptions == nullptr) 25 | raiseBugException("can't initialize logger before command line options are init'd"); 26 | if(toolkitSettings == nullptr) 27 | raiseBugException("can't initialize logger before toolkit settings are init'd"); 28 | 29 | auto logFilePath = Utils::getLogFilePath(creationTime, 30 | toolkitSettings->getLoggerRunLogDir(), 31 | rttCliOptions->getInputDataPath(), 32 | rttCliOptions->getBatteryArg().getShortName(), 33 | rttCliOptions->hasJid() ? rttCliOptions->getJid() : 0 34 | ); 35 | 36 | logger = std::unique_ptr(new Logger(logId , logFilePath , toCout)); 37 | } 38 | 39 | clinterface::RTTCliOptions * GlobalContainer::getRttCliOptions() const { 40 | if(rttCliOptions == nullptr) 41 | raiseBugException("rttCliOptions were not initialized"); 42 | 43 | return rttCliOptions.get(); 44 | } 45 | 46 | ToolkitSettings * GlobalContainer::getToolkitSettings() const { 47 | if(toolkitSettings == nullptr) 48 | raiseBugException("toolkitSettings were not initialized"); 49 | 50 | return toolkitSettings.get(); 51 | } 52 | 53 | batteries::Configuration * GlobalContainer::getBatteryConfiguration() const { 54 | if(batteryConfiguration == nullptr) 55 | raiseBugException("batteryConfiguration was not initialized"); 56 | 57 | return batteryConfiguration.get(); 58 | } 59 | 60 | Logger * GlobalContainer::getLogger() const { 61 | if(logger == nullptr) 62 | raiseBugException("logger was not initialized"); 63 | 64 | return logger.get(); 65 | } 66 | 67 | time_t GlobalContainer::getCreationTime() const { 68 | return creationTime; 69 | } 70 | 71 | 72 | } // namespace rtt 73 | -------------------------------------------------------------------------------- /rtt/globalcontainer.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_GLOBALCONTAINER_H 2 | #define RTT_GLOBALCONTAINER_H 3 | 4 | #include 5 | 6 | #include "rtt/clinterface/rttclioptions.h" 7 | #include "rtt/toolkitsettings.h" 8 | #include "rtt/batteries/configuration-batt.h" 9 | #include "rtt/logger.h" 10 | 11 | namespace rtt { 12 | 13 | /** 14 | * @brief The GlobalContainer class Class that unifies objects 15 | * that are widely used thorough application 16 | * so that only one object is passed to other classes. Should be passed 17 | * as constant reference, only holds pointers to other objects. Before 18 | * calling getter on desired object, it must be first initialized using 19 | * init methods. Init only calls class' constructor or getInstance 20 | * method and creates an unique pointer. 21 | */ 22 | class GlobalContainer { 23 | public: 24 | GlobalContainer() 25 | : creationTime(Utils::getRawTime()) {} 26 | 27 | /** 28 | * @brief initCliOptions Initializes CliOptions object, will 29 | * parse command line arguments of the program 30 | * @param argc 31 | * @param argv 32 | */ 33 | void initRttCliOptions(int argc , char * argv[]); 34 | 35 | /** 36 | * @brief initToolkitSettings Initializes ToolkitSettings object, 37 | * will read configuration file with said settings. 38 | * @param filename 39 | */ 40 | void initToolkitSettings(const std::string & filename); 41 | 42 | /** 43 | * @brief initBatteriesConfiguration Initializes BatteriesConfiguration object, 44 | * will read configuration file. 45 | * @param filename 46 | */ 47 | void initBatteriesConfiguration(const std::string & filename); 48 | 49 | /** 50 | * @brief initLogger Initializes logger object. 51 | * @param logId Unique id of the logged 52 | * @param toCout Sets whether the log will be also written to standard output 53 | */ 54 | void initLogger(const std::string & logId , bool toCout); 55 | 56 | /** 57 | * @brief getCreationTime 58 | * @return Raw time of creation of the class instance 59 | */ 60 | time_t getCreationTime() const; 61 | 62 | /** 63 | * @brief getCliOptions 64 | * @return CliOptions pointer, bug exception if not initialized 65 | */ 66 | clinterface::RTTCliOptions * getRttCliOptions() const; 67 | 68 | /** 69 | * @brief getToolkitSettings 70 | * @return ToolkitSettings pointer, bug exception if not initialized. 71 | */ 72 | ToolkitSettings * getToolkitSettings() const; 73 | 74 | /** 75 | * @brief getBatteryConfiguration 76 | * @return BatteryConfiguration pointer, bug exception if not initialized 77 | */ 78 | batteries::Configuration * getBatteryConfiguration() const; 79 | 80 | /** 81 | * @brief getLogger 82 | * @return Logger pointer, bug exception if not initialized 83 | */ 84 | Logger * getLogger() const; 85 | 86 | private: 87 | /* Application start time, will be used in naming files, etc. */ 88 | time_t creationTime; 89 | //std::unique_ptr cliOptions; 90 | std::unique_ptr rttCliOptions; 91 | std::unique_ptr toolkitSettings; 92 | std::unique_ptr batteryConfiguration; 93 | std::unique_ptr logger; 94 | }; 95 | 96 | } // namespace rtt 97 | 98 | #endif // RTT_GLOBALCONTAINER_H 99 | -------------------------------------------------------------------------------- /rtt/logger.cpp: -------------------------------------------------------------------------------- 1 | #include "logger.h" 2 | 3 | #include "rtt/bugexception.h" 4 | #include "rtt/utils.h" 5 | #include "rtt/version.h" 6 | 7 | namespace rtt { 8 | 9 | Logger::Logger(const std::string &logId, const std::string &logFile, bool toCout) { 10 | /* Empty to make header, will be set later */ 11 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::Format, "%msg"); 12 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::Filename, 13 | logFile); 14 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::Enabled, 15 | "true"); 16 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::ToFile, 17 | "true"); 18 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::MillisecondsWidth, 19 | "1"); 20 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::PerformanceTracking, 21 | "false"); 22 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::MaxLogFileSize, 23 | "10485760"); /* 10MB */ 24 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::LogFlushThreshold, 25 | "100"); 26 | if(toCout) 27 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::ToStandardOutput, 28 | "true"); 29 | else 30 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::ToStandardOutput, 31 | "false"); 32 | 33 | rawLogger = el::Loggers::getLogger(logId); 34 | 35 | el::Loggers::reconfigureLogger(rawLogger , rawLoggerConf); 36 | 37 | /* Writing log header */ 38 | rawLogger->info("\nRandomness Testing Toolkit logger start."); 39 | rawLogger->info("Application build "+ (std::string)GIT_COMMIT_SHORT); 40 | rawLogger->info("Logger name " + logId); 41 | rawLogger->info("Logging start " + 42 | Utils::formatRawTime(Utils::getRawTime() , "%d-%m-%Y %H:%M:%S")); 43 | rawLogger->info("\n"); 44 | 45 | /* Set format for normal logging */ 46 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::Format, 47 | "[%datetime{%H:%m:%s}] Thread %thread: %level - %msg"); 48 | 49 | el::Loggers::reconfigureLogger(rawLogger , rawLoggerConf); 50 | } 51 | 52 | Logger::~Logger() { 53 | /* Setting clear format for ending info. */ 54 | rawLoggerConf.set(el::Level::Global, el::ConfigurationType::Format, "%msg"); 55 | el::Loggers::reconfigureLogger(rawLogger , rawLoggerConf); 56 | 57 | /* Writing ending info */ 58 | rawLogger->info("\n\nLogging end " + 59 | Utils::formatRawTime(Utils::getRawTime() , "%d-%m-%Y %H:%M:%S")); 60 | rawLogger->info("Error count " + Utils::itostr(errorMessages.size())); 61 | rawLogger->info("Warning count " + Utils::itostr(warningMessages.size())); 62 | rawLogger->info(""); 63 | } 64 | 65 | void Logger::log(LogLevel level, const std::string & msg) { 66 | switch(level) { 67 | case LogLevel::INFO: 68 | info(msg); 69 | break; 70 | case LogLevel::WARN: 71 | warn(msg); 72 | break; 73 | case LogLevel::ERROR: 74 | error(msg); 75 | break; 76 | default: 77 | raiseBugException("unknown log level"); 78 | } 79 | } 80 | 81 | void Logger::info(const std::string & msg) { 82 | rawLogger->info(msg); 83 | } 84 | 85 | void Logger::warn(const std::string & msg) { 86 | /* Raw logger is thread-safe. It is the rest I am worried about. */ 87 | rawLogger->warn(msg); 88 | { 89 | std::lock_guard l (warningMessages_mux); 90 | warningMessages.push_back(msg); 91 | } 92 | } 93 | 94 | void Logger::error(const std::string & msg) { 95 | /* Raw logger is thread-safe. It is the rest I am worried about. */ 96 | rawLogger->error(msg); 97 | { 98 | std::lock_guard l (errorMessages_mux); 99 | errorMessages.push_back(msg); 100 | } 101 | } 102 | 103 | std::vector Logger::getWarningMessages() { 104 | std::lock_guard l (warningMessages_mux); 105 | return warningMessages; 106 | } 107 | 108 | std::vector Logger::getErrorMessages() { 109 | std::lock_guard l (errorMessages_mux); 110 | return errorMessages; 111 | } 112 | 113 | } // namespace rtt 114 | -------------------------------------------------------------------------------- /rtt/logger.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_LOGGER_H 2 | #define RTT_LOGGER_H 3 | 4 | #include 5 | 6 | #ifndef ELPP_NO_DEFAULT_LOG_FILE 7 | #define ELPP_NO_DEFAULT_LOG_FILE 8 | #endif 9 | #ifndef ELPP_THREAD_SAFE 10 | #define ELPP_THREAD_SAFE 11 | #endif 12 | #ifndef ELPP_FORCE_USE_STD_THREAD 13 | #define ELPP_FORCE_USE_STD_THREAD 14 | #endif 15 | 16 | #include "libs/easylogging/easylogging++.h" 17 | 18 | namespace rtt { 19 | 20 | enum class LogLevel { 21 | INFO , WARN , ERROR 22 | }; 23 | 24 | /** 25 | * @brief The Logger class This is just a simple wrapper 26 | * for Easylogging++. Will hold pointer to logger and make header on start. 27 | */ 28 | class Logger { 29 | public: 30 | /** 31 | * @brief Logger Will create Logger instance and write log header. 32 | * @param logId Program wide unique id. 33 | * @param logFile Path to log file 34 | * @param toCout If true, log will be written also on standard output 35 | */ 36 | Logger(const std::string & logId , 37 | const std::string & logFile , bool toCout); 38 | 39 | /** 40 | * @brief ~Logger desctructor, will finalize log and write number of warnings and errors during the run. 41 | */ 42 | ~Logger(); 43 | 44 | /** 45 | * @brief log Will write logger message of desired level. 46 | * @param level Log level, can be INFO, WARN or ERROR 47 | * @param msg message 48 | */ 49 | void log(LogLevel level , const std::string & msg); 50 | 51 | /** 52 | * @brief info Will write informational message to log. 53 | * @param msg 54 | */ 55 | void info(const std::string & msg); 56 | 57 | /** 58 | * @brief warn Will write warning message to log and store msg in warningMessages 59 | * @param msg 60 | */ 61 | void warn(const std::string & msg); 62 | 63 | /** 64 | * @brief error Will write error message to log and store msg in errorMessages 65 | * @param msg 66 | */ 67 | void error(const std::string & msg); 68 | 69 | /** 70 | * @brief getWarningMessages 71 | * @return All warning messages that were logged using this object 72 | */ 73 | std::vector getWarningMessages(); 74 | 75 | /** 76 | * @brief getErrorMessages 77 | * @return All error messages that were logged using this object 78 | */ 79 | std::vector getErrorMessages(); 80 | 81 | private: 82 | el::Logger * rawLogger = NULL; 83 | el::Configurations rawLoggerConf; 84 | 85 | /* Mutex for operations with warning messages */ 86 | std::mutex warningMessages_mux; 87 | std::vector warningMessages; 88 | 89 | /* Mutex for operations with error messages */ 90 | std::mutex errorMessages_mux; 91 | std::vector errorMessages; 92 | }; 93 | 94 | } // namespace rtt 95 | 96 | #endif // RTT_LOGGER_H 97 | -------------------------------------------------------------------------------- /rtt/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "rtt/storage/istorage.h" 5 | #include "rtt/batteries/ibattery-batt.h" 6 | #include "rtt/clinterface/rttclioptions.h" 7 | #include "rtt/globalcontainer.h" 8 | #include "rtt/version.h" 9 | 10 | /* This line must stay in main! */ 11 | INITIALIZE_EASYLOGGINGPP 12 | 13 | using namespace rtt; 14 | 15 | int main (int argc , char * argv[]) try { 16 | if(argc == 1 || (argc == 2 && (strcmp(argv[1], "-h") == 0 || 17 | strcmp(argv[1], "--help") == 0))) { 18 | std::cout << clinterface::RTTCliOptions::getUsage() << std::endl; 19 | return -1; 20 | } 21 | 22 | /* Initialization of global container. 23 | * Since we can't be sure if logger was initialized, 24 | * errors are written to cout and no log is created. */ 25 | GlobalContainer gc; 26 | try { 27 | gc.initRttCliOptions(argc , argv); 28 | gc.initToolkitSettings(gc.getRttCliOptions()->hasSettingsFilePath() ? 29 | gc.getRttCliOptions()->getSettingsFilePath() : 30 | Constants::FILE_TOOLKIT_SETTINGS); 31 | 32 | } catch (std::exception & ex) { 33 | std::cout << "[Invalid toolkit configuration] " << ex.what() << std::endl; 34 | return -1; 35 | } 36 | 37 | /* Logger must be initialized last as it uses settings from main configuration file 38 | * and command line options. Otherwise exception is raised. */ 39 | gc.initLogger("Randomness_Testing_Toolkit", true); 40 | 41 | /* Logger is now created and all subsequent errors are logged. */ 42 | 43 | try { 44 | /* Initializing storage */ 45 | auto storage = storage::IStorage::getInstance(gc); 46 | storage->init(); 47 | 48 | try { 49 | /* Initialization of battery configuration in container - 50 | * should something go wrong, the error is logged in storage */ 51 | gc.initBatteriesConfiguration(gc.getRttCliOptions()->getInputCfgPath()); 52 | /* Initialization of battery */ 53 | auto battery = batteries::IBattery::getInstance(gc); 54 | /* Executing analysis */ 55 | battery->runTests(); 56 | /* Obtaining and storing results */ 57 | const auto & results = battery->getTestResults();; 58 | storage->checkStorage(); 59 | storage->writeResults(Utils::getRawPtrs(results)); 60 | /* And we are done. */ 61 | 62 | } catch(std::exception & ex) { 63 | /* Something happened during battery initialization/execution */ 64 | gc.getLogger()->error(ex.what()); 65 | } 66 | 67 | /* Store warnings and errors into storage */ 68 | storage->checkStorage(); 69 | storage->addBatteryWarnings(gc.getLogger()->getWarningMessages()); 70 | storage->addBatteryErrors(gc.getLogger()->getErrorMessages()); 71 | /* Call to close storage is important - 72 | * changes are committed, files saved, etc... */ 73 | storage->close(); 74 | 75 | } catch(std::exception & ex) { 76 | /* Storage creation failed. */ 77 | gc.getLogger()->error(ex.what()); 78 | return -1; 79 | } 80 | 81 | } catch(std::exception & ex) { 82 | std::cout << "[Error] " << ex.what() << std::endl << std::endl; 83 | return -1; 84 | } 85 | -------------------------------------------------------------------------------- /rtt/rttexception.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_RTTEXCEPTION_H 2 | #define RTT_RTTEXCEPTION_H 3 | 4 | #include 5 | #include 6 | #include 7 | 8 | #include "rtt/bugexception.h" 9 | 10 | namespace rtt { 11 | 12 | /** 13 | * @brief The RTTException class Used for indicating error during runtime 14 | */ 15 | class RTTException : public std::runtime_error { 16 | public: 17 | RTTException(const std::string & objIdentifier , 18 | const std::string & message) : 19 | std::runtime_error(objIdentifier + ": " + message) { 20 | if(objIdentifier.empty()) 21 | raiseBugException("empty objIdentifier"); 22 | } 23 | }; 24 | 25 | } // namespace rtt 26 | 27 | #endif // RTT_RTTEXCEPTION_H 28 | -------------------------------------------------------------------------------- /rtt/storage/filestorage.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_STORAGE_FILESTORAGE_H 2 | #define RTT_STORAGE_FILESTORAGE_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #include "rtt/clinterface/rttclioptions.h" 11 | #include "rtt/globalcontainer.h" 12 | #include "rtt/storage/istorage.h" 13 | 14 | namespace rtt { 15 | namespace storage { 16 | 17 | typedef std::vector tStringVector; 18 | 19 | using namespace clinterface; 20 | 21 | class FileStorage : public IStorage { 22 | public: 23 | static std::unique_ptr getInstance(const GlobalContainer & container); 24 | 25 | void init(); 26 | 27 | void writeResults(const std::vector & testResults); 28 | 29 | void close(); 30 | 31 | void addBatteryError(const std::string & error); 32 | 33 | void addBatteryErrors(const std::vector & errors); 34 | 35 | void addBatteryWarning(const std::string & warning); 36 | 37 | void addBatteryWarnings(const std::vector & warnings); 38 | 39 | private: 40 | /* 41 | ================= 42 | *** Constants *** 43 | ================= 44 | */ 45 | /* Strings in report */ 46 | static const std::string STRING_PASSED_PROP; 47 | static const std::string STRING_BATTERY_WARNINGS; 48 | static const std::string STRING_BATTERY_ERRORS; 49 | 50 | /* Other constants */ 51 | static const size_t MISC_TAB_SIZE; 52 | static const size_t MISC_COL_WIDTH; 53 | static const uint FLOAT_PRECISION; 54 | 55 | /* 56 | ================= 57 | *** Variables *** 58 | ================= 59 | */ 60 | /* Pointers to global objects */ 61 | RTTCliOptions * rttCliOptions; 62 | ToolkitSettings * toolkitSettings; 63 | 64 | time_t creationTime; 65 | BatteryArg battery; 66 | std::string inFilePath; 67 | std::string outFilePath; 68 | std::string mainOutFilePath; 69 | bool initialized = false; 70 | std::stringstream report; 71 | int passedTestsCount = 0; 72 | int totalTestsCount = 0; 73 | std::string passedTestProp; 74 | int indent = 0; 75 | int currSubtest = 0; 76 | int currVariant = 0; 77 | 78 | /* 79 | =============== 80 | *** Methods *** 81 | =============== 82 | */ 83 | FileStorage() {} 84 | 85 | void addNewTest(const std::string & testName); 86 | 87 | void finalizeTest(); 88 | 89 | void addVariant(); 90 | 91 | void finalizeVariant(); 92 | 93 | void addSubTest(); 94 | 95 | void finalizeSubTest(); 96 | 97 | void setTestResult(bool passed); 98 | 99 | void setTestPartialAlpha(double alpha); 100 | 101 | void setUserSettings( 102 | const std::vector> & options); 103 | 104 | void setTestParameters( 105 | const std::vector > & options); 106 | 107 | void setWarningMessages(const std::vector & warnings); 108 | 109 | void setErrorMessages(const std::vector & errors); 110 | 111 | void setStdErrMessages(const std::vector & stderr); 112 | 113 | void addStatisticResult( 114 | const std::string & statName , 115 | double value , int precision , bool passed); 116 | 117 | void addPValues( 118 | const std::vector & pvals, 119 | int precision); 120 | 121 | void finalizeReport(); 122 | 123 | void makeReportHeader(); 124 | 125 | std::string doIndent() const; 126 | 127 | void addResultToTableFile() const; 128 | 129 | void loadMainTable(tStringVector & header, 130 | tStringVector & fileNames, 131 | std::vector & tableData) const; 132 | 133 | void saveMainTable(const tStringVector & header, 134 | const tStringVector & fileNames, 135 | const std::vector & tableData) const; 136 | 137 | void addNewRow(tStringVector & fileNames, 138 | std::vector & tableData) const; 139 | 140 | static std::string stripSpacesFromString(const std::string & str); 141 | }; 142 | 143 | } // namespace storage 144 | } // namespace rtt 145 | 146 | #endif // RTT_STORAGE_FILESTORAGE_H 147 | -------------------------------------------------------------------------------- /rtt/storage/istorage.cpp: -------------------------------------------------------------------------------- 1 | #include "istorage.h" 2 | 3 | #include "rtt/storage/filestorage.h" 4 | #include "rtt/storage/mysqlstorage.h" 5 | 6 | namespace rtt { 7 | namespace storage { 8 | 9 | std::unique_ptr IStorage::getInstance(const GlobalContainer & container) { 10 | switch(container.getRttCliOptions()->getResultStorageId()) { 11 | case Constants::ResultStorageID::FILE_REPORT: 12 | return FileStorage::getInstance(container); 13 | #if USE_MYSQL_BACKEND 14 | case Constants::ResultStorageID::DB_MYSQL: 15 | return MySQLStorage::getInstance(container); 16 | #endif 17 | default: 18 | raiseBugException("invalid result storage id"); 19 | } 20 | } 21 | 22 | } // namespace storage 23 | } // namespace rtt 24 | -------------------------------------------------------------------------------- /rtt/storage/istorage.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_STORAGE_ISTORAGE_H 2 | #define RTT_STORAGE_ISTORAGE_H 3 | 4 | #include 5 | #include 6 | 7 | #include "rtt/globalcontainer.h" 8 | #include "rtt/batteries/itestresult-batt.h" 9 | 10 | namespace rtt { 11 | namespace storage { 12 | 13 | class IStorage { 14 | public: 15 | /** 16 | * @brief getInstance Creates storage 17 | * object according to global settings in container 18 | * @param container Object with global settings 19 | * @return 20 | */ 21 | static std::unique_ptr getInstance(const GlobalContainer & container); 22 | 23 | /** 24 | * @brief ~IStorage destructor 25 | */ 26 | virtual ~IStorage() {} 27 | 28 | /** 29 | * @brief init Initializes the object. This must be done before writing any results. 30 | * If done multiple times on the same object, peviously written results may be discarded. 31 | */ 32 | virtual void init() = 0; 33 | 34 | /** 35 | * @brief writeResults Will write results into the storage. 36 | * Can be called multiple times, the results will acummulate. 37 | * @param testResults Results of the tests 38 | */ 39 | virtual void writeResults(const std::vector & testResults) = 0; 40 | 41 | /** 42 | * @brief close Closes storage, resets the state, saves changes in the files or databases. 43 | */ 44 | virtual void close() = 0; 45 | 46 | /** 47 | * @brief addBatteryError Adds single battery runtime error into storage. 48 | * @param error 49 | */ 50 | virtual void addBatteryError(const std::string & error) = 0; 51 | 52 | /** 53 | * @brief addBatteryErrors Adds multiple battery runtime errors into storage. 54 | * @param errors 55 | */ 56 | virtual void addBatteryErrors(const std::vector & errors) = 0; 57 | 58 | /** 59 | * @brief addBatteryWarning Adds single battery runtime warning into storage. 60 | * @param warning 61 | */ 62 | virtual void addBatteryWarning(const std::string & warning) = 0; 63 | 64 | /** 65 | * @brief addBatteryWarnings Adds multiple battery runtime warnings into storage. 66 | * @param warnings 67 | */ 68 | virtual void addBatteryWarnings(const std::vector & warnings) = 0; 69 | 70 | /** 71 | * Ensures that storage is working before working with it (e.g., database connection is alive) 72 | */ 73 | virtual void checkStorage() {}; 74 | }; 75 | 76 | } // namespace storage 77 | } // namespace rtt 78 | 79 | #endif // RTT_STORAGE_ISTORAGE_H 80 | -------------------------------------------------------------------------------- /rtt/storage/mysqlstorage.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_STORAGE_MYSQLSTORAGE_H 2 | #define RTT_STORAGE_MYSQLSTORAGE_H 3 | 4 | #if USE_MYSQL_BACKEND 5 | 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | #include "rtt/clinterface/rttclioptions.h" 13 | #include "rtt/globalcontainer.h" 14 | #include "rtt/storage/istorage.h" 15 | 16 | namespace rtt { 17 | namespace storage { 18 | 19 | using namespace clinterface; 20 | 21 | class MySQLStorage : public IStorage { 22 | public: 23 | static std::unique_ptr getInstance(const GlobalContainer & container); 24 | 25 | void init(); 26 | 27 | void writeResults(const std::vector & testResults); 28 | 29 | void close(); 30 | 31 | void addBatteryError(const std::string & error); 32 | 33 | void addBatteryErrors(const std::vector & errors); 34 | 35 | void addBatteryWarning(const std::string & warning); 36 | 37 | void addBatteryWarnings(const std::vector & warnings); 38 | 39 | void checkStorage(); 40 | 41 | private: 42 | /* 43 | ================= 44 | *** Variables *** 45 | ================= 46 | */ 47 | static const std::string objectInfo; 48 | /* Pointers to global objects */ 49 | RTTCliOptions * rttCliOptions; 50 | ToolkitSettings * toolkitSettings; 51 | const GlobalContainer * gContainer; 52 | 53 | time_t creationTime; 54 | BatteryArg battery; 55 | 56 | sql::Driver * driver; 57 | std::unique_ptr conn; 58 | std::string dbAddress; 59 | 60 | std::uint64_t dbBatteryId = 0; 61 | std::uint64_t currDbTestId = 0; 62 | std::uint64_t currDbVariantId = 0; 63 | std::uint64_t currDbSubtestId = 0; 64 | int currTestIdx = 0; 65 | int currSubtestIdx = 0; 66 | int currVariantIdx = 0; 67 | int totalTestCount = 0; 68 | int passedTestCount = 0; 69 | 70 | /* 71 | =============== 72 | *** Methods *** 73 | =============== 74 | */ 75 | MySQLStorage() {} 76 | 77 | void addNewTest(const std::string & testName); 78 | void finalizeTest(); 79 | 80 | void addVariant(); 81 | void finalizeVariant(); 82 | 83 | void addSubTest(); 84 | void finalizeSubTest(); 85 | 86 | void setTestResult(bool passed); 87 | 88 | void setTestPartialAlpha(double alpha); 89 | 90 | void setUserSettings( 91 | const std::vector > & options); 92 | 93 | void setTestParameters( 94 | const std::vector > & options); 95 | 96 | void setVariantWarnings(const std::vector & warnings); 97 | 98 | void setVariantErrors(const std::vector & errors); 99 | 100 | void setVariantStdErr(const std::vector & stderr); 101 | 102 | void addStatisticResult( 103 | const std::string & statName , 104 | double value, bool passed); 105 | 106 | void addPValues(const std::vector & pvals); 107 | 108 | void finalizeReport(); 109 | 110 | bool pingConnection(); 111 | 112 | bool reconnectIfNeeded(); 113 | 114 | void connectDb(); 115 | 116 | void initBattery(); 117 | void initBatteryIfNeeded(); 118 | 119 | std::uint64_t getLastInsertedId(); 120 | }; 121 | 122 | } // namespace storage 123 | } // namespace rtt 124 | 125 | #endif // USE_MYSQL_BACKEND 126 | 127 | #endif // RTT_STORAGE_MYSQLSTORAGE_H 128 | -------------------------------------------------------------------------------- /rtt/strings.cpp: -------------------------------------------------------------------------------- 1 | #include "strings.h" 2 | 3 | namespace rtt { 4 | 5 | const std::string Strings::ERR_FILE_OPEN_FAIL = "can't open file - "; 6 | const std::string Strings::ERR_INVALID_BATTERY = "invalid battery"; 7 | const std::string Strings::ERR_INVALID_TEST_CONST = "unknown test constant - "; 8 | 9 | const std::string Strings::BATT_ERR_ALREADY_EXECUTED = "battery was already executed"; 10 | const std::string Strings::BATT_ERR_NO_TESTS = "no tests were set for execution"; 11 | const std::string Strings::BATT_ERR_NO_EXEC_PROC = "battery must be executed before result processing"; 12 | const std::string Strings::BATT_ERR_KS_NO_PSAMPLES = "can't calculate Kolmogorov-Smirnov statistic from 0 p-values"; 13 | 14 | const std::string Strings::TEST_ERR_NO_EXEC_RES = "test wasn't executed, can't provide results"; 15 | const std::string Strings::TEST_ERR_NO_EXEC_LOGS = "test wasn't executed, can't provide logs"; 16 | const std::string Strings::TEST_ERR_NO_BINARY_DATA = "empty input binary data path"; 17 | const std::string Strings::TEST_ERR_NO_EXECUTABLE = "empty executable path"; 18 | const std::string Strings::TEST_ERR_PSAMPLES_NOT_SET = "p-sample count option was not set"; 19 | const std::string Strings::TEST_ERR_ARGS_BAD_FORMAT_OPT_WO_VAL = "invalid test arguments - each option must have a value"; 20 | const std::string Strings::TEST_ERR_NO_PVALS_EXTRACTED = ": no p-values were extracted"; 21 | const std::string Strings::TEST_ERR_PVALS_BAD_COUNT = ": p-values couldn't be extracted. Number of found p-values is different from expected number. Inspect test log."; 22 | const std::string Strings::TEST_ERR_STREAM_SIZE_NOT_SET = "stream size option was not set"; 23 | const std::string Strings::TEST_ERR_STREAM_COUNT_NOT_SET = "stream count option was not set"; 24 | const std::string Strings::TEST_ERR_EXCEPTION_DURING_THREAD = ": exception was caught during execution: "; 25 | const std::string Strings::TEST_ERR_PVAL_OUTSIDE_INTERVAL = "file contains p-value outside <0,1> interval"; 26 | const std::string Strings::TEST_ERR_REPS_NOT_SET = "repetitions option were not set"; 27 | const std::string Strings::TEST_ERR_PARAM_INCOMPLETE = "incomplete parameter settings"; 28 | const std::string Strings::TEST_ERR_BITNB_NOT_SET = "bit_nb option was not set"; 29 | const std::string Strings::TEST_ERR_BITR_NOT_SET = "bit_r option was not set"; 30 | const std::string Strings::TEST_ERR_BITS_NOT_SET = "bit_s option was not set"; 31 | const std::string Strings::TEST_ERR_UNKNOWN_STATISTICS = ": number of statistics extracted from log differs from default numbers. Inspect the test log for correct statistics names."; 32 | 33 | const std::string Strings::BATT_INFO_PROCESSING_FILE = ": processing file "; 34 | const std::string Strings::BATT_INFO_PROCESSING_STARTED = ": Processing and storing battery results."; 35 | const std::string Strings::BATT_INFO_PROCESSING_COMPLETE = ": Result processing finished."; 36 | 37 | } // namespace rtt 38 | 39 | -------------------------------------------------------------------------------- /rtt/strings.h: -------------------------------------------------------------------------------- 1 | #ifndef RTT_STRINGS_H 2 | #define RTT_STRINGS_H 3 | 4 | #include 5 | 6 | namespace rtt { 7 | 8 | /** 9 | * @brief The Strings class Class with hardcoded strings that are used in application 10 | * to notify about errors, progress, etc 11 | */ 12 | class Strings { 13 | public: 14 | static const std::string ERR_FILE_OPEN_FAIL; 15 | static const std::string ERR_INVALID_BATTERY; 16 | static const std::string ERR_INVALID_TEST_CONST; 17 | 18 | static const std::string BATT_ERR_ALREADY_EXECUTED; 19 | static const std::string BATT_ERR_NO_TESTS; 20 | static const std::string BATT_ERR_NO_EXEC_PROC; 21 | static const std::string BATT_ERR_KS_NO_PSAMPLES; 22 | 23 | static const std::string TEST_ERR_NO_EXEC_RES; 24 | static const std::string TEST_ERR_NO_EXEC_LOGS; 25 | static const std::string TEST_ERR_NO_BINARY_DATA; 26 | static const std::string TEST_ERR_NO_EXECUTABLE; 27 | static const std::string TEST_ERR_PSAMPLES_NOT_SET; 28 | static const std::string TEST_ERR_ARGS_BAD_FORMAT_OPT_WO_VAL; 29 | static const std::string TEST_ERR_NO_PVALS_EXTRACTED; 30 | static const std::string TEST_ERR_PVALS_BAD_COUNT; 31 | static const std::string TEST_ERR_STREAM_SIZE_NOT_SET; 32 | static const std::string TEST_ERR_STREAM_COUNT_NOT_SET; 33 | static const std::string TEST_ERR_EXCEPTION_DURING_THREAD; 34 | static const std::string TEST_ERR_PVAL_OUTSIDE_INTERVAL; 35 | static const std::string TEST_ERR_REPS_NOT_SET; 36 | static const std::string TEST_ERR_PARAM_INCOMPLETE; 37 | static const std::string TEST_ERR_BITNB_NOT_SET; 38 | static const std::string TEST_ERR_BITR_NOT_SET; 39 | static const std::string TEST_ERR_BITS_NOT_SET; 40 | static const std::string TEST_ERR_UNKNOWN_STATISTICS; 41 | 42 | static const std::string BATT_INFO_PROCESSING_FILE; 43 | static const std::string BATT_INFO_PROCESSING_STARTED; 44 | static const std::string BATT_INFO_PROCESSING_COMPLETE; 45 | 46 | private: 47 | Strings() {} 48 | }; 49 | 50 | } // namespace rtt 51 | 52 | #endif // RTT_STRINGS_H 53 | -------------------------------------------------------------------------------- /rtt/version.h: -------------------------------------------------------------------------------- 1 | #define GIT_COMMIT "1.0" 2 | #define GIT_COMMIT_SHORT "1.0" 3 | -------------------------------------------------------------------------------- /rtt/version.h.in: -------------------------------------------------------------------------------- 1 | #define GIT_COMMIT "@GIT_COMMIT@" 2 | #define GIT_COMMIT_SHORT "@GIT_COMMIT_SHORT@" 3 | --------------------------------------------------------------------------------