Merged buffer size in config

pull/9184/head
Conrad Braam 2019-01-15 17:33:35 +00:00
parent 7095b82126
commit c36f5406ae
15 changed files with 221 additions and 105 deletions

View File

@ -65,7 +65,7 @@ const char *errorcodes = // descriptions from nfc/stack/nfc_errors.h
"20 NFC_ERR_DISCONNECTED \n"
"21 NFC_ERR_ABORTED\n";
// for easy manual UI interaction
/** Disables VT100 etc. for easy manual UI interaction */
int seteasy(int argc, char *argv[])
{
const char msg[][20] =
@ -95,15 +95,17 @@ int main(int argc, char *argv[])
"last NFC error code", errorcodes);
cmd_add("setlastnfcerror", HandleTestCommand::cmd_set_last_nfc_error,
"self-test", "for self-test only");
cmd_add("iseeprom", HandleTestCommand::cmd_get_conf_nfceeprom,
"get NFC configEEPROM present",
"true if config exists, else false");
cmd_add("initnfc", HandleTestCommand::cmd_init_nfc, "init NFC driver",
"call first");
cmd_add("getmaxndef", HandleTestCommand::cmd_get_max_ndef, "get max NDEF record target supports",
"returns the eeprom size, or max buffer if a controller");
cmd_add("init", HandleTestCommand::cmd_init_nfc, "alias initnfc",
"call first");
cmd_add("setsmartposter", HandleTestCommand::cmd_set_smartposter,
"send smartposter NDEF", "<uri>");
cmd_add("iseeprom", HandleTestCommand::cmd_get_conf_nfceeprom,
"get NFC configEEPROM present",
"true if config exists, else false");
cmd_add("readmessage", HandleTestCommand::cmd_read_message,
"read EEPROM else return last message", "returns hex dump");
cmd_add("read", HandleTestCommand::cmd_read_message, "alias readmessage",

View File

@ -1,6 +1,6 @@
{
"config": {
"TEST_NDEF_MSG_MAX" : 8192
"TEST_NDEF_MSG_MAX" : 1024
},
"target_overrides": {
"DISCO_L475VG_IOT01A": {

View File

@ -68,6 +68,17 @@ int HandleTestCommand::cmd_set_last_nfc_error(int argc, char *argv[])
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
}
int HandleTestCommand::cmd_get_max_ndef(int argc, char *argv[])
{
if (pNFC_Test_Shim) {
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_get_max_ndef);
return CMDLINE_RETCODE_EXCUTING_CONTINUE;
}
return CMDLINE_RETCODE_FAIL;
}
int HandleTestCommand::cmd_init_nfc(int argc, char *argv[])
{
@ -82,7 +93,7 @@ int HandleTestCommand::cmd_init_nfc(int argc, char *argv[])
int HandleTestCommand::cmd_read_message(int argc, char *argv[])
{
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_read_nfceeprom);
nfcQueue.call(pNFC_Test_Shim, &NFCTestShim::cmd_read_nfc_contents);
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
}
@ -133,6 +144,12 @@ int HandleTestCommand::cmd_write_long_ndef_message(int argc, char *argv[])
cmd_printf("Cannot convert value to int\r\n");
return (CMDLINE_RETCODE_INVALID_PARAMETERS);
}
// check that it would not overflow
if (length > MBED_CONF_APP_TEST_NDEF_MSG_MAX) {
cmd_printf("Buffer length may not exceed %d !\r\n", (int)MBED_CONF_APP_TEST_NDEF_MSG_MAX);
return (CMDLINE_RETCODE_FAIL);
}
data = (char *) malloc(length + 1);
if (!data) {
cmd_printf("WARN out of memory!\r\n");

View File

@ -38,44 +38,49 @@ extern events::EventQueue nfcQueue;
*/
class HandleTestCommand {
public:
// start thread and handle queue
HandleTestCommand();
/* set corresponding mask bit on, return false if the supplied string cannot parse */
/** set corresponding mask bit on in referenced structure, return false if the supplied string cannot parse */
static bool set_protocol_target(mbed::nfc::nfc_rf_protocols_bitmask_t &bitmask, const char *protocolName);
/* return and clear the last result code. Type "help getlastnfcerror" for a list of error codes */
/** return and clear the last result code. Type "help getlastnfcerror" for a list of error codes */
static int cmd_get_last_nfc_error(int argc, char *argv[])
{
nfcQueue.call(NFCTestShim::cmd_get_last_nfc_error);
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
}
/* internal function to test getlastnfcerror */
/** internal function to test getlastnfcerror */
static int cmd_set_last_nfc_error(int argc, char *argv[]);
/* compile time flag */
/** returns compile time flag if NFC EEPROM was compiled */
static int cmd_get_conf_nfceeprom(int argc, char *argv[])
{
nfcQueue.call(NFCTestShim::cmd_get_conf_nfceeprom);
return (CMDLINE_RETCODE_EXCUTING_CONTINUE);
}
/* must be called before invoking any other calls */
/** For EEPROM, returns the driver max_ndef value, else returns the app config MBED_CONF_APP_TEST_NDEF_MSG_MAX */
static int cmd_get_max_ndef(int argc, char *argv[]);
/** Init must be called before invoking any other calls, obtains a driver reference and initializes driver */
static int cmd_init_nfc(int argc, char *argv[]);
/* write a smartposter url, 'Sp' NDEF to the target */
/** write a smartposter url, 'Sp' NDEF to the target */
static int cmd_set_smartposter(int argc, char *argv[]);
/* erase EEPROM */
/** erases the EEPROM if present */
static int cmd_erase(int argc, char *argv[]);
// controller driver methods:
/** Returns a CSV list of protocols supported */
static int cmd_get_supported_rf_protocols(int argc, char *argv[]);
/** Sets the protocols supported (unimplemented) */
static int cmd_configure_rf_protocols(int argc, char *argv[]);
/** starts the NFC discovery loop if controller, has no effect on EEPROM */
static int cmd_start_discovery(int argc, char *argv[]);
/** stops the NFC discovery loop if controller */
static int cmd_stop_discovery(int argc, char *argv[]);
/* read raw EEPROM contents */
/** read raw EEPROM contents, reads a buffer if a controller is used */
static int cmd_read_message(int argc, char *argv[]);
/* write a text 'T' NDEF message to the target */
/** write a text 'T' NDEF message to the target */
static int cmd_write_long_ndef_message(int argc, char *argv[]);
};

View File

@ -48,6 +48,11 @@ class NFCProcessController: NFCTestShim,
public:
NFCProcessController(events::EventQueue &queue);
void cmd_get_max_ndef()
{
cmd_printf("{{maxndef=%d}}\r\n", (int)MBED_CONF_APP_TEST_NDEF_MSG_MAX);
cmd_ready(CMDLINE_RETCODE_SUCCESS);
}
nfc_err_t init();
nfc_err_t start_discovery();
nfc_err_t stop_discovery();

View File

@ -47,7 +47,7 @@ using mbed::nfc::NFCEEPROMDriver;
// implements : mbed::nfc::NFCEEPROM::Delegate
NFCProcessEEPROM::NFCProcessEEPROM(events::EventQueue &queue, NFCEEPROMDriver &eeprom_driver) :
NFCTestShim(queue), _eeprom(&eeprom_driver, &queue, _ndef_buffer)
NFCTestShim(queue), _eeprom(&eeprom_driver, &queue, _ndef_buffer), _ptr_eeprom_driver(&eeprom_driver)
{}
nfc_err_t NFCProcessEEPROM::init()
@ -63,6 +63,13 @@ nfc_err_t NFCProcessEEPROM::init()
return (err);
}
void NFCProcessEEPROM::cmd_get_max_ndef()
{
cmd_printf("{{maxndef=%d}}\r\n", (int)_ptr_eeprom_driver->read_max_size());
cmd_ready(CMDLINE_RETCODE_SUCCESS);
}
void NFCProcessEEPROM::queue_write_call()
{
cmd_printf("NFCProcessEEPROM::queue_write_call() entry\r\n");
@ -83,7 +90,6 @@ void NFCProcessEEPROM::queue_erase_call()
void NFCProcessEEPROM::on_ndef_message_written(nfc_err_t result)
{
// todo: de-duplicate this code
set_last_nfc_error(result);
if (result == NFC_OK) {
cmd_printf("message written successfully\r\n");
@ -108,7 +114,6 @@ void NFCProcessEEPROM::on_ndef_message_read(nfc_err_t result)
void NFCProcessEEPROM::on_ndef_message_erased(nfc_err_t result)
{
// todo : de-duplicate/template this callback handler
set_last_nfc_error(result);
if (result == NFC_OK) {
cmd_printf("message erased successfully\r\n");

View File

@ -43,6 +43,8 @@ public:
void queue_write_long_call();
void queue_read_call();
void queue_erase_call();
void cmd_get_max_ndef();
private:
virtual void on_ndef_message_written(nfc_err_t result);
@ -52,6 +54,7 @@ private:
virtual void on_ndef_message_erased(nfc_err_t result);
private:
mbed::nfc::NFCEEPROM _eeprom;
mbed::nfc::NFCEEPROMDriver *_ptr_eeprom_driver;
};
#endif // eeprom

View File

@ -42,7 +42,6 @@ using mbed::nfc::nfc_rf_protocols_bitmask_t;
// statics
namespace {
char long_string[MBED_CONF_APP_TEST_NDEF_MSG_MAX];
char const *uri_prefix_string[] = { "",
"http://www.",
"https://www.",
@ -234,18 +233,19 @@ void NFCTestShim::cmd_configure_rf_protocols(
* the framework
* \return void An ICETEA error code and NFC error is set asyncronously
*/
void NFCTestShim::cmd_read_nfceeprom()
void NFCTestShim::cmd_read_nfc_contents()
{
#if MBED_CONF_NFCEEPROM
((NFCProcessEEPROM *)this)->queue_read_call();
cmd_printf("NFCTestShim::read_nfceeprom() exit\r\n");
cmd_printf("NFCTestShim::cmd_read_nfc_contents() exit\r\n");
#else
// returns last message "written", since we cannot read
print_ndef_message(_ndef_write_buffer, _ndef_write_buffer_used);
cmd_printf("Controller buffer data size=%d\r\n", _ndef_write_buffer_used);
set_last_nfc_error(NFC_OK);
cmd_printf("NFCTestShim::read_nfceeprom()\r\n");
cmd_printf("NFCTestShim::cmd_read_nfc_contents()\r\n");
cmd_ready(CMDLINE_RETCODE_SUCCESS);
#endif
}
@ -271,11 +271,10 @@ void NFCTestShim::cmd_erase()
* \param uri This method must free the passed in pointer
* \return void An ICETEA error code and NFC error is set asyncronously
*/
void NFCTestShim::cmd_write_long(char *data)
void NFCTestShim::cmd_write_long(char *text_string)
{
MessageBuilder builder(ndef_poster_message);
strcpy(::long_string, data); //max_ndef - header - overheads
strcpy(::long_string, text_string); //max_ndef - header - overheads
Text text(Text::UTF8, span_from_cstr("en-US"),
span_from_cstr((const char *)(::long_string)));
@ -290,9 +289,8 @@ void NFCTestShim::cmd_write_long(char *data)
set_last_nfc_error(NFC_OK);
cmd_ready(CMDLINE_RETCODE_SUCCESS);
#endif
cmd_printf("NFCTestShim::write_long() exit\r\n");
free(data);
free(text_string);
}
/** \brief Write a URI Use case would be to prompt to install an app from the appstore using the tag

View File

@ -28,7 +28,9 @@
#include "nfc/ndef/common/util.h"
#include "nfc/NFCDefinitions.h"
/**
* Test app driver wrapper. This is a base class containing shared EEPROM and Controller test data + logic
*/
class NFCTestShim {
public:
NFCTestShim(events::EventQueue &queue);
@ -46,6 +48,7 @@ public:
{
get_conf_nfceeprom();
};
virtual void cmd_get_max_ndef() = 0;
static void get_last_nfc_error();
static void set_last_nfc_error(int err);
static void get_conf_nfceeprom();
@ -59,8 +62,8 @@ public:
void cmd_set_smartposter(char *cmdUri);
void cmd_erase();
void cmd_write_long(char *data);
void cmd_read_nfceeprom();
void cmd_write_long(char *text_string);
void cmd_read_nfc_contents();
void cmd_start_discovery(bool manual = false);
void cmd_stop_discovery();
void cmd_configure_rf_protocols(mbed::nfc::nfc_rf_protocols_bitmask_t protocols);
@ -101,7 +104,6 @@ protected:
uint8_t _ndef_buffer[MBED_CONF_APP_TEST_NDEF_MSG_MAX]; // driver I/O buffer
bool _discovery_restart; // default true, restart discovery loop again on remote disconnect
events::EventQueue &_queue;
};
// forward declare single instance

View File

@ -25,9 +25,10 @@ class NfcTestParsers(PluginBase):
def get_parsers(self):
return {
'iseeprom': self.status_parser,
'getmaxndef': self.status_parser,
'getlastnfcerror': self.trace_parser,
'setlastnfcerror': self.trace_parser,
'iseeprom': self.trace_parser,
'initnfc': self.trace_parser, # all commands that return an NFC error code
'readmessage' : self.trace_parser,
'erase' : self.trace_parser,
@ -39,18 +40,17 @@ class NfcTestParsers(PluginBase):
'setprotocols': self.trace_parser
}
def trace_parser(self, response):
def status_parser(self, response):
"""
commands that do NOT return an NFC result-code
"""
results = {'iseeprom': None, # 'true' if EEPROM
'lastnfcerror':None, # 0=OK >0 = error
'nfcmessage':None, # NDEF array of bytes
'protocols':None, # csv list
'uri_id':None} # nfc URI type identifier
'lastnfcerror':0, # ignored here
'maxndef':None # actual driver buffer size
}
respLines = response.lines
for line in respLines:
try:
value = PluginBase.find_one(line, "{{lastnfcerror=([0-9]+)}}")
if value is not False:
results['lastnfcerror'] = int(value)
# iseeprom
value = PluginBase.find_one(line, "{{iseeprom=([\w]+)}}")
if value is not False:
@ -58,18 +58,78 @@ class NfcTestParsers(PluginBase):
results['iseeprom'] = True
else:
results['iseeprom'] = False
# nfcmessage (hex data dumps)
data = PluginBase.find_one(line, "{{nfcmessage=([0-9a-f\s]*)}}")
# max ndef
value = PluginBase.find_one(line, "{{maxndef=([0-9]+)}}")
if value is not False:
results['maxndef'] = int(value)
except re.error as e: # the framework gobbles errors in the plugin
print("Regex error",e,"occured in",os.path.basename(__file__), "!!")
raise e
return results
def convert_from_hex(self, data):
value = []
for byte in data.split(' '):
if bool(byte):
if len(byte) > 2: # the line wrapping code for huge lines appears to munch the space character between 2 bytes
value.append( int(byte[:2], 16))
value.append( int(byte[2:4], 16))
else:
value.append( int(byte, 16))
return value
# regex findall with additional filtering
@staticmethod
def find_all_hex_data(line, lookup):
"""
regexp search with one value to return.
:param line: Line
:param lookup: regexp
:return: List of match groups or False
"""
results = re.findall(lookup, line)
if results is not False:
results = [m for m in results if len(m) > 2] # remove empty matches and
# non hex-data result entries
return results
return False
def trace_parser(self, response):
results = {'iseeprom': None, # 'true' if EEPROM
'lastnfcerror':None, # 0=OK >0 = error
'nfcmessage':None, # NDEF array of bytes
'protocols':None, # csv list
'uri_id':None} # nfc URI type identifier
respLines = response.lines
started_read_data = False
partial_data = ""
for line in respLines:
try:
value = PluginBase.find_one(line, "{{lastnfcerror=([0-9]+)}}")
if value is not False:
results['lastnfcerror'] = int(value)
# {{nfcmessage=([0-9a-f\s]*)}}
data = PluginBase.find_one(line, "{{nfcmessage=([0-9a-f\s]*).*")
if data is not False:
value = []
for byte in data.split(' '):
if bool(byte):
value.append( int(byte, 16))
results['nfcmessage'] = value
started_read_data = True
if started_read_data: # read data until we see a }} pair
values = self.find_all_hex_data(line, "([0-9a-f\s]*)")
if values is not False:
if "{{nfcmessage" in line:
value = values[0]
else:
value = values[0]
#print ("==%s==" % value)
partial_data += value
if PluginBase.find_one(line, ".*(}})") is not False: # search for end marker
started_read_data = False
results['nfcmessage'] = self.convert_from_hex(partial_data)
# t1t,t2t,t3t,isodep,nfcdef,t5t
value = PluginBase.find_one(line, "{{protocols=(([\w]*,?)*)}}")
if value is not False:
results['protocols'] = value # a csv list
# smartposter uri
value = PluginBase.find_one(line, "{{uri_id=([0-9]+)}}")
if value is not False:
results['uri_id'] = int(value)

View File

@ -9,7 +9,7 @@ This project is called CreamScone, which is an ice tea framework based cli-drive
- [NFC tests.](#nfc-tests)
- [Overview](#overview)
- [System Test high level design](#system-test-high-level-design)
- [System Test high level requirement](#system-test-high-level-requirement)
- [Low level design](#low-level-design)
- [User Guide](#user-guide)
- [Test cases](#test-cases)
@ -46,7 +46,7 @@ Because the comissioning workflow application quality is the end goal, the NFC s
# System Test high level design
# System Test high level requirement
Mitigate risks identified, to the product from an internal view to supporting releases. Help customers develop a driver or a design, and reduce their production risks. In summary:
- Architecture risks and Api breaks
- Partner cannot NFC forum Certify
@ -67,16 +67,15 @@ In short, “Empower engineers to efficiently ship quality code with confidence.
API standalone Self tests [test_self.py](TEST_APPS\testcases\nfc\test_self.py)
API E2E (wireless) tests [test_nfc.py](TEST_APPS\testcases\nfc\test_nfc.py)
Commandline (serial port) driven [target app](TEST_APPS\devices\nfcapp\main.cpp) aka _'CreamScone'_ which allows manual interactions with the driver. The app will send all API return data over serial link.
An [icetea](https://github.com/ARMmbed/icetea/blob/master/README.md) framework test program. Commandline (serial port) driven [target app](TEST_APPS\devices\nfcapp\main.cpp) aka _'CreamScone'_ which allows manual interactions with the driver. The app will send all API return data over serial link.
An icetea plugin [nfc_test_parsers.py](TEST_APPS\icetea_plugins\nfc_test_parsers.py) which parses API responses over the serial port into python variables.
MbedOS cli test app [main.cpp](TEST_APPS\device\nfcapp\main.cpp). The CLI commands return results asynchronously for most commands which get passed to and handled on a driver thread.
**Future: ** A complete inter-op ready design intended to include a switch-box to allow the reader to connect to NFC enabled targets nearby using flying cables and a sticky-back antenna. The switch allows selecting either alternative tags, or NFC peers. The switch can be controlled using GPIO either driven from spare IO pins on the target DUT itself (preferred option), or perhaps from a Raspberry pi.
**Future: ** A complete inter-op ready design intended to include a switch-box to allow the reader to connect to NFC enabled targets nearby using flying cables and a sticky-back antenna. The switch should allow selecting either alternative tags, or NFC peers, and provide inter-operability coverage. The switch-box may be controlled using GPIO either driven from spare IO pins on the target DUT itself (preferred option), or perhaps from a Raspberry pi.
![inter-op](img/inter-op-view.png)
@ -159,7 +158,7 @@ writelong fill entire FILE with pattern
...
```
Note: Most commands also return a NFC status value (type "getlastnfcerror help" in console) which allow us to build negative test cases.
Note: Some commands only apply to NFC controllers, these commands fail with the appropriate not-supported code NFC_ERR_UNSUPPORTED and additionally return -2 error code to ice-tea.
Note: Some commands only apply to NFC controllers, these commands fail with the appropriate not-supported code NFC_ERR_UNSUPPORTED and additionally return -2 error code to ice-tea. Commands like the erase command is a no-op on a NFC Controller target in the test app, for test-writting convenience.
**unimplemented CLI commands**
@ -323,7 +322,8 @@ You can issue the command "getlastnfcerror help" to see a list of error codes th
```
# Known issues
1. The test app defines large buffer to store the maximum realistic message of 8K by default. For targets with limited memory (< ~32K) will need to modify the app config. Open mbed_app.config and modify the setting ` "TEST_NDEF_MSG_MAX" : 8192` to suit by overriding it on specific targets. The test cases (python code) which stress read/write will need updates if the buffer is reduced to 2K by editing test_nfc.py and modifying the line(s) to fall within the new macro value.
1. The test app defines large buffer to store the maximum realistic message of 8K by default. For targets with limited memory (< ~32K) will need to modify the app config. Open mbed_app.config and modify the setting
` "TEST_NDEF_MSG_MAX" : 8192` to suit by overriding it on specific targets. The test cases (python code) which stress read/write will need updates if the buffer is reduced to 2K by editing test_nfc.py and modifying the line(s) to fall within the new macro value.
```python
# Values > 4 k incur large time costs
STRESS_BUFFLEN = 2050

View File

@ -23,7 +23,7 @@ import logging
import icetea_lib.tools.asserts as asserts
# Values > 4 k incur large time costs
STRESS_BUFFLEN = 2050 # constant value for large buffers, this needs to be less than the target supported size.
STRESS_BUFFLEN = 4096 # Default value for large buffer tests, this value can be read from the target with a command
class CliHelper():
"""
@ -61,20 +61,20 @@ class CliHelper():
text = ">> %s=%s" % (key, value)
logging.Logger.info(text)
def assert_binary_equal(self, left, right, left_length, right_length):
asserts.assertEqual(left_length, right_length, "Buffers are not same length")
def assert_binary_equal(self, left, right):
asserts.assertEqual(len(left), len(right), "Buffers are not same length %d %d" % (len(left), len(right)))
i = 0
while i < left_length:
while i < len(left):
asserts.assertEqual(left[i], ord(right[i]), ("Missmatch @offset %d 0x%x <> 0x%x" % (i, left[i], ord(right[i]))) )
i = i + 1
def assert_text_equal(self, left, right, left_length, right_length):
def assert_text_equal(self, left, right):
"""
Asserts if the 2 buffers (Text) differ
"""
asserts.assertEqual(left_length, right_length, "Buffers are not same length")
asserts.assertEqual(len(left), len(right), "Buffers are not same length %d %d" % (len(left), len(right)))
i = 0
while i < left_length:
while i < len(left):
asserts.assertEqual(ord(left[i]), ord(right[i]), ("Missmatch @offset %d %d <> %d" % (i, ord(left[i]), ord(right[i]))) )
i = i + 1

View File

@ -21,28 +21,28 @@ import logging
class NfcErrors(Enum):
nfc_ok = 0
nfc_ok = 0
nfc_err_unknown = 1
nfc_err_length = 2
nfc_err_not_found = 3
nfc_err_unsupported = 4
nfc_err_params = 5
nfc_err_buffer_too_small= 6
nfc_err_buffer_too_small = 6
nfc_err_timeout = 7
nfc_err_crc = 8
nfc_err_nopeer = 9
nfc_err_parity = 10
nfc_err_field = 11
nfc_err_collision = 12
nfc_err_wrong_comm = 13
nfc_err_protocol = 14
nfc_err_busy = 15
nfc_err_controller = 16
nfc_err_halted = 17
nfc_err_mac = 18
nfc_err_underflow = 19
nfc_err_disconnected = 20
nfc_err_aborted = 21
nfc_err_parity = 10
nfc_err_field = 11
nfc_err_collision = 12
nfc_err_wrong_comm = 13
nfc_err_protocol = 14
nfc_err_busy = 15
nfc_err_controller = 16
nfc_err_halted = 17
nfc_err_mac = 18
nfc_err_underflow = 19
nfc_err_disconnected = 20
nfc_err_aborted = 21
'''

View File

@ -169,27 +169,22 @@ def test_nfce2e_reprogrammed(self):
asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "SmartposterRecord", "expected SmartposterRecord")
asserts.assertEqual(expectedURI, tag.ndef.records[0].uri_records[0].uri, "expected exact URI")
self.clf.parse("mute") # disable radio
self.clf.parse("mute") # disable radio, to allow a local session
# verify in target
response = self.nfc_command("dev1", "readmessage")
# check contents
expected_message = str(smartposter)
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message, len(response.parsed['nfcmessage']), len(expected_message))
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message)
@test_case(CreamSconeTests)
def test_nfce2e_read_stress(self):
"""
check - Large record can be read via contactless
check - Large record can be programmed in and read via contactless
"""
messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
textLength = STRESS_BUFFLEN # 2K < x < 4K
# calculate actual message to compare to using the library
expected_text = nfc_messages.repeat_string_to_length(messageRep, textLength)
message = nfc_messages.make_textrecord( expected_text )
response = self.nfc_command("dev1", "iseeprom")
eeprom = response.parsed['iseeprom']
@ -198,16 +193,23 @@ def test_nfce2e_read_stress(self):
self.nfc_command("dev1", "initnfc")
if not eeprom:
self.nfc_command("dev1", "start")
textLength = STRESS_BUFFLEN
else:
max_ndef = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
textLength = max_ndef / 2 # large values slow down test runs and may time out
self.nfc_command("dev1", "erase")
self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep))
# calculate actual message to compare to using the library
expected_text = nfc_messages.repeat_string_to_length(messageRep, textLength)
# write a large message to the tag via API, then read it wirelessly
self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep))
self.clf.parse("connect")
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not connect to any tag")
# assert that read the eeprom contents gives correct data and length
asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "TextRecord", "expected TextRecord")
self.assert_text_equal(tag.ndef.records[0].text, expected_text, len(tag.ndef.records[0].text), len(expected_text))
self.assert_text_equal(tag.ndef.records[0].text, expected_text)
@test_case(CreamSconeTests)
@ -216,11 +218,7 @@ def test_nfce2e_reprogrammed_stress(self):
check - Large record can be programmed from a remote and read via contactless
"""
messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
textLength = STRESS_BUFFLEN # 2K < x < 4K
# calculate actual message to compare to using the library
message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(messageRep, textLength))
expected_message = str(message)
response = self.nfc_command("dev1", "iseeprom")
eeprom = response.parsed['iseeprom']
@ -229,31 +227,38 @@ def test_nfce2e_reprogrammed_stress(self):
self.nfc_command("dev1", "initnfc")
if not eeprom:
self.nfc_command("dev1", "start")
textLength = STRESS_BUFFLEN
else:
max_ndef = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
textLength = max_ndef / 2 # large values slow down test runs and may time out
# calculate actual message to compare to using the library
message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(messageRep, textLength))
expected_message = str(message)
self.nfc_command("dev1", "erase")
# program a large tag to target wirelessly
# program a large tag to target remotely
self.clf.parse("connect")
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not connect to any tag")
nfc_messages.program_remote_tag(message, tag)
self.logger.info("%d bytes chunk of data written to tag remotely" % len(str(message)))
# read device
# read device locally
self.clf.parse("connect")
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not re-connect to any tag")
self.clf.parse("mute") # disable the reader radio
self.clf.parse("mute") # disable the reader radio, to allow local access
# verify in target
response = self.nfc_command("dev1", "readmessage")
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message, len(response.parsed['nfcmessage']), len(expected_message))
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message)
@test_case(CreamSconeTests)
def test_nfce2e_discovery_loop(self):
"""
check - Controller discovery loop stop/start
fails : blocked by an issue
fails : blocked by an issue on NFC controllers only
"""
expectedURI = "https://www.nasa.com" # ensure that these differ per test case
@ -261,7 +266,8 @@ def test_nfce2e_discovery_loop(self):
eeprom = response.parsed['iseeprom']
self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
self.nfc_command("dev1", "initnfc") # this NOT automatically start discovery at the same time, the test command "start" must be used on a controller. (Eeeproms always have the loop enabled.)
self.nfc_command("dev1", "initnfc") # this NOT automatically start discovery at the same time, the test command
# "start" must be used on a controller. (Eeeproms always have the loop enabled.)
# By default, the test app automatically starts discovery loop again after a reader disconnects from the controller.
# Automatic resume after disconnect can be turned off by using command "start man" , the default is "start auto" .
@ -294,3 +300,4 @@ def test_nfce2e_discovery_loop(self):
# eeprom, so not supported
self.nfc_command("dev1", "start", expected_retcode=-2, expected_nfc_error= NfcErrors.nfc_err_unsupported )
self.nfc_command("dev1", "stop", expected_retcode=-2, expected_nfc_error= NfcErrors.nfc_err_unsupported )

View File

@ -23,6 +23,7 @@ import nfc_messages
from nfc_messages import NfcErrors
from nfc_cli_helper import CliHelper
from nfc_cli_helper import STRESS_BUFFLEN
import nfc
"""
Standalone (no NFC reader needed) tests, which cover API with no end-to-end checks.
@ -146,7 +147,7 @@ def test_nfc_write_long(self):
self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep))
response = self.nfc_command("dev1", "readmessage")
# assert that read the eeprom contents gives textlength bytes (including framing bytes which will vary)
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message, len(response.parsed['nfcmessage']), len(expected_message))
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message)
'''
check - Query supported protocols if we have a controller
@ -177,13 +178,13 @@ def test_nfc_set_controller_protocols(self):
if eeprom:
self.logger.info("Test ignore - target includes NFCEEPROM: %s" % eeprom)
else:
response = self.nfc_command("dev1", "setprotocols t1t")
response = self.nfc_command("dev1", "setprotocols t2t")
response = self.nfc_command("dev1", "setprotocols t3t")
response = self.nfc_command("dev1", "setprotocols isodep")
response = self.nfc_command("dev1", "setprotocols nfcdep")
response = self.nfc_command("dev1", "setprotocols t5t")
response = self.nfc_command("dev1", "setprotocols t1t t2t t3t isodep nfcdep t5t")
self.nfc_command("dev1", "setprotocols t1t")
self.nfc_command("dev1", "setprotocols t2t")
self.nfc_command("dev1", "setprotocols t3t")
self.nfc_command("dev1", "setprotocols isodep")
self.nfc_command("dev1", "setprotocols nfcdep")
self.nfc_command("dev1", "setprotocols t5t")
self.nfc_command("dev1", "setprotocols t1t t2t t3t isodep nfcdep t5t")
'''
check - SmartPoster URI forms are supported (in the test-app)
@ -241,3 +242,14 @@ def test_nfc_check_smartposter_uri_forms(self):
asserts.assertEqual(result.parsed['uri_id'], IDS.TEL)
result = self.nfc_command("dev1", "setsmartposter ftp://www.mbed.com/files/")
asserts.assertEqual(result.parsed['uri_id'], IDS.FTP )
'''
smoke - driver buffer size can be retrieved
'''
@test_case(CreamSconeSelfTests)
def test_nfc_get_max_ndef(self):
self.nfc_command("dev1", "initnfc")
max = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
self.logger.info("Target NDEF max buffer size %d" % max)
self.logger.info("Teststress size %d" % STRESS_BUFFLEN)