mirror of https://github.com/ARMmbed/mbed-os.git
Add unexpected reset test
Add a test which repeatedly resets a device and then checks that the filesystem is still valid using real hardware.pull/5538/head
parent
bb155adc16
commit
2d374cee5c
|
|
@ -0,0 +1,114 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2017-2017 ARM Limited
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
* SOFTWARE.
|
||||
*/
|
||||
|
||||
#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;
|
||||
|
||||
#ifndef MBED_TEST_BLOCKDEVICE
|
||||
#define MBED_TEST_BLOCKDEVICE SPIFBlockDevice
|
||||
#define MBED_TEST_BLOCKDEVICE_DECL SPIFBlockDevice bd(PTE2, PTE4, PTE1, PTE5)
|
||||
#endif
|
||||
|
||||
#ifndef MBED_TEST_BLOCKDEVICE_DECL
|
||||
#define MBED_TEST_BLOCKDEVICE_DECL MBED_TEST_BLOCKDEVICE bd
|
||||
#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(60, "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);
|
||||
}
|
||||
|
|
@ -0,0 +1,103 @@
|
|||
"""
|
||||
mbed SDK
|
||||
Copyright (c) 2017-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.
|
||||
"""
|
||||
from __future__ import print_function
|
||||
|
||||
from mbed_host_tests import BaseHostTest
|
||||
from time import sleep
|
||||
|
||||
|
||||
class UnexpectedResetTest(BaseHostTest):
|
||||
"""This test checks that a device's RTC keeps count through a reset
|
||||
|
||||
It does this by setting the RTC's time, triggering a reset,
|
||||
delaying and then reading the RTC's time again to ensure
|
||||
that the RTC is still counting.
|
||||
"""
|
||||
|
||||
"""Number of times to reset the device in this test"""
|
||||
RESET_COUNT = 20
|
||||
RESET_DELAY_BASE = 1.0
|
||||
RESET_DELAY_INC = 0.02
|
||||
VALUE_PLACEHOLDER = "0"
|
||||
|
||||
def setup(self):
|
||||
"""Register callbacks required for the test"""
|
||||
self._error = False
|
||||
generator = self.unexpected_reset_test()
|
||||
generator.next()
|
||||
|
||||
def run_gen(key, value, time):
|
||||
"""Run the generator, and fail testing if the iterator stops"""
|
||||
if self._error:
|
||||
return
|
||||
try:
|
||||
generator.send((key, value, time))
|
||||
except StopIteration:
|
||||
self._error = True
|
||||
|
||||
for resp in ("start", "read", "format_done", "soft_reset_dut_complete"):
|
||||
self.register_callback(resp, run_gen)
|
||||
|
||||
def teardown(self):
|
||||
"""No work to do here"""
|
||||
pass
|
||||
|
||||
def unexpected_reset_test(self):
|
||||
"""Generator for running the reset test
|
||||
|
||||
This function calls yield to wait for the next event from
|
||||
the device. If the device gives the wrong response, then the
|
||||
generator terminates by returing which raises a StopIteration
|
||||
exception and fails the test.
|
||||
"""
|
||||
|
||||
# Wait for start token
|
||||
key, value, time = yield
|
||||
if key != "start":
|
||||
return
|
||||
|
||||
# Format the device before starting the test
|
||||
self.send_kv("format", self.VALUE_PLACEHOLDER)
|
||||
key, value, time = yield
|
||||
if key != "format_done":
|
||||
return
|
||||
|
||||
for i in range(self.RESET_COUNT):
|
||||
|
||||
self.send_kv("run", self.VALUE_PLACEHOLDER)
|
||||
sleep(self.RESET_DELAY_BASE + self.RESET_DELAY_INC * i)
|
||||
|
||||
self.reset()
|
||||
|
||||
# Wait for start token
|
||||
key, value, time = yield
|
||||
self.log("Key from yield: %s" % key)
|
||||
if key != "soft_reset_dut_complete":
|
||||
return
|
||||
|
||||
|
||||
self.send_kv("__sync", "00000000-0000-000000000-000000000000")
|
||||
|
||||
# Wait for start token
|
||||
key, value, time = yield
|
||||
if key != "start":
|
||||
return
|
||||
|
||||
self.send_kv("exit", "pass")
|
||||
|
||||
yield # No more events expected
|
||||
|
||||
Loading…
Reference in New Issue