Skip to content

Commit 9e1b6ed

Browse files
committed
clang-format
1 parent 95c55bf commit 9e1b6ed

27 files changed

+238
-192
lines changed

Makefile

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
.PHONY: clean test coverage asan format format-check ci lf-test lib proto
2+
3+
test: unit-test lf-test
4+
5+
# Generate protobuf code
6+
proto:
7+
python3 external/nanopb/generator/nanopb_generator.py -Iexternal/nanopb/generator/proto/ -Iexternal/proto -L'#include "nanopb/%s"' -Dexternal/proto message.proto
8+
9+
# Build reactor-uc as a static library
10+
lib:
11+
cmake -Bbuild
12+
cmake --build build
13+
make -C build
14+
15+
# Build and run the unit tests
16+
unit-test:
17+
cmake -Bbuild -DBUILD_TESTS=ON
18+
cmake --build build
19+
make test -C build
20+
21+
# Build and run lf tests
22+
lf-test:
23+
make -C test/lf
24+
25+
# Get coverage data on unit tests
26+
coverage:
27+
cmake -Bbuild -DBUILD_TESTS=ON -DTEST_COVERAGE=ON
28+
cmake --build build
29+
make coverage -C build
30+
31+
# Compile tests with AddressSanitizer and run them
32+
asan:
33+
cmake -Bbuild -DASAN=ON -DBUILD_TESTS=ON
34+
cmake --build build
35+
make test -C build
36+
37+
# Format the code base
38+
SRC_FILES := $(shell find ./lib -name '*.cc' -print)
39+
HDR_FILES := $(shell find ./include -name '*.hh' -print)
40+
41+
format:
42+
clang-format -i -style=file $(SRC_FILES) $(HDR_FILES)
43+
44+
# Check that the code base is formatted
45+
format-check:
46+
clang-format --dry-run --Werror -style=file $(SRC_FILES) $(HDR_FILES)
47+
48+
# Run the entire CI flow
49+
ci: clean test coverage format-check
50+
51+
clean:
52+
rm -rf build

include/reactor-cpp/connection.hh

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,8 @@ public:
143143
};
144144
}
145145

146-
auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock,
147-
const std::function<bool(void)>& abort_waiting) -> bool override {
146+
auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock, const std::function<bool(void)>& abort_waiting)
147+
-> bool override {
148148
reactor_assert(lock.owns_lock());
149149
log_.debug() << "downstream tries to acquire tag " << tag;
150150

@@ -210,8 +210,8 @@ public:
210210
};
211211
}
212212

213-
auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock,
214-
const std::function<bool(void)>& abort_waiting) -> bool override {
213+
auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock, const std::function<bool(void)>& abort_waiting)
214+
-> bool override {
215215
// Since this is a delayed connection, we can go back in time and need to
216216
// acquire the latest upstream tag that can create an event at the given
217217
// tag. We also need to consider that given a delay d and a tag g=(t, n),
@@ -240,8 +240,8 @@ public:
240240
};
241241
}
242242

243-
auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock,
244-
const std::function<bool(void)>& abort_waiting) -> bool override {
243+
auto acquire_tag(const Tag& tag, std::unique_lock<std::mutex>& lock, const std::function<bool(void)>& abort_waiting)
244+
-> bool override {
245245
this->log_.debug() << "downstream tries to acquire tag " << tag;
246246
return PhysicalTimeBarrier::acquire_tag(tag, lock, this->environment()->scheduler(), abort_waiting);
247247
}

include/reactor-cpp/environment.hh

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,25 @@ private:
7575
Graph<BasePort*, ConnectionProperties> graph_{};
7676
Graph<BasePort*, ConnectionProperties> optimized_graph_{};
7777

78-
7978
std::mutex shutdown_mutex_{};
8079

8180
auto startup(const TimePoint& start_time) -> std::thread;
8281

8382
public:
84-
//TODO: fix visebility
83+
// TODO: fix visebility
8584
void calculate_indexes();
8685
void build_dependency_graph(Reactor* reactor);
8786
void clear_dependency_graph();
8887

89-
9088
explicit Environment(unsigned int num_workers, bool fast_fwd_execution = default_fast_fwd_execution,
9189
const Duration& timeout = Duration::max());
9290
explicit Environment(const std::string& name, Environment* containing_environment);
9391

9492
auto name() -> const std::string& { return name_; }
9593

96-
void start_mutation() {
97-
phase_ = Phase::Mutation;
98-
}
94+
void start_mutation() { phase_ = Phase::Mutation; }
9995

100-
void stop_mutation() {
101-
phase_ = Phase::Execution;
102-
}
96+
void stop_mutation() { phase_ = Phase::Execution; }
10397

10498
// this method draw a connection between two graph elements with some properties
10599
template <class T> void draw_connection(Port<T>& source, Port<T>& sink, ConnectionProperties properties) {
@@ -112,7 +106,6 @@ public:
112106
auto properties = graph_.remove_edge(source, sink);
113107
} else {
114108
return top_environment_->remove_connection(source, sink);
115-
116109
}
117110
}
118111

include/reactor-cpp/graph.hh

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,24 +54,22 @@ public:
5454
std::vector<std::pair<P, E>> edges{std::make_pair(properties, destination)};
5555
graph_[source] = edges;
5656
} else {
57-
auto &edges = graph_[source];
58-
auto duplicate = std::find_if(edges.begin(), edges.end(),
59-
[&](const std::pair<P, E>& edge) {
60-
return edge.first == properties && edge.second == destination;
61-
});
62-
if (duplicate == edges.end()) {
63-
graph_[source].emplace_back(properties, destination);
64-
}
57+
auto& edges = graph_[source];
58+
auto duplicate = std::find_if(edges.begin(), edges.end(), [&](const std::pair<P, E>& edge) {
59+
return edge.first == properties && edge.second == destination;
60+
});
61+
if (duplicate == edges.end()) {
62+
graph_[source].emplace_back(properties, destination);
63+
}
6564
}
6665
}
6766

6867
auto remove_edge(E source, E destinations) noexcept -> std::optional<P> {
6968
if (graph_.find(source) == std::end(graph_)) {
7069
return std::nullopt;
7170
} else {
72-
auto conns = std::find_if(std::begin(graph_[source]), std::end(graph_[source]), [destinations](auto val) {
73-
return val.second == destinations;
74-
});
71+
auto conns = std::find_if(std::begin(graph_[source]), std::end(graph_[source]),
72+
[destinations](auto val) { return val.second == destinations; });
7573

7674
if (conns != std::end(graph_[source])) {
7775
graph_[source].erase(conns);

include/reactor-cpp/impl/port_impl.hh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,10 @@
99
#ifndef REACTOR_CPP_IMPL_PORT_IMPL_HH
1010
#define REACTOR_CPP_IMPL_PORT_IMPL_HH
1111

12-
#include "reactor-cpp/port.hh"
13-
#include "reactor-cpp/reactor.hh"
1412
#include "reactor-cpp/assert.hh"
1513
#include "reactor-cpp/environment.hh"
16-
14+
#include "reactor-cpp/port.hh"
15+
#include "reactor-cpp/reactor.hh"
1716

1817
namespace reactor {
1918

include/reactor-cpp/multiport.hh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,32 +48,31 @@ protected:
4848

4949
void register_port(BasePort& port, size_t idx);
5050

51-
5251
public:
53-
explicit BaseMultiport(const std::string& name) : multiport_name_(name) {};
52+
explicit BaseMultiport(const std::string& name)
53+
: multiport_name_(name){};
5454
~BaseMultiport() = default;
55-
auto name() const -> std::string {
56-
return multiport_name_;
57-
}
55+
auto name() const -> std::string { return multiport_name_; }
5856
};
5957

60-
template <class T>
61-
class MutationChangeMultiportSize;
58+
template <class T> class MutationChangeMultiportSize;
6259

6360
template <class T, class A = std::allocator<T>>
6461
class Multiport : public BaseMultiport { // NOLINT cppcoreguidelines-special-member-functions
6562
protected:
6663
std::vector<T> ports_{}; // NOLINT cppcoreguidelines-non-private-member-variables-in-classes
6764

6865
friend MutationChangeMultiportSize<T>;
66+
6967
public:
7068
using value_type = typename A::value_type;
7169
using size_type = typename A::size_type;
7270

7371
using iterator = typename std::vector<T>::iterator;
7472
using const_iterator = typename std::vector<T>::const_iterator;
7573

76-
explicit Multiport(const std::string& name) noexcept : BaseMultiport(name) {};
74+
explicit Multiport(const std::string& name) noexcept
75+
: BaseMultiport(name){};
7776
~Multiport() noexcept = default;
7877

7978
auto operator==(const Multiport& other) const noexcept -> bool {
@@ -106,7 +105,8 @@ public:
106105

107106
template <class T, class A = std::allocator<T>> class ModifableMultiport : public Multiport<T, A> {
108107
public:
109-
ModifableMultiport(const std::string& name) : Multiport<T, A>(name) {}
108+
ModifableMultiport(const std::string& name)
109+
: Multiport<T, A>(name) {}
110110

111111
void reserve(std::size_t size) noexcept {
112112
this->ports_.reserve(size);

include/reactor-cpp/mutations.hh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ enum MutationResult {
1313
class Mutation {
1414
public:
1515
virtual ~Mutation() = default;
16-
virtual auto run() -> MutationResult = 0 ;
16+
virtual auto run() -> MutationResult = 0;
1717
virtual auto rollback() -> MutationResult = 0;
1818
};
1919

20-
}
20+
} // namespace reactor
2121

22-
#endif //MUTATIONS_HH
22+
#endif // MUTATIONS_HH

include/reactor-cpp/mutations/bank.hh

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,14 @@
77

88
#include <vector>
99

10-
#include "../reactor.hh"
1110
#include "../mutations.hh"
11+
#include "../reactor.hh"
1212

1313
namespace reactor {
1414
class Reactor;
1515
class Environment;
1616

17-
template<class T>
18-
class MutationChangeBankSize : public reactor::Mutation {
19-
private:
17+
template <class T> class MutationChangeBankSize : public reactor::Mutation {
2018
std::vector<T>* bank_ = nullptr;
2119
std::size_t desired_size_ = 0;
2220
std::size_t size_before_application_ = 0;
@@ -26,14 +24,18 @@ private:
2624
void change_size(std::size_t);
2725

2826
public:
29-
MutationChangeBankSize(std::vector<T>* bank, Reactor* reactor, std::size_t size, std::function<T(Reactor* reactor, std::size_t index)>);
27+
MutationChangeBankSize(std::vector<T>* bank, Reactor* reactor, std::size_t size,
28+
std::function<T(Reactor* reactor, std::size_t index)>);
3029
MutationChangeBankSize() = default;
31-
explicit MutationChangeBankSize(const std::vector<T>& other) : bank_(other.bank_), desired_size_(other.desired_size_), size_before_application_(other.size_before_application_) {}
30+
explicit MutationChangeBankSize(const std::vector<T>& other)
31+
: bank_(other.bank_)
32+
, desired_size_(other.desired_size_)
33+
, size_before_application_(other.size_before_application_) {}
3234
~MutationChangeBankSize() override = default;
3335

34-
auto run() -> reactor::MutationResult override;
35-
auto rollback() -> reactor::MutationResult override;
36+
auto run() -> MutationResult override;
37+
auto rollback() -> MutationResult override;
3638
};
37-
}
39+
} // namespace reactor
3840

39-
#endif //MUTATION_BANK_HH
41+
#endif // MUTATION_BANK_HH

include/reactor-cpp/mutations/connection.hh

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ namespace reactor {
1111
class Reactor;
1212
class Environment;
1313

14-
template<class A, class B>
15-
class MutationAddConnection : public Mutation {
14+
template <class A, class B> class MutationAddConnection : public Mutation {
1615
private:
1716
A* source_;
1817
B* sink_;
@@ -21,13 +20,17 @@ private:
2120

2221
public:
2322
MutationAddConnection(A* source, B* sink, Reactor* reactor);
24-
MutationAddConnection(const MutationAddConnection& other) : source_(other.source_), sink_(other.sink_), connection_(other.connection_), reactor_(other.reactor_) {}
23+
MutationAddConnection(const MutationAddConnection& other)
24+
: source_(other.source_)
25+
, sink_(other.sink_)
26+
, connection_(other.connection_)
27+
, reactor_(other.reactor_) {}
2528
MutationAddConnection() = default;
2629
~MutationAddConnection() override = default;
2730

2831
auto run() -> MutationResult override;
2932
auto rollback() -> MutationResult override;
3033
};
31-
}
34+
} // namespace reactor
3235

33-
#endif //MUTATION_CONNECTION_HH
36+
#endif // MUTATION_CONNECTION_HH

include/reactor-cpp/mutations/multiport.hh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,11 @@
1111
#include "../mutations.hh"
1212
#include "../port.hh"
1313

14-
1514
namespace reactor {
1615
class Reactor;
1716
class Environment;
1817

19-
template<class T>
20-
class MutationChangeOutputMultiportSize : public Mutation {
18+
template <class T> class MutationChangeOutputMultiportSize : public Mutation {
2119
private:
2220
ModifableMultiport<Output<T>>* multiport_ = nullptr;
2321
std::set<Reaction*> anti_dependencies_{};
@@ -28,16 +26,18 @@ private:
2826
void change_size(std::size_t);
2927

3028
public:
31-
MutationChangeOutputMultiportSize(ModifableMultiport<Output<T>>* multiport, Reactor* reactor, std::set<Reaction*>& anti_dependencies, std::size_t size);
29+
MutationChangeOutputMultiportSize(ModifableMultiport<Output<T>>* multiport, Reactor* reactor,
30+
std::set<Reaction*>& anti_dependencies, std::size_t size);
3231
MutationChangeOutputMultiportSize() = default;
33-
MutationChangeOutputMultiportSize(const MutationChangeOutputMultiportSize& other) : multiport_(other.multiport_), desired_size_(other.desired_size_), size_before_application_(other.size_before_application_) {}
32+
MutationChangeOutputMultiportSize(const MutationChangeOutputMultiportSize& other)
33+
: multiport_(other.multiport_)
34+
, desired_size_(other.desired_size_)
35+
, size_before_application_(other.size_before_application_) {}
3436
~MutationChangeOutputMultiportSize() override = default;
3537

36-
3738
auto run() -> MutationResult override;
3839
auto rollback() -> MutationResult override;
3940
};
40-
}
41-
41+
} // namespace reactor
4242

43-
#endif //MUTATION_MULTIPORT_HH
43+
#endif // MUTATION_MULTIPORT_HH

0 commit comments

Comments
 (0)