Skip to content

Commit

Permalink
Add function for verifying correctness of new checksum computation
Browse files Browse the repository at this point in the history
  • Loading branch information
dpino committed Aug 15, 2018
1 parent de2db4e commit a8a2625
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/lib/newchecksum.dasl
Original file line number Diff line number Diff line change
Expand Up @@ -161,15 +161,8 @@ function selftest ()
return ("elapse: %.6f; ns_per_csum: %.2f; ns_per_byte: %.2f"):format(ret.elapse, ret.ns_per_csum, ret.ns_per_byte)
end
local function benchmark_report (size, mpps)
local function hex (num)
return ("0x%.2x"):format(num)
end
local ntohs = lib.ntohs
local times = mpps*10^6
local pkt = create_packet(size)
-- Verify checksum is correct.
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(ntohs(checksum_lua(pkt.data, pkt.length))))
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(C.cksum_generic(pkt.data, pkt.length, 0)))
print(mpps.."M; "..size.." bytes")
-- Benchmark for different architectures.
print("Gen: ", benchmark(function() return C.cksum_generic(pkt.data, pkt.length, 0), pkt end, times))
Expand All @@ -181,8 +174,20 @@ function selftest ()
end
print("New: ", benchmark(function() return newchecksum(pkt.data, pkt.length), pkt end, times))
end
local function verify_correctness ()
local function hex (num)
return ("0x%.2x"):format(num)
end
local ntohs = lib.ntohs
for size=44,1500 do
local pkt = create_packet(size)
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(ntohs(checksum_lua(pkt.data, pkt.length))))
assert(hex(ntohs(newchecksum(pkt.data, pkt.length))) == hex(C.cksum_generic(pkt.data, pkt.length, 0)))
end
end

print("selftest: newchecksum")
verify_correctness()
benchmark_report(44, 14.4)
benchmark_report(550, 2)
benchmark_report(1500, 1)
Expand Down

0 comments on commit a8a2625

Please sign in to comment.