Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
scapy
Manage
Activity
Members
Plan
Wiki
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
CodeLinaro
public-release-test-restored
platform
external
scapy
Commits
0e02addc
Commit
0e02addc
authored
7 years ago
by
Pierre Lalet
Committed by
GitHub
7 years ago
Browse files
Options
Downloads
Plain Diff
Merge pull request #833 from guedou/coverage_plist
[coverage] PacketList methods regression tests
parents
ef3d5672
20bb4692
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
.travis/install.sh
+1
-0
1 addition, 0 deletions
.travis/install.sh
test/regression.uts
+166
-1
166 additions, 1 deletion
test/regression.uts
with
167 additions
and
1 deletion
.travis/install.sh
+
1
−
0
View file @
0e02addc
...
@@ -19,6 +19,7 @@ fi
...
@@ -19,6 +19,7 @@ fi
if
[
"
$SCAPY_COVERAGE
"
=
"yes"
]
if
[
"
$SCAPY_COVERAGE
"
=
"yes"
]
then
then
$SCAPY_SUDO
pip
install
$PIP_INSTALL_FLAGS
coverage
$SCAPY_SUDO
pip
install
$PIP_INSTALL_FLAGS
coverage
$SCAPY_SUDO
apt-get
install
python-pyx
fi
fi
# Install pcap & dnet
# Install pcap & dnet
...
...
This diff is collapsed.
Click to expand it.
test/regression.uts
+
166
−
1
View file @
0e02addc
...
@@ -8932,4 +8932,169 @@ if WINDOWS:
...
@@ -8932,4 +8932,169 @@ if WINDOWS:
conf.route.resync()
conf.route.resync()
conf.route6.resync()
conf.route6.resync()
True
True
\ No newline at end of file
############
############
+ PacketList methods
= plot()
import mock
@mock.patch("scapy.plist.plt")
def test_plot(mock_plt):
def fake_plot(data, **kwargs):
return data
mock_plt.plot = fake_plot
plist = PacketList([IP(id=i)/TCP() for i in xrange(10)])
lines = plist.plot(lambda p: (p.time, p.id))
assert(len(lines) == 10)
test_plot()
= diffplot()
import mock
@mock.patch("scapy.plist.plt")
def test_diffplot(mock_plt):
def fake_plot(data, **kwargs):
return data
mock_plt.plot = fake_plot
plist = PacketList([IP(id=i)/TCP() for i in xrange(10)])
lines = plist.diffplot(lambda x,y: (x.time, y.id-x.id))
assert(len(lines) == 9)
test_diffplot()
= multiplot()
import mock
@mock.patch("scapy.plist.plt")
def test_multiplot(mock_plt):
def fake_plot(data, **kwargs):
return data
mock_plt.plot = fake_plot
tmp = [IP(id=i)/TCP() for i in xrange(10)]
plist = PacketList([tuple(tmp[i-2:i]) for i in xrange(2, 10, 2)])
lines = plist.multiplot(lambda x: (x[1][IP].src, (x[1].time, x[1][IP].id)))
assert(len(lines) == 1)
assert(len(lines[0]) == 4)
test_multiplot()
= rawhexdump()
def test_rawhexdump():
with ContextManagerCaptureOutput() as cmco:
p = PacketList([IP()/TCP() for i in xrange(2)])
p.rawhexdump()
result_pl_rawhexdump = cmco.get_output()
assert(len(result_pl_rawhexdump.split('\n')) == 7)
assert(result_pl_rawhexdump.startswith("0000 45000028"))
test_rawhexdump()
= hexraw()
def test_hexraw():
with ContextManagerCaptureOutput() as cmco:
p = PacketList([IP()/Raw(str(i)) for i in xrange(2)])
p.hexraw()
result_pl_hexraw = cmco.get_output()
assert(len(result_pl_hexraw.split('\n')) == 5)
assert("0000 30" in result_pl_hexraw)
test_hexraw()
= hexdump()
def test_hexdump():
with ContextManagerCaptureOutput() as cmco:
p = PacketList([IP()/Raw(str(i)) for i in xrange(2)])
p.hexdump()
result_pl_hexdump = cmco.get_output()
assert(len(result_pl_hexdump.split('\n')) == 7)
assert("0010 7F00000131" in result_pl_hexdump)
test_hexdump()
= padding()
def test_padding():
with ContextManagerCaptureOutput() as cmco:
p = PacketList([IP()/conf.padding_layer(str(i)) for i in xrange(2)])
p.padding()
result_pl_padding = cmco.get_output()
assert(len(result_pl_padding.split('\n')) == 5)
assert("0000 30" in result_pl_padding)
test_padding()
= nzpadding()
def test_nzpadding():
with ContextManagerCaptureOutput() as cmco:
p = PacketList([IP()/conf.padding_layer("A%s" % i) for i in xrange(2)])
p.nzpadding()
result_pl_nzpadding = cmco.get_output()
assert(len(result_pl_nzpadding.split('\n')) == 5)
assert("0000 4130" in result_pl_nzpadding)
test_nzpadding()
= conversations()
import mock
@mock.patch("scapy.plist.do_graph")
def test_conversations(mock_do_graph):
def fake_do_graph(graph, **kwargs):
return graph
mock_do_graph.side_effect = fake_do_graph
plist = PacketList([IP(dst="127.0.0.2")/TCP(dport=i) for i in xrange(2)])
plist.extend([IP(src="127.0.0.2")/TCP(sport=i) for i in xrange(2)])
result_conversations = plist.conversations()
assert(len(result_conversations.split('\n')) == 5)
assert(result_conversations.startswith('digraph "conv" {'))
test_conversations()
= afterglow()
import mock
@mock.patch("scapy.plist.do_graph")
def test_afterglow(mock_do_graph):
def fake_do_graph(graph, **kwargs):
return graph
mock_do_graph.side_effect = fake_do_graph
plist = PacketList([IP(dst="127.0.0.2")/TCP(dport=i) for i in xrange(2)])
plist.extend([IP(src="127.0.0.2")/TCP(sport=i) for i in xrange(2)])
result_afterglow = plist.afterglow()
assert(len(result_afterglow.split('\n')) == 19)
assert(result_afterglow.startswith('digraph "afterglow" {'))
test_afterglow()
= psdump()
print(test_pyx())
if test_pyx():
import tempfile
import os
filename = tempfile.mktemp(suffix=".ps")
plist = PacketList([IP()/TCP()])
plist.psdump(filename)
assert(os.path.exists(filename))
os.unlink(filename)
= pdfdump()
print(test_pyx())
if test_pyx():
import tempfile
import os
filename = tempfile.mktemp(suffix=".pdf")
plist = PacketList([IP()/TCP()])
plist.pdfdump(filename)
assert(os.path.exists(filename))
os.unlink(filename)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment