Skip to content

Commit 1a1d4aa

Browse files
committed
More commsdsl2wireshark unit tests.
1 parent c6120bd commit 1a1d4aa

16 files changed

Lines changed: 255 additions & 14 deletions

File tree

app/commsdsl2comms/test/test40/Schema.xml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<schema name="test40"
3-
id="1"
4-
endian="big">
2+
<schema name="test40" endian="big">
53
<message name="Msg1" id="1">
64
<int name="Time_ns" type="uint8" units="ns" />
75
<int name="Time_us" type="uint8" units="us" />

app/commsdsl2comms/test/test41/Schema.xml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<schema name="test41"
3-
id="1"
4-
endian="big"
5-
version="2">
2+
<schema name="test41" endian="big" version="2">
63
<fields>
74
<enum name="MsgId" type="uint8" semanticType="messageId" >
85
<validValue name="M1" val="1" />

app/commsdsl2wireshark/src/WiresharkField.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,11 @@ std::size_t WiresharkField::wiresharkMinFieldLength(const WiresharkField* refFie
229229
}
230230

231231
auto parseObj = refField->wiresharkGenField().genParseObj();
232+
233+
if (parseObj.parseIsPseudo()) {
234+
return 0U;
235+
}
236+
232237
auto len = parseObj.parseMinLength();
233238
auto* bitfieldParent = refField->wiresharkParentBitfield();
234239
if (bitfieldParent == nullptr) {

app/commsdsl2wireshark/src/WiresharkIdLayer.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ std::string WiresharkIdLayer::wiresharkDissectBodyImpl() const
4343
{
4444
static const std::string Templ =
4545
"#^#FIELD#$#\n"
46-
"local id = tvb(offset, next_offset - offset):#^#VALUE#$#\n"
46+
"local id = #^#VALUE_FUNC#$#()\n"
4747
"local msg = #^#MAP#$#[id]\n"
48-
"offset = next_offset\n"
48+
"#^#OFFSET#$# = #^#NEXT_OFFSET#$#\n"
4949
"#^#NEXT#$#\n"
5050
;
5151

@@ -54,9 +54,11 @@ std::string WiresharkIdLayer::wiresharkDissectBodyImpl() const
5454

5555
util::GenReplacementMap repl = {
5656
{"FIELD", wiresharkDissectFieldCode()},
57-
{"VALUE", field->wiresharkTvbRangeAccess()},
5857
{"NEXT", wiresharkNextFuncCode()},
5958
{"MAP", wiresharkMsgMapNameInternal()},
59+
{"VALUE_FUNC", field->wiresharkValueFuncName()},
60+
{"OFFSET", WiresharkField::wiresharkOffsetStr()},
61+
{"NEXT_OFFSET", WiresharkField::wiresharkNextOffsetStr()},
6062
};
6163

6264
return util::genProcessTemplate(Templ, repl);

app/commsdsl2wireshark/src/WiresharkIntField.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ std::string WiresharkIntField::wiresharkDissectBodyImpl(const WiresharkField* re
207207

208208
auto& wiresharkGenerator = WiresharkGenerator::wiresharkCast(genGenerator());
209209
auto parseObj = genIntFieldParseObj();
210-
bool hasVal = !wiresharkHasTrivialValidImpl();
210+
bool hasVal = (!wiresharkHasTrivialValidImpl()) || parseObj.parseIsPseudo();
211211
util::GenReplacementMap repl = {
212212
{"LEN", std::to_string(wiresharkMinFieldLength(refField))},
213213
{"SUCCESS", Wireshark::wiresharkStatusCodeStr(wiresharkGenerator, Wireshark::WiresharkStatusCode::Success)},
@@ -467,6 +467,20 @@ std::string WiresharkIntField::wiresharkFieldAsFloatRegistrationInternal(const W
467467
std::string WiresharkIntField::wiresharkValDeclCodeInternal() const
468468
{
469469
auto parseObj = genIntFieldParseObj();
470+
471+
if (parseObj.parseIsPseudo()) {
472+
static const std::string Templ =
473+
"local #^#VAL#$# = #^#VALUE#$#\n"
474+
;
475+
476+
util::GenReplacementMap repl = {
477+
{"VAL", wiresharkValStr()},
478+
{"VALUE", std::to_string(parseObj.parseDefaultValue())},
479+
};
480+
481+
return util::genProcessTemplate(Templ, repl);
482+
}
483+
470484
auto type = parseObj.parseType();
471485
if (genIsVarLengthType(type)) {
472486
static const std::string Templ =

app/commsdsl2wireshark/src/WiresharkListField.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ std::string WiresharkListField::wiresharkDissectBodyImpl([[maybe_unused]] const
225225
break;
226226
}
227227

228-
repl["READ"] = "-- TODO: implement";
228+
repl["READ"] = wiresharkUnboundDissectInternal();
229229
} while (false);
230230

231231
return util::genProcessTemplate(Templ, repl);
@@ -554,6 +554,23 @@ std::string WiresharkListField::wiresharkTermSuffixDissectInternal() const
554554
return util::genProcessTemplate(Templ, repl);
555555
}
556556

557+
std::string WiresharkListField::wiresharkUnboundDissectInternal() const
558+
{
559+
static const std::string Templ =
560+
"while (#^#NEXT_OFFSET#$# < #^#LIMIT#$#) do\n"
561+
" #^#READ_ELEM#$#\n"
562+
"end\n"
563+
;
564+
565+
util::GenReplacementMap repl = {
566+
{"LIMIT", wiresharkOffsetLimitStr()},
567+
{"NEXT_OFFSET", wiresharkNextOffsetStr()},
568+
{"READ_ELEM", wiresharkDissectElemCodeInternal()},
569+
};
570+
571+
return util::genProcessTemplate(Templ, repl);
572+
}
573+
557574
std::string WiresharkListField::wiresharkElemLimitCodeInternal() const
558575
{
559576
auto parseObj = genListFieldParseObj();

app/commsdsl2wireshark/src/WiresharkListField.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class WiresharkListField final : public commsdsl::gen::GenListField, public Wire
6565
std::string wiresharkCountPrefixDissectInternal() const;
6666
std::string wiresharkLengthPrefixDissectInternal() const;
6767
std::string wiresharkTermSuffixDissectInternal() const;
68+
std::string wiresharkUnboundDissectInternal() const;
6869
std::string wiresharkElemLimitCodeInternal() const;
6970

7071
std::vector<WiresharkField*> m_wiresharkFields;

app/commsdsl2wireshark/test/test38/test38.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from functools import reduce
2-
import operator
31
import sys
42

53
from commsdsl_pcap_gen import *
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
from functools import reduce
2+
import operator
3+
import sys
4+
5+
from commsdsl_pcap_gen import *
6+
7+
def do_frame(size, id, payload):
8+
prefix = struct.pack('>HB', size, id)
9+
return prefix + payload
10+
11+
def pcap1(f):
12+
seq = 1000
13+
msg1_payload = struct.pack('>BBBBB', 1, 0x32, 4, 5, 6)
14+
msg1 = do_frame(1 + len(msg1_payload), 1, msg1_payload)
15+
header = commsdsl_create_ethernet_ip_tcp_headers(len(msg1), seq)
16+
commsdsl_write_packet(f, header + msg1, time.time())
17+
18+
def main():
19+
with open(sys.argv[1], 'wb') as f:
20+
commsdsl_write_pcap_header(f)
21+
pcap1(f)
22+
23+
if __name__ == '__main__':
24+
main()
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import sys
2+
3+
from commsdsl_pcap_gen import *
4+
5+
def do_frame(id, payload):
6+
prefix = struct.pack('>B', id)
7+
return prefix + payload
8+
9+
def pcap1(f):
10+
seq = 1000
11+
msg1_payload = struct.pack('>42B', *range(1, 43))
12+
msg1 = do_frame(1, msg1_payload)
13+
header = commsdsl_create_ethernet_ip_tcp_headers(len(msg1), seq)
14+
commsdsl_write_packet(f, header + msg1, time.time())
15+
16+
def pcap2(f):
17+
seq = 2000
18+
msg2_payload = struct.pack('')
19+
msg2 = do_frame(2, msg2_payload)
20+
header = commsdsl_create_ethernet_ip_tcp_headers(len(msg2), seq)
21+
commsdsl_write_packet(f, header + msg2, time.time())
22+
23+
def main():
24+
with open(sys.argv[1], 'wb') as f:
25+
commsdsl_write_pcap_header(f)
26+
pcap1(f)
27+
pcap2(f)
28+
29+
if __name__ == '__main__':
30+
main()

0 commit comments

Comments
 (0)