From af531b09fe79b303f3c079e8d02079f5f677379c Mon Sep 17 00:00:00 2001 From: Richard Meadows Date: Mon, 29 Jun 2015 19:54:01 +0100 Subject: [PATCH] Added mem write all test case --- firmware/test/tc/mem_write_all.h | 64 +++++++++++++++++++++++++++++++ firmware/test/tc/mem_write_all.py | 53 +++++++++++++++++++++++++ 2 files changed, 117 insertions(+) create mode 100644 firmware/test/tc/mem_write_all.h create mode 100644 firmware/test/tc/mem_write_all.py diff --git a/firmware/test/tc/mem_write_all.h b/firmware/test/tc/mem_write_all.h new file mode 100644 index 0000000..673b676 --- /dev/null +++ b/firmware/test/tc/mem_write_all.h @@ -0,0 +1,64 @@ +#ifndef __verification__ +#define __verification__ +#endif + +/****************************//* mem_write_all_tc *//****************************/ +/** + * Erases and writes the entire memory chip + */ +#include "memory.h" + +/* Parameters in */ +struct mem_write_all_tc_params { + + /* Input paramters to your test case go here */ + uint8_t page_data[256]; + +} mem_write_all_tc_params; +/* Results out */ +struct mem_write_all_tc_results { + + /* Result values should be populated here */ + uint8_t all_good; + uint32_t fail_address; + uint8_t fail_wrote, fail_read; + +} mem_write_all_tc_results; +/* Function */ +__verification__ void mem_write_all_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 + */ + uint8_t page_read[0x100]; + uint32_t i, j; + + init_memory(); + mem_chip_erase(); + + for (i = 0; i < TOTAL_PAGES; i++) { + mem_write_page(i * 0x100, mem_write_all_tc_params.page_data, 0x100); + } + for (i = 0; i < TOTAL_PAGES; i++) { + mem_read_memory(i * 0x100, page_read, 0x100); + + for (j = 0; j < 0x100; j++) { + if (page_read[j] != mem_write_all_tc_params.page_data[j]) { + /* Error */ + mem_write_all_tc_results.all_good = 0; + mem_write_all_tc_results.fail_address = (i * 0x100) + j; + mem_write_all_tc_results.fail_wrote = + mem_write_all_tc_params.page_data[i]; + mem_write_all_tc_results.fail_read = page_read[i]; + + return; + } + } + } + + /* All good */ + mem_write_all_tc_results.all_good = 1; +} diff --git a/firmware/test/tc/mem_write_all.py b/firmware/test/tc/mem_write_all.py new file mode 100644 index 0000000..8bdaf36 --- /dev/null +++ b/firmware/test/tc/mem_write_all.py @@ -0,0 +1,53 @@ +#!/usr/bin/env python + +# ------------------------------------------------------------------------------ +# Imports +# ------------------------------------------------------------------------------ + +import sys +sys.path.append("./test") +import main + +from random import randint + +# ------------------------------------------------------------------------------ +# Test Script +# ------------------------------------------------------------------------------ + +class mem_write_all_tc: + def __init__(self): + self.name = self.__class__.__name__ + self.iterations = 1 + + + def get_test(self): + """Returns some suitable test parameters""" + params = main.struct_mem_write_all_tc_params() + + """ + Assign input parameters here + """ + for i in range(0x100): + params.page_data[i] = randint(0, 0xff) + + return params + + def is_correct(self, params, result, print_info): + """Returns if a result is correct for the given parameters""" + + all_good = result['all_good'] + fail_address = result['fail_address'] + fail_wrote = result['fail_wrote'] + fail_read = result['fail_read'] + """ + Compare result and params here, decide sth. + Can use print_info + """ + if not all_good: + print_info("Error at index {:#x}: {:#x} != {:#x}" + .format(int(fail_address), int(fail_read), int(fail_wrote))) + return False + + print_info("All correct!") + + return True