Commit 4af21b89 authored by Sergio Costas's avatar Sergio Costas

Added extra tests to ensure that FOR loops behave as expected

parent 3702584a
......@@ -117,7 +117,7 @@ class Test(unittest.TestCase):
self._raise_test("unitest/test2.c", crust.crust.VarNotFoundException, [(crust.crust.MSG_CRITICAL, "Unknown variable '{:s}' at line {:d}", "var", 4)])
def test003Overwrite(self):
self._generic_test("unitest/test3.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param3", 5, 4) ])
self._generic_test("unitest/test3.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "param3", 7, 6) ])
def test004UseUninitialized(self):
self._generic_test("unitest/test4.c", [ (crust.crust.MSG_ERROR, "Argument {:d} when calling function '{:s}' at line {:d} isn't initialized", 1, "function", 5) ])
......@@ -799,10 +799,10 @@ class Test(unittest.TestCase):
def test192GlobalVariableFreedAtExit(self):
self._generic_test("unitest/test192.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to a block freed at line {:d}.", 16, "var1", 14) ])
self._generic_test("unitest/test192.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to a block freed at line {:d}.", 14, "var1", 12) ])
def test193GlobalVariableFreedAtExit(self):
lib = self._generic_test("unitest/test193.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to the same block than global variable '{:s}'.", 20, "var1", "var2") ])
lib = self._generic_test("unitest/test193.c", [ (crust.crust.MSG_ERROR, "At exit point in line {:d}, global variable '{:s}' points to the same block than global variable '{:s}'.", 18, "var1", "var2") ])
self._check_block_id_is_the_same(lib, "arg1", "var1")
self._check_block_id_is_the_same(lib, "arg1", "var2")
......@@ -810,6 +810,14 @@ class Test(unittest.TestCase):
lib = self._all_fine_test("unitest/test194.c")
self._check_var_status(lib, "global_var", crust.crust.VALUE_NOT_NULL_OR_NULL)
def test195ForLoopWithoutFreeing(self):
self._generic_test("unitest/test195.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "var", 12, 9), (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "var", 12, 12) ])
def test196ForLoopWithoutFreeing2(self):
self._generic_test("unitest/test196.c", [ (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "var", 14, 11), (crust.crust.MSG_ERROR, "Assignment to '{:s}' at line {:d}, which was already assigned at line {:d}", "var", 14, 14) ])
def test197ForLoopFreeing(self):
self._all_fine_test("unitest/test197.c")
if __name__ == '__main__':
try:
......
typedef __crust_t__ unsigned char *crust_t;
typedef void (*test)(void);
crust_t var1;
void function(crust_t);
......
typedef __crust_t__ unsigned char *crust_t;
typedef void (*test)(void);
crust_t var1;
void function(crust_t);
......
typedef __crust_t__ unsigned char *crust_t;
typedef void (*test)(void);
crust_t var1;
crust_t var2;
......
typedef __crust_t__ unsigned char *crust_t;
typedef void (*test)(void);
struct {
char var1;
int var2;
......
#define NULL ((void *)0)
__crust_t__ struct crust_t2 {
char var1;
int var2;
__crust_t__ struct crust_t2 *next;
};
void main(__crust_t__ struct crust_t2 *var) {
__crust_t__ struct crust_t2 *tmp;
for(; var != NULL; var = tmp) {
tmp = var->next;
}
}
#define NULL ((void *)0)
struct crust_ts {
char var1;
int var2;
struct crust_ts *next;
};
typedef __crust_t__ struct crust_ts* crust_t;
void function(crust_t var) {
crust_t tmp;
for(; var != NULL; var = tmp) {
tmp = var->next;
}
}
#define NULL ((void *)0)
struct crust_ts {
char var1;
int var2;
struct crust_ts *next;
};
typedef __crust_t__ struct crust_ts* crust_t;
void function2(crust_t);
void function(crust_t var) {
crust_t tmp;
for(; var != NULL; var = tmp) {
tmp = var->next;
function2(var);
}
}
typedef __crust_t__ unsigned char *crust_t;
int function(crust_t param1, crust_t param2) {
void function2(crust_t param);
void function(crust_t param1, crust_t param2) {
crust_t param3 = param1;
param3 = param2; // ERROR: param3 is overwriten by another variable without being NULL
__crust_disable__ // added here to ensure only one error per unitest
function2(param3);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment