-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
David Schneider
committed
May 23, 2019
1 parent
93b585d
commit 866d692
Showing
7 changed files
with
150 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from vbftool.vbf import Vbf | ||
import bincopy | ||
|
||
bin = bincopy.BinFile() | ||
bin.add_ihex_file('test.hex') | ||
|
||
vbf = Vbf(0x1000000, 0x3C0000, bin.as_binary()) | ||
|
||
with open('reference.vbf', 'wb') as fp: | ||
vbf.dump(fp) |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
from io import BytesIO | ||
|
||
import vbftool.options as opts | ||
from vbftool import SwPartType, Network, FrameFormat | ||
|
||
|
||
def assert_desc(desc, expected): | ||
with BytesIO() as fp: | ||
desc.dump(fp) | ||
fp.seek(0) | ||
assert fp.read() == expected | ||
|
||
|
||
def test_description_single_line(): | ||
desc = opts.Description('description') | ||
assert_desc(desc, b'\t// Description\r\n\tdescription = { "description" };\r\n\r\n') | ||
|
||
|
||
def test_description_multi_line(): | ||
desc = opts.Description(['description1', 'description2']) | ||
assert_desc(desc, b'\t// Description\r\n\tdescription = { "description1", "description2" };\r\n\r\n') | ||
|
||
|
||
def test_sw_part_number_wers_or_eniva(): | ||
desc = opts.SwPartNumber('WERS number') | ||
assert_desc(desc, b'\t// Software part number\r\n\tsw_part_number = "WERS number";\r\n\r\n') | ||
|
||
|
||
def test_sw_part_number_wers_and_eniva(): | ||
desc = opts.SwPartNumber(['WERS number', "ENOVIA number"]) | ||
assert_desc(desc, b'\t// Software part number\r\n\tsw_part_number = { "WERS number", "ENOVIA number" };\r\n\r\n') | ||
|
||
|
||
def test_sw_part_number_DID(): | ||
desc = opts.SwPartNumberDID(0xF188) | ||
assert_desc(desc, b'\t// DID to read software part number\r\n\tsw_part_number_DID = 0xF188;\r\n\r\n') | ||
|
||
|
||
def test_sw_part_type(): | ||
desc = opts.SwPartType(SwPartType.EXE) | ||
assert_desc(desc, b'\t// Software part type\r\n\tsw_part_type = EXE;\r\n\r\n') | ||
|
||
|
||
def test_data_format_identifier_none(): | ||
desc = opts.DataFormatIdentifier(0, 0) | ||
assert_desc(desc, b'\t// Format identifier\r\n\tdata_format_identifier = 0x00;\r\n\r\n') | ||
|
||
|
||
def test_data_format_identifier_compressed(): | ||
desc = opts.DataFormatIdentifier(1, 0) | ||
assert_desc(desc, b'\t// Format identifier\r\n\tdata_format_identifier = 0x10;\r\n\r\n') | ||
|
||
|
||
def test_network_single(): | ||
desc = opts.Network(Network.CAN_HS) | ||
assert_desc(desc, b'\t// Network type or list\r\n\tnetwork = CAN_HS;\r\n\r\n') | ||
|
||
|
||
def test_network_subnet(): | ||
desc = opts.Network([Network.CAN_HS, Network.SUB_CAN1]) | ||
assert_desc(desc, b'\t// Network type or list\r\n\tnetwork = { CAN_HS, SUB_CAN1 };\r\n\r\n') | ||
|
||
|
||
def test_ecu_address_single(): | ||
desc = opts.EcuAddress(0x723) | ||
assert_desc(desc, b'\t// ECU address or list\r\n\tecu_address = 0x723;\r\n\r\n') | ||
|
||
|
||
def test_ecu_address_subnet(): | ||
desc = opts.EcuAddress([0x723, 0x740]) | ||
assert_desc(desc, b'\t// ECU address or list\r\n\tecu_address = { 0x723, 0x740 };\r\n\r\n') | ||
|
||
|
||
def test_frame_format(): | ||
desc = opts.FrameFormat(FrameFormat.CAN_STANDARD) | ||
assert_desc(desc, b'\t// Format frame\r\n\tframe_format = CAN_STANDARD;\r\n\r\n') | ||
|
||
|
||
def test_erase_single_block(): | ||
desc = opts.Erase([[0x10000, 0x20000]]) | ||
assert_desc(desc, b'\t// Erase block\r\n\terase = { { 0x10000, 0x20000 } };\r\n\r\n') | ||
|
||
|
||
def test_erase_multi_block(): | ||
desc = opts.Erase([[0x10000, 0x20000], [0x50000, 0x1000]]) | ||
assert_desc(desc, b'\t// Erase block\r\n\terase = { { 0x10000, 0x20000 }, { 0x50000, 0x1000 } };\r\n\r\n') | ||
|
||
|
||
def test_call(): | ||
desc = opts.Call(0x10000) | ||
assert_desc(desc, b'\t// Call address\r\n\tcall = 0x10000;\r\n\r\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
def writeline(fp, s): | ||
fp.write(b'%s\r\n' % s.encode('utf-8')) | ||
|
||
|
||
def newline(fp): | ||
fp.write(b'\r\n') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters