Import Mbed OS hard-float snapshot
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "mbed.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#include "atomic_usage.h"
|
||||
#include "ObservingBlockDevice.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
// test configuration
|
||||
#ifndef MBED_TEST_SIM_BLOCKDEVICE
|
||||
#error [NOT_SUPPORTED] Simulation block device required for resilience tests
|
||||
#else
|
||||
|
||||
#ifndef MBED_TEST_SIM_BLOCKDEVICE_DECL
|
||||
#define MBED_TEST_SIM_BLOCKDEVICE_DECL MBED_TEST_SIM_BLOCKDEVICE bd(MBED_TEST_BLOCK_COUNT*512, 1, 1, 512)
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_BLOCK_COUNT
|
||||
#define MBED_TEST_BLOCK_COUNT 64
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_CYCLES
|
||||
#define MBED_TEST_CYCLES 10
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_TIMEOUT
|
||||
#define MBED_TEST_TIMEOUT 480
|
||||
#endif
|
||||
|
||||
// declarations
|
||||
#define STRINGIZE(x) STRINGIZE2(x)
|
||||
#define STRINGIZE2(x) #x
|
||||
#define INCLUDE(x) STRINGIZE(x.h)
|
||||
|
||||
#include INCLUDE(MBED_TEST_SIM_BLOCKDEVICE)
|
||||
|
||||
|
||||
/**
|
||||
* Check that the filesystem is valid after every change
|
||||
*
|
||||
* This test is to ensure that littlefs contains a valid filesystem at
|
||||
* all times. This property is required for handling unexpected power
|
||||
* loss.
|
||||
*/
|
||||
void test_resilience()
|
||||
{
|
||||
MBED_TEST_SIM_BLOCKDEVICE_DECL;
|
||||
|
||||
// bring up to get block size
|
||||
bd.init();
|
||||
bd_size_t block_size = bd.get_erase_size();
|
||||
bd.deinit();
|
||||
|
||||
SlicingBlockDevice slice(&bd, 0, MBED_TEST_BLOCK_COUNT * block_size);
|
||||
|
||||
// Setup the test
|
||||
setup_atomic_operations(&slice, true);
|
||||
|
||||
// Run check on every write operation
|
||||
ObservingBlockDevice observer(&slice);
|
||||
observer.attach(check_atomic_operations);
|
||||
|
||||
// Perform operations
|
||||
printf("Performing %i operations on flash\n", MBED_TEST_CYCLES);
|
||||
for (int i = 1; i <= MBED_TEST_CYCLES; i++) {
|
||||
int64_t ret = perform_atomic_operations(&observer);
|
||||
TEST_ASSERT_EQUAL(i, ret);
|
||||
}
|
||||
printf("No errors detected\n");
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("test resilience", test_resilience),
|
||||
};
|
||||
|
||||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
|
||||
|
||||
int main()
|
||||
{
|
||||
Harness::run(specification);
|
||||
}
|
||||
|
||||
#endif // MBED_TEST_SIM_BLOCKDEVICE
|
||||
@@ -0,0 +1,121 @@
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "mbed.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#include "atomic_usage.h"
|
||||
#include "ObservingBlockDevice.h"
|
||||
#include "LittleFileSystem.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
||||
// test configuration
|
||||
#ifndef MBED_TEST_BLOCKDEVICE
|
||||
#error [NOT_SUPPORTED] Non-volatile block device required for resilience_functional tests
|
||||
#else
|
||||
|
||||
#ifndef MBED_TEST_BLOCKDEVICE_DECL
|
||||
#define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_BLOCK_COUNT
|
||||
#define MBED_TEST_BLOCK_COUNT 64
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_CYCLES
|
||||
#define MBED_TEST_CYCLES 10
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_TIMEOUT
|
||||
#define MBED_TEST_TIMEOUT 480
|
||||
#endif
|
||||
|
||||
// declarations
|
||||
#define STRINGIZE(x) STRINGIZE2(x)
|
||||
#define STRINGIZE2(x) #x
|
||||
#define INCLUDE(x) STRINGIZE(x.h)
|
||||
|
||||
#include INCLUDE(MBED_TEST_BLOCKDEVICE)
|
||||
|
||||
MBED_TEST_BLOCKDEVICE_DECL;
|
||||
|
||||
typedef enum {
|
||||
CMD_STATUS_PASS,
|
||||
CMD_STATUS_FAIL,
|
||||
CMD_STATUS_CONTINUE,
|
||||
CMD_STATUS_ERROR
|
||||
} cmd_status_t;
|
||||
|
||||
void use_filesystem()
|
||||
{
|
||||
// Perform operations
|
||||
while (true) {
|
||||
int64_t ret = perform_atomic_operations(&bd);
|
||||
TEST_ASSERT(ret > 0);
|
||||
}
|
||||
}
|
||||
|
||||
static cmd_status_t handle_command(const char *key, const char *value)
|
||||
{
|
||||
if (strcmp(key, "format") == 0) {
|
||||
setup_atomic_operations(&bd, true);
|
||||
greentea_send_kv("format_done", 1);
|
||||
return CMD_STATUS_CONTINUE;
|
||||
|
||||
} else if (strcmp(key, "run") == 0) {
|
||||
use_filesystem();
|
||||
return CMD_STATUS_CONTINUE;
|
||||
|
||||
} else if (strcmp(key, "exit") == 0) {
|
||||
if (strcmp(value, "pass") != 0) {
|
||||
return CMD_STATUS_FAIL;
|
||||
}
|
||||
check_atomic_operations(&bd);
|
||||
return CMD_STATUS_PASS;
|
||||
|
||||
} else {
|
||||
return CMD_STATUS_ERROR;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
GREENTEA_SETUP(MBED_TEST_TIMEOUT, "unexpected_reset");
|
||||
|
||||
static char _key[10 + 1] = {};
|
||||
static char _value[128 + 1] = {};
|
||||
|
||||
greentea_send_kv("start", 1);
|
||||
|
||||
// Handshake with host
|
||||
cmd_status_t cmd_status = CMD_STATUS_CONTINUE;
|
||||
while (CMD_STATUS_CONTINUE == cmd_status) {
|
||||
memset(_key, 0, sizeof(_key));
|
||||
memset(_value, 0, sizeof(_value));
|
||||
greentea_parse_kv(_key, _value, sizeof(_key) - 1, sizeof(_value) - 1);
|
||||
cmd_status = handle_command(_key, _value);
|
||||
}
|
||||
|
||||
GREENTEA_TESTSUITE_RESULT(CMD_STATUS_PASS == cmd_status);
|
||||
}
|
||||
|
||||
#endif // MBED_TEST_BLOCKDEVICE
|
||||
@@ -0,0 +1,122 @@
|
||||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "mbed.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
#include "test_env.h"
|
||||
|
||||
#include "atomic_usage.h"
|
||||
#include "ExhaustibleBlockDevice.h"
|
||||
#include "SlicingBlockDevice.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
// test configuration
|
||||
#ifndef MBED_TEST_SIM_BLOCKDEVICE
|
||||
#error [NOT_SUPPORTED] Simulation block device required for wear leveling tests
|
||||
#else
|
||||
|
||||
#ifndef MBED_TEST_SIM_BLOCKDEVICE_DECL
|
||||
#define MBED_TEST_SIM_BLOCKDEVICE_DECL MBED_TEST_SIM_BLOCKDEVICE bd(MBED_TEST_BLOCK_COUNT*512, 1, 1, 512)
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_BLOCK_COUNT
|
||||
#define MBED_TEST_BLOCK_COUNT 64
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_ERASE_CYCLES
|
||||
#define MBED_TEST_ERASE_CYCLES 100
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_TIMEOUT
|
||||
#define MBED_TEST_TIMEOUT 480
|
||||
#endif
|
||||
|
||||
// declarations
|
||||
#define STRINGIZE(x) STRINGIZE2(x)
|
||||
#define STRINGIZE2(x) #x
|
||||
#define INCLUDE(x) STRINGIZE(x.h)
|
||||
|
||||
#include INCLUDE(MBED_TEST_SIM_BLOCKDEVICE)
|
||||
|
||||
|
||||
static uint32_t test_wear_leveling_size(uint32_t block_count)
|
||||
{
|
||||
MBED_TEST_SIM_BLOCKDEVICE_DECL;
|
||||
|
||||
// bring up to get block size
|
||||
bd.init();
|
||||
bd_size_t block_size = bd.get_erase_size();
|
||||
bd.deinit();
|
||||
|
||||
SlicingBlockDevice slice(&bd, 0, block_count * block_size);
|
||||
ExhaustibleBlockDevice ebd(&slice, MBED_TEST_ERASE_CYCLES);
|
||||
|
||||
printf("Testing size %llu bytes (%lux%llu) blocks\n",
|
||||
block_count * block_size, block_count, block_size);
|
||||
setup_atomic_operations(&ebd, true);
|
||||
|
||||
int64_t cycles = 0;
|
||||
while (true) {
|
||||
int64_t ret = perform_atomic_operations(&ebd);
|
||||
check_atomic_operations(&ebd);
|
||||
if (-1 == ret) {
|
||||
break;
|
||||
}
|
||||
cycles++;
|
||||
TEST_ASSERT_EQUAL(cycles, ret);
|
||||
|
||||
}
|
||||
|
||||
printf(" Simulated flash lasted %lli cylces\n", cycles);
|
||||
return cycles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check that storage life is proportional to storage size
|
||||
*
|
||||
* This test is to ensure that littlefs is properly handling wear
|
||||
* leveling. It does this by creating a simulated flash block device
|
||||
* which can be worn out and then using it until it is exhausted.
|
||||
* It then doubles the size of the block device and runs the same
|
||||
* test. If the block device with twice the size lasts at least
|
||||
* twice as long then the test passes.
|
||||
*/
|
||||
void test_wear_leveling()
|
||||
{
|
||||
uint32_t cycles_1 = test_wear_leveling_size(MBED_TEST_BLOCK_COUNT / 2);
|
||||
uint32_t cycles_2 = test_wear_leveling_size(MBED_TEST_BLOCK_COUNT / 1);
|
||||
TEST_ASSERT(cycles_2 > cycles_1 * 2);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("test wear leveling", test_wear_leveling),
|
||||
};
|
||||
|
||||
utest::v1::status_t greentea_test_setup(const size_t number_of_cases)
|
||||
{
|
||||
GREENTEA_SETUP(MBED_TEST_TIMEOUT, "default_auto");
|
||||
return greentea_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Specification specification(greentea_test_setup, cases, greentea_test_teardown_handler);
|
||||
|
||||
int main()
|
||||
{
|
||||
Harness::run(specification);
|
||||
}
|
||||
|
||||
#endif // MBED_TEST_SIM_BLOCKDEVICE
|
||||
Reference in New Issue
Block a user