Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can we build and test kmesh ebpf code locally. #401

Open
Okabe-Rintarou-0 opened this issue May 30, 2024 · 2 comments
Open

How can we build and test kmesh ebpf code locally. #401

Okabe-Rintarou-0 opened this issue May 30, 2024 · 2 comments
Labels
question Further information is requested

Comments

@Okabe-Rintarou-0
Copy link
Member

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:

  • Kmesh version:
  • Others:
@Okabe-Rintarou-0 Okabe-Rintarou-0 added the question Further information is requested label May 30, 2024
@bitcoffeeiux
Copy link
Contributor

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.

@bfforever
Copy link
Member

bfforever commented May 31, 2024

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()
	
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants