From dd1648d56c722b14970004da7e6f3ee0b9ae45ea Mon Sep 17 00:00:00 2001 From: Dave Thaler Date: Fri, 26 Jan 2024 13:49:19 -0800 Subject: [PATCH] Add YAML tests for packet access instructions Signed-off-by: Dave Thaler --- src/ebpf_yaml.cpp | 1 + test-data/packet.yaml | 102 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+) diff --git a/src/ebpf_yaml.cpp b/src/ebpf_yaml.cpp index 109eb2b70..f91eb437e 100644 --- a/src/ebpf_yaml.cpp +++ b/src/ebpf_yaml.cpp @@ -169,6 +169,7 @@ static ebpf_verifier_options_t raw_options_to_options(const std::set& 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") { diff --git a/test-data/packet.yaml b/test-data/packet.yaml index 4de7f6745..57c31c203 100644 --- a/test-data/packet.yaml +++ b/test-data/packet.yaml @@ -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: + : | + 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: + : | + 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: + : | + 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: + : | + 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: + : | + 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: + : | + r0 = *(u32 *)skb[r7] + +post: [ + "r0.type=number", + "r6.type=ctx", "r6.ctx_offset=0", + "r7.type=number", "r7.svalue=23", "r7.uvalue=23" +]