@@ -58,14 +58,23 @@ function countdiff(s0, s1)
5858end
5959
6060function assertmostlyeql (threshold , s0 , s1 )
61+ if # s0 ~= # s1 then
62+ print (" s0" , h (s0 ))
63+ print (" s1" , h (s1 ))
64+ end
6165 assert (# s0 == # s1 )
66+
6267 local diff = countdiff (s0 , s1 )
63- assert (diff <= threshold , diff )
68+ if diff > threshold then
69+ print (" s0" , h (s0 ))
70+ print (" s1" , h (s1 ))
71+ end
72+ assert (diff <= threshold , diff .. " is less than threshold " .. threshold )
6473end
6574
66- function pcapreencode (incap , outcap )
75+ function pcaprecode (incap , outcap )
6776 if not outcap then
68- outcap = " reencoded -" .. incap
77+ outcap = " recoded -" .. incap
6978 end
7079 os.remove (outcap )
7180
@@ -79,8 +88,8 @@ function pcapreencode(incap, outcap)
7988 assert (n :clear ())
8089 assert (n :decode_eth (pkt ))
8190 assert (dmp :dump (n :block (), time , len ))
91+ -- print(n:dump())
8292 end
83- -- FIXME assert(i > 0)
8493 dmp :close ()
8594 cap :close ()
8695 n :destroy ()
@@ -97,12 +106,28 @@ function assertpcapsimilar(threshold, file0, file1)
97106 local pkt1 , time1 , len1 = assert (cap1 :next ())
98107 i = i + 1
99108
100- print (" packet0 " , i , " wirelen" , len0 , " timestamp" , time0 , os.date (" !%c" , time0 ))
101- print (" packet1 " , i , " wirelen" , len1 , " timestamp" , time1 , os.date (" !%c" , time1 ))
109+ print (" " .. file0 , i , " wirelen" , len0 , " timestamp" , time0 , os.date (" !%c" , time0 ))
110+ print (file1 , i , " wirelen" , len1 , " timestamp" , time1 , os.date (" !%c" , time1 ))
102111
103112 assert (len0 == len1 )
104113 assert (time0 == time1 , string.format (" %.7f ~= %.7f" , time0 , time1 ))
105- assertmostlyeql (threshold , pkt0 , pkt1 )
114+
115+ local _threshold = threshold
116+ if type (threshold ) == " table" then
117+ if threshold [file0 ] then
118+ if type (threshold [file0 ]) == " table" then
119+ if threshold [file0 ][i ] then
120+ _threshold = threshold [file0 ][i ]
121+ end
122+ else
123+ _threshold = threshold [file0 ]
124+ end
125+ else
126+ _threshold = 0
127+ end
128+ end
129+
130+ assertmostlyeql (_threshold , pkt0 , pkt1 )
106131 end
107132 assert (cap1 :next () == nil )
108133 n0 :destroy ()
0 commit comments