Skip to content

Commit 95a8026

Browse files
committed
cstest: compare the PPC branch details once and without requiring operands
1 parent d82c726 commit 95a8026

2 files changed

Lines changed: 53 additions & 30 deletions

File tree

suite/cstest/src/test_detail_ppc.c

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -123,19 +123,19 @@ bool test_expected_ppc(csh *handle, const cs_ppc *actual,
123123
compare_enum_ret(actual->format, expected->format, false);
124124
compare_tbool_ret(actual->update_cr0, expected->update_cr0, false);
125125

126-
if (expected->operands_count == 0) {
127-
return true;
126+
if (expected->operands_count != 0) {
127+
compare_uint8_ret(actual->op_count, expected->operands_count,
128+
false);
128129
}
129-
compare_uint8_ret(actual->op_count, expected->operands_count, false);
130-
for (size_t i = 0; i < actual->op_count; ++i) {
130+
for (size_t i = 0; i < expected->operands_count; ++i) {
131131
const cs_ppc_op *op = &actual->operands[i];
132132
TestDetailPPCOp *eop = expected->operands[i];
133133
compare_enum_ret(op->type, eop->type, false);
134134
compare_enum_ret(op->access, eop->access, false);
135135
switch (op->type) {
136136
default:
137137
fprintf(stderr,
138-
"arm op type %" PRId32 " not handled.\n",
138+
"ppc op type %" PRId32 " not handled.\n",
139139
op->type);
140140
return false;
141141
case PPC_OP_REG:
@@ -152,33 +152,31 @@ bool test_expected_ppc(csh *handle, const cs_ppc *actual,
152152
compare_int_ret(op->mem.disp, eop->mem_disp, false);
153153
break;
154154
}
155+
}
155156

156-
if (expected->bc) {
157-
if (expected->bc->bi_set) {
158-
compare_uint8_ret(actual->bc.bi,
159-
expected->bc->bi, false);
160-
} else {
161-
assert(expected->bc->bi == 0);
162-
}
163-
if (expected->bc->bo_set) {
164-
compare_uint8_ret(actual->bc.bo,
165-
expected->bc->bo, false);
166-
} else {
167-
assert(expected->bc->bo == 0);
168-
}
169-
compare_enum_ret(actual->bc.bh, expected->bc->bh,
170-
false);
171-
compare_reg_ret(*handle, actual->bc.crX,
172-
expected->bc->crX, false);
173-
compare_enum_ret(actual->bc.crX_bit,
174-
expected->bc->crX_bit, false);
175-
compare_enum_ret(actual->bc.hint, expected->bc->hint,
176-
false);
177-
compare_enum_ret(actual->bc.pred_cr,
178-
expected->bc->pred_cr, false);
179-
compare_enum_ret(actual->bc.pred_ctr,
180-
expected->bc->pred_ctr, false);
157+
if (expected->bc) {
158+
if (expected->bc->bi_set) {
159+
compare_uint8_ret(actual->bc.bi, expected->bc->bi,
160+
false);
161+
} else {
162+
assert(expected->bc->bi == 0);
163+
}
164+
if (expected->bc->bo_set) {
165+
compare_uint8_ret(actual->bc.bo, expected->bc->bo,
166+
false);
167+
} else {
168+
assert(expected->bc->bo == 0);
181169
}
170+
compare_enum_ret(actual->bc.bh, expected->bc->bh, false);
171+
compare_reg_ret(*handle, actual->bc.crX, expected->bc->crX,
172+
false);
173+
compare_enum_ret(actual->bc.crX_bit, expected->bc->crX_bit,
174+
false);
175+
compare_enum_ret(actual->bc.hint, expected->bc->hint, false);
176+
compare_enum_ret(actual->bc.pred_cr, expected->bc->pred_cr,
177+
false);
178+
compare_enum_ret(actual->bc.pred_ctr, expected->bc->pred_ctr,
179+
false);
182180
}
183181

184182
return true;

tests/details/ppc.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1819,3 +1819,28 @@ test_cases:
18191819
bo_set: true
18201820
pred_cr: PPC_PRED_INVALID
18211821
pred_ctr: PPC_PRED_NZ
1822+
-
1823+
input:
1824+
# Deliberately no operands: — the branch block must be compared even
1825+
# when the case asserts nothing about the operand list.
1826+
bytes: [ 0x4c, 0x16, 0x00, 0x20 ]
1827+
arch: "ppc"
1828+
options: [ CS_MODE_BIG_ENDIAN, CS_OPT_DETAIL ]
1829+
address: 0x1000
1830+
expected:
1831+
insns:
1832+
-
1833+
asm_text: "bdnzflr 4*cr5+eq"
1834+
details:
1835+
ppc:
1836+
bc:
1837+
bi: 22
1838+
bi_set: true
1839+
bo: 0
1840+
bo_set: true
1841+
bh: PPC_BH_SUBROUTINE_RET
1842+
crX: cr5
1843+
crX_bit: PPC_BI_Z
1844+
pred_cr: PPC_PRED_NE
1845+
pred_ctr: PPC_PRED_NZ
1846+
hint: PPC_BR_NOT_GIVEN

0 commit comments

Comments
 (0)