Commit 57c40f71 authored by Fabio Utzig's avatar Fabio Utzig Committed by David Brown
Browse files

Fix assert abstraction in sim

Assertions that are expected to fail under sim test, are now marked as such
using the macro ASSERT which allows to programmatically switch between normal
assert() behavior and captured assertion.

Assertion changes were moved to more appropriate owners and code duplication
was removed.

Signed-off-by: default avatarFabio Utzig <utzig@apache.org>
parent a91c626f
Loading
Loading
Loading
Loading
−6
Changes for boot/bootutil/src/bootutil_misc.c: 0 added lines, 6 removed lines.
Original line number Diff line number Diff line
@@ -34,12 +34,6 @@
#define BOOT_LOG_LEVEL BOOT_LOG_LEVEL_INFO
#include "bootutil/bootutil_log.h"

#ifdef __BOOTSIM__
#undef assert
void sim_assert(int, const char *test, const char *, unsigned int, const char *);
#define assert(x) sim_assert((x), #x, __FILE__, __LINE__, __func__)
#endif

int boot_current_slot;

const uint32_t boot_img_magic[] = {
+6
Changes for boot/bootutil/src/bootutil_priv.h: 6 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -28,6 +28,12 @@
extern "C" {
#endif

#ifdef __BOOTSIM__
#include "bootsim.h"
#else
#define ASSERT assert
#endif

struct flash_area;

#define BOOT_EFLASH     1
+2 −8
Changes for boot/bootutil/src/loader.c: 2 added lines, 8 removed lines.
Original line number Diff line number Diff line
@@ -41,12 +41,6 @@
#include "mcuboot_config/mcuboot_config.h"
#endif

#ifdef __BOOTSIM__
#undef assert
void sim_assert(int, const char *test, const char *, unsigned int, const char *);
#define assert(x) sim_assert((x), #x, __FILE__, __LINE__, __func__)
#endif

static struct boot_loader_state boot_data;

#ifdef MCUBOOT_VALIDATE_SLOT0
@@ -58,7 +52,7 @@ static int boot_status_fails = 0;
        }                                    \
    } while (0)
#else
#define BOOT_STATUS_ASSERT(x) assert(x)
#define BOOT_STATUS_ASSERT(x) ASSERT(x)
#endif

struct boot_status_table {
@@ -1429,7 +1423,7 @@ boot_go(struct boot_rsp *rsp)

#ifdef MCUBOOT_VALIDATE_SLOT0
    rc = boot_validate_slot(0);
    assert(rc == 0);
    ASSERT(rc == 0);
    if (rc != 0) {
        rc = BOOT_EBADIMAGE;
        goto out;
+1
Changes for sim/mcuboot-sys/build.rs: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
@@ -81,6 +81,7 @@ fn main() {
    conf.file("csupport/run.c");
    conf.include("../../boot/bootutil/include");
    conf.include("../../boot/zephyr/include");
    conf.include("csupport");
    conf.debug(true);
    conf.flag("-Wall");
    conf.flag("-Werror");
+7
Changes for sim/mcuboot-sys/csupport/bootsim.h: 7 added lines, 0 removed lines.
Original line number Diff line number Diff line
#ifndef H_BOOTSIM_
#define H_BOOTSIM_

void sim_assert(int, const char *test, const char *, unsigned int, const char *);
#define ASSERT(x) sim_assert((x), #x, __FILE__, __LINE__, __func__)

#endif
Loading