Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issues encountered during 1.4.0 rc.1 testing #1898

Merged
merged 11 commits into from Aug 30, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -54,7 +54,7 @@ void SessionPersist::prepare_save(const uint8_t* random, uint32_t keys_checksum,
{
this->keys_checksum = keys_checksum;
in_epoch = context->in_epoch;
memcpy(out_ctr, context->out_ctr, 8);
memcpy(out_ctr, context->cur_out_ctr, 8);
memcpy(randbytes, random, sizeof(randbytes));
this->next_coap_id = next_id;
save_session(context->session);
@@ -70,7 +70,7 @@ void SessionPersist::update(mbedtls_ssl_context* context, save_fn_t saver, messa
{
if (context->state == MBEDTLS_SSL_HANDSHAKE_OVER)
{
memcpy(out_ctr, context->out_ctr, 8);
memcpy(out_ctr, context->cur_out_ctr, 8);
this->next_coap_id = next_id;
save_this_with(saver);
}
@@ -116,7 +116,7 @@ auto SessionPersist::restore(mbedtls_ssl_context* context, bool renegotiate, uin
if (!renegotiate) {
context->state = MBEDTLS_SSL_HANDSHAKE_WRAPUP;
context->in_epoch = in_epoch;
memcpy(context->out_ctr, &out_ctr, sizeof(out_ctr));
memcpy(context->cur_out_ctr, &out_ctr, sizeof(out_ctr));
memcpy(context->handshake->randbytes, randbytes, sizeof(randbytes));
context->transform_negotiate->ciphersuite_info = mbedtls_ssl_ciphersuite_from_id(ciphersuite);
if (!context->transform_negotiate->ciphersuite_info)
@@ -1728,14 +1728,14 @@
*
* This module provides debugging functions.
*/
//#define MBEDTLS_DEBUG_C
#define MBEDTLS_DEBUG_C

/**
* \def MBEDTLS_DEBUG_COMPILE_TIME_LEVEL
*
* Set the maximum log level in compile time.
*/
//#define MBEDTLS_DEBUG_COMPILE_TIME_LEVEL 1
#define MBEDTLS_DEBUG_COMPILE_TIME_LEVEL 1

/**
* \def MBEDTLS_DES_C
@@ -284,8 +284,54 @@ int cellular_signal(CellularSignalHal* signal, cellular_signal_t* signalExt) {
const auto strn = s.strength();
const auto qual = s.quality();
if (signal) {
signal->rssi = strn;
signal->qual = qual;
// Compatibility with Gen 2
if (strn != 99 && strn != 255) {
int compatStrn = strn;
switch (s.strengthUnits()) {
case CellularStrengthUnits::RXLEV: {
// Leave as-is
break;
}
case CellularStrengthUnits::RSCP: {
// Simply re-map from [0-96] to [0-63]
compatStrn = (compatStrn * 63) / 96;
break;
}
case CellularStrengthUnits::RSRP: {
// Simply remap from [0-97] to [0-63]
compatStrn = (compatStrn * 63) / 97;
break;
}
}
// -113 to -50dBm
signal->rssi = -113 + compatStrn;
}
// see 3GPP TS 45.008 [20] subclause 8.2.4
static const char compatQualMap[] = { 49, 43, 37, 25, 19, 13, 7, 0 };
if (qual != 99 && qual != 255) {
int compatQual = qual;
switch (s.qualityUnits()) {
case CellularQualityUnits::RXQUAL:
case CellularQualityUnits::MEAN_BEP: {
// Leave as-is
break;
}
case CellularQualityUnits::ECN0: {
// Re-map from [0-49] to [0-7]. Table in UBX-13002752 - R62 (7.2.4)
compatQual = 7 - ((std::max(std::min(compatQual, 44), 2) - 2) / 6);
break;
}
case CellularQualityUnits::RSRQ: {
// Re-map from [0-34] to [0-7]. Table in UBX-13002752 - R62 (7.2.4)
compatQual = (compatQual < 10) ? (compatQual / 5) : ((std::min(compatQual, 30) - 10) / 4) + 2;
break;
}
}
// Just in case validate that we are not going to go out of bounds
if (compatQual >= 0 && compatQual <= 7) {
signal->qual = compatQualMap[compatQual];
}
}

This comment has been minimized.

Copy link
@technobly

technobly Aug 30, 2019

Member

Since we already calculate the signal/qual in signalExt, could we fix this with less code and more accuracy by adding signal->rssi = signalExt->rsrp / 100; and signal->qual = signalExt->rsrq / 100; in cellular_hal.cpp? I would like to make sure we are not calculating two different things for the Cellular.RSSI() API and Vitals. Also there is a ch35974 for this.

This comment has been minimized.

Copy link
@avtolstoy

avtolstoy Aug 30, 2019

Author Member

We can't. This is exactly what is needed to provide the compatibility with what's available on Electron. Going forward we simply need to encourage the usage of https://docs.particle.io/reference/device-os/firmware/boron/#cellularsignal-class, which is the same thing that the vitals are using.

}
if (signalExt) {
signalExt->rat = fromCellularAccessTechnology(s.accessTechnology());
@@ -311,7 +311,7 @@ void HAL_Core_Config(void) {
#if defined(MODULAR_FIRMWARE)
if (HAL_Core_Validate_User_Module()) {
new_heap_end = module_user_pre_init();
if (new_heap_end > malloc_heap_end()) {
if (new_heap_end < malloc_heap_end()) {
malloc_set_heap_end(new_heap_end);
}
} else {
@@ -1698,7 +1698,7 @@
*
* This module provides debugging functions.
*/
//#define MBEDTLS_DEBUG_C
#define MBEDTLS_DEBUG_C

/**
* \def MBEDTLS_DEBUG_COMPILE_TIME_LEVEL
@@ -13,7 +13,6 @@ endif
ifeq ("$(LOG_SERIAL)","y")
CFLAGS += -DLOG_SERIAL
CXXFLAGS += -DLOG_SERIAL
$(error "test")
endif

ifeq ("$(LOG_SERIAL1)","y")
@@ -141,7 +141,6 @@ test(CELLULAR_06_resolve) {
assertEqual(addr, 0);
}

// FIXME: This test is failing on Gen 3 Boron / B SoM as of 1.1.0 or earlier
test(CELLULAR_07_rssi_is_valid) {
connect_to_cloud(6*60*1000);
CellularSignal s;
@@ -160,6 +159,15 @@ test(CELLULAR_07_rssi_is_valid) {
#define LOREM "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque ut elit nec mi bibendum mollis. Nam nec nisl mi. Donec dignissim iaculis purus, ut condimentum arcu semper quis. Phasellus efficitur ut arcu ac dignissim. In interdum sem id dictum luctus. Ut nec mattis sem. Nullam in aliquet lacus. Donec egestas nisi volutpat lobortis sodales. Aenean elementum magna ipsum, vitae pretium tellus lacinia eu. Phasellus commodo nisi at quam tincidunt, tempor gravida mauris facilisis. Duis tristique ligula ac pulvinar consectetur. Cras aliquam, leo ut eleifend molestie, arcu odio semper odio, quis sollicitudin metus libero et lorem. Donec venenatis congue commodo. Vivamus mattis elit metus, sed fringilla neque viverra eu. Phasellus leo urna, elementum vel pharetra sit amet, auctor non sapien. Phasellus at justo ac augue rutrum vulputate. In hac habitasse platea dictumst. Pellentesque nibh eros, placerat id laoreet sed, dapibus efficitur augue. Praesent pretium diam ac sem varius fermentum. Nunc suscipit dui risus sed"

test(MDM_01_socket_writes_with_length_more_than_1023_work_correctly) {

#if HAL_PLATFORM_NCP
// CH32073
if (cellular_modem_type() == DEV_SARA_R410) {
skip();
return;
}
#endif // HAL_PLATFORM_NCP

// https://github.com/spark/firmware/issues/1104
const char request[] =
"POST /post HTTP/1.1\r\n"
@@ -213,9 +221,6 @@ test(MDM_01_socket_writes_with_length_more_than_1023_work_correctly) {
assertTrue(contains);
}

// TODO: Cellular.command() is not implemented on Gen 3 devices
#if !HAL_PLATFORM_NCP

static int atCallback(int type, const char* buf, int len, int* lines) {
if (len && type == TYPE_UNKNOWN)
(*lines)++;
@@ -242,6 +247,8 @@ test(MDM_02_at_commands_with_long_response_are_correctly_parsed_and_flow_control
assertMoreOrEqual(lines, 200);
}

#endif // !HAL_PLATFORM_NCP
test(MDM_03_restore_cloud_connection) {
connect_to_cloud(6*60*1000);
}

#endif // Wiring_Cellular == 1
@@ -26,7 +26,11 @@ test(MESH_01_PublishWithoutSubscribeStillReadsDataOutOfPubSubSocket) {

static const constexpr unsigned MAX_ITERATIONS = 1000;

assertTrue(network_has_credentials(NETWORK_INTERFACE_MESH, 0, nullptr));
if (!network_has_credentials(NETWORK_INTERFACE_MESH, 0, nullptr)) {
// Simply skip this test if there are no mesh credentials
skip();
return;
}

// Make sure the device is a known (deinitialized) state
Mesh.uninitializeUdp();
@@ -52,6 +52,17 @@ const uint8_t pwm_pins[] = {

static pin_t pin = pwm_pins[0];

test(PWM_00_prepare) {
#if (PLATFORM_ID == 8) // P1
// disable POWERSAVE_CLOCK on P1S6
System.disableFeature(FEATURE_WIFI_POWERSAVE_CLOCK);
#endif // (PLATFORM_ID == 8) // P1

// Disconnect network and cloud
Particle.disconnect();
Network.disconnect();
}

#if (PLATFORM_ID == 8) // P1
test(PWM_00_P1S6SetupForP1) {
// disable POWERSAVE_CLOCK on P1S6
@@ -546,9 +557,14 @@ test(PWM_10_HighFrequencyAnalogWriteOnPinResultsInCorrectPulseWidth) {
});
}

test(PWM_11_restore) {
#if (PLATFORM_ID == 8) // P1
test(PWM_11_P1S6CleanupForP1) {
// enable POWERSAVE_CLOCK on P1S6
System.enableFeature(FEATURE_WIFI_POWERSAVE_CLOCK);
#endif // (PLATFORM_ID == 8)

// Restore network and cloud connection
Network.connect();
Particle.connect();
waitFor(Particle.connected, 6*60*1000);
}
#endif
@@ -1,7 +1,7 @@

#include "application.h"
#include "unit-test/unit-test.h"

#include "random.h"

#if PLATFORM_ID >= 3
test(SYSTEM_01_freeMemory)
@@ -142,7 +142,8 @@ test(SYSTEM_05_button_mirror_disable)
bool oomEventReceived = false;
size_t oomSizeReceived = 0;
void handle_oom(system_event_t event, int param, void*) {
Serial.printlnf("got event %d %d", event, param);
// Serial is not thread-safe
// Serial.printlnf("got event %d %d", event, param);
if (out_of_memory==event) {
oomEventReceived = true;
oomSizeReceived = param;
@@ -159,9 +160,12 @@ void unregister_oom() {
System.off(out_of_memory, handle_oom);
}


test(SYSTEM_06_out_of_memory)
{
// Disconnect from the cloud and network just in case
Particle.disconnect();
Network.disconnect();

const size_t size = 1024*1024*1024;
register_oom();
malloc(size);
@@ -173,17 +177,25 @@ test(SYSTEM_06_out_of_memory)
}

test(SYSTEM_07_fragmented_heap) {
struct block {
struct Block {
Block() {
// Write garbage data to more easily corrupt the RAM
// in case of issues like static RAM / heap overlap or
// just simple heap corruption
Random rng;
rng.gen(data, sizeof(data));
next = nullptr;
}
char data[508];
block* next;
Block* next;
};
register_oom();

block* next = nullptr;
Block* next = nullptr;

// exhaust memory
for (;;) {
block* b = new block();
Block* b = new Block();
if (!b) {
break;
} else {
@@ -193,21 +205,21 @@ test(SYSTEM_07_fragmented_heap) {
}

assertTrue(oomEventReceived);
assertEqual(oomSizeReceived, sizeof(block));
assertEqual(oomSizeReceived, sizeof(Block));

runtime_info_t info;
info.size = sizeof(info);
HAL_Core_Runtime_Info(&info, nullptr);

// we can't really say about the free heap but the block size should be less
assertLessOrEqual(info.largest_free_block_heap, sizeof(block));
assertLessOrEqual(info.largest_free_block_heap, sizeof(Block));
size_t low_heap = info.freeheap;

// free every 2nd block
block* head = next;
Block* head = next;
int count = 0;
for (;head;) {
block* free = head->next;
Block* free = head->next;
if (free) {
// skip the next block
head->next = free->next;
@@ -226,22 +238,22 @@ test(SYSTEM_07_fragmented_heap) {
unregister_oom();
register_oom();
const size_t BLOCKS_TO_MALLOC = 3;
block* b = new block[BLOCKS_TO_MALLOC]; // no room for 3 blocks, memory is clearly fragmented
delete b;
Block* b = new Block[BLOCKS_TO_MALLOC]; // no room for 3 blocks, memory is clearly fragmented
delete[] b;

// free the remaining blocks
for (;next;) {
block* b = next;
Block* b = next;
next = b->next;
delete b;
}

assertMoreOrEqual(half_fragment_block_size, sizeof(block)); // there should definitely be one block available
assertLessOrEqual(half_fragment_block_size, BLOCKS_TO_MALLOC*sizeof(block)-1); // we expect malloc of 3 blocks to fail, so this better allow up to that size less 1
assertMoreOrEqual(half_fragment_free, low_heap+(sizeof(block)*count));
assertMoreOrEqual(half_fragment_block_size, sizeof(Block)); // there should definitely be one block available
assertLessOrEqual(half_fragment_block_size, BLOCKS_TO_MALLOC*sizeof(Block)-1); // we expect malloc of 3 blocks to fail, so this better allow up to that size less 1
assertMoreOrEqual(half_fragment_free, low_heap+(sizeof(Block)*count));

assertTrue(oomEventReceived);
assertMoreOrEqual(oomSizeReceived, sizeof(block)*BLOCKS_TO_MALLOC);
assertMoreOrEqual(oomSizeReceived, sizeof(Block)*BLOCKS_TO_MALLOC);
}

test(SYSTEM_08_out_of_memory_not_raised_for_0_size_malloc)
@@ -255,6 +267,12 @@ test(SYSTEM_08_out_of_memory_not_raised_for_0_size_malloc)
assertFalse(oomEventReceived);
}

test(SYSTEM_09_out_of_memory_restore_state)
{
// Restore connection to the cloud and network
Network.connect();
Particle.connect();
waitFor(Particle.connected, 6*60*1000);
}


#endif
#endif // PLATFORM_ID!=0
@@ -105,19 +105,25 @@ test(APPLICATION_WATCHDOG_02_doesnt_fire_when_app_checks_in)
os_thread_yield();
}
// now force a timeout
HAL_Delay_Milliseconds(t+10);
// Worst case scenario it may take two application watchdog loop iterations
HAL_Delay_Milliseconds(t * 2);
// LOG_DEBUG(INFO, "TIME: %d, R %d:%s", millis()-startTime, x, timeout_called?"pass":"fail");
assertEqual(timeout_called, 1);
waitForComplete(wd);
uint32_t endTime = millis();
assertMoreOrEqual(endTime-startTime, 307); // should be 310 (give it 1% margin)
assertLessOrEqual(endTime-startTime, 313); // |
const auto expected = t * 4; // should be t*4
const auto margin = expected / 100; // 1%
assertMoreOrEqual(endTime - startTime, expected - margin);
assertLessOrEqual(endTime - startTime, expected + margin);
// LOG_DEBUG(INFO, "E %d",endTime-startTime);
}
}

test(APPLICATION_WATCHDOG_03_doesnt_leak_memory)
{
// Give the system some time to get the resources back
delay(500);

// Before Photon/P1 Thread fixes were introduced, we would lose approximately 20k
// of RAM due to 10 allocations of ApplicationWatchdog in APPLICATION_WATCHDOG_02.
// Taking fragmentation and other potential allocations into consideration, 2k seems like
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.