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

Ci dwc2 dma #2827

Merged
merged 8 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
e_arr=($e)
build_system="${e_arr[0]}"
toolchain="${e_arr[1]}"
FAMILY=$(echo $MATRIX_JSON | jq -r ".\"$toolchain\".family")
FAMILY=$(echo $MATRIX_JSON | jq -r ".\"$toolchain\"")
echo "FAMILY_${toolchain}=$FAMILY"

# FAMILY_LARGE = FAMILY - RESOURCE_LARGE
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ jobs:
with:
build-system: 'cmake'
toolchain: ${{ matrix.toolchain }}
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].family) }}
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain]) }}
one-per-family: ${{ github.event_name == 'push' }}

# ---------------------------------------
Expand All @@ -89,7 +89,7 @@ jobs:
with:
build-system: 'make'
toolchain: ${{ matrix.toolchain }}
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].family) }}
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain]) }}
one-per-family: true

# ---------------------------------------
Expand Down Expand Up @@ -117,7 +117,7 @@ jobs:
needs: set-matrix
runs-on: [self-hosted, Linux, X64, hifiphile]
env:
BUILD_ARGS: ${{ join(fromJSON(needs.set-matrix.outputs.json)['arm-iar'].family, ' ') }}
BUILD_ARGS: ${{ join(fromJSON(needs.set-matrix.outputs.json)['arm-iar'], ' ') }}
steps:
- name: Clean workspace
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_set_matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def set_matrix_json():
hfp_boards = [f"-b{board['name']}" for board in hfp_data['boards']]
filtered_families = filtered_families + hfp_boards

matrix[toolchain] = {"family": filtered_families}
matrix[toolchain] = filtered_families

print(json.dumps(matrix))

Expand Down
13 changes: 6 additions & 7 deletions .github/workflows/hil_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ jobs:
- name: Generate matrix json
id: set-matrix-json
run: |
MATRIX_ARMGCC=$(jq -c '{ "arm-gcc": { "family": [.boards[] | select(.flasher != "esptool" and .flasher != "openocd_wch") | "-b \(.name)"] } }' "${{ env.HIL_JSON }}")
MATRIX_ESP=$(jq -c '{ "esp-idf": { "family": [.boards[] | select(.flasher == "esptool") | "-b \(.name)"] } }' "${{ env.HIL_JSON }}")
MATRIX_RISCV=$(jq -c '{ "riscv-gcc": { "family": [.boards[] | select(.flasher == "openocd_wch") | "-b \(.name)"] } }' "${{ env.HIL_JSON }}")
MATRIX_JSON=$(jq -nc --argjson arm "$MATRIX_ARMGCC" --argjson esp "$MATRIX_ESP" --argjson riscv "$MATRIX_RISCV" '$arm + $esp + $riscv')
MATRIX_JSON=$(python test/hil/hil_ci_set_matrix.py ${{ env.HIL_JSON }})
echo "matrix=$MATRIX_JSON"
echo "matrix=$MATRIX_JSON" >> $GITHUB_OUTPUT

Expand All @@ -55,13 +52,13 @@ jobs:
with:
build-system: 'cmake'
toolchain: ${{ matrix.toolchain }}
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain].family) }}
build-args: ${{ toJSON(fromJSON(needs.set-matrix.outputs.json)[matrix.toolchain]) }}
one-per-family: true
upload-artifacts: true

# ---------------------------------------
# Hardware in the loop (HIL)
# self-hosted running on an VM. For attached hardware checkout test/hil/tinyusb.json
# self-hosted running on an VM. For attached hardware checkout HIL_JSON
# ---------------------------------------
hil-tinyusb:
if: github.repository_owner == 'hathach'
Expand All @@ -86,4 +83,6 @@ jobs:
merge-multiple: true

- name: Test on actual hardware
run: python3 test/hil/hil_test.py ${{ env.HIL_JSON }}
run: |
ls cmake-build/
python3 test/hil/hil_test.py ${{ env.HIL_JSON }}
43 changes: 43 additions & 0 deletions test/hil/hil_ci_set_matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import argparse
import json
import os


def main():
parser = argparse.ArgumentParser()
parser.add_argument('config_file', help='Configuration JSON file')
args = parser.parse_args()

config_file = args.config_file

# if config file is not found, try to find it in the same directory as this script
if not os.path.exists(config_file):
config_file = os.path.join(os.path.dirname(__file__), config_file)
with open(config_file) as f:
config = json.load(f)

matrix = {
'arm-gcc': [],
'esp-idf': []
}
for board in config['boards']:
name = board['name']
if board['flasher'] == 'esptool':
toolchain = 'esp-idf'
else:
toolchain = 'arm-gcc'

if 'build' in board and 'flags_on' in board['build']:
for f in board['build']['flags_on']:
if f == '':
matrix[toolchain].append(f'-b {name}')
else:
matrix[toolchain].append(f'-b {name} -f1 {f.replace(" ", " -f1 ")}')
else:
matrix[toolchain].append(f'-b {name}')

print(json.dumps(matrix))


if __name__ == '__main__':
main()
64 changes: 36 additions & 28 deletions test/hil/hil_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,37 +424,45 @@ def test_board(board):
test_list.append('device/board_test')

err_count = 0
for test in test_list:
fw_dir = f'cmake-build/cmake-build-{name}/{test}'
if not os.path.exists(fw_dir):
fw_dir = f'examples/cmake-build-{name}/{test}'
fw_name = f'{fw_dir}/{os.path.basename(test)}'
print(f'{name:25} {test:30} ... ', end='')

if not os.path.exists(fw_dir):
print('Skip (no binary)')
continue

# flash firmware. It may fail randomly, retry a few times
for i in range(3):
ret = globals()[f'flash_{flasher}'](board, fw_name)
flags_on_list = [""]
if 'build' in board and 'flags_on' in board['build']:
flags_on_list = board['build']['flags_on']

for f1 in flags_on_list:
f1_str = ""
if f1 != "":
f1_str = '-' + f1.replace(' ', '-')
for test in test_list:
fw_dir = f'cmake-build/cmake-build-{name}{f1_str}/{test}'
if not os.path.exists(fw_dir):
fw_dir = f'examples/cmake-build-{name}{f1_str}/{test}'
fw_name = f'{fw_dir}/{os.path.basename(test)}'
print(f'{name+f1_str:40} {test:30} ... ', end='')

if not os.path.exists(fw_dir):
print('Skip (no binary)')
continue

# flash firmware. It may fail randomly, retry a few times
for i in range(3):
ret = globals()[f'flash_{flasher}'](board, fw_name)
if ret.returncode == 0:
break
else:
print(f'Flashing failed, retry {i+1}')
time.sleep(1)

if ret.returncode == 0:
break
try:
ret = globals()[f'test_{test.replace("/", "_")}'](board)
print('OK')
except Exception as e:
err_count += 1
print(STATUS_FAILED)
print(f' {e}')
else:
print(f'Flashing failed, retry {i+1}')
time.sleep(1)

if ret.returncode == 0:
try:
ret = globals()[f'test_{test.replace("/", "_")}'](board)
print('OK')
except Exception as e:
err_count += 1
print(STATUS_FAILED)
print(f' {e}')
else:
err_count += 1
print(f'Flash {STATUS_FAILED}')
print(f'Flash {STATUS_FAILED}')
return err_count


Expand Down
3 changes: 3 additions & 0 deletions test/hil/tinyusb.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@
{
"name": "espressif_s3_devkitm",
"uid": "84F703C084E4",
"build" : {
"flags_on": ["", "CFG_TUD_DWC2_DMA"]
},
"tests": {
"only": ["device/cdc_msc_freertos", "device/hid_composite_freertos"]
},
Expand Down
39 changes: 29 additions & 10 deletions tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
build_separator = '-' * 95
build_status = [STATUS_OK, STATUS_FAILED, STATUS_SKIPPED]

verbose = False

# -----------------------------
# Helper
Expand All @@ -38,6 +39,9 @@ def run_cmd(cmd):
else:
print(title)
print(r.stdout.decode("utf-8"))
elif verbose:
print(cmd)
print(r.stdout.decode("utf-8"))
return r


Expand Down Expand Up @@ -75,10 +79,17 @@ def print_build_result(board, example, status, duration):
# -----------------------------
# CMake
# -----------------------------
def cmake_board(board, toolchain):
def cmake_board(board, toolchain, build_flags_on):
ret = [0, 0, 0]
start_time = time.monotonic()
build_dir = f"cmake-build/cmake-build-{board}"

build_dir = f'cmake-build/cmake-build-{board}'
build_flags = ''
if len(build_flags_on) > 0:
build_flags = ' '.join(f'-D{flag}=1' for flag in build_flags_on)
build_flags = f'-DCFLAGS_CLI="{build_flags}"'
build_dir += '-' + '-'.join(build_flags_on)

family = find_family(board)
if family == 'espressif':
# for espressif, we have to build example individually
Expand All @@ -87,12 +98,14 @@ def cmake_board(board, toolchain):
if build_utils.skip_example(example, board):
ret[2] += 1
else:
rcmd = run_cmd(f'cmake examples/{example} -B {build_dir}/{example} -G "Ninja" -DBOARD={board}')
rcmd = run_cmd(f'cmake examples/{example} -B {build_dir}/{example} -G "Ninja" '
f'-DBOARD={board} {build_flags}')
if rcmd.returncode == 0:
rcmd = run_cmd(f'cmake --build {build_dir}/{example}')
ret[0 if rcmd.returncode == 0 else 1] += 1
else:
rcmd = run_cmd(f'cmake examples -B {build_dir} -G "Ninja" -DBOARD={board} -DCMAKE_BUILD_TYPE=MinSizeRel -DTOOLCHAIN={toolchain}')
rcmd = run_cmd(f'cmake examples -B {build_dir} -G "Ninja" -DBOARD={board} -DCMAKE_BUILD_TYPE=MinSizeRel '
f'-DTOOLCHAIN={toolchain} {build_flags}')
if rcmd.returncode == 0:
rcmd = run_cmd(f"cmake --build {build_dir}")
ret[0 if rcmd.returncode == 0 else 1] += 1
Expand Down Expand Up @@ -144,12 +157,12 @@ def make_board(board, toolchain):
# -----------------------------
# Build Family
# -----------------------------
def build_boards_list(boards, toolchain, build_system):
def build_boards_list(boards, toolchain, build_system, build_flags_on):
ret = [0, 0, 0]
for b in boards:
r = [0, 0, 0]
if build_system == 'cmake':
r = cmake_board(b, toolchain)
r = cmake_board(b, toolchain, build_flags_on)
elif build_system == 'make':
r = make_board(b, toolchain)
ret[0] += r[0]
Expand All @@ -158,7 +171,7 @@ def build_boards_list(boards, toolchain, build_system):
return ret


def build_family(family, toolchain, build_system, one_per_family, boards):
def build_family(family, toolchain, build_system, build_flags_on, one_per_family, boards):
all_boards = []
for entry in os.scandir(f"hw/bsp/{family}/boards"):
if entry.is_dir() and entry.name != 'pico_sdk':
Expand All @@ -174,27 +187,33 @@ def build_family(family, toolchain, build_system, one_per_family, boards):
return ret
all_boards = [random.choice(all_boards)]

ret = build_boards_list(all_boards, toolchain, build_system)
ret = build_boards_list(all_boards, toolchain, build_system, build_flags_on)
return ret


# -----------------------------
# Main
# -----------------------------
def main():
global verbose

parser = argparse.ArgumentParser()
parser.add_argument('families', nargs='*', default=[], help='Families to build')
parser.add_argument('-b', '--board', action='append', default=[], help='Boards to build')
parser.add_argument('-t', '--toolchain', default='gcc', help='Toolchain to use, default is gcc')
parser.add_argument('-s', '--build-system', default='cmake', help='Build system to use, default is cmake')
parser.add_argument('-f1', '--build-flags-on', action='append', default=[], help='Build flag to pass to build system')
parser.add_argument('-1', '--one-per-family', action='store_true', default=False, help='Build only one random board inside a family')
parser.add_argument('-v', '--verbose', action='store_true', help='Verbose output')
args = parser.parse_args()

families = args.families
boards = args.board
toolchain = args.toolchain
build_system = args.build_system
build_flags_on = args.build_flags_on
one_per_family = args.one_per_family
verbose = args.verbose

if len(families) == 0 and len(boards) == 0:
print("Please specify families or board to build")
Expand All @@ -217,13 +236,13 @@ def main():

# succeeded, failed, skipped
for f in all_families:
r = build_family(f, toolchain, build_system, one_per_family, boards)
r = build_family(f, toolchain, build_system, build_flags_on, one_per_family, boards)
result[0] += r[0]
result[1] += r[1]
result[2] += r[2]

# build boards
r = build_boards_list(boards, toolchain, build_system)
r = build_boards_list(boards, toolchain, build_system, build_flags_on)
result[0] += r[0]
result[1] += r[1]
result[2] += r[2]
Expand Down
1 change: 1 addition & 0 deletions tools/get_deps.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ def main():
parser = argparse.ArgumentParser()
parser.add_argument('families', nargs='*', default=[], help='Families to fetch')
parser.add_argument('-b', '--board', action='append', default=[], help='Boards to fetch')
parser.add_argument('-f1', '--build-flags-on', action='append', default=[], help='Have no effect')
parser.add_argument('--print', action='store_true', help='Print commit hash only')
args = parser.parse_args()

Expand Down
Loading