Browse Source

ld/tests: add scripts for testing devices.data

More tests, who likes debugging regexps by hand/eye?

Signed-off-by: Karl Palsson <karlp@tweak.au>
pull/1526/head
Karl Palsson 10 months ago
parent
commit
2fe76ce62b
  1. 51
      ld/tests/compare-real-csv.py
  2. 37
      ld/tests/generate-sample-data.py
  3. 108
      ld/tests/stm32g0-samples.csv

51
ld/tests/compare-real-csv.py

@ -0,0 +1,51 @@
#!/usr/bin/env python3
"""
Runs the linker script generator portion against a csv of "correct" device properties to check for regexp madness.
"""
import argparse
import csv
import dataclasses
import genlink
@dataclasses.dataclass
class InputDevice:
name: str
ram: str
flash: str
def domain(opts):
fi = csv.DictReader(filter(lambda row: row[0]!='#', opts.input))
idevs = [InputDevice(name=row['name'], ram=row['ram'], flash=row['flash']) for row in fi]
good_count = 0
for idev in idevs:
print(f"checking: {idev.name}")
x = genlink.get_device_data(opts.devices_data, idev.name, exit_on_fail=False)
if not x:
print(f"Failed to match: {idev.name}")
continue
xram: str = [lol for lol in x["defs"] if lol[0] == "RAM"][0][1]
xrom: str = [lol for lol in x["defs"] if lol[0] == "ROM"][0][1]
assert(xram.lower() == idev.ram.lower())
assert(xrom.lower() == idev.flash.lower())
good_count += 1
print(f"Validated {idev.name} with flash: {idev.flash} and ram: {idev.name}")
assert(good_count == len(idevs))
def get_parser():
parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument("-d", "--devices_data", help="devices.data file to check against", required=True)
parser.add_argument("-i", "--input", help="csv input file to check against", type=argparse.FileType('r'), required=True)
return parser
if __name__ == "__main__":
p = get_parser()
opts = p.parse_args()
domain(opts)

37
ld/tests/generate-sample-data.py

@ -0,0 +1,37 @@
#!/usr/bin/env python3
"""
Generates a sample data csv file that can be used to test regexps for the `compare-real-csv.py` script
"""
def stm32g01():
"""
Typed in by inspection of the chart on https://www.st.com/en/microcontrollers-microprocessors/stm32g0x1.html
on 2024-01-17
"""
for package in ['j', 'f', 'g', 'k', 'c']:
print(f"stm32g031{package}4,16k,8k")
print(f"stm32g031{package}6,32k,8k")
print(f"stm32g041{package}6,32k,8k")
for package in ['f', 'g', 'k', 'c']:
print(f"stm32g051{package}6,32k,18k")
print(f"stm32g061{package}6,32k,18k")
for package in ['f', 'g', 'k', 'c', 'y']:
print(f"stm32g031{package}8,64k,8k")
print(f"stm32g041{package}8,64k,8k")
print(f"stm32g051{package}8,64k,18k")
print(f"stm32g061{package}8,64k,18k")
for package in ['g', 'k', 'c', 'r']:
print(f"stm32g071{package}8,64k,36k")
for package in ['g', 'k', 'c', 'r', 'e']:
print(f"stm32g071{package}b,128k,36k")
print(f"stm32g081{package}b,128k,36k")
for package in ['k', 'c', 'r', 'm', 'v']:
print(f"stm32g0b1{package}b,128k,144k")
print(f"stm32g0b1{package}c,256k,144k")
print(f"stm32g0c1{package}c,256k,144k")
for package in ['k', 'c', 'r', 'm', 'v', 'n']:
print(f"stm32g0b1{package}e,512k,144k")
print(f"stm32g0c1{package}e,512k,144k")
stm32g01()

108
ld/tests/stm32g0-samples.csv

@ -0,0 +1,108 @@
# manually ripped from
# https://www.st.com/en/microcontrollers-microprocessors/stm32g0x0-value-line.html
# on 2024-01-17
name,flash,ram
stm32g030j6,32k,8k
stm32g030f6,32k,8k
stm32g030k6,32k,8k
stm32g030c6,32k,8k
stm32g050f6,32k,18k
stm32g050k6,32k,18k
stm32g050c6,32k,18k
stm32g030k8,64k,8k
stm32g030c8,64k,8k
stm32g050k8,64k,18k
stm32g050c8,64k,18k
stm32g070kb,128k,36k
stm32g070cb,128k,36k
stm32g070rb,128k,36k
stm32g0b0ke,512k,144k
stm32g0b0ce,512k,144k
stm32g0b0re,512k,144k
stm32g0b0ve,512k,144k
# Ripped from https://www.st.com/en/microcontrollers-microprocessors/stm32g0x1.html
# on 2024-01-17
stm32g031j4,16k,8k
stm32g031j6,32k,8k
stm32g041j6,32k,8k
stm32g031f4,16k,8k
stm32g031f6,32k,8k
stm32g041f6,32k,8k
stm32g031g4,16k,8k
stm32g031g6,32k,8k
stm32g041g6,32k,8k
stm32g031k4,16k,8k
stm32g031k6,32k,8k
stm32g041k6,32k,8k
stm32g031c4,16k,8k
stm32g031c6,32k,8k
stm32g041c6,32k,8k
stm32g051f6,32k,18k
stm32g061f6,32k,18k
stm32g051g6,32k,18k
stm32g061g6,32k,18k
stm32g051k6,32k,18k
stm32g061k6,32k,18k
stm32g051c6,32k,18k
stm32g061c6,32k,18k
stm32g031f8,64k,8k
stm32g041f8,64k,8k
stm32g051f8,64k,18k
stm32g061f8,64k,18k
stm32g031g8,64k,8k
stm32g041g8,64k,8k
stm32g051g8,64k,18k
stm32g061g8,64k,18k
stm32g031k8,64k,8k
stm32g041k8,64k,8k
stm32g051k8,64k,18k
stm32g061k8,64k,18k
stm32g031c8,64k,8k
stm32g041c8,64k,8k
stm32g051c8,64k,18k
stm32g061c8,64k,18k
stm32g031y8,64k,8k
stm32g041y8,64k,8k
stm32g051y8,64k,18k
stm32g061y8,64k,18k
stm32g071g8,64k,36k
stm32g071k8,64k,36k
stm32g071c8,64k,36k
stm32g071r8,64k,36k
stm32g071gb,128k,36k
stm32g081gb,128k,36k
stm32g071kb,128k,36k
stm32g081kb,128k,36k
stm32g071cb,128k,36k
stm32g081cb,128k,36k
stm32g071rb,128k,36k
stm32g081rb,128k,36k
stm32g071eb,128k,36k
stm32g081eb,128k,36k
stm32g0b1kb,128k,144k
stm32g0b1kc,256k,144k
stm32g0c1kc,256k,144k
stm32g0b1cb,128k,144k
stm32g0b1cc,256k,144k
stm32g0c1cc,256k,144k
stm32g0b1rb,128k,144k
stm32g0b1rc,256k,144k
stm32g0c1rc,256k,144k
stm32g0b1mb,128k,144k
stm32g0b1mc,256k,144k
stm32g0c1mc,256k,144k
stm32g0b1vb,128k,144k
stm32g0b1vc,256k,144k
stm32g0c1vc,256k,144k
stm32g0b1ke,512k,144k
stm32g0c1ke,512k,144k
stm32g0b1ce,512k,144k
stm32g0c1ce,512k,144k
stm32g0b1re,512k,144k
stm32g0c1re,512k,144k
stm32g0b1me,512k,144k
stm32g0c1me,512k,144k
stm32g0b1ve,512k,144k
stm32g0c1ve,512k,144k
stm32g0b1ne,512k,144k
stm32g0c1ne,512k,144k
Can't render this file because it has a wrong number of fields in line 4.
Loading…
Cancel
Save