Skip to content

Commit

Permalink
Add compile tests for examples, prepare for unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
luni64 committed Dec 19, 2022
1 parent fefb39e commit 9253e91
Show file tree
Hide file tree
Showing 4 changed files with 124 additions and 17 deletions.
17 changes: 0 additions & 17 deletions test/main.cpp

This file was deleted.

34 changes: 34 additions & 0 deletions test/onBoard_tests_TBD/cfgRunUnitTests.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html

[env]
lib_deps = thomasfredericks/Bounce2@^2.71

[extra]
tytoolspath = C:/toolchain/TyTools

[teensyBase]
platform = teensy
framework = arduino

[env:Teensy 41]
extends = teensyBase
board = teensy41
upload_command = ${extra.tytoolsPath}/tycmd upload --board @usb-1-3-3 $SOURCE
test_port = COM15
upload_port = COM15

[env:Teensy LC]
extends = teensyBase
board = teensylc
upload_command = ${extra.tytoolsPath}/tycmd upload --board @usb-1-3-2 $SOURCE
test_port = COM41
upload_port = COM41

87 changes: 87 additions & 0 deletions test/runCompileTests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@

libraryName = "TeensyTimerTool"

boards = [
"teensylc",
"teensy31",
"teensy41",
]

examples = [
{"folder":"examples/01_basic/HelloPeriodic"},
{"folder":"examples/01_basic/HelloOneShot"},
{"folder":"examples/01_basic/ArrayOfTimers"},
{"folder":"examples/01_basic/MoreTimers", "exclude":["teensy31","teensylc"]},
{"folder":"examples/01_basic/RTC_Timer", "exclude":["teensy31","teensylc"]},
{"folder":"examples/01_basic/UsingChronoDurations1"},
{"folder":"examples/01_basic/UsingChronoDurations2"},
{"folder":"examples/02_Advanced/CallbackWithParams"},
{"folder":"examples/02_Advanced/UsingLambdas"},
{"folder":"examples/02_Advanced/CapturingLambdas"},
{"folder":"examples/03_Applications/DoubleExposure", "exclude":["teensylc","teensy41"]},
{"folder":"examples/99_Misc/PinInformation", "exclude":["teensy31"]},
]

dependencies=[
]

#*************************************************************************************************
import subprocess
import tempfile
import os
import distutils.dir_util

print("\n================================ SETTING UP TEST PROJECT ================================")

targetPrjFolder = os.path.join(tempfile.gettempdir(), libraryName)
targetLibFolder = os.path.join(targetPrjFolder,"lib",libraryName)
targetSrcFolder = os.path.join(targetPrjFolder,"src")

if os.path.isdir(targetPrjFolder): # start with a fresh setup
distutils.dir_util.remove_tree(targetPrjFolder)

distutils.dir_util.mkpath(targetPrjFolder)

initParams = ["pio","project", "init", "-s"]
initParams.append("--project-dir=" + targetPrjFolder)
for board in boards:
initParams.append("--board=" + board)

opt = "--project-option=lib_deps="
for dep in dependencies:
opt += (dep + '\n')
initParams.append(opt)

result = subprocess.run(initParams)

print("\n================================== COMPILING EXAMPLES ===================================")

distutils.dir_util.copy_tree("./src",targetLibFolder+"/src")

totalExamples = str(len(examples)*len(boards))
currentExample = 1

for board in boards:
print('{:57}'.format("SKETCH") + '{:25}'.format("BOARD")+ " STATUS" )
for example in examples:
exFolder = example['folder']
counter = (f"{currentExample}/{totalExamples}").center(8)
currentExample += 1
print("- " + '{:55}'.format(exFolder) + '{:25}'.format(board) + counter, end="\r", flush=True)

if os.path.isdir(targetSrcFolder):
distutils.dir_util.remove_tree(targetSrcFolder)
distutils.dir_util.copy_tree (exFolder,targetSrcFolder)

print("- " + '{:55}'.format(exFolder) + '{:25}'.format(board), end='', flush=True)

if not ("exclude" in example and (board in example['exclude'])):
result = subprocess.run(["pio", "run", "-e"+board, "--project-dir=" + targetPrjFolder],capture_output=True)

if result.returncode == 0:
print("\033[92m[PASSED]\033[0m"+" ")
else:
print("\033[91m[FAILED]\033[0m"+" ")
else:
print("\033[93m[ N/A ]\033[0m"+" ")
print(' ')
3 changes: 3 additions & 0 deletions test/runUnitTests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import subprocess

result = subprocess.run(["pio", "test", "-ctest/cfgRunUnitTests.ini"])

0 comments on commit 9253e91

Please sign in to comment.