Added test scripts

pull/290/head
Daniele Lacamera 2023-03-14 16:05:47 +01:00
parent 6aa5c114e5
commit 57a8fb30f1
5 changed files with 89 additions and 10 deletions

View File

@ -61,7 +61,7 @@ static int mmap_file(const char *path, uint8_t *address, uint8_t** ret_address)
fd = open(path, O_RDWR);
if (fd == -1) {
printf("can't open %s\n", path);
fprintf(stderr,"can't open %s\n", path);
return -1;
}
@ -110,9 +110,11 @@ int hal_flash_erase(uint32_t address, int len)
uint8_t *ptr = 0;
/* implicit cast abide compiler warning */
printf("hal_flash_erase addr %p len %d\n", address, len);
fprintf(stderr,"hal_flash_erase addr %p len %d\n", address, len);
if (address == erasefail_address) {
printf("POWER FAILURE\n");
fprintf(stderr,"POWER FAILURE\n");
/* Corrupt page */
memset(ptr + address, 0xEE, len);
exit(0);
}
memset(ptr + address, 0xff, len);
@ -127,14 +129,14 @@ void hal_init(void)
ret = mmap_file(INTERNAL_FLASH_FILE,
(uint8_t*)WOLFBOOT_PARTITION_BOOT_ADDRESS, &p);
if (ret != 0) {
printf("failed to load internal flash file\n");
fprintf(stderr,"failed to load internal flash file\n");
exit(-1);
}
#ifdef EXT_FLASH
ret = mmap_file(EXTERNAL_FLASH_FILE, NULL, &flash_base);
if (ret != 0) {
printf("failed to load internal flash file\n");
fprintf(stderr,"failed to load internal flash file\n");
exit(-1);
}
#endif /* EXT_FLASH */
@ -142,7 +144,7 @@ void hal_init(void)
for (i = 1; i < main_argc; i++) {
if (strcmp(main_argv[i], "powerfail") == 0) {
erasefail_address = strtol(main_argv[++i], NULL, 16);
printf("Set power fail to erase at address %p\n", erasefail_address);
fprintf(stderr,"Set power fail to erase at address %p\n", erasefail_address);
break;
}
}
@ -184,18 +186,18 @@ void do_boot(const uint32_t *app_offset)
fd = memfd_create("test_app", 0);
if (fd == -1) {
printf("memfd error\n");
fprintf(stderr,"memfd error\n");
exit(-1);
}
ret = write(fd, app_offset, WOLFBOOT_PARTITION_SIZE);
if (ret != WOLFBOOT_PARTITION_SIZE) {
printf("can't write test-app to memfd\n");
fprintf(stderr,"can't write test-app to memfd\n");
exit(-1);
}
ret = fexecve(fd, main_argv, envp);
printf("fexecve error\n");
fprintf(stderr,"fexecve error\n");
exit(1);
}

View File

@ -76,4 +76,4 @@ int main(int argc, char *argv[]) {
return 0;
}
#endif /** PLATFROM_sim **/
#endif /** PLATFORM_sim **/

View File

@ -0,0 +1,19 @@
#!/bin/bash
V=`./wolfboot.elf update_trigger get_version 2>/dev/null`
if [ "x$V" != "x1" ]; then
echo "Failed first boot with update_trigger"
exit 1
fi
V=`./wolfboot.elf success get_version 2>/dev/null`
if [ "x$V" != "x2" ]; then
echo "Failed update (V: $V)"
exit 1
fi
echo Test successful.
exit 0

View File

@ -0,0 +1,25 @@
#!/bin/bash
V=`./wolfboot.elf update_trigger get_version 2>/dev/null`
if [ "x$V" != "x1" ]; then
echo "Failed first boot with update_trigger"
exit 1
fi
V=`./wolfboot.elf get_version 2>/dev/null`
if [ "x$V" != "x2" ]; then
echo "Failed update (V: $V)"
exit 1
fi
V=`./wolfboot.elf get_version 2>/dev/null`
if [ "x$V" != "x1" ]; then
echo "Failed fallback (V: $V)"
exit 1
fi
echo Test successful.
exit 0

View File

@ -0,0 +1,33 @@
#!/bin/bash
V=`./wolfboot.elf update_trigger get_version 2>/dev/null`
if [ "x$V" != "x1" ]; then
echo "Failed first boot with update_trigger"
exit 1
fi
./wolfboot.elf powerfail 15000 get_version 2>/dev/null
./wolfboot.elf powerfail 18000 get_version 2>/dev/null
./wolfboot.elf powerfail 1a000 get_version 2>/dev/null
V=`./wolfboot.elf get_version 2>/dev/null`
if [ "x$V" != "x2" ]; then
echo "Failed update (V: $V)"
exit 1
fi
./wolfboot.elf powerfail 11000 get_version 2>/dev/null
./wolfboot.elf powerfail 14000 get_version 2>/dev/null
./wolfboot.elf powerfail 1e000 get_version 2>/dev/null
V=`./wolfboot.elf get_version 2>/dev/null`
if [ "x$V" != "x1" ]; then
echo "Failed fallback (V: $V)"
exit 1
fi
echo Test successful.
exit 0