Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/ut.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Kmesh Unit Test Workflow

on: pull_request

jobs:

build:
runs-on: ubuntu-22.04

env:
PKG_CONFIG_PATH: $GITHUB_WORKSPACE/mk

strategy:
matrix:
go-version: [ '1.21' ]

steps:
- uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v4.0.0
with:
go-version: ${{ matrix.go-version }}

- name: Set enviroments
run: |
find $GITHUB_WORKSPACE/mk -name "*.pc" | xargs sed -i "s#^prefix=.*#prefix=$GITHUB_WORKSPACE#g"
echo "PKG_CONFIG_PATH=$GITHUB_WORKSPACE/mk" >> $GITHUB_ENV

- name: Go Test
run: |
go test -v -vet=off ./...
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -166,3 +166,8 @@ clean:
$(QUIET) make clean -C bpf/deserialization_to_bpf_map
$(call printlog, CLEAN, "kernel")
$(QUIET) make clean -C kernel/ko_src

test-ut:
$(QUIET) find $(ROOT_DIR)/mk -name "*.pc" | xargs sed -i "s#^prefix=.*#prefix=${ROOT_DIR}#g"
$(QUIET) (export PKG_CONFIG_PATH=$(PKG_CONFIG_PATH):$(ROOT_DIR)mk; \
$(GO) test -v -vet=off -tags testut ./pkg/...)
2 changes: 1 addition & 1 deletion mk/api-v2-c.pc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prefix=
prefix=/home/vander0x00/workplace/kmesh/

Name: api-v2-c
Description: api-v2-c
Expand Down
2 changes: 1 addition & 1 deletion mk/bpf.pc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
prefix=
prefix=/home/vander0x00/workplace/kmesh/
Name: bpf
Description: bpf
Version:
Expand Down
3 changes: 3 additions & 0 deletions pkg/bpf/bpf.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !testut
// +build !testut

/*
* Copyright 2023 The Kmesh Authors.
*
Expand Down
11 changes: 6 additions & 5 deletions pkg/bpf/bpf_kmesh.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// +build enhanced
//go:build enhanced || ignore || !testut
// +build enhanced ignore !testut

/*
* Copyright 2023 The Kmesh Authors.
Expand Down Expand Up @@ -46,8 +47,8 @@ type BpfSockOps struct {

type BpfKmesh struct {
TracePoint BpfTracePoint
SockConn BpfSockConn
SockOps BpfSockOps
SockConn BpfSockConn
SockOps BpfSockOps
}

func (sc *BpfTracePoint) NewBpf(cfg *Config) {
Expand Down Expand Up @@ -93,7 +94,7 @@ func NewBpfKmesh(cfg *Config) (BpfKmesh, error) {

func (sc *BpfTracePoint) loadKmeshTracePointObjects() (*ebpf.CollectionSpec, error) {
var (
err error
err error
spec *ebpf.CollectionSpec
opts ebpf.CollectionOptions
)
Expand Down Expand Up @@ -314,7 +315,7 @@ func (sc *BpfKmesh) ApiEnvCfg() error {
}

func (sc *BpfTracePoint) Attach() error {
tpopt := link.RawTracepointOptions {
tpopt := link.RawTracepointOptions{
Name: "connect_ret",
Program: sc.KmeshTracePointObjects.ConnectRet,
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/bpf/bpf_kmesh_common.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !testut
// +build !testut

/*
* Copyright 2023 The Kmesh Authors.
*
Expand Down
4 changes: 2 additions & 2 deletions pkg/bpf/bpf_kmesh_l4.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//go:build !enhanced
// +build !enhanced
//go:build !enhanced && !testut
// +build !enhanced,!testut

/*
* Copyright 2023 The Kmesh Authors.
Expand Down
3 changes: 3 additions & 0 deletions pkg/bpf/bpf_kmesh_l4_workload.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !testut
// +build !testut

/*
* Copyright 2024 The Kmesh Authors.
*
Expand Down
3 changes: 3 additions & 0 deletions pkg/bpf/bpf_kmesh_workload.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !testut
// +build !testut

/*
* Copyright 2024 The Kmesh Authors.
*
Expand Down
83 changes: 83 additions & 0 deletions pkg/bpf/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
/*
* Copyright 2023 The Kmesh Authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.

* Author: Min Chen
* Create: 2024-01-23
*/

package bpf

import "testing"

func TestConfig_ParseConfig(t *testing.T) {
type fields struct {
BpfFsPath string
Cgroup2Path string
EnableKmesh bool
EnableMda bool
BpfVerifyLogSize int
}
tests := []struct {
name string
fields fields
wantErr bool
}{
// TODO: Add test cases.
{
name: "valid Mda config",
fields: fields{
EnableMda: true,
},
wantErr: false,
},
// {
// name: "valid Kmesh config",
// fields: fields{
// EnableKmesh: true,

// },
// },
{
name: "none of EnableKmesh or EnableMda",
fields: fields{
EnableKmesh: false,
EnableMda: false,
},
wantErr: true,
},
{
name: "both EnableKmesh and EnableMda",
fields: fields{
EnableKmesh: true,
EnableMda: true,
},
wantErr: true,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := &Config{
BpfFsPath: tt.fields.BpfFsPath,
Cgroup2Path: tt.fields.Cgroup2Path,
EnableKmesh: tt.fields.EnableKmesh,
EnableMda: tt.fields.EnableMda,
BpfVerifyLogSize: tt.fields.BpfVerifyLogSize,
}
if err := c.ParseConfig(); (err != nil) != tt.wantErr {
t.Errorf("ParseConfig() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}
3 changes: 3 additions & 0 deletions pkg/bpf/pin.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//go:build !testut
// +build !testut

/*
* Copyright 2023 The Kmesh Authors.
*
Expand Down