]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lib: procfs: add unittests
authorThomas Weißschuh <thomas@t-8ch.de>
Sat, 24 Dec 2022 16:43:29 +0000 (16:43 +0000)
committerThomas Weißschuh <thomas@t-8ch.de>
Sat, 24 Dec 2022 17:31:28 +0000 (17:31 +0000)
tests/commands.sh
tests/expected/lib/procfs-one-process [new file with mode: 0644]
tests/expected/lib/procfs-stat-nth [new file with mode: 0644]
tests/expected/lib/procfs-stat-nth.err [new file with mode: 0644]
tests/ts/lib/procfs [new file with mode: 0755]
tests/ts/lib/procfs-data/proc/1/cmdline [new file with mode: 0644]
tests/ts/lib/procfs-data/proc/1/comm [new file with mode: 0644]
tests/ts/lib/procfs-data/proc/1/stat [new file with mode: 0644]

index 377cc2492b63e472a3c85b38cb7352b2acc368cf..ef9e74d238197f17954b2510f8bc66578b2d6fa7 100644 (file)
@@ -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 (file)
index 0000000..a8ecf79
--- /dev/null
@@ -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 (file)
index 0000000..c6c333a
--- /dev/null
@@ -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 (file)
index 0000000..aff7b24
--- /dev/null
@@ -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 (executable)
index 0000000..0d0c812
--- /dev/null
@@ -0,0 +1,49 @@
+#!/bin/bash
+#
+# Copyright (C) 2022 Thomas Weißschuh <thomas@t-8ch.de>
+#
+# 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 (file)
index 0000000..2baeb31
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 (file)
index 0000000..9daeafb
--- /dev/null
@@ -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 (file)
index 0000000..35cb1bd
--- /dev/null
@@ -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