Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions user/tests/integration/00_before/before.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2025 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#define PARTICLE_USE_UNSTABLE_API

#include "application.h"
#include "test.h"
#include "softcrc32.h"
#include "check.h"
#include "storage_hal.h"

namespace {

bool getFactoryModule(hal_module_t* factoryModule) {
// Search the platform modules for the factory module
hal_system_info_t info = {};
info.size = sizeof(info);
const int r = system_info_get_unstable(&info, 0 /* flags */, nullptr /* reserved */);
if (r != 0) {
return false;
}
SCOPE_GUARD({
system_info_free_unstable(&info, nullptr /* reserved */);
});

for (size_t i = 0; i < info.module_count; ++i) {
const auto& module = info.modules[i];
if (module.bounds.store == MODULE_STORE_FACTORY) {
*factoryModule = module;
return true;
}
}
return false;
}

} // namespace

test(01_erase_factory_module) {
// Determine the factory reset module start address from the platform flash modules
hal_module_t factoryModule = {};
bool isFactoryModule = getFactoryModule(&factoryModule);
// Log.info("getFactoryModule(): %d", isFactoryModule);

if (isFactoryModule) {
#if HAL_PLATFORM_NRF52840 // FIXME for RTL872x-based platforms
// Erase entire Factory Module
hal_storage_erase(HAL_STORAGE_ID_EXTERNAL_FLASH, EXTERNAL_FLASH_FAC_ADDRESS, EXTERNAL_FLASH_FAC_LENGTH);
#endif // HAL_PLATFORM_NRF52840
}
}

test(02_remove_static_ip) {
// Easiest way to erase all NETWORK_CONFIG settings, and default to dynamic IP
unlink("/sys/network.dat");
}

test(03_enable_listening_mode) {
System.disableFeature(FEATURE_DISABLE_LISTENING_MODE);
}
24 changes: 24 additions & 0 deletions user/tests/integration/00_before/before.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
suite('00_before: Preparation/Setup for HIL Testing');

platform('gen3', 'gen4');
systemThread('enabled');

before(function() {
// console.log('before js runs');
});

test('01_erase_factory_module', async function () {

});

test('02_remove_static_ip', async function () {

});

test('03_enable_listening_mode', async function () {

});

after(function() {
// console.log('after js runs');
});
73 changes: 73 additions & 0 deletions user/tests/integration/zz_after/after.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright (c) 2025 Particle Industries, Inc. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation, either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/

#define PARTICLE_USE_UNSTABLE_API

#include "application.h"
#include "test.h"
#include "softcrc32.h"
#include "check.h"
#include "storage_hal.h"

namespace {

bool getFactoryModule(hal_module_t* factoryModule) {
// Search the platform modules for the factory module
hal_system_info_t info = {};
info.size = sizeof(info);
const int r = system_info_get_unstable(&info, 0 /* flags */, nullptr /* reserved */);
if (r != 0) {
return false;
}
SCOPE_GUARD({
system_info_free_unstable(&info, nullptr /* reserved */);
});

for (size_t i = 0; i < info.module_count; ++i) {
const auto& module = info.modules[i];
if (module.bounds.store == MODULE_STORE_FACTORY) {
*factoryModule = module;
return true;
}
}
return false;
}

} // namespace

test(01_erase_factory_module) {
// Determine the factory reset module start address from the platform flash modules
hal_module_t factoryModule = {};
bool isFactoryModule = getFactoryModule(&factoryModule);
// Log.info("getFactoryModule(): %d", isFactoryModule);

if (isFactoryModule) {
#if HAL_PLATFORM_NRF52840 // FIXME for RTL872x-based platforms
// Erase entire Factory Module
hal_storage_erase(HAL_STORAGE_ID_EXTERNAL_FLASH, EXTERNAL_FLASH_FAC_ADDRESS, EXTERNAL_FLASH_FAC_LENGTH);
#endif // HAL_PLATFORM_NRF52840
}
}

test(02_remove_static_ip) {
// Easiest way to erase all NETWORK_CONFIG settings, and default to dynamic IP
unlink("/sys/network.dat");
}

test(03_enable_listening_mode) {
System.disableFeature(FEATURE_DISABLE_LISTENING_MODE);
}
24 changes: 24 additions & 0 deletions user/tests/integration/zz_after/after.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
suite('Cleanup for HIL Testing');

platform('gen3', 'gen4');
systemThread('enabled');

before(function() {
// console.log('before js runs');
});

test('01_erase_factory_module', async function () {

});

test('02_remove_static_ip', async function () {

});

test('03_enable_listening_mode', async function () {

});

after(function() {
// console.log('after js runs');
});