Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test uploading firmware #153

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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()