Skip to content

Commit

Permalink
tests: replace Test_parse_proc_pid_stat_Self with Test_parse_proc_pid…
Browse files Browse the repository at this point in the history
…_stat_1

Running the test against ourselves is unreliable due to golang thread
multiplexing.

Hopefully init (pid1) is almost always is state 'S' (sleeping).

=== RUN   Test_parse_proc_pid_stat_Self
    testsuite_unit_test.go:247:
        have=earlyoom_testsuite._Ctype_struct___2{state:83, ppid:237, num_threads:6}
        want=earlyoom_testsuite._Ctype_struct___2{state:82, ppid:237, num_threads:6}
--- FAIL: Test_parse_proc_pid_stat_Self (0.00s)
  • Loading branch information
rfjakob committed Mar 29, 2024
1 parent 9b9739e commit d49bc1e
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions testsuite_unit_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -225,24 +225,22 @@ func Test_parse_proc_pid_stat_buf(t *testing.T) {
}
}

func Test_parse_proc_pid_stat_Self(t *testing.T) {
pid := os.Getpid()
path := fmt.Sprintf("/proc/%d/stat", pid)
stat, err := linuxproc.ReadProcessStat(path)
func Test_parse_proc_pid_stat_1(t *testing.T) {
stat, err := linuxproc.ReadProcessStat("/proc/1/stat")
if err != nil {
t.Fatal(err)
}

_, want := parse_proc_pid_stat(1) // Stupid hack to get a C.pid_stat_t
want.state = _Ctype_char(stat.State[0])
want.ppid = _Ctype_int(stat.Ppid)
want.num_threads = _Ctype_long(stat.NumThreads)

res, have := parse_proc_pid_stat(pid)
res, have := parse_proc_pid_stat(1)
if !res {
t.Fatal(res)
}

want := have
want.state = _Ctype_char(stat.State[0])
want.ppid = _Ctype_int(stat.Ppid)
want.num_threads = _Ctype_long(stat.NumThreads)

if have != want {
t.Errorf("\nhave=%#v\nwant=%#v", have, want)
}
Expand Down

0 comments on commit d49bc1e

Please sign in to comment.