'Assert an esptool binary image object contains
the data for a particular ELF section.'

def assertImageContainsSection(self, image, elf, section_name):

    with open(elf, 'rb') as f:
        e = ELFFile(f)
        section = e.get_section_by_name(section_name)
        self.assertTrue(section, ('%s    should    be    in    the    ELF' % section_name))
        sh_addr = section.header.sh_addr
        data = section.data()
        for seg in sorted(image.segments, key=(lambda s: s.addr)):
            print ('comparing    seg    0x%x    sec    0x%x    len    0x%x' % (seg.addr, sh_addr, len(data)))
            if (seg.addr == sh_addr):
                overlap_len = min(len(seg.data), len(data))
                self.assertEqual(data[:overlap_len], seg.data[:overlap_len], ("ELF    '%s'    section    has    mis-matching    binary    image    data" % section_name))
                sh_addr += overlap_len
                data = data[overlap_len:]
        self.assertEqual(0, len(data), ("ELF    %s    section    '%s'    has    no    encompassing    segment(s)    in    binary    image    (image    segments:    %s)" % (elf, section_name, image.segments)))
