Skip to content

Commit

Permalink
More tests
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Sep 20, 2023
1 parent 4b93b05 commit a7ad2da
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 0 deletions.
31 changes: 31 additions & 0 deletions .github/workflows/tests_other_repo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Build

# Build on every branch push, tag push, and pull request change:
on: [push, pull_request_target]

jobs:
build_repo:
name: Build repo
runs-on: ubuntu-latest

strategy:
fail-fast: false

steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}

- name: Install Python dependencies
run: pip3 install -r requirements.txt

- name: Get extra dependencies
uses: actions/checkout@v4
with:
repository: ${{ secrets.SECRETREPO }}
token: ${{ secrets.SECRETTOKEN }}
path: deps_repo

- name: Run repo tests
run: python3 tests/check_recursive.py deps_repo
75 changes: 75 additions & 0 deletions tests/check_recursive.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3

# SPDX-FileCopyrightText: © 2023 Decompollaborate
# SPDX-License-Identifier: MIT

from __future__ import annotations

import argparse
import ipl3checksum
from pathlib import Path
import struct


print(f"Running ipl3checksum version {ipl3checksum.__version__}")

def checkChecksum(romPath: Path) -> bool:
print(romPath)

print(" Reading...")
romBytes = romPath.read_bytes()

binChecksum = struct.unpack_from(f">II", romBytes, 0x10)

print(f" Expected checksum is: 0x{binChecksum[0]:08X} 0x{binChecksum[1]:08X}")

print(" Detecting CIC...")
cicKind = ipl3checksum.detectCIC(romBytes)
if cicKind is None:
print(f" Not able to detect CIC for {romPath}")
return False

print(" Calculating checksum...")
calculatedChecksum = ipl3checksum.calculateChecksum(romBytes, cicKind)
if calculatedChecksum is None:
print(f" Not able to calculate checksum for {romPath}")
return False

print(f" Calculated checksum is: 0x{calculatedChecksum[0]:08X} 0x{calculatedChecksum[1]:08X}")

print(" Checking checksum...")
if calculatedChecksum[0] != binChecksum[0] or calculatedChecksum[1] != binChecksum[1]:
print(f" Wrong checksum for {romPath}")
return False

print(f" {romPath} OK")

return True

def recursePaths(folder: Path) -> int:
errors = 0

for subpath in sorted(folder.iterdir()):
if subpath.is_dir():
recursePaths(subpath)
continue

if subpath.parts[-2] == "drmario64" and subpath.name == "baserom.cn.z64":
# iQue has a wrong checksum for some reason
continue

ok = checkChecksum(subpath)
if not ok:
errors += 1

print(f"Total errors: {errors}")

return errors


parser = argparse.ArgumentParser()
parser.add_argument("path")

args = parser.parse_args()

exit(recursePaths(Path(args.path)))

0 comments on commit a7ad2da

Please sign in to comment.