Skip to content

Commit 14e2987

Browse files
committed
imgtool: Add big-endian sign and verify tests
Add sign and verify tests for testing endianness support. Signed-off-by: Rustam Ismayilov <[email protected]> Change-Id: I3ab85ba137164cebcb9f38f45c93d87b96afbe68
1 parent 653be2e commit 14e2987

File tree

1 file changed

+78
-2
lines changed

1 file changed

+78
-2
lines changed

scripts/tests/test_sign.py

Lines changed: 78 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def test_sign_overwrite_only(self, tmp_path_persistent):
434434

435435
@pytest.mark.parametrize("endian", ("little", "big"))
436436
def test_sign_endian(self, tmp_path_persistent, endian):
437-
"""Test sign endian"""
437+
"""Test signing image with endian option"""
438438

439439
result = self.runner.invoke(
440440
imgtool,
@@ -455,7 +455,7 @@ def test_sign_endian(self, tmp_path_persistent, endian):
455455
str(self.image_signed),
456456
],
457457
)
458-
assert_image_signed(result, self.image_signed, verify=False)
458+
assert_image_signed(result, self.image_signed)
459459

460460
def test_sign_rom_fixed(self, tmp_path_persistent):
461461
"""Test sign with rom fixed"""
@@ -738,6 +738,43 @@ def test_sign_load_addr_rom_fixed(self, key_type, tmp_path_persistent):
738738
assert result.exit_code != 0
739739
assert "Can not set rom_fixed and load_addr at the same time" in result.output
740740

741+
@pytest.mark.parametrize("endian", ("little", "big"))
742+
@pytest.mark.parametrize("key_type", KEY_TYPES)
743+
def test_sign_endian_key(self, tmp_path_persistent, endian, key_type):
744+
"""Test signing image with endian and key option"""
745+
key = tmp_name(tmp_path_persistent, key_type, GEN_KEY_EXT)
746+
# Enable for preserving outputs:
747+
# self.image_signed = signed_images_dir + "/endian/" + key_type + "_" + endian + ".signed"
748+
749+
result = self.runner.invoke(
750+
imgtool,
751+
[
752+
"sign",
753+
"--key",
754+
key,
755+
"--align",
756+
"16",
757+
"--version",
758+
"1.0.0",
759+
"--header-size",
760+
"0x20",
761+
"--slot-size",
762+
"0x2500",
763+
"--pad-header",
764+
"--endian",
765+
endian,
766+
str(self.image),
767+
str(self.image_signed),
768+
],
769+
)
770+
assert result.exit_code == 0
771+
772+
runner = CliRunner()
773+
result = runner.invoke(
774+
imgtool, ["verify", "--key", key, str(self.image_signed), ],
775+
)
776+
assert result.exit_code == 0
777+
741778
@pytest.mark.parametrize("key_type", KEY_TYPES)
742779
def test_sign_custom_tlv(self, tmp_path_persistent, key_type):
743780
"""Test signing with custom TLV"""
@@ -930,6 +967,45 @@ def test_sign_custom_tlv(self, tmp_path_persistent, key_type):
930967
assert result.exit_code != 0
931968
assert "Invalid custom TLV type value" in result.stdout
932969

970+
@pytest.mark.parametrize("endian", ("little", "big"))
971+
@pytest.mark.parametrize("key_type", KEY_TYPES)
972+
def test_sign_custom_tlv_endian(self, tmp_path_persistent, key_type, endian):
973+
key = keys_dir + key_type + ".key"
974+
# Enable for preserving outputs:
975+
# self.image_signed = signed_images_dir + "/endian/" + key_type + "_" + endian + "_custom.signed"
976+
977+
result = self.runner.invoke(
978+
imgtool,
979+
[
980+
"sign",
981+
"--key",
982+
key,
983+
"--align",
984+
"16",
985+
"--version",
986+
"1.0.0",
987+
"--header-size",
988+
"0x20",
989+
"--slot-size",
990+
"0x2500",
991+
"--pad-header",
992+
"--endian",
993+
endian,
994+
"--custom-tlv",
995+
"0x00a0",
996+
"0x00ffddee",
997+
str(self.image),
998+
str(self.image_signed),
999+
],
1000+
)
1001+
assert result.exit_code == 0
1002+
1003+
runner = CliRunner()
1004+
result = runner.invoke(
1005+
imgtool, ["verify", "--key", key, str(self.image_signed), ],
1006+
)
1007+
assert result.exit_code == 0
1008+
9331009
@pytest.mark.parametrize("key_type", KEY_TYPES)
9341010
def test_sign_pad_sig(self, tmp_path_persistent, key_type):
9351011
"""Test pad signature"""

0 commit comments

Comments
 (0)