-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_linux_test.go
85 lines (81 loc) · 1.8 KB
/
command_linux_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
package utils
import (
"fmt"
"log"
"os"
"strconv"
"testing"
)
func TestCmd(t *testing.T) {
cmd := NewCmd()
// user, err := user.Current()
// if err != nil {
// log.Println(err)
// return
// }
// cmd.SetUser(user)
defer cmd.Close()
// path, err := os.Getwd()
// if err != nil {
// log.Println(err)
// return
// }
// cmd.SetTimeout(1 * time.Second)
args := []string{"--cpu", "1", "--vm", "1", "--vm-bytes", "220M", "--timeout", "10s", "--vm-keep"}
pid, err := cmd.Command("stress", args...)
if err != nil {
log.Println(err)
return
}
// cmd.NeedInput("hello:")
pid1 := cmd.GetPid()
log.Printf("pid is: %d, %d", pid, pid1)
out, err := cmd.Run()
if err != nil {
log.Println(err.Error())
return
}
log.Printf("%s", out)
}
func TestCmd2(t *testing.T) {
cmd := NewCmd().SetDebug(true)
// user, err := user.Current()
// if err != nil {
// log.Println(err)
// return
// }
// cmd.SetUser(user)
defer cmd.Close()
// path, err := os.Getwd()
// if err != nil {
// log.Println(err)
// return
// }
// cmd.SetTimeout(1 * time.Second)
args := []string{"/home/realjf/Downloads/e780530a-5eac-4118-9aa0-cb2d2f3e7db8.epub", "/home/realjf/Downloads/e780530a-5eac-4118-9aa0-cb2d2f3e7db8.pdf"}
pid, err := cmd.Command("ebook-convert", args...)
if err != nil {
log.Println(err)
return
}
// cmd.NeedInput("hello:")
pid1 := cmd.GetPid()
log.Printf("pid is: %d, %d", pid, pid1)
out, err := cmd.Run()
if err != nil {
log.Println(err.Error())
return
}
log.Printf("%s", out)
}
func TestV2(t *testing.T) {
cmd := NewCmd().SetDebug(true)
defer cmd.Close()
args := []string{"-c", "$(echo -1000 > /proc/" + strconv.Itoa(os.Getpid()) + "/oom_score_adj)"}
_, err := cmd.RunCommand("/bin/bash", args...)
if err != nil {
fmt.Printf("%s\n", err.Error())
} else {
fmt.Println("done")
}
}