[loader] add testcase for loader, but disable testcases from loader build

main-solar-only
Richard Meadows 2016-08-12 20:08:28 +01:00
rodzic 06bf01b3a5
commit d8d09fc960
7 zmienionych plików z 138 dodań i 33 usunięć

Wyświetl plik

@ -115,7 +115,7 @@ INCLUDE_PATH += chip/ chip/cmsis/ samd20/ samd20/component/ test/tc/
# Verification suite code
#
#
SYSTEM += test/tmain.c
#SYSTEM += test/tmain.c
# Linker Scripts
#

Wyświetl plik

@ -25,6 +25,17 @@
#ifndef FLASH_H
#define FLASH_H
#include "samd20.h"
#define APPLICATION_BASE (0x00004000) /* 16K */
#define APPLICATION_LENGTH (112*1024) /* 112K */
#define D1_START (APPLICATION_BASE)
#define D1_SECTORS (APPLICATION_LENGTH/256)
#define D2_START (APPLICATION_BASE+APPLICATION_LENGTH)
#define D2_SECTORS (D1_SECTORS)
uint32_t check_and_repair_memory(void);
#endif /* FLASH_H */

Wyświetl plik

@ -30,14 +30,6 @@
#include "flash.h"
#include "watchdog.h"
#define APPLICATION_BASE (0x00004000) /* 16K */
#define APPLICATION_LENGTH (112*1024) /* 112K */
#define D1_START (APPLICATION_BASE)
#define D1_SECTORS (APPLICATION_LENGTH/256)
#define D2_START (APPLICATION_BASE+APPLICATION_LENGTH)
#define D2_SECTORS (D1_SECTORS)
/* Check these are multiples of 64 */
#if (D1_SECTORS & 0x3F)
#error D1_SECTORS _must_ be a mul 64, so checksums fill integer no. of sectors
@ -123,30 +115,6 @@ uint32_t checksum_sector(unsigned int* sector)
SECTOR_SIZE); /* length */
}
/* /\** */
/* * checks if memory checksum is good */
/* *\/ */
/* enum flash_state check_flash_state(void) */
/* { */
/* unsigned int calculated = checksum_memory(); */
/* if (*flash_checksum == 0xFFFFFFFF) { /\* not written *\/ */
/* /\* write it *\/ */
/* mem_write_word((uint32_t)flash_checksum, calculated); */
/* return FLASH_GOOD; */
/* } else { /\* written *\/ */
/* /\* check it *\/ */
/* if (calculated == *flash_checksum) { */
/* return FLASH_GOOD; */
/* } else { */
/* return FLASH_BAD_CSUM; */
/* } */
/* } */
/* } */
/**
* updates checksum records in nvm
*/
@ -166,6 +134,8 @@ void update_checksums(const uint32_t* nvm, uint32_t* ram, int sectors)
/**
* Checks and repairs application memory space
*
* returns the number of errors successfully corrected
*/
uint32_t check_and_repair_memory(void)
{

Wyświetl plik

@ -0,0 +1,9 @@
# Import every module in this subdirectory
import os
import glob
modules = glob.glob(os.path.dirname(__file__)+"/*.py")
__all__ = [ os.path.basename(f)[:-3] for f in modules if not f.endswith('__init__.py')]
del os
del glob
del f
del modules

Wyświetl plik

@ -0,0 +1,49 @@
#ifndef __verification__
#define __verification__
#endif
/****************************//* repair_test_tc *//****************************/
/**
* Write a description of your test case here
*/
#include <string.h>
#include "flash.h"
#include "memory.h"
/* Parameters in */
struct repair_test_tc_params {
/* Input paramters to your test case go here */
uint32_t address_to_corrupt;
} repair_test_tc_params;
/* Results out */
struct repair_test_tc_results {
/* Result values should be populated here */
uint32_t errors_corrected;
int memcmp_result;
} repair_test_tc_results;
/* Function */
__verification__ void repair_test_tc(void) {
/**
* The main body of the test case goes here.
*
* Use the input parameters to run the test case. Populate the
* results structure at the end
*/
if (repair_test_tc_params.address_to_corrupt) {
mem_write_word((unsigned int*)repair_test_tc_params.address_to_corrupt, 0);
}
/* repair */
repair_test_tc_results.errors_corrected = check_and_repair_memory();
/* check memory */
repair_test_tc_results.memcmp_result =
memcmp((void*)D1_START, (void*)D2_START, APPLICATION_LENGTH);
}

Wyświetl plik

@ -0,0 +1,65 @@
#!/usr/bin/env python
# coding=utf-8
# ------------------------------------------------------------------------------
# Imports
# ------------------------------------------------------------------------------
import sys
sys.path.append("./test")
import main
from random import randint
# ------------------------------------------------------------------------------
# Test Script
# ------------------------------------------------------------------------------
class repair_test_tc:
def __init__(self):
self.name = self.__class__.__name__
self.index = 0
self.addresses = [0, # Do nothing
0x00004000, # D1 start
0x00020000, # D2 start
0x0003C000, # EEPROM
];
self.errors_expected = [0,
1,
1,
0];
def get_test(self):
"""Returns some suitable test parameters"""
params = main.struct_repair_test_tc_params()
if self.index >= len(self.addresses):
return None
params.address_to_corrupt = self.addresses[self.index]
return params
def is_correct(self, params, result, print_info):
"""Returns if a result is correct for the given parameters"""
errors_corrected = int(result['errors_corrected'])
memcmp_result = int(result['memcmp_result'])
errors_expected = self.errors_expected[self.index]
self.index +=1
# Check errors
if errors_corrected != errors_expected:
print_info("Expected {:d} errors, actually repaired {:d} errors!"
.format(errors_expected, errors_corrected))
return False
if memcmp_result != 0:
print_info("D1 and D2 regions differ! memcmp = {d}"
.format(memcmp_result))
return False
print_info("Case {:d} passed ✓".format(self.index))
return True

Wyświetl plik

@ -37,6 +37,7 @@
/***************************** test cases *******************************/
#include "times_two.h"
#include "repair_test.h"
/* [new_tc] */