From d49bc1ecd17135614369ef66623116271eef1b9c Mon Sep 17 00:00:00 2001 From: Jakob Unterwurzacher Date: Fri, 29 Mar 2024 21:09:08 +0100 Subject: [PATCH] tests: replace Test_parse_proc_pid_stat_Self with Test_parse_proc_pid_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) --- testsuite_unit_test.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/testsuite_unit_test.go b/testsuite_unit_test.go index fb5bd34..68cebb2 100644 --- a/testsuite_unit_test.go +++ b/testsuite_unit_test.go @@ -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) }