Skip to content

Commit

Permalink
test: add test cases for inspect --ps-tree-env
Browse files Browse the repository at this point in the history
Signed-off-by: Kouame Behouba Manasse <[email protected]>
  • Loading branch information
behouba committed Jul 24, 2023
1 parent 8281d4b commit 7ca1003
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
31 changes: 31 additions & 0 deletions test/checkpointctl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,37 @@ function teardown() {
[[ ${lines[0]} == *"failed to process command line arguments"* ]]
}
@test "Run checkpointctl inspect with tar file and --ps-tree-env" {
cp data/config.dump \
data/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
cp test-imgs/pstree.img \
test-imgs/core-*.img \
test-imgs/pagemap-*.img \
test-imgs/pages-*.img \
test-imgs/mm-*.img "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl inspect "$TEST_TMP_DIR2"/test.tar --ps-tree-env
[ "$status" -eq 0 ]
[[ ${lines[8]} == *"Process tree"* ]]
[[ ${lines[9]} == *"piggie"* ]]
[[ ${lines[10]} == *"="* ]]
}
@test "Run checkpointctl inspect with tar file and --ps-tree-env and missing pages-*.img {
cp data/config.dump \
data/spec.dump "$TEST_TMP_DIR1"
mkdir "$TEST_TMP_DIR1"/checkpoint
cp test-imgs/pstree.img \
test-imgs/core-*.img \
test-imgs/pagemap-*.img \
test-imgs/mm-*.img "$TEST_TMP_DIR1"/checkpoint
( cd "$TEST_TMP_DIR1" && tar cf "$TEST_TMP_DIR2"/test.tar . )
checkpointctl inspect "$TEST_TMP_DIR2"/test.tar --ps-tree-env
[ "$status" -eq 1 ]
[[ ${lines[0]} == *"no such file or directory"* ]]
}

@test "Run checkpointctl inspect with tar file and --files" {
cp data/config.dump \
data/spec.dump "$TEST_TMP_DIR1"
Expand Down
17 changes: 11 additions & 6 deletions tree.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,30 @@ func addPsTreeToTree(tree treeprint.Tree, psTree *crit.PsTree, checkpointOutputD
// processNodes is a recursive function to create
// a new branch for each process and add its child
// processes as child nodes of the branch.
var processNodes func(treeprint.Tree, *crit.PsTree)
processNodes = func(tree treeprint.Tree, root *crit.PsTree) {
var processNodes func(treeprint.Tree, *crit.PsTree) error
processNodes = func(tree treeprint.Tree, root *crit.PsTree) error {
node := tree.AddMetaBranch(root.PID, root.Comm)
// attach environment variables to process
if psTreeEnv {
envVars, _ := getPsEnvVars(checkpointOutputDir, root.PID)
envVars, err := getPsEnvVars(checkpointOutputDir, root.PID)
if err != nil {
return err
}

for _, env := range envVars {
node.AddBranch(env)
}
}
for _, child := range root.Children {
processNodes(node, child)
if err := processNodes(node, child); err != nil {
return err
}
}
return nil
}
psTreeNode := tree.AddBranch("Process tree")
processNodes(psTreeNode, psRoot)

return nil
return processNodes(psTreeNode, psRoot)
}

func addFdsToTree(tree treeprint.Tree, fds []*crit.Fd) {
Expand Down

0 comments on commit 7ca1003

Please sign in to comment.