github.phpd.cn/cilium/cilium@v1.6.12/test/runtime/verifier.go (about)

     1  // Copyright 2018-2019 Authors of Cilium
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package RuntimeTest
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/cilium/cilium/test/config"
    21  	. "github.com/cilium/cilium/test/ginkgo-ext"
    22  	"github.com/cilium/cilium/test/helpers"
    23  
    24  	. "github.com/onsi/gomega"
    25  )
    26  
    27  const (
    28  	script = "bpf/verifier-test.sh"
    29  )
    30  
    31  var _ = Describe("RuntimeVerifier", func() {
    32  	var vm *helpers.SSHMeta
    33  
    34  	BeforeAll(func() {
    35  		vm = helpers.InitRuntimeHelper(helpers.Runtime, logger)
    36  		ExpectCiliumReady(vm)
    37  
    38  		By("Stopping Cilium")
    39  		res := vm.ExecWithSudo("systemctl stop cilium")
    40  		res.ExpectSuccess()
    41  		ExpectCiliumNotRunning(vm)
    42  		res = vm.ExecWithSudo("rm -f /sys/fs/bpf/tc/globals/cilium*")
    43  		res.ExpectSuccess()
    44  		cmd := fmt.Sprintf("make -C %s/../bpf clean V=0", helpers.BasePath)
    45  		res = vm.Exec(cmd)
    46  		res.ExpectSuccess("Expected cleaning the bpf/ tree to succeed")
    47  	})
    48  
    49  	AfterFailed(func() {
    50  		if config.CiliumTestConfig.HoldEnvironment {
    51  			GinkgoPrint("Skipped gathering logs (-cilium.holdEnvironment=true)\n")
    52  			return
    53  		}
    54  
    55  		GinkgoPrint("===================== TEST FAILED =====================")
    56  		commands := []string{"clang --version", "uname -a"}
    57  		for _, cmd := range commands {
    58  			res := vm.ExecWithSudo(fmt.Sprintf("%s", cmd))
    59  			GinkgoPrint(res.GetDebugMessage())
    60  		}
    61  		GinkgoPrint("===================== EXITING REPORT GENERATION =====================\n")
    62  	})
    63  
    64  	AfterAll(func() {
    65  		err := vm.RestartCilium()
    66  		Expect(err).Should(BeNil(), "restarting Cilium failed")
    67  		vm.CloseSSHClient()
    68  	})
    69  
    70  	It("runs the kernel verifier against the tree copy of the BPF datapath", func() {
    71  		By("Building BPF objects from the tree")
    72  		cmd := fmt.Sprintf("make -C %s/../bpf V=0", helpers.BasePath)
    73  		res := vm.Exec(cmd)
    74  		res.ExpectSuccess("Expected compilation of the BPF objects to succeed")
    75  
    76  		By("Running the verifier test script")
    77  		cmd = fmt.Sprintf("%s/%s", helpers.BasePath, script)
    78  		res = vm.ExecWithSudo(cmd)
    79  		res.ExpectSuccess("Expected the kernel verifier to pass for BPF programs")
    80  	})
    81  })