2019-01-09 07:06:01 -05:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
2021-01-25 21:49:01 -05:00
|
|
|
from __future__ import division, print_function, unicode_literals
|
|
|
|
|
2019-01-09 07:06:01 -05:00
|
|
|
import hashlib
|
2021-01-25 21:49:01 -05:00
|
|
|
import os
|
|
|
|
import re
|
2019-01-09 07:06:01 -05:00
|
|
|
|
2019-11-26 22:58:07 -05:00
|
|
|
import ttfw_idf
|
2021-01-25 21:49:01 -05:00
|
|
|
from tiny_test_fw import Utility
|
2019-01-09 07:06:01 -05:00
|
|
|
|
|
|
|
|
|
|
|
def verify_elf_sha256_embedding(dut):
|
2021-01-25 21:49:01 -05:00
|
|
|
elf_file = os.path.join(dut.app.binary_path, 'blink.elf')
|
2019-01-09 07:06:01 -05:00
|
|
|
sha256 = hashlib.sha256()
|
2021-01-25 21:49:01 -05:00
|
|
|
with open(elf_file, 'rb') as f:
|
2019-01-09 07:06:01 -05:00
|
|
|
sha256.update(f.read())
|
|
|
|
sha256_expected = sha256.hexdigest()
|
|
|
|
|
|
|
|
dut.reset()
|
|
|
|
sha256_reported = dut.expect(re.compile(r'ELF file SHA256:\s+([a-f0-9]+)'), timeout=5)[0]
|
|
|
|
|
|
|
|
Utility.console_log('ELF file SHA256: %s' % sha256_expected)
|
|
|
|
Utility.console_log('ELF file SHA256 (reported by the app): %s' % sha256_reported)
|
|
|
|
# the app reports only the first several hex characters of the SHA256, check that they match
|
|
|
|
if not sha256_expected.startswith(sha256_reported):
|
|
|
|
raise ValueError('ELF file SHA256 mismatch')
|
|
|
|
|
|
|
|
|
2021-03-12 01:05:17 -05:00
|
|
|
@ttfw_idf.idf_example_test(env_tag='Example_GENERIC', target=['esp32', 'esp32c3'])
|
2019-01-09 07:06:01 -05:00
|
|
|
def test_examples_blink(env, extra_data):
|
2021-03-12 01:05:17 -05:00
|
|
|
dut = env.get_dut('blink', 'examples/get-started/blink')
|
2021-01-25 21:49:01 -05:00
|
|
|
binary_file = os.path.join(dut.app.binary_path, 'blink.bin')
|
2019-01-09 07:06:01 -05:00
|
|
|
bin_size = os.path.getsize(binary_file)
|
2021-01-25 21:49:01 -05:00
|
|
|
ttfw_idf.log_performance('blink_bin_size', '{}KB'.format(bin_size // 1024))
|
2019-01-09 07:06:01 -05:00
|
|
|
|
|
|
|
dut.start_app()
|
|
|
|
|
|
|
|
verify_elf_sha256_embedding(dut)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
test_examples_blink()
|