@@ -0,0 +1,3059 @@
+#!/usr/bin/python%0A# Copyright 2016 Mender Software AS%0A#%0A#    Licensed under the Apache License, Version 2.0 (the %22License%22);%0A#    you may not use this file except in compliance with the License.%0A#    You may obtain a copy of the License at%0A#%0A#        http://www.apache.org/licenses/LICENSE-2.0%0A#%0A#    Unless required by applicable law or agreed to in writing, software%0A#    distributed under the License is distributed on an %22AS IS%22 BASIS,%0A#    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A#    See the License for the specific language governing permissions and%0A#    limitations under the License.%0A%0Afrom fabric.api import *%0A%0Aimport pytest%0Aimport subprocess%0Aimport os%0A%0A# Make sure common is imported after fabric, because we override some functions.%0Afrom common import *%0A%0Aclass EmbeddedBootloader:%0A    loader = None%0A    offset = 0%0A%0A    def __init__(self, loader, offset):%0A        self.loader = loader%0A        self.offset = offset%0A%0A@pytest.fixture(scope=%22session%22)%0Adef embedded_bootloader():%0A    assert(os.environ.get('BUILDDIR', False), %22BUILDDIR must be set%22)%0A%0A    current_dir = os.open(%22.%22, os.O_RDONLY)%0A    os.chdir(os.environ%5B'BUILDDIR'%5D)%0A%0A    output = subprocess.Popen(%5B%22bitbake%22, %22-e%22, %22core-image-minimal%22%5D, stdout=subprocess.PIPE)%0A    loader_base = None%0A    loader_dir = None%0A    loader = None%0A    offset = 0%0A    for line in output.stdout:%0A        line = line.strip()%0A        if line.startswith('IMAGE_BOOTLOADER_FILE=%22') and line.endswith('%22'):%0A            loader_base = line.split('=', 2)%5B1%5D%5B1:-1%5D%0A        elif line.startswith('IMAGE_BOOTLOADER_BOOTSECTOR_OFFSET=%22') and line.endswith('%22'):%0A            offset = int(line.split('=', 2)%5B1%5D%5B1:-1%5D) * 512%0A        elif line.startswith('DEPLOY_DIR_IMAGE=%22') and line.endswith('%22'):%0A            loader_dir = line.split('=', 2)%5B1%5D%5B1:-1%5D%0A%0A    if loader_base is not None and loader_base != %22%22:%0A        loader = os.path.join(loader_dir, loader_base)%0A%0A    output.wait()%0A    os.fchdir(current_dir)%0A%0A    return EmbeddedBootloader(loader, offset)%0A%0Aclass TestSdimg:%0A    def test_bootloader_embed(self, embedded_bootloader, latest_sdimg):%0A        %22%22%22Test that IMAGE_BOOTLOADER_FILE causes the bootloader to be embedded%0A        correctly in the resulting sdimg. If the variable has not been defined,%0A        the test is skipped.%22%22%22%0A%0A        if embedded_bootloader.loader is None:%0A            pytest.skip(%22No embedded bootloader specified%22)%0A%0A        original = os.open(embedded_bootloader.loader, os.O_RDONLY)%0A        embedded = os.open(latest_sdimg, os.O_RDONLY)%0A        os.lseek(embedded, embedded_bootloader.offset, 0)%0A%0A        checked = 0%0A        block_size = 4096%0A        while True:%0A            org_read = os.read(original, block_size)%0A            org_read_size = len(org_read)%0A            emb_read = os.read(embedded, org_read_size)%0A%0A            assert(org_read == emb_read), %22Embedded bootloader is not identical to the file specified in IMAGE_BOOTLOADER_FILE%22%0A%0A            if org_read_size %3C block_size:%0A                break%0A%0A        os.close(original)%0A        os.close(embedded)%0A

Add test for IMAGE_BOOTLOADER_FILE bitbake option.