Skip to content

Commit

Permalink
Add stack numbers info to post in YAML tests
Browse files Browse the repository at this point in the history
For consistency with s[a..b].type=packet etc output, this uses
the same style of output for stack numeric ranges.

Signed-off-by: Dave Thaler <dthaler@microsoft.com>
  • Loading branch information
dthaler authored and elazarg committed Feb 19, 2022
1 parent ef11bb0 commit f9ab1fc
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/crab/array_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,8 @@ bool array_domain_t::is_bottom() const { return num_bytes.is_bottom(); }

bool array_domain_t::is_top() const { return num_bytes.is_top(); }

string_invariant array_domain_t::to_set() const { return num_bytes.to_set(); }

bool array_domain_t::operator<=(const array_domain_t& other) const { return num_bytes <= other.num_bytes; }

bool array_domain_t::operator==(const array_domain_t& other) const {
Expand Down Expand Up @@ -665,4 +667,5 @@ array_domain_t array_domain_t::narrow(const array_domain_t& other) const {
std::ostream& operator<<(std::ostream& o, const array_domain_t& dom) {
return o << dom.num_bytes;
}

} // namespace crab::domains
1 change: 1 addition & 0 deletions src/crab/array_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class array_domain_t final {
array_domain_t narrow(const array_domain_t& other) const;

friend std::ostream& operator<<(std::ostream& o, const array_domain_t& dom);
[[nodiscard]] string_invariant to_set() const;

bool all_num(NumAbsDomain& inv, const linear_expression_t& lb, const linear_expression_t& ub);

Expand Down
29 changes: 29 additions & 0 deletions src/crab/bitset_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,32 @@ std::ostream& operator<<(std::ostream& o, const bitset_domain_t& b) {
o << "}";
return o;
}

string_invariant bitset_domain_t::to_set() const
{
if (this->is_bottom()) {
return string_invariant::bottom();
}
if (this->is_top()) {
return string_invariant::top();
}

std::set<std::string> result;
bool first = true;
for (int i = -EBPF_STACK_SIZE; i < 0; i++) {
if (non_numerical_bytes[EBPF_STACK_SIZE + i])
continue;
first = false;
std::string value = "s[" + std::to_string(EBPF_STACK_SIZE + i);
int j = i + 1;
for (; j < 0; j++)
if (non_numerical_bytes[EBPF_STACK_SIZE + j])
break;
if (j > i + 1)
value += "..." + std::to_string(EBPF_STACK_SIZE + j - 1);
value += "].type=number";
result.insert(value);
i = j;
}
return string_invariant{result};
}
3 changes: 3 additions & 0 deletions src/crab/bitset_domain.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <cassert>
#include <bitset>

#include "string_constraints.hpp"
#include "spec_type_descriptors.hpp" // for EBPF_STACK_SIZE

class bitset_domain_t final {
Expand All @@ -24,6 +25,8 @@ class bitset_domain_t final {

[[nodiscard]] bool is_bottom() const { return false; }

[[nodiscard]] string_invariant to_set() const;

bool operator<=(const bitset_domain_t& other) const {
return (non_numerical_bytes | other.non_numerical_bytes) == other.non_numerical_bytes;
}
Expand Down
2 changes: 1 addition & 1 deletion src/crab/ebpf_domain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ void ebpf_domain_t::operator()(const Bin& bin) {
}

string_invariant ebpf_domain_t::to_set() {
return this->m_inv.to_set();
return this->m_inv.to_set() + this->stack.to_set();
}

std::ostream& operator<<(std::ostream& o, const ebpf_domain_t& dom) {
Expand Down
12 changes: 12 additions & 0 deletions src/string_constraints.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,18 @@ string_invariant string_invariant::operator-(const string_invariant& b) const {
return res;
}

// return a+b, taking account potential optional-none
string_invariant string_invariant::operator+(const string_invariant& b) const {
if (this->is_bottom())
return b;
string_invariant res = *this;
for (const std::string& cst : b.value()) {
if (res.is_bottom() || !res.contains(cst))
res.maybe_inv->insert(cst);
}
return res;
}

std::ostream& operator<<(std::ostream& o, const string_invariant& inv) {
if (inv.is_bottom()) {
return o << "_|_";
Expand Down
1 change: 1 addition & 0 deletions src/string_constraints.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ struct string_invariant {
}

string_invariant operator-(const string_invariant& b) const;
string_invariant operator+(const string_invariant& b) const;

bool operator==(const string_invariant& other) const { return maybe_inv == other.maybe_inv; }

Expand Down
2 changes: 2 additions & 0 deletions test-data/single-instruction-assignment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ code:
post:
- r10.type=stack
- r10.offset=512
- s[504...511].type=number
- s[504...511].value=0
---
test-case: stack assign number register
Expand All @@ -78,6 +79,7 @@ post:
- r1.value=0
- r10.type=stack
- r10.offset=512
- s[504...511].type=number
- s[504...511].value=0
---
test-case: stack assign packet register
Expand Down

0 comments on commit f9ab1fc

Please sign in to comment.