]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
tests: Use pgrep instead of ps
authorBenjamin Berg <benjamin.berg@intel.com>
Wed, 17 Jan 2024 18:02:31 +0000 (19:02 +0100)
committerJouni Malinen <j@w1.fi>
Sat, 20 Jan 2024 07:35:39 +0000 (09:35 +0200)
The ps command as shipped by busybox does not support the "command"
column. Change the code to use pgrep instead which will work fine in all
environments.

In addition, raise an exception if PID was not found since the test
would just hang with pid = 0.

Signed-off-by: Benjamin Berg <benjamin.berg@intel.com>
tests/hwsim/test_ap_eap.py
tests/hwsim/vm/inside.sh

index bfc1bb4175ddc01dcdc32664cece4313be04acf6..a201403163b13ce2e7ddc7e8011112042eac241f 100644 (file)
@@ -7607,20 +7607,15 @@ def test_ap_wpa2_eap_psk_mac_addr_change(dev, apdev):
     params = hostapd.wpa2_eap_params(ssid="test-wpa2-eap")
     hapd = hostapd.add_ap(apdev[0], params)
 
-    cmd = subprocess.Popen(['ps', '-eo', 'pid,command'], stdout=subprocess.PIPE)
-    res = cmd.stdout.read().decode()
+    cmd = subprocess.Popen(['pgrep', '-nf', 'wpa_supplicant.*' + dev[0].ifname],
+                           stdout=subprocess.PIPE)
+    res = cmd.stdout.read().decode().strip()
     cmd.stdout.close()
-    pid = 0
-    for p in res.splitlines():
-        if "wpa_supplicant" not in p:
-            continue
-        if dev[0].ifname not in p:
-            continue
-        pid = int(p.strip().split(' ')[0])
-    if pid == 0:
-        logger.info("Could not find wpa_supplicant PID")
-    else:
+    if res:
+        pid = int(res)
         logger.info("wpa_supplicant PID %d" % pid)
+    else:
+        raise Exception("Could not find wpa_supplicant PID")
 
     addr = dev[0].get_status_field("address")
     subprocess.call(['ip', 'link', 'set', 'dev', dev[0].ifname, 'down'])
index 38c5284d9c2e2a0facf459cdf221e4f7d4159d68..31dfb9d5708cc58cd6e20133213f81bc9c3236a9 100755 (executable)
@@ -146,6 +146,9 @@ if [ "$TELNET" = "1" ] ; then
   ) &
 fi
 
+# procps 3.3.17 needs an uptime of >1s (relevant for UML time-travel)
+sleep 1
+
 # check if we're rebooting due to a kernel panic ...
 if grep -q 'Kernel panic' /tmp/logs/console ; then
        echo "KERNEL CRASHED!" >/dev/ttyS0