fix(idf_tools): Fix platform detection for arm64 machine but arm32 environment

This commit is contained in:
Anton Maklakov
2023-12-18 20:01:27 +07:00
parent da9536dbab
commit 04b77f56f5
5 changed files with 65 additions and 17 deletions

View File

@@ -2,7 +2,6 @@
#
# SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
# SPDX-License-Identifier: Apache-2.0
import json
import os
import re
@@ -10,6 +9,7 @@ import shutil
import sys
import tempfile
import unittest
from unittest.mock import patch
try:
from contextlib import redirect_stdout
@@ -606,5 +606,30 @@ class TestMaintainer(unittest.TestCase):
self.assertEqual(json.load(f1), expected_json, "Please check 'tools/tools.new.json' to find a cause!")
class TestArmDetection(unittest.TestCase):
ELF_HEADERS = {
idf_tools.PLATFORM_LINUX_ARM64: 'platform_detection/arm64_header.elf',
idf_tools.PLATFORM_LINUX_ARMHF: 'platform_detection/armhf_header.elf',
idf_tools.PLATFORM_LINUX_ARM32: 'platform_detection/arm32_header.elf',
}
ARM_PLATFORMS = {
idf_tools.PLATFORM_LINUX_ARM64,
idf_tools.PLATFORM_LINUX_ARMHF,
idf_tools.PLATFORM_LINUX_ARM32,
}
def test_arm_detection(self):
for platform in idf_tools.Platforms.PLATFORM_FROM_NAME.values():
with patch('sys.executable', __file__): # use invalid ELF as executable. In this case passed parameter must return
self.assertEqual(idf_tools.Platforms.detect_linux_arm_platform(platform), platform)
# detect_linux_arm_platform() intended to return arch that detected in sys.executable ELF
for exec_platform in (idf_tools.PLATFORM_LINUX_ARM64, idf_tools.PLATFORM_LINUX_ARMHF, idf_tools.PLATFORM_LINUX_ARM32):
with patch('sys.executable', TestArmDetection.ELF_HEADERS[exec_platform]):
for platform in TestArmDetection.ARM_PLATFORMS:
self.assertEqual(idf_tools.Platforms.detect_linux_arm_platform(platform), exec_platform)
if __name__ == '__main__':
unittest.main()