code review from paul,don addressed:compilers fixed

pull/9184/head
Conrad Braam 2019-02-04 18:00:30 +00:00
parent c509af32ce
commit dea37cb97e
11 changed files with 98 additions and 125 deletions

View File

@ -1,19 +1,28 @@
{ {
"config": { "config": {
"TEST_NDEF_MSG_MAX" : 1024 "TEST_NDEF_MSG_MAX": {
"help": "NFC-Driver buffer (EEPROM and Controller) maximum MAX Size of NFC message(s) driver buffer",
"value": 4096
}
}, },
"target_overrides": { "target_overrides": {
"DISCO_L475VG_IOT01A": { "DISCO_L475VG_IOT01A": {
"target.extra_labels_add": ["M24SR"], "target.extra_labels_add": ["M24SR"],
"MBED_NFC_M24SR.nfceeprom": true "MBED_NFC_M24SR.nfceeprom": true
}, },
"NUCLEO_F401RE": { "NUCLEO_F401RE": {
"target.extra_labels_add": ["PN512"] "target.extra_labels_add": ["PN512"],
"MBED_NFC_M24SR.nfceeprom": false
}, },
"NUCLEO_F746ZG": { "NUCLEO_F746ZG": {
"target.extra_labels_add": ["M24SR"], "target.extra_labels_add": ["M24SR"],
"MBED_NFC_M24SR.X_NUCLEO_NFC01A1": true, "MBED_NFC_M24SR.X_NUCLEO_NFC01A1": true,
"MBED_NFC_M24SR.nfceeprom": true "MBED_NFC_M24SR.nfceeprom": true
},
"NUCLEO_F429ZI": {
"target.extra_labels_add": ["M24SR"],
"MBED_NFC_M24SR.X_NUCLEO_NFC01A1": true,
"MBED_NFC_M24SR.nfceeprom": true
} }
} }
} }

View File

@ -17,6 +17,7 @@
#include <vector> #include <vector>
#include <stdarg.h> #include <stdarg.h>
#include <stdlib.h> #include <stdlib.h>
#include <ctype.h>
#include "mbed_events.h" #include "mbed_events.h"
#include "mbed-client-cli/ns_cmdline.h" #include "mbed-client-cli/ns_cmdline.h"
#include "rtos\Thread.h" #include "rtos\Thread.h"

View File

@ -17,6 +17,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <cstring> #include <cstring>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "mbed_events.h" #include "mbed_events.h"
#include "mbed-client-cli/ns_cmdline.h" #include "mbed-client-cli/ns_cmdline.h"
@ -98,6 +99,7 @@ void NFCProcessEEPROM::on_ndef_message_written(nfc_err_t result)
} }
// complete the async test method here // complete the async test method here
cmd_ready(CMDLINE_RETCODE_SUCCESS); cmd_ready(CMDLINE_RETCODE_SUCCESS);
free(long_string); // free buffer allocated by the command class now
} }
void NFCProcessEEPROM::on_ndef_message_read(nfc_err_t result) void NFCProcessEEPROM::on_ndef_message_read(nfc_err_t result)

View File

@ -38,12 +38,12 @@
class NFCProcessEEPROM : NFCTestShim, mbed::nfc::NFCEEPROM::Delegate { class NFCProcessEEPROM : NFCTestShim, mbed::nfc::NFCEEPROM::Delegate {
public: public:
NFCProcessEEPROM(events::EventQueue &queue, mbed::nfc::NFCEEPROMDriver &eeprom_driver); NFCProcessEEPROM(events::EventQueue &queue, mbed::nfc::NFCEEPROMDriver &eeprom_driver);
nfc_err_t init(); virtual nfc_err_t init();
void queue_write_call(); void queue_write_call();
void queue_write_long_call(); void queue_write_long_call();
void queue_read_call(); void queue_read_call();
void queue_erase_call(); void queue_erase_call();
void cmd_get_max_ndef(); virtual void cmd_get_max_ndef();
private: private:

View File

@ -17,6 +17,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <cstring> #include <cstring>
#include <string.h> #include <string.h>
#include <stdlib.h>
#include "mbed-client-cli/ns_cmdline.h" #include "mbed-client-cli/ns_cmdline.h"
#include "nfc/ndef/common/Text.h" #include "nfc/ndef/common/Text.h"
#include "nfc/ndef/common/URI.h" #include "nfc/ndef/common/URI.h"
@ -41,7 +42,7 @@ using mbed::nfc::nfc_rf_protocols_bitmask_t;
// statics // statics
namespace { namespace {
char long_string[MBED_CONF_APP_TEST_NDEF_MSG_MAX];
char const *uri_prefix_string[] = { "", char const *uri_prefix_string[] = { "",
"http://www.", "http://www.",
"https://www.", "https://www.",
@ -278,15 +279,15 @@ void NFCTestShim::cmd_erase()
/** \brief Writes a Text T record buffer with really long message - length checks to be done by driver only. /** \brief Writes a Text T record buffer with really long message - length checks to be done by driver only.
* If an NFC controller, no write to the chip happens, we copy the data into a Controller buffer * If an NFC controller, no write to the chip happens, we copy the data into a Controller buffer
* \param uri This method must free the passed in pointer * \param text_string This method must free the passed in pointer
* \return void An ICETEA error code and NFC error is set asyncronously * \return void An ICETEA error code and NFC error is set asynchronously
*/ */
void NFCTestShim::cmd_write_long(char *text_string) void NFCTestShim::cmd_write_long(char *text_string)
{ {
MessageBuilder builder(_ndef_poster_message); MessageBuilder builder(_ndef_poster_message);
strcpy(::long_string, text_string); //max_ndef - header - overheads long_string = text_string; // copy the pointer and free it when the write completes
Text text(Text::UTF8, span_from_cstr("en-US"), Text text(Text::UTF8, span_from_cstr("en-US"),
span_from_cstr((const char *)(::long_string))); span_from_cstr((const char *)(long_string)));
text.append_as_record(builder, true); text.append_as_record(builder, true);
_ndef_write_buffer_used = builder.get_message().size(); _ndef_write_buffer_used = builder.get_message().size();
@ -295,12 +296,12 @@ void NFCTestShim::cmd_write_long(char *text_string)
#if MBED_CONF_NFCEEPROM #if MBED_CONF_NFCEEPROM
((NFCProcessEEPROM *)this)->queue_write_call(); ((NFCProcessEEPROM *)this)->queue_write_call();
#else #else
// not on a wire, so the caller will store the message in a buffer // not on a wire, and we just stored the message in _ndef_write_buffer above
set_last_nfc_error(NFC_OK); set_last_nfc_error(NFC_OK);
cmd_ready(CMDLINE_RETCODE_SUCCESS); cmd_ready(CMDLINE_RETCODE_SUCCESS);
free(long_string); // free buffer allocated by the command class now
#endif #endif
trace_printf("NFCTestShim::write_long() exit\r\n"); trace_printf("NFCTestShim::write_long() exit\r\n");
free(text_string);
} }
/** \brief Write a URI Use case would be to prompt to install an app from the appstore using the tag /** \brief Write a URI Use case would be to prompt to install an app from the appstore using the tag

View File

@ -100,6 +100,7 @@ protected:
uint8_t _ndef_buffer[MBED_CONF_APP_TEST_NDEF_MSG_MAX]; // driver I/O buffer 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 bool _discovery_restart; // default true, restart discovery loop again on remote disconnect
events::EventQueue &_queue; events::EventQueue &_queue;
char *long_string;
}; };
// forward declare single instance // forward declare single instance

View File

@ -110,6 +110,7 @@ class NfcTestParsers(PluginBase):
if value is not False: if value is not False:
results['lastnfcerror'] = int(value) results['lastnfcerror'] = int(value)
# {{nfcmessage=([0-9a-f\s]*)}} # {{nfcmessage=([0-9a-f\s]*)}}
# message may be split over multiple lines, so we will start a search and wait until we get a }} pair
data = PluginBase.find_one(line, "{{nfcmessage=([0-9a-f\s]*).*") data = PluginBase.find_one(line, "{{nfcmessage=([0-9a-f\s]*).*")
if data is not False: if data is not False:
started_read_data = True started_read_data = True
@ -117,10 +118,9 @@ class NfcTestParsers(PluginBase):
values = self.find_all_hex_data(line, "([0-9a-f\s]*)") values = self.find_all_hex_data(line, "([0-9a-f\s]*)")
if values is not False: if values is not False:
if "{{nfcmessage" in line: if "{{nfcmessage" in line:
value = values[0] value = values[0] # first (and possibly only data line)
else: else:
value = values[0] value += values[0] # concatenate (2nd and possibly last data line)
#print ("==%s==" % value)
partial_data += value partial_data += value
if PluginBase.find_one(line, ".*(}})") is not False: # search for end marker if PluginBase.find_one(line, ".*(}})") is not False: # search for end marker
started_read_data = False started_read_data = False

View File

@ -25,9 +25,6 @@ import logging
""" """
# def command_is(string, command):
# return string.split(' ')[0] == command
def debug_nfc_data(key, value): def debug_nfc_data(key, value):
""" """
@ -55,25 +52,27 @@ class NfcWrapper:
logger.error("The NFC reader was not detected on any USB port!") logger.error("The NFC reader was not detected on any USB port!")
self.clfResponse = None self.clfResponse = None
def clf_response(self): def connect(self):
return self.clfResponse
def connect(self, target_options = ("106A","106B","212F")):
# note: only supporting type4 # note: only supporting type4
time.sleep(0.5)
after5s = lambda: time.time() - started > 5 after5s = lambda: time.time() - started > 5
started = time.time() started = time.time()
tag = self.clf.connect( rdwr={'on-connect': lambda tag: False}, tag = self.clf.connect( rdwr={'on-connect': lambda tag: False},
llcp={}, terminate = after5s) terminate = after5s)
self.clfResponse = tag
if tag: # None if timeout expires if tag: # None if timeout expires
logging.info("NFCReader: connected " + str(tag)) logging.info("NFCReader: connected " + str(tag))
else:
logging.info("NFCReader: warning, no tag detected ")
return tag return tag
def mute(self): def mute(self):
"""turn off the reader radio""" """turn off the reader radio"""
if self.clf.device: if (self.clf.device is not None):
logging.info("NFCReader: radio mute" + self.clf.device.product_name) logging.info("NFCReader: radio mute" + self.clf.device.product_name)
self.clf.device.mute() self.clf.device.mute()
else:
logging.warning("NFCReader: reader not initialized!")
def disconnect(self): def disconnect(self):
logging.info("NFCReader: close frontend.") logging.info("NFCReader: close frontend.")
@ -97,5 +96,3 @@ class ContactlessCommandRunner():
__nfc_wrapper = None __nfc_wrapper = None
def clf_response(self):
return self.nfc.clf_response()

View File

@ -22,8 +22,8 @@ from nfc_messages import NfcErrors
import logging import logging
import icetea_lib.tools.asserts as asserts import icetea_lib.tools.asserts as asserts
# Values > 4 k incur large time costs # Values > 1 k incur large time costs
STRESS_BUFFLEN = 4096 # Default value for large buffer tests, this value can be read from the target with a command LARGE_BUFFLEN = 400 # Value for large buffer tests, a maximum value can be read from the target with a command
class CliHelper(): class CliHelper():
""" """

View File

@ -24,7 +24,7 @@ from mbed_clitest.tools.tools import test_case
import icetea_lib.tools.asserts as asserts import icetea_lib.tools.asserts as asserts
from nfc_messages import NfcErrors from nfc_messages import NfcErrors
from nfc_cli_helper import CliHelper from nfc_cli_helper import CliHelper
from nfc_cli_helper import STRESS_BUFFLEN from nfc_cli_helper import LARGE_BUFFLEN
class CreamSconeTests(Bench, CliHelper): class CreamSconeTests(Bench, CliHelper):
@ -56,16 +56,31 @@ class CreamSconeTests(Bench, CliHelper):
Bench.__init__(self, **testcase_args) Bench.__init__(self, **testcase_args)
def setup(self): def setup(self):
#try: self.logger.info("Test setup: Open Reader and mute...")
try:
self.clf = ContactlessCommandRunner() self.clf = ContactlessCommandRunner()
self.clf.nfc.mute() self.clf.nfc.mute() # mute if the last test case did not mute
#except: except:
# raise asserts.TestStepFail("Could not find NFC reader") raise asserts.TestStepFail("Could not find NFC reader")
def teardown(self): def teardown(self):
self.logger.info("Test teardown: Reboot target...") self.logger.info("Test teardown: Reboot target...")
self.reset_dut() self.reset_dut()
self.clf.nfc.mute() # mute if the last test case did not mute
def prepare_target(self):
"""
simple set up a clean target device
:return:
"""
response = self.nfc_command("dev1", "iseeprom")
eeprom = response.parsed['iseeprom']
self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
self.nfc_command("dev1", "initnfc")
if not eeprom:
self.nfc_command("dev1", "start")
self.nfc_command("dev1", "erase")
@test_case(CreamSconeTests) @test_case(CreamSconeTests)
@ -83,8 +98,7 @@ def test_nfce2e_target_found(self):
if not eeprom: if not eeprom:
self.nfc_command("dev1", "start") self.nfc_command("dev1", "start")
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not connect to any tag") asserts.assertNotNone(tag, "Could not connect to any tag")
@ -103,8 +117,7 @@ def test_nfce2e_type4_found(self):
if not eeprom: if not eeprom:
self.nfc_command("dev1", "start") self.nfc_command("dev1", "start")
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not connect to any tag") asserts.assertNotNone(tag, "Could not connect to any tag")
asserts.assertEqual(tag.type, 'Type4Tag', "Tag of type Type4Tag not found") asserts.assertEqual(tag.type, 'Type4Tag', "Tag of type Type4Tag not found")
@ -117,20 +130,12 @@ def test_nfce2e_smartposter(self):
""" """
expectedURI = "https://www.mbed.com" # ensure that these differ per test case expectedURI = "https://www.mbed.com" # ensure that these differ per test case
self.nfc_command("dev1", "initnfc") self.prepare_target()
self.nfc_command("dev1", "erase")
response = self.nfc_command("dev1", "iseeprom")
eeprom = response.parsed['iseeprom']
self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
if not eeprom:
self.nfc_command("dev1", "start")
# write poster tag to target # write poster tag to target
self.command("dev1", "setsmartposter %s" % expectedURI) self.command("dev1", "setsmartposter %s" % expectedURI)
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not connect to any tag") asserts.assertNotNone(tag, "Could not connect to any tag")
asserts.assertEqual(1, len(tag.ndef.records), "expected number NDEF records") asserts.assertEqual(1, len(tag.ndef.records), "expected number NDEF records")
@ -145,27 +150,18 @@ def test_nfce2e_reprogrammed(self):
""" """
expectedURI = "https://www.google.com" expectedURI = "https://www.google.com"
response = self.nfc_command("dev1", "iseeprom") self.prepare_target()
eeprom = response.parsed['iseeprom']
self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
self.nfc_command("dev1", "initnfc")
if not eeprom:
self.nfc_command("dev1", "start")
self.nfc_command("dev1", "erase")
# program a poster tag to target # program a poster tag to target
print("Write Smartposter MESSAGE wirelessly") self.logger.info("Write Smartposter MESSAGE wirelessly")
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not connect to any tag") asserts.assertNotNone(tag, "Could not connect to any tag")
smartposter = nfc_messages.make_smartposter(expectedURI, ["en-US:Other search engines exist"]) smartposter = nfc_messages.make_smartposter(expectedURI, ["en-US:Other search engines exist"])
nfc_messages.program_remote_tag(smartposter, tag) nfc_messages.program_remote_tag(smartposter, tag)
self.logger.info("Remote programmed %d bytes Smartposter" % len(str(smartposter))) self.logger.info("Remote programmed %d bytes Smartposter" % len(str(smartposter)))
print("Write back Smartposter MESSAGE wirelessly") self.logger.info("Write back Smartposter MESSAGE wirelessly")
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not re-connect to any tag") asserts.assertNotNone(tag, "Could not re-connect to any tag")
asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "SmartposterRecord", "expected SmartposterRecord") asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "SmartposterRecord", "expected SmartposterRecord")
@ -185,35 +181,22 @@ def test_nfce2e_read_stress(self):
""" """
check - Large record can be programmed in and read via contactless check - Large record can be programmed in and read via contactless
""" """
messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written message_to_repeat = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
text_length = LARGE_BUFFLEN
response = self.nfc_command("dev1", "iseeprom")
eeprom = response.parsed['iseeprom']
self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
max_ndef = STRESS_BUFFLEN
self.nfc_command("dev1", "initnfc")
if not eeprom:
self.nfc_command("dev1", "start")
else:
max_ndef = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
if (max_ndef > 800 ):
textLength = 800 # large values slow down test runs and may time out
else:
textLength = max_ndef
self.nfc_command("dev1", "erase")
# calculate actual message to compare to using the library # calculate actual message to compare to using the library
expected_text = nfc_messages.repeat_string_to_length(messageRep, textLength) expected_text = nfc_messages.repeat_string_to_length(message_to_repeat, text_length)
self.prepare_target()
# write a large message to the tag via API, then read it wirelessly # write a large message to the tag via API, then read it wirelessly
print("Write/set tag MESSAGE (%d) bytes" % textLength) self.logger.info("Write/set tag MESSAGE (%d) bytes" % text_length)
self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep)) self.nfc_command("dev1", "writelong %d %s" % (text_length,message_to_repeat))
self.clf.nfc.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 # assert that read the eeprom contents gives correct data and length
print("Read tag MESSAGE wirelessly" ) self.logger.info("Read tag MESSAGE wirelessly" )
tag = self.clf.nfc.connect()
asserts.assertNotNone(tag, "Could not connect to any tag")
asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "TextRecord", "expected TextRecord") asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "TextRecord", "expected TextRecord")
self.assert_text_equal(tag.ndef.records[0].text, expected_text) self.assert_text_equal(tag.ndef.records[0].text, expected_text)
@ -223,43 +206,27 @@ def test_nfce2e_reprogrammed_stress(self):
""" """
check - Large record can be programmed from a remote and read via contactless check - Large record can be programmed from a remote and read via contactless
""" """
messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written message_to_repeat = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
text_length = LARGE_BUFFLEN # large values slow down test runs and may time out
response = self.nfc_command("dev1", "iseeprom")
eeprom = response.parsed['iseeprom']
self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
max_ndef = STRESS_BUFFLEN
self.nfc_command("dev1", "initnfc")
if not eeprom:
self.nfc_command("dev1", "start")
else:
max_ndef = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
if (max_ndef > 800 ):
textLength = 800 # large values slow down test runs and may time out
else:
textLength = max_ndef
self.nfc_command("dev1", "erase")
# calculate actual message to compare to using the library # calculate actual message to compare to using the library
message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(messageRep, textLength)) message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(message_to_repeat, text_length))
expected_message = str(message) expected_message = str(message)
self.prepare_target()
# program a large tag to target remotely # program a large tag to target remotely
print("Write tag MESSAGE wirelessly (%d) bytes" % len(str(message))) self.logger.info("Write tag MESSAGE wirelessly (%d) bytes" % len(str(message)))
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not connect to any tag") asserts.assertNotNone(tag, "Could not connect to any tag")
nfc_messages.program_remote_tag(message, tag) nfc_messages.program_remote_tag(message, tag)
self.logger.info("%d bytes chunk of data written to tag remotely" % len(str(message))) self.logger.info("%d bytes chunk of data written to tag remotely" % len(str(message)))
self.clf.nfc.mute()
# read device locally # read device locally
print("Read back tag MESSAGE wirelessly") self.logger.info("Read back tag MESSAGE wirelessly")
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not re-connect to any tag") asserts.assertNotNone(tag, "Could not re-connect to any tag")
asserts.assertEqual(tag.ndef.records[0].__class__.__name__, "TextRecord", "expected TextRecord")
self.clf.nfc.mute() # disable the reader radio, to allow local access self.clf.nfc.mute() # disable the reader radio, to allow local access
# verify in target # verify in target
@ -285,27 +252,23 @@ def test_nfce2e_discovery_loop(self):
# Automatic resume after disconnect can be turned off by using command "start man" , the default is "start auto" . # Automatic resume after disconnect can be turned off by using command "start man" , the default is "start auto" .
if not eeprom: if not eeprom:
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNone(tag, "post-init: Tag discovery loop should be stopped!") asserts.assertNone(tag, "post-init: Tag discovery loop should be stopped!")
self.nfc_command("dev1", "stop") self.nfc_command("dev1", "stop")
time.sleep(1) time.sleep(1)
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNone(tag, "post-stop: Tag discovery loop should be stopped!") asserts.assertNone(tag, "post-stop: Tag discovery loop should be stopped!")
self.nfc_command("dev1", "start") self.nfc_command("dev1", "start")
time.sleep(1) time.sleep(1)
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
asserts.assertNotNone(tag, "Could not connect to any tag") asserts.assertNotNone(tag, "Could not connect to any tag")
self.clf.nfc.mute() self.clf.nfc.mute()
self.nfc_command("dev1", "stop") self.nfc_command("dev1", "stop")
time.sleep(10) time.sleep(10)
self.clf.nfc.connect() tag = self.clf.nfc.connect()
tag = self.clf.clf_response()
# test blocked by issue raised IOTPAN313 NFC Controller discovery can stop but cannot restart - PN512 # test blocked by issue raised IOTPAN313 NFC Controller discovery can stop but cannot restart - PN512
asserts.assertNone(tag, "post-restart: Tag discovery loop should be stopped!") asserts.assertNone(tag, "post-restart: Tag discovery loop should be stopped!")

View File

@ -22,7 +22,7 @@ import icetea_lib.tools.asserts as asserts
import nfc_messages import nfc_messages
from nfc_messages import NfcErrors from nfc_messages import NfcErrors
from nfc_cli_helper import CliHelper from nfc_cli_helper import CliHelper
from nfc_cli_helper import STRESS_BUFFLEN from nfc_cli_helper import LARGE_BUFFLEN
import nfc import nfc
""" """
@ -111,6 +111,7 @@ check - Create a SmartPoster but does not read it back
def test_nfc_setsmartposter(self): def test_nfc_setsmartposter(self):
self.nfc_command("dev1", "initnfc") self.nfc_command("dev1", "initnfc")
self.nfc_command("dev1", "setsmartposter https://www.mbed.com") self.nfc_command("dev1", "setsmartposter https://www.mbed.com")
@test_case(CreamSconeSelfTests) @test_case(CreamSconeSelfTests)
@ -120,7 +121,6 @@ def test_nfc_erase(self):
eeprom = response.parsed['iseeprom'] eeprom = response.parsed['iseeprom']
if eeprom: if eeprom:
self.logger.info("Target includes NFCEEPROM: %s" % eeprom) self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
self.nfc_command("dev1", "erase", timeout=30) self.nfc_command("dev1", "erase", timeout=30)
response = self.nfc_command("dev1", "readmessage") response = self.nfc_command("dev1", "readmessage")
asserts.assertEqual(response.parsed['nfcmessage'] is None, True) asserts.assertEqual(response.parsed['nfcmessage'] is None, True)
@ -132,7 +132,7 @@ can be read back.
@test_case(CreamSconeSelfTests) @test_case(CreamSconeSelfTests)
def test_nfc_write_long(self): def test_nfc_write_long(self):
messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written messageRep = 'thequickbrownfoxjumpedoverthelazydog' # repeating message written
textLength = STRESS_BUFFLEN / 2 # 2K < x < 4K textLength = LARGE_BUFFLEN # large values take longer
# calculate actual message to compare to using the library # calculate actual message to compare to using the library
message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(messageRep, textLength)) message = nfc_messages.make_textrecord( nfc_messages.repeat_string_to_length(messageRep, textLength))
expected_message = str(message) expected_message = str(message)
@ -142,7 +142,6 @@ def test_nfc_write_long(self):
eeprom = response.parsed['iseeprom'] eeprom = response.parsed['iseeprom']
if eeprom: if eeprom:
self.logger.info("Target includes NFCEEPROM: %s" % eeprom) self.logger.info("Target includes NFCEEPROM: %s" % eeprom)
self.nfc_command("dev1", "erase") self.nfc_command("dev1", "erase")
self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep)) self.nfc_command("dev1", "writelong %d %s" % (textLength,messageRep))
response = self.nfc_command("dev1", "readmessage") response = self.nfc_command("dev1", "readmessage")
@ -252,5 +251,5 @@ def test_nfc_get_max_ndef(self):
self.nfc_command("dev1", "initnfc") self.nfc_command("dev1", "initnfc")
max = self.nfc_command("dev1", "getmaxndef").parsed['maxndef'] max = self.nfc_command("dev1", "getmaxndef").parsed['maxndef']
self.logger.info("Target NDEF max buffer size %d" % max) self.logger.info("Target NDEF max buffer size %d" % max)
self.logger.info("Teststress size %d" % STRESS_BUFFLEN) self.logger.info("Teststress size %d" % LARGE_BUFFLEN)