1
2if (!ps_os_type()[["LINUX"]]) return()
3
4context("linux")
5
6test_that("status", {
7  ## Argument check
8  expect_error(ps_status(123), class = "invalid_argument")
9
10  p1 <- processx::process$new("sleep", "10")
11  on.exit(p1$kill(), add = TRUE)
12  ps <- ps_handle(p1$get_pid())
13  expect_true(ps_is_running(ps))
14
15  wait_for_status(ps, "sleeping")
16  expect_equal(ps_status(ps), "sleeping")
17  ps_suspend(ps)
18  wait_for_status(ps, "stopped")
19  expect_equal(ps_status(ps), "stopped")
20  ps_resume(ps)
21  wait_for_status(ps, "sleeping")
22  expect_equal(ps_status(ps), "sleeping")
23  ## TODO: rest?
24})
25
26## TODO: cpu_times ??? We apparently cannot get them from ps
27
28test_that("memory_info", {
29  ## Argument check
30  expect_error(ps_memory_info(123), class = "invalid_argument")
31
32  skip_on_cran()
33
34  p1 <- processx::process$new("ls", c("-lR", "/"))
35  on.exit(p1$kill(), add = TRUE)
36  ps <- ps_handle(p1$get_pid())
37
38  Sys.sleep(0.2)
39  ps_suspend(ps)
40  mem <- ps_memory_info(ps)
41  mem2 <- scan(sprintf("/proc/%d/statm", ps_pid(ps)), what = integer(),
42               quiet = TRUE)
43
44  expect_equal(mem[["rss"]], mem2[[1]])
45  expect_equal(mem[["vms"]], mem2[[2]])
46})
47