mirror of
https://github.com/evilsocket/opensnitch.git
synced 2025-03-04 00:24:40 +01:00
updated TestProcIOStats test
On this test we assumed that there would always be reading stats for our own process /proc/self, but on restricted environments that might not alwys be the case. Anyway, a value of 0 is not an error in itself. Closes #1075
This commit is contained in:
parent
1518cb39de
commit
b2bd56d7e2
2 changed files with 13 additions and 26 deletions
|
@ -304,10 +304,10 @@ func (p *Process) readDescriptors() {
|
|||
}
|
||||
}
|
||||
|
||||
func (p *Process) readIOStats() {
|
||||
func (p *Process) readIOStats() (err error) {
|
||||
f, err := os.Open(p.pathIO)
|
||||
if err != nil {
|
||||
return
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
|
@ -318,19 +318,21 @@ func (p *Process) readIOStats() {
|
|||
s := strings.Split(scanner.Text(), " ")
|
||||
switch s[0] {
|
||||
case "rchar:":
|
||||
p.IOStats.RChar, _ = strconv.ParseInt(s[1], 10, 64)
|
||||
p.IOStats.RChar, err = strconv.ParseInt(s[1], 10, 64)
|
||||
case "wchar:":
|
||||
p.IOStats.WChar, _ = strconv.ParseInt(s[1], 10, 64)
|
||||
p.IOStats.WChar, err = strconv.ParseInt(s[1], 10, 64)
|
||||
case "syscr:":
|
||||
p.IOStats.SyscallRead, _ = strconv.ParseInt(s[1], 10, 64)
|
||||
p.IOStats.SyscallRead, err = strconv.ParseInt(s[1], 10, 64)
|
||||
case "syscw:":
|
||||
p.IOStats.SyscallWrite, _ = strconv.ParseInt(s[1], 10, 64)
|
||||
p.IOStats.SyscallWrite, err = strconv.ParseInt(s[1], 10, 64)
|
||||
case "read_bytes:":
|
||||
p.IOStats.ReadBytes, _ = strconv.ParseInt(s[1], 10, 64)
|
||||
p.IOStats.ReadBytes, err = strconv.ParseInt(s[1], 10, 64)
|
||||
case "write_bytes:":
|
||||
p.IOStats.WriteBytes, _ = strconv.ParseInt(s[1], 10, 64)
|
||||
p.IOStats.WriteBytes, err = strconv.ParseInt(s[1], 10, 64)
|
||||
}
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func (p *Process) readStatus() {
|
||||
|
|
|
@ -61,26 +61,11 @@ func TestProcEnv(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestProcIOStats(t *testing.T) {
|
||||
proc.readIOStats()
|
||||
err := proc.readIOStats()
|
||||
|
||||
if proc.IOStats.RChar == 0 {
|
||||
t.Error("Proc.IOStats.RChar should not be 0:", proc.IOStats)
|
||||
if err != nil {
|
||||
t.Error("error reading proc IOStats:", err)
|
||||
}
|
||||
if proc.IOStats.WChar == 0 {
|
||||
t.Error("Proc.IOStats.WChar should not be 0:", proc.IOStats)
|
||||
}
|
||||
if proc.IOStats.SyscallRead == 0 {
|
||||
t.Error("Proc.IOStats.SyscallRead should not be 0:", proc.IOStats)
|
||||
}
|
||||
if proc.IOStats.SyscallWrite == 0 {
|
||||
t.Error("Proc.IOStats.SyscallWrite should not be 0:", proc.IOStats)
|
||||
}
|
||||
/*if proc.IOStats.ReadBytes == 0 {
|
||||
t.Error("Proc.IOStats.ReadBytes should not be 0:", proc.IOStats)
|
||||
}
|
||||
if proc.IOStats.WriteBytes == 0 {
|
||||
t.Error("Proc.IOStats.WriteBytes should not be 0:", proc.IOStats)
|
||||
}*/
|
||||
}
|
||||
|
||||
func TestProcStatus(t *testing.T) {
|
||||
|
|
Loading…
Add table
Reference in a new issue