mirror of
https://github.com/ceph/go-ceph
synced 2025-02-16 10:37:19 +00:00
tests: add benchmarks for PtrGuard related types
Signed-off-by: Sven Anderson <sven@redhat.com>
This commit is contained in:
parent
6be8d370cb
commit
1c719b199e
@ -30,7 +30,7 @@ func TestCreateMount(t *testing.T) {
|
||||
assert.NoError(t, mount.Release())
|
||||
}
|
||||
|
||||
func fsConnect(t *testing.T) *MountInfo {
|
||||
func fsConnect(t require.TestingT) *MountInfo {
|
||||
mount, err := CreateMount()
|
||||
require.NoError(t, err)
|
||||
require.NotNil(t, mount)
|
||||
@ -52,7 +52,7 @@ func fsConnect(t *testing.T) *MountInfo {
|
||||
return mount
|
||||
}
|
||||
|
||||
func fsDisconnect(t *testing.T, mount *MountInfo) {
|
||||
func fsDisconnect(t assert.TestingT, mount *MountInfo) {
|
||||
assert.NoError(t, mount.Unmount())
|
||||
assert.NoError(t, mount.Release())
|
||||
}
|
||||
|
@ -959,3 +959,35 @@ func TestFileTruncate(t *testing.T) {
|
||||
assert.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func BenchmarkFile(b *testing.B) {
|
||||
const bufNum = 64
|
||||
const bufSize = 1024 * 64
|
||||
mount := fsConnect(b)
|
||||
defer fsDisconnect(b, mount)
|
||||
|
||||
fname := "TestFilePreadvPwritev.txt"
|
||||
defer mount.Unlink(fname)
|
||||
|
||||
ivec := make([][]byte, bufNum)
|
||||
for i := range ivec {
|
||||
ivec[i] = make([]byte, bufSize)
|
||||
}
|
||||
|
||||
ovec := make([][]byte, bufNum/4)
|
||||
for i := range ovec {
|
||||
ovec[i] = make([]byte, bufSize*4)
|
||||
}
|
||||
|
||||
f, _ := mount.Open(fname, os.O_RDWR|os.O_CREATE, 0644)
|
||||
defer f.Close()
|
||||
|
||||
for i := 0; i < b.N; i++ {
|
||||
n, err := f.Pwritev(ivec, 0)
|
||||
assert.NoError(b, err)
|
||||
assert.NotZero(b, n)
|
||||
m, err := f.Preadv(ovec, 0)
|
||||
assert.NoError(b, err)
|
||||
assert.Equal(b, n, m)
|
||||
}
|
||||
}
|
||||
|
@ -17,7 +17,7 @@ CEPH_CONF=/tmp/ceph/ceph.conf
|
||||
# but can be used to change the test behavior:
|
||||
# GO_CEPH_TEST_MDS_NAME
|
||||
|
||||
CLI="$(getopt -o h --long test-run:,test-pkg:,pause,cpuprofile,memprofile,no-cover,micro-osd:,wait-for:,results:,ceph-conf:,mirror:,help -n "${0}" -- "$@")"
|
||||
CLI="$(getopt -o h --long test-run:,test-bench:,test-pkg:,pause,cpuprofile,memprofile,no-cover,micro-osd:,wait-for:,results:,ceph-conf:,mirror:,help -n "${0}" -- "$@")"
|
||||
eval set -- "${CLI}"
|
||||
while true ; do
|
||||
case "${1}" in
|
||||
@ -31,6 +31,11 @@ while true ; do
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
--test-bench)
|
||||
TEST_BENCH="${2}"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
--pause)
|
||||
PAUSE=yes
|
||||
shift
|
||||
@ -76,6 +81,7 @@ while true ; do
|
||||
echo "Options:"
|
||||
echo " --test-run=VALUE Run selected test or ALL, NONE"
|
||||
echo " ALL is the default"
|
||||
echo " --test-bench=VALUE Run selected benchmarks"
|
||||
echo " --test-pkg=PKG Run only tests from PKG"
|
||||
echo " --pause Sleep forever after tests execute"
|
||||
echo " --micro-osd Specify path to micro-osd script"
|
||||
@ -184,6 +190,9 @@ test_pkg() {
|
||||
if [[ ${TEST_RUN} != ALL ]]; then
|
||||
testargs+=("-run" "${TEST_RUN}")
|
||||
fi
|
||||
if [[ -n ${TEST_BENCH} ]]; then
|
||||
testargs+=("-bench" "${TEST_BENCH}")
|
||||
fi
|
||||
if [[ ${COVERAGE} = yes ]]; then
|
||||
testargs+=(\
|
||||
"-covermode=count" \
|
||||
|
@ -56,3 +56,15 @@ func TestIovec(t *testing.T) {
|
||||
iovec.Sync()
|
||||
iovec.Free()
|
||||
}
|
||||
|
||||
func BenchmarkIovec(b *testing.B) {
|
||||
data := make([][]byte, 64)
|
||||
for i := range data {
|
||||
data[i] = make([]byte, 1024*64)
|
||||
}
|
||||
for i := 0; i < b.N; i++ {
|
||||
iovec := ByteSlicesToIovec(data)
|
||||
iovec.Sync()
|
||||
iovec.Free()
|
||||
}
|
||||
}
|
||||
|
14
internal/cutil/sync_buffer_test.go
Normal file
14
internal/cutil/sync_buffer_test.go
Normal file
@ -0,0 +1,14 @@
|
||||
package cutil
|
||||
|
||||
import "testing"
|
||||
|
||||
func BenchmarkSyncBuffer(b *testing.B) {
|
||||
data := make([]byte, 1024*64)
|
||||
var p = Malloc(PtrSize)
|
||||
defer Free(p)
|
||||
for i := 0; i < b.N; i++ {
|
||||
sb := NewSyncBuffer(p, data)
|
||||
sb.Sync()
|
||||
sb.Release()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user