woj-server/internal/service/runner/nsjail_test.go

46 lines
902 B
Go
Raw Normal View History

package runner
import (
"testing"
)
func BenchmarkContainerRun(b *testing.B) {
srv := GetService(false).(*service)
args := &RunArgs{
2024-03-13 20:03:12 +08:00
Program: ProgramArgs{Args: []string{"/bin/sh", "-c", "echo hello world"}},
Runtime: RuntimeArgs{Rootfs: RootfsRunDir, Memory: 16 * 1024 * 1024},
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
2024-03-13 20:03:12 +08:00
_, err := srv.JailRun(args)
if err != nil {
b.Error(err)
}
}
}
func BenchmarkContainerRunPool(b *testing.B) {
srv := GetService(false).(*service)
args := &RunArgs{
2024-03-13 20:03:12 +08:00
Program: ProgramArgs{Args: []string{"/bin/sh", "-c", "echo hello world"}},
Runtime: RuntimeArgs{Rootfs: RootfsRunDir, Memory: 16 * 1024 * 1024},
}
b.ResetTimer()
var ids []uint64
for i := 0; i < b.N; i++ {
2024-03-13 20:03:12 +08:00
id := srv.JailRunPool(args)
ids = append(ids, id)
}
for _, id := range ids {
2024-03-13 20:03:12 +08:00
buf := srv.pool.WaitForTask(id)
if buf.Error != nil {
b.Error(buf.Error)
}
}
}