Initial commit
Initial commit.
This commit is contained in:
35
bootloader/mcuboot/boot/boot_serial/test/pkg.yml
Normal file
35
bootloader/mcuboot/boot/boot_serial/test/pkg.yml
Normal file
@@ -0,0 +1,35 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
pkg.name: boot/boot_serial/test
|
||||
pkg.type: unittest
|
||||
pkg.description: "Boot serial unit tests."
|
||||
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
|
||||
pkg.homepage: "http://mynewt.apache.org/"
|
||||
pkg.keywords:
|
||||
|
||||
pkg.deps:
|
||||
- "@mcuboot/boot/boot_serial"
|
||||
- "@mcuboot/boot/bootutil"
|
||||
- "@apache-mynewt-core/sys/log/stub"
|
||||
- "@apache-mynewt-core/test/testutil"
|
||||
|
||||
pkg.deps.SELFTEST:
|
||||
- "@apache-mynewt-core/sys/console/stub"
|
||||
|
||||
pkg.cflags:
|
||||
- '-DMCUBOOT_MYNEWT=1'
|
||||
85
bootloader/mcuboot/boot/boot_serial/test/src/boot_test.c
Normal file
85
bootloader/mcuboot/boot/boot_serial/test/src/boot_test.c
Normal file
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "sysflash/sysflash.h"
|
||||
#include "os/endian.h"
|
||||
#include "base64/base64.h"
|
||||
#include "crc/crc16.h"
|
||||
#include "testutil/testutil.h"
|
||||
#include "hal/hal_flash.h"
|
||||
#include "flash_map_backend/flash_map_backend.h"
|
||||
|
||||
#include "boot_serial/boot_serial.h"
|
||||
#include "boot_serial_priv.h"
|
||||
|
||||
TEST_CASE_DECL(boot_serial_setup)
|
||||
TEST_CASE_DECL(boot_serial_empty_msg)
|
||||
TEST_CASE_DECL(boot_serial_empty_img_msg)
|
||||
TEST_CASE_DECL(boot_serial_img_msg)
|
||||
TEST_CASE_DECL(boot_serial_upload_bigger_image)
|
||||
|
||||
static void
|
||||
test_uart_write(const char *str, int len)
|
||||
{
|
||||
}
|
||||
|
||||
static const struct boot_uart_funcs test_uart = {
|
||||
.write = test_uart_write
|
||||
};
|
||||
|
||||
void
|
||||
tx_msg(void *src, int len)
|
||||
{
|
||||
boot_serial_input(src, len);
|
||||
}
|
||||
|
||||
TEST_SUITE(boot_serial_suite)
|
||||
{
|
||||
boot_serial_setup();
|
||||
boot_serial_empty_msg();
|
||||
boot_serial_empty_img_msg();
|
||||
boot_serial_img_msg();
|
||||
boot_serial_upload_bigger_image();
|
||||
}
|
||||
|
||||
int
|
||||
boot_serial_test(void)
|
||||
{
|
||||
boot_uf = &test_uart;
|
||||
boot_serial_suite();
|
||||
return tu_any_failed;
|
||||
}
|
||||
|
||||
#if MYNEWT_VAL(SELFTEST)
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
sysinit();
|
||||
|
||||
boot_serial_test();
|
||||
|
||||
return tu_any_failed;
|
||||
}
|
||||
#endif
|
||||
50
bootloader/mcuboot/boot/boot_serial/test/src/boot_test.h
Normal file
50
bootloader/mcuboot/boot/boot_serial/test/src/boot_test.h
Normal file
@@ -0,0 +1,50 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#ifndef _BOOT_TEST_H
|
||||
#define _BOOT_TEST_H
|
||||
|
||||
#include <assert.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <inttypes.h>
|
||||
#include "syscfg/syscfg.h"
|
||||
#include "sysflash/sysflash.h"
|
||||
#include "os/endian.h"
|
||||
#include "base64/base64.h"
|
||||
#include "crc/crc16.h"
|
||||
#include "testutil/testutil.h"
|
||||
#include "hal/hal_flash.h"
|
||||
#include "flash_map_backend/flash_map_backend.h"
|
||||
#include "bootutil/bootutil.h"
|
||||
|
||||
#include "boot_serial_priv.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void tx_msg(void *src, int len);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* _BOOT_TEST_H */
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#include "boot_test.h"
|
||||
|
||||
TEST_CASE(boot_serial_empty_img_msg)
|
||||
{
|
||||
char buf[sizeof(struct nmgr_hdr) + 32];
|
||||
struct nmgr_hdr *hdr;
|
||||
|
||||
hdr = (struct nmgr_hdr *)buf;
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
hdr->nh_op = NMGR_OP_WRITE;
|
||||
hdr->nh_group = htons(MGMT_GROUP_ID_IMAGE);
|
||||
hdr->nh_id = IMGMGR_NMGR_ID_UPLOAD;
|
||||
hdr->nh_len = htons(2);
|
||||
strcpy((char *)(hdr + 1), "{}");
|
||||
|
||||
tx_msg(buf, sizeof(*hdr) + 2);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#include "boot_test.h"
|
||||
|
||||
TEST_CASE(boot_serial_empty_msg)
|
||||
{
|
||||
char buf[4];
|
||||
struct nmgr_hdr hdr;
|
||||
|
||||
tx_msg(buf, 0);
|
||||
|
||||
strcpy(buf, "--");
|
||||
tx_msg(buf, 2);
|
||||
|
||||
memset(&hdr, 0, sizeof(hdr));
|
||||
tx_msg(&hdr, sizeof(hdr));
|
||||
|
||||
hdr.nh_op = NMGR_OP_WRITE;
|
||||
|
||||
tx_msg(&hdr, sizeof(hdr));
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include "boot_test.h"
|
||||
|
||||
TEST_CASE(boot_serial_img_msg)
|
||||
{
|
||||
char img[16];
|
||||
char enc_img[BASE64_ENCODE_SIZE(sizeof(img)) + 1];
|
||||
char buf[sizeof(struct nmgr_hdr) + sizeof(enc_img) + 32];
|
||||
int len;
|
||||
int rc;
|
||||
struct nmgr_hdr *hdr;
|
||||
const struct flash_area *fap;
|
||||
|
||||
/* 00000000 a3 64 64 61 74 61 58 10 |.ddataX.|
|
||||
* 00000008 a5 a5 a5 a5 a5 a5 a5 a5 |........|
|
||||
* 00000010 a5 a5 a5 a5 a5 a5 a5 a5 |........|
|
||||
* 00000018 63 6c 65 6e 1a 00 01 14 |clen....|
|
||||
* 00000020 e8 63 6f 66 66 00 |.coff.|
|
||||
*/
|
||||
static const uint8_t payload[] = {
|
||||
0xa3, 0x64, 0x64, 0x61, 0x74, 0x61, 0x58, 0x10,
|
||||
/* 16 bytes of image data starts here. */
|
||||
0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5,
|
||||
0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5,
|
||||
0x63, 0x6c, 0x65, 0x6e, 0x1a, 0x00, 0x01, 0x14,
|
||||
0xe8, 0x63, 0x6f, 0x66, 0x66, 0x00,
|
||||
};
|
||||
|
||||
memset(img, 0xa5, sizeof(img));
|
||||
|
||||
hdr = (struct nmgr_hdr *)buf;
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
hdr->nh_op = NMGR_OP_WRITE;
|
||||
hdr->nh_group = htons(MGMT_GROUP_ID_IMAGE);
|
||||
hdr->nh_id = IMGMGR_NMGR_ID_UPLOAD;
|
||||
|
||||
memcpy(hdr + 1, payload, sizeof payload);
|
||||
hdr->nh_len = htons(sizeof payload);
|
||||
|
||||
len = sizeof(*hdr) + sizeof payload;
|
||||
tx_msg(buf, len);
|
||||
|
||||
/*
|
||||
* Validate contents inside the primary slot
|
||||
*/
|
||||
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(0), &fap);
|
||||
assert(rc == 0);
|
||||
|
||||
rc = flash_area_read(fap, 0, enc_img, sizeof(img));
|
||||
assert(rc == 0);
|
||||
assert(!memcmp(enc_img, img, sizeof(img)));
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
#include "boot_test.h"
|
||||
|
||||
TEST_CASE(boot_serial_setup)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
#include <flash_map_backend/flash_map_backend.h>
|
||||
|
||||
#include "boot_test.h"
|
||||
#include "zcbor_common.h"
|
||||
|
||||
TEST_CASE(boot_serial_upload_bigger_image)
|
||||
{
|
||||
char img[256];
|
||||
char enc_img[64];
|
||||
char buf[sizeof(struct nmgr_hdr) + 128];
|
||||
int len;
|
||||
int off;
|
||||
int rc;
|
||||
struct nmgr_hdr *hdr;
|
||||
const struct flash_area *fap;
|
||||
int i;
|
||||
|
||||
const int payload_off = sizeof *hdr;
|
||||
const int img_data_off = payload_off + 8;
|
||||
|
||||
/* 00000000 a3 64 64 61 74 61 58 20 |.ddataX.|
|
||||
* 00000008 00 00 00 00 00 00 00 00 |........|
|
||||
* 00000010 00 00 00 00 00 00 00 00 |........|
|
||||
* 00000018 00 00 00 00 00 00 00 00 |........|
|
||||
* 00000020 00 00 00 00 00 00 00 00 |........|
|
||||
* 00000028 63 6c 65 6e 1a 00 01 14 |clen....|
|
||||
* 00000030 e8 63 6f 66 66 00 |.coff.|
|
||||
*/
|
||||
static const uint8_t payload_first[] = {
|
||||
0xa3, 0x64, 0x64, 0x61, 0x74, 0x61, 0x58, 0x20,
|
||||
/* 32 bytes of image data starts here. */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x63, 0x6c, 0x65, 0x6e, 0x1a, 0x00, 0x01, 0x14,
|
||||
0xe8, 0x63, 0x6f, 0x66, 0x66, 0x00,
|
||||
};
|
||||
|
||||
/* 00000000 a3 64 64 61 74 61 58 20 |.ddataX.|
|
||||
* 00000008 00 00 00 00 00 00 00 00 |........|
|
||||
* 00000010 00 00 00 00 00 00 00 00 |........|
|
||||
* 00000018 00 00 00 00 00 00 00 00 |........|
|
||||
* 00000020 00 00 00 00 00 00 00 00 |........|
|
||||
* 00000028 63 6f 66 66 00 00 |coff..|
|
||||
*/
|
||||
static const uint8_t payload_next[] = {
|
||||
0xa2, 0x64, 0x64, 0x61, 0x74, 0x61, 0x58, 0x20,
|
||||
/* 32 bytes of image data starts here. */
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x63, 0x6f, 0x66, 0x66,
|
||||
/* 2 bytes of offset value starts here. */
|
||||
0x00, 0x00
|
||||
};
|
||||
|
||||
for (i = 0; i < sizeof(img); i++) {
|
||||
img[i] = i;
|
||||
}
|
||||
|
||||
for (off = 0; off < sizeof(img); off += 32) {
|
||||
hdr = (struct nmgr_hdr *)buf;
|
||||
memset(hdr, 0, sizeof(*hdr));
|
||||
hdr->nh_op = NMGR_OP_WRITE;
|
||||
hdr->nh_group = htons(MGMT_GROUP_ID_IMAGE);
|
||||
hdr->nh_id = IMGMGR_NMGR_ID_UPLOAD;
|
||||
|
||||
if (off) {
|
||||
memcpy(buf + payload_off, payload_next, sizeof payload_next);
|
||||
len = sizeof payload_next;
|
||||
buf[payload_off + len - 2] = ZCBOR_VALUE_IS_1_BYTE;
|
||||
buf[payload_off + len - 1] = off;
|
||||
} else {
|
||||
memcpy(buf + payload_off, payload_first, sizeof payload_first);
|
||||
len = sizeof payload_first;
|
||||
}
|
||||
memcpy(buf + img_data_off, img + off, 32);
|
||||
hdr->nh_len = htons(len);
|
||||
|
||||
len = sizeof(*hdr) + len;
|
||||
|
||||
tx_msg(buf, len);
|
||||
}
|
||||
|
||||
/*
|
||||
* Validate contents inside the primary slot
|
||||
*/
|
||||
rc = flash_area_open(FLASH_AREA_IMAGE_PRIMARY(0), &fap);
|
||||
assert(rc == 0);
|
||||
|
||||
for (off = 0; off < sizeof(img); off += sizeof(enc_img)) {
|
||||
rc = flash_area_read(fap, off, enc_img, sizeof(enc_img));
|
||||
assert(rc == 0);
|
||||
assert(!memcmp(enc_img, &img[off], sizeof(enc_img)));
|
||||
}
|
||||
}
|
||||
23
bootloader/mcuboot/boot/boot_serial/test/syscfg.yml
Normal file
23
bootloader/mcuboot/boot/boot_serial/test/syscfg.yml
Normal file
@@ -0,0 +1,23 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
#
|
||||
|
||||
# Package: boot/boot_serial/test
|
||||
|
||||
syscfg.vals:
|
||||
# This is here to work around the $notnull syscfg restriction.
|
||||
BOOT_SERIAL_DETECT_PIN: 0
|
||||
Reference in New Issue
Block a user