Skip to content

Commit cb8f1a0

Browse files
committed
Add unittest to march-to-cpu-opt
#1167 has found some bug, and I realized the testing of march-to-cpu-opt is...not well, so spend some time to improve that a little bit, it's not complete testing, but at least it's a start :P
1 parent a4f97aa commit cb8f1a0

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

scripts/march-to-cpu-opt

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import argparse
44
import sys
5+
import unittest
56

67
EXT_OPTS = {
78
"zba": "zba=true",
@@ -129,8 +130,22 @@ def conver_arch_to_qemu_cpu_opt(march):
129130
cpu_opt.append(EXT_OPTS[ext])
130131
return ",".join(cpu_opt)
131132

133+
134+
class TestArchStringParse(unittest.TestCase):
135+
def _test(self, arch, expected_arch_list, expected_vlen=0):
136+
exts = parse_march(arch)
137+
vlen = get_vlen(exts)
138+
self.assertEqual(expected_vlen, vlen)
139+
self.assertEqual(set(expected_arch_list), set(exts.keys()))
140+
141+
def test_rv64gc(self):
142+
self._test("rv64gc", ['i', 'm', 'a', 'f', 'd', 'c'])
143+
self._test("rv32imc_zve32x", ['i', 'm', 'c', 'zve32x'], expected_vlen=32)
144+
self._test("rv32imc_zve32x_zvl128b", ['i', 'm', 'c', 'zve32x', 'zvl128b'], expected_vlen=128)
145+
146+
132147
def selftest():
133-
print(parse_march("rv64gc"))
148+
unittest.main(argv=sys.argv[1:])
134149

135150
def main(argv):
136151
opt = parse_opt(argv)

0 commit comments

Comments
 (0)