mirror of https://github.com/containers/podman.git
Merge pull request #16495 from dfr/freebsd-unit-test
Fix unit tests for FreeBSD
This commit is contained in:
commit
725f17bb6f
|
|
@ -1,3 +1,6 @@
|
||||||
|
//go:build linux
|
||||||
|
// +build linux
|
||||||
|
|
||||||
package libpod
|
package libpod
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,15 @@
|
||||||
//go:build linux && cgo
|
//go:build (linux || freebsd) && cgo
|
||||||
// +build linux,cgo
|
// +build linux freebsd
|
||||||
|
// +build cgo
|
||||||
|
|
||||||
package shm
|
package shm
|
||||||
|
|
||||||
// #cgo LDFLAGS: -lrt -lpthread
|
// #cgo LDFLAGS: -lrt -lpthread
|
||||||
// #cgo CFLAGS: -Wall -Werror
|
// #cgo CFLAGS: -Wall -Werror
|
||||||
// #include <stdlib.h>
|
// #include <stdlib.h>
|
||||||
|
// #include <sys/types.h>
|
||||||
|
// #include <sys/mman.h>
|
||||||
|
// #include <fcntl.h>
|
||||||
// #include "shm_lock.h"
|
// #include "shm_lock.h"
|
||||||
// const uint32_t bitmap_size_c = BITMAP_SIZE;
|
// const uint32_t bitmap_size_c = BITMAP_SIZE;
|
||||||
import "C"
|
import "C"
|
||||||
|
|
@ -261,3 +265,13 @@ func (locks *SHMLocks) UnlockSemaphore(sem uint32) error {
|
||||||
|
|
||||||
return nil
|
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
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,12 @@
|
||||||
//go:build linux
|
//go:build linux || freebsd
|
||||||
// +build linux
|
// +build linux freebsd
|
||||||
|
|
||||||
package shm
|
package shm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
"os"
|
"os"
|
||||||
"runtime"
|
"runtime"
|
||||||
"testing"
|
"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
|
// We need a test main to ensure that the SHM is created before the tests run
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
// Remove prior /dev/shm/libpod_test
|
// Remove prior /libpod_test
|
||||||
os.RemoveAll("/dev/shm" + lockPath)
|
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)
|
shmLock, err := CreateSHMLock(lockPath, numLocks)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Fprintf(os.Stderr, "Error creating SHM for tests: %v\n", err)
|
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
|
// Test that creating an SHM with a bad size rounds up to a good size
|
||||||
func TestCreateNewSHMBadSizeRoundsUp(t *testing.T) {
|
func TestCreateNewSHMBadSizeRoundsUp(t *testing.T) {
|
||||||
// Remove prior /dev/shm/test1
|
// Remove prior /test1
|
||||||
os.RemoveAll("/dev/shm/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
|
// Odd number, not a power of 2, should never be a word size on a system
|
||||||
lock, err := CreateSHMLock("/test1", 7)
|
lock, err := CreateSHMLock("/test1", 7)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,6 @@
|
||||||
|
//go:build linux
|
||||||
|
// +build linux
|
||||||
|
|
||||||
package kube
|
package kube
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
|
|
||||||
|
|
@ -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")
|
|
||||||
}
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
// +build linux darwin
|
// +build linux darwin freebsd
|
||||||
|
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//go:build linux || darwin
|
//go:build linux || darwin || freebsd
|
||||||
// +build linux darwin
|
// +build linux darwin freebsd
|
||||||
|
|
||||||
package utils
|
package utils
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue