Skip to content

Commit 8971eb5

Browse files
a bitmap to record the branch coverage
1 parent 1c6a045 commit 8971eb5

File tree

2 files changed

+26
-22
lines changed

2 files changed

+26
-22
lines changed

headers/wasm/concolic_driver.hpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "symbolic_rt.hpp"
77
#include "utils.hpp"
88
#include <functional>
9+
#include <optional>
910
#include <ostream>
1011
#include <string>
1112
#include <vector>
@@ -14,10 +15,11 @@ class ConcolicDriver {
1415
friend class ManagedConcolicCleanup;
1516

1617
public:
17-
ConcolicDriver(std::function<void()> entrypoint, std::string tree_file)
18-
: entrypoint(entrypoint), tree_file(tree_file) {}
19-
ConcolicDriver(std::function<void()> entrypoint)
20-
: entrypoint(entrypoint), tree_file(std::nullopt) {}
18+
ConcolicDriver(std::function<void()> entrypoint,
19+
std::optional<std::string> tree_file, int branchCount)
20+
: entrypoint(entrypoint), tree_file(tree_file) {
21+
ExploreTree.branch_cov_map.assign(branchCount, false);
22+
}
2123
void run();
2224

2325
private:
@@ -92,22 +94,16 @@ static std::monostate reset_stacks() {
9294
return std::monostate{};
9395
}
9496

95-
static void start_concolic_execution_with(
96-
std::function<std::monostate(std::monostate)> entrypoint,
97-
std::string tree_file) {
98-
ConcolicDriver driver([=]() { entrypoint(std::monostate{}); }, tree_file);
99-
driver.run();
100-
}
101-
10297
static void start_concolic_execution_with(
10398
std::function<std::monostate(std::monostate)> entrypoint, int branchCount) {
10499

105100
const char *env_tree_file = std::getenv("TREE_FILE");
106101

107-
ConcolicDriver driver =
108-
env_tree_file ? ConcolicDriver([=]() { entrypoint(std::monostate{}); },
109-
env_tree_file)
110-
: ConcolicDriver([=]() { entrypoint(std::monostate{}); });
102+
auto tree_file =
103+
env_tree_file ? std::make_optional(env_tree_file) : std::nullopt;
104+
105+
ConcolicDriver driver = ConcolicDriver(
106+
[=]() { entrypoint(std::monostate{}); }, tree_file, branchCount);
111107
driver.run();
112108
}
113109

headers/wasm/symbolic_rt.hpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ struct NodeBox {
291291
std::unique_ptr<Node> node;
292292
NodeBox *parent;
293293

294-
std::monostate fillIfElseNode(SymVal cond, int id);
294+
std::monostate fillIfElseNode(SymVal cond);
295295
std::monostate fillFinishedNode();
296296
std::monostate fillFailedNode();
297297
std::monostate fillUnreachableNode();
@@ -344,11 +344,10 @@ struct IfElseNode : Node {
344344
SymVal cond;
345345
std::unique_ptr<NodeBox> true_branch;
346346
std::unique_ptr<NodeBox> false_branch;
347-
int id;
348347

349-
IfElseNode(SymVal cond, NodeBox *parent, int id)
348+
IfElseNode(SymVal cond, NodeBox *parent)
350349
: cond(cond), true_branch(std::make_unique<NodeBox>(parent)),
351-
false_branch(std::make_unique<NodeBox>(parent)), id(id) {}
350+
false_branch(std::make_unique<NodeBox>(parent)) {}
352351

353352
std::string to_string() override {
354353
std::string result = "IfElseNode {\n";
@@ -481,10 +480,10 @@ inline NodeBox::NodeBox(NodeBox *parent)
481480
/* TODO: avoid allocation of unexplored node */
482481
parent(parent) {}
483482

484-
inline std::monostate NodeBox::fillIfElseNode(SymVal cond, int id) {
483+
inline std::monostate NodeBox::fillIfElseNode(SymVal cond) {
485484
// fill the current NodeBox with an ifelse branch node when it's unexplored
486485
if (this->isUnexplored()) {
487-
node = std::make_unique<IfElseNode>(cond, this, id);
486+
node = std::make_unique<IfElseNode>(cond, this);
488487
}
489488
assert(
490489
dynamic_cast<IfElseNode *>(node.get()) != nullptr &&
@@ -583,7 +582,8 @@ class ExploreTree_t {
583582
std::monostate fillFailedNode() { return cursor->fillFailedNode(); }
584583

585584
std::monostate fillIfElseNode(SymVal cond, int id) {
586-
return cursor->fillIfElseNode(cond, id);
585+
branch_cov_map[id] = true;
586+
return cursor->fillIfElseNode(cond);
587587
}
588588

589589
std::monostate moveCursor(bool branch, Snapshot_t snapshot) {
@@ -637,6 +637,14 @@ class ExploreTree_t {
637637
// For now, we just iterate through the tree and return the first unexplored
638638
return pick_unexplored_of(root.get());
639639
}
640+
std::vector<bool> branch_cov_map;
641+
bool all_branch_covered() const {
642+
for (bool covered : branch_cov_map) {
643+
if (!covered)
644+
return false;
645+
}
646+
return true;
647+
}
640648

641649
private:
642650
NodeBox *pick_unexplored_of(NodeBox *node) {

0 commit comments

Comments
 (0)