Merge pull request #16495 from dfr/freebsd-unit-test

Fix unit tests for FreeBSD
This commit is contained in:
OpenShift Merge Robot 2022-11-14 21:23:21 +00:00 committed by GitHub
commit 725f17bb6f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 39 additions and 34 deletions

View File

@ -1,3 +1,6 @@
//go:build linux
// +build linux
package libpod
import (

View File

@ -1,11 +1,15 @@
//go:build linux && cgo
// +build linux,cgo
//go:build (linux || freebsd) && cgo
// +build linux freebsd
// +build cgo
package shm
// #cgo LDFLAGS: -lrt -lpthread
// #cgo CFLAGS: -Wall -Werror
// #include <stdlib.h>
// #include <sys/types.h>
// #include <sys/mman.h>
// #include <fcntl.h>
// #include "shm_lock.h"
// const uint32_t bitmap_size_c = BITMAP_SIZE;
import "C"
@ -261,3 +265,13 @@ func (locks *SHMLocks) UnlockSemaphore(sem uint32) error {
return nil
}
func unlinkSHMLock(path string) error {
cPath := C.CString(path)
defer C.free(unsafe.Pointer(cPath))
if _, err := C.shm_unlink(cPath); err != nil {
return fmt.Errorf("failed to unlink SHM locks: %w", err)
}
return nil
}

View File

@ -1,10 +1,12 @@
//go:build linux
// +build linux
//go:build linux || freebsd
// +build linux freebsd
package shm
import (
"errors"
"fmt"
"io/fs"
"os"
"runtime"
"testing"
@ -28,8 +30,11 @@ const lockPath = "/libpod_test"
// We need a test main to ensure that the SHM is created before the tests run
func TestMain(m *testing.M) {
// Remove prior /dev/shm/libpod_test
os.RemoveAll("/dev/shm" + lockPath)
// Remove prior /libpod_test
if err := unlinkSHMLock(lockPath); err != nil && !errors.Is(err, fs.ErrNotExist) {
fmt.Fprintf(os.Stderr, "Error cleaning SHM for tests: %v\n", err)
os.Exit(-1)
}
shmLock, err := CreateSHMLock(lockPath, numLocks)
if err != nil {
fmt.Fprintf(os.Stderr, "Error creating SHM for tests: %v\n", err)
@ -76,8 +81,10 @@ func runLockTest(t *testing.T, testFunc func(*testing.T, *SHMLocks)) {
// Test that creating an SHM with a bad size rounds up to a good size
func TestCreateNewSHMBadSizeRoundsUp(t *testing.T) {
// Remove prior /dev/shm/test1
os.RemoveAll("/dev/shm/test1")
// Remove prior /test1
if err := unlinkSHMLock("/test1"); err != nil && !errors.Is(err, fs.ErrNotExist) {
t.Fatalf("Error cleaning SHM for tests: %v\n", err)
}
// Odd number, not a power of 2, should never be a word size on a system
lock, err := CreateSHMLock("/test1", 7)
assert.NoError(t, err)

View File

@ -1,3 +1,6 @@
//go:build linux
// +build linux
package kube
import (

View File

@ -1,22 +0,0 @@
//go:build freebsd
// +build freebsd
package utils
import "errors"
func RunUnderSystemdScope(pid int, slice string, unitName string) error {
return errors.New("not implemented for freebsd")
}
func MoveUnderCgroupSubtree(subtree string) error {
return errors.New("not implemented for freebsd")
}
func GetOwnCgroup() (string, error) {
return "", errors.New("not implemented for freebsd")
}
func GetCgroupProcess(pid int) (string, error) {
return "", errors.New("not implemented for freebsd")
}

View File

@ -1,5 +1,5 @@
//go:build linux || darwin
// +build linux darwin
//go:build linux || darwin || freebsd
// +build linux darwin freebsd
package utils

View File

@ -1,5 +1,5 @@
//go:build linux || darwin
// +build linux darwin
//go:build linux || darwin || freebsd
// +build linux darwin freebsd
package utils