Skip to content

Commit 8aa53af

Browse files
committed
Add negative test case for cstest_py
1 parent 280582d commit 8aa53af

File tree

7 files changed

+137
-0
lines changed

7 files changed

+137
-0
lines changed

suite/run_tests.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,22 @@
1818
f"cstest_py {root_dir}/tests/features/",
1919
]
2020

21+
expected_to_fail = [
22+
f"cstest_py {root_dir}/tests/negative/",
23+
]
24+
2125
for test in tests:
2226
logger.info(f'Running {test}')
2327
logger.info("#######################")
2428
subprocess.run(test.split(" "), check=True)
2529
logger.info("-----------------------")
30+
31+
for test in expected_to_fail:
32+
logger.info(f'Running {test}')
33+
logger.info("#######################")
34+
try:
35+
subprocess.run(test.split(" "), check=True)
36+
logger.error("Test was expected to fail.")
37+
exit(-1)
38+
except Exception as e:
39+
logger.info("-----------------------")

tests/negative/should_fail_I.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
test_cases:
2+
-
3+
input:
4+
name: "Fail because of too few input bytes."
5+
bytes: [ 0x00 ]
6+
arch: "sparc"
7+
options: [ CS_OPT_DETAIL, CS_MODE_BIG_ENDIAN ]
8+
address: 0x1000
9+
expected:
10+
insns:
11+
-
12+
asm_text: "cmp %g1, %g2"
13+
details:
14+
sparc:
15+
operands:
16+
-
17+
type: SPARC_OP_REG
18+
reg: g1
19+
-
20+
type: SPARC_OP_REG
21+
reg: g2

tests/negative/should_fail_II.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
test_cases:
2+
-
3+
input:
4+
name: "Fails due to mismatching asm text"
5+
bytes: [ 0x80, 0xa0, 0x40, 0x02 ]
6+
arch: "sparc"
7+
options: [ CS_OPT_DETAIL, CS_MODE_BIG_ENDIAN ]
8+
address: 0x1000
9+
expected:
10+
insns:
11+
-
12+
asm_text: "cmp %g1, %g3"
13+
details:
14+
sparc:
15+
operands:
16+
-
17+
type: SPARC_OP_REG
18+
reg: g1
19+
-
20+
type: SPARC_OP_REG
21+
reg: g2
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
test_cases:
2+
-
3+
input:
4+
name: "Fails due to missing detail operand"
5+
bytes: [ 0x80, 0xa0, 0x40, 0x02 ]
6+
arch: "sparc"
7+
options: [ CS_OPT_DETAIL, CS_MODE_BIG_ENDIAN ]
8+
address: 0x1000
9+
expected:
10+
insns:
11+
-
12+
asm_text: "cmp %g1, %g2"
13+
details:
14+
sparc:
15+
operands:
16+
-
17+
type: SPARC_OP_REG
18+
reg: g1

tests/negative/should_fail_IV.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
test_cases:
2+
-
3+
input:
4+
name: "Fails due to non existant architecture name."
5+
bytes: [ 0x00, 0xa0, 0x40, 0x02 ]
6+
arch: "not_existant"
7+
options: [ CS_OPT_DETAIL, CS_MODE_BIG_ENDIAN ]
8+
address: 0x1000
9+
expected:
10+
insns:
11+
-
12+
asm_text: "cmp %g1, %g2"
13+
details:
14+
sparc:
15+
operands:
16+
-
17+
type: SPARC_OP_REG
18+
reg: g1
19+
-
20+
type: SPARC_OP_REG
21+
reg: g2

tests/negative/should_fail_V.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
test_cases:
2+
-
3+
input:
4+
name: "Fails due to not decoded details."
5+
bytes: [ 0x80, 0xa0, 0x40, 0x02 ]
6+
arch: "sparc"
7+
options: [ CS_MODE_BIG_ENDIAN ]
8+
address: 0x1000
9+
expected:
10+
insns:
11+
-
12+
asm_text: "cmp %g1, %g2"
13+
details:
14+
sparc:
15+
operands:
16+
-
17+
type: SPARC_OP_REG
18+
reg: g1
19+
-
20+
type: SPARC_OP_REG
21+
reg: g2

tests/negative/should_fail_VI.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
test_cases:
2+
-
3+
input
4+
name: "Failes due to malformatted file"
5+
bytes: [ 0x00 ]
6+
arch: "sparc"
7+
options: [ CS_OPT_DETAIL, CS_MODE_BIG_ENDIAN ]
8+
address: 0x1000
9+
expected:
10+
insns:
11+
-
12+
asm_text: "cmp %g1, %g2"
13+
details:
14+
sparc:
15+
operands:
16+
-
17+
type: SPARC_OP_REG
18+
reg: g1
19+
-
20+
type: SPARC_OP_REG
21+
reg: g2

0 commit comments

Comments
 (0)