tests/periph_i2c: Add automated tests#9409
Conversation
|
ping @smlng |
tests/periph_i2c/main.c
Outdated
| 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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
tests/periph_i2c/main.c
Outdated
| 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, |
There was a problem hiding this comment.
same here (see below) should be _check_param(argc, argv, 4, (4 + BUFSIZE -1,)
tests/periph_i2c/tests/base_if.py
Outdated
| import serial.tools.list_ports | ||
|
|
||
|
|
||
| class IfParams: |
There was a problem hiding this comment.
as discussed, use dictionary instead
tests/periph_i2c/tests/base_if.py
Outdated
| self.connect(port, baud) | ||
|
|
||
| def get_port(self): | ||
| if (self.__dev.isOpen()): |
There was a problem hiding this comment.
here (and below) .isOpen() is deprecated according to documentation, use .is_open instead
tests/periph_i2c/tests/base_if.py
Outdated
| self.connect(port) | ||
| ret = fxn().data | ||
| try: | ||
| logging.debug("ID rx: %s" % ret) |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
there is a short hand for that:
str = ' '.join(str(x) for x in data)
There was a problem hiding this comment.
which you could also place directly into the commands below
tests/periph_i2c/tests/test.py
Outdated
| if (isinstance(val1, str) and isinstance(val2, str)): | ||
| if (val1.lower() == val2.lower()): | ||
| res = "PASS" | ||
| elif (isinstance(val1, list)): |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
might also wanna use dictionary here?
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Then the output includes the indents I think...
tests/periph_i2c/tests/test.py
Outdated
|
|
||
| def print_full_result(test): | ||
| print('===================================================================\ | ||
| =============') |
There was a problem hiding this comment.
minor, but this looks a bit ugly - can't we live we no line break or less ==== to fit 80 chars?
There was a problem hiding this comment.
Again throw away so it doesn't matter.
|
@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? |
|
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). |
tests/periph_i2c/tests/README.md
Outdated
| @@ -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) | |||
There was a problem hiding this comment.
DUT and BPT acronyms should be described first here.
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. |
aabadie
left a comment
There was a problem hiding this comment.
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.
a9c4248 to
d2d55fd
Compare
|
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. |
|
Thanks, I will separate out the connection soon... |
|
@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.
9e9eb57 to
bbed7c9
Compare
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.
bbed7c9 to
3b6d0af
Compare
|
@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. |
|
@smlng If this PR is mature enough feels free to ACK/merge |
|
@smlng what a tempting big green button... Don't you just want to see what happens when you press it? |
…/autotester tests/periph_i2c: Add automated tests
…/autotester tests/periph_i2c: Add automated tests
…ster tests/periph_i2c: Add automated tests
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