From 716cf26984a4d22de917733bcb365ffc6142d327 Mon Sep 17 00:00:00 2001 From: Sergey Kacheev Date: Mon, 3 May 2021 00:00:44 +0700 Subject: [PATCH] add parsing of real data from testdata with the splitProcStat function --- v3/process/process_linux_test.go | 20 ++++++++++++++++++++ v3/process/testdata/linux/proc/68927/stat | 1 + 2 files changed, 21 insertions(+) create mode 100644 v3/process/testdata/linux/proc/68927/stat diff --git a/v3/process/process_linux_test.go b/v3/process/process_linux_test.go index 2e1350c..8c7ef89 100644 --- a/v3/process/process_linux_test.go +++ b/v3/process/process_linux_test.go @@ -4,6 +4,7 @@ package process import ( "fmt" + "io/ioutil" "strconv" "strings" "testing" @@ -52,3 +53,22 @@ func Test_Process_splitProcStat(t *testing.T) { }) } } + +func Test_Process_splitProcStat_fromFile(t *testing.T) { + pid := "68927" + ppid := "68044" + statFile := "testdata/linux/proc/" + pid + "/stat" + contents, err := ioutil.ReadFile(statFile) + assert.NoError(t, err) + fields := splitProcStat(contents) + assert.Equal(t, fields[1], pid) + assert.Equal(t, fields[2], "test(cmd).sh") + assert.Equal(t, fields[3], "S") + assert.Equal(t, fields[4], ppid) + assert.Equal(t, fields[5], pid) // pgrp + assert.Equal(t, fields[6], ppid) // session + assert.Equal(t, fields[8], pid) // tpgrp + assert.Equal(t, fields[18], "20") // priority + assert.Equal(t, fields[20], "1") // num threads + assert.Equal(t, fields[52], "0") // exit code +} diff --git a/v3/process/testdata/linux/proc/68927/stat b/v3/process/testdata/linux/proc/68927/stat new file mode 100644 index 0000000..6f3a7d0 --- /dev/null +++ b/v3/process/testdata/linux/proc/68927/stat @@ -0,0 +1 @@ +68927 (test(cmd).sh) S 68044 68927 68044 34818 68927 4194304 165 0 0 0 0 0 0 0 20 0 1 0 114413973 9961472 868 18446744073709551615 94388826710016 94388827626021 140725039102800 0 0 0 2 4 65536 1 0 0 17 1 0 0 0 0 0 94388827875984 94388827924080 94388835627008 140725039105503 140725039105528 140725039105528 140725039108073 0