1 2if (!ps_os_type()[["POSIX"]]) return() 3 4context("posix-zombie") 5 6test_that("zombie api", { 7 zpid <- zombie() 8 on.exit(waitpid(zpid), add = TRUE) 9 p <- ps_handle(zpid) 10 me <- ps_handle() 11 12 expect_match(format(p), format_regexp()) 13 expect_output(print(p), format_regexp()) 14 15 expect_equal(ps_pid(p), zpid) 16 expect_true(ps_create_time(p) > ps_create_time(me)) 17 expect_true(ps_is_running(p)) 18 expect_equal(ps_status(p), "zombie") 19 expect_equal(ps_ppid(p), Sys.getpid()) 20 expect_equal(ps_pid(ps_parent(p)), Sys.getpid()) 21 expect_equal(ps_name(p), ps_name(me)) 22 expect_identical(ps_uids(p), ps_uids(me)) 23 expect_identical(ps_username(p), ps_username(me)) 24 expect_identical(ps_gids(p), ps_gids(me)) 25 expect_identical(ps_terminal(p), ps_terminal(me)) 26 expect_silent(ps_children(p)) 27 28 ## You can still send signals if you like 29 expect_silent(ps_send_signal(p, signals()$SIGINT)) 30 expect_equal(ps_status(p), "zombie") 31 expect_silent(ps_suspend(p)) 32 expect_equal(ps_status(p), "zombie") 33 expect_silent(ps_resume(p)) 34 expect_equal(ps_status(p), "zombie") 35 expect_silent(ps_terminate(p)) 36 expect_equal(ps_status(p), "zombie") 37 expect_silent(ps_kill(p)) 38 expect_equal(ps_status(p), "zombie") 39 40 chk <- function(expr) { 41 err <- tryCatch(expr, error = function(e) e) 42 expect_s3_class(err, "zombie_process") 43 expect_s3_class(err, "ps_error") 44 expect_equal(err$pid, zpid) 45 } 46 47 ## These raise zombie_process errors 48 chk(ps_exe(p)) 49 chk(ps_cmdline(p)) 50 chk(ps_environ(p)) 51 chk(ps_cwd(p)) 52 chk(ps_memory_info(p)) 53 chk(ps_cpu_times(p)) 54 chk(ps_num_threads(p)) 55 chk(ps_num_fds(p)) 56 chk(ps_open_files(p)) 57 chk(ps_connections(p)) 58 chk(ps_get_nice(p)) 59 chk(ps_set_nice(p, 20L)) 60}) 61