PandA-2024.02
non_deterministic_flows.cpp
Go to the documentation of this file.
1 /*
2  *
3  * _/_/_/ _/_/ _/ _/ _/_/_/ _/_/
4  * _/ _/ _/ _/ _/_/ _/ _/ _/ _/ _/
5  * _/_/_/ _/_/_/_/ _/ _/_/ _/ _/ _/_/_/_/
6  * _/ _/ _/ _/ _/ _/ _/ _/ _/
7  * _/ _/ _/ _/ _/ _/_/_/ _/ _/
8  *
9  * ***********************************************
10  * PandA Project
11  * URL: http://panda.dei.polimi.it
12  * Politecnico di Milano - DEIB
13  * System Architectures Group
14  * ***********************************************
15  * Copyright (C) 2017-2024 Politecnico di Milano
16  *
17  * This file is part of the PandA framework.
18  *
19  * The PandA framework is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  *
32  */
42 #include "Parameter.hpp" // for Parameter, OPT_output_tem...
43 #include "dbgPrintHelper.hpp" // for DEBUG_LEVEL_VERY_PEDANTIC
44 #include "exceptions.hpp" // for IsError, THROW_ASSERT
45 #include "fileIO.hpp" // for PandaSystem
46 #include "string_manipulation.hpp" // for STR
47 #include <filesystem> // for create_directory, exists
48 
49 const std::string NonDeterministicFlows::ComputeArgString(const size_t seed) const
50 {
51  const auto argv = parameters->CGetArgv();
52  std::string arg_string;
53  for(const auto& arg : argv)
54  {
56  if(arg_string == "")
57  {
58  THROW_ASSERT(arg.size() and arg[0] == '/', "Relative path executable not supported " + arg);
59  arg_string += arg;
60  }
61  else
62  {
63  arg_string += " ";
64  if(arg.find("--test-single-non-deterministic-flow") == std::string::npos and
65  arg.find("--test-multiple-non-deterministic-flows") == std::string::npos)
66  {
67  arg_string += arg;
68  }
69  }
70  }
71  arg_string += " --test-single-non-deterministic-flow=" + STR(seed);
72  return arg_string;
73 }
74 
75 bool NonDeterministicFlows::ExecuteTool(const size_t seed) const
76 {
77  INDENT_DBG_MEX(DEBUG_LEVEL_VERY_PEDANTIC, debug_level, "-->Executing with seed " + STR(seed));
78  const auto arg_string = ComputeArgString(seed);
79  const auto temp_directory = parameters->getOption<std::string>(OPT_output_temporary_directory);
80  const auto new_directory = temp_directory + "/" + STR(seed);
81  if(std::filesystem::exists(new_directory))
82  {
83  std::filesystem::remove_all(new_directory);
84  }
85  std::filesystem::create_directory(new_directory);
86  const auto ret = PandaSystem(parameters, "cd " + new_directory + "; " + arg_string, false,
87  new_directory + "/tool_execution_output");
88  if(IsError(ret))
89  {
91  return false;
92  }
93  else
94  {
96  return true;
97  }
98 }
99 
100 NonDeterministicFlows::NonDeterministicFlows(const DesignFlowManagerConstRef _design_flow_manager,
101  const ParameterConstRef _parameters)
102  : DesignFlow(_design_flow_manager, DesignFlow_Type::NON_DETERMINISTIC_FLOWS, _parameters)
103 {
104 }
105 
107 
109 {
110  const auto initial_seed = parameters->getOption<size_t>(OPT_seed);
111  const auto number_of_runs = parameters->getOption<size_t>(OPT_test_multiple_non_deterministic_flows);
112  for(size_t run = 0; run < number_of_runs; run++)
113  {
114  if(not ExecuteTool(initial_seed + run))
115  {
117  }
118  }
120 }
#define DEBUG_LEVEL_VERY_PEDANTIC
extremely verbose debugging print is performed.
#define INDENT_DBG_MEX(dbgLevel, curDbgLevel, mex)
We are producing a debug version of the program, so the message is printed;.
DesignFlowStep_Status Exec() override
Execute the flow.
File containing functions and utilities to support the printing of debug messagges.
Design flow to check different non deterministic flows.
exceptions managed by PandA
#define STR(s)
Macro which performs a lexical_cast to a string.
Auxiliary methods for manipulating string.
bool IsError(const int error_value)
Utility include.
Definition: exceptions.cpp:58
~NonDeterministicFlows() override
Destructor.
NonDeterministicFlows(const DesignFlowManagerConstRef design_flow_manager, const ParameterConstRef parameters)
Constructor.
utility function used to read files.
bool ExecuteTool(const size_t seed) const
Execute tool with non deterministic flow.
const ParameterConstRef parameters
Set of input parameters.
DesignFlowStep_Status
The status of a step.
int PandaSystem(const ParameterConstRef Param, const std::string &system_command, bool host_exec, const std::string &output, const unsigned int type, const bool background, const size_t timeout)
System call forcing execution with bash.
Definition: fileIO.cpp:78
DesignFlow_Type
Definition: design_flow.hpp:47
Template borrowed from the ANTLR library by Terence Parr (http://www.jGuru.com - Software rights: htt...
Definition: refcount.hpp:94
this class is used to manage the command-line or XML options.
int debug_level
The debug level.
const std::string ComputeArgString(const size_t seed) const
Compute the arg list string of the tool.
#define THROW_ASSERT(cond, str_expr)
helper function used to check an assert and if needed to throw an error in a standard way ...
Definition: exceptions.hpp:289

Generated on Mon Feb 12 2024 13:02:51 for PandA-2024.02 by doxygen 1.8.13