test_idf_tools.py 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. #!/usr/bin/env python
  2. #
  3. # SPDX-FileCopyrightText: 2019-2021 Espressif Systems (Shanghai) CO LTD
  4. # SPDX-License-Identifier: Apache-2.0
  5. import json
  6. import os
  7. import re
  8. import shutil
  9. import sys
  10. import tempfile
  11. import unittest
  12. try:
  13. from contextlib import redirect_stdout
  14. except ImportError:
  15. import contextlib
  16. @contextlib.contextmanager # type: ignore
  17. def redirect_stdout(target):
  18. original = sys.stdout
  19. sys.stdout = target
  20. yield
  21. sys.stdout = original
  22. try:
  23. from cStringIO import StringIO
  24. except ImportError:
  25. from io import StringIO
  26. # Need to do this before importing idf_tools.py
  27. os.environ['IDF_MAINTAINER'] = '1'
  28. try:
  29. import idf_tools
  30. except ImportError:
  31. sys.path.append('..')
  32. import idf_tools
  33. ESP32ULP = 'esp32ulp-elf'
  34. ESP32ULP_ARCHIVE = 'binutils-esp32ulp'
  35. ESP32S2ULP = 'esp32s2ulp-elf'
  36. ESP32S2ULP_ARCHIVE = 'binutils-esp32s2ulp'
  37. OPENOCD = 'openocd-esp32'
  38. RISCV_ELF = 'riscv32-esp-elf'
  39. XTENSA_ESP32_ELF = 'xtensa-esp32-elf'
  40. XTENSA_ESP32S2_ELF = 'xtensa-esp32s2-elf'
  41. XTENSA_ESP32S3_ELF = 'xtensa-esp32s3-elf'
  42. def get_version_dict():
  43. '''
  44. Return a dictionary with tool name to tool version mapping.
  45. It works with tools.json directly and not through idf_tools.py in order to bypass the script under test. This is
  46. a little hacky but thanks to this, versions are not required to be updated here every time a tool is updated.
  47. '''
  48. with open(os.path.join(os.path.dirname(os.path.abspath(__file__)), '..', 'tools.json')) as f:
  49. tools_obj = json.loads(f.read())
  50. return dict((tool['name'], tool['versions'][0]['name']) for tool in tools_obj['tools'])
  51. version_dict = get_version_dict()
  52. ESP32ULP_VERSION = version_dict[ESP32ULP]
  53. ESP32S2ULP_VERSION = version_dict[ESP32S2ULP]
  54. OPENOCD_VERSION = version_dict[OPENOCD]
  55. RISCV_ELF_VERSION = version_dict[RISCV_ELF]
  56. XTENSA_ESP32_ELF_VERSION = version_dict[XTENSA_ESP32_ELF]
  57. XTENSA_ESP32S2_ELF_VERSION = version_dict[XTENSA_ESP32S2_ELF]
  58. XTENSA_ESP32S3_ELF_VERSION = version_dict[XTENSA_ESP32S3_ELF]
  59. class TestUsage(unittest.TestCase):
  60. @classmethod
  61. def setUpClass(cls):
  62. old_tools_dir = os.environ.get('IDF_TOOLS_PATH') or os.path.expanduser(idf_tools.IDF_TOOLS_PATH_DEFAULT)
  63. mirror_prefix_map = None
  64. if os.path.exists(old_tools_dir):
  65. mirror_prefix_map = 'https://dl.espressif.com/dl/toolchains/preview,file://' + os.path.join(old_tools_dir,
  66. 'dist')
  67. mirror_prefix_map += ';https://dl.espressif.com/dl,file://' + os.path.join(old_tools_dir, 'dist')
  68. mirror_prefix_map += ';https://github.com/espressif/.*/releases/download/.*/,file://' + os.path.join(
  69. old_tools_dir, 'dist', '')
  70. if mirror_prefix_map:
  71. print('Using IDF_MIRROR_PREFIX_MAP={}'.format(mirror_prefix_map))
  72. os.environ['IDF_MIRROR_PREFIX_MAP'] = mirror_prefix_map
  73. cls.temp_tools_dir = tempfile.mkdtemp(prefix='idf_tools_tmp')
  74. print('Using IDF_TOOLS_PATH={}'.format(cls.temp_tools_dir))
  75. os.environ['IDF_TOOLS_PATH'] = cls.temp_tools_dir
  76. cls.idf_env_json = os.path.join(cls.temp_tools_dir, 'idf-env.json')
  77. @classmethod
  78. def tearDownClass(cls):
  79. shutil.rmtree(cls.temp_tools_dir)
  80. def tearDown(self):
  81. if os.path.isdir(os.path.join(self.temp_tools_dir, 'dist')):
  82. shutil.rmtree(os.path.join(self.temp_tools_dir, 'dist'))
  83. if os.path.isdir(os.path.join(self.temp_tools_dir, 'tools')):
  84. shutil.rmtree(os.path.join(self.temp_tools_dir, 'tools'))
  85. if os.path.isfile(self.idf_env_json):
  86. os.remove(self.idf_env_json)
  87. def assert_tool_installed(self, output, tool, tool_version, tool_archive_name=None):
  88. if tool_archive_name is None:
  89. tool_archive_name = tool
  90. self.assertIn('Installing %s@' % tool + tool_version, output)
  91. self.assertRegex(output, re.compile(rf'Downloading \S+/{tool_archive_name}'))
  92. def assert_tool_not_installed(self, output, tool, tool_version, tool_archive_name=None):
  93. if tool_archive_name is None:
  94. tool_archive_name = tool
  95. self.assertNotIn('Installing %s@' % tool + tool_version, output)
  96. self.assertNotRegex(output, re.compile(rf'Downloading \S+/{tool_archive_name}'))
  97. def run_idf_tools_with_action(self, action):
  98. output_stream = StringIO()
  99. with redirect_stdout(output_stream):
  100. idf_tools.main(['--non-interactive'] + action)
  101. output = output_stream.getvalue()
  102. return output
  103. def test_usage_basic(self):
  104. output = self.run_idf_tools_with_action(['list'])
  105. self.assertIn('* %s:' % ESP32ULP, output)
  106. self.assertIn('- %s (recommended)' % ESP32ULP_VERSION, output)
  107. self.assertIn('* %s:' % ESP32S2ULP, output)
  108. self.assertIn('- %s (recommended)' % ESP32S2ULP_VERSION, output)
  109. self.assertIn('* %s:' % OPENOCD, output)
  110. self.assertIn('- %s (recommended)' % OPENOCD_VERSION, output)
  111. self.assertIn('* %s:' % RISCV_ELF, output)
  112. self.assertIn('- %s (recommended)' % RISCV_ELF_VERSION, output)
  113. self.assertIn('* %s:' % XTENSA_ESP32_ELF, output)
  114. self.assertIn('- %s (recommended)' % XTENSA_ESP32_ELF_VERSION, output)
  115. self.assertIn('* %s:' % XTENSA_ESP32S2_ELF, output)
  116. self.assertIn('- %s (recommended)' % XTENSA_ESP32S2_ELF_VERSION, output)
  117. self.assertIn('* %s:' % XTENSA_ESP32S3_ELF, output)
  118. self.assertIn('- %s (recommended)' % XTENSA_ESP32S3_ELF_VERSION, output)
  119. required_tools_installed = 7
  120. output = self.run_idf_tools_with_action(['install'])
  121. self.assert_tool_installed(output, OPENOCD, OPENOCD_VERSION)
  122. self.assert_tool_installed(output, RISCV_ELF, RISCV_ELF_VERSION)
  123. self.assert_tool_installed(output, XTENSA_ESP32_ELF, XTENSA_ESP32_ELF_VERSION)
  124. self.assert_tool_installed(output, XTENSA_ESP32S2_ELF, XTENSA_ESP32S2_ELF_VERSION)
  125. self.assert_tool_installed(output, XTENSA_ESP32S3_ELF, XTENSA_ESP32S3_ELF_VERSION)
  126. self.assert_tool_installed(output, ESP32ULP, ESP32ULP_VERSION, ESP32ULP_ARCHIVE)
  127. self.assert_tool_installed(output, ESP32S2ULP, ESP32S2ULP_VERSION, ESP32S2ULP_ARCHIVE)
  128. self.assertIn('Destination: {}'.format(os.path.join(self.temp_tools_dir, 'dist')), output)
  129. self.assertEqual(required_tools_installed, output.count('Done'))
  130. output = self.run_idf_tools_with_action(['check'])
  131. self.assertIn('version installed in tools directory: ' + ESP32ULP_VERSION, output)
  132. self.assertIn('version installed in tools directory: ' + ESP32S2ULP_VERSION, output)
  133. self.assertIn('version installed in tools directory: ' + OPENOCD_VERSION, output)
  134. self.assertIn('version installed in tools directory: ' + RISCV_ELF_VERSION, output)
  135. self.assertIn('version installed in tools directory: ' + XTENSA_ESP32_ELF_VERSION, output)
  136. self.assertIn('version installed in tools directory: ' + XTENSA_ESP32S2_ELF_VERSION, output)
  137. self.assertIn('version installed in tools directory: ' + XTENSA_ESP32S3_ELF_VERSION, output)
  138. output = self.run_idf_tools_with_action(['export'])
  139. self.assertIn('%s/tools/esp32ulp-elf/%s/esp32ulp-elf-binutils/bin' %
  140. (self.temp_tools_dir, ESP32ULP_VERSION), output)
  141. self.assertIn('%s/tools/xtensa-esp32-elf/%s/xtensa-esp32-elf/bin' %
  142. (self.temp_tools_dir, XTENSA_ESP32_ELF_VERSION), output)
  143. self.assertIn('%s/tools/openocd-esp32/%s/openocd-esp32/bin' %
  144. (self.temp_tools_dir, OPENOCD_VERSION), output)
  145. self.assertIn('%s/tools/riscv32-esp-elf/%s/riscv32-esp-elf/bin' %
  146. (self.temp_tools_dir, RISCV_ELF_VERSION), output)
  147. self.assertIn('%s/tools/esp32s2ulp-elf/%s/esp32s2ulp-elf-binutils/bin' %
  148. (self.temp_tools_dir, ESP32S2ULP_VERSION), output)
  149. self.assertIn('%s/tools/xtensa-esp32s2-elf/%s/xtensa-esp32s2-elf/bin' %
  150. (self.temp_tools_dir, XTENSA_ESP32S2_ELF_VERSION), output)
  151. self.assertIn('%s/tools/xtensa-esp32s3-elf/%s/xtensa-esp32s3-elf/bin' %
  152. (self.temp_tools_dir, XTENSA_ESP32S3_ELF_VERSION), output)
  153. def test_tools_for_esp32(self):
  154. required_tools_installed = 3
  155. output = self.run_idf_tools_with_action(['install', '--targets=esp32'])
  156. self.assert_tool_installed(output, XTENSA_ESP32_ELF, XTENSA_ESP32_ELF_VERSION)
  157. self.assert_tool_installed(output, OPENOCD, OPENOCD_VERSION)
  158. self.assert_tool_installed(output, ESP32ULP, ESP32ULP_VERSION, ESP32ULP_ARCHIVE)
  159. self.assert_tool_not_installed(output, RISCV_ELF, RISCV_ELF_VERSION)
  160. self.assert_tool_not_installed(output, XTENSA_ESP32S2_ELF, XTENSA_ESP32S2_ELF_VERSION)
  161. self.assert_tool_not_installed(output, XTENSA_ESP32S3_ELF, XTENSA_ESP32S3_ELF_VERSION)
  162. self.assert_tool_not_installed(output, ESP32S2ULP, ESP32S2ULP_VERSION, ESP32S2ULP_ARCHIVE)
  163. self.assertIn('Destination: {}'.format(os.path.join(self.temp_tools_dir, 'dist')), output)
  164. self.assertEqual(required_tools_installed, output.count('Done'))
  165. output = self.run_idf_tools_with_action(['check'])
  166. self.assertIn('version installed in tools directory: ' + ESP32ULP_VERSION, output)
  167. self.assertIn('version installed in tools directory: ' + XTENSA_ESP32_ELF_VERSION, output)
  168. self.assertIn('version installed in tools directory: ' + OPENOCD_VERSION, output)
  169. output = self.run_idf_tools_with_action(['export'])
  170. self.assertIn('%s/tools/esp32ulp-elf/%s/esp32ulp-elf-binutils/bin' %
  171. (self.temp_tools_dir, ESP32ULP_VERSION), output)
  172. self.assertIn('%s/tools/xtensa-esp32-elf/%s/xtensa-esp32-elf/bin' %
  173. (self.temp_tools_dir, XTENSA_ESP32_ELF_VERSION), output)
  174. self.assertIn('%s/tools/openocd-esp32/%s/openocd-esp32/bin' %
  175. (self.temp_tools_dir, OPENOCD_VERSION), output)
  176. self.assertNotIn('%s/tools/riscv32-esp-elf/%s/riscv32-esp-elf/bin' %
  177. (self.temp_tools_dir, RISCV_ELF_VERSION), output)
  178. self.assertNotIn('%s/tools/esp32s2ulp-elf/%s/esp32s2ulp-elf-binutils/bin' %
  179. (self.temp_tools_dir, ESP32S2ULP_VERSION), output)
  180. self.assertNotIn('%s/tools/xtensa-esp32s2-elf/%s/xtensa-esp32s2-elf/bin' %
  181. (self.temp_tools_dir, XTENSA_ESP32S2_ELF_VERSION), output)
  182. self.assertNotIn('%s/tools/xtensa-esp32s3-elf/%s/xtensa-esp32s3-elf/bin' %
  183. (self.temp_tools_dir, XTENSA_ESP32S3_ELF_VERSION), output)
  184. def test_tools_for_esp32c3(self):
  185. required_tools_installed = 2
  186. output = self.run_idf_tools_with_action(['install', '--targets=esp32c3'])
  187. self.assert_tool_installed(output, OPENOCD, OPENOCD_VERSION)
  188. self.assert_tool_installed(output, RISCV_ELF, RISCV_ELF_VERSION)
  189. self.assert_tool_not_installed(output, XTENSA_ESP32_ELF, XTENSA_ESP32_ELF_VERSION)
  190. self.assert_tool_not_installed(output, XTENSA_ESP32S2_ELF, XTENSA_ESP32S2_ELF_VERSION)
  191. self.assert_tool_not_installed(output, XTENSA_ESP32S3_ELF, XTENSA_ESP32S3_ELF_VERSION)
  192. self.assert_tool_not_installed(output, ESP32ULP, ESP32ULP_VERSION, ESP32ULP_ARCHIVE)
  193. self.assert_tool_not_installed(output, ESP32S2ULP, ESP32S2ULP_VERSION, ESP32S2ULP_ARCHIVE)
  194. self.assertIn('Destination: {}'.format(os.path.join(self.temp_tools_dir, 'dist')), output)
  195. self.assertEqual(required_tools_installed, output.count('Done'))
  196. output = self.run_idf_tools_with_action(['check'])
  197. self.assertIn('version installed in tools directory: ' + OPENOCD_VERSION, output)
  198. self.assertIn('version installed in tools directory: ' + RISCV_ELF_VERSION, output)
  199. output = self.run_idf_tools_with_action(['export'])
  200. self.assertIn('%s/tools/openocd-esp32/%s/openocd-esp32/bin' %
  201. (self.temp_tools_dir, OPENOCD_VERSION), output)
  202. self.assertIn('%s/tools/riscv32-esp-elf/%s/riscv32-esp-elf/bin' %
  203. (self.temp_tools_dir, RISCV_ELF_VERSION), output)
  204. self.assertNotIn('%s/tools/esp32ulp-elf/%s/esp32ulp-elf-binutils/bin' %
  205. (self.temp_tools_dir, ESP32ULP_VERSION), output)
  206. self.assertNotIn('%s/tools/xtensa-esp32-elf/%s/xtensa-esp32-elf/bin' %
  207. (self.temp_tools_dir, XTENSA_ESP32_ELF_VERSION), output)
  208. self.assertNotIn('%s/tools/esp32s2ulp-elf/%s/esp32s2ulp-elf-binutils/bin' %
  209. (self.temp_tools_dir, ESP32S2ULP_VERSION), output)
  210. self.assertNotIn('%s/tools/xtensa-esp32s2-elf/%s/xtensa-esp32s2-elf/bin' %
  211. (self.temp_tools_dir, XTENSA_ESP32S2_ELF_VERSION), output)
  212. self.assertNotIn('%s/tools/xtensa-esp32s3-elf/%s/xtensa-esp32s3-elf/bin' %
  213. (self.temp_tools_dir, XTENSA_ESP32S3_ELF_VERSION), output)
  214. def test_tools_for_esp32s2(self):
  215. required_tools_installed = 4
  216. output = self.run_idf_tools_with_action(['install', '--targets=esp32s2'])
  217. self.assert_tool_installed(output, XTENSA_ESP32S2_ELF, XTENSA_ESP32S2_ELF_VERSION)
  218. self.assert_tool_installed(output, OPENOCD, OPENOCD_VERSION)
  219. self.assert_tool_installed(output, RISCV_ELF, RISCV_ELF_VERSION)
  220. self.assert_tool_not_installed(output, XTENSA_ESP32_ELF, XTENSA_ESP32_ELF_VERSION)
  221. self.assert_tool_not_installed(output, XTENSA_ESP32S3_ELF, XTENSA_ESP32S3_ELF_VERSION)
  222. self.assert_tool_not_installed(output, ESP32ULP, ESP32ULP_VERSION, ESP32ULP_ARCHIVE)
  223. self.assert_tool_installed(output, ESP32S2ULP, ESP32S2ULP_VERSION, ESP32S2ULP_ARCHIVE)
  224. self.assertIn('Destination: {}'.format(os.path.join(self.temp_tools_dir, 'dist')), output)
  225. self.assertEqual(required_tools_installed, output.count('Done'))
  226. output = self.run_idf_tools_with_action(['check'])
  227. self.assertIn('version installed in tools directory: ' + ESP32S2ULP_VERSION, output)
  228. self.assertIn('version installed in tools directory: ' + OPENOCD_VERSION, output)
  229. self.assertIn('version installed in tools directory: ' + XTENSA_ESP32S2_ELF_VERSION, output)
  230. output = self.run_idf_tools_with_action(['export'])
  231. self.assertIn('%s/tools/esp32s2ulp-elf/%s/esp32s2ulp-elf-binutils/bin' %
  232. (self.temp_tools_dir, ESP32S2ULP_VERSION), output)
  233. self.assertIn('%s/tools/xtensa-esp32s2-elf/%s/xtensa-esp32s2-elf/bin' %
  234. (self.temp_tools_dir, XTENSA_ESP32S2_ELF_VERSION), output)
  235. self.assertIn('%s/tools/openocd-esp32/%s/openocd-esp32/bin' %
  236. (self.temp_tools_dir, OPENOCD_VERSION), output)
  237. self.assertNotIn('%s/tools/esp32ulp-elf/%s/esp32ulp-elf-binutils/bin' %
  238. (self.temp_tools_dir, ESP32ULP_VERSION), output)
  239. self.assertNotIn('%s/tools/xtensa-esp32-elf/%s/xtensa-esp32-elf/bin' %
  240. (self.temp_tools_dir, XTENSA_ESP32_ELF_VERSION), output)
  241. self.assertIn('%s/tools/riscv32-esp-elf/%s/riscv32-esp-elf/bin' %
  242. (self.temp_tools_dir, RISCV_ELF_VERSION), output)
  243. self.assertNotIn('%s/tools/xtensa-esp32s3-elf/%s/xtensa-esp32s3-elf/bin' %
  244. (self.temp_tools_dir, XTENSA_ESP32S3_ELF_VERSION), output)
  245. def test_tools_for_esp32s3(self):
  246. required_tools_installed = 4
  247. output = self.run_idf_tools_with_action(['install', '--targets=esp32s3'])
  248. self.assert_tool_installed(output, XTENSA_ESP32S3_ELF, XTENSA_ESP32S3_ELF_VERSION)
  249. self.assert_tool_installed(output, OPENOCD, OPENOCD_VERSION)
  250. self.assert_tool_installed(output, RISCV_ELF, RISCV_ELF_VERSION)
  251. self.assert_tool_not_installed(output, XTENSA_ESP32_ELF, XTENSA_ESP32_ELF_VERSION)
  252. self.assert_tool_not_installed(output, XTENSA_ESP32S2_ELF, XTENSA_ESP32S2_ELF_VERSION)
  253. self.assert_tool_not_installed(output, ESP32ULP, ESP32ULP_VERSION, ESP32ULP_ARCHIVE)
  254. self.assert_tool_installed(output, ESP32S2ULP, ESP32S2ULP_VERSION, ESP32S2ULP_ARCHIVE)
  255. self.assertIn('Destination: {}'.format(os.path.join(self.temp_tools_dir, 'dist')), output)
  256. self.assertEqual(required_tools_installed, output.count('Done'))
  257. output = self.run_idf_tools_with_action(['check'])
  258. self.assertIn('version installed in tools directory: ' + OPENOCD_VERSION, output)
  259. self.assertIn('version installed in tools directory: ' + XTENSA_ESP32S3_ELF_VERSION, output)
  260. output = self.run_idf_tools_with_action(['export'])
  261. self.assertIn('%s/tools/openocd-esp32/%s/openocd-esp32/bin' %
  262. (self.temp_tools_dir, OPENOCD_VERSION), output)
  263. self.assertIn('%s/tools/xtensa-esp32s3-elf/%s/xtensa-esp32s3-elf/bin' %
  264. (self.temp_tools_dir, XTENSA_ESP32S3_ELF_VERSION), output)
  265. self.assertNotIn('%s/tools/esp32ulp-elf/%s/esp32ulp-elf-binutils/bin' %
  266. (self.temp_tools_dir, ESP32ULP_VERSION), output)
  267. self.assertNotIn('%s/tools/xtensa-esp32-elf/%s/xtensa-esp32-elf/bin' %
  268. (self.temp_tools_dir, XTENSA_ESP32_ELF_VERSION), output)
  269. self.assertIn('%s/tools/riscv32-esp-elf/%s/riscv32-esp-elf/bin' %
  270. (self.temp_tools_dir, RISCV_ELF_VERSION), output)
  271. self.assertIn('%s/tools/esp32s2ulp-elf/%s/esp32s2ulp-elf-binutils/bin' %
  272. (self.temp_tools_dir, ESP32S2ULP_VERSION), output)
  273. self.assertNotIn('%s/tools/xtensa-esp32s2-elf/%s/xtensa-esp32s2-elf/bin' %
  274. (self.temp_tools_dir, XTENSA_ESP32S2_ELF_VERSION), output)
  275. def test_uninstall_option(self):
  276. self.run_idf_tools_with_action(['install', '--targets=esp32,esp32c3'])
  277. output = self.run_idf_tools_with_action(['uninstall', '--dry-run'])
  278. self.assertEqual(output, '')
  279. with open(self.idf_env_json, 'r') as idf_env_file:
  280. idf_env_json = json.load(idf_env_file)
  281. idf_env_json['idfInstalled'][idf_env_json['idfSelectedId']]['targets'].remove('esp32')
  282. with open(self.idf_env_json, 'w') as w:
  283. json.dump(idf_env_json, w)
  284. output = self.run_idf_tools_with_action(['uninstall'])
  285. self.assertIn(XTENSA_ESP32_ELF, output)
  286. self.assertIn(ESP32ULP, output)
  287. output = self.run_idf_tools_with_action(['uninstall', '--dry-run'])
  288. self.assertEqual(output, '')
  289. def test_unset(self):
  290. self.run_idf_tools_with_action(['install'])
  291. self.run_idf_tools_with_action(['export'])
  292. self.assertTrue(os.path.isfile(self.idf_env_json), 'File {} was not found. '.format(self.idf_env_json))
  293. self.assertNotEqual(os.stat(self.idf_env_json).st_size, 0, 'File {} is empty. '.format(self.idf_env_json))
  294. with open(self.idf_env_json, 'r') as idf_env_file:
  295. idf_env_json = json.load(idf_env_file)
  296. selected_idf = idf_env_json['idfSelectedId']
  297. self.assertIn('unset', idf_env_json['idfInstalled'][selected_idf],
  298. 'Unset was not created for active environment in {}.'.format(self.idf_env_json))
  299. class TestMaintainer(unittest.TestCase):
  300. def test_validation(self):
  301. idf_tools.main(['validate'])
  302. def test_json_rewrite(self):
  303. idf_tools.main(['rewrite'])
  304. idf_path = os.getenv('IDF_PATH')
  305. if not idf_path:
  306. self.fail('IDF_PATH needs to be set to run this test')
  307. with open(os.path.join(idf_path, 'tools/tools.json'), 'r') as f:
  308. json_old = f.read()
  309. with open(os.path.join(idf_path, 'tools/tools.new.json'), 'r') as f:
  310. json_new = f.read()
  311. self.assertEqual(json_old, json_new, "Please check 'tools/tools.new.json' to find a cause!")
  312. if __name__ == '__main__':
  313. unittest.main()