Open Okabe-Rintarou-0 opened 1 month ago
Good question. Currently, KMesh does not have a mature ebpf testing framework. Testing ebpf programs depends on functional black-box testing. In the roadmap for the second half of this year, we plan to develop an independent ebpf test framework for KMesh. The basic selection is based on the BPF_PROG_TEST_RUN command (this command was added to the kernel in kernel 4.12). Pay attention to the Kmesh community and participate in the regular community meeting to learn about the development progress.
For ebpf locally build, maybe u could firstly install Dependencies reference https://github.com/libbpf/libbpf-bootstrap?tab=readme-ov-file#install-dependencies Then, you can build and load ebpf prog to kernel using below code, which I used to verify whether ebpf prog could load into kernel correctly , which will print ebpf error msg when prog is not correct. Because I think Kmesh in printing BpfVerifyLog is very limited.
package bpf
import (
"fmt"
"os"
"testing"
"github.com/stretchr/testify/suite"
"kmesh.net/kmesh/daemon/options"
)
type BpfTestSuite struct{
suite.Suite
l *BpfLoader
config *options.BpfConfig
}
func TestBpfTestSuite(t *testing.T) {
suite.Run(t, new(BpfTestSuite))
}
func (suite *BpfTestSuite) SetupSuite () {
err := os.Setenv("PKG_CONFIG_PATH", "/root/tmp/kmesh/mk")
if err != nil {
panic(err)
}
config := &options.BpfConfig{
Mode: "ads",
BpfFsPath: "/sys/fs/bpf",
Cgroup2Path: "/mnt/kmesh_cgroup2",
EnableMda: false,
BpfVerifyLogSize: 100 * 1024 * 1024, // 1MB
}
suite.l = NewBpfLoader(config)
suite.config = config
}
func (suite *BpfTestSuite) TearDownSuite() {
fmt.Println(">>> From TearDownSuite")
}
func (suite *BpfTestSuite) TestStartAdsMode() {
if err := suite.l.Start(suite.config); err != nil {
fmt.Printf("bpf start err:%s", err)
}
defer suite.l.Stop()
}
Please provide an in-depth description of the question you have: How can we build and test kmesh ebpf code locally? I am working on a Ubuntu-20.04. What do you think about this question?:
Environment: