diff --git a/cephfs/cephfs_test.go b/cephfs/cephfs_test.go index f7cf42a..f380c99 100644 --- a/cephfs/cephfs_test.go +++ b/cephfs/cephfs_test.go @@ -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()) } diff --git a/cephfs/file_test.go b/cephfs/file_test.go index d028ce7..3720bfc 100644 --- a/cephfs/file_test.go +++ b/cephfs/file_test.go @@ -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) + } +} diff --git a/entrypoint.sh b/entrypoint.sh index d9c33a4..0ce71f5 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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" \ diff --git a/internal/cutil/iovec_test.go b/internal/cutil/iovec_test.go index 0534131..292137d 100644 --- a/internal/cutil/iovec_test.go +++ b/internal/cutil/iovec_test.go @@ -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() + } +} diff --git a/internal/cutil/sync_buffer_test.go b/internal/cutil/sync_buffer_test.go new file mode 100644 index 0000000..ace8970 --- /dev/null +++ b/internal/cutil/sync_buffer_test.go @@ -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() + } +}