Skip to content

Commit

Permalink
Merge branch 'dev' into astra/3934-alarm-improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Astrrra authored Dec 23, 2024
2 parents 905f949 + 519b896 commit a0c087c
Show file tree
Hide file tree
Showing 115 changed files with 3,468 additions and 1,342 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ env:
DEFAULT_TARGET: f7
FBT_TOOLCHAIN_PATH: /runner/_work
FBT_GIT_SUBMODULE_SHALLOW: 1
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
main:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/build_compact.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
env:
FBT_TOOLCHAIN_PATH: /runner/_work
FBT_GIT_SUBMODULE_SHALLOW: 1
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
compact:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
env:
TARGETS: f7
DEFAULT_TARGET: f7
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
check-secret:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/merge_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:

env:
FBT_TOOLCHAIN_PATH: /runner/_work
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
merge_report:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/pvs_studio.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ env:
DEFAULT_TARGET: f7
FBT_TOOLCHAIN_PATH: /runner/_work
FBT_GIT_SUBMODULE_SHALLOW: 1
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

jobs:
analyse_c_cpp:
Expand Down
48 changes: 20 additions & 28 deletions .github/workflows/unit_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,64 +5,56 @@ on:
env:
TARGETS: f7
DEFAULT_TARGET: f7
FBT_TOOLCHAIN_PATH: /opt
FBT_TOOLCHAIN_PATH: /opt/
FBT_GIT_SUBMODULE_SHALLOW: 1

jobs:
run_units_on_bench:
runs-on: [self-hosted, FlipperZeroUnitTest]
runs-on: [ self-hosted, FlipperZeroTest ]
steps:
- name: 'Wipe workspace'
run: find ./ -mount -maxdepth 1 -exec rm -rf {} \;

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
ref: ${{ github.event.pull_request.head.sha }}

- name: 'Get flipper from device manager (mock)'
id: device
run: |
echo "flipper=auto" >> $GITHUB_OUTPUT
- name: 'Flash unit tests firmware'
id: flashing
if: success()
timeout-minutes: 10
run: |
./fbt resources firmware_latest flash SWD_TRANSPORT_SERIAL=2A0906016415303030303032 LIB_DEBUG=1 FIRMWARE_APP_SET=unit_tests FORCE=1
- name: 'Wait for flipper and format ext'
id: format_ext
if: steps.flashing.outcome == 'success'
timeout-minutes: 5
timeout-minutes: 20
run: |
source scripts/toolchain/fbtenv.sh
python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=120 await_flipper
python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} format_ext
./fbt resources firmware_latest flash LIB_DEBUG=1 FIRMWARE_APP_SET=unit_tests FORCE=1
- name: 'Copy assets and unit data, reboot and wait for flipper'
id: copy
if: steps.format_ext.outcome == 'success'
if: steps.flashing.outcome == 'success'
timeout-minutes: 7
run: |
source scripts/toolchain/fbtenv.sh
python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=15 await_flipper
rm -rf build/latest/resources/dolphin
python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} -f send build/latest/resources /ext
python3 scripts/power.py -p ${{steps.device.outputs.flipper}} reboot
python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=15 await_flipper
python3 scripts/testops.py -t=15 await_flipper
python3 scripts/storage.py -f send build/latest/resources /ext
python3 scripts/storage.py -f send /region_data /ext/.int/.region_data
python3 scripts/power.py reboot
python3 scripts/testops.py -t=30 await_flipper
- name: 'Run units and validate results'
id: run_units
if: steps.copy.outcome == 'success'
timeout-minutes: 7
run: |
source scripts/toolchain/fbtenv.sh
python3 scripts/testops.py run_units -p ${{steps.device.outputs.flipper}}
python3 scripts/testops.py run_units
- name: 'Upload test results'
if: failure() && steps.flashing.outcome == 'success' && steps.run_units.outcome != 'skipped'
uses: actions/upload-artifact@v4
with:
name: unit-tests_output
path: unit_tests*.txt

- name: 'Check GDB output'
if: failure() && steps.flashing.outcome == 'success'
run: |
./fbt gdb_trace_all SWD_TRANSPORT_SERIAL=2A0906016415303030303032 LIB_DEBUG=1 FIRMWARE_APP_SET=unit_tests FORCE=1
./fbt gdb_trace_all LIB_DEBUG=1 FIRMWARE_APP_SET=unit_tests FORCE=1
54 changes: 10 additions & 44 deletions .github/workflows/updater_test.yml
Original file line number Diff line number Diff line change
@@ -1,73 +1,39 @@
name: 'Updater test'
on:
pull_request:

env:
TARGETS: f7
DEFAULT_TARGET: f7
FBT_TOOLCHAIN_PATH: /opt
FBT_TOOLCHAIN_PATH: /opt/
FBT_GIT_SUBMODULE_SHALLOW: 1

jobs:
test_updater_on_bench:
runs-on: [self-hosted, FlipperZeroUpdaterTest]
runs-on: [self-hosted, FlipperZeroTest ]
steps:
- name: 'Wipe workspace'
run: find ./ -mount -maxdepth 1 -exec rm -rf {} \;

- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 1
submodules: false
ref: ${{ github.event.pull_request.head.sha }}

- name: 'Get flipper from device manager (mock)'
id: device
run: |
echo "flipper=auto" >> $GITHUB_OUTPUT
echo "stlink=0F020D026415303030303032" >> $GITHUB_OUTPUT
- name: 'Flashing target firmware'
id: first_full_flash
timeout-minutes: 10
timeout-minutes: 20
run: |
source scripts/toolchain/fbtenv.sh
./fbt flash_usb_full PORT=${{steps.device.outputs.flipper}} FORCE=1
python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=180 await_flipper
python3 scripts/testops.py -t=180 await_flipper
./fbt flash_usb_full FORCE=1
- name: 'Validating updater'
id: second_full_flash
timeout-minutes: 10
if: success()
run: |
source scripts/toolchain/fbtenv.sh
./fbt flash_usb PORT=${{steps.device.outputs.flipper}} FORCE=1
python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=180 await_flipper
- name: 'Get last release tag'
id: release_tag
if: failure()
run: |
echo "tag=$(git tag -l --sort=-version:refname | grep -v "rc\|RC" | head -1)" >> $GITHUB_OUTPUT
- name: 'Wipe workspace'
run: find ./ -mount -maxdepth 1 -exec rm -rf {} \;
python3 scripts/testops.py -t=180 await_flipper
./fbt flash_usb FORCE=1
python3 scripts/testops.py -t=180 await_flipper
- name: 'Checkout latest release'
uses: actions/checkout@v4
if: failure()
with:
fetch-depth: 1
ref: ${{ steps.release_tag.outputs.tag }}

- name: 'Flash last release'
if: failure()
run: |
./fbt flash SWD_TRANSPORT_SERIAL=${{steps.device.outputs.stlink}} FORCE=1
- name: 'Wait for flipper and format ext'
if: failure()
run: |
source scripts/toolchain/fbtenv.sh
python3 scripts/testops.py -p=${{steps.device.outputs.flipper}} -t=180 await_flipper
python3 scripts/storage.py -p ${{steps.device.outputs.flipper}} format_ext
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ static bool test_write(const char* file_name) {
if(!flipper_format_file_open_always(file, file_name)) break;
if(!flipper_format_write_header_cstr(file, test_filetype, test_version)) break;
if(!flipper_format_write_comment_cstr(file, "This is comment")) break;
if(!flipper_format_write_empty_line(file)) break;
if(!flipper_format_write_string_cstr(file, test_string_key, test_string_data)) break;
if(!flipper_format_write_int32(file, test_int_key, test_int_data, COUNT_OF(test_int_data)))
break;
Expand Down
108 changes: 108 additions & 0 deletions applications/debug/unit_tests/tests/furi/furi_stdio_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#include <furi.h>
#include <errno.h>
#include <stdio.h>
#include "../test.h" // IWYU pragma: keep

#define TAG "StdioTest"

#define CONTEXT_MAGIC ((void*)0xDEADBEEF)

// stdin

static char mock_in[256];
static size_t mock_in_len, mock_in_pos;

static void set_mock_in(const char* str) {
size_t len = strlen(str);
strcpy(mock_in, str);
mock_in_len = len;
mock_in_pos = 0;
}

static size_t mock_in_cb(char* buffer, size_t size, FuriWait wait, void* context) {
UNUSED(wait);
furi_check(context == CONTEXT_MAGIC);
size_t remaining = mock_in_len - mock_in_pos;
size = MIN(remaining, size);
memcpy(buffer, mock_in + mock_in_pos, size);
mock_in_pos += size;
return size;
}

void test_stdin(void) {
FuriThreadStdinReadCallback in_cb = furi_thread_get_stdin_callback();
furi_thread_set_stdin_callback(mock_in_cb, CONTEXT_MAGIC);
char buf[256];

// plain in
set_mock_in("Hello, World!\n");
fgets(buf, sizeof(buf), stdin);
mu_assert_string_eq("Hello, World!\n", buf);
mu_assert_int_eq(EOF, getchar());

// ungetc
ungetc('i', stdin);
ungetc('H', stdin);
fgets(buf, sizeof(buf), stdin);
mu_assert_string_eq("Hi", buf);
mu_assert_int_eq(EOF, getchar());

// ungetc + plain in
set_mock_in(" World");
ungetc('i', stdin);
ungetc('H', stdin);
fgets(buf, sizeof(buf), stdin);
mu_assert_string_eq("Hi World", buf);
mu_assert_int_eq(EOF, getchar());

// partial plain in
set_mock_in("Hello, World!\n");
fgets(buf, strlen("Hello") + 1, stdin);
mu_assert_string_eq("Hello", buf);
mu_assert_int_eq(',', getchar());
fgets(buf, sizeof(buf), stdin);
mu_assert_string_eq(" World!\n", buf);

furi_thread_set_stdin_callback(in_cb, CONTEXT_MAGIC);
}

// stdout

static FuriString* mock_out;
FuriThreadStdoutWriteCallback original_out_cb;

static void mock_out_cb(const char* data, size_t size, void* context) {
furi_check(context == CONTEXT_MAGIC);
// there's no furi_string_cat_strn :(
for(size_t i = 0; i < size; i++) {
furi_string_push_back(mock_out, data[i]);
}
}

static void assert_and_clear_mock_out(const char* expected) {
// return the original stdout callback for the duration of the check
// if the check fails, we don't want the error to end up in our buffer,
// we want to be able to see it!
furi_thread_set_stdout_callback(original_out_cb, CONTEXT_MAGIC);
mu_assert_string_eq(expected, furi_string_get_cstr(mock_out));
furi_thread_set_stdout_callback(mock_out_cb, CONTEXT_MAGIC);

furi_string_reset(mock_out);
}

void test_stdout(void) {
original_out_cb = furi_thread_get_stdout_callback();
furi_thread_set_stdout_callback(mock_out_cb, CONTEXT_MAGIC);
mock_out = furi_string_alloc();

puts("Hello, World!");
assert_and_clear_mock_out("Hello, World!\n");

printf("He");
printf("llo!");
fflush(stdout);
assert_and_clear_mock_out("Hello!");

furi_string_free(mock_out);
furi_thread_set_stdout_callback(original_out_cb, CONTEXT_MAGIC);
}
8 changes: 8 additions & 0 deletions applications/debug/unit_tests/tests/furi/furi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ void test_furi_memmgr(void);
void test_furi_event_loop(void);
void test_errno_saving(void);
void test_furi_primitives(void);
void test_stdin(void);
void test_stdout(void);

static int foo = 0;

Expand Down Expand Up @@ -52,6 +54,11 @@ MU_TEST(mu_test_furi_primitives) {
test_furi_primitives();
}

MU_TEST(mu_test_stdio) {
test_stdin();
test_stdout();
}

MU_TEST_SUITE(test_suite) {
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
MU_RUN_TEST(test_check);
Expand All @@ -61,6 +68,7 @@ MU_TEST_SUITE(test_suite) {
MU_RUN_TEST(mu_test_furi_pubsub);
MU_RUN_TEST(mu_test_furi_memmgr);
MU_RUN_TEST(mu_test_furi_event_loop);
MU_RUN_TEST(mu_test_stdio);
MU_RUN_TEST(mu_test_errno_saving);
MU_RUN_TEST(mu_test_furi_primitives);
}
Expand Down
Loading

0 comments on commit a0c087c

Please sign in to comment.