(t *testing.T)
| 293 | } |
| 294 | |
| 295 | func TestMoveTo(t *testing.T) { |
| 296 | checkCgroupMode(t) |
| 297 | |
| 298 | src, err := NewManager(defaultCgroup2Path, "/test-moveto-src", ToResources(&specs.LinuxResources{})) |
| 299 | require.NoError(t, err) |
| 300 | t.Cleanup(func() { |
| 301 | _ = src.Kill() |
| 302 | _ = src.Delete() |
| 303 | }) |
| 304 | |
| 305 | cmd := exec.Command("sleep", "infinity") |
| 306 | // Don't leak the process if we fail to join the cg, |
| 307 | // send sigkill after tests over. |
| 308 | cmd.SysProcAttr = &syscall.SysProcAttr{ |
| 309 | Pdeathsig: syscall.SIGKILL, |
| 310 | } |
| 311 | err = cmd.Start() |
| 312 | require.NoError(t, err) |
| 313 | |
| 314 | proc := cmd.Process.Pid |
| 315 | err = src.AddProc(uint64(proc)) |
| 316 | require.NoError(t, err) |
| 317 | |
| 318 | destination, err := NewManager(defaultCgroup2Path, "/test-moveto-dest", ToResources(&specs.LinuxResources{})) |
| 319 | require.NoError(t, err) |
| 320 | t.Cleanup(func() { |
| 321 | _ = destination.Kill() |
| 322 | _ = destination.Delete() |
| 323 | }) |
| 324 | |
| 325 | err = src.MoveTo(destination) |
| 326 | require.NoError(t, err) |
| 327 | |
| 328 | desProcs, err := destination.Procs(true) |
| 329 | require.NoError(t, err) |
| 330 | |
| 331 | desMap := make(map[int]bool) |
| 332 | for _, p := range desProcs { |
| 333 | desMap[int(p)] = true |
| 334 | } |
| 335 | if !desMap[proc] { |
| 336 | t.Fatalf("process %v not in destination cgroup", proc) |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | func TestCgroupType(t *testing.T) { |
| 341 | checkCgroupMode(t) |
nothing calls this directly
no test coverage detected
searching dependent graphs…