[FL-2627] Flipper applications: SDK, build and debug system (#1387)

* Added support for running applications from SD card (FAPs - Flipper Application Packages)
* Added plugin_dist target for fbt to build FAPs
* All apps of type FlipperAppType.EXTERNAL and FlipperAppType.PLUGIN are built as FAPs by default
* Updated VSCode configuration for new fbt features - re-deploy stock configuration to use them
* Added debugging support for FAPs with fbt debug & VSCode
* Added public firmware API with automated versioning

Co-authored-by: hedger <hedger@users.noreply.github.com>
Co-authored-by: SG <who.just.the.doctor@gmail.com>
Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
SG
2022-09-15 02:11:38 +10:00
committed by Aleksandr Kutuzov
parent 0f6f9ad52e
commit b9a766d909
895 changed files with 8862 additions and 1465 deletions

View File

@@ -0,0 +1,272 @@
#include "../minunit.h"
#include <furi.h>
#include <m-dict.h>
#include <toolbox/dir_walk.h>
static const char* const storage_test_dirwalk_paths[] = {
"1",
"11",
"111",
"1/2",
"1/22",
"1/222",
"11/2",
"111/2",
"111/22",
"111/22/33",
};
static const char* const storage_test_dirwalk_files[] = {
"file1.test",
"file2.test",
"file3.ext_test",
"1/file1.test",
"111/22/33/file1.test",
"111/22/33/file2.test",
"111/22/33/file3.ext_test",
"111/22/33/file4.ext_test",
};
typedef struct {
const char* const path;
bool is_dir;
} StorageTestPathDesc;
const StorageTestPathDesc storage_test_dirwalk_full[] = {
{.path = "1", .is_dir = true},
{.path = "11", .is_dir = true},
{.path = "111", .is_dir = true},
{.path = "1/2", .is_dir = true},
{.path = "1/22", .is_dir = true},
{.path = "1/222", .is_dir = true},
{.path = "11/2", .is_dir = true},
{.path = "111/2", .is_dir = true},
{.path = "111/22", .is_dir = true},
{.path = "111/22/33", .is_dir = true},
{.path = "file1.test", .is_dir = false},
{.path = "file2.test", .is_dir = false},
{.path = "file3.ext_test", .is_dir = false},
{.path = "1/file1.test", .is_dir = false},
{.path = "111/22/33/file1.test", .is_dir = false},
{.path = "111/22/33/file2.test", .is_dir = false},
{.path = "111/22/33/file3.ext_test", .is_dir = false},
{.path = "111/22/33/file4.ext_test", .is_dir = false},
};
const StorageTestPathDesc storage_test_dirwalk_no_recursive[] = {
{.path = "1", .is_dir = true},
{.path = "11", .is_dir = true},
{.path = "111", .is_dir = true},
{.path = "file1.test", .is_dir = false},
{.path = "file2.test", .is_dir = false},
{.path = "file3.ext_test", .is_dir = false},
};
const StorageTestPathDesc storage_test_dirwalk_filter[] = {
{.path = "file1.test", .is_dir = false},
{.path = "file2.test", .is_dir = false},
{.path = "1/file1.test", .is_dir = false},
{.path = "111/22/33/file1.test", .is_dir = false},
{.path = "111/22/33/file2.test", .is_dir = false},
};
typedef struct {
bool is_dir;
bool visited;
} StorageTestPath;
DICT_DEF2(StorageTestPathDict, string_t, STRING_OPLIST, StorageTestPath, M_POD_OPLIST)
static StorageTestPathDict_t*
storage_test_paths_alloc(const StorageTestPathDesc paths[], size_t paths_count) {
StorageTestPathDict_t* data = malloc(sizeof(StorageTestPathDict_t));
StorageTestPathDict_init(*data);
for(size_t i = 0; i < paths_count; i++) {
string_t key;
string_init_set(key, paths[i].path);
StorageTestPath value = {
.is_dir = paths[i].is_dir,
.visited = false,
};
StorageTestPathDict_set_at(*data, key, value);
string_clear(key);
}
return data;
}
static void storage_test_paths_free(StorageTestPathDict_t* data) {
StorageTestPathDict_clear(*data);
free(data);
}
static bool storage_test_paths_mark(StorageTestPathDict_t* data, string_t path, bool is_dir) {
bool found = false;
StorageTestPath* record = StorageTestPathDict_get(*data, path);
if(record) {
if(is_dir == record->is_dir) {
if(record->visited == false) {
record->visited = true;
found = true;
}
}
}
return found;
}
static bool storage_test_paths_check(StorageTestPathDict_t* data) {
bool error = false;
StorageTestPathDict_it_t it;
for(StorageTestPathDict_it(it, *data); !StorageTestPathDict_end_p(it);
StorageTestPathDict_next(it)) {
const StorageTestPathDict_itref_t* itref = StorageTestPathDict_cref(it);
if(itref->value.visited == false) {
error = true;
break;
}
}
return error;
}
static bool write_file_13DA(Storage* storage, const char* path) {
File* file = storage_file_alloc(storage);
bool result = false;
if(storage_file_open(file, path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
result = storage_file_write(file, "13DA", 4) == 4;
}
storage_file_close(file);
storage_file_free(file);
return result;
}
static void storage_dirs_create(Storage* storage, const char* base) {
string_t path;
string_init(path);
storage_common_mkdir(storage, base);
for(size_t i = 0; i < COUNT_OF(storage_test_dirwalk_paths); i++) {
string_printf(path, "%s/%s", base, storage_test_dirwalk_paths[i]);
storage_common_mkdir(storage, string_get_cstr(path));
}
for(size_t i = 0; i < COUNT_OF(storage_test_dirwalk_files); i++) {
string_printf(path, "%s/%s", base, storage_test_dirwalk_files[i]);
write_file_13DA(storage, string_get_cstr(path));
}
string_clear(path);
}
MU_TEST_1(test_dirwalk_full, Storage* storage) {
string_t path;
string_init(path);
FileInfo fileinfo;
StorageTestPathDict_t* paths =
storage_test_paths_alloc(storage_test_dirwalk_full, COUNT_OF(storage_test_dirwalk_full));
DirWalk* dir_walk = dir_walk_alloc(storage);
mu_check(dir_walk_open(dir_walk, EXT_PATH("dirwalk")));
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
string_right(path, strlen(EXT_PATH("dirwalk/")));
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
}
dir_walk_free(dir_walk);
string_clear(path);
mu_check(storage_test_paths_check(paths) == false);
storage_test_paths_free(paths);
}
MU_TEST_1(test_dirwalk_no_recursive, Storage* storage) {
string_t path;
string_init(path);
FileInfo fileinfo;
StorageTestPathDict_t* paths = storage_test_paths_alloc(
storage_test_dirwalk_no_recursive, COUNT_OF(storage_test_dirwalk_no_recursive));
DirWalk* dir_walk = dir_walk_alloc(storage);
dir_walk_set_recursive(dir_walk, false);
mu_check(dir_walk_open(dir_walk, EXT_PATH("dirwalk")));
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
string_right(path, strlen(EXT_PATH("dirwalk/")));
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
}
dir_walk_free(dir_walk);
string_clear(path);
mu_check(storage_test_paths_check(paths) == false);
storage_test_paths_free(paths);
}
static bool test_dirwalk_filter_no_folder_ext(const char* name, FileInfo* fileinfo, void* ctx) {
UNUSED(ctx);
// only files
if(!(fileinfo->flags & FSF_DIRECTORY)) {
// with ".test" in name
if(strstr(name, ".test") != NULL) {
return true;
}
}
return false;
}
MU_TEST_1(test_dirwalk_filter, Storage* storage) {
string_t path;
string_init(path);
FileInfo fileinfo;
StorageTestPathDict_t* paths = storage_test_paths_alloc(
storage_test_dirwalk_filter, COUNT_OF(storage_test_dirwalk_filter));
DirWalk* dir_walk = dir_walk_alloc(storage);
dir_walk_set_filter_cb(dir_walk, test_dirwalk_filter_no_folder_ext, NULL);
mu_check(dir_walk_open(dir_walk, EXT_PATH("dirwalk")));
while(dir_walk_read(dir_walk, path, &fileinfo) == DirWalkOK) {
string_right(path, strlen(EXT_PATH("dirwalk/")));
mu_check(storage_test_paths_mark(paths, path, (fileinfo.flags & FSF_DIRECTORY)));
}
dir_walk_free(dir_walk);
string_clear(path);
mu_check(storage_test_paths_check(paths) == false);
storage_test_paths_free(paths);
}
MU_TEST_SUITE(test_dirwalk_suite) {
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_dirs_create(storage, EXT_PATH("dirwalk"));
MU_RUN_TEST_1(test_dirwalk_full, storage);
MU_RUN_TEST_1(test_dirwalk_no_recursive, storage);
MU_RUN_TEST_1(test_dirwalk_filter, storage);
storage_simply_remove_recursive(storage, EXT_PATH("dirwalk"));
furi_record_close(RECORD_STORAGE);
}
int run_minunit_test_dirwalk() {
MU_RUN_SUITE(test_dirwalk_suite);
return MU_EXIT_CODE;
}

View File

@@ -0,0 +1,317 @@
#include "../minunit.h"
#include <furi.h>
#include <storage/storage.h>
#define STORAGE_LOCKED_FILE EXT_PATH("locked_file.test")
#define STORAGE_LOCKED_DIR STORAGE_INT_PATH_PREFIX
static void storage_file_open_lock_setup() {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
storage_simply_remove(storage, STORAGE_LOCKED_FILE);
mu_check(storage_file_open(file, STORAGE_LOCKED_FILE, FSAM_WRITE, FSOM_CREATE_NEW));
mu_check(storage_file_write(file, "0123", 4) == 4);
mu_check(storage_file_close(file));
storage_file_free(file);
furi_record_close(RECORD_STORAGE);
}
static void storage_file_open_lock_teardown() {
Storage* storage = furi_record_open(RECORD_STORAGE);
mu_check(storage_simply_remove(storage, STORAGE_LOCKED_FILE));
furi_record_close(RECORD_STORAGE);
}
static int32_t storage_file_locker(void* ctx) {
Storage* storage = furi_record_open(RECORD_STORAGE);
FuriSemaphore* semaphore = ctx;
File* file = storage_file_alloc(storage);
furi_check(storage_file_open(file, STORAGE_LOCKED_FILE, FSAM_READ_WRITE, FSOM_OPEN_EXISTING));
furi_semaphore_release(semaphore);
furi_delay_ms(1000);
furi_check(storage_file_close(file));
furi_record_close(RECORD_STORAGE);
storage_file_free(file);
return 0;
}
MU_TEST(storage_file_open_lock) {
Storage* storage = furi_record_open(RECORD_STORAGE);
bool result = false;
FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0);
File* file = storage_file_alloc(storage);
// file_locker thread start
FuriThread* locker_thread = furi_thread_alloc();
furi_thread_set_name(locker_thread, "StorageFileLocker");
furi_thread_set_stack_size(locker_thread, 2048);
furi_thread_set_context(locker_thread, semaphore);
furi_thread_set_callback(locker_thread, storage_file_locker);
furi_thread_start(locker_thread);
// wait for file lock
furi_semaphore_acquire(semaphore, FuriWaitForever);
furi_semaphore_free(semaphore);
result = storage_file_open(file, STORAGE_LOCKED_FILE, FSAM_READ_WRITE, FSOM_OPEN_EXISTING);
storage_file_close(file);
// file_locker thread stop
mu_check(furi_thread_join(locker_thread) == FuriStatusOk);
furi_thread_free(locker_thread);
// clean data
storage_file_free(file);
furi_record_close(RECORD_STORAGE);
mu_assert(result, "cannot open locked file");
}
MU_TEST(storage_file_open_close) {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file;
file = storage_file_alloc(storage);
mu_check(storage_file_open(file, STORAGE_LOCKED_FILE, FSAM_READ_WRITE, FSOM_OPEN_EXISTING));
storage_file_close(file);
storage_file_free(file);
for(size_t i = 0; i < 10; i++) {
file = storage_file_alloc(storage);
mu_check(
storage_file_open(file, STORAGE_LOCKED_FILE, FSAM_READ_WRITE, FSOM_OPEN_EXISTING));
storage_file_free(file);
}
furi_record_close(RECORD_STORAGE);
}
MU_TEST_SUITE(storage_file) {
storage_file_open_lock_setup();
MU_RUN_TEST(storage_file_open_close);
MU_RUN_TEST(storage_file_open_lock);
storage_file_open_lock_teardown();
}
MU_TEST(storage_dir_open_close) {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file;
file = storage_file_alloc(storage);
mu_check(storage_dir_open(file, STORAGE_LOCKED_DIR));
storage_dir_close(file);
storage_file_free(file);
for(size_t i = 0; i < 10; i++) {
file = storage_file_alloc(storage);
mu_check(storage_dir_open(file, STORAGE_LOCKED_DIR));
storage_file_free(file);
}
furi_record_close(RECORD_STORAGE);
}
static int32_t storage_dir_locker(void* ctx) {
Storage* storage = furi_record_open(RECORD_STORAGE);
FuriSemaphore* semaphore = ctx;
File* file = storage_file_alloc(storage);
furi_check(storage_dir_open(file, STORAGE_LOCKED_DIR));
furi_semaphore_release(semaphore);
furi_delay_ms(1000);
furi_check(storage_dir_close(file));
furi_record_close(RECORD_STORAGE);
storage_file_free(file);
return 0;
}
MU_TEST(storage_dir_open_lock) {
Storage* storage = furi_record_open(RECORD_STORAGE);
bool result = false;
FuriSemaphore* semaphore = furi_semaphore_alloc(1, 0);
File* file = storage_file_alloc(storage);
// file_locker thread start
FuriThread* locker_thread = furi_thread_alloc();
furi_thread_set_name(locker_thread, "StorageDirLocker");
furi_thread_set_stack_size(locker_thread, 2048);
furi_thread_set_context(locker_thread, semaphore);
furi_thread_set_callback(locker_thread, storage_dir_locker);
furi_thread_start(locker_thread);
// wait for dir lock
furi_semaphore_acquire(semaphore, FuriWaitForever);
furi_semaphore_free(semaphore);
result = storage_dir_open(file, STORAGE_LOCKED_DIR);
storage_dir_close(file);
// file_locker thread stop
mu_check(furi_thread_join(locker_thread) == FuriStatusOk);
furi_thread_free(locker_thread);
// clean data
storage_file_free(file);
furi_record_close(RECORD_STORAGE);
mu_assert(result, "cannot open locked dir");
}
MU_TEST_SUITE(storage_dir) {
MU_RUN_TEST(storage_dir_open_close);
MU_RUN_TEST(storage_dir_open_lock);
}
static const char* const storage_copy_test_paths[] = {
"1",
"11",
"111",
"1/2",
"1/22",
"1/222",
"11/1",
"111/2",
"111/22",
"111/22/33",
};
static const char* const storage_copy_test_files[] = {
"file.test",
"1/file.test",
"111/22/33/file.test",
};
static bool write_file_13DA(Storage* storage, const char* path) {
File* file = storage_file_alloc(storage);
bool result = false;
if(storage_file_open(file, path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) {
result = storage_file_write(file, "13DA", 4) == 4;
}
storage_file_close(file);
storage_file_free(file);
return result;
}
static bool check_file_13DA(Storage* storage, const char* path) {
File* file = storage_file_alloc(storage);
bool result = false;
if(storage_file_open(file, path, FSAM_READ, FSOM_OPEN_EXISTING)) {
char data[10] = {0};
result = storage_file_read(file, data, 4) == 4;
if(result) {
result = memcmp(data, "13DA", 4) == 0;
}
}
storage_file_close(file);
storage_file_free(file);
return result;
}
static void storage_dir_create(Storage* storage, const char* base) {
string_t path;
string_init(path);
storage_common_mkdir(storage, base);
for(size_t i = 0; i < COUNT_OF(storage_copy_test_paths); i++) {
string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
storage_common_mkdir(storage, string_get_cstr(path));
}
for(size_t i = 0; i < COUNT_OF(storage_copy_test_files); i++) {
string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
write_file_13DA(storage, string_get_cstr(path));
}
string_clear(path);
}
static void storage_dir_remove(Storage* storage, const char* base) {
storage_simply_remove_recursive(storage, base);
}
static bool storage_dir_rename_check(Storage* storage, const char* base) {
bool result = false;
string_t path;
string_init(path);
result = (storage_common_stat(storage, base, NULL) == FSE_OK);
if(result) {
for(size_t i = 0; i < COUNT_OF(storage_copy_test_paths); i++) {
string_printf(path, "%s/%s", base, storage_copy_test_paths[i]);
result = (storage_common_stat(storage, string_get_cstr(path), NULL) == FSE_OK);
if(!result) {
break;
}
}
}
if(result) {
for(size_t i = 0; i < COUNT_OF(storage_copy_test_files); i++) {
string_printf(path, "%s/%s", base, storage_copy_test_files[i]);
result = check_file_13DA(storage, string_get_cstr(path));
if(!result) {
break;
}
}
}
string_clear(path);
return result;
}
MU_TEST(storage_file_rename) {
Storage* storage = furi_record_open(RECORD_STORAGE);
File* file = storage_file_alloc(storage);
mu_check(write_file_13DA(storage, EXT_PATH("file.old")));
mu_check(check_file_13DA(storage, EXT_PATH("file.old")));
mu_assert_int_eq(
FSE_OK, storage_common_rename(storage, EXT_PATH("file.old"), EXT_PATH("file.new")));
mu_assert_int_eq(FSE_NOT_EXIST, storage_common_stat(storage, EXT_PATH("file.old"), NULL));
mu_assert_int_eq(FSE_OK, storage_common_stat(storage, EXT_PATH("file.new"), NULL));
mu_check(check_file_13DA(storage, EXT_PATH("file.new")));
mu_assert_int_eq(FSE_OK, storage_common_remove(storage, EXT_PATH("file.new")));
storage_file_free(file);
furi_record_close(RECORD_STORAGE);
}
MU_TEST(storage_dir_rename) {
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_dir_create(storage, EXT_PATH("dir.old"));
mu_check(storage_dir_rename_check(storage, EXT_PATH("dir.old")));
mu_assert_int_eq(
FSE_OK, storage_common_rename(storage, EXT_PATH("dir.old"), EXT_PATH("dir.new")));
mu_assert_int_eq(FSE_NOT_EXIST, storage_common_stat(storage, EXT_PATH("dir.old"), NULL));
mu_check(storage_dir_rename_check(storage, EXT_PATH("dir.new")));
storage_dir_remove(storage, EXT_PATH("dir.new"));
mu_assert_int_eq(FSE_NOT_EXIST, storage_common_stat(storage, EXT_PATH("dir.new"), NULL));
furi_record_close(RECORD_STORAGE);
}
MU_TEST_SUITE(storage_rename) {
MU_RUN_TEST(storage_file_rename);
MU_RUN_TEST(storage_dir_rename);
Storage* storage = furi_record_open(RECORD_STORAGE);
storage_dir_remove(storage, EXT_PATH("dir.old"));
storage_dir_remove(storage, EXT_PATH("dir.new"));
furi_record_close(RECORD_STORAGE);
}
int run_minunit_test_storage() {
MU_RUN_SUITE(storage_file);
MU_RUN_SUITE(storage_dir);
MU_RUN_SUITE(storage_rename);
return MU_EXIT_CODE;
}