lib/oeqa/runtime: ping: fix ping false fail

Submitted by Stanacar, StefanX on Aug. 30, 2013, 4:48 p.m. | Patch ID: 57151


Message ID
State Accepted
Commit 56d144fd22d37189e49cdf3032afb00f0be469c6
Headers show

Commit Message

Stanacar, StefanX Aug. 30, 2013, 4:48 p.m.
We run the ping test as soon as we reach the login prompt.
But sometimes (seen in sato systemd) we end up with link down/link up stuff like:

    qemux86-64 login: IPv6: ADDRCONF(NETDEV_UP): eth0: link is not ready
    e1000: eth0 NIC Link is Up 1000 Mbps Full Duplex, Flow Control: RX
    IPv6: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready

The logic behind ping -w 30 -c 1 was to wait at most 30 seconds
for at least one reply,  but there is a catch: reply doesn't seems
to be echo reply but any reply (non-reply means loss not network error)
ping's man page:
    -w deadline
              Specify  a  timeout, in seconds, before ping exits regardless of
              how many packets have been sent or received. In this  case  ping
              does  not  stop after count packet are sent, it waits either for
              deadline expire or until count probes are answered or  for  some
              error notification from network.

Just when the link up/link down happens ping returns:
    From icmp_seq=1 Destination Host Unreachable
    --- ping statistics ---
    1 packets transmitted, 0 received, +1 errors, 100% packet loss, time 0ms

and exits sooner than the 30 seconds timeout.

This patch should do what was originally intended (wait at most
30 seconds for at least one reply).

Signed-off-by: Stefan Stanacar <>
 meta/lib/oeqa/runtime/ | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/meta/lib/oeqa/runtime/ b/meta/lib/oeqa/runtime/
index d6a0c28..935f638 100644
--- a/meta/lib/oeqa/runtime/
+++ b/meta/lib/oeqa/runtime/
@@ -1,11 +1,17 @@ 
 import subprocess
 import unittest
 import sys
+import time
 from oeqa.oetest import oeRuntimeTest
 class PingTest(oeRuntimeTest):
     def test_ping(self):
-        status ="ping -w 30 -c 1 %s" %, shell=True, stdout=subprocess.PIPE)
-        self.assertEqual(status, 0)
+        output = ''
+        status = None
+        endtime = time.time() + 30
+        while status != 0 and time.time() < endtime:
+            proc = subprocess.Popen("ping -c 1 %s" %, shell=True, stdout=subprocess.PIPE)
+            output += proc.communicate()[0]
+            status = proc.poll()
+        self.assertEqual(status, 0, msg = "No echo reply, ping output is:\n%s" % output)