Skip to content

Commit

Permalink
Add YAML tests for packet access instructions
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Thaler <[email protected]>
  • Loading branch information
dthaler committed Jan 26, 2024
1 parent 490f717 commit dd1648d
Show file tree
Hide file tree
Showing 2 changed files with 103 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/ebpf_yaml.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ static ebpf_verifier_options_t raw_options_to_options(const std::set<string>& ra
// All YAML tests use no_simplify and !setup_constraints.
options.no_simplify = true;
options.setup_constraints = false;
options.legacy = true;

for (const string& name : raw_options) {
if (name == "!allow_division_by_zero") {
Expand Down
102 changes: 102 additions & 0 deletions test-data/packet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,105 @@ post: [
"r3.svalue=r3.uvalue",
"r2.packet_offset-r3.packet_offset<=65526", "r3.packet_offset-r2.packet_offset<=8"
]
---
test-case: legacy 1 byte packet access imm

pre: [
"r1.type=number",
"r6.type=ctx", "r6.ctx_offset=0"
]

code:
<start>: |
r0 = *(u8 *)skb[23]
post: [
"r0.type=number",
"r6.type=ctx", "r6.ctx_offset=0"
]
---
test-case: legacy 2 byte packet access imm

pre: [
"r1.type=number",
"r6.type=ctx", "r6.ctx_offset=0"
]

code:
<start>: |
r0 = *(u16 *)skb[23]
post: [
"r0.type=number",
"r6.type=ctx", "r6.ctx_offset=0"
]
---
test-case: legacy 4 byte packet access imm

pre: [
"r1.type=number",
"r6.type=ctx", "r6.ctx_offset=0"
]

code:
<start>: |
r0 = *(u32 *)skb[23]
post: [
"r0.type=number",
"r6.type=ctx", "r6.ctx_offset=0"
]
---
test-case: legacy 1 byte packet access reg

pre: [
"r1.type=number",
"r6.type=ctx", "r6.ctx_offset=0",
"r7.type=number", "r7.svalue=23", "r7.uvalue=23"
]

code:
<start>: |
r0 = *(u8 *)skb[r7]
post: [
"r0.type=number",
"r6.type=ctx", "r6.ctx_offset=0",
"r7.type=number", "r7.svalue=23", "r7.uvalue=23"
]
---
test-case: legacy 2 byte packet access reg

pre: [
"r1.type=number",
"r6.type=ctx", "r6.ctx_offset=0",
"r7.type=number", "r7.svalue=23", "r7.uvalue=23"
]

code:
<start>: |
r0 = *(u16 *)skb[r7]
post: [
"r0.type=number",
"r6.type=ctx", "r6.ctx_offset=0",
"r7.type=number", "r7.svalue=23", "r7.uvalue=23"
]
---
test-case: legacy 4 byte packet access reg

pre: [
"r1.type=number",
"r6.type=ctx", "r6.ctx_offset=0",
"r7.type=number", "r7.svalue=23", "r7.uvalue=23"
]

code:
<start>: |
r0 = *(u32 *)skb[r7]
post: [
"r0.type=number",
"r6.type=ctx", "r6.ctx_offset=0",
"r7.type=number", "r7.svalue=23", "r7.uvalue=23"
]

0 comments on commit dd1648d

Please sign in to comment.