Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions test/firmware.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
"""Test uploading firmware"""

import time
import unittest
from multiprocessing import Process, Queue
from queue import Empty

from gpiozero import DigitalOutputDevice

RESET_GPIO_NUMBER = 4
BOOT0_GPIO_NUMBER = 22


def resethat():
"""Reset the HAT"""
reset = DigitalOutputDevice(RESET_GPIO_NUMBER)
boot0 = DigitalOutputDevice(BOOT0_GPIO_NUMBER)
boot0.off()
reset.off()
time.sleep(0.01)
reset.on()
time.sleep(0.01)
boot0.close()
reset.close()
time.sleep(0.5)


def reboot(exc):
"""Reboot hat and load firmware

:param exc: Queue to pass exceptions
"""
try:
from buildhat import Hat
resethat()
h = Hat(debug=True)
print(h.get())
except Exception as e:
exc.put(e)


class TestFirmware(unittest.TestCase):
"""Test firmware uploading functions"""

def test_upload(self):
"""Test upload firmware

:raises exc.get: Raised if exception in subprocess
"""
for _ in range(500):
exc = Queue()
p = Process(target=reboot, args=(exc,))
p.start()
p.join()
try:
raise exc.get(False)
except Empty:
pass


if __name__ == '__main__':
unittest.main()