You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
3.5 KiB

  1. # About Adafruit_Micropython_Blinka
  2. This repository is structured around integration tests rooted at the `test/src`
  3. directory, intended to test the compatibility layer rooted in `src`.
  4. The tests offer a procedural way to assert equivalence between 'native' CircuitPython behaviour and behaviour of the **adafruit_blinka** compatibility layer.
  5. The structure of the testing modules permits test suites to be imported and configured selectively on different implementations, platforms and boards (see `adafruit_blinka.agnostic.py` for definitions of these terms).
  6. Automated introspection of the python runtime combines with interactive prompts
  7. to configure a scenario for testing (e.g. which platform, which board, what is wired to it)
  8. so the same routines can be carried out on Micropython boards, dual boards running either CircuitPython or Micropython, or dedicated CircuitPython boards.
  9. Typically the tests have first run on a native CircuitPython platform, and are then used to
  10. prove equivalence on a Micropython platform running the **adafruit_blinka** compatibility layer.
  11. # Tests so far
  12. Tests of compatible versions of **digitalio**, **board** and **microcontroller** have successfully demonstrated
  13. the same code running on either platform, setting and getting pin values and using pull.
  14. Tests have also proven compatibility of the following unmodified CircuitPython libraries...
  15. * adafruit_bme280
  16. * adafruit_mma8451
  17. * adafruit_gps
  18. ...which proves the fundamentals of bitbangio.I2C, busio.I2C and busio.UART
  19. # Example
  20. To take a minimal example, the following should assert the default behaviour of the DigitalInOut
  21. constructor, checks the behaviour of switch_to_input/output(), configures a pin as a pull-up button, a pull-down button and an LED.
  22. ```python
  23. from testing import test_module_name
  24. test_module_name("testing.universal.digitalio")
  25. ```
  26. Or to take a more involved example of constructing a test suite requiring hardware,
  27. the following should verify I2C communication with a BME280 module.
  28. ```python
  29. import unittest
  30. import testing.universal.i2c
  31. suite = unittest.TestSuite()
  32. suite.addTest(testing.universal.i2c.TestBME280Interactive)
  33. runner = unittest.TestRunner()
  34. runner.run(suite)
  35. ```
  36. To prove this on a newly-flashed Feather Huzzah running Micropython 1.9.3,
  37. it should be possible (on a posix-compliant platform with adafruit_ampy installed)
  38. to `cd test/scripts` then run `./upload_feather_huzzah_micropython_put.sh` to
  39. synchronize relevant files to the filesystem of the huzzah, reset the huzzah then
  40. connect using `screen /dev/ttyUSB0 115200` before running the above commands.
  41. Micropython hosts require a micropython repository alongside
  42. the Adafruit_Micropython_Blinka repository. For circuitpython,
  43. the repository is expected to be called circuitpython_2.2.3.
  44. In each case, the matching version should have been checked out from github
  45. and `make` needs to have been run in the `mpy-cross` folder. This provides a tool
  46. to make bytecode-compiled .mpy versions of all .py files before upload so that
  47. tests can be achieved within the limited memory available on many target platforms.
  48. ## Comments
  49. There are reference routines in `test/scripts` like `upload_feather_huzzah_micropython_put.sh` which execute a selective bytecode-compile to .mpy format and an ampy upload for CircuitPython/Micropython on esp8266, or `upload_pyboard_micropython_cp.sh` which selectively bytecode-compiles and synchronizes files with cp to the CIRCUITPY or PYBFLASH disk mount for stm32 and samd21 platforms.