Hedgehog  3.1.0
A library to generate hybrid pipeline workflow systems
Loading...
Searching...
No Matches
data_race_test.h
Go to the documentation of this file.
1// NIST-developed software is provided by NIST as a public service. You may use, copy and distribute copies of the
2// software in any medium, provided that you keep intact this entire notice. You may improve, modify and create
3// derivative works of the software or any portion of the software, and you may copy and distribute such modifications
4// or works. Modified works should carry a notice stating that you changed the software and should note the date and
5// nature of any such change. Please explicitly acknowledge the National Institute of Standards and Technology as the
6// source of the software. NIST-developed software is expressly provided "AS IS." NIST MAKES NO WARRANTY OF ANY KIND,
7// EXPRESS, IMPLIED, IN FACT OR ARISING BY OPERATION OF LAW, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF
8// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT AND DATA ACCURACY. NIST NEITHER REPRESENTS NOR
9// WARRANTS THAT THE OPERATION OF THE SOFTWARE WILL BE UNINTERRUPTED OR ERROR-FREE, OR THAT ANY DEFECTS WILL BE
10// CORRECTED. NIST DOES NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE OF THE SOFTWARE OR THE RESULTS
11// THEREOF, INCLUDING BUT NOT LIMITED TO THE CORRECTNESS, ACCURACY, RELIABILITY, OR USEFULNESS OF THE SOFTWARE. You
12// are solely responsible for determining the appropriateness of using and distributing the software and you assume
13// all risks associated with its use, including but not limited to the risks and costs of program errors, compliance
14// with applicable laws, damage to or loss of data, programs or equipment, and the unavailability or interruption of
15// operation. This software is not intended to be used in any situation where a failure could cause risk of injury or
16// damage to property. The software developed by NIST employees is not subject to copyright protection within the
17// United States.
18
19#ifndef HEDGEHOG_CX_DATA_RACE_TEST_H_
20#define HEDGEHOG_CX_DATA_RACE_TEST_H_
21
22#ifdef HH_ENABLE_HH_CX
23#include "abstract_test.h"
24
26namespace hh_cx {
27
33template<tool::HedgehogDynamicGraphForStaticAnalysis GraphType>
34class DataRaceTest : public hh_cx::AbstractTest<GraphType> {
35 public:
37 constexpr DataRaceTest() : AbstractTest<GraphType>("DataRaceTest") {}
38
40 constexpr ~DataRaceTest() override = default;
41
44 constexpr void test(hh_cx::Graph<GraphType> const *graph) override {
45 auto &registeredNodes = graph->registeredNodes();
46
47 for (size_t senderId = 0; senderId < registeredNodes.size(); ++senderId) {
48 tool::TypesNodesMap map{};
49 auto senderNode = graph->node(senderId);
50 for (size_t receiverId = 0; receiverId < graph->adjacentNodesTypes(senderNode).size(); ++receiverId) {
51 for (auto &type : graph->adjacentNodesTypes(senderNode).at(receiverId)) {
52 map.insert(type, graph->node(receiverId));
53 }
54 }
55 for (auto const &type : map.types()) {
56 if (map.nodes(type).size() > 1) {
57 bool isOutputSafe = true;
58 for (auto const &receiverNode : map.nodes(type)) {
59 isOutputSafe &= (
60 graph->isROLinked(senderNode, receiverNode, type)
61 || graph->isConstLinked(senderNode, receiverNode, type)
62 );
63 }
64 if (!isOutputSafe) {
65 if (this->errorMessage().empty()) { this->appendErrorMessage("Possible data races found:\n"); }
66 for (auto &receiverNode : map.nodes(type)) {
67 this->appendErrorMessage("\t");
68 this->appendErrorMessage(senderNode->name());
69 this->appendErrorMessage(" -> ");
70 this->appendErrorMessage(receiverNode->name());
71 this->appendErrorMessage(" (");
72 this->appendErrorMessage(type);
73 this->appendErrorMessage(")\n");
74 }
75 }
76 }
77 }
78 }
79
80 if (!this->errorMessage().empty()) {
81 this->graphValid(false);
82 }
83 }
84};
85
86} // hh_cx
87#endif //HH_ENABLE_HH_CX
88#endif //HEDGEHOG_CX_DATA_RACE_TEST_H_