Skip to content

Commit

Permalink
Merge pull request #6 from miri64/testutils/fix/pktbuf_check
Browse files Browse the repository at this point in the history
testsutils.mixins: fix pktbuf emptiness check
  • Loading branch information
jia200x authored Nov 10, 2018
2 parents 929a4c4 + 5090d2f commit 4009cf4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
8 changes: 1 addition & 7 deletions 05-single-hop-route/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ def single_hop_run(source, dest, ip_src, ip_dest,
source.reboot()
dest.reboot()

buf_source_start = source.extract_unused()
buf_dest_start = dest.extract_unused()

# Get useful information
iface = source.get_first_iface()
ip_src_ll = dest.get_ip_addr()
Expand All @@ -59,8 +56,5 @@ def single_hop_run(source, dest, ip_src, ip_dest,

packet_loss = source.ping(
count, ip_dest.split("/")[0], PAYLOAD_SIZE, DELAY)
buf_source_end = source.extract_unused()
buf_dest_end = dest.extract_unused()

return (packet_loss, buf_source_end == buf_source_start,
buf_dest_end == buf_dest_start)
return (packet_loss, source.is_empty(), dest.is_empty())
20 changes: 17 additions & 3 deletions testutils/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,21 @@ def ping(self, count, dest_addr, payload_size, delay):


class PktBuf:
def extract_unused(self):
def is_empty(self):
self.pexpect.sendline("pktbuf")
self.pexpect.expect("unused: ([0-9xa-f]+) ")
return self.pexpect.match.group(1)
self.pexpect.expect(r"packet buffer: "
r"first byte: 0x(?P<first_byte>[0-9A-Fa-f]+), "
r"last byte: 0x[0-9A-Fa-f]+ "
r"\(size: (?P<size>\d+)\)")
exp_first_byte = int(self.pexpect.match.group("first_byte"), base=16)
exp_size = int(self.pexpect.match.group("size"))
exp = self.pexpect.expect([r"~ unused: 0x(?P<first_byte>[0-9A-Fa-f]+) "
r"\(next: ((\(nil\))|0), "
r"size: (?P<size>\d+)\) ~",
pexpect.TIMEOUT])
if exp == 0:
first_byte = int(self.pexpect.match.group("first_byte"), base=16)
size == int(self.pexpect.match.group("size"))
return (exp_first_byte == first_byte) and (exp_size == size)
else:
return False

0 comments on commit 4009cf4

Please sign in to comment.