From 92d82a736970b6ffc5fae367d0f84608957654a8 Mon Sep 17 00:00:00 2001 From: Luke Kenneth Casson Leighton Date: Fri, 23 Apr 2021 20:27:20 +0100 Subject: [PATCH] add logical test cases --- src/openpower/test/logical/logical_cases.py | 120 ++++++++++++++++++++ 1 file changed, 120 insertions(+) create mode 100644 src/openpower/test/logical/logical_cases.py diff --git a/src/openpower/test/logical/logical_cases.py b/src/openpower/test/logical/logical_cases.py new file mode 100644 index 00000000..33b77cc9 --- /dev/null +++ b/src/openpower/test/logical/logical_cases.py @@ -0,0 +1,120 @@ +import unittest +from openpower.simulator.program import Program +from openpower.endian import bigendian +from openpower.test.common import TestAccumulatorBase +import random + + +class LogicalTestCase(TestAccumulatorBase): + + def case_complement(self): + insns = ["andc", "orc", "nand", "nor"] + for i in range(40): + choice = random.choice(insns) + lst = [f"{choice} 3, 1, 2"] + initial_regs = [0] * 32 + initial_regs[1] = random.randint(0, (1 << 64)-1) + initial_regs[2] = random.randint(0, (1 << 64)-1) + self.add_case(Program(lst, bigendian), initial_regs) + + def case_rand(self): + insns = ["and", "or", "xor", "eqv"] + for i in range(40): + choice = random.choice(insns) + lst = [f"{choice} 3, 1, 2"] + initial_regs = [0] * 32 + initial_regs[1] = random.randint(0, (1 << 64)-1) + initial_regs[2] = random.randint(0, (1 << 64)-1) + self.add_case(Program(lst, bigendian), initial_regs) + + def case_rand_(self): + insns = ["and.", "or.", "xor.", "eqv.", "andc.", + "orc.", "nand.", "nor."] + for XER in [0, 0xe00c0000]: + for i in range(40): + choice = random.choice(insns) + lst = [f"{choice} 3, 1, 2"] + initial_regs = [0] * 32 + initial_regs[1] = random.randint(0, (1 << 64)-1) + initial_regs[2] = random.randint(0, (1 << 64)-1) + self.add_case(Program(lst, bigendian), initial_regs, + initial_sprs = {'XER': XER}) + + def case_rand_imm_so(self): + insns = ["andi.", "andis."] + for i in range(1): + choice = random.choice(insns) + imm = random.randint(0, (1 << 16)-1) + lst = [f"{choice} 3, 1, {imm}"] + print(lst) + initial_regs = [0] * 32 + initial_regs[1] = random.randint(0, (1 << 64)-1) + initial_sprs = {'XER': 0xe00c0000} + + self.add_case(Program(lst, bigendian), initial_regs, + initial_sprs=initial_sprs) + + def case_rand_imm_logical(self): + insns = ["andi.", "andis.", "ori", "oris", "xori", "xoris"] + for i in range(10): + choice = random.choice(insns) + imm = random.randint(0, (1 << 16)-1) + lst = [f"{choice} 3, 1, {imm}"] + print(lst) + initial_regs = [0] * 32 + initial_regs[1] = random.randint(0, (1 << 64)-1) + self.add_case(Program(lst, bigendian), initial_regs) + + def case_cntz(self): + insns = ["cntlzd", "cnttzd", "cntlzw", "cnttzw"] + for i in range(100): + choice = random.choice(insns) + lst = [f"{choice} 3, 1"] + print(lst) + initial_regs = [0] * 32 + initial_regs[1] = random.randint(0, (1 << 64)-1) + self.add_case(Program(lst, bigendian), initial_regs) + + def case_parity(self): + insns = ["prtyw", "prtyd"] + for i in range(10): + choice = random.choice(insns) + lst = [f"{choice} 3, 1"] + print(lst) + initial_regs = [0] * 32 + initial_regs[1] = random.randint(0, (1 << 64)-1) + self.add_case(Program(lst, bigendian), initial_regs) + + def case_popcnt(self): + insns = ["popcntb", "popcntw", "popcntd"] + for i in range(10): + choice = random.choice(insns) + lst = [f"{choice} 3, 1"] + print(lst) + initial_regs = [0] * 32 + initial_regs[1] = random.randint(0, (1 << 64)-1) + self.add_case(Program(lst, bigendian), initial_regs) + + def case_popcnt_edge(self): + insns = ["popcntb", "popcntw", "popcntd"] + for choice in insns: + lst = [f"{choice} 3, 1"] + initial_regs = [0] * 32 + initial_regs[1] = -1 + self.add_case(Program(lst, bigendian), initial_regs) + + def case_cmpb(self): + lst = ["cmpb 3, 1, 2"] + initial_regs = [0] * 32 + initial_regs[1] = 0xdeadbeefcafec0de + initial_regs[2] = 0xd0adb0000afec1de + self.add_case(Program(lst, bigendian), initial_regs) + + def case_bpermd(self): + lst = ["bpermd 3, 1, 2"] + for i in range(20): + initial_regs = [0] * 32 + initial_regs[1] = 1 << random.randint(0, 63) + initial_regs[2] = 0xdeadbeefcafec0de + self.add_case(Program(lst, bigendian), initial_regs) + -- 2.30.2