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

Create pfcpiface unit tests' scaffolding #431

Merged
merged 33 commits into from
Feb 1, 2022
Merged
Show file tree
Hide file tree
Changes from 31 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
4969aa8
Make draft for testing
Jan 27, 2022
69255cc
Create test scaffolding
Jan 27, 2022
f78b438
Add unit test coverage
Jan 27, 2022
2600f57
Fix indentation
Jan 27, 2022
6954a83
Fix indentation
Jan 27, 2022
6ad6e1d
Merge branch 'master' of github.com:omec-project/upf-epc into improve…
Jan 27, 2022
c90d35e
Fix copyright header
Jan 27, 2022
a0a6564
Add simple FAR parsing test
Jan 27, 2022
e9a99e8
Fix linter
Jan 27, 2022
790086d
Refactor test to use table driven approach
Jan 28, 2022
e501c29
Add parallel statement to test
Jan 28, 2022
8be9bf0
Refactor. extracted common testCase struct
Jan 28, 2022
5141c3c
Refactor leftover from makefile
Jan 28, 2022
6a2b4df
Merge branch 'master' of github.com:omec-project/upf-epc into improve…
Jan 28, 2022
a56b786
Merge branch 'master' of github.com:omec-project/upf-epc into improve…
Jan 28, 2022
4169c54
Address review comments
Jan 31, 2022
39afd2f
Add expected field in test scaffolding
Jan 31, 2022
a3562bc
Fix golint
Jan 31, 2022
df027ad
Add GH action job to run unit tests
Jan 31, 2022
e3d7baa
Try fix for CI not being able to build before running tests
Jan 31, 2022
3ff4ca4
Try fix for CI not being able to build before running tests
Jan 31, 2022
ff87c13
Try fix for CI not being able to build before running tests
Jan 31, 2022
b8a56bf
Remove CI not being able to run test
Jan 31, 2022
b299a63
Try fix for CI. Download packages before executing tests
Jan 31, 2022
7f6072a
Remove CI workflow
Jan 31, 2022
5420c04
Merge branch 'master' into improve-testing
Jan 31, 2022
adf28ba
Run unit tests in Docker
pudelkoM Jan 31, 2022
7af5734
Readd tests to CI
pudelkoM Jan 31, 2022
05031e9
Add new workflow file for unit test
Jan 31, 2022
5539f70
Remove go version from workflow
Jan 31, 2022
d086b68
Clean pull_request.yml
Jan 31, 2022
44f88fe
Merge branch 'master' into improve-testing
pudelkoM Feb 1, 2022
1b2f002
Merge branch 'master' into improve-testing
pudelkoM Feb 1, 2022
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
20 changes: 20 additions & 0 deletions .github/workflows/run-pfcp-agent-unit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2022-present Open Networking Foundation
name: Unit tests

on:
push:
branches:
- master
pull_request:

jobs:
unit-test-pfcpiface:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2.4.0
- uses: actions/setup-go@v2

- name: Run unit tests for PFCP Agent
run: |
make test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2019 Intel Corporation
.coverage/
*.pyc
*.swp
output
15 changes: 14 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ py-pb:
.;
cp -a output/bess_pb/. ${PTF_PB_DIR}

.coverage:
rm -rf $(CURDIR)/.coverage
mkdir -p $(CURDIR)/.coverage

test: .coverage
docker run --rm -v $(CURDIR):/upf-epc -w /upf-epc golang:latest \
go test \
-race \
-coverprofile=.coverage/coverage-unit.txt \
-covermode=atomic \
-v \
./pfcpiface

fmt:
@go fmt ./...

Expand All @@ -93,4 +106,4 @@ golint:
check-reuse:
@docker run --rm -v $(CURDIR):/upf-epc -w /upf-epc omecproject/reuse-verify:latest reuse lint

.PHONY: docker-build docker-push output pb fmt golint check-reuse test-up4-integration
.PHONY: docker-build docker-push output pb fmt golint check-reuse test-up4-integration .coverage test
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,6 @@ require (
google.golang.org/genproto v0.0.0-20201110150050-8816d57aaa9a
google.golang.org/grpc v1.43.0
google.golang.org/protobuf v1.27.1
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
gotest.tools/v3 v3.1.0 // indirect
)
3 changes: 2 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -975,8 +975,9 @@ gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
Expand Down
157 changes: 157 additions & 0 deletions pfcpiface/parse-far_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
// SPDX-License-Identifier: Apache-2.0
// Copyright 2022-present Open Networking Foundation

package main

import (
"net"
"testing"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/wmnsk/go-pfcp/ie"
)

type testCase struct {
input *ie.IE
EmanueleGallone marked this conversation as resolved.
Show resolved Hide resolved
op operation
expected *far
description string
}

const (
defaultGTPProtocolPort = 2152
)

// TODO use pfcpsim library to create FARs

func TestParseFAR(t *testing.T) {
createOp, updateOp := create, update

var FSEID uint64 = 100

coreIP := net.ParseIP("10.0.10.1")
UEAddressForDownlink := net.ParseIP("10.0.1.1")

for _, scenario := range []testCase{
{
op: createOp,
input: ie.NewCreateFAR(
ie.NewFARID(999),
ie.NewApplyAction(ActionDrop),
ie.NewForwardingParameters(
ie.NewDestinationInterface(core),
),
),
expected: &far{
farID: 999,
applyAction: ActionDrop,
fseID: FSEID,
},
description: "Valid Uplink FAR input with create operation",
},
{
op: updateOp,
input: ie.NewUpdateFAR(
ie.NewFARID(1),
ie.NewApplyAction(ActionForward),
ie.NewUpdateForwardingParameters(
ie.NewDestinationInterface(access),
ie.NewOuterHeaderCreation(0x100, 100, UEAddressForDownlink.String(), "", 0, 0, 0),
),
),
expected: &far{
farID: 1,
fseID: FSEID,
applyAction: ActionForward,
dstIntf: access,
tunnelTEID: 100,
tunnelType: access,
tunnelIP4Src: ip2int(coreIP),
tunnelIP4Dst: ip2int(UEAddressForDownlink),
tunnelPort: uint16(defaultGTPProtocolPort),
},
description: "Valid Downlink FAR input with update operation",
},
} {
t.Run(scenario.description, func(t *testing.T) {
mockFar := &far{}
mockUpf := &upf{
accessIP: net.ParseIP("192.168.0.1"),
coreIP: coreIP,
}

err := mockFar.parseFAR(scenario.input, FSEID, mockUpf, scenario.op)
require.NoError(t, err)

assert.Equal(t, mockFar, scenario.expected)
})
}
}

func TestParseFARShouldError(t *testing.T) {
createOp, updateOp := create, update

var FSEID uint64 = 101

for _, scenario := range []testCase{
{
op: createOp,
input: ie.NewCreateFAR(
ie.NewFARID(1),
ie.NewApplyAction(0),
ie.NewForwardingParameters(
ie.NewDestinationInterface(ie.DstInterfaceCore),
),
),
expected: &far{
EmanueleGallone marked this conversation as resolved.
Show resolved Hide resolved
farID: 1,
fseID: FSEID,
},
description: "Uplink FAR with invalid action",
},
{
op: updateOp,
input: ie.NewUpdateFAR(
ie.NewFARID(1),
ie.NewApplyAction(0),
ie.NewUpdateForwardingParameters(
ie.NewDestinationInterface(ie.DstInterfaceAccess),
ie.NewOuterHeaderCreation(0x100, 100, "10.0.0.1", "", 0, 0, 0),
),
),
expected: &far{
farID: 1,
fseID: FSEID,
},
description: "Downlink FAR with invalid action",
},
{
op: createOp,
input: ie.NewCreateFAR(
ie.NewApplyAction(ActionDrop),
ie.NewUpdateForwardingParameters(
ie.NewDestinationInterface(ie.DstInterfaceAccess),
ie.NewOuterHeaderCreation(0x100, 100, "10.0.0.1", "", 0, 0, 0),
),
),
expected: &far{
fseID: FSEID,
},
description: "Malformed Downlink FAR with missing FARID",
},
} {
t.Run(scenario.description, func(t *testing.T) {
mockFar := &far{}
mockUpf := &upf{
accessIP: net.ParseIP("192.168.0.1"),
coreIP: net.ParseIP("10.0.0.1"),
}

err := mockFar.parseFAR(scenario.input, 101, mockUpf, scenario.op)
require.Error(t, err)

assert.Equal(t, scenario.expected, mockFar)
})
}
}