Skip to content
Snippets Groups Projects
Commit 0c0e1cf7 authored by Whitney Armstrong's avatar Whitney Armstrong
Browse files

Moved everything into common_bench namespace

parent 6862a2b1
Branches
No related tags found
1 merge request!16Moved everything into common_bench namespace
Showing
with 4877 additions and 518 deletions
...@@ -12,8 +12,12 @@ default: ...@@ -12,8 +12,12 @@ default:
- .local/share - .local/share
- results - results
- config - config
- juggler.env
reports:
dotenv: juggler.env
stages: stages:
- config0
- config - config
- initialize - initialize
- data_init - data_init
...@@ -21,174 +25,70 @@ stages: ...@@ -21,174 +25,70 @@ stages:
- benchmarks - benchmarks
- deploy - deploy
common:variables:
stage: config0
#rules:
# - if: '$CI_SERVER_HOST == "eicweb.phy.anl.gov"'
script:
- |
echo " CI_PIPELINE_SOURCE = ${CI_PIPELINE_SOURCE}"
echo " COMMON_BENCH_VERSION = ${COMMON_BENCH_VERSION}"
if [[ "${CI_PIPELINE_SOURCE}" == "push" || "x${CI_PIPELINE_SOURCE}" == "xmerge_request_event" || "$CI_COMMIT_BRANCH" == "master" ]]; then
export COMMON_BENCH_VERSION="${CI_COMMIT_REF_NAME}"
echo "COMMON_BENCH_VERSION = ${CI_COMMIT_REF_NAME}"
echo "COMMON_BENCH_VERSION=${CI_COMMIT_REF_NAME}" >> juggler.env
fi
echo "COMMON_BENCH_VERSION = ${COMMON_BENCH_VERSION}"
include: 'share/common.yml' common:setup:
stage: config
needs: ["common:variables"]
script:
- git clone -b "${COMMON_BENCH_VERSION}" "${CI_REPOSITORY_URL}" setup
- source setup/bin/env.sh && ./setup/bin/install_common.sh
#env: common:detector:
# tags: stage: initialize
# - singularity needs: ["common:setup"]
# stage: config script:
# script: - source .local/bin/env.sh && build_detector.sh
# - bash bin/config_env.sh - bin/mkdir_local_data_link sim_output
# - print_env.sh
# - ls -lrth
#detector:
# tags: detector_benchmarks:
# - singularity stage: benchmarks
# stage: initialize needs: ["common:variables"]
# needs: ["env"] variables:
# timeout: 1 hours JUGGLER_DETECTOR: "athena"
# #cache: COMMON_BENCH_VERSION: "$COMMON_BENCH_VERSION"
# # key: trigger:
# # files: project: EIC/benchmarks/detector_benchmarks
# # - options/env.sh strategy: depend
# # - util/build_detector.sh
# # prefix: "$CI_COMMIT_REF_SLUG" physics_benchmarks:
# # paths: stage: benchmarks
# # - .local/detector needs: ["common:variables"]
# # - .local/lib variables:
# script: JUGGLER_DETECTOR: "athena"
# - whoami && hostname COMMON_BENCH_VERSION: "$COMMON_BENCH_VERSION"
# - ls -lrth trigger:
# - pwd project: EIC/benchmarks/physics_benchmarks
# - ./bin/print_env.sh strategy: depend
# - ./bin/build_detector.sh
# - ./bin/print_env.sh
# - mkdir -p results pages:
# - mkdir -p config image: eicweb.phy.anl.gov:4567/containers/eic_container/alpine
# - echo "$CI_PIPLINE_ID" && echo "$CI_PROJECT_NAME" stage: deploy
rules:
- if: '$CI_SERVER_HOST == "gitlab.phy.anl.gov" && $CI_COMMIT_BRANCH == "master"'
script:
- apk update && apk add doxygen graphviz ttf-ubuntu-font-family
- cd doc && doxygen Doxyfile && cd ..
- mkdir -p public && cp -r doc/docs/html/* public/.
# - mkdir build && cd build && cmake ../. -DCMAKE_INSTALL_PREFIX=../install && make doc_doxygen && cd ..
#- cp -r build/doxygen_output/html public
artifacts:
paths:
- public
#get_data:
# stage: data_init
# needs: ["detector"]
# script:
# - source options/env.sh
# - ln -s ${LOCAL_DATA_PATH}/sim_output sim_output
# - ln -s ${LOCAL_DATA_PATH}/datasets/data data
# - cd ${LOCAL_DATA_PATH} && git clone --depth=1 https://eicweb.phy.anl.gov/EIC/datasets.git datasets
#
#.det_benchmark:
# needs:
# - ["get_data"]
# before_script:
# - source options/env.sh
# - ln -s ${LOCAL_DATA_PATH}/sim_output sim_output
# - ln -s ${LOCAL_DATA_PATH}/datasets/data data
# artifacts:
# expire_in: 20 weeks
# paths:
# - results/
#
#
#include:
# - local: 'benchmarks/trackers/config.yml'
# - local: 'benchmarks/calorimeters/config.yml'
# - local: 'benchmarks/pid/config.yml'
#
# #roman_pot_simu:
# # stage: simulate
# # needs:
# # - ["get_data","detector"]
# # script:
# # - bash benchmarks/trackers/roman_pot_simu.sh
# #
# #roman_pot_nhits:
# # stage: benchmarks
# # needs:
# # - ["roman_pot_simu","detector"]
# # script:
# # - root -b -q benchmarks/trackers/simple_tracking.cxx+
# # allow_failure: true
# #
# #roman_pot_eta:
# # stage: benchmarks
# # needs:
# # - ["roman_pot_simu","detector"]
# # script:
# # - root -b -q benchmarks/trackers/roman_pot_hit_eta.cxx+
# # allow_failure: true
# #
# #zdc_simulation:
# # stage: simulate
# # needs:
# # - ["get_data","detector"]
# # script:
# # - bash benchmarks/calorimeters/run_simulation_zdc.sh
# #
# #cal_test_3_zdc_neutrons_reader:
# # stage: benchmarks
# # needs:
# # - ["zdc_simulation","detector"]
# # script:
# # - root -b -q benchmarks/calorimeters/zdc_neutrons_reader.cxx
# # allow_failure: true
# #
# #
# #zdc_benchmark:
# # stage: benchmarks
# # needs:
# # - ["zdc_simulation","detector"]
# # script:
# # - ls -lrth sim_output
# # - root -b -q benchmarks/calorimeters/simple_checking.cxx+
# # allow_failure: true
# #
# #zdc_benchmark_info_histogram:
# # stage: benchmarks
# # needs:
# # - ["zdc_simulation","detector"]
# # script:
# # - root -b -q benchmarks/calorimeters/simple_info_plot_histograms.cxx+
# # allow_failure: true
# #
# #crystal_emcal_simulation:
# # stage: simulate
# # needs:
# # - ["get_data"]
# # script:
# # bash benchmarks/calorimeters/run_simulation_crystal.sh
# #
# #crystal_benchmark:
# # stage: benchmarks
# # needs:
# # - ["crystal_emcal_simulation","detector"]
# # script:
# # - ls -lrth sim_output
# # - root -b -q benchmarks/calorimeters/simple_checking_crystal.cxx+
# # allow_failure: true
# #
# #crystal_pion_simulation:
# # stage: simulate
# # needs:
# # - ["get_data","detector"]
# # tags:
# # - silicon
# # script:
# # - source options/env.sh
# # - npsim --runType batch --numberOfEvents 100 --compactFile ${DETECTOR_PATH}/topside.xml --inputFiles data/emcal_electrons.hepmc --outputFile sim_output/output_emcal_electrons.root
#
#deploy_results:
# stage: deploy
# needs:
# - ["cal_bench:zdc_benchmark"]
# tags:
# - silicon
# script:
# - echo "deploy results!"
#
#
#pages:
# stage: deploy
# rules:
# - if: '$CI_COMMIT_BRANCH == "master" && $CI_SERVER_HOST != "eicweb.phy.anl.gov"'
# cache:
# paths:
# - node_modules/
# image: node:latest
# script:
# - mkdir public && cp doc/main.html public/index.html
# artifacts:
# paths:
# - public
#
#
Common Benchmark Code [TOC]
=====================
# Common Benchmark Code
## Overview
Code common to: Code common to:
- `detector_benchmarks` - `detector_benchmarks`
- `reconstruction_benchmarks` - `reconstruction_benchmarks`
- `physics_benchmarks` - `physics_benchmarks`
## Usage
Bookkeeping of test data to store data of one or more tests in a json file to
facilitate future accounting.
### Usage Example 1 (single test):
#### define our test
~~~~~~~~~~~~~{.cpp}
common_bench::Test test1{
{{"name", "example_test"},
{"title", "Example Test"},
{"description", "This is an example of a test definition"},
{"quantity", "efficiency"},
{"target", "1"}}};
~~~~~~~~~~~~~
#### set pass/fail/error status and return value (in this case .99)
~~~~~~~~~~~~~{.cpp}
test1.pass(0.99)
~~~~~~~~~~~~~
#### write our test data to a json file
~~~~~~~~~~~~~{.cpp}
common_bench::write_test(test1, "test1.json");
~~~~~~~~~~~~~
### Usage Example 2 (multiple tests):
#### Define our tests
~~~~~~~~~~~~~{.cpp}
common_bench::Test test1{{
{"name", "example_test"},
{"title", "Example Test"},
{"description", "This is an example of a test definition"},
{"quantity", "efficiency"},
{"target", "1"}}};
common_bench::Test test2{{
{"name", "another_test"},
{"title", "Another example Test"},
{"description", "This is a second example of a test definition"},
{"quantity", "resolution"},
{"target", "3."}}};
~~~~~~~~~~~~~
#### set pass/fail/error status and return value (in this case .99)
~~~~~~~~~~~~~{.cpp}
test1.fail(10)
~~~~~~~~~~~~~
#### write our test data to a json file
~~~~~~~~~~~~~{.cpp}
common_bench::write_test({test1, test2}, "test.json");
~~~~~~~~~~~~~
...@@ -18,6 +18,7 @@ if [[ -n "${LOCAL_PREFIX}" ]] ; then ...@@ -18,6 +18,7 @@ if [[ -n "${LOCAL_PREFIX}" ]] ; then
cp -v -r ${SETUP_DIR}/bin/* "${LOCAL_PREFIX}/bin/." cp -v -r ${SETUP_DIR}/bin/* "${LOCAL_PREFIX}/bin/."
cp -v -r ${SETUP_DIR}/include/* "${LOCAL_PREFIX}/include/." cp -v -r ${SETUP_DIR}/include/* "${LOCAL_PREFIX}/include/."
#cp -v -r ${SETUP_DIR}/include/common_bench/* "${LOCAL_PREFIX}/include/."
cp -v -r ${SETUP_DIR}/share/* "${LOCAL_PREFIX}/share/." cp -v -r ${SETUP_DIR}/share/* "${LOCAL_PREFIX}/share/."
else else
......
This diff is collapsed.
/**
Doxygen Awesome
https://github.com/jothepro/doxygen-awesome-css
MIT License
Copyright (c) 2021 jothepro
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
@media screen and (min-width: 768px) {
#MSearchBox {
width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium)) - var(--searchbar-height) - 1px);
}
#MSearchField {
width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium)) - 66px - var(--searchbar-height));
}
}
/**
Doxygen Awesome
https://github.com/jothepro/doxygen-awesome-css
MIT License
Copyright (c) 2021 jothepro
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
html {
/* side nav width. MUST be = `TREEVIEW_WIDTH`.
* Make sure it is wide enought to contain the page title (logo + title + version)
*/
--side-nav-fixed-width: 340px;
--menu-display: none;
--top-height: 120px;
}
@media screen and (min-width: 768px) {
html {
--searchbar-background: var(--page-background-color);
}
#side-nav {
min-width: var(--side-nav-fixed-width);
max-width: var(--side-nav-fixed-width);
top: var(--top-height);
}
#nav-tree, #side-nav {
height: calc(100vh - var(--top-height)) !important;
}
#nav-tree {
padding: 0;
}
#top {
display: block;
border-bottom: none;
height: var(--top-height);
margin-bottom: calc(0px - var(--top-height));
max-width: var(--side-nav-fixed-width);
background: var(--side-nav-background);
}
#main-nav {
float: left;
padding-right: 0;
}
.ui-resizable-handle {
cursor: default;
width: 1px !important;
box-shadow: 0 calc(-2 * var(--top-height)) 0 0 var(--separator-color);
}
#nav-path {
position: fixed;
right: 0;
left: var(--side-nav-fixed-width);
bottom: 0;
width: auto;
}
#doc-content {
height: calc(100vh - 31px) !important;
padding-bottom: calc(3 * var(--spacing-large));
padding-top: calc(var(--top-height) - 80px);
box-sizing: border-box;
margin-left: var(--side-nav-fixed-width) !important;
}
#MSearchBox {
width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium)));
}
#MSearchField {
width: calc(var(--side-nav-fixed-width) - calc(2 * var(--spacing-medium)) - 65px);
}
#MSearchResultsWindow {
left: var(--spacing-medium) !important;
right: auto;
}
}
This diff is collapsed.
.github-corner svg {
fill: var(--primary-light-color);
color: var(--page-background-color);
width: 72px;
height: 72px;
}
@media screen and (max-width: 767px) {
.github-corner svg {
width: 55px;
height: 55px;
}
#projectnumber {
margin-right: 22px;
}
}
<!-- HTML footer for doxygen 1.9.1-->
<!-- start footer part -->
<!--BEGIN GENERATE_TREEVIEW-->
<div id="nav-path" class="navpath"><!-- id is needed for treeview function! -->
<ul>
$navpath
<li class="footer">$generatedby <a href="https://www.doxygen.org/index.html"><img class="footer" src="$relpath^doxygen.svg" width="104" height="31" alt="doxygen"/></a> $doxygenversion </li>
</ul>
</div>
<!--END GENERATE_TREEVIEW-->
<!--BEGIN !GENERATE_TREEVIEW-->
<hr class="footer"/><address class="footer"><small>
$generatedby&#160;<a href="https://www.doxygen.org/index.html"><img class="footer" src="$relpath^doxygen.svg" width="104" height="31" alt="doxygen"/></a> $doxygenversion
</small></address>
<!--END !GENERATE_TREEVIEW-->
<script type="text/javascript">
$(document).ready(function(){
toggleButton = document.createElement('doxygen-awesome-dark-mode-toggle')
toggleButton.title = "Toggle Light/Dark Mode"
document.getElementById("MSearchBox").parentNode.appendChild(toggleButton)
})
</script>
</body>
</html>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen $doxygenversion"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<!-- BEGIN opengraph metadata -->
<meta property="og:title" content="Doxygen Awesome" />
<meta property="og:image" content="https://repository-images.githubusercontent.com/348492097/4f16df80-88fb-11eb-9d31-4015ff22c452" />
<meta property="og:description" content="Custom CSS theme for doxygen html-documentation with lots of customization parameters." />
<meta property="og:url" content="https://jothepro.github.io/doxygen-awesome-css/" />
<!-- END opengraph metadata -->
<!-- BEGIN twitter metadata -->
<meta name="twitter:image:src" content="https://repository-images.githubusercontent.com/348492097/4f16df80-88fb-11eb-9d31-4015ff22c452" />
<meta name="twitter:title" content="Doxygen Awesome" />
<meta name="twitter:description" content="Custom CSS theme for doxygen html-documentation with lots of customization parameters." />
<!-- END twitter metadata -->
<!--BEGIN PROJECT_NAME--><title>$projectname: $title</title><!--END PROJECT_NAME-->
<!--BEGIN !PROJECT_NAME--><title>$title</title><!--END !PROJECT_NAME-->
<link href="$relpath^tabs.css" rel="stylesheet" type="text/css"/>
<link rel="icon" type="image/svg+xml" href="logo.drawio.svg"/>
<script type="text/javascript" src="$relpath^jquery.js"></script>
<script type="text/javascript" src="$relpath^dynsections.js"></script>
<script type="text/javascript" src="$relpath^doxygen-awesome-darkmode-toggle.js"></script>
$treeview
$search
$mathjax
<link href="$relpath^$stylesheet" rel="stylesheet" type="text/css" />
$extrastylesheet
</head>
<body>
<!-- https://tholman.com/github-corners/ -->
<a href="https://github.com/jothepro/doxygen-awesome-css" class="github-corner" title="View source on GitHub">
<svg viewBox="0 0 250 250" style="position: absolute; top: 0; border: 0; right: 0;" aria-hidden="true">
<path d="M0,0 L115,115 L130,115 L142,142 L250,250 L250,0 Z"></path><path d="M128.3,109.0 C113.8,99.7 119.0,89.6 119.0,89.6 C122.0,82.7 120.5,78.6 120.5,78.6 C119.2,72.0 123.4,76.3 123.4,76.3 C127.3,80.9 125.5,87.3 125.5,87.3 C122.9,97.6 130.6,101.9 134.4,103.2" fill="currentColor" style="transform-origin: 130px 106px;" class="octo-arm"></path><path d="M115.0,115.0 C114.9,115.1 118.7,116.5 119.8,115.4 L133.7,101.6 C136.9,99.2 139.9,98.4 142.2,98.6 C133.8,88.0 127.5,74.4 143.8,58.0 C148.5,53.4 154.0,51.2 159.7,51.0 C160.3,49.4 163.2,43.6 171.4,40.1 C171.4,40.1 176.1,42.5 178.8,56.2 C183.1,58.6 187.2,61.8 190.9,65.4 C194.5,69.0 197.7,73.2 200.1,77.6 C213.8,80.2 216.3,84.9 216.3,84.9 C212.7,93.1 206.9,96.0 205.4,96.6 C205.1,102.4 203.0,107.8 198.3,112.5 C181.9,128.9 168.3,122.5 157.7,114.1 C157.9,116.9 156.7,120.9 152.7,124.9 L141.0,136.5 C139.8,137.7 141.6,141.9 141.8,141.8 Z" fill="currentColor" class="octo-body"></path></svg></a><style>.github-corner:hover .octo-arm{animation:octocat-wave 560ms ease-in-out}@keyframes octocat-wave{0%,100%{transform:rotate(0)}20%,60%{transform:rotate(-25deg)}40%,80%{transform:rotate(10deg)}}@media (max-width:500px){.github-corner:hover .octo-arm{animation:none}.github-corner .octo-arm{animation:octocat-wave 560ms ease-in-out}}</style>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<!--BEGIN TITLEAREA-->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<!--BEGIN PROJECT_LOGO-->
<td id="projectlogo"><img alt="Logo" src="$relpath^$projectlogo"/></td>
<!--END PROJECT_LOGO-->
<!--BEGIN PROJECT_NAME-->
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">$projectname
<!--BEGIN PROJECT_NUMBER-->&#160;<span id="projectnumber">$projectnumber</span><!--END PROJECT_NUMBER-->
</div>
<!--BEGIN PROJECT_BRIEF--><div id="projectbrief">$projectbrief</div><!--END PROJECT_BRIEF-->
</td>
<!--END PROJECT_NAME-->
<!--BEGIN !PROJECT_NAME-->
<!--BEGIN PROJECT_BRIEF-->
<td style="padding-left: 0.5em;">
<div id="projectbrief">$projectbrief</div>
</td>
<!--END PROJECT_BRIEF-->
<!--END !PROJECT_NAME-->
<!--BEGIN DISABLE_INDEX-->
<!--BEGIN SEARCHENGINE-->
<td>$searchbox</td>
<!--END SEARCHENGINE-->
<!--END DISABLE_INDEX-->
</tr>
</tbody>
</table>
</div>
<!--END TITLEAREA-->
<!-- end header part -->
#ifndef BENCHMARK_H
#define BENCHMARK_H
#include "exception.h"
#include <fmt/core.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <nlohmann/json.hpp>
#include <string>
// Bookkeeping of test data to store data of one or more tests in a json file to
// facilitate future accounting.
//
// Usage Example 1 (single test):
// ==============================
// 1. define our test
// eic::util::Test test1{
// {{"name", "example_test"},
// {"title", "Example Test"},
// {"description", "This is an example of a test definition"},
// {"quantity", "efficiency"},
// {"target", "1"}}};
// 2. set pass/fail/error status and return value (in this case .99)
// test1.pass(0.99)
// 3. write our test data to a json file
// eic::util::write_test(test1, "test1.json");
//
// Usage Example 2 (multiple tests):
// =================================
// 1. define our tests
// eic::util::Test test1{
// {{"name", "example_test"},
// {"title", "Example Test"},
// {"description", "This is an example of a test definition"},
// {"quantity", "efficiency"},
// {"target", "1"}}};
// eic::util::Test test2{
// {{"name", "another_test"},
// {"title", "Another example Test"},
// {"description", "This is a second example of a test definition"},
// {"quantity", "resolution"},
// {"target", "3."}}};
// 2. set pass/fail/error status and return value (in this case .99)
// test1.fail(10)
// 3. write our test data to a json file
// eic::util::write_test({test1, test2}, "test.json");
// Namespace for utility scripts, FIXME this should be part of an independent
// library
namespace eic::util {
struct TestDefinitionError : Exception {
TestDefinitionError(std::string_view msg) : Exception(msg, "test_definition_error") {}
};
// Wrapper for our test data json, with three methods to set the status
// after test completion (to pass, fail or error). The default value
// is error.
// The following fields should be defined in the definitions json
// for the test to make sense:
// - name: unique identifier for this test
// - title: Slightly more verbose identifier for this test
// - description: Concise description of what is tested
// - quantity: What quantity is tested? Unites of value/target
// - target: Target value of <quantity> that we want to reach
// - value: Actual value of <quantity>
// - weight: Weight for this test (this is defaulted to 1.0 if not specified)
// - result: pass/fail/error
struct Test {
// note: round braces for the json constructor, as else it will pick the wrong
// initializer-list constructur (it will put everything in an array)
Test(const std::map<std::string, std::string>& definition) : json(definition)
{
// std::cout << json.dump() << std::endl;
// initialize with error (as we don't have a value yet)
error();
// Check that all required fields are present
for (const auto& field :
{"name", "title", "description", "quantity", "target", "value", "result"}) {
if (json.find(field) == json.end()) {
throw TestDefinitionError{
fmt::format("Error in test definition: field '{}' missing", field)};
}
}
// Default "weight" to 1 if not set
if (json.find("weight") == json.end()) {
json["weight"] = 1.0;
}
}
// Set this test to pass/fail/error
void pass(double value) { update_result("pass", value); }
void fail(double value) { update_result("fail", value); }
void error(double value = 0) { update_result("error", value); }
nlohmann::json json;
private:
void update_result(std::string_view status, double value)
{
json["result"] = status;
json["value"] = value;
}
};
void write_test(const std::vector<Test>& data, const std::string& fname)
{
nlohmann::json test;
for (auto& entry : data) {
test["tests"].push_back(entry.json);
}
std::cout << fmt::format("Writing test data to {}\n", fname);
std::ofstream output_file(fname);
output_file << std::setw(4) << test << "\n";
}
void write_test(const Test& data, const std::string& fname)
{
std::vector<Test> vtd{data};
write_test(vtd, fname);
}
} // namespace eic::util
#endif
#ifndef BENCHMARK_H
#define BENCHMARK_H
#include "exception.h"
#include <fmt/core.h>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <nlohmann/json.hpp>
#include <string>
namespace common_bench {
/** Exception
*/
struct TestDefinitionError : Exception {
TestDefinitionError(std::string_view msg)
: Exception(msg, "test_definition_error") {}
};
/** Benchmark test class.
* Wrapper for our test data json, with three methods to set the status
* after test completion (to pass, fail or error). The default value
* is error.
* The following fields should be defined in the definitions json
* for the test to make sense:
* - name: unique identifier for this test
* - title: Slightly more verbose identifier for this test
* - description: Concise description of what is tested
* - quantity: What quantity is tested? Unites of value/target
* - target: Target value of <quantity> that we want to reach
* - value: Actual value of <quantity>
* - weight: Weight for this test (this is defaulted to 1.0 if not specified)
* - result: pass/fail/error
*/
struct Test {
/** Test construction.
* \note Round braces for the json constructor, as else it will pick the wrong
* initializer-list constructur (it will put everything in an array)
*/
Test(const std::map<std::string, std::string> &definition)
: json(definition) {
// std::cout << json.dump() << std::endl;
// initialize with error (as we don't have a value yet)
error();
// Check that all required fields are present
for (const auto &field : {"name", "title", "description", "quantity",
"target", "value", "result"}) {
if (json.find(field) == json.end()) {
throw TestDefinitionError{
fmt::format("Error in test definition: field '{}' missing", field)};
}
}
// Default "weight" to 1 if not set
if (json.find("weight") == json.end()) {
json["weight"] = 1.0;
}
}
/// Set this test to pass.
void pass(double value) { update_result("pass", value); }
/// Set this test to fail state.
void fail(double value) { update_result("fail", value); }
/// Set this test to error state.
void error(double value = 0) { update_result("error", value); }
nlohmann::json json;
private:
void update_result(std::string_view status, double value) {
json["result"] = status;
json["value"] = value;
}
};
/** Write out a collection of tests to a json file.
*
*/
void write_test(const std::vector<Test> &data, const std::string &fname) {
nlohmann::json test;
for (auto &entry : data) {
test["tests"].push_back(entry.json);
}
std::cout << fmt::format("Writing test data to {}\n", fname);
std::ofstream output_file(fname);
output_file << std::setw(4) << test << "\n";
}
/** Write a single test to json file.
*/
void write_test(const Test &data, const std::string &fname) {
std::vector<Test> vtd{data};
write_test(vtd, fname);
}
} // namespace common_bench
#endif
File moved
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include <exception> #include <exception>
#include <string> #include <string>
namespace eic::util { namespace common_bench {
class Exception : public std::exception { class Exception : public std::exception {
public: public:
Exception(std::string_view msg, std::string_view type = "exception") : msg_{msg}, type_{type} {} Exception(std::string_view msg, std::string_view type = "exception") : msg_{msg}, type_{type} {}
......
File moved
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
common:setup: common:setup:
stage: config stage: config
needs: ["common:variables"]
artifacts: artifacts:
expire_in: 72 hours expire_in: 72 hours
paths: paths:
...@@ -11,7 +12,7 @@ common:setup: ...@@ -11,7 +12,7 @@ common:setup:
- results - results
- config - config
script: script:
- git clone "${CI_REPOSITORY_URL}" setup - git clone -b "${COMMON_BENCH_VERSION}" "${CI_REPOSITORY_URL}" setup
- source setup/bin/env.sh && ./setup/bin/install_common.sh - source setup/bin/env.sh && ./setup/bin/install_common.sh
common:detector: common:detector:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment