Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion tests/subsys/storage/flash_map/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,10 @@ cmake_minimum_required(VERSION 3.20.0)
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(flash_map)

FILE(GLOB app_sources src/*.c)
if(NOT CONFIG_FLASH_AREA_CHECK_INTEGRITY_PSA AND NOT CONFIG_FLASH_AREA_CHECK_INTEGRITY_MBEDTLS)
FILE(GLOB app_sources src/main.c)
else()
FILE(GLOB app_sources src/main_sha.c)
endif()

target_sources(app PRIVATE ${app_sources})
181 changes: 14 additions & 167 deletions tests/subsys/storage/flash_map/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
#define SLOT1_PARTITION_ID FIXED_PARTITION_ID(SLOT1_PARTITION)
#define SLOT1_PARTITION_DEV FIXED_PARTITION_DEVICE(SLOT1_PARTITION)
#define SLOT1_PARTITION_NODE DT_NODELABEL(SLOT1_PARTITION)
#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION)

Check notice on line 19 in tests/subsys/storage/flash_map/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/storage/flash_map/src/main.c:19 -#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION) +#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION)

Check notice on line 19 in tests/subsys/storage/flash_map/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/storage/flash_map/src/main.c:19 -#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION) +#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION)
extern int flash_map_entries;
struct flash_sector fs_sectors[1024];

Expand All @@ -41,8 +42,6 @@
int i;
int rc;
off_t off;
uint8_t wd[512];
uint8_t rd[512];
const struct device *flash_dev;
const struct device *flash_dev_a = SLOT1_PARTITION_DEV;

Expand All @@ -55,180 +54,28 @@
/* Device obtained by label should match the one from fa object */
zassert_equal(flash_dev, flash_dev_a, "Device for slot1_partition do not match");

rc = flash_erase(flash_dev, fa->fa_off, fa->fa_size);
zassert_true(rc == 0, "flash area erase fail");

(void)memset(wd, 0xa5, sizeof(wd));

sec_cnt = ARRAY_SIZE(fs_sectors);
rc = flash_area_get_sectors(SLOT1_PARTITION_ID, &sec_cnt, fs_sectors);
zassert_true(rc == 0, "flash_area_get_sectors failed");

/* write stuff to beginning of every sector */
off = 0;
for (i = 0; i < sec_cnt; i++) {
rc = flash_area_write(fa, off, wd, sizeof(wd));
zassert_true(rc == 0, "flash_area_write() fail");

/* read it back via hal_flash_Read() */
rc = flash_read(flash_dev, fa->fa_off + off, rd, sizeof(rd));
zassert_true(rc == 0, "hal_flash_read() fail");

rc = memcmp(wd, rd, sizeof(wd));
zassert_true(rc == 0, "read data != write data");

/* write stuff to end of area */
rc = flash_write(flash_dev, fa->fa_off + off +
fs_sectors[i].fs_size - sizeof(wd),
wd, sizeof(wd));
zassert_true(rc == 0, "hal_flash_write() fail");

/* and read it back */
(void)memset(rd, 0, sizeof(rd));
rc = flash_area_read(fa, off + fs_sectors[i].fs_size -
sizeof(rd),
rd, sizeof(rd));
zassert_true(rc == 0, "hal_flash_read() fail");

rc = memcmp(wd, rd, sizeof(rd));
zassert_true(rc == 0, "read data != write data");

/* For each reported sector, check if it corresponds to real page on device */
for (i = 0; i < sec_cnt; ++i) {
struct flash_pages_info fpi;

zassert_ok(flash_get_page_info_by_offs(flash_dev,
SLOT1_PARTITION_OFFSET + off,
&fpi));
/* Offset of page taken directly from device corresponds to offset
* within flash area
*/
zassert_equal(fpi.start_offset,
fs_sectors[i].fs_off + SLOT1_PARTITION_OFFSET);
zassert_equal(fpi.size, fs_sectors[i].fs_size);

Check notice on line 75 in tests/subsys/storage/flash_map/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/storage/flash_map/src/main.c:75 - zassert_ok(flash_get_page_info_by_offs(flash_dev, - SLOT1_PARTITION_OFFSET + off, - &fpi)); + zassert_ok( + flash_get_page_info_by_offs(flash_dev, SLOT1_PARTITION_OFFSET + off, &fpi)); /* Offset of page taken directly from device corresponds to offset * within flash area */ - zassert_equal(fpi.start_offset, - fs_sectors[i].fs_off + SLOT1_PARTITION_OFFSET); + zassert_equal(fpi.start_offset, fs_sectors[i].fs_off + SLOT1_PARTITION_OFFSET);

Check notice on line 75 in tests/subsys/storage/flash_map/src/main.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/storage/flash_map/src/main.c:75 - zassert_ok(flash_get_page_info_by_offs(flash_dev, - SLOT1_PARTITION_OFFSET + off, - &fpi)); + zassert_ok( + flash_get_page_info_by_offs(flash_dev, SLOT1_PARTITION_OFFSET + off, &fpi)); /* Offset of page taken directly from device corresponds to offset * within flash area */ - zassert_equal(fpi.start_offset, - fs_sectors[i].fs_off + SLOT1_PARTITION_OFFSET); + zassert_equal(fpi.start_offset, fs_sectors[i].fs_off + SLOT1_PARTITION_OFFSET);
off += fs_sectors[i].fs_size;
}

/* erase it */
rc = flash_area_erase(fa, 0, fa->fa_size);
zassert_true(rc == 0, "read data != write data");

/* should read back ff all throughout*/
(void)memset(wd, 0xff, sizeof(wd));
for (off = 0; off < fa->fa_size; off += sizeof(rd)) {
rc = flash_area_read(fa, off, rd, sizeof(rd));
zassert_true(rc == 0, "hal_flash_read() fail");

rc = memcmp(wd, rd, sizeof(rd));
zassert_true(rc == 0, "area not erased");
}

flash_area_close(fa);
}

ZTEST(flash_map, test_flash_area_check_int_sha256)
{
/* for i in {1..16}; do echo $'0123456789abcdef\nfedcba98765432' >> tst.sha; done
* hexdump tst.sha
*/
uint8_t tst_vec[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a };
/* sha256sum tst.sha */
uint8_t tst_sha[] = { 0xae, 0xed, 0x7d, 0x59, 0x53, 0xbd, 0xb7, 0x28,
0x3e, 0x59, 0xc2, 0x65, 0x59, 0x62, 0xe3, 0x7e,
0xfa, 0x97, 0xbd, 0x76, 0xf6, 0xac, 0xc3, 0x92,
0x59, 0x48, 0x4e, 0xc0, 0xaf, 0xa8, 0x49, 0x65 };

const struct flash_area *fa;
struct flash_area_check fac = { NULL, 0, -1, NULL, 0 };
uint8_t buffer[16];
int rc;

rc = flash_area_open(SLOT1_PARTITION_ID, &fa);
zassert_true(rc == 0, "flash_area_open() fail, error %d\n", rc);
rc = flash_area_erase(fa, 0, fa->fa_size);
zassert_true(rc == 0, "Flash erase failure (%d), error %d\n", rc);
rc = flash_area_write(fa, 0, tst_vec, sizeof(tst_vec));
zassert_true(rc == 0, "Flash img write, error %d\n", rc);

rc = flash_area_check_int_sha256(NULL, NULL);
zassert_true(rc == -EINVAL, "Flash area check int 256 params 1, 2\n");
rc = flash_area_check_int_sha256(NULL, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 params 2\n");
rc = flash_area_check_int_sha256(fa, NULL);
zassert_true(rc == -EINVAL, "Flash area check int 256 params 1\n");

rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac match\n");
fac.match = tst_sha;
rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac clen\n");
fac.clen = sizeof(tst_vec);
rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac off\n");
fac.off = 0;
rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac rbuf\n");
fac.rbuf = buffer;
rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac rblen\n");
fac.rblen = sizeof(buffer);

rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == 0, "Flash area check int 256 OK, error %d\n", rc);
tst_sha[0] = 0x00;
rc = flash_area_check_int_sha256(fa, &fac);
zassert_false(rc == 0, "Flash area check int 256 wrong sha\n");

flash_area_close(fa);
}

Expand Down
139 changes: 139 additions & 0 deletions tests/subsys/storage/flash_map/src/main_sha.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/*
* Copyright (c) 2017-2024 Nordic Semiconductor ASA
* Copyright (c) 2015 Runtime Inc
* Copyright (c) 2020 Gerson Fernando Budke <[email protected]>
* Copyright 2024 NXP
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <zephyr/ztest.h>
#include <zephyr/drivers/flash.h>
#include <zephyr/storage/flash_map.h>

#define SLOT1_PARTITION slot1_partition
#define SLOT1_PARTITION_ID FIXED_PARTITION_ID(SLOT1_PARTITION)
#define SLOT1_PARTITION_DEV FIXED_PARTITION_DEVICE(SLOT1_PARTITION)
#define SLOT1_PARTITION_NODE DT_NODELABEL(SLOT1_PARTITION)
#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION)

ZTEST(flash_map_sha, test_flash_area_check_int_sha256)
{
/* for i in {1..16}; do echo $'0123456789abcdef\nfedcba98765432' >> tst.sha; done
* hexdump tst.sha
*/
uint8_t tst_vec[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a,
0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66,
0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39,
0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a };
/* sha256sum tst.sha */
uint8_t tst_sha[] = { 0xae, 0xed, 0x7d, 0x59, 0x53, 0xbd, 0xb7, 0x28,
0x3e, 0x59, 0xc2, 0x65, 0x59, 0x62, 0xe3, 0x7e,
0xfa, 0x97, 0xbd, 0x76, 0xf6, 0xac, 0xc3, 0x92,
0x59, 0x48, 0x4e, 0xc0, 0xaf, 0xa8, 0x49, 0x65 };

const struct flash_area *fa;
struct flash_area_check fac = { NULL, 0, -1, NULL, 0 };
uint8_t buffer[16];

Check notice on line 97 in tests/subsys/storage/flash_map/src/main_sha.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/storage/flash_map/src/main_sha.c:97 -#define SLOT1_PARTITION slot1_partition -#define SLOT1_PARTITION_ID FIXED_PARTITION_ID(SLOT1_PARTITION) -#define SLOT1_PARTITION_DEV FIXED_PARTITION_DEVICE(SLOT1_PARTITION) -#define SLOT1_PARTITION_NODE DT_NODELABEL(SLOT1_PARTITION) -#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION) +#define SLOT1_PARTITION slot1_partition +#define SLOT1_PARTITION_ID FIXED_PARTITION_ID(SLOT1_PARTITION) +#define SLOT1_PARTITION_DEV FIXED_PARTITION_DEVICE(SLOT1_PARTITION) +#define SLOT1_PARTITION_NODE DT_NODELABEL(SLOT1_PARTITION) +#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION) ZTEST(flash_map_sha, test_flash_area_check_int_sha256) { /* for i in {1..16}; do echo $'0123456789abcdef\nfedcba98765432' >> tst.sha; done * hexdump tst.sha */ - uint8_t tst_vec[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34,

Check notice on line 97 in tests/subsys/storage/flash_map/src/main_sha.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

tests/subsys/storage/flash_map/src/main_sha.c:97 -#define SLOT1_PARTITION slot1_partition -#define SLOT1_PARTITION_ID FIXED_PARTITION_ID(SLOT1_PARTITION) -#define SLOT1_PARTITION_DEV FIXED_PARTITION_DEVICE(SLOT1_PARTITION) -#define SLOT1_PARTITION_NODE DT_NODELABEL(SLOT1_PARTITION) -#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION) +#define SLOT1_PARTITION slot1_partition +#define SLOT1_PARTITION_ID FIXED_PARTITION_ID(SLOT1_PARTITION) +#define SLOT1_PARTITION_DEV FIXED_PARTITION_DEVICE(SLOT1_PARTITION) +#define SLOT1_PARTITION_NODE DT_NODELABEL(SLOT1_PARTITION) +#define SLOT1_PARTITION_OFFSET FIXED_PARTITION_OFFSET(SLOT1_PARTITION) ZTEST(flash_map_sha, test_flash_area_check_int_sha256) { /* for i in {1..16}; do echo $'0123456789abcdef\nfedcba98765432' >> tst.sha; done * hexdump tst.sha */ - uint8_t tst_vec[] = { 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34, 0x33, 0x32, 0x0a, - 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, - 0x38, 0x39, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, - 0x0a, 0x66, 0x65, 0x64, 0x63, 0x62, 0x61, 0x39, - 0x38, 0x37, 0x36, 0x35, 0x34,
int rc;

rc = flash_area_open(SLOT1_PARTITION_ID, &fa);
zassert_true(rc == 0, "flash_area_open() fail, error %d\n", rc);
rc = flash_area_erase(fa, 0, fa->fa_size);
zassert_true(rc == 0, "Flash erase failure (%d), error %d\n", rc);
rc = flash_area_write(fa, 0, tst_vec, sizeof(tst_vec));
zassert_true(rc == 0, "Flash img write, error %d\n", rc);

rc = flash_area_check_int_sha256(NULL, NULL);
zassert_true(rc == -EINVAL, "Flash area check int 256 params 1, 2\n");
rc = flash_area_check_int_sha256(NULL, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 params 2\n");
rc = flash_area_check_int_sha256(fa, NULL);
zassert_true(rc == -EINVAL, "Flash area check int 256 params 1\n");

rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac match\n");
fac.match = tst_sha;
rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac clen\n");
fac.clen = sizeof(tst_vec);
rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac off\n");
fac.off = 0;
rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac rbuf\n");
fac.rbuf = buffer;
rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == -EINVAL, "Flash area check int 256 fac rblen\n");
fac.rblen = sizeof(buffer);

rc = flash_area_check_int_sha256(fa, &fac);
zassert_true(rc == 0, "Flash area check int 256 OK, error %d\n", rc);
tst_sha[0] = 0x00;
rc = flash_area_check_int_sha256(fa, &fac);
zassert_false(rc == 0, "Flash area check int 256 wrong sha\n");

flash_area_close(fa);
}

ZTEST_SUITE(flash_map_sha, NULL, NULL, NULL, NULL, NULL);
4 changes: 2 additions & 2 deletions tests/subsys/storage/flash_map/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ tests:
integration_platforms:
- nrf52840dk/nrf52840
tags: flash_map
storage.flash_map.mbedtls:
storage.flash_map_sha.mbedtls:
extra_args: EXTRA_CONF_FILE=overlay-mbedtls.conf
platform_allow:
- nrf51dk/nrf51822
Expand All @@ -33,7 +33,7 @@ tests:
tags: flash_map
integration_platforms:
- native_sim
storage.flash_map.psa:
storage.flash_map_sha.psa:
extra_args: EXTRA_CONF_FILE=overlay-psa.conf
platform_allow:
- nrf51dk/nrf51822
Expand Down
Loading