From: Thomas Weißschuh Date: Sat, 24 Dec 2022 16:43:29 +0000 (+0000) Subject: lib: procfs: add unittests X-Git-Tag: v2.39-rc1~356^2~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d34b0603e8c0c2f7ec548a15c2d23bcb2c4dea1b;p=thirdparty%2Futil-linux.git lib: procfs: add unittests --- diff --git a/tests/commands.sh b/tests/commands.sh index 377cc2492b..ef9e74d238 100644 --- a/tests/commands.sh +++ b/tests/commands.sh @@ -46,6 +46,7 @@ TS_HELPER_CAL="${ts_helpersdir}test_cal" TS_HELPER_LAST_FUZZ="${ts_helpersdir}test_last_fuzz" TS_HELPER_MKFDS="${ts_helpersdir}test_mkfds" TS_HELPER_BLKID_FUZZ="${ts_helpersdir}test_blkid_fuzz" +TS_HELPER_PROCFS="${ts_helpersdir}test_procfs" # paths to commands TS_CMD_ADDPART=${TS_CMD_ADDPART:-"${ts_commandsdir}addpart"} diff --git a/tests/expected/lib/procfs-one-process b/tests/expected/lib/procfs-one-process new file mode 100644 index 0000000000..a8ecf79514 --- /dev/null +++ b/tests/expected/lib/procfs-one-process @@ -0,0 +1,4 @@ +1 + UID: [redacted] + CMDLINE: './test' + COMM: 'test' diff --git a/tests/expected/lib/procfs-stat-nth b/tests/expected/lib/procfs-stat-nth new file mode 100644 index 0000000000..c6c333ab06 --- /dev/null +++ b/tests/expected/lib/procfs-stat-nth @@ -0,0 +1,2 @@ +1: 1th 373850 +1: 4th 373752 diff --git a/tests/expected/lib/procfs-stat-nth.err b/tests/expected/lib/procfs-stat-nth.err new file mode 100644 index 0000000000..aff7b24278 --- /dev/null +++ b/tests/expected/lib/procfs-stat-nth.err @@ -0,0 +1,2 @@ +test_procfs: read 2th number failed: Invalid argument +test_procfs: read 3th number failed: Invalid argument diff --git a/tests/ts/lib/procfs b/tests/ts/lib/procfs new file mode 100755 index 0000000000..0d0c812c3b --- /dev/null +++ b/tests/ts/lib/procfs @@ -0,0 +1,49 @@ +#!/bin/bash +# +# Copyright (C) 2022 Thomas Weißschuh +# +# This file is part of util-linux. +# +# This file is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This file is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +TS_TOPDIR="${0%/*}/../.." +TS_DESC="procfs library" + +. "$TS_TOPDIR"/functions.sh +ts_init "$*" + +ts_check_test_command "$TS_HELPER_PROCFS" + +test_data="$TS_SELF/procfs-data" +test_cmd() { + "$TS_HELPER_PROCFS" --prefix "$test_data" "$@" \ + 2>> "$TS_ERRLOG" \ + | sed -e 's/ UID: .*/ UID: [redacted]/' \ + >> "$TS_OUTPUT" +} + +ts_init_subtest "one-process" + +test_cmd --one 1 + +ts_finalize_subtest + + +ts_init_subtest "stat-nth" + +test_cmd --stat-nth 1 1 +test_cmd --stat-nth 1 2 +test_cmd --stat-nth 1 3 +test_cmd --stat-nth 1 4 + +ts_finalize_subtest + +ts_finalize diff --git a/tests/ts/lib/procfs-data/proc/1/cmdline b/tests/ts/lib/procfs-data/proc/1/cmdline new file mode 100644 index 0000000000..2baeb318e8 Binary files /dev/null and b/tests/ts/lib/procfs-data/proc/1/cmdline differ diff --git a/tests/ts/lib/procfs-data/proc/1/comm b/tests/ts/lib/procfs-data/proc/1/comm new file mode 100644 index 0000000000..9daeafb986 --- /dev/null +++ b/tests/ts/lib/procfs-data/proc/1/comm @@ -0,0 +1 @@ +test diff --git a/tests/ts/lib/procfs-data/proc/1/stat b/tests/ts/lib/procfs-data/proc/1/stat new file mode 100644 index 0000000000..35cb1bd20c --- /dev/null +++ b/tests/ts/lib/procfs-data/proc/1/stat @@ -0,0 +1 @@ +373850 (test) S 373752 373850 373752 34835 373850 4194304 83 0 0 0 0 0 0 0 20 0 1 0 6164479 2543616 320 18446744073709551615 94138801930240 94138801930657 140720370008720 0 0 0 0 0 0 1 0 0 17 1 0 0 0 0 0 94138801941968 94138801942568 94138832138240 140720370011239 140720370011246 140720370011246 140720370012145 0