Add test/list-cmd

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2022-12-04 15:56:52 +01:00
commit 03da0449c4
4 changed files with 165 additions and 0 deletions

6
test/list-cmd/Makefile Normal file
View file

@ -0,0 +1,6 @@
TOPDIR = ../..
include $(TOPDIR)/make/proj.mk
include $(JWBDIR)/make/platform.mk
include $(JWBDIR)/make/py-run.mk
include $(JWBDIR)/make/dev-utils.mk

67
test/list-cmd/ps-out.txt Normal file
View file

@ -0,0 +1,67 @@
~ # ps
PID USER VSZ STAT COMMAND
1 root 2300 S init
2 root 0 SW [kthreadd]
3 root 0 SW [ksoftirqd/0]
4 root 0 SW [events/0]
5 root 0 SW [khelper]
6 root 0 SW [async/mgr]
7 root 0 SW [sync_supers]
8 root 0 SW [bdi-default]
9 root 0 SW [kblockd/0]
10 root 0 SW [khubd]
11 root 0 SW [kseriod]
12 root 0 SW [cfg80211]
13 root 0 SW [kswapd0]
14 root 0 SW [aio/0]
15 root 0 SW [crypto/0]
24 root 0 SW [mtdblockd]
33 root 0 SW [usbhid_resumer]
34 root 0 SW [scsi_eh_0]
35 root 0 SW [usb-storage]
38 root 0 SW [kjournald]
40 root 2300 S {rc.start} /bin/sh /etc/rc.start
41 root 2304 S /bin/sh
66 root 3008 S /lib/udev/udevd
81 root 3076 S /lib/udev/udevd
82 root 3004 S /lib/udev/udevd
84 root 1928 S logger
87 root 2084 S metalog [MASTER]
89 root 2076 S metalog [KERNEL]
104 root 0 SW [kjournald]
122 root 2912 S /usr/bin/dbus-daemon --system
123 root 5948 S /usr/sbin/accudrv
127 blah 3984 S /usr/sbin/watchdogd
139 root 4788 S /usr/sbin/sshd -f /etc/sshd_config
158 www 5248 S /usr/sbin/lighttpd -f /etc/lighttpd.conf
163 www 3960 S /usr/bin/json-dbus-bridge
173 nonroot 23136 S /usr/sbin/blob-lock
174 root 68284 S /usr/sbin/canon
192 root 57888 S /usr/sbin/barcode
193 root 3980 S /usr/sbin/auto-restarter /usr/sbin/auto-programming
194 root 26048 S /usr/sbin/sgc
247 root 15816 S /usr/sbin/nonexisting-broken-command
196 root 42828 S /usr/sbin/auto-programming
227 root 26096 S /usr/sbin/descread
228 root 131m S /usr/sbin/device-driver
244 root 3980 S /usr/sbin/auto-restarter /usr/sbin/bcc
246 root 52776 S /usr/sbin/db2js
247 root 15816 S /usr/sbin/pcs
248 root 28688 S /usr/sbin/timeset
251 root 69720 S /usr/sbin/bcc
273 root 22272 S /usr/libexec/polkitd
275 root 103m S /usr/sbin/pcs
349 root 2300 S {rc.start} /bin/sh /etc/rc.start
355 root 2300 S {gratuitous-arp.} /bin/sh /usr/sbin/gratuitous-arp.s
356 root 2300 S {update-status.s} /bin/sh /usr/sbin/update-status.sh
451 root 4668 S update-status
452 root 1928 S logger -p INFO -t UPDATESTATUS
644 root 2168 S sleep 1800
2113 root 18296 S /usr/sbin/NetworkManager
2126 root 0 SW [wlan0]
2129 root 6244 S /usr/sbin/wpa_supplicant -u
2699 root 2168 S sleep 29
2736 root 7432 S {sshd} sshd: root@pts/0
2741 root 2304 S -sh
2754 root 2304 R ps
~ #

68
test/list-cmd/ps-ref.txt Normal file
View file

@ -0,0 +1,68 @@
~ # ps
PID USER VSZ STAT COMMAND
1 root 2300 S init
2 root 0 SW [kthreadd]
3 root 0 SW [ksoftirqd/0]
4 root 0 SW [events/0]
5 root 0 SW [khelper]
6 root 0 SW [async/mgr]
7 root 0 SW [sync_supers]
8 root 0 SW [bdi-default]
9 root 0 SW [kblockd/0]
10 root 0 SW [khubd]
11 root 0 SW [kseriod]
12 root 0 SW [cfg80211]
13 root 0 SW [kswapd0]
14 root 0 SW [aio/0]
15 root 0 SW [crypto/0]
24 root 0 SW [mtdblockd]
33 root 0 SW [usbhid_resumer]
34 root 0 SW [scsi_eh_0]
35 root 0 SW [usb-storage]
38 root 0 SW [kjournald]
40 root 2300 S {rc.start} /bin/sh /etc/rc.start
41 root 2304 S /bin/sh
66 root 3008 S /lib/udev/udevd
81 root 3076 S /lib/udev/udevd
82 root 3004 S /lib/udev/udevd
84 root 1928 S logger
87 root 2084 S metalog [MASTER]
89 root 2076 S metalog [KERNEL]
104 root 0 SW [kjournald]
122 root 2912 S /usr/bin/dbus-daemon --system
123 root 5948 S /usr/sbin/accudrv
127 root 3984 S /usr/sbin/watchdogd # "ignore": true
127 blah 3984 S /usr/sbin/watchdogd # "ignore": true
139 root 4788 S /usr/sbin/sshd -f /etc/sshd_config # ignore
158 www 5248 S /usr/sbin/lighttpd -f /etc/lighttpd.conf
163 www 3960 S /usr/bin/json-dbus-bridge
173 root 23136 S /usr/sbin/blob-lock # "ignore": [ "bug-soandso" ], "unneeded": [ "polp" ]
173 nonroot 23136 S /usr/sbin/blob-lock
174 root 68284 S /usr/sbin/canon
192 root 57888 S /usr/sbin/barcode
193 root 3980 S /usr/sbin/auto-restarter /usr/sbin/auto-programming
194 root 26048 S /usr/sbin/sgc
196 root 42828 S /usr/sbin/auto-programming
227 root 26096 S /usr/sbin/descread
228 root 131m S /usr/sbin/device-driver
244 root 3980 S /usr/sbin/auto-restarter /usr/sbin/bcc
246 root 52776 S /usr/sbin/db2js
247 root 15816 S /usr/sbin/pcs
248 root 28688 S /usr/sbin/timeset
251 root 69720 S /usr/sbin/bcc
273 root 22272 S /usr/libexec/polkitd
275 root 103m S /usr/sbin/pcs
349 root 2300 S {rc.start} /bin/sh /etc/rc.start
355 root 2300 S {gratuitous-arp.} /bin/sh /usr/sbin/gratuitous-arp.s
356 root 2300 S {update-status.s} /bin/sh /usr/sbin/update-status.sh
451 root 4668 S update-status
452 root 1928 S logger -p INFO -t UPDATESTATUS
644 root 2168 S sleep 1800
2113 root 18296 S /usr/sbin/NetworkManager
2126 root 0 SW [wlan0]
2129 root 6244 S /usr/sbin/wpa_supplicant -u
2699 root 2168 S sleep 29
2736 root 7432 S {sshd} sshd: root@pts/0
2741 root 2304 S -sh
2754 root 2304 R ps
~ #

24
test/list-cmd/test.py Normal file
View file

@ -0,0 +1,24 @@
#!/usr/bin/python3.8
from jwutils.misc import multi_regex_edit
from jwutils.log import *
from devtest.os.test import ListCmd as Base
class TestCase(Base):
def _filter(self, output):
slog(WARNING, "Running filter")
output = multi_regex_edit([
('del', 'nonexist'),
('sub', '/usr/bin', '/klaut/bin')
], output)
return output
if __name__ == '__main__':
set_level(INFO)
refpath = 'ps-ref.txt'
testpath = 'ps-out.txt'
with open(testpath, "r") as f:
lines = f.readlines()
features = set(['polp'])
TestCase(refpath, write_response=True).test(lines, features)