Skip to content

Conversation

MrKevinWeiss
Copy link
Contributor

Contribution description

This is all the components needed to run automated i2c tests. It is not great but so far it catches quite a few issues.

Issues/PRs references

#6577

@MrKevinWeiss MrKevinWeiss added Area: tests Area: tests and testing framework Type: new feature The issue requests / The PR implemements a new feature for RIOT labels Jun 25, 2018
@MrKevinWeiss MrKevinWeiss self-assigned this Jun 25, 2018
@MrKevinWeiss MrKevinWeiss requested a review from smlng June 25, 2018 11:46
@tcschmidt
Copy link
Member

ping @smlng

@smlng smlng added the TF: I2C Marks issues and PRs related to the work of the I²C rework task force label Jun 28, 2018
if (argc < 5) {
INVALID_ARGS;
printf("Usage:\n%s ADDR REG FLAG BYTE0 [BYTE1 ...]\n", argv[0]);
dev = _check_param(argc, argv, 5, 5 + BUFSIZE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't this _check_param(argc, argv, 6, (5 + BUFSIZE), because the 6 param contains the first byte, ie. the minimum. At least the help text suggests that the first byte is not optional, or not?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah no it should be _check_param(argc, argv, 5, (5 + BUFSIZE -1), bc the last param is already the first byte hence buffer must be one less, right?

if (argc < 4) {
INVALID_ARGS;
printf("Usage:\n%s: ADDR FLAG BYTE0 [BYTE1 [BYTE_n [...]]]\n", argv[0]);
dev = _check_param(argc, argv, 4, 4 + BUFSIZE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here (see below) should be _check_param(argc, argv, 4, (4 + BUFSIZE -1,)

import serial.tools.list_ports


class IfParams:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as discussed, use dictionary instead

self.connect(port, baud)

def get_port(self):
if (self.__dev.isOpen()):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here (and below) .isOpen() is deprecated according to documentation, use .is_open instead

self.connect(port)
ret = fxn().data
try:
logging.debug("ID rx: %s" % ret)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the new python way for string formatting would look like this:

 logging.debug("ID rx: {}".format(ret))

simply replace every %s or %d and such by {},
that way you don't need to care about variable types (which is not very pythonic anyway)


def write_bytes(self, dev=__dev, addr=__addr, data=__data, flag=None):
str = ''
for val in data:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there is a short hand for that:

str = ' '.join(str(x) for x in data)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

which you could also place directly into the commands below

if (isinstance(val1, str) and isinstance(val2, str)):
if (val1.lower() == val2.lower()):
res = "PASS"
elif (isinstance(val1, list)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you assume val2 is a list, too?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup but why check, if it isn't it will just get caught in the exception. Also this is a throwaway test, only as an example.

return [res, val1, val2]


class TestParam:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might also wanna use dictionary here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup but I don't want to spend more time on this.

def write_test():
cmd_log = list()
t = Test('write test', 'Tests the write functionality for default i2c bus \
(0) with the bpt', cmd_log)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then the output includes the indents I think...


def print_full_result(test):
print('===================================================================\
=============')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor, but this looks a bit ugly - can't we live we no line break or less ==== to fit 80 chars?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again throw away so it doesn't matter.

@smlng
Copy link
Member

smlng commented Jun 29, 2018

@MrKevinWeiss my comment on the python stuff are more informational, hence non blocking. But please have a look at the C stuff specifically the numbers for the argv checker - might be a possible buffer overflow?

@MrKevinWeiss
Copy link
Contributor Author

I disagree with the Travis errors, the training white-spaces are a feature of the .md (so that it can have a newline) and the duplicated if else are not touched by me (as well as serve an actual purpose if certain flags are set).

@@ -0,0 +1,15 @@
How To Run
==========
Connect the DUT I2C0 to the BPT. Information for BPT setup can be found [here](https://github.com/MrKevinWeiss/Testing)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DUT and BPT acronyms should be described first here.

@aabadie
Copy link
Contributor

aabadie commented Jul 2, 2018

the training white-spaces are a feature of the .md

Indeed, but I think (personal preference) that it's sometime better to add an extra newline in this case. If you strongly disagree, you can try to patch the trailing white spaces checker script to avoid this particular case in .md files.

Copy link
Contributor

@aabadie aabadie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would make the python scripts more readable with some comments or doctrings added. Class names could be made more explicit (What is DDIf ?).

Long lines in READMEs could be split as well (to fit in 80 characters line length).

Prefixing constants with double underscore in Python doesn't seem very common to me, (__BPT_ADDR, etc). Same for class constant attributes, do we real want to have name mangling ?
See PEP8 for reference.

In the tests/README.md, there's an 'How to run' section that redirect to the BPT project, but none of them explains precisely how (what) to run.
As a user/tester, the information I'm looking for is: how to wire my board to the BPT (well explained by the BPT project, what to run (what command and from where exactly). For the latter, the BPT project should point to the corresponding RIOT test folder.

@cladmi
Copy link
Contributor

cladmi commented Jul 5, 2018

As we did some python reviews IRL yesterday and found that the API would still need some adapting, I will add the WIP label, this way you can rebase/squash if you want to until it stabilize.

@cladmi cladmi added the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Jul 5, 2018
@MrKevinWeiss
Copy link
Contributor Author

Thanks, I will separate out the connection soon...

@MrKevinWeiss MrKevinWeiss removed the State: WIP State: The PR is still work-in-progress and its code is not in its final presentable form yet label Jul 9, 2018
@MrKevinWeiss
Copy link
Contributor Author

@smlng Ready for review then I will squash and rebase.

	Changed shell to reflect the api very closely.
	This allows full access to each function for unit testing.
@MrKevinWeiss MrKevinWeiss force-pushed the pr/tests/i2c_periph/autotester branch from 9e9eb57 to bbed7c9 Compare July 10, 2018 09:03
	Add automated script to test devices against a known testers.
	This will make it easier to run tests instead of manual testing.
	This is something that works for now but will be better integrated later.
@MrKevinWeiss MrKevinWeiss force-pushed the pr/tests/i2c_periph/autotester branch from bbed7c9 to 3b6d0af Compare July 10, 2018 09:08
@smlng
Copy link
Member

smlng commented Jul 10, 2018

@dylad if you agree, we should get this merged swiftly. Besides adapting the test to the new API it also adds an automated test script which is very helpful.

@dylad
Copy link
Member

dylad commented Jul 10, 2018

@smlng If this PR is mature enough feels free to ACK/merge

@MrKevinWeiss
Copy link
Contributor Author

@smlng what a tempting big green button... Don't you just want to see what happens when you press it?

@smlng smlng merged commit ff372bf into RIOT-OS:new_i2c_if Jul 10, 2018
basilfx pushed a commit to basilfx/RIOT that referenced this pull request Jul 10, 2018
…/autotester

tests/periph_i2c: Add automated tests
@cladmi cladmi added this to the Release 2018.07 milestone Jul 10, 2018
dylad pushed a commit to dylad/RIOT that referenced this pull request Jul 10, 2018
…/autotester

tests/periph_i2c: Add automated tests
@MrKevinWeiss MrKevinWeiss deleted the pr/tests/i2c_periph/autotester branch July 11, 2018 08:03
dylad pushed a commit that referenced this pull request Jul 11, 2018
…ster

tests/periph_i2c: Add automated tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: tests Area: tests and testing framework TF: I2C Marks issues and PRs related to the work of the I²C rework task force Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants