Skip to content

Commit

Permalink
Merge branch 'main' into swap
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan-Jowett committed Jan 16, 2024
2 parents fb48ac5 + 3a32dae commit 4946099
Show file tree
Hide file tree
Showing 23 changed files with 194 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:

- name: Cache nuget packages
if: inputs.platform == 'windows-2019' || inputs.platform == 'windows-2022'
uses: actions/cache@704facf57e6136b1bc63b828d79edcd491f0ee84
uses: actions/cache@e12d46a63a90f2fae62d114769bbf2a179198b5c
env:
cache-name: cache-nuget-modules
with:
Expand Down
30 changes: 26 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ Options:
--list_instructions arg List instructions used and not used in tests
--list_used_instructions arg List instructions used in tests
--list_unused_instructions arg List instructions not used in tests
--debug arg Print debug information
--xdp_prolog arg XDP prolog
--elf arg ELF format
--debug (true|false) Print debug information
--xdp_prolog (true|false) XDP prolog
--elf (true|false) ELF format
--cpu_version arg CPU version
--include_regex arg Include regex
--exclude_regex arg Exclude regex
```

The `--xdp_prolog` argument should *only* be used with the `libbpf_plugin`.
`--xdp_prolog true` should *only* be used with the `libbpf_plugin`.

## Using a published package
Select the desired version from [bpf_conformance](https://github.com/Alan-Jowett/bpf_conformance/pkgs/container/bpf_conformance)
Expand Down Expand Up @@ -179,3 +179,25 @@ PASS: "tests/subnet.data"
Passed 91 out of 91 tests.
```

## bpf_conformance_runner plugins

bpf_conformance_runner invokes plugins using command-line execution, and uses stdin, stdout, and stderr to
exchange additional information as follows:

```
<plugin name> [<base16 memory bytes>] [<plugin options>] [--elf]
```

where:
* `<plugin name>`: the plugin executable name
* `<base16 memory bytes>`: if present, the contents of the `mem` section of a test data file
* `<plugin options>`: any additional options to pass to the plugin
* `--elf`: if present, indicates that the data passed to stdin will be in ELF format

The program is then passed to the plugin via stdin, either as raw bytecode or (if `--elf` is specified) in ELF format.
The plugin must then either:
* compute a successful result and output the final contents of `r0` in hex (either with or without a leading "0x")
to stdout and exit with a status of 0, OR
* output an error message to stderr and exit with a non-zero status.

Additional plugins can be created based on the above specification.
2 changes: 1 addition & 1 deletion external/elfio
Submodule elfio updated 1 files
+1 −1 elfio/elfio_modinfo.hpp
6 changes: 4 additions & 2 deletions src/bpf_assembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ typedef class _bpf_assembler
{"rsh", 0x7},
{"neg", 0x8},
{"mod", 0x9},
{"smod", 0x9},
{"xor", 0xa},
{"mov", 0xb},
{"arsh", 0xc},
Expand Down Expand Up @@ -252,7 +253,7 @@ typedef class _bpf_assembler
inst.imm = _decode_imm32(mnemonic.substr(4));
return inst;
}
if (mnemonic.starts_with("sdiv")) {
if (mnemonic.starts_with("sdiv") || mnemonic.starts_with("smod")) {
inst.offset = 1;
}

Expand Down Expand Up @@ -454,7 +455,6 @@ typedef class _bpf_assembler
{"be16", {&_bpf_assembler::_encode_alu, 1}}, {"be32", {&_bpf_assembler::_encode_alu, 1}},
{"be64", {&_bpf_assembler::_encode_alu, 1}}, {"call", {&_bpf_assembler::_encode_jmp, 2}},
{"div", {&_bpf_assembler::_encode_alu, 2}}, {"div32", {&_bpf_assembler::_encode_alu, 2}},
{"sdiv", {&_bpf_assembler::_encode_alu, 2}}, {"sdiv32", {&_bpf_assembler::_encode_alu, 2}},
{"exit", {&_bpf_assembler::_encode_jmp, 0}}, {"ja", {&_bpf_assembler::_encode_jmp, 1}},
{"jeq", {&_bpf_assembler::_encode_jmp, 3}}, {"jeq32", {&_bpf_assembler::_encode_jmp, 3}},
{"jge", {&_bpf_assembler::_encode_jmp, 3}}, {"jge32", {&_bpf_assembler::_encode_jmp, 3}},
Expand All @@ -478,6 +478,8 @@ typedef class _bpf_assembler
{"neg", {&_bpf_assembler::_encode_alu, 1}}, {"neg32", {&_bpf_assembler::_encode_alu, 1}},
{"or", {&_bpf_assembler::_encode_alu, 2}}, {"or32", {&_bpf_assembler::_encode_alu, 2}},
{"rsh", {&_bpf_assembler::_encode_alu, 2}}, {"rsh32", {&_bpf_assembler::_encode_alu, 2}},
{"sdiv", {&_bpf_assembler::_encode_alu, 2}}, {"sdiv32", {&_bpf_assembler::_encode_alu, 2}},
{"smod", {&_bpf_assembler::_encode_alu, 2}}, {"smod32", {&_bpf_assembler::_encode_alu, 2}},
{"stb", {&_bpf_assembler::_encode_st, 2}}, {"stdw", {&_bpf_assembler::_encode_st, 2}},
{"sth", {&_bpf_assembler::_encode_st, 2}}, {"stw", {&_bpf_assembler::_encode_st, 2}},
{"stxb", {&_bpf_assembler::_encode_stx, 2}}, {"stxdw", {&_bpf_assembler::_encode_stx, 2}},
Expand Down
15 changes: 10 additions & 5 deletions src/opcode_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ needs_imm(uint8_t opcode)
inline bool
needs_offset(uint8_t opcode)
{
return opcode == 0x34 || opcode == 0x37 || opcode == 0x3c || opcode == 0x3f;
return opcode == 0x34 || opcode == 0x37 || opcode == 0x3c || opcode == 0x3f || opcode == 0x94 || opcode == 0x97 ||
opcode == 0x9c || opcode == 0x9f || opcode == 0xb4 || opcode == 0xb7 || opcode == 0xbc || opcode == 0xbf;
}

class bpf_conformance_instruction_t
Expand Down Expand Up @@ -289,11 +290,15 @@ static const std::set<bpf_conformance_instruction_t, InstCmp> instructions_from_
{bpf_conformance_test_cpu_version_t::v3, 0x85, 0x01},
{bpf_conformance_test_cpu_version_t::v3, 0x85, 0x02},
{bpf_conformance_test_cpu_version_t::v1, 0x87},
{bpf_conformance_test_cpu_version_t::v1, 0x94},
{bpf_conformance_test_cpu_version_t::v1, 0x94, 0x00, 0x00, 0x00},
{bpf_conformance_test_cpu_version_t::v4, 0x94, 0x00, 0x00, 0x01},
{bpf_conformance_test_cpu_version_t::v1, 0x95},
{bpf_conformance_test_cpu_version_t::v1, 0x97},
{bpf_conformance_test_cpu_version_t::v1, 0x9c},
{bpf_conformance_test_cpu_version_t::v1, 0x9f},
{bpf_conformance_test_cpu_version_t::v1, 0x97, 0x00, 0x00, 0x00},
{bpf_conformance_test_cpu_version_t::v4, 0x97, 0x00, 0x00, 0x01},
{bpf_conformance_test_cpu_version_t::v1, 0x9c, 0x00, 0x00, 0x00},
{bpf_conformance_test_cpu_version_t::v4, 0x9c, 0x00, 0x00, 0x01},
{bpf_conformance_test_cpu_version_t::v1, 0x9f, 0x00, 0x00, 0x00},
{bpf_conformance_test_cpu_version_t::v4, 0x9f, 0x00, 0x00, 0x01},
{bpf_conformance_test_cpu_version_t::v1, 0xa4},
{bpf_conformance_test_cpu_version_t::v2, 0xa5},
{bpf_conformance_test_cpu_version_t::v3, 0xa6},
Expand Down
8 changes: 8 additions & 0 deletions tests/sdiv32-by-zero-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, 1
sdiv32 %r0, 0
exit
-- result
0x0
8 changes: 8 additions & 0 deletions tests/sdiv64-by-zero-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, 1
sdiv %r0, 0
exit
-- result
0x0
8 changes: 8 additions & 0 deletions tests/smod32-neg-by-neg-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, -13
smod32 %r0, -3
exit
-- result
0xffffffff
9 changes: 9 additions & 0 deletions tests/smod32-neg-by-neg-reg.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, -13
mov32 %r1, -3
smod32 %r0, %r1
exit
-- result
0xffffffff
8 changes: 8 additions & 0 deletions tests/smod32-neg-by-pos-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, -13
smod32 %r0, 4
exit
-- result
0xffffffff
9 changes: 9 additions & 0 deletions tests/smod32-neg-by-pos-reg.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, -13
mov32 %r1, 4
smod32 %r0, %r1
exit
-- result
0xffffffff
8 changes: 8 additions & 0 deletions tests/smod32-neg-by-zero-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, -10
smod32 %r0, 0
exit
-- result
0xFFFFFFF6
9 changes: 9 additions & 0 deletions tests/smod32-neg-by-zero-reg.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, -10
mov32 %r1, 0
smod32 %r0, %r1
exit
-- result
0xFFFFFFF6
8 changes: 8 additions & 0 deletions tests/smod32-pos-by-neg-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, 13
smod32 %r0, -3
exit
-- result
0x1
9 changes: 9 additions & 0 deletions tests/smod32-pos-by-neg-reg.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov32 %r0, 13
mov32 %r1, -3
smod32 %r0, %r1
exit
-- result
0x1
8 changes: 8 additions & 0 deletions tests/smod64-neg-by-neg-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov %r0, -13
smod %r0, -3
exit
-- result
0xffffffffffffffff
9 changes: 9 additions & 0 deletions tests/smod64-neg-by-neg-reg.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov %r0, -13
mov %r1, -3
smod %r0, %r1
exit
-- result
0xffffffffffffffff
8 changes: 8 additions & 0 deletions tests/smod64-neg-by-pos-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov %r0, -13
smod %r0, 4
exit
-- result
0xffffffffffffffff
9 changes: 9 additions & 0 deletions tests/smod64-neg-by-pos-reg.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov %r0, -13
mov %r1, 4
smod %r0, %r1
exit
-- result
0xffffffffffffffff
8 changes: 8 additions & 0 deletions tests/smod64-neg-by-zero-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov %r0, -10
smod %r0, 0
exit
-- result
0xFFFFFFFFFFFFFFF6
9 changes: 9 additions & 0 deletions tests/smod64-neg-by-zero-reg.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov %r0, -10
mov %r1, 0
smod %r0, %r1
exit
-- result
0xFFFFFFFFFFFFFFF6
8 changes: 8 additions & 0 deletions tests/smod64-pos-by-neg-imm.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov %r0, 13
smod %r0, -3
exit
-- result
0x1
9 changes: 9 additions & 0 deletions tests/smod64-pos-by-neg-reg.data
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Copyright (c) Dave Thaler
# SPDX-License-Identifier: MIT
-- asm
mov %r0, 13
mov %r1, -3
smod %r0, %r1
exit
-- result
0x1

0 comments on commit 4946099

Please sign in to comment.