Skip to content

Commit

Permalink
bugs: test functions have no arguments
Browse files Browse the repository at this point in the history
This test was created for/with input from issue
avast/retdec#155
  • Loading branch information
Peter Kubov committed Aug 1, 2020
1 parent 0bd6623 commit 1082936
Show file tree
Hide file tree
Showing 7 changed files with 109 additions and 0 deletions.
Binary file not shown.
Binary file not shown.
40 changes: 40 additions & 0 deletions bugs/funcs-no-args/for-loops/for.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>
#include <stdlib.h>

int g = 100;

int f1();
int f2();
int f3();

int main() {
g = 100;
f1();
f2();
f3();
return 0;
}

int f1() {
int i;
for (i = 0; i < g; ++i) {
printf("looping");
}
return 0;
}

int f2() {
int i;
for (i = 0; i < rand(); ++i) {
printf("looping %d", i);
}
return 0;
}

int f3() {
int i;
for (i = 0; i < rand(); ++i) {
printf("looping");
}
return 0;
}
22 changes: 22 additions & 0 deletions bugs/funcs-no-args/for-loops/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from regression_tests import *

class Test(Test):
settings = TestSettings(
input=files_in_dir('2020-07-31')
)

def test_check_function_have_no_args(self):
f1 = 'f1' if self.out_c.has_func('f1') else '_f1'
assert self.out_c.has_func(f1)
assert self.out_c.funcs[f1].param_count == 0
assert self.out_c.funcs[f1].return_type.is_int(32)

f2 = 'f2' if self.out_c.has_func('f2') else '_f2'
assert self.out_c.has_func(f2)
assert self.out_c.funcs[f2].param_count == 0
assert self.out_c.funcs[f2].return_type.is_int(32)

f3 = 'f3' if self.out_c.has_func('f3') else '_f3'
assert self.out_c.has_func(f3)
assert self.out_c.funcs[f3].param_count == 0
assert self.out_c.funcs[f3].return_type.is_int(32)
29 changes: 29 additions & 0 deletions bugs/funcs-no-args/more-loops/test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
char bar(void) {
return 'a';
}

int foo(void) {
int x = 5;
return x;
}

int main(int argc, char **argv) {
if(argc < 4) {
int i = foo();
while(i > 0) {
;
i--;
}
} else {
do {
continue;
} while(0);
}

while(1) {
bar();
break;
}

return 0;
}
Binary file added bugs/funcs-no-args/more-loops/test.elf
Binary file not shown.
18 changes: 18 additions & 0 deletions bugs/funcs-no-args/more-loops/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from regression_tests import *

class Test(Test):
settings = TestSettings(
input='test.elf'
)

def test_check_function_have_no_args(self):
assert self.out_c.has_func('foo')
assert self.out_c.funcs['foo'].param_count == 0
# TODO: currently RetDec returns int32_t for every
# unkown type.
# assert self.out_c.funcs['foo'].return_type.is_int(8)

assert self.out_c.has_func('bar')
assert self.out_c.funcs['bar'].param_count == 0
# test.elf binary is 32 bit -> int is 32 bit.
assert self.out_c.funcs['foo'].return_type.is_int(32)

0 comments on commit 1082936

Please sign in to comment.