blob: cd10de4e06b3803b46467130ee2ff94da9caa6a1 [file] [log] [blame]
Bernhard Reutner-Fischer82338d82005-10-06 12:50:11 +00001#!/bin/sh
2
3# pidof tests.
Bernhard Reutner-Fischer6c4dade2008-09-25 12:13:34 +00004# Copyright 2005 by Bernhard Reutner-Fischer
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02005# Licensed under GPLv2, see file LICENSE in this source tree.
Bernhard Reutner-Fischer82338d82005-10-06 12:50:11 +00006
Denis Vlasenko9213a9e2006-09-17 16:28:10 +00007# AUDIT:
Bernhard Reutner-Fischer82338d82005-10-06 12:50:11 +00008
Mike Frysingercaa79402009-11-04 18:41:22 -05009. ./testing.sh
Bernhard Reutner-Fischer82338d82005-10-06 12:50:11 +000010
11# testing "test name" "options" "expected result" "file input" "stdin"
12
Rob Landley4bb1b042006-03-16 15:20:45 +000013testing "pidof (exit with error)" \
14 "pidof veryunlikelyoccuringbinaryname ; echo \$?" "1\n" "" ""
15testing "pidof (exit with success)" "pidof pidof > /dev/null; echo \$?" \
16 "0\n" "" ""
17# We can get away with this because it says #!/bin/sh up top.
Bernhard Reutner-Fischer82338d82005-10-06 12:50:11 +000018
Rob Landley4bb1b042006-03-16 15:20:45 +000019testing "pidof this" "pidof pidof.tests | grep -o -w $$" "$$\n" "" ""
Bernhard Reutner-Fischer82338d82005-10-06 12:50:11 +000020
Denys Vlasenko33eae282018-06-27 14:26:21 +020021test x"`cat /proc/1/comm`" = x"init" && {
Rob Landley48c61572005-11-07 08:50:53 +000022optional FEATURE_PIDOF_SINGLE
Rob Landley4bb1b042006-03-16 15:20:45 +000023testing "pidof -s" "pidof -s init" "1\n" "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020024SKIP=
Denys Vlasenko33eae282018-06-27 14:26:21 +020025}
Bernhard Reutner-Fischer82338d82005-10-06 12:50:11 +000026
Denys Vlasenko4c58f242018-06-27 14:50:00 +020027test x"`cat /proc/1/comm`" = x"init" && {
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020028optional FEATURE_PIDOF_OMIT FEATURE_PIDOF_SINGLE
Denis Vlasenko6446c2d2007-11-25 04:54:13 +000029# This test fails now because process name matching logic has changed,
30# but new logic is not "wrong" either... see find_pid_by_name.c comments
31#testing "pidof -o %PPID" "pidof -o %PPID pidof.tests | grep -o -w $$" "" "" ""
Rob Landley4bb1b042006-03-16 15:20:45 +000032testing "pidof -o %PPID NOP" "pidof -o %PPID -s init" "1\n" "" ""
Denys Vlasenko4c58f242018-06-27 14:50:00 +020033SKIP=
34}
35
36optional FEATURE_PIDOF_OMIT
Denis Vlasenko9213a9e2006-09-17 16:28:10 +000037testing "pidof -o init" "pidof -o 1 init | grep -o -w 1" "" "" ""
Denys Vlasenkobfa1b2e2010-05-11 03:53:57 +020038SKIP=
Bernhard Reutner-Fischer82338d82005-10-06 12:50:11 +000039
40exit $FAILCOUNT