mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-24 03:29:57 -07:00
Merge branch 'dev' into zlo/tlsf-and-a-temple-of-memcorrupt
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#include <furi.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
#include <bit_lib/bit_lib.h>
|
||||
|
||||
MU_TEST(test_bit_lib_increment_index) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#include <bt/bt_service/bt_keys_storage.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#include <toolbox/compress.h>
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <furi.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#include <datetime/datetime.h>
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <dialogs/dialogs.h>
|
||||
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
MU_TEST(test_dialog_file_browser_set_basic_options_should_init_all_fields) {
|
||||
mu_assert(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
#include <furi.h>
|
||||
#include <m-dict.h>
|
||||
#include <toolbox/dir_walk.h>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#include <furi.h>
|
||||
#include <furi_hal_random.h>
|
||||
|
||||
@@ -2,10 +2,10 @@
|
||||
#include <flipper_format/flipper_format.h>
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <toolbox/stream/stream.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#define TEST_DIR_NAME EXT_PATH(".tmp/unit_tests/ff")
|
||||
#define TEST_DIR TEST_DIR_NAME "/"
|
||||
#define TEST_DIR_NAME EXT_PATH("unit_tests_tmp")
|
||||
|
||||
static const char* test_filetype = "Flipper File test";
|
||||
static const uint32_t test_version = 666;
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#include <flipper_format/flipper_format_i.h>
|
||||
#include <toolbox/stream/stream.h>
|
||||
#include <storage/storage.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
static const char* test_filetype = "Flipper Format test";
|
||||
static const uint32_t test_version = 666;
|
||||
@@ -298,7 +298,8 @@ MU_TEST(flipper_format_string_test) {
|
||||
MU_TEST(flipper_format_file_test) {
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
FlipperFormat* flipper_format = flipper_format_file_alloc(storage);
|
||||
mu_check(flipper_format_file_open_always(flipper_format, EXT_PATH("flipper.fff")));
|
||||
mu_check(
|
||||
flipper_format_file_open_always(flipper_format, EXT_PATH(".tmp/unit_tests/flipper.fff")));
|
||||
Stream* stream = flipper_format_get_raw_stream(flipper_format);
|
||||
|
||||
mu_check(flipper_format_write_header_cstr(flipper_format, test_filetype, test_version));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <float.h>
|
||||
#include <float_tools.h>
|
||||
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
MU_TEST(float_tools_equal_test) {
|
||||
mu_check(float_is_equal(FLT_MAX, FLT_MAX));
|
||||
|
||||
164
applications/debug/unit_tests/tests/furi/furi_event_loop.c
Normal file
164
applications/debug/unit_tests/tests/furi/furi_event_loop.c
Normal file
@@ -0,0 +1,164 @@
|
||||
#include "../test.h"
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#define TAG "TestFuriEventLoop"
|
||||
|
||||
#define EVENT_LOOP_EVENT_COUNT (256u)
|
||||
|
||||
typedef struct {
|
||||
FuriMessageQueue* mq;
|
||||
|
||||
FuriEventLoop* producer_event_loop;
|
||||
uint32_t producer_counter;
|
||||
|
||||
FuriEventLoop* consumer_event_loop;
|
||||
uint32_t consumer_counter;
|
||||
} TestFuriData;
|
||||
|
||||
bool test_furi_event_loop_producer_mq_callback(FuriMessageQueue* queue, void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriData* data = context;
|
||||
furi_check(data->mq == queue, "Invalid queue");
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG, "producer_mq_callback: %lu %lu", data->producer_counter, data->consumer_counter);
|
||||
|
||||
// Remove and add should not cause crash
|
||||
// if(data->producer_counter == EVENT_LOOP_EVENT_COUNT/2) {
|
||||
// furi_event_loop_message_queue_remove(data->producer_event_loop, data->mq);
|
||||
// furi_event_loop_message_queue_add(
|
||||
// data->producer_event_loop,
|
||||
// data->mq,
|
||||
// FuriEventLoopEventOut,
|
||||
// test_furi_event_loop_producer_mq_callback,
|
||||
// data);
|
||||
// }
|
||||
|
||||
if(data->producer_counter == EVENT_LOOP_EVENT_COUNT) {
|
||||
furi_event_loop_stop(data->producer_event_loop);
|
||||
return false;
|
||||
}
|
||||
|
||||
data->producer_counter++;
|
||||
furi_check(
|
||||
furi_message_queue_put(data->mq, &data->producer_counter, 0) == FuriStatusOk,
|
||||
"furi_message_queue_put failed");
|
||||
furi_delay_us(furi_hal_random_get() % 1000);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t test_furi_event_loop_producer(void* p) {
|
||||
furi_check(p);
|
||||
|
||||
FURI_LOG_I(TAG, "producer start");
|
||||
|
||||
TestFuriData* data = p;
|
||||
|
||||
data->producer_event_loop = furi_event_loop_alloc();
|
||||
furi_event_loop_message_queue_subscribe(
|
||||
data->producer_event_loop,
|
||||
data->mq,
|
||||
FuriEventLoopEventOut,
|
||||
test_furi_event_loop_producer_mq_callback,
|
||||
data);
|
||||
|
||||
furi_event_loop_run(data->producer_event_loop);
|
||||
|
||||
furi_event_loop_message_queue_unsubscribe(data->producer_event_loop, data->mq);
|
||||
furi_event_loop_free(data->producer_event_loop);
|
||||
|
||||
FURI_LOG_I(TAG, "producer end");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool test_furi_event_loop_consumer_mq_callback(FuriMessageQueue* queue, void* context) {
|
||||
furi_check(context);
|
||||
|
||||
TestFuriData* data = context;
|
||||
furi_check(data->mq == queue);
|
||||
|
||||
furi_delay_us(furi_hal_random_get() % 1000);
|
||||
furi_check(furi_message_queue_get(data->mq, &data->consumer_counter, 0) == FuriStatusOk);
|
||||
|
||||
FURI_LOG_I(
|
||||
TAG, "consumer_mq_callback: %lu %lu", data->producer_counter, data->consumer_counter);
|
||||
|
||||
// Remove and add should not cause crash
|
||||
// if(data->producer_counter == EVENT_LOOP_EVENT_COUNT/2) {
|
||||
// furi_event_loop_message_queue_remove(data->consumer_event_loop, data->mq);
|
||||
// furi_event_loop_message_queue_add(
|
||||
// data->consumer_event_loop,
|
||||
// data->mq,
|
||||
// FuriEventLoopEventIn,
|
||||
// test_furi_event_loop_producer_mq_callback,
|
||||
// data);
|
||||
// }
|
||||
|
||||
if(data->consumer_counter == EVENT_LOOP_EVENT_COUNT) {
|
||||
furi_event_loop_stop(data->consumer_event_loop);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int32_t test_furi_event_loop_consumer(void* p) {
|
||||
furi_check(p);
|
||||
|
||||
FURI_LOG_I(TAG, "consumer start");
|
||||
|
||||
TestFuriData* data = p;
|
||||
|
||||
data->consumer_event_loop = furi_event_loop_alloc();
|
||||
furi_event_loop_message_queue_subscribe(
|
||||
data->consumer_event_loop,
|
||||
data->mq,
|
||||
FuriEventLoopEventIn,
|
||||
test_furi_event_loop_consumer_mq_callback,
|
||||
data);
|
||||
|
||||
furi_event_loop_run(data->consumer_event_loop);
|
||||
|
||||
furi_event_loop_message_queue_unsubscribe(data->consumer_event_loop, data->mq);
|
||||
furi_event_loop_free(data->consumer_event_loop);
|
||||
|
||||
FURI_LOG_I(TAG, "consumer end");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void test_furi_event_loop(void) {
|
||||
TestFuriData data = {};
|
||||
|
||||
data.mq = furi_message_queue_alloc(16, sizeof(uint32_t));
|
||||
|
||||
FuriThread* producer_thread = furi_thread_alloc();
|
||||
furi_thread_set_name(producer_thread, "producer_thread");
|
||||
furi_thread_set_stack_size(producer_thread, 1 * 1024);
|
||||
furi_thread_set_callback(producer_thread, test_furi_event_loop_producer);
|
||||
furi_thread_set_context(producer_thread, &data);
|
||||
furi_thread_start(producer_thread);
|
||||
|
||||
FuriThread* consumer_thread = furi_thread_alloc();
|
||||
furi_thread_set_name(consumer_thread, "consumer_thread");
|
||||
furi_thread_set_stack_size(consumer_thread, 1 * 1024);
|
||||
furi_thread_set_callback(consumer_thread, test_furi_event_loop_consumer);
|
||||
furi_thread_set_context(consumer_thread, &data);
|
||||
furi_thread_start(consumer_thread);
|
||||
|
||||
// Wait for thread to complete their tasks
|
||||
furi_thread_join(producer_thread);
|
||||
furi_thread_join(consumer_thread);
|
||||
|
||||
// The test itself
|
||||
mu_assert_int_eq(data.producer_counter, data.consumer_counter);
|
||||
|
||||
// Release memory
|
||||
furi_thread_free(consumer_thread);
|
||||
furi_thread_free(producer_thread);
|
||||
furi_message_queue_free(data.mq);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <furi.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
const uint32_t context_value = 0xdeadbeef;
|
||||
const uint32_t notify_value_0 = 0x12345678;
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <furi.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#define TEST_RECORD_NAME "test/holding"
|
||||
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
#include <stdio.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
// v2 tests
|
||||
void test_furi_create_open(void);
|
||||
void test_furi_concurrent_access(void);
|
||||
void test_furi_pubsub(void);
|
||||
|
||||
void test_furi_memmgr(void);
|
||||
void test_furi_memmgr_advanced(void);
|
||||
void test_furi_memmgr_aligned8(void);
|
||||
void test_furi_event_loop(void);
|
||||
|
||||
static int foo = 0;
|
||||
|
||||
@@ -43,15 +42,19 @@ MU_TEST(mu_test_furi_memmgr) {
|
||||
test_furi_memmgr_aligned8();
|
||||
}
|
||||
|
||||
MU_TEST(mu_test_furi_event_loop) {
|
||||
test_furi_event_loop();
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_suite) {
|
||||
MU_SUITE_CONFIGURE(&test_setup, &test_teardown);
|
||||
|
||||
MU_RUN_TEST(test_check);
|
||||
|
||||
// v2 tests
|
||||
MU_RUN_TEST(mu_test_furi_create_open);
|
||||
MU_RUN_TEST(mu_test_furi_pubsub);
|
||||
MU_RUN_TEST(mu_test_furi_memmgr);
|
||||
MU_RUN_TEST(mu_test_furi_event_loop);
|
||||
}
|
||||
|
||||
int run_minunit_test_furi(void) {
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
#include "furi_hal_rtc.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include <lp5562_reg.h>
|
||||
#include "../test.h"
|
||||
#include <stdlib.h>
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#define DATA_SIZE 4
|
||||
#define EEPROM_ADDRESS 0b10101000
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#include <stdio.h>
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
static const uint8_t key_ctr_1[32] = {
|
||||
0x77, 0x6B, 0xEF, 0xF2, 0x85, 0x1D, 0xB0, 0x6F, 0x4C, 0x8A, 0x05, 0x42, 0xC8, 0x69, 0x6F, 0x6C,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <furi.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
static void test_setup(void) {
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
#include <flipper_format.h>
|
||||
#include <infrared.h>
|
||||
#include <common/infrared_common_i.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#define IR_TEST_FILES_DIR EXT_PATH("unit_tests/infrared/")
|
||||
#define IR_TEST_FILE_PREFIX "test_"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <furi.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
#include <toolbox/protocols/protocol_dict.h>
|
||||
#include <lfrfid/protocols/lfrfid_protocols.h>
|
||||
#include <toolbox/pulse_protocols/pulse_glue.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <furi.c>
|
||||
#include "../test.h"
|
||||
#include <furi.h>
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
#include <update_util/resources/manifest.h>
|
||||
|
||||
#define TAG "Manifest"
|
||||
|
||||
@@ -12,6 +12,8 @@
|
||||
#include <nfc/protocols/mf_ultralight/mf_ultralight.h>
|
||||
#include <nfc/protocols/mf_ultralight/mf_ultralight_poller_sync.h>
|
||||
#include <nfc/protocols/mf_classic/mf_classic_poller_sync.h>
|
||||
#include <nfc/protocols/felica/felica.h>
|
||||
#include <nfc/protocols/felica/felica_poller_sync.h>
|
||||
#include <nfc/protocols/mf_classic/mf_classic_poller.h>
|
||||
#include <nfc/protocols/iso15693_3/iso15693_3_poller.h>
|
||||
#include <nfc/protocols/slix/slix.h>
|
||||
@@ -24,7 +26,7 @@
|
||||
#include <toolbox/keys_dict.h>
|
||||
#include <nfc/nfc.h>
|
||||
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#define TAG "NfcTest"
|
||||
|
||||
@@ -646,6 +648,56 @@ MU_TEST(mf_classic_dict_test) {
|
||||
"Remove test dict failed");
|
||||
}
|
||||
|
||||
static FelicaError
|
||||
felica_do_request_response(FelicaData* felica_data, const FelicaCardKey* card_key) {
|
||||
NfcDeviceData* nfc_device = nfc_device_alloc();
|
||||
|
||||
FelicaError error = FelicaErrorNone;
|
||||
if(!nfc_device_load(nfc_device, EXT_PATH("unit_tests/nfc/Felica.nfc"))) {
|
||||
error = FelicaErrorNotPresent;
|
||||
} else {
|
||||
Nfc* poller = nfc_alloc();
|
||||
Nfc* listener = nfc_alloc();
|
||||
NfcListener* felica_listener = nfc_listener_alloc(
|
||||
listener, NfcProtocolFelica, nfc_device_get_data(nfc_device, NfcProtocolFelica));
|
||||
nfc_listener_start(felica_listener, NULL, NULL);
|
||||
|
||||
error = felica_poller_sync_read(poller, felica_data, card_key);
|
||||
|
||||
nfc_listener_stop(felica_listener);
|
||||
nfc_listener_free(felica_listener);
|
||||
|
||||
nfc_free(listener);
|
||||
nfc_free(poller);
|
||||
}
|
||||
|
||||
nfc_device_free(nfc_device);
|
||||
return error;
|
||||
}
|
||||
|
||||
MU_TEST(felica_read) {
|
||||
FelicaData* felica_data = felica_alloc();
|
||||
FelicaError error = felica_do_request_response(felica_data, NULL);
|
||||
mu_assert(error == FelicaErrorNone, "felica_poller() failed");
|
||||
mu_assert(felica_data->data.fs.spad[4].SF1 == 0x01, "block[4].SF1 != 0x01");
|
||||
mu_assert(felica_data->data.fs.spad[4].SF2 == 0xB1, "block[4].SF2 != 0xB1");
|
||||
|
||||
felica_free(felica_data);
|
||||
}
|
||||
|
||||
MU_TEST(felica_read_auth) {
|
||||
FelicaData* felica_data = felica_alloc();
|
||||
FelicaCardKey card_key;
|
||||
memset(card_key.data, 0xFF, FELICA_DATA_BLOCK_SIZE);
|
||||
|
||||
FelicaError error = felica_do_request_response(felica_data, &card_key);
|
||||
mu_assert(error == FelicaErrorNone, "felica_poller() failed");
|
||||
mu_assert(felica_data->data.fs.spad[4].SF1 == 0x00, "block[4].SF1 != 0x00");
|
||||
mu_assert(felica_data->data.fs.spad[4].SF2 == 0x00, "block[4].SF2 != 0x00");
|
||||
|
||||
felica_free(felica_data);
|
||||
}
|
||||
|
||||
MU_TEST(slix_file_with_capabilities_test) {
|
||||
NfcDevice* nfc_device_missed_cap = nfc_device_alloc();
|
||||
mu_assert(
|
||||
@@ -807,6 +859,8 @@ MU_TEST_SUITE(nfc) {
|
||||
MU_RUN_TEST(mf_classic_value_block);
|
||||
MU_RUN_TEST(mf_classic_send_frame_test);
|
||||
MU_RUN_TEST(mf_classic_dict_test);
|
||||
MU_RUN_TEST(felica_read);
|
||||
MU_RUN_TEST(felica_read_auth);
|
||||
|
||||
MU_RUN_TEST(slix_file_with_capabilities_test);
|
||||
MU_RUN_TEST(slix_set_password_default_cap_correct_pass);
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
static void power_test_deinit(void) {
|
||||
// Try to reset to default charge voltage limit
|
||||
@@ -13,46 +13,47 @@ MU_TEST(test_power_charge_voltage_limit_exact) {
|
||||
//
|
||||
// This test may need adapted if other charge controllers are used in the future.
|
||||
for(uint16_t charge_mv = 3840; charge_mv <= 4208; charge_mv += 16) {
|
||||
float charge_volt = (float)charge_mv / 1000.0f;
|
||||
float charge_volt = (float)charge_mv / 1000;
|
||||
furi_hal_power_set_battery_charge_voltage_limit(charge_volt);
|
||||
mu_assert_double_eq(charge_volt, furi_hal_power_get_battery_charge_voltage_limit());
|
||||
mu_assert_double_eq(
|
||||
(double)charge_volt, (double)furi_hal_power_get_battery_charge_voltage_limit());
|
||||
}
|
||||
}
|
||||
|
||||
MU_TEST(test_power_charge_voltage_limit_floating_imprecision) {
|
||||
// 4.016f should act as 4.016 V, even with floating point imprecision
|
||||
furi_hal_power_set_battery_charge_voltage_limit(4.016f);
|
||||
mu_assert_double_eq(4.016f, furi_hal_power_get_battery_charge_voltage_limit());
|
||||
mu_assert_double_eq(4.016, (double)furi_hal_power_get_battery_charge_voltage_limit());
|
||||
}
|
||||
|
||||
MU_TEST(test_power_charge_voltage_limit_inexact) {
|
||||
// Charge voltage limits that are not power of 16mV get truncated down
|
||||
furi_hal_power_set_battery_charge_voltage_limit(3.841f);
|
||||
mu_assert_double_eq(3.840, furi_hal_power_get_battery_charge_voltage_limit());
|
||||
mu_assert_double_eq(3.840, (double)furi_hal_power_get_battery_charge_voltage_limit());
|
||||
|
||||
furi_hal_power_set_battery_charge_voltage_limit(3.900f);
|
||||
mu_assert_double_eq(3.888, furi_hal_power_get_battery_charge_voltage_limit());
|
||||
mu_assert_double_eq(3.888, (double)furi_hal_power_get_battery_charge_voltage_limit());
|
||||
|
||||
furi_hal_power_set_battery_charge_voltage_limit(4.200f);
|
||||
mu_assert_double_eq(4.192, furi_hal_power_get_battery_charge_voltage_limit());
|
||||
mu_assert_double_eq(4.192, (double)furi_hal_power_get_battery_charge_voltage_limit());
|
||||
}
|
||||
|
||||
MU_TEST(test_power_charge_voltage_limit_invalid_clamped) {
|
||||
// Out-of-range charge voltage limits get clamped to 3.840 V and 4.208 V
|
||||
furi_hal_power_set_battery_charge_voltage_limit(3.808f);
|
||||
mu_assert_double_eq(3.840, furi_hal_power_get_battery_charge_voltage_limit());
|
||||
mu_assert_double_eq(3.840, (double)furi_hal_power_get_battery_charge_voltage_limit());
|
||||
furi_hal_power_set_battery_charge_voltage_limit(1.0f);
|
||||
mu_assert_double_eq(3.840, furi_hal_power_get_battery_charge_voltage_limit());
|
||||
mu_assert_double_eq(3.840, (double)furi_hal_power_get_battery_charge_voltage_limit());
|
||||
|
||||
// NOTE: Intentionally picking a small increment above 4.208 V to reduce the risk of an
|
||||
// unhappy battery if this fails.
|
||||
furi_hal_power_set_battery_charge_voltage_limit(4.240f);
|
||||
mu_assert_double_eq(4.208, furi_hal_power_get_battery_charge_voltage_limit());
|
||||
mu_assert_double_eq(4.208, (double)furi_hal_power_get_battery_charge_voltage_limit());
|
||||
// Likewise, picking a number that the uint8_t wraparound in the driver would result in a
|
||||
// VREG value under 23 if this test fails.
|
||||
// E.g. (uint8_t)((8105-3840)/16) -> 10
|
||||
furi_hal_power_set_battery_charge_voltage_limit(8.105f);
|
||||
mu_assert_double_eq(4.208, furi_hal_power_get_battery_charge_voltage_limit());
|
||||
mu_assert_double_eq(4.208, (double)furi_hal_power_get_battery_charge_voltage_limit());
|
||||
}
|
||||
|
||||
MU_TEST_SUITE(test_power_suite) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <furi.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
#include <toolbox/protocols/protocol_dict.h>
|
||||
|
||||
typedef enum {
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
#include <core/check.h>
|
||||
#include <core/record.h>
|
||||
#include <furi.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include <FreeRTOS.h>
|
||||
#include <semphr.h>
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
#include <rpc/rpc_i.h>
|
||||
#include <cli/cli.h>
|
||||
@@ -17,7 +12,7 @@
|
||||
#include <lib/toolbox/path.h>
|
||||
|
||||
#include <m-list.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#include <protobuf_version.h>
|
||||
#include <pb.h>
|
||||
@@ -40,8 +35,8 @@ static uint32_t command_id = 0;
|
||||
typedef struct {
|
||||
RpcSession* session;
|
||||
FuriStreamBuffer* output_stream;
|
||||
SemaphoreHandle_t close_session_semaphore;
|
||||
SemaphoreHandle_t terminate_semaphore;
|
||||
FuriSemaphore* close_session_semaphore;
|
||||
FuriSemaphore* terminate_semaphore;
|
||||
uint32_t timeout;
|
||||
} RpcSessionContext;
|
||||
|
||||
@@ -51,8 +46,8 @@ static RpcSessionContext rpc_session[TEST_RPC_SESSIONS];
|
||||
#define MAX_RECEIVE_OUTPUT_TIMEOUT 3000
|
||||
#define MAX_NAME_LENGTH 255
|
||||
#define MAX_DATA_SIZE 512u // have to be exact as in rpc_storage.c
|
||||
#define TEST_DIR_NAME EXT_PATH(".tmp/unit_tests/rpc")
|
||||
#define TEST_DIR TEST_DIR_NAME "/"
|
||||
#define TEST_DIR_NAME EXT_PATH("unit_tests_tmp")
|
||||
#define MD5SUM_SIZE 16
|
||||
|
||||
#define PING_REQUEST 0
|
||||
@@ -96,8 +91,8 @@ static void test_rpc_setup(void) {
|
||||
|
||||
rpc_session[0].output_stream = furi_stream_buffer_alloc(4096, 1);
|
||||
rpc_session_set_send_bytes_callback(rpc_session[0].session, output_bytes_callback);
|
||||
rpc_session[0].close_session_semaphore = xSemaphoreCreateBinary();
|
||||
rpc_session[0].terminate_semaphore = xSemaphoreCreateBinary();
|
||||
rpc_session[0].close_session_semaphore = furi_semaphore_alloc(1, 0);
|
||||
rpc_session[0].terminate_semaphore = furi_semaphore_alloc(1, 0);
|
||||
rpc_session_set_close_callback(rpc_session[0].session, test_rpc_session_close_callback);
|
||||
rpc_session_set_terminated_callback(
|
||||
rpc_session[0].session, test_rpc_session_terminated_callback);
|
||||
@@ -116,8 +111,8 @@ static void test_rpc_setup_second_session(void) {
|
||||
|
||||
rpc_session[1].output_stream = furi_stream_buffer_alloc(1000, 1);
|
||||
rpc_session_set_send_bytes_callback(rpc_session[1].session, output_bytes_callback);
|
||||
rpc_session[1].close_session_semaphore = xSemaphoreCreateBinary();
|
||||
rpc_session[1].terminate_semaphore = xSemaphoreCreateBinary();
|
||||
rpc_session[1].close_session_semaphore = furi_semaphore_alloc(1, 0);
|
||||
rpc_session[1].terminate_semaphore = furi_semaphore_alloc(1, 0);
|
||||
rpc_session_set_close_callback(rpc_session[1].session, test_rpc_session_close_callback);
|
||||
rpc_session_set_terminated_callback(
|
||||
rpc_session[1].session, test_rpc_session_terminated_callback);
|
||||
@@ -126,13 +121,15 @@ static void test_rpc_setup_second_session(void) {
|
||||
|
||||
static void test_rpc_teardown(void) {
|
||||
furi_check(rpc_session[0].close_session_semaphore);
|
||||
xSemaphoreTake(rpc_session[0].terminate_semaphore, 0);
|
||||
furi_semaphore_acquire(rpc_session[0].terminate_semaphore, 0);
|
||||
rpc_session_close(rpc_session[0].session);
|
||||
furi_check(xSemaphoreTake(rpc_session[0].terminate_semaphore, portMAX_DELAY));
|
||||
furi_check(
|
||||
furi_semaphore_acquire(rpc_session[0].terminate_semaphore, FuriWaitForever) ==
|
||||
FuriStatusOk);
|
||||
furi_record_close(RECORD_RPC);
|
||||
furi_stream_buffer_free(rpc_session[0].output_stream);
|
||||
vSemaphoreDelete(rpc_session[0].close_session_semaphore);
|
||||
vSemaphoreDelete(rpc_session[0].terminate_semaphore);
|
||||
furi_semaphore_free(rpc_session[0].close_session_semaphore);
|
||||
furi_semaphore_free(rpc_session[0].terminate_semaphore);
|
||||
++command_id;
|
||||
rpc_session[0].output_stream = NULL;
|
||||
rpc_session[0].close_session_semaphore = NULL;
|
||||
@@ -142,12 +139,14 @@ static void test_rpc_teardown(void) {
|
||||
|
||||
static void test_rpc_teardown_second_session(void) {
|
||||
furi_check(rpc_session[1].close_session_semaphore);
|
||||
xSemaphoreTake(rpc_session[1].terminate_semaphore, 0);
|
||||
furi_semaphore_acquire(rpc_session[1].terminate_semaphore, 0);
|
||||
rpc_session_close(rpc_session[1].session);
|
||||
furi_check(xSemaphoreTake(rpc_session[1].terminate_semaphore, portMAX_DELAY));
|
||||
furi_check(
|
||||
furi_semaphore_acquire(rpc_session[1].terminate_semaphore, FuriWaitForever) ==
|
||||
FuriStatusOk);
|
||||
furi_stream_buffer_free(rpc_session[1].output_stream);
|
||||
vSemaphoreDelete(rpc_session[1].close_session_semaphore);
|
||||
vSemaphoreDelete(rpc_session[1].terminate_semaphore);
|
||||
furi_semaphore_free(rpc_session[1].close_session_semaphore);
|
||||
furi_semaphore_free(rpc_session[1].terminate_semaphore);
|
||||
++command_id;
|
||||
rpc_session[1].output_stream = NULL;
|
||||
rpc_session[1].close_session_semaphore = NULL;
|
||||
@@ -204,14 +203,14 @@ static void test_rpc_session_close_callback(void* context) {
|
||||
furi_check(context);
|
||||
RpcSessionContext* callbacks_context = context;
|
||||
|
||||
xSemaphoreGive(callbacks_context->close_session_semaphore);
|
||||
furi_check(furi_semaphore_release(callbacks_context->close_session_semaphore) == FuriStatusOk);
|
||||
}
|
||||
|
||||
static void test_rpc_session_terminated_callback(void* context) {
|
||||
furi_check(context);
|
||||
RpcSessionContext* callbacks_context = context;
|
||||
|
||||
xSemaphoreGive(callbacks_context->terminate_semaphore);
|
||||
furi_check(furi_semaphore_release(callbacks_context->terminate_semaphore) == FuriStatusOk);
|
||||
}
|
||||
|
||||
static void test_rpc_print_message_list(MsgList_t msg_list) {
|
||||
@@ -1645,7 +1644,7 @@ static void test_rpc_feed_rubbish_run(
|
||||
|
||||
test_rpc_add_empty_to_list(expected, PB_CommandStatus_ERROR_DECODE, 0);
|
||||
|
||||
furi_check(!xSemaphoreTake(rpc_session[0].close_session_semaphore, 0));
|
||||
furi_check(furi_semaphore_acquire(rpc_session[0].close_session_semaphore, 0) != FuriStatusOk);
|
||||
test_rpc_encode_and_feed(input_before, 0);
|
||||
test_send_rubbish(rpc_session[0].session, pattern, pattern_size, size);
|
||||
test_rpc_encode_and_feed(input_after, 0);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
#include <furi.h>
|
||||
#include <storage/storage.h>
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <toolbox/stream/file_stream.h>
|
||||
#include <toolbox/stream/buffered_file_stream.h>
|
||||
#include <storage/storage.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
static const char* stream_test_data = "I write differently from what I speak, "
|
||||
"I speak differently from what I think, "
|
||||
@@ -15,6 +15,8 @@ static const char* stream_test_left_data = "There are two cardinal human sins ";
|
||||
static const char* stream_test_right_data =
|
||||
"from which all others derive: impatience and indolence.";
|
||||
|
||||
#define FILESTREAM_PATH EXT_PATH(".tmp/unit_tests/filestream.str")
|
||||
|
||||
MU_TEST_1(stream_composite_subtest, Stream* stream) {
|
||||
const size_t data_size = 128;
|
||||
uint8_t data[data_size];
|
||||
@@ -304,15 +306,14 @@ MU_TEST(stream_composite_test) {
|
||||
// test file stream
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
stream = file_stream_alloc(storage);
|
||||
mu_check(
|
||||
file_stream_open(stream, EXT_PATH("filestream.str"), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
mu_check(file_stream_open(stream, FILESTREAM_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
MU_RUN_TEST_1(stream_composite_subtest, stream);
|
||||
stream_free(stream);
|
||||
|
||||
// test buffered file stream
|
||||
stream = buffered_file_stream_alloc(storage);
|
||||
mu_check(buffered_file_stream_open(
|
||||
stream, EXT_PATH("filestream.str"), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
mu_check(
|
||||
buffered_file_stream_open(stream, FILESTREAM_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
MU_RUN_TEST_1(stream_composite_subtest, stream);
|
||||
stream_free(stream);
|
||||
furi_record_close(RECORD_STORAGE);
|
||||
@@ -346,7 +347,7 @@ MU_TEST(stream_write_read_save_load_test) {
|
||||
mu_check(stream_seek(stream_orig, 0, StreamOffsetFromStart));
|
||||
mu_assert_int_eq(
|
||||
strlen(stream_test_data),
|
||||
stream_save_to_file(stream_orig, storage, EXT_PATH("filestream.str"), FSOM_CREATE_ALWAYS));
|
||||
stream_save_to_file(stream_orig, storage, FILESTREAM_PATH, FSOM_CREATE_ALWAYS));
|
||||
|
||||
stream_free(stream_copy);
|
||||
stream_free(stream_orig);
|
||||
@@ -354,8 +355,7 @@ MU_TEST(stream_write_read_save_load_test) {
|
||||
// load from file, read
|
||||
Stream* stream_new = string_stream_alloc();
|
||||
mu_assert_int_eq(
|
||||
strlen(stream_test_data),
|
||||
stream_load_from_file(stream_new, storage, EXT_PATH("filestream.str")));
|
||||
strlen(stream_test_data), stream_load_from_file(stream_new, storage, FILESTREAM_PATH));
|
||||
MU_RUN_TEST_1(stream_read_subtest, stream_new);
|
||||
stream_free(stream_new);
|
||||
|
||||
@@ -396,15 +396,14 @@ MU_TEST(stream_split_test) {
|
||||
// test file stream
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
stream = file_stream_alloc(storage);
|
||||
mu_check(
|
||||
file_stream_open(stream, EXT_PATH("filestream.str"), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
mu_check(file_stream_open(stream, FILESTREAM_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
MU_RUN_TEST_1(stream_split_subtest, stream);
|
||||
stream_free(stream);
|
||||
|
||||
// test buffered stream
|
||||
stream = buffered_file_stream_alloc(storage);
|
||||
mu_check(buffered_file_stream_open(
|
||||
stream, EXT_PATH("filestream.str"), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
mu_check(
|
||||
buffered_file_stream_open(stream, FILESTREAM_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
MU_RUN_TEST_1(stream_split_subtest, stream);
|
||||
stream_free(stream);
|
||||
|
||||
@@ -424,8 +423,8 @@ MU_TEST(stream_buffered_write_after_read_test) {
|
||||
|
||||
Storage* storage = furi_record_open(RECORD_STORAGE);
|
||||
Stream* stream = buffered_file_stream_alloc(storage);
|
||||
mu_check(buffered_file_stream_open(
|
||||
stream, EXT_PATH("filestream.str"), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
mu_check(
|
||||
buffered_file_stream_open(stream, FILESTREAM_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
mu_assert_int_eq(strlen(stream_test_data), stream_write_cstring(stream, stream_test_data));
|
||||
mu_check(stream_rewind(stream));
|
||||
mu_assert_int_eq(prefix_len, stream_read(stream, (uint8_t*)buf, prefix_len));
|
||||
@@ -458,8 +457,8 @@ MU_TEST(stream_buffered_large_file_test) {
|
||||
|
||||
// write test data to file
|
||||
Stream* stream = buffered_file_stream_alloc(storage);
|
||||
mu_check(buffered_file_stream_open(
|
||||
stream, EXT_PATH("filestream.str"), FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
mu_check(
|
||||
buffered_file_stream_open(stream, FILESTREAM_PATH, FSAM_READ_WRITE, FSOM_CREATE_ALWAYS));
|
||||
mu_assert_int_eq(0, stream_size(stream));
|
||||
mu_assert_int_eq(furi_string_size(input_data), stream_write_string(stream, input_data));
|
||||
mu_assert_int_eq(furi_string_size(input_data), stream_size(stream));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
#include <lib/subghz/receiver.h>
|
||||
#include <lib/subghz/transmitter.h>
|
||||
#include <lib/subghz/subghz_keystore.h>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include <furi.h>
|
||||
#include <furi_hal.h>
|
||||
|
||||
#include "../test.h"
|
||||
#include "../test.h" // IWYU pragma: keep
|
||||
|
||||
#include <toolbox/varint.h>
|
||||
#include <toolbox/profiler.h>
|
||||
|
||||
Reference in New Issue
Block a user