Commit 22c1ed69 authored by Sergio Costas's avatar Sergio Costas

Added tests for untested errors

parent 09d057b5
......@@ -536,9 +536,9 @@ class crust(object):
# we are assigning the result of a function call
ret_value = orig_var["function_params"][0]
if ret_value["crust"] and (dest_type == self.TYPE_NO_CRUST):
self._add_error(v["varlist"], self.MSG_ERROR, "Assigning the crust-type result value of function '{:s}' at line {:d} to the non-crust variable {:s}", orig_var["name"], statement.line, statement.name)
self._add_error(v["varlist"], self.MSG_ERROR, "Assigning the crust-type result value of function '{:s}' at line {:d} to the non-crust variable '{:s}'", orig_var["name"], statement.line, statement.name)
if (not ret_value["crust"]) and (dest_type == self.TYPE_CRUST):
self._add_error(v["varlist"], self.MSG_ERROR, "Assigning the non-crust-type result value of function '{:s}' at line {:d} to the crust variable {:s}", orig_var["name"], statement.line, statement.name)
self._add_error(v["varlist"], self.MSG_ERROR, "Assigning the non-crust-type result value of function '{:s}' at line {:d} to the crust variable '{:s}'", orig_var["name"], statement.line, statement.name)
if dest_data["alias"]:
self._remove_alias(v["varlist"], dest_data)
self._set_var_value(v["varlist"], dest_var.name, v["status"], statement.line, False, False, True)
......@@ -1112,7 +1112,7 @@ class crust(object):
init_line = data["init_line"]
if (not data["alias"]) and ((data["status"] == self.STATUS_NOT_NULL) or (data["status"] == self.STATUS_NOT_NULL_OR_NULL)) and (not data["borrowed"]):
if init_line is None:
self._add_error(var_container, self.MSG_ERROR, "Memory block '{:s}' still is in use at exit point at line {:d}", variable, line)
self._add_error(var_container, self.MSG_ERROR, "Memory block '{:s}' is still in use at exit point at line {:d}", variable, line)
else:
self._add_error(var_container, self.MSG_ERROR, "Memory block '{:s}', initialized at line {:d}, is still in use at exit point at line {:d}", variable, init_line, line)
......
#!/usr/bin/env python3
import sys
messages = {}
with open("crust/crust.py", "r") as origin:
n = 0
for line in origin.readlines():
n += 1
line = line.strip()
if line.startswith("self._add_error"):
status = 0 # find the open parenteses
msg = ""
for c in line:
if status == 0:
if c == '(':
status = 1 # first parameter
continue
if status == 1:
if c == ',':
status = 2 # second parameter
continue
if status == 2:
if c == ',':
status = 3 # third parameter
continue
if status == 3:
if c == '"':
status = 4 # start of the third parameter
continue
if status == 4:
if c == '"': # end of the third parameter
break
msg += c
messages[msg] = n
with open("error_list.txt", "r") as testlist:
for line in testlist.readlines():
line = line.strip()
if line in messages:
messages[line] = True
for msg in messages:
if messages[msg] == True:
continue
print("{:d}: {:s}".format(messages[msg],msg))
......@@ -31,6 +31,9 @@ class Test(unittest.TestCase):
self.assertIsNone(var["aliases"])
def _test_msg(self, lib, error_element, params):
with open("error_list.txt", "a") as errorlist:
errorlist.write(error_element[1])
errorlist.write("\n")
self.assertEqual(len(error_element), len(params))
for index in range(len(error_element)):
self.assertEqual(error_element[index], params[index])
......@@ -451,6 +454,21 @@ class Test(unittest.TestCase):
def test115VariableNumberOfArguments(self):
self._generic_test("unitest/test115.c", [ (crust.crust.MSG_CRITICAL, "Passed a __crust_t__ variable as argument {:d} when calling function '{:s}' at line {:d}, but __crust_t__ variables are not allowed for optional arguments in functions with variable number of arguments", 3, "function", 11) ])
def test116NonCrustRetValToCrust(self):
self._generic_test("unitest/test116.c", [ (crust.crust.MSG_ERROR, "Assigning the non-crust-type result value of function '{:s}' at line {:d} to the crust variable '{:s}'", "function", 5, "retval") ])
def test117CrustRetValToNonCrust(self):
self._generic_test("unitest/test117.c", [ (crust.crust.MSG_ERROR, "Assigning the crust-type result value of function '{:s}' at line {:d} to the non-crust variable '{:s}'", "function", 5, "retval") ])
def test118CallingPointerWithPosibleNull(self):
self._generic_test("unitest/test118.c", [ (crust.crust.MSG_WARNING, "Using function pointer '{:s}' at line {:d} with a possible NULL value", "test1", 11) ])
def test119CallingPointerWithPosibleNull(self):
self._generic_test("unitest/test119.c", [ (crust.crust.MSG_WARNING, "Using function pointer '{:s}' at line {:d} with a possible NULL value", "test1", 9) ])
if __name__ == '__main__':
try:
os.remove("error_list.txt")
except:
pass
unittest.main()
typedef __crust_t__ unsigned char *crust_t;
int function() {
crust_t retval = function(); // Error: assigning non-crust return value to a crust variable
__crust_disable__
}
typedef __crust_t__ unsigned char *crust_t;
crust_t function() {
int retval = function(); // Error: assigning crust return value to a non-crust variable
__crust_disable__
}
typedef __crust_t__ unsigned char *crust_t;
typedef char* (*prueba)(crust_t);
#define NULL ((void *)0)
prueba function();
void main(crust_t param1) {
prueba test1 = function();
(*test1)(param1); // WARNING: calling a function pointer with a possible NULL value
}
typedef __crust_t__ unsigned char *crust_t;
#define NULL ((void *)0)
char* (*function)(crust_t) ();
void main(crust_t param1) {
char* (*test1)(crust_t) = function();
(*test1)(param1); // WARNING: calling a function pointer with a possible NULL value
}
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