Skip to content

Commit

Permalink
add REM2A, REC2A
Browse files Browse the repository at this point in the history
  • Loading branch information
FanWuUCL committed Oct 22, 2015
1 parent e7a6d80 commit 5c378c9
Show file tree
Hide file tree
Showing 8 changed files with 318 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ SOURCES=src/*.c

OBJECTS= App.o ASTNode.o ASTNodeUtil.o ASTPrinter.o ASTUnit.o Milu3.o MultiProcessing.o Mutant.o MutantExecutor.o MutantSet.o MutationId.o MutationOperator.o MutationTemplate.o Mutator.o Options.o Project.o TestInput.o Utility.o $(OPOBJ) $(MUTOBJ)

MUTOBJ=add_arithmetic_assignment_replacement.o add_arithmetic_replacement.o and_logical_negation.o and_logical_replacement.o austin_add_arithmetic_replacement.o austin_and_logical_negation.o austin_and_logical_replacement.o austin_divide_arithmetic_replacement.o austin_equal_relational_replacement.o austin_greater_equal_relational_replacement.o austin_greater_relationa_replacement.o austin_integer_constant_replacement.o austin_less_equal_relational_replacement.o austin_less_relational_replacement.o austin_modulus_arithmetic_replacement.o austin_multiply_arithmetic_replacement.o austin_not_equal_relational_replacement.o austin_or_logical_negation.o austin_or_logical_replacement.o austin_subtract_arithmetic_replacement.o bitwise_and_logical_assignment_replacement.o bitwise_and_logical_replacement.o bitwise_or_logical_assignment_replacement.o bitwise_or_logical_replacement.o divide_arithmetic_assignment_replacement.o divide_arithmetic_replacement.o equal_relational_replacement.o greater_equal_relational_replacement.o greater_relational_replacement.o if_expression_negation_replacement.o integer_constant_replacement.o less_equal_relational_replacement.o less_relational_replacement.o modulus_arithmetic_assignment_replacement.o modulus_arithmetic_replacement.o multiply_arithmetic_assignment_replacement.o multiply_arithmetic_replacement.o not_equal_relational_replacement.o or_logical_negation.o or_logical_replacement.o postfix_decrement_replacement.o postfix_increment_replacement.o prefix_decrement_replacement.o prefix_increment_replacement.o subtract_arithmetic_assignment_replacement.o subtract_arithmetic_replacement.o break_continue_replacement.o float_constant_replacement.o statement_deletion.o integer_var_abs_insertion.o float_var_abs_insertion.o integer_var_uoi_insertion.o while_expression_negation_replacement.o remove_null_assignment.o replace_calloc_with_null.o replace_malloc_with_null.o replace_malloc_size_with_zero.o replace_calloc_size_with_zero.o replace_sizeof_argument_with_pointer_equivalent.o replace_sizeof_argument_with_nonpointer_equivalent.o replace_calloc_with_malloc.o remove_free_statement.o
MUTOBJ=add_arithmetic_assignment_replacement.o add_arithmetic_replacement.o and_logical_negation.o and_logical_replacement.o austin_add_arithmetic_replacement.o austin_and_logical_negation.o austin_and_logical_replacement.o austin_divide_arithmetic_replacement.o austin_equal_relational_replacement.o austin_greater_equal_relational_replacement.o austin_greater_relationa_replacement.o austin_integer_constant_replacement.o austin_less_equal_relational_replacement.o austin_less_relational_replacement.o austin_modulus_arithmetic_replacement.o austin_multiply_arithmetic_replacement.o austin_not_equal_relational_replacement.o austin_or_logical_negation.o austin_or_logical_replacement.o austin_subtract_arithmetic_replacement.o bitwise_and_logical_assignment_replacement.o bitwise_and_logical_replacement.o bitwise_or_logical_assignment_replacement.o bitwise_or_logical_replacement.o divide_arithmetic_assignment_replacement.o divide_arithmetic_replacement.o equal_relational_replacement.o greater_equal_relational_replacement.o greater_relational_replacement.o if_expression_negation_replacement.o integer_constant_replacement.o less_equal_relational_replacement.o less_relational_replacement.o modulus_arithmetic_assignment_replacement.o modulus_arithmetic_replacement.o multiply_arithmetic_assignment_replacement.o multiply_arithmetic_replacement.o not_equal_relational_replacement.o or_logical_negation.o or_logical_replacement.o postfix_decrement_replacement.o postfix_increment_replacement.o prefix_decrement_replacement.o prefix_increment_replacement.o subtract_arithmetic_assignment_replacement.o subtract_arithmetic_replacement.o break_continue_replacement.o float_constant_replacement.o statement_deletion.o integer_var_abs_insertion.o float_var_abs_insertion.o integer_var_uoi_insertion.o while_expression_negation_replacement.o remove_null_assignment.o replace_calloc_with_null.o replace_malloc_with_null.o replace_malloc_size_with_zero.o replace_calloc_size_with_zero.o replace_sizeof_argument_with_pointer_equivalent.o replace_sizeof_argument_with_nonpointer_equivalent.o replace_calloc_with_malloc.o remove_free_statement.o replace_malloc_with_alloca.o replace_calloc_with_alloca.o

OPOBJ=Austin_CRCR.o Austin_OAAN.o Austin_OLLN.o Austin_OLNG.o Austin_ORRN.o CRCR.o ABS.o OAAA.o OAAN.o OBBA.o OBBN.o OCNG.o OIDO.o OLLN.o OLNG.o ORRN.o SBRC.o SSDL.o UOI.o RMNA.o REDAWN.o REDAWZ.o RESOTPE.o REMSOTP.o REC2M.o RMFS.o
OPOBJ=Austin_CRCR.o Austin_OAAN.o Austin_OLLN.o Austin_OLNG.o Austin_ORRN.o CRCR.o ABS.o OAAA.o OAAN.o OBBA.o OBBN.o OCNG.o OIDO.o OLLN.o OLNG.o ORRN.o SBRC.o SSDL.o UOI.o RMNA.o REDAWN.o REDAWZ.o RESOTPE.o REMSOTP.o REC2M.o RMFS.o REM2A.o REC2A.o

all : init milu clean

Expand Down
15 changes: 13 additions & 2 deletions src/include/ASTNodeUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -633,9 +633,9 @@ gboolean is_ASTNode_free_statement(const ASTNode * node);
/**
* \brief Create a substitution malloc tree for calloc
*
* \left the first argument of original calloc
* \left the first argument of original calloc call
*
* \right the second argument of original calloc
* \right the second argument of original calloc call
*
* \return new malloc subtree.
**/
Expand All @@ -661,6 +661,17 @@ gboolean ASTNode_set_null_statement(ASTNode* node);
**/
gboolean ASTNode_restore_free_statement(ASTNode* node, ASTNode* children);

/**
* \brief Create a substitution alloca tree for calloc
*
* \left the first argument of original calloc call
*
* \right the second argument of original calloc call
*
* \return new alloca subtree.
**/
ASTNode * ASTNode_new_alloca_substitution_for_calloc(ASTNode* left, ASTNode* right);

#endif /* ASTNODEUTIL_H_ */

/**@}*/
23 changes: 23 additions & 0 deletions src/mutation/ASTNodeUtil.c
Original file line number Diff line number Diff line change
Expand Up @@ -613,3 +613,26 @@ gboolean ASTNode_restore_free_statement(ASTNode* node, ASTNode* children)
children->next_sibling->parent=node;
return TRUE;
}

ASTNode * ASTNode_new_alloca_substitution_for_calloc(ASTNode* left, ASTNode* right)
{
left->parent=NULL;
left->prev_sibling=NULL;
left->next_sibling=NULL;
right->parent=NULL;
right->prev_sibling=NULL;
right->next_sibling=NULL;
ASTNode * unexposed_node = ASTNode_new(NodeKind_UnexposedExpr, "alloca", NULL);
ASTNode * call_node = ASTNode_new_with_parent(unexposed_node, NodeKind_CallExpr, "alloca", NULL);
ASTNode * decl_ref_node = ASTNode_new_with_parent(call_node, NodeKind_DeclRefExpr, "alloca", NULL);

ASTNode * unexposed_node_left = ASTNode_new(NodeKind_UnexposedExpr, "", NULL);
ASTNode * unexposed_node_right = ASTNode_new(NodeKind_UnexposedExpr, "", NULL);
ASTNode * paren_node_left = ASTNode_new_with_parent(unexposed_node_left, NodeKind_ParenExpr, "", NULL);
ASTNode * paren_node_right = ASTNode_new_with_parent(unexposed_node_right, NodeKind_ParenExpr, "", NULL);
ASTNode_append_child(paren_node_left, left);
ASTNode_append_child(paren_node_right, right);
ASTNode * multiply_node=ASTNode_new_bop_node("*", unexposed_node_left, unexposed_node_right);
ASTNode_append_child(call_node, multiply_node);
return unexposed_node;
}
8 changes: 8 additions & 0 deletions src/mutation/MutationOperator.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,14 @@ GPtrArray * mutation_operators_load(const gchar * mut_op_path)
{
g_ptr_array_add(operators, (gpointer)get_RMFS_operator());
}
else if(g_strcmp0("REM2A", op_name) == 0)
{
g_ptr_array_add(operators, (gpointer)get_REM2A_operator());
}
else if(g_strcmp0("REC2A", op_name) == 0)
{
g_ptr_array_add(operators, (gpointer)get_REC2A_operator());
}
else
{
g_assert_not_reached();
Expand Down
105 changes: 105 additions & 0 deletions src/mutators/memory_c/REC2A/replace_calloc_with_alloca.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
Milu v3.0 - A Higher Order Mutation Testing Tool
Copyright (c) 2015, Fan Wu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University College London nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "Mutator.h"
#include "ASTNodeUtil.h"

static gboolean mutator_milu_replace_calloc_with_alloca_node_checking(ASTNode *);
static gboolean mutator_milu_replace_calloc_with_alloca_clean(ASTNode * node, gint type);
static gboolean mutator_milu_replace_calloc_with_alloca_mutate(ASTNode * node, gint type);

static ASTNode * tmpNode;
static gint tmpIndex;

Mutator * mutator_milu_replace_calloc_with_alloca()
{
Mutator * mut = mutator_new("(Memory)Replace calloc() with alloca()", "");
mut->node_checking = & mutator_milu_replace_calloc_with_alloca_node_checking;
mut->mutate = & mutator_milu_replace_calloc_with_alloca_mutate;
mut->clean = & mutator_milu_replace_calloc_with_alloca_clean;
mut->size = 1;
return mut;
}


static gboolean mutator_milu_replace_calloc_with_alloca_node_checking(ASTNode * node)
{
return has_ASTNode_calloc_call(node);
}

static gboolean mutator_milu_replace_calloc_with_alloca_mutate(ASTNode * node, gint type)
{
ASTNode *left, *right, *replace;
ASTNode * child=node->children;
gint index=1;
while(child){
if(is_ASTNode_calloc_call(child)) break;
child=child->next_sibling;
index++;
}
if(!child){
return FALSE;
}
switch(type)
{
case 1:
left=child->children->children->next_sibling;
right=left->next_sibling;
replace=ASTNode_new_alloca_substitution_for_calloc(left->children, right->children);
left->children=NULL;
right->children=NULL;
tmpIndex=index;
tmpNode=child;
replace_subtree_with(child, replace);
return TRUE;

default:
break;
}

return FALSE;
}

static gboolean mutator_milu_replace_calloc_with_alloca_clean(ASTNode * node, gint type)
{
node=ASTNode_get_nth_child(node, tmpIndex);
ASTNode *left=tmpNode->children->children->next_sibling;
ASTNode *right=left->next_sibling;
ASTNode *left_expr=node->children->children->next_sibling;
ASTNode *right_expr=left_expr->children->next_sibling->children->children;
left_expr=left_expr->children->children->children;
left->children=left_expr;
right->children=right_expr;
left_expr->parent=left;
right_expr->parent=right;
replace_subtree_with(node, tmpNode);
tmpNode=NULL;
tmpIndex=0;
return TRUE;
}
77 changes: 77 additions & 0 deletions src/mutators/memory_c/REM2A/replace_malloc_with_alloca.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Milu v3.0 - A Higher Order Mutation Testing Tool
Copyright (c) 2015, Fan Wu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University College London nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "Mutator.h"
#include "ASTNodeUtil.h"

static gboolean mutator_milu_replace_malloc_with_alloca_node_checking(ASTNode *);
static gboolean mutator_milu_replace_malloc_with_alloca_clean(ASTNode * node, gint type);
static gboolean mutator_milu_replace_malloc_with_alloca_mutate(ASTNode * node, gint type);


Mutator * mutator_milu_replace_malloc_with_alloca()
{
Mutator * mut = mutator_new("(Memory)Replace malloc() with alloca()", "");
mut->node_checking = & mutator_milu_replace_malloc_with_alloca_node_checking;
mut->mutate = & mutator_milu_replace_malloc_with_alloca_mutate;
mut->clean = & mutator_milu_replace_malloc_with_alloca_clean;
mut->size = 1;
return mut;
}


static gboolean mutator_milu_replace_malloc_with_alloca_node_checking(ASTNode * node)
{
return is_ASTNode_malloc_call(node);
}

static gboolean mutator_milu_replace_malloc_with_alloca_mutate(ASTNode * node, gint type)
{
switch(type)
{
case 1:
ASTNode_set_text(node, "alloca");
ASTNode_set_text(node->children, "alloca");
ASTNode_set_text(node->children->children, "alloca");
return TRUE;

default:
break;
}

return FALSE;
}

static gboolean mutator_milu_replace_malloc_with_alloca_clean(ASTNode * node, gint type)
{
ASTNode_set_text(node, "malloc");
ASTNode_set_text(node->children, "malloc");
ASTNode_set_text(node->children->children, "malloc");
return TRUE;
}
45 changes: 45 additions & 0 deletions src/operators/REC2A.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Milu v3.0 - A Higher Order Mutation Testing Tool
Copyright (c) 2015, Fan Wu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University College London nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "MutationOperator.h"


Operator * get_REC2A_operator()
{
const gchar * name = "REC2A";
const gchar * info = "Replace calloc() with alloca()";

Operator * op = mutation_operator_new(name, info);

g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_calloc_with_alloca());

return op;
}


45 changes: 45 additions & 0 deletions src/operators/REM2A.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
Milu v3.0 - A Higher Order Mutation Testing Tool
Copyright (c) 2015, Fan Wu
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
* Neither the name of the University College London nor the
names of its contributors may be used to endorse or promote products
derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "MutationOperator.h"


Operator * get_REM2A_operator()
{
const gchar * name = "REM2A";
const gchar * info = "Replace malloc() with alloca()";

Operator * op = mutation_operator_new(name, info);

g_ptr_array_add(op->mutators, (gpointer)mutator_milu_replace_malloc_with_alloca());

return op;
}


0 comments on commit 5c378c9

Please sign in to comment.