removed 'using nn' +listed issues +uri types

pull/9184/head
Conrad Braam 2019-01-09 16:20:06 +00:00
parent fa29270b2e
commit 7095b82126
14 changed files with 236 additions and 91 deletions

View File

@ -1,4 +1,7 @@
{
"config": {
"TEST_NDEF_MSG_MAX" : 8192
},
"target_overrides": {
"DISCO_L475VG_IOT01A": {
"target.extra_labels_add": ["M24SR"],

View File

@ -27,6 +27,8 @@
#include "nfcProcessEeprom.h"
#endif
using mbed::nfc::nfc_rf_protocols_bitmask_t;
events::EventQueue nfcQueue;
rtos::Thread nfcThread;
NFCTestShim *pNFC_Test_Shim = NULL;
@ -87,6 +89,7 @@ int HandleTestCommand::cmd_read_message(int argc, char *argv[])
int HandleTestCommand::cmd_set_smartposter(int argc, char *argv[])
{
// args are "setsmartposter", "<uri>"
if (argc <= 1) {
cmd_printf("setlastnfcerror() invalid parameter(s)\r\n");
return (CMDLINE_RETCODE_INVALID_PARAMETERS);

View File

@ -41,7 +41,7 @@ public:
// start thread and handle queue
HandleTestCommand();
/* set corresponding mask bit on, return false if the supplied string cannot parse */
static bool set_protocol_target(nfc_rf_protocols_bitmask_t &bitmask, const char *protocolName);
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 */
static int cmd_get_last_nfc_error(int argc, char *argv[])

View File

@ -183,7 +183,7 @@ void NFCProcessController::on_discovery_terminated(
}
void NFCProcessController::on_nfc_initiator_discovered(
const SharedPtr<NFCRemoteInitiator> &nfc_initiator)
const SharedPtr<mbed::nfc::NFCRemoteInitiator> &nfc_initiator)
{
cmd_printf("on_nfc_initiator_discovered()\r\n");

View File

@ -38,33 +38,24 @@
#include "nfc/NFCController.h"
#include "nfc/ndef/common/util.h"
using mbed::nfc::NFCRemoteInitiator;
using mbed::nfc::NFCController;
using mbed::nfc::ndef::MessageBuilder;
using mbed::nfc::ndef::common::URI;
using mbed::nfc::ndef::common::span_from_cstr;
using mbed::Span;
/**
* Wrapper class handles calls and callbacks for NFC controller drivers. Note, that users must call "start"
* in order to start the discovery loop for controllers. An internal buffer stores the NFC message and records.
*/
class NFCProcessController: NFCTestShim,
NFCRemoteInitiator::Delegate,
NFCController::Delegate {
mbed::nfc::NFCRemoteInitiator::Delegate,
mbed::nfc::NFCController::Delegate {
public:
NFCProcessController(events::EventQueue &queue);
nfc_err_t init();
nfc_err_t start_discovery();
nfc_err_t stop_discovery();
nfc_rf_protocols_bitmask_t get_rf_protocols();
nfc_err_t set_rf_protocols(nfc_rf_protocols_bitmask_t protocols);
mbed::nfc::nfc_rf_protocols_bitmask_t get_rf_protocols();
nfc_err_t set_rf_protocols(mbed::nfc::nfc_rf_protocols_bitmask_t protocols);
virtual void parse_ndef_message(const Span<const uint8_t> &buffer);
virtual size_t build_ndef_message(const Span<uint8_t> &buffer);
virtual void parse_ndef_message(const mbed::Span<const uint8_t> &buffer);
virtual size_t build_ndef_message(const mbed::Span<uint8_t> &buffer);
const char *str_discovery_terminated_reason(
nfc_discovery_terminated_reason_t reason);
@ -83,13 +74,13 @@ private:
/**
* Implementation of NFCController::Delegate */
virtual void on_nfc_initiator_discovered(
const SharedPtr<NFCRemoteInitiator> &nfc_initiator);
const SharedPtr<mbed::nfc::NFCRemoteInitiator> &nfc_initiator);
private:
mbed::nfc::PN512SPITransportDriver _pn512_transport;
mbed::nfc::PN512Driver _pn512_driver;
NFCController _nfc_controller;
SharedPtr<NFCRemoteInitiator> _nfc_remote_initiator;
mbed::nfc::NFCController _nfc_controller;
SharedPtr<mbed::nfc::NFCRemoteInitiator> _nfc_remote_initiator;
};
#endif // Controller

View File

@ -42,10 +42,12 @@ using mbed::nfc::ndef::common::span_from_cstr;
using mbed::nfc::ndef::common::Mime;
using mbed::nfc::ndef::common::Text;
using mbed::nfc::ndef::common::URI;
using mbed::nfc::NFCEEPROM;
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)
{}
nfc_err_t NFCProcessEEPROM::init()

View File

@ -31,19 +31,13 @@
#include "NFCEEPROM.h"
#include "EEPROMDriver.h"
using mbed::nfc::ndef::MessageBuilder;
using mbed::nfc::ndef::common::URI;
using mbed::nfc::ndef::common::span_from_cstr;
using mbed::Span;
using mbed::nfc::NFCEEPROM;
using mbed::nfc::NFCEEPROMDriver;
/**
* Wrapper class handles events specific to the EEPROM driver.
*/
class NFCProcessEEPROM : NFCTestShim, mbed::nfc::NFCEEPROM::Delegate {
public:
NFCProcessEEPROM(events::EventQueue &queue, NFCEEPROMDriver &eeprom_driver);
NFCProcessEEPROM(events::EventQueue &queue, mbed::nfc::NFCEEPROMDriver &eeprom_driver);
nfc_err_t init();
void queue_write_call();
void queue_write_long_call();
@ -53,14 +47,13 @@ public:
private:
virtual void on_ndef_message_written(nfc_err_t result);
virtual void on_ndef_message_read(nfc_err_t result);
virtual void parse_ndef_message(const Span<const uint8_t> &buffer);
virtual size_t build_ndef_message(const Span<uint8_t> &buffer);
virtual void parse_ndef_message(const mbed::Span<const uint8_t> &buffer);
virtual size_t build_ndef_message(const mbed::Span<uint8_t> &buffer);
virtual void on_ndef_message_erased(nfc_err_t result);
private:
NFCEEPROM _eeprom;
mbed::nfc::NFCEEPROM _eeprom;
};
#endif // eeprom
#endif // _NFCPROCESS_H_INCLUDED

View File

@ -38,9 +38,48 @@ using mbed::nfc::ndef::common::Text;
using mbed::nfc::ndef::common::URI;
using mbed::nfc::nfc_rf_protocols_bitmask_t;
// statics
namespace {
char long_string[0x2000];
char long_string[MBED_CONF_APP_TEST_NDEF_MSG_MAX];
char const *uri_prefix_string[] = { "",
"http://www.",
"https://www.",
"http://",
"https://",
"tel:",
"mailto:",
"ftp://anonymous:anonymous@",
"ftp://ftp.",
"ftps://",
"sftp://",
"smb://",
"nfs://",
"ftp://",
"dav://",
"news:",
"telnet://",
"imap:",
"rstp://",
"urn:",
"pop:",
"sip:",
"sips:",
"tftp:",
"btspp://",
"btl2cap://",
"btgoep://",
"tcpobex://",
"irdaobex://",
"file://",
"urn:epc:id:",
"urn:epc:tag:",
"urn:epc:pat:",
"urn:epc:raw:",
"urn:epc:",
"urn:nfc:"
};
int last_nfc_error = 0;
#if MBED_CONF_NFCEEPROM
@ -95,6 +134,31 @@ void NFCTestShim::print_ndef_message(const Span<const uint8_t> &buffer,
cmd_printf("}}\r\n");
}
URI::uri_identifier_code_t NFCTestShim::get_ndef_record_type(char const *url)
{
size_t i;
int len, bestLen = -1, index = -1;
// find largest matching prefix
for (i = 1; i < sizeof(uri_prefix_string) / sizeof(uri_prefix_string[0]); i++) {
len = strlen(uri_prefix_string[i]);
if (0 == strncmp(uri_prefix_string[i], url, len)) {
if (len > bestLen) {
index = i;
bestLen = len;
}
}
}
return (URI::uri_identifier_code_t)index;
}
char const *NFCTestShim::get_ndef_record_type_prefix(URI::uri_identifier_code_t id)
{
if ((id < 1) | (id > sizeof(uri_prefix_string) / sizeof(uri_prefix_string[0]))) {
return (""); // unknown case
}
return (::uri_prefix_string[(int)id]);
}
void NFCTestShim::cmd_init()
{
nfc_err_t ret = init();
@ -242,9 +306,11 @@ void NFCTestShim::cmd_set_smartposter(char *cmdUri)
uint8_t smart_poster_buffer[1024];
MessageBuilder smart_poster_builder(smart_poster_buffer);
char *urlbegin = strstr(cmdUri, ".");
urlbegin++;
URI uri(URI::HTTPS_WWW, span_from_cstr(urlbegin));
URI::uri_identifier_code_t uri_id = get_ndef_record_type(cmdUri);
char *urlbegin = cmdUri + strlen(get_ndef_record_type_prefix(uri_id));
URI uri(uri_id, span_from_cstr(urlbegin));
cmd_printf("{{uri_id=%d}}\r\n", (int)uri_id);
uri.append_as_record(smart_poster_builder, true);
builder.append_record(

View File

@ -29,8 +29,6 @@
#include "nfc/NFCDefinitions.h"
using mbed::nfc::nfc_rf_protocols_bitmask_t;
class NFCTestShim {
public:
NFCTestShim(events::EventQueue &queue);
@ -53,6 +51,8 @@ public:
static void get_conf_nfceeprom();
static void print_ndef_message(const mbed::Span<const uint8_t> &buffer,
size_t length);
static mbed::nfc::ndef::common::URI::uri_identifier_code_t get_ndef_record_type(char const *url);
static char const *get_ndef_record_type_prefix(mbed::nfc::ndef::common::URI::uri_identifier_code_t id);
void cmd_init();
virtual nfc_err_t init() = 0;
@ -63,18 +63,18 @@ public:
void cmd_read_nfceeprom();
void cmd_start_discovery(bool manual = false);
void cmd_stop_discovery();
void cmd_configure_rf_protocols(nfc_rf_protocols_bitmask_t protocols);
void cmd_configure_rf_protocols(mbed::nfc::nfc_rf_protocols_bitmask_t protocols);
void cmd_get_rf_protocols();
protected:
// implement/declare EEPROM and Controller model underlying common BH and delegate specializations
virtual nfc_err_t set_rf_protocols(nfc_rf_protocols_bitmask_t protocols)
virtual nfc_err_t set_rf_protocols(mbed::nfc::nfc_rf_protocols_bitmask_t protocols)
{
return NFC_ERR_UNSUPPORTED ;
};
virtual nfc_rf_protocols_bitmask_t get_rf_protocols()
virtual mbed::nfc::nfc_rf_protocols_bitmask_t get_rf_protocols()
{
nfc_rf_protocols_bitmask_t none;
mbed::nfc::nfc_rf_protocols_bitmask_t none;
return none;
};
virtual nfc_err_t start_discovery()
@ -97,8 +97,8 @@ protected:
protected:
size_t _ndef_write_buffer_used;
mbed::Span<uint8_t> ndef_poster_message; // message to build and send
uint8_t _ndef_write_buffer[0x2000]; // if this buffer is smaller than the EEPROM, the driver may crash see IOTPAN-297
uint8_t _ndef_buffer[0x2000]; // driver I/O buffer
uint8_t _ndef_write_buffer[MBED_CONF_APP_TEST_NDEF_MSG_MAX]; // if this buffer is smaller than the EEPROM, the driver may crash see IOTPAN-297
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;

View File

@ -43,7 +43,8 @@ class NfcTestParsers(PluginBase):
results = {'iseeprom': None, # 'true' if EEPROM
'lastnfcerror':None, # 0=OK >0 = error
'nfcmessage':None, # NDEF array of bytes
'protocols':None} # csv list
'protocols':None, # csv list
'uri_id':None} # nfc URI type identifier
respLines = response.lines
for line in respLines:
try:
@ -69,6 +70,9 @@ class NfcTestParsers(PluginBase):
value = PluginBase.find_one(line, "{{protocols=(([\w]*,?)*)}}")
if value is not False:
results['protocols'] = value # a csv list
value = PluginBase.find_one(line, "{{uri_id=([0-9]+)}}")
if value is not False:
results['uri_id'] = 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

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)
- [NFC System Testing high level design](#nfc-system-testing-high-level-design)
- [System Test high level design](#system-test-high-level-design)
- [Low level design](#low-level-design)
- [User Guide](#user-guide)
- [Test cases](#test-cases)
@ -17,6 +17,7 @@ This project is called CreamScone, which is an ice tea framework based cli-drive
- [How to](#how-to)
- [Running the tests](#running-the-tests)
- [Alternate NFC drivers note:](#alternate-nfc-drivers-note)
- [Known issues](#known-issues)
<!-- /TOC -->
@ -45,7 +46,7 @@ Because the comissioning workflow application quality is the end goal, the NFC s
# NFC System Testing high level design
# System Test high level design
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
@ -62,36 +63,43 @@ In short, “Empower engineers to efficiently ship quality code with confidence.
- Be able to set up and run locally in development
# Low level design
**components**
**Components**
An icetea suite [test_nfc.py](TEST_APPS\testcases\nfc\test_nfc.py)
API standalone Self tests [test_self.py](TEST_APPS\testcases\nfc\test_self.py)
Commandline (serial port) driven app [ice_device.py](TEST_APPS\testcases\nfc\ice_device.py) aka _'CreamScone'_ which allows manual interactions with the driver.
An icetea plugin [nfc_test_parsers.py](TEST_APPS\icetea_plugins\nfc_test_parsers.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 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.
The SUT target is rebooted between tests, since test modify the target hardware state.
**Future: ** A complete inter-op ready design expands to also 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 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.
![inter-op](img/inter-op-view.png)
![future](img/creamscone-mobile.png)
**Reference: **
** Reference: **
https://github.com/ARMmbed/mbed-os/blob/master/docs/design-documents/nfc/nfc_design.md
[ARMmbed NFC design](https://github.com/ARMmbed/mbed-os/blob/master/docs/design-documents/nfc/nfc_design.md)
https://github.com/ARMmbed/mbed-os/tree/master/features/nfc/nfc
[ARMmbed NFC code](https://github.com/ARMmbed/mbed-os/tree/master/features/nfc/nfc)
https://github.com/ARMmbed/mbed-os-example-nfc
[ARMmbed NFC example application](https://github.com/ARMmbed/mbed-os-example-nfc/)
[Python NFC library](https://nfcpy.readthedocs.io/en/latest/topics/get-started.html)
[NFC forum](https://nfc-forum.org/)
# User Guide
This section covers the test case specification and how to run the test suite.
The SUT target is rebooted between tests, since tests modify the target hardware state.
## Test cases
CLI commands used by each test case describe the steps in a test.
** Basic local only cases **
@ -196,7 +204,7 @@ indicated pins on the Shield.
```
Schematic (https://www.element14.com/community/docs/DOC-76384/l/explore-nfc-board-schematic)
To change pinouts, if your reference design or shield pins differ for the PN512 controller driver, open nfcProcessCtrl.cpp and find the code
```
```json
NFCProcessController::NFCProcessController(events::EventQueue &queue) :
// pins: mosi, miso, sclk, ssel, irq, rst
_pn512_transport(D11, D12, D13, D10, A1, A0), _pn512_driver(
@ -209,7 +217,7 @@ modify pins as needed.
**Compilation target drivers**
If using the EEPROM driver, the mbed_app.json will contain
```
```json
"target_overrides": {
"DISCO_L475VG_IOT01A": {
"target.extra_labels_add": ["M24SR"]
@ -218,7 +226,7 @@ If using the EEPROM driver, the mbed_app.json will contain
...
```
If using the Explorer Shield or PN512 driver mbed_app.json will add
```
```json
"target_overrides": {
"NUCLEO_F401RE": {
"target.extra_labels_add": ["PN512"]
@ -248,17 +256,17 @@ And copy the files into your mbed root:
`xcopy ..\mbed-nfc-m24sr\*.* .\eeprom_driver\'
To run the End2End tests, type:
`mbed test --icetea -n test_nfce2e`
`mbed test --icetea --app-config .\TEST_APPS\device\nfcapp\mbed_app.json -n test_nfce2e`
To run only the standalone (readerless tests if you do not have a card reader), type:
`mbed test --icetea -n test_nfc_eeprom,test_nfc_error_codes,test_nfc_setsmartposter,test_nfc_erase,test_nfc_write_long`
`mbed test --icetea --app-config .\TEST_APPS\device\nfcapp\mbed_app.json -n test_nfc_eeprom,test_nfc_error_codes,test_nfc_setsmartposter,test_nfc_erase,test_nfc_write_long`
# Alternate NFC drivers note:
Please see the example json file .\TEST_APPS\testcases\nfc\mbed_app.json . The test does not check that you have any needed shield installed, so if it "hangs" at the point the "initnfc" command is used, the driver or shield may be the fault. The test assumes that MBED_CONF_NFCEEPROM is set to 1, if not it assumes that a NFC Controller driver is in use. To test drivers other than PN512 and M24SR, it is required to make test code changes that reference the driver. The driver can be instantiated once only.
If the new driver you add is for Eeprom, open nfccommands.cpp and find the code and modify line as shown +++
```
```C++
NFCTestShim* new_testshim() {
#if MBED_CONF_NFCEEPROM
--- mbed::nfc::NFCEEPROMDriver& eeprom_driver = get_eeprom_driver(nfcQueue);
@ -272,7 +280,7 @@ NFCTestShim* new_testshim() {
```
If the driver you add is a Controller driver, open nfcProcessCtrl.cpp and find the code
```
```C++
NFCProcessController::NFCProcessController(events::EventQueue &queue) :
// pins: mosi, miso, sclk, ssel, irq, rst
_pn512_transport(D11, D12, D13, D10, A1, A0), _pn512_driver(
@ -289,7 +297,7 @@ Note: If the target uses an EEPROM, it need not be powered/running, to be read,
**Device API error codes**
You can issue the command "getlastnfcerror help" to see a list of error codes that are returned by most commands.
```
```C++
#define NFC_OK 0 ///< No error
#define NFC_ERR_UNKNOWN 1 ///< Unknown error
#define NFC_ERR_LENGTH 2 ///< Length of parameter is wrong
@ -313,3 +321,16 @@ You can issue the command "getlastnfcerror help" to see a list of error codes th
#define NFC_ERR_DISCONNECTED 20 ///< Link has disconnected
#define NFC_ERR_ABORTED 21 ///< Command was aborted
```
# 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.
```python
# Values > 4 k incur large time costs
STRESS_BUFFLEN = 2050
```
2. The test app and the supplied drivers only support Type4 tags. The test app thus does not exercise the different protocols and always sets iso-dep level functionality (Type4) for NFC Controller initialization.
1. Test test_nfce2e_discovery_loop fails on NFC controller. The NFC controller driver discovery loop cannot be stopped manually. No major functionality is lost, it only prevents a complete disable of NFC at runtime. A bug ticket #IOTPAN-313 was logged to fix the stop function. The Controller still restarts discovery loop normally under app control after a peer disconnects.
1. The smartposter NDEF record wrapper class `smartposter.h` is also provided as part of the NFC examples. The examples are not needed to compile the test app, but this example class may be usefull to customers. This file may thus move into the NFC component in future.

View File

@ -22,9 +22,12 @@ from nfc_messages import NfcErrors
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.
class CliHelper():
"""
Helper method, checks the nfc SDK error-code for you, makes writing a negative test much easier
Helper methods, checks the nfc SDK error-code for you, makes writing a negative test much easier
Example:
if (target_is_eeprom):
nfc_command("dev1", "start", expected_retcode=-2, expected_nfc_error= NfcErrors.nfc_err_unsupported)
@ -39,6 +42,9 @@ class CliHelper():
asynchronous=False,
report_cmd_fail=True,
expected_nfc_error=NfcErrors.nfc_ok):
"""
By default will assert if the NFC result code is non-zero.
"""
response = self.command(k, cmd, wait, timeout, expected_retcode, asynchronous, report_cmd_fail)
asserts.assertEqual(int(response.parsed['lastnfcerror']), expected_nfc_error.value)
return response
@ -50,23 +56,25 @@ class CliHelper():
@staticmethod
def debug_nfc_data(key, value):
"""
print useful data values for the host/user {{in between}} easy to spot brackets.
print useful data values for the host/user with a >> preamble to make it easy to spot
"""
text = "{{%s=%s}}" % (key, value)
text = ">> %s=%s" % (key, value)
logging.Logger.info(text)
def assert_binary_equal(self, left, right, length):
def assert_binary_equal(self, left, right, left_length, right_length):
asserts.assertEqual(left_length, right_length, "Buffers are not same length")
i = 0
while i < length:
while i < left_length:
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, length):
def assert_text_equal(self, left, right, left_length, right_length):
"""
Asserts if the 2 buffers (Text) differ
"""
asserts.assertEqual(left_length, right_length, "Buffers are not same length")
i = 0
while i < length:
while i < left_length:
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

@ -24,6 +24,7 @@ from mbed_clitest.tools.tools import test_case
import icetea_lib.tools.asserts as asserts
from nfc_messages import NfcErrors
from nfc_cli_helper import CliHelper
from nfc_cli_helper import STRESS_BUFFLEN
class CreamSconeTests(Bench, CliHelper):
@ -75,6 +76,9 @@ def test_nfce2e_target_found(self):
response = self.nfc_command("dev1", "iseeprom")
eeprom = response.parsed['iseeprom']
# Invokes icetea command, this method also checks the NFC api result expected_nfc_error=NFC_OK
# Tester can supply the expected_nfc_error=NFC_XXX parameter, to override.
self.nfc_command("dev1", "initnfc")
if not eeprom:
self.nfc_command("dev1", "start")
@ -172,8 +176,7 @@ def test_nfce2e_reprogrammed(self):
# check contents
expected_message = str(smartposter)
asserts.assertEqual(len(response.parsed['nfcmessage']), len(expected_message))
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message, len(expected_message))
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message, len(response.parsed['nfcmessage']), len(expected_message))
@test_case(CreamSconeTests)
@ -182,7 +185,7 @@ def test_nfce2e_read_stress(self):
check - Large record can be read via contactless
"""
messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
textLength = 2050 # 2K < x < 4K
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)
@ -204,8 +207,7 @@ def test_nfce2e_read_stress(self):
# assert that read the eeprom contents gives correct data and length
asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "TextRecord", "expected TextRecord")
asserts.assertEqual(len(tag.ndef.records[0].text), len(expected_text))
self.assert_text_equal(tag.ndef.records[0].text, expected_text, len(expected_text))
self.assert_text_equal(tag.ndef.records[0].text, expected_text, len(tag.ndef.records[0].text), len(expected_text))
@test_case(CreamSconeTests)
@ -214,7 +216,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 = 2050 # 2K < x < 4K
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))
@ -244,8 +246,7 @@ def test_nfce2e_reprogrammed_stress(self):
# verify in target
response = self.nfc_command("dev1", "readmessage")
asserts.assertEqual(len(response.parsed['nfcmessage']), len(expected_message))
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message, len(expected_message))
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message, len(response.parsed['nfcmessage']), len(expected_message))
@test_case(CreamSconeTests)

View File

@ -22,7 +22,7 @@ import icetea_lib.tools.asserts as asserts
import nfc_messages
from nfc_messages import NfcErrors
from nfc_cli_helper import CliHelper
from nfc_cli_helper import STRESS_BUFFLEN
"""
Standalone (no NFC reader needed) tests, which cover API with no end-to-end checks.
@ -110,7 +110,7 @@ check - Create a SmartPoster but does not read it back
def test_nfc_setsmartposter(self):
self.nfc_command("dev1", "initnfc")
self.nfc_command("dev1", "setsmartposter -u https://www.mbed.com")
self.nfc_command("dev1", "setsmartposter https://www.mbed.com")
@test_case(CreamSconeSelfTests)
def test_nfc_erase(self):
@ -131,7 +131,7 @@ can be read back.
@test_case(CreamSconeSelfTests)
def test_nfc_write_long(self):
messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
textLength = 200 # 2K < x < 4K
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)
@ -146,12 +146,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)
asserts.assertEqual(len(response.parsed['nfcmessage']), len(expected_message))
i = 0
# assert that read the eeprom contents gives thequickbrownfoxjumpedoverthelazydog repeated in loop
while i < len(response.parsed['nfcmessage']):
asserts.assertEqual(response.parsed['nfcmessage'][i], ord(expected_message[i]))
i = i + 1
self.assert_binary_equal(response.parsed['nfcmessage'], expected_message, len(response.parsed['nfcmessage']), len(expected_message))
'''
check - Query supported protocols if we have a controller
@ -170,7 +165,8 @@ def test_nfc_get_controller_protocols(self):
'''
Set used protocols if we have an controller
check - Can set used protocols if we have a controller
Note: Currently only support Typ4 tags in PN512 driver
'''
@test_case(CreamSconeSelfTests)
def test_nfc_set_controller_protocols(self):
@ -188,3 +184,60 @@ def test_nfc_set_controller_protocols(self):
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")
'''
check - SmartPoster URI forms are supported (in the test-app)
'''
@test_case(CreamSconeSelfTests)
def test_nfc_check_smartposter_uri_forms(self):
def enum(**enums):
return type('Enum', (), enums)
IDS = enum(NA=0x00, # Not applicable
HTTP_WWW=0x01, # http://www.
HTTPS_WWW=0x02, # https://www.
HTTP=0x03, # http://
HTTPS=0x04, # https://
TEL=0x05, # tel:
MAILTO=0x06, # mailto:
FTP_ANONYMOUS=0x07, # ftp://anonymous:anonymous@
FTP_FTP=0x08, # ftp://ftp.
FTPS=0x09, # ftps://
SFTP=0x0A, # sftp://
SMB=0x0B, # smb://
NFS=0x0C, # nfs://
FTP=0x0D, # ftp://
DAV=0x0E, # dav://
NEWS=0x0F, # news:
TELNET=0x10, # telnet://
IMAP=0x11, # imap:
RSTP=0x12, # rstp://
URN=0x13, # urn:
POP=0x14, # pop:
SIP=0x15, # sip:
SIPS=0x16, # sips:
TFTP=0x17, # tftp:
BTSPP=0x18, # btspp://
BTL2CAP=0x19, # btl2cap://
BTGOEP=0x1A, # btgoep://
TCPOBEX=0x1B, # tcpobex://
IRDAOBEX=0x1C, # irdaobex://
FILE=0x1D, # file://
URN_EPC_ID=0x1E, # urn:epc:id:
URN_EPC_TAG=0x1F, # urn:epc:tag:
URN_EPC_PAT=0x20, # urn:epc:pat:
URN_EPC_RAW=0x21, # urn:epc:raw:
URN_EPC=0x22, # urn:epc:
URN_NFC=0x23, # urn:nfc:
)
self.nfc_command("dev1", "initnfc")
result = self.nfc_command("dev1", "setsmartposter https://www.mbed.com")
asserts.assertEqual(result.parsed['uri_id'], IDS.HTTPS_WWW, "uri type expected HTTPS_WWW")
result = self.nfc_command("dev1", "setsmartposter http://www.mbed.com")
asserts.assertEqual(result.parsed['uri_id'], IDS.HTTP_WWW)
result = self.nfc_command("dev1", "setsmartposter https://www.topleveldomain")
asserts.assertEqual(result.parsed['uri_id'], IDS.HTTPS_WWW)
result = self.nfc_command("dev1", "setsmartposter tel:555-5551234")
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 )