Skip to content

Commit

Permalink
Removed deprecate libcheck API
Browse files Browse the repository at this point in the history
  • Loading branch information
danielinux committed Sep 6, 2024
1 parent a1a7601 commit 2972998
Show file tree
Hide file tree
Showing 11 changed files with 253 additions and 252 deletions.
4 changes: 2 additions & 2 deletions tools/unit-tests/unit-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,12 @@ int ext_flash_erase(uintptr_t address, int len) {

void ext_flash_unlock(void)
{
fail_unless(elocked, "Double ext unlock detected\n");
ck_assert_msg(elocked, "Double ext unlock detected\n");
elocked--;
}
void ext_flash_lock(void)
{
fail_if(elocked, "Double ext lock detected\n");
ck_assert_msg(!elocked, "Double ext lock detected\n");
elocked++;
}

Expand Down
98 changes: 49 additions & 49 deletions tools/unit-tests/unit-enc-nvm.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,53 +57,53 @@ START_TEST (test_nvm_update_with_encryption)

ret = mmap_file("/tmp/wolfboot-unit-file.bin", (void *)MOCK_ADDRESS,
WOLFBOOT_PARTITION_SIZE, NULL);
fail_if(ret < 0);
ck_assert(ret >= 0);
#ifdef FLAGS_HOME
ret = mmap_file("/tmp/wolfboot-unit-int-file.bin", (void *)MOCK_ADDRESS_BOOT,
WOLFBOOT_PARTITION_SIZE, NULL);
fail_if(ret < 0);
ck_assert(ret >= 0);
part = PART_BOOT;
base_addr = WOLFBOOT_PARTITION_BOOT_ADDRESS;
home_off = PART_BOOT_ENDFLAGS - PART_UPDATE_ENDFLAGS;
#endif
ret = mmap_file("/tmp/wolfboot-unit-swap.bin", (void *)MOCK_ADDRESS_SWAP,
WOLFBOOT_SECTOR_SIZE, NULL);
fail_if(ret < 0);
ck_assert(ret >= 0);

/* Sanity */
fail_if(home_off > WOLFBOOT_SECTOR_SIZE);
ck_assert(home_off <= WOLFBOOT_SECTOR_SIZE);

/* unlock the flash to allow operations */
hal_flash_unlock();

/* Check swap erase */
wolfBoot_erase_partition(PART_SWAP);
fail_if(erased_swap != 1);
ck_assert(erased_swap == 1);
for (i = 0; i < WOLFBOOT_SECTOR_SIZE; i+=4) {
uint32_t *word = ((uint32_t *)((uintptr_t)WOLFBOOT_PARTITION_SWAP_ADDRESS + i));
fail_if(*word != 0xFFFFFFFF);
ck_assert(*word == 0xFFFFFFFF);
}

erased_update = 0;
wolfBoot_erase_partition(part);
#ifndef FLAGS_HOME
fail_if(erased_update != 1);
ck_assert(erased_update == 1);
#else
fail_if(erased_boot != 1);
ck_assert(erased_boot == 1);
#endif
/* Erased flag sectors: select '0' by default */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 0, "Failed to select default fresh sector\n");
ck_assert_msg(ret == 0, "Failed to select default fresh sector\n");

/* Force a good 'magic' at the end of sector 1 by setting the magic word */
wolfBoot_set_partition_state(PART_UPDATE, IMG_STATE_NEW);
magic = get_partition_magic(PART_UPDATE);
fail_if(*magic != *boot_word,
ck_assert_msg(*magic == *boot_word,
"Failed to read back 'BOOT' trailer at the end of the partition");

/* Current selected should now be 1 */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 1, "Failed to select good fresh sector\n");
ck_assert_msg(ret == 1, "Failed to select good fresh sector\n");

erased_nvm_bank1 = 0;
erased_nvm_bank0 = 0;
Expand All @@ -113,37 +113,37 @@ START_TEST (test_nvm_update_with_encryption)

/* Current selected should now be 0 */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 0, "Failed to select updating fresh sector\n");
fail_if(erased_nvm_bank1 == 0, "Did not erase the non-selected bank");
ck_assert_msg(ret == 0, "Failed to select updating fresh sector\n");
ck_assert_msg(erased_nvm_bank1 > 0, "Did not erase the non-selected bank");

erased_nvm_bank1 = 0;
erased_nvm_bank0 = 0;

/* Check state is read back correctly */
ret = wolfBoot_get_partition_state(PART_UPDATE, &st);
fail_if(ret != 0, "Failed to read back state\n");
fail_if(st != IMG_STATE_UPDATING, "Bootloader in the wrong state\n");
ck_assert_msg(ret == 0, "Failed to read back state\n");
ck_assert_msg(st == IMG_STATE_UPDATING, "Bootloader in the wrong state\n");

/* Check that reading did not change the current sector */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 0, "Failed to select right sector after reading\n");
ck_assert_msg(ret == 0, "Failed to select right sector after reading\n");

/* Update one sector flag, it should change nvm sector */
wolfBoot_set_update_sector_flag(0, SECT_FLAG_SWAPPING);

/* Current selected should now be 1 */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 1, "Failed to select updating fresh sector\n");
fail_if(erased_nvm_bank0 == 0, "Did not erase the non-selected bank");
ck_assert_msg(ret == 1, "Failed to select updating fresh sector\n");
ck_assert_msg(erased_nvm_bank0 != 0, "Did not erase the non-selected bank");

/* Check sector state is read back correctly */
ret = wolfBoot_get_update_sector_flag(0, &st);
fail_if (ret != 0, "Failed to read sector flag state\n");
fail_if (st != SECT_FLAG_SWAPPING, "Wrong sector flag state\n");
ck_assert_msg(ret == 0, "Failed to read sector flag state\n");
ck_assert_msg(st == SECT_FLAG_SWAPPING, "Wrong sector flag state\n");

/* Check that reading did not change the current sector (1) */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 1, "Failed to select right sector after reading sector state\n");
ck_assert_msg(ret == 1, "Failed to select right sector after reading sector state\n");

/* Update sector flag, again. it should change nvm sector */
erased_nvm_bank1 = 0;
Expand All @@ -152,17 +152,17 @@ START_TEST (test_nvm_update_with_encryption)

/* Current selected should now be 0 */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 0, "Failed to select updating fresh sector\n");
fail_if(erased_nvm_bank1 == 0, "Did not erase the non-selected bank");
ck_assert_msg(ret == 0, "Failed to select updating fresh sector\n");
ck_assert_msg(erased_nvm_bank1 != 0, "Did not erase the non-selected bank");

/* Check sector state is read back correctly */
ret = wolfBoot_get_update_sector_flag(0, &st);
fail_if (ret != 0, "Failed to read sector flag state\n");
fail_if (st != SECT_FLAG_UPDATED, "Wrong sector flag state\n");
ck_assert_msg(ret == 0, "Failed to read sector flag state\n");
ck_assert_msg(st == SECT_FLAG_UPDATED, "Wrong sector flag state\n");

/* Check that reading did not change the current sector (0) */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 0, "Failed to select right sector after reading sector state\n");
ck_assert_msg(ret == 0, "Failed to select right sector after reading sector state\n");

/* Update sector flag, again. it should change nvm sector */
erased_nvm_bank1 = 0;
Expand All @@ -171,17 +171,17 @@ START_TEST (test_nvm_update_with_encryption)

/* Current selected should now be 1 */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 1, "Failed to select updating fresh sector\n");
fail_if(erased_nvm_bank0 == 0, "Did not erase the non-selected bank");
ck_assert_msg(ret == 1, "Failed to select updating fresh sector\n");
ck_assert_msg(erased_nvm_bank0 > 0, "Did not erase the non-selected bank");

/* Check sector state is read back correctly */
ret = wolfBoot_get_update_sector_flag(1, &st);
fail_if (ret != 0, "Failed to read sector flag state\n");
fail_if (st != SECT_FLAG_SWAPPING, "Wrong sector flag state\n");
ck_assert_msg(ret == 0, "Failed to read sector flag state\n");
ck_assert_msg(st == SECT_FLAG_SWAPPING, "Wrong sector flag state\n");

/* Check that reading did not change the current sector (1) */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 1, "Failed to select right sector after reading sector state\n");
ck_assert_msg(ret == 1, "Failed to select right sector after reading sector state\n");

/* Update sector flag, again. it should change nvm sector */
erased_nvm_bank1 = 0;
Expand All @@ -202,7 +202,7 @@ START_TEST (test_nvm_update_with_encryption)

/* This should fall back to 1 */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 1, "Failed to select most recent sector after deleting flags\n");
ck_assert_msg(ret == 1, "Failed to select most recent sector after deleting flags\n");

/* Start over, update some sector flags */
wolfBoot_erase_partition(PART_UPDATE);
Expand All @@ -216,23 +216,23 @@ START_TEST (test_nvm_update_with_encryption)

/* Current selected should now be 1 */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 1, "Failed to select updating fresh sector\n");
fail_if(erased_nvm_bank0 == 0, "Did not erase the non-selected bank");
ck_assert_msg(ret == 1, "Failed to select updating fresh sector\n");
ck_assert_msg(erased_nvm_bank0 > 0, "Did not erase the non-selected bank");

/* Check sector state is read back correctly */
for (i = 0; i < 4; i++) {
ret = wolfBoot_get_update_sector_flag(i, &st);
fail_if (ret != 0, "Failed to read sector flag state\n");
fail_if (st != SECT_FLAG_UPDATED, "Wrong sector flag state\n");
ck_assert_msg(ret == 0, "Failed to read sector flag state\n");
ck_assert_msg(st == SECT_FLAG_UPDATED, "Wrong sector flag state\n");

}
ret = wolfBoot_get_update_sector_flag(4, &st);
fail_if (ret != 0, "Failed to read sector flag state\n");
fail_if (st != SECT_FLAG_SWAPPING, "Wrong sector flag state\n");
ck_assert_msg(ret == 0, "Failed to read sector flag state\n");
ck_assert_msg(st == SECT_FLAG_SWAPPING, "Wrong sector flag state\n");

/* Check that reading did not change the current sector (1) */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 1, "Failed to select right sector after reading sector state\n");
ck_assert_msg(ret == 1, "Failed to select right sector after reading sector state\n");

/* Copy flags from 1 to 0 */
src = (uint8_t *)((uintptr_t)base_addr + WOLFBOOT_PARTITION_SIZE - (2 * WOLFBOOT_SECTOR_SIZE));
Expand All @@ -247,26 +247,26 @@ START_TEST (test_nvm_update_with_encryption)

/* Check if still there */
ret = wolfBoot_get_update_sector_flag(4, &st);
fail_if (ret != 0, "Failed to read sector flag state\n");
fail_if (st != SECT_FLAG_UPDATED, "Wrong sector flag state\n");
ck_assert_msg(ret == 0, "Failed to read sector flag state\n");
ck_assert_msg(st == SECT_FLAG_UPDATED, "Wrong sector flag state\n");

/* This should fall back to 0 */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 0, "Failed to select most recent sector after deleting flags\n");
ck_assert_msg(ret == 0, "Failed to select most recent sector after deleting flags\n");


/* Erase partition and start over */
erased_update = 0;
erased_boot = 0;
wolfBoot_erase_partition(part);
#ifndef FLAGS_HOME
fail_if(erased_update != 1);
ck_assert(erased_update == 1);
#else
fail_if(erased_boot != 1);
ck_assert(erased_boot == 1);
#endif

ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 0, "Failed to select right sector after reading sector state\n");
ck_assert_msg(ret == 0, "Failed to select right sector after reading sector state\n");

/* re-lock the flash: update_trigger implies unlocking/locking */
hal_flash_lock();
Expand All @@ -276,15 +276,15 @@ START_TEST (test_nvm_update_with_encryption)

/* Current selected should now be 0 */
ret = nvm_select_fresh_sector(PART_UPDATE);
fail_if(ret != 0, "Failed to select updating fresh sector\n");
fail_if(erased_nvm_bank1 == 0, "Did not erase the non-selected bank");
ck_assert_msg(ret == 0, "Failed to select updating fresh sector\n");
ck_assert_msg(erased_nvm_bank1 != 0, "Did not erase the non-selected bank");

magic = get_partition_magic(PART_UPDATE);
fail_if(*magic != *boot_word,
ck_assert_msg(*magic == *boot_word,
"Failed to read back 'BOOT' trailer at the end of the partition");

/* Sanity check at the end of the operations. */
fail_unless(locked, "The FLASH was left unlocked.\n");
ck_assert_msg(locked, "The FLASH was left unlocked.\n");


}
Expand Down
4 changes: 2 additions & 2 deletions tools/unit-tests/unit-extflash.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ int hal_flash_erase(haladdr_t address, int len)
}
void hal_flash_unlock(void)
{
fail_unless(locked, "Double unlock detected\n");
ck_assert_msg(locked, "Double unlock detected\n");
locked--;
}
void hal_flash_lock(void)
{
fail_if(locked, "Double lock detected\n");
ck_assert_msg(!locked, "Double lock detected\n");
locked++;
}

Expand Down
14 changes: 7 additions & 7 deletions tools/unit-tests/unit-mock-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int hal_flash_write(haladdr_t address, const uint8_t *data, int len)
{
int i;
uint8_t *a = (uint8_t *)(uintptr_t)address;
fail_if(locked, "Attempting to write to a locked FLASH");
ck_assert_msg(!locked, "Attempting to write to a locked FLASH");
if ((address >= WOLFBOOT_PARTITION_SWAP_ADDRESS) &&
(address < WOLFBOOT_PARTITION_UPDATE_ADDRESS + WOLFBOOT_SECTOR_SIZE)) {
for (i = 0; i < len; i++) {
Expand Down Expand Up @@ -72,7 +72,7 @@ int hal_flash_write(haladdr_t address, const uint8_t *data, int len)
}
int hal_flash_erase(haladdr_t address, int len)
{
fail_if(locked, "Attempting to erase a locked FLASH");
ck_assert_msg(!locked, "Attempting to erase a locked FLASH");
if ((address >= WOLFBOOT_PARTITION_BOOT_ADDRESS) &&
(address < WOLFBOOT_PARTITION_BOOT_ADDRESS + WOLFBOOT_PARTITION_SIZE)) {
erased_boot++;
Expand Down Expand Up @@ -109,12 +109,12 @@ int hal_flash_erase(haladdr_t address, int len)
}
void hal_flash_unlock(void)
{
fail_unless(locked, "Double unlock detected\n");
ck_assert_msg(locked, "Double unlock detected\n");
locked--;
}
void hal_flash_lock(void)
{
fail_if(locked, "Double lock detected\n");
ck_assert_msg(!locked, "Double lock detected\n");
locked++;
}

Expand Down Expand Up @@ -160,7 +160,7 @@ int ext_flash_write(uintptr_t address, const uint8_t *data, int len)
{
int i;
uint8_t *a = (uint8_t *)address;
fail_if(ext_locked, "Attempting to write to a locked FLASH");
ck_assert_msg(!ext_locked, "Attempting to write to a locked FLASH");
for (i = 0; i < len; i++) {
a[i] = data[i];
}
Expand All @@ -179,12 +179,12 @@ int ext_flash_read(uintptr_t address, uint8_t *data, int len)

void ext_flash_unlock(void)
{
fail_unless(ext_locked, "Double ext unlock detected\n");
ck_assert_msg(ext_locked, "Double ext unlock detected\n");
ext_locked--;
}
void ext_flash_lock(void)
{
fail_if(ext_locked, "Double ext lock detected\n");
ck_assert_msg(!ext_locked, "Double ext lock detected\n");
ext_locked++;
}

Expand Down
5 changes: 3 additions & 2 deletions tools/unit-tests/unit-mock-state.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include <string.h>
#include "user_settings.h"
#include "wolfboot/wolfboot.h"

static uint8_t* get_trailer_at(uint8_t part, uint32_t at);
static void set_trailer_at(uint8_t part, uint32_t at, uint8_t val);
static void set_partition_magic(uint8_t part);
Expand Down Expand Up @@ -185,12 +186,12 @@ int ext_flash_erase(uintptr_t address, int len)
}
void ext_flash_unlock(void)
{
fail_unless(ext_locked, "Double unlock detected (ext)\n");
ck_assert_msg(ext_locked, "Double unlock detected (ext)\n");
ext_locked--;
}
void ext_flash_lock(void)
{
fail_if(ext_locked, "Double lock detected(ext)\n");
ck_assert_msg(!ext_locked, "Double lock detected(ext)\n");
ext_locked++;
}

Expand Down
Loading

0 comments on commit 2972998

Please sign in to comment.