smoke.py 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. from machine import Pin
  2. from machine import RTC
  3. import time
  4. import os
  5. """
  6. Execute it like this:
  7. python3 run-tests --target wipy --device 192.168.1.1 ../cc3200/tools/smoke.py
  8. """
  9. pin_map = [23, 24, 11, 12, 13, 14, 15, 16, 17, 22, 28, 10, 9, 8, 7, 6, 30, 31, 3, 0, 4, 5]
  10. test_bytes = os.urandom(1024)
  11. def test_pin_read (pull):
  12. # enable the pull resistor on all pins, then read the value
  13. for p in pin_map:
  14. pin = Pin('GP' + str(p), mode=Pin.IN, pull=pull)
  15. # read the pin value
  16. print(pin())
  17. def test_pin_shorts (pull):
  18. if pull == Pin.PULL_UP:
  19. pull_inverted = Pin.PULL_DOWN
  20. else:
  21. pull_inverted = Pin.PULL_UP
  22. # enable all pulls of the specified type
  23. for p in pin_map:
  24. pin = Pin('GP' + str(p), mode=Pin.IN, pull=pull_inverted)
  25. # then change the pull one pin at a time and read its value
  26. i = 0
  27. while i < len(pin_map):
  28. pin = Pin('GP' + str(pin_map[i]), mode=Pin.IN, pull=pull)
  29. Pin('GP' + str(pin_map[i - 1]), mode=Pin.IN, pull=pull_inverted)
  30. i += 1
  31. # read the pin value
  32. print(pin())
  33. test_pin_read(Pin.PULL_UP)
  34. test_pin_read(Pin.PULL_DOWN)
  35. test_pin_shorts(Pin.PULL_UP)
  36. test_pin_shorts(Pin.PULL_DOWN)
  37. # create a test directory
  38. os.mkdir('/flash/test')
  39. os.chdir('/flash/test')
  40. print(os.getcwd())
  41. # create a new file
  42. f = open('test.txt', 'w')
  43. n_w = f.write(test_bytes)
  44. print(n_w == len(test_bytes))
  45. f.close()
  46. f = open('test.txt', 'r')
  47. r = bytes(f.read(), 'ascii')
  48. # check that we can write and read it correctly
  49. print(r == test_bytes)
  50. f.close()
  51. os.remove('test.txt')
  52. os.chdir('..')
  53. os.rmdir('test')
  54. ls = os.listdir()
  55. print('test' not in ls)
  56. print(ls)
  57. # test the real time clock
  58. rtc = RTC()
  59. while rtc.now()[6] > 800:
  60. pass
  61. time1 = rtc.now()
  62. time.sleep_ms(1000)
  63. time2 = rtc.now()
  64. print(time2[5] - time1[5] == 1)
  65. print(time2[6] - time1[6] < 5000) # microseconds