Best Python code snippet using Testify_python
propagate.py
Source:propagate.py
1import os2from collections import deque34import src.com.jcparse.base as base5import src.com.jcparse.astree as astree6import src.com.jcparse.cirtree as cirtree7import src.com.jcparse.cirflow as cirflow8import src.com.jcparse.cirinst as cirinst9import src.com.jcparse.cprogram as cprog10import src.com.jcmuta.operator as oprt11import src.com.jcmuta.symbol as sym12import src.com.jcmuta.mutation as mut13import graphviz141516# error propagation model1718class StateErrorEdge:19 """20 It defines the error propagation relationship between two group of state errors in different location21 such that one causes or propagate to another as {source, target, constraints}.22 """2324 def __init__(self, source, target, constraints: mut.StateConstraints):25 self.source = source26 self.target = target27 self.constraints = constraints28 return2930 def get_source(self):31 """32 :return: source of state errors from which the propagation occurs33 """34 self.source: StateErrorNode35 return self.source3637 def get_target(self):38 """39 :return: target of state errors that are caused from the source40 """41 self.target: StateErrorNode42 return self.target4344 def get_constraints(self):45 """46 :return: symbolic constraints that are required for the propagation to occur.47 """48 return self.constraints495051class StateErrorNode:52 """53 It defines a set of correlated state errors in one location that can cause errors in other place of the54 program, and defined as {graph, key; error, all_errors; in_edges, ou_edges;}55 """5657 def __init__(self, graph, state_error: mut.StateError):58 self.graph = graph59 self.error = state_error60 self.necessary_errors = state_error.get_error_set().extend(state_error, True)61 self.all_errors = state_error.get_error_set().extend(state_error, False)62 self.in_edges = list()63 self.ou_edges = list()64 # generate the unique key of the node65 key_list = list()66 for error in self.necessary_errors:67 key_list.append(str(error))68 key_list.sort()69 self.key = str(key_list)70 return7172 def get_graph(self):73 """74 :return: graph where the node is created75 """76 self.graph: StateErrorGraph77 return self.graph7879 def get_key(self):80 """81 :return: the unique key that represents this node by its necessary set of state errors in one location82 """83 return self.key8485 def get_error(self):86 """87 :return: the source error that generates necessary set of errors in this node of location88 """89 return self.error9091 def get_necessary_errors(self):92 """93 :return: necessary or representative set of state errors in this node94 """95 return self.necessary_errors9697 def get_representative_errors(self):98 """99 :return: necessary or representative set of state errors in this node100 """101 return self.necessary_errors102103 def get_all_errors(self):104 """105 :return: all the state errors implied from the necessary set of errors in this node of location106 """107 return self.all_errors108109 def get_cir_location(self):110 """111 :return: the location where the state errors in this node occur112 """113 return self.error.get_cir_location()114115 def get_code_instances(self):116 """117 :return: the instances in flow graph that represent the code location where the error occurs in data flow118 analysis.119 """120 cir_location = self.error.get_cir_location()121 if cir_location is None:122 return list()123 c_program = cir_location.get_tree().program124 c_program: cprog.CProgram125 instance_graph = c_program.get_instance_graph()126 return instance_graph.get_instances().get_instances_of_object(cir_location)127128 def get_instance_nodes(self):129 """130 :return: the instances of execution of statement where the state error occurs in this node, which can be131 used to translate the error to an instance in data flow analysis.132 """133 code_instances = self.get_code_instances()134 instance_nodes = list()135 for code_instance in code_instances:136 code_instance: cirinst.CirInstanceCode137 instance_nodes.append(code_instance.get_instance_node())138 return instance_nodes139140 def get_in_edges(self):141 """142 :return: the propagation edges that cause this node of errors143 """144 return self.in_edges145146 def get_ou_edges(self):147 """148 :return: the propagation edges caused from the errors in this node149 """150 return self.ou_edges151152 def propagate(self, target, constraints: mut.StateConstraints):153 """154 :param target:155 :param constraints:156 :return: the propagation edge from this node to the target or None if the propagation is impossible157 """158 # to avoid self-self implications159 if self == target:160 return None161 # to avoid duplicated propagation edge162 target: StateErrorNode163 for ou_edge in self.ou_edges:164 ou_edge: StateErrorEdge165 if ou_edge.get_target() == target:166 return ou_edge167 # to simplify the state constraints168 sym_condition = constraints.sym_condition()169 if sym_condition.sym_type == sym.CSymbolType.Constant:170 constant = sym.sym_evaluator.__boolean__(sym_condition.content)171 if constant:172 constraints = mut.StateConstraints(True)173 else:174 return None # no possible propagation175 # create the propagation edge from source to target176 edge = StateErrorEdge(self, target, constraints)177 self.ou_edges.append(edge)178 target.in_edges.append(edge)179 return edge180181 def __str__(self):182 return str(self.error)183184 def node_text(self, max_code_length):185 """186 :return:187 """188 buffer = str(self.error.get_error_type()) + "[ "189 for operand in self.error.get_operands():190 if isinstance(operand, cirtree.CirNode):191 operand: cirtree.CirNode192 if operand.ast_source is not None:193 ast_node = operand.get_ast_source()194 code = ast_node.get_code(True)195 if len(code) > max_code_length:196 code = code[0:max_code_length] + "..."197 buffer += str(operand.cir_type) + "[" + str(ast_node.get_beg_line() + 1) + "]::\"" + code + "\"; "198 else:199 code = operand.generate_code(True)200 if len(code) > max_code_length:201 code = code[0:max_code_length] + "..."202 buffer += str(operand.cir_type) + "::\"" + code + "\"; "203 else:204 buffer += str(operand) + "; "205 buffer += "]"206 return buffer207208209class StateErrorGraph:210 """211 It defines a causality graph that describes the error propagation in state errors as212 {infection[mutant, error_set, program]; nodes, faulty_node;}213 """214215 def __init__(self, infection: mut.StateInfection, distance: int):216 self.infection = infection217 self.nodes = dict()218 self.faulty_node = None219 self.invalid_chars = ["\"", '#']220 builder = StateErrorBuilder(self)221 builder.generate_infection_layer()222 builder.generate_reaching_links()223 builder.generate_propagation(distance)224 return225226 def get_infection(self):227 """228 :return: state infection used to generate the state error graph229 """230 return self.infection231232 def get_mutant(self):233 """234 :return: the mutant from which the state error graph describes235 """236 return self.infection.get_mutant()237238 def get_error_set(self):239 """240 :return: the state-errors that is used to generate state error in this graph241 """242 return self.infection.get_mutant().get_mutant_space().state_errors243244 def get_program(self):245 """246 :return: the program from which the state errors in graph can occur247 """248 return self.infection.get_mutant().get_mutant_space().get_program()249250 def get_faulty_node(self):251 """252 :return: node of execute(faulty_statement)253 """254 self.faulty_node: StateErrorNode255 return self.faulty_node256257 def get_keys(self):258 """259 :return: keys of existing nodes in graph260 """261 return self.nodes.keys()262263 def get_nodes(self):264 """265 :return: existing nodes266 """267 return self.nodes.values()268269 def get_node(self, key: str):270 """271 :param key:272 :return: existing node w.r.t. the unique string key273 """274 node = self.nodes[key]275 node: StateErrorNode276 return node277278 def get_node_of(self, state_error: mut.StateError):279 """280 :param state_error:281 :return: an existing node w.r.t. the error or newly created one282 """283 node = StateErrorNode(self, state_error)284 if node.get_key() not in self.nodes:285 self.nodes[node.key] = node286 return self.get_node(node.key)287288 def __normalize_string__(self, text: str):289 buffer = ""290 for k in range(0, len(text)):291 char = text[k]292 if char == "\"":293 char = "\'"294 elif char in self.invalid_chars:295 char = ""296 buffer += char297 return buffer298299 def write_dot_graph(self, file: str, max_code_length: int):300 """301 :param max_code_length:302 :param file:303 :return:304 """305 # 1. initialize the pdf graph306 graph_name = self.get_program().get_file_name() + "_mut_" + str(self.get_mutant().get_id())307 graph_mutant = self.get_mutant()308 graph_comment = "Mutant_%d of %s at Line %d as \"%s\" being mutated." % \309 (graph_mutant.get_id(),310 str(graph_mutant.get_mutation().get_mutation_operator()),311 graph_mutant.get_mutation().get_location().get_beg_line() + 1,312 graph_mutant.get_mutation().get_location().get_code(True))313 digraph = graphviz.Digraph(name=graph_name, comment=self.__normalize_string__(graph_comment), filename=file)314 # 2. create the nodes for each node in state error propagation graph315 for key, node in self.nodes.items():316 node: StateErrorNode317 state_error = node.get_error()318 if state_error.is_system_error():319 color = "red"320 elif state_error.is_statement_error():321 color = "green"322 elif state_error.is_boolean_error():323 color = "yellow"324 elif state_error.is_numeric_error():325 color = "blue"326 elif state_error.is_address_error():327 color = "gray"328 else:329 color = "black"330 digraph.node(name=key, label=self.__normalize_string__(node.node_text(max_code_length)), color=color)331 # 3. create the edges for each propagation pair in the graph332 for source_key, source in self.nodes.items():333 source: StateErrorNode334 for edge in source.get_ou_edges():335 edge: StateErrorEdge336 target = edge.get_target()337 target_key = target.get_key()338 constraints = edge.get_constraints()339 code = str(constraints)340 digraph.edge(source_key, target_key, label=self.__normalize_string__(code))341 # 3. generate the dot file to pdf342 digraph.render(file)343 return344345346class StateErrorBuilder:347 """348 To build up the state error graph349 """350351 def __init__(self, graph: StateErrorGraph):352 self.graph = graph353 return354355 # generate infection layer356 def generate_infection_layer(self):357 """358 :return: generate the infection layer, including faulty-node and its infection edges to359 the node of state errors directly caused by the mutation.360 """361 errors = self.graph.get_error_set()362 faulty_statement = self.graph.get_infection().get_faulty_execution().get_statement()363 source = self.graph.get_node_of(errors.execute(faulty_statement))364 self.graph.faulty_node = source365 for state_error, state_constraints in self.graph.get_infection().error_infections.items():366 target = self.graph.get_node_of(state_error)367 source.propagate(target, state_constraints)368 return369370 # generate coverage layer371372 @staticmethod373 def __constraints_of_flow__(flow):374 """375 :param flow: either execution flow or instance edge376 :return: the constraints to describe execution flow377 """378 constraints = mut.StateConstraints(True)379 if isinstance(flow, cirflow.CirExecutionFlow): # execution-flow380 flow: cirflow.CirExecutionFlow381 if flow.get_flow_type() == cirflow.CirExecutionFlowType.true_flow: # cir_condition as true382 cir_condition = flow.get_source().get_statement().get_child(0)383 sym_condition = sym.sym_parser.parse_by_cir_tree(cir_condition)384 constraints.add_constraint(flow.get_source(), sym_condition)385 elif flow.get_flow_type() == cirflow.CirExecutionFlowType.false_flow: # cir_condition as false386 cir_condition = flow.get_source().get_statement().get_child(0)387 sym_operand = sym.sym_parser.parse_by_cir_tree(cir_condition)388 sym_condition = sym.CSymbolNode(sym.CSymbolType.UnaryExpression,389 base.CType(base.CMetaType.BoolType), base.COperator.logic_not)390 sym_condition.add_child(sym_operand)391 constraints.add_constraint(flow.get_source(), sym_condition)392 else: # all-true for others393 pass394 else: # instance_edge395 flow: cirinst.CirInstanceEdge396 if flow.get_flow_type() == cirflow.CirExecutionFlowType.true_flow: # cir_condition as false397 cir_condition = flow.get_source().get_source_statement().get_child(0)398 sym_condition = sym.sym_parser.parse_by_cir_tree(cir_condition)399 constraints.add_constraint(flow.get_source().get_source_execution(), sym_condition)400 elif flow.get_flow_type() == cirflow.CirExecutionFlowType.false_flow: # cir_condition as false401 cir_condition = flow.get_source().get_source_statement().get_child(0)402 sym_operand = sym.sym_parser.parse_by_cir_tree(cir_condition)403 sym_condition = sym.CSymbolNode(sym.CSymbolType.UnaryExpression,404 base.CType(base.CMetaType.BoolType), base.COperator.logic_not)405 sym_condition.add_child(sym_operand)406 constraints.add_constraint(flow.get_source().get_source_execution(), sym_condition)407 else: # all-true for others408 pass409 return constraints410411 def __generate_reaching_link__(self, beg_node: cirinst.CirInstanceNode, end_node: cirinst.CirInstanceNode, edges):412 """413 :param beg_node:414 :param end_node:415 :param edges:416 :return: generate the execution-link based on given instance path417 """418 if beg_node != end_node and len(edges) > 0:419 errors = self.graph.get_error_set()420 source = self.graph.get_node_of(errors.execute(beg_node.get_source_statement()))421 constraints = mut.StateConstraints(True)422 for edge in edges:423 edge: cirinst.CirInstanceEdge424 target = self.graph.get_node_of(errors.execute(edge.get_source().get_source_statement()))425 source.propagate(target, constraints)426 # update the loop-invariant427 source = target428 constraints = StateErrorBuilder.__constraints_of_flow__(edge)429 target = self.graph.get_node_of(errors.execute(end_node.get_source_statement()))430 source.propagate(target, constraints)431 return432433 def generate_reaching_links(self):434 """435 :return: generate the execution-links for coverage conditions.436 """437 instance_nodes = self.graph.get_faulty_node().get_instance_nodes()438 for instance_node in instance_nodes:439 dominance_path = cprog.CDominancePath(instance_node)440 self.__generate_reaching_link__(dominance_path.get_beg_node(),441 dominance_path.get_mid_node(),442 dominance_path.get_prev_edges())443 return444445 # generate propagation through operands in unary expression446447 @staticmethod448 def __execution_of_cir_location__(cir_location: cirtree.CirNode):449 """450 :param cir_location:451 :return: the execution of the statement where the location is defined452 """453 c_program = cir_location.get_tree().program454 c_program: cprog.CProgram455 cir_statement = cir_location.statement_of()456 if cir_statement is not None:457 c_function = c_program.get_function_call_graph().get_function_of(cir_statement)458 return c_function.get_execution_flow_graph().get_execution_of(cir_statement)459 return None460461 def __generate_on_arith_pos__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):462 """463 :param expression: +{operand}464 :param error: to cause errors in expression from operand465 :return: error_dict: dict[StateError, constraints]466 """467 errors = self.graph.get_error_set()468 if error.error_type == mut.ErrorType.set_bool: # set_numb469 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))470 new_error = errors.set_numb(expression, parameter)471 elif error.error_type == mut.ErrorType.chg_bool: # chg_numb472 new_error = errors.chg_numb(expression)473 elif error.error_type == mut.ErrorType.set_numb:474 parameter = sym.sym_evaluator.__number__(error.get_operand(1))475 new_error = errors.set_numb(expression, parameter)476 elif error.error_type == mut.ErrorType.neg_numb:477 new_error = errors.neg_numb(expression)478 elif error.error_type == mut.ErrorType.rsv_numb:479 new_error = errors.rsv_numb(expression)480 elif error.error_type == mut.ErrorType.dif_numb:481 parameter = sym.sym_evaluator.__number__(error.get_operand(1))482 new_error = errors.dif_numb(expression, parameter)483 elif error.error_type == mut.ErrorType.inc_numb:484 new_error = errors.inc_numb(expression)485 elif error.error_type == mut.ErrorType.dec_numb:486 new_error = errors.dec_numb(expression)487 elif error.error_type == mut.ErrorType.chg_numb:488 new_error = errors.chg_numb(expression)489 elif error.error_type == mut.ErrorType.set_addr:490 parameter = sym.sym_evaluator.__memory__.int_address(error.get_operand(1))491 new_error = errors.set_numb(expression, parameter)492 elif error.error_type == mut.ErrorType.dif_addr:493 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))494 new_error = errors.dif_numb(expression, parameter)495 elif error.error_type == mut.ErrorType.chg_addr:496 new_error = errors.chg_numb(expression)497 elif error.error_type == mut.ErrorType.mut_refer:498 new_error = errors.chg_numb(expression)499 elif error.error_type == mut.ErrorType.mut_expr:500 new_error = errors.chg_numb(expression)501 else: # no more propagation from unavailable errors502 new_error = None503 if new_error is not None:504 error_dict[new_error] = mut.StateConstraints(True)505 return error_dict506507 def __generate_on_arith_neg__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):508 """509 :param expression: -{operand}510 :param error: to cause errors in expression from operand511 :return: error_dict: dict[StateError, constraints]512 """513 errors = self.graph.get_error_set()514 if error.error_type == mut.ErrorType.set_bool:515 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))516 new_error = errors.set_numb(expression, -parameter)517 elif error.error_type == mut.ErrorType.chg_bool:518 new_error = errors.chg_numb(expression)519 elif error.error_type == mut.ErrorType.set_numb:520 parameter = sym.sym_evaluator.__number__(error.get_operand(1))521 new_error = errors.set_numb(expression, -parameter)522 elif error.error_type == mut.ErrorType.neg_numb:523 new_error = errors.neg_numb(expression)524 elif error.error_type == mut.ErrorType.rsv_numb:525 new_error = errors.chg_numb(expression)526 elif error.error_type == mut.ErrorType.dif_numb:527 parameter = sym.sym_evaluator.__number__(error.get_operand(1))528 new_error = errors.dif_numb(expression, -parameter)529 elif error.error_type == mut.ErrorType.inc_numb:530 new_error = errors.dec_numb(expression)531 elif error.error_type == mut.ErrorType.dec_numb:532 new_error = errors.inc_numb(expression)533 elif error.error_type == mut.ErrorType.chg_numb:534 new_error = errors.chg_numb(expression)535 elif error.error_type == mut.ErrorType.dif_addr:536 parameter = sym.sym_evaluator.__number__(error.get_operand(1))537 new_error = errors.set_numb(expression, -parameter)538 elif error.error_type == mut.ErrorType.set_addr:539 parameter = sym.sym_evaluator.__memory__.int_address(error.get_operand(1))540 new_error = errors.set_numb(expression, -parameter)541 elif error.error_type == mut.ErrorType.chg_addr:542 new_error = errors.chg_numb(expression)543 elif error.error_type == mut.ErrorType.mut_refer:544 new_error = errors.chg_numb(expression)545 elif error.error_type == mut.ErrorType.mut_expr:546 new_error = errors.chg_numb(expression)547 else:548 new_error = None549 if new_error is not None:550 error_dict[new_error] = mut.StateConstraints(True)551 return error_dict552553 def __generate_on_bitws_rsv__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):554 """555 :param expression: ~operand556 :param error:557 :param error_dict:558 :return:559 """560 errors = self.graph.get_error_set()561 if error.error_type == mut.ErrorType.set_bool:562 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))563 new_error = errors.set_numb(expression, ~parameter)564 elif error.error_type == mut.ErrorType.chg_bool:565 new_error = errors.chg_numb(expression)566 elif error.error_type == mut.ErrorType.set_numb:567 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))568 new_error = errors.set_numb(expression, ~parameter)569 elif error.error_type == mut.ErrorType.neg_numb:570 new_error = errors.chg_numb(expression)571 elif error.error_type == mut.ErrorType.rsv_numb:572 new_error = errors.rsv_numb(expression)573 elif error.error_type == mut.ErrorType.dif_numb:574 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))575 new_error = errors.dif_numb(expression, ~parameter)576 elif error.error_type == mut.ErrorType.inc_numb:577 new_error = errors.dec_numb(expression)578 elif error.error_type == mut.ErrorType.dec_numb:579 new_error = errors.inc_numb(expression)580 elif error.error_type == mut.ErrorType.chg_numb:581 new_error = errors.chg_numb(expression)582 elif error.error_type == mut.ErrorType.set_numb:583 parameter = sym.sym_evaluator.__memory__.int_address(error.get_operand(1))584 new_error = errors.set_numb(expression, ~parameter)585 elif error.error_type == mut.ErrorType.dif_addr:586 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))587 new_error = errors.dif_numb(expression, ~parameter)588 elif error.error_type == mut.ErrorType.chg_addr:589 new_error = errors.chg_numb(expression)590 elif error.error_type == mut.ErrorType.mut_refer:591 new_error = errors.chg_numb(expression)592 elif error.error_type == mut.ErrorType.mut_expr:593 new_error = errors.chg_numb(expression)594 else:595 new_error = None596 if new_error is not None:597 error_dict[new_error] = mut.StateConstraints(True)598 return error_dict599600 @staticmethod601 def __boolean_constraint__(expression: cirtree.CirNode, parameter: bool):602 """603 :param expression:604 :param parameter:605 :return: constraint that describes the boolean constraint on expression606 """607 constraints = mut.StateConstraints(True)608 sym_operand = sym.sym_parser.parse_by_cir_tree(expression)609 if parameter:610 if not expression.get_data_type().is_bool_type(): # expression != 0611 sym_condition = sym.CSymbolNode(sym.CSymbolType.BinaryExpression, base.CType(base.CMetaType.BoolType),612 base.COperator.not_equals)613 sym_condition.add_child(sym_operand)614 sym_condition.add_child(615 sym.CSymbolNode(sym.CSymbolType.Constant, base.CType(base.CMetaType.IntType), 0))616 else: # expression itself617 sym_condition = sym_operand618 else:619 if not expression.get_data_type().is_bool_type(): # expression == 0620 sym_condition = sym.CSymbolNode(sym.CSymbolType.BinaryExpression, base.CType(base.CMetaType.BoolType),621 base.COperator.equal_with)622 sym_condition.add_child(sym_operand)623 sym_condition.add_child(624 sym.CSymbolNode(sym.CSymbolType.Constant, base.CType(base.CMetaType.IntType), 0))625 else: # !expression626 sym_condition = sym.CSymbolNode(sym.CSymbolType.UnaryExpression, base.CType(base.CMetaType.BoolType),627 base.COperator.logic_not)628 sym_condition.add_child(sym_operand)629 constraints.add_constraint(StateErrorBuilder.__execution_of_cir_location__(expression), sym_condition)630 return constraints631632 def __generate_on_logic_not__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):633 """634 :param expression: !{operand}635 :param error:636 :param error_dict:637 :return:638 """639 errors = self.graph.get_error_set()640 new_error, constraints = None, None641 if error.error_type == mut.ErrorType.set_bool:642 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))643 new_error = errors.set_bool(expression, not parameter)644 constraints = StateErrorBuilder.__boolean_constraint__(expression, parameter)645 elif error.error_type == mut.ErrorType.chg_bool:646 new_error = errors.chg_bool(expression)647 constraints = mut.StateConstraints(True)648 elif error.error_type == mut.ErrorType.set_numb:649 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))650 new_error = errors.set_bool(expression, not parameter)651 constraints = StateErrorBuilder.__boolean_constraint__(expression, parameter)652 elif error.error_type == mut.ErrorType.neg_numb:653 pass # impossible influence654 elif error.error_type == mut.ErrorType.rsv_numb:655 parameter = True656 new_error = errors.set_bool(expression, not parameter)657 constraints = StateErrorBuilder.__boolean_constraint__(expression, parameter)658 elif error.error_type == mut.ErrorType.dif_numb:659 parameter = True660 new_error = errors.set_bool(expression, not parameter)661 constraints = StateErrorBuilder.__boolean_constraint__(expression, parameter)662 elif error.error_type == mut.ErrorType.inc_numb:663 parameter = True664 new_error = errors.set_bool(expression, not parameter)665 constraints = StateErrorBuilder.__boolean_constraint__(expression, parameter)666 elif error.error_type == mut.ErrorType.dec_numb:667 new_error = errors.chg_bool(expression)668 constraints = mut.StateConstraints(True)669 elif error.error_type == mut.ErrorType.chg_numb:670 new_error = errors.chg_bool(expression)671 constraints = mut.StateConstraints(True)672 elif error.error_type == mut.ErrorType.set_addr:673 parameter = sym.sym_evaluator.__memory__.int_address(error.get_operand(1))674 parameter = sym.sym_evaluator.__boolean__(parameter)675 new_error = errors.set_bool(expression, not parameter)676 constraints = StateErrorBuilder.__boolean_constraint__(expression, parameter)677 elif error.error_type == mut.ErrorType.dif_addr:678 parameter = True679 new_error = errors.set_bool(expression, not parameter)680 constraints = StateErrorBuilder.__boolean_constraint__(expression, parameter)681 elif error.error_type == mut.ErrorType.chg_addr:682 new_error = errors.chg_bool(expression)683 constraints = mut.StateConstraints(True)684 else:685 pass686 if new_error is not None:687 error_dict[new_error] = constraints688 return error_dict689690 def __generate_on_address_of__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):691 """692 :param expression: &operand693 :param error:694 :param error_dict:695 :return:696 """697 errors = self.graph.get_error_set()698 new_error, constraints = None, None699 if error.error_type == mut.ErrorType.mut_refer:700 new_error = errors.chg_addr(expression)701 constraints = mut.StateConstraints(True)702 else:703 pass704 if new_error is not None:705 error_dict[new_error] = constraints706 return error_dict707708 def __generate_on_dereference__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):709 """710 :param expression: *operand711 :param error:712 :param error_dict:713 :return:714 """715 errors = self.graph.get_error_set()716 new_error, constraints = None, None717 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.chg_bool:718 new_error = errors.failure()719 constraints = mut.StateConstraints(True)720 elif error.error_type == mut.ErrorType.set_numb:721 int_address = sym.sym_evaluator.__integer__(error.get_operand(1))722 sym_address = sym.sym_evaluator.__memory__.sym_address(int_address)723 if sym_address.startswith("#null") or sym_address.startswith("#invalid"):724 new_error = errors.failure()725 else:726 new_error = errors.mut_refer(expression)727 constraints = mut.StateConstraints(True)728 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb:729 new_error = errors.failure()730 constraints = mut.StateConstraints(True)731 elif error.error_type == mut.ErrorType.dif_numb:732 new_error = errors.mut_refer(expression)733 constraints = mut.StateConstraints(True)734 elif error.error_type == mut.ErrorType.inc_numb or error.error_type == mut.ErrorType.dec_numb:735 new_error = errors.mut_refer(expression)736 constraints = mut.StateConstraints(True)737 elif error.error_type == mut.ErrorType.chg_numb:738 new_error = errors.mut_refer(expression)739 constraints = mut.StateConstraints(True)740 elif error.error_type == mut.ErrorType.set_addr:741 sym_address = str(error.get_operand(1))742 if sym_address.startswith("#null") or sym_address.startswith("#invalid"):743 new_error = errors.failure()744 else:745 new_error = errors.mut_refer(expression)746 constraints = mut.StateConstraints(True)747 elif error.error_type == mut.ErrorType.dif_addr:748 new_error = errors.mut_refer(expression)749 constraints = mut.StateConstraints(True)750 elif error.error_type == mut.ErrorType.chg_addr:751 new_error = errors.mut_refer(expression)752 constraints = mut.StateConstraints(True)753 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:754 new_error = errors.mut_refer(expression)755 constraints = mut.StateConstraints(True)756 else:757 pass758 if new_error is not None:759 error_dict[new_error] = constraints760 return error_dict761762 def __generate_on_type_cast__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):763 """764 :param expression:765 :param error:766 :param error_dict:767 :return:768 """769 cast_type = expression.get_data_type()770 errors = self.graph.get_error_set()771 new_error, constraints = None, mut.StateConstraints(True)772 if error.error_type == mut.ErrorType.set_bool:773 if cast_type.is_bool_type():774 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))775 new_error = errors.set_bool(expression, parameter)776 elif cast_type.is_integer_type():777 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))778 new_error = errors.set_numb(expression, parameter)779 elif cast_type.is_real_type():780 parameter = sym.sym_evaluator.__number__(error.get_operand(1))781 new_error = errors.set_numb(expression, parameter)782 elif cast_type.is_address_type():783 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))784 parameter = sym.sym_evaluator.__memory__.sym_address(parameter)785 new_error = errors.set_addr(expression, parameter)786 else:787 pass788 elif error.error_type == mut.ErrorType.chg_bool:789 if cast_type.is_bool_type():790 new_error = errors.chg_bool(expression)791 elif cast_type.is_integer_type() or cast_type.is_real_type():792 new_error = errors.chg_numb(expression)793 elif cast_type.is_address_type():794 new_error = errors.chg_addr(expression)795 else:796 pass797 elif error.error_type == mut.ErrorType.set_numb:798 if cast_type.is_bool_type():799 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))800 new_error = errors.set_bool(expression, parameter)801 constraints = StateErrorBuilder.__boolean_constraint__(expression, not parameter)802 elif cast_type.is_integer_type():803 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))804 new_error = errors.set_numb(expression, parameter)805 elif cast_type.is_real_type():806 parameter = sym.sym_evaluator.__number__(error.get_operand(1)) + 0.0807 new_error = errors.set_numb(expression, parameter)808 elif cast_type.is_address_type():809 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))810 parameter = sym.sym_evaluator.__memory__.sym_address(parameter)811 new_error = errors.set_addr(expression, parameter)812 else:813 pass814 elif error.error_type == mut.ErrorType.neg_numb:815 if cast_type.is_bool_type():816 pass817 elif cast_type.is_integer_type() or cast_type.is_real_type():818 new_error = errors.neg_numb(expression)819 elif cast_type.is_address_type():820 new_error = errors.set_addr(expression, "#invalid")821 else:822 pass823 elif error.error_type == mut.ErrorType.rsv_numb:824 if cast_type.is_bool_type():825 new_error = errors.set_bool(expression, True)826 constraints = StateErrorBuilder.__boolean_constraint__(expression, False)827 elif cast_type.is_integer_type():828 new_error = errors.rsv_numb(expression)829 elif cast_type.is_real_type():830 new_error = errors.chg_numb(expression)831 elif cast_type.is_address_type():832 new_error = errors.set_addr(expression, "#invalid")833 else:834 pass835 elif error.error_type == mut.ErrorType.dif_numb:836 if cast_type.is_bool_type():837 new_error = errors.set_bool(expression, True)838 constraints = StateErrorBuilder.__boolean_constraint__(expression, False)839 elif cast_type.is_integer_type() or cast_type.is_real_type():840 parameter = sym.sym_evaluator.__number__(error.get_operand(1))841 new_error = errors.dif_numb(expression, parameter)842 elif cast_type.is_address_type():843 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))844 new_error = errors.dif_addr(expression, parameter)845 else:846 pass847 elif error.error_type == mut.ErrorType.inc_numb:848 if cast_type.is_bool_type():849 new_error = errors.set_bool(expression, True)850 constraints = StateErrorBuilder.__boolean_constraint__(expression, False)851 elif cast_type.is_integer_type() or cast_type.is_real_type():852 new_error = errors.inc_numb(expression)853 elif cast_type.is_address_type():854 new_error = errors.chg_addr(expression)855 else:856 pass857 elif error.error_type == mut.ErrorType.dec_numb:858 if cast_type.is_bool_type():859 new_error = errors.chg_bool(expression)860 elif cast_type.is_integer_type() or cast_type.is_real_type():861 new_error = errors.dec_numb(expression)862 elif cast_type.is_address_type():863 new_error = errors.chg_addr(expression)864 else:865 pass866 elif error.error_type == mut.ErrorType.chg_numb:867 if cast_type.is_bool_type():868 new_error = errors.chg_bool(expression)869 elif cast_type.is_integer_type() or cast_type.is_real_type():870 new_error = errors.chg_numb(expression)871 elif cast_type.is_address_type():872 new_error = errors.chg_addr(expression)873 else:874 pass875 elif error.error_type == mut.ErrorType.set_addr:876 int_address = sym.sym_evaluator.__integer__(error.get_operand(1))877 if cast_type.is_bool_type():878 parameter = sym.sym_evaluator.__boolean__(int_address)879 new_error = errors.set_bool(expression, parameter)880 constraints = StateErrorBuilder.__boolean_constraint__(expression, not parameter)881 elif cast_type.is_integer_type() or cast_type.is_real_type():882 parameter = sym.sym_evaluator.__integer__(int_address)883 new_error = errors.set_numb(expression, parameter)884 elif cast_type.is_address_type():885 parameter = sym.sym_evaluator.__memory__.sym_address(int_address)886 new_error = errors.set_addr(expression, parameter)887 else:888 pass889 elif error.error_type == mut.ErrorType.dif_addr:890 if cast_type.is_bool_type():891 new_error = errors.set_bool(expression, True)892 constraints = StateErrorBuilder.__boolean_constraint__(expression, False)893 elif cast_type.is_integer_type() or cast_type.is_real_type():894 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))895 new_error = errors.dif_numb(expression, parameter)896 elif cast_type.is_address_type():897 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))898 new_error = errors.dif_addr(expression, parameter)899 else:900 pass901 elif error.error_type == mut.ErrorType.chg_addr:902 if cast_type.is_bool_type():903 new_error = errors.chg_bool(expression)904 elif cast_type.is_integer_type() or cast_type.is_real_type():905 new_error = errors.chg_numb(expression)906 elif cast_type.is_address_type():907 new_error = errors.chg_addr(expression)908 else:909 pass910 elif error.error_type == mut.ErrorType.mut_expr:911 if cast_type.is_bool_type():912 new_error = errors.chg_bool(expression)913 elif cast_type.is_integer_type() or cast_type.is_real_type():914 new_error = errors.chg_numb(expression)915 elif cast_type.is_address_type():916 new_error = errors.chg_addr(expression)917 else:918 pass919 elif error.error_type == mut.ErrorType.mut_refer:920 if cast_type.is_bool_type():921 new_error = errors.chg_bool(expression)922 elif cast_type.is_integer_type() or cast_type.is_real_type():923 new_error = errors.chg_numb(expression)924 elif cast_type.is_address_type():925 new_error = errors.chg_addr(expression)926 else:927 pass928 else:929 pass930 if new_error is not None:931 error_dict[new_error] = constraints932 return error_dict933934 def __generate_on_wait_expression__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):935 """936 :param expression:937 :param error:938 :param error_dict:939 :return:940 """941 cast_type = expression.get_data_type()942 errors = self.graph.get_error_set()943 new_error, constraints = None, mut.StateConstraints(True)944 if error.error_type == mut.ErrorType.syntax_error or error.error_type == mut.ErrorType.failure:945 pass946 elif cast_type.is_bool_type():947 new_error = errors.chg_bool(expression)948 elif cast_type.is_integer_type() or cast_type.is_real_type():949 new_error = errors.chg_numb(expression)950 elif cast_type.is_address_type():951 new_error = errors.chg_addr(expression)952 else:953 new_error = errors.mut_expr(expression)954 if new_error is not None:955 error_dict[new_error] = constraints956 return error_dict957958 def __generate_on_assignment__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):959 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)960 if error.error_type == mut.ErrorType.set_bool:961 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))962 new_error = errors.set_bool(expression, parameter)963 elif error.error_type == mut.ErrorType.chg_bool:964 new_error = errors.chg_bool(expression)965 elif error.error_type == mut.ErrorType.set_numb:966 parameter = sym.sym_evaluator.__number__(error.get_operand(1))967 new_error = errors.set_numb(expression, parameter)968 elif error.error_type == mut.ErrorType.neg_numb:969 new_error = errors.neg_numb(expression)970 elif error.error_type == mut.ErrorType.rsv_numb:971 new_error = errors.rsv_numb(expression)972 elif error.error_type == mut.ErrorType.dif_numb:973 parameter = sym.sym_evaluator.__number__(error.get_operand(1))974 new_error = errors.dif_numb(expression, parameter)975 elif error.error_type == mut.ErrorType.inc_numb:976 new_error = errors.inc_numb(expression)977 elif error.error_type == mut.ErrorType.dec_numb:978 new_error = errors.dec_numb(expression)979 elif error.error_type == mut.ErrorType.chg_numb:980 new_error = errors.chg_numb(expression)981 elif error.error_type == mut.ErrorType.set_addr:982 parameter = str(error.get_operand(1))983 new_error = errors.set_addr(expression, parameter)984 elif error.error_type == mut.ErrorType.dif_addr:985 parameter = sym.sym_evaluator.__number__(error.get_operand(1))986 new_error = errors.dif_addr(expression, parameter)987 elif error.error_type == mut.ErrorType.chg_addr:988 new_error = errors.chg_addr(expression)989 elif error.error_type == mut.ErrorType.mut_expr:990 new_error = errors.mut_expr(expression)991 elif error.error_type == mut.ErrorType.mut_refer:992 new_error = errors.mut_refer(expression)993 else:994 pass995 if new_error is not None:996 error_dict[new_error] = constraints997 return error_dict998999 # propagation through operand in binary-expression10001001 def __generate_on_arith_add__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):1002 """1003 :param expression:1004 :param error:1005 :return:1006 """1007 # 1. get another operand w.r.t. the expression as given1008 if expression.get_child(0) == error.get_cir_location():1009 other_operand = expression.get_child(1)1010 else:1011 other_operand = expression.get_child(0)1012 other_value = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(other_operand))1013 # 2. generate new error and constraint based source error1014 errors = self.graph.get_error_set()1015 new_error, constraints = None, mut.StateConstraints(True)1016 if error.error_type == mut.ErrorType.set_bool:1017 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1018 if other_value.sym_type == sym.CSymbolType.Constant:1019 parameter = parameter + sym.sym_evaluator.__number__(other_value.content)1020 new_error = errors.set_numb(expression, parameter)1021 else:1022 new_error = errors.chg_numb(expression)1023 elif error.error_type == mut.ErrorType.chg_bool:1024 new_error = errors.chg_numb(expression)1025 elif error.error_type == mut.ErrorType.set_numb:1026 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1027 if other_value.sym_type == sym.CSymbolType.Constant:1028 parameter = parameter + sym.sym_evaluator.__number__(other_value.content)1029 new_error = errors.set_numb(expression, parameter)1030 else:1031 new_error = errors.chg_numb(expression)1032 elif error.error_type == mut.ErrorType.neg_numb:1033 if other_value.sym_type == sym.CSymbolType.Constant and \1034 sym.sym_evaluator.__number__(other_value.content) == 0:1035 new_error = errors.neg_numb(expression)1036 else:1037 new_error = errors.chg_numb(expression)1038 elif error.error_type == mut.ErrorType.rsv_numb:1039 if other_value.sym_type == sym.CSymbolType.Constant and \1040 sym.sym_evaluator.__number__(other_value.content) == 0:1041 new_error = errors.rsv_numb(expression)1042 else:1043 new_error = errors.chg_numb(expression)1044 elif error.error_type == mut.ErrorType.dif_numb:1045 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1046 new_error = errors.dif_numb(expression, parameter)1047 elif error.error_type == mut.ErrorType.inc_numb:1048 new_error = errors.inc_numb(expression)1049 elif error.error_type == mut.ErrorType.dec_numb:1050 new_error = errors.dec_numb(expression)1051 elif error.error_type == mut.ErrorType.chg_numb:1052 new_error = errors.chg_numb(expression)1053 elif error.error_type == mut.ErrorType.set_addr:1054 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1055 if other_value.sym_type == sym.CSymbolType.Constant:1056 parameter = parameter + sym.sym_evaluator.__integer__(other_value.content)1057 parameter = sym.sym_evaluator.__memory__.sym_address(parameter)1058 new_error = errors.set_addr(expression, parameter)1059 else:1060 new_error = errors.chg_addr(expression)1061 elif error.error_type == mut.ErrorType.dif_addr:1062 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1063 new_error = errors.dif_addr(expression, parameter)1064 elif error.error_type == mut.ErrorType.chg_addr:1065 new_error = errors.chg_addr(expression)1066 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:1067 new_error = errors.chg_numb(expression)1068 else:1069 pass1070 # 3. save the results in error_dict1071 if new_error is not None:1072 error_dict[new_error] = constraints1073 return error_dict10741075 def __generate_on_arith_sub__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):1076 """1077 :param expression:1078 :param error:1079 :param error_dict:1080 :return:1081 """1082 # 1. declaration1083 errors = self.graph.get_error_set()1084 new_error, constraints = None, mut.StateConstraints(True)1085 # 2. generate the new-error and constraints w.r.t. the expression1086 if expression.get_child(0) == error.get_cir_location(): # expression := error - operand1087 other_operand = expression.get_child(1)1088 other_value = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(other_operand))1089 if error.error_type == mut.ErrorType.set_bool:1090 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1091 if other_value.sym_type == sym.CSymbolType.Constant:1092 parameter -= sym.sym_evaluator.__number__(other_value.content)1093 new_error = errors.set_numb(expression, parameter)1094 else:1095 if parameter:1096 new_error = errors.dif_numb(expression, 1)1097 else:1098 new_error = errors.dif_numb(expression, -1)1099 elif error.error_type == mut.ErrorType.chg_bool:1100 new_error = errors.chg_numb(expression)1101 elif error.error_type == mut.ErrorType.set_numb:1102 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1103 if other_value.sym_type == sym.CSymbolType.Constant:1104 parameter -= sym.sym_evaluator.__number__(other_value.content)1105 new_error = errors.set_numb(expression, parameter)1106 else:1107 new_error = errors.chg_numb(expression)1108 elif error.error_type == mut.ErrorType.neg_numb:1109 if other_value.sym_type == sym.CSymbolType.Constant and \1110 sym.sym_evaluator.__number__(other_value.content) == 0:1111 new_error = errors.neg_numb(expression)1112 else:1113 new_error = errors.chg_numb(expression)1114 elif error.error_type == mut.ErrorType.rsv_numb:1115 if other_value.sym_type == sym.CSymbolType.Constant and \1116 sym.sym_evaluator.__number__(other_value.content) == 0:1117 new_error = errors.rsv_numb(expression)1118 else:1119 new_error = errors.chg_numb(expression)1120 elif error.error_type == mut.ErrorType.dif_numb:1121 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1122 new_error = errors.dif_numb(expression, parameter)1123 elif error.error_type == mut.ErrorType.inc_numb:1124 new_error = errors.inc_numb(expression)1125 elif error.error_type == mut.ErrorType.dec_numb:1126 new_error = errors.dec_numb(expression)1127 elif error.error_type == mut.ErrorType.chg_numb:1128 new_error = errors.chg_numb(expression)1129 elif error.error_type == mut.ErrorType.set_addr:1130 if other_value.sym_type == sym.CSymbolType.Constant:1131 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1132 parameter -= sym.sym_evaluator.__number__(other_value.content)1133 new_error = errors.set_numb(expression, parameter)1134 else:1135 new_error = errors.chg_numb(expression)1136 elif error.error_type == mut.ErrorType.dif_addr:1137 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1138 new_error = errors.dif_numb(expression, parameter)1139 elif error.error_type == mut.ErrorType.chg_addr:1140 new_error = errors.chg_numb(expression)1141 elif error.error_type == mut.ErrorType.mut_expr:1142 new_error = errors.mut_expr(expression)1143 elif error.error_type == mut.ErrorType.mut_refer:1144 new_error = errors.mut_expr(expression)1145 else:1146 pass1147 else: # expression := operand - error1148 other_operand = expression.get_child(0)1149 other_value = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(other_operand))1150 if error.error_type == mut.ErrorType.set_bool:1151 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1152 if other_value.sym_type == sym.CSymbolType.Constant:1153 parameter = sym.sym_evaluator.__number__(other_value.content) - parameter1154 new_error = errors.set_numb(expression, parameter)1155 else:1156 if parameter:1157 new_error = errors.dif_numb(expression, -1)1158 else:1159 new_error = errors.dif_numb(expression, 1)1160 elif error.error_type == mut.ErrorType.chg_bool:1161 new_error = errors.chg_numb(expression)1162 elif error.error_type == mut.ErrorType.set_numb:1163 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1164 if other_value.sym_type == sym.CSymbolType.Constant:1165 parameter = sym.sym_evaluator.__number__(other_value.content) - parameter1166 new_error = errors.set_numb(expression, parameter)1167 else:1168 new_error = errors.chg_numb(expression)1169 elif error.error_type == mut.ErrorType.neg_numb:1170 if other_value.sym_type == sym.CSymbolType.Constant and \1171 sym.sym_evaluator.__number__(other_value.content) == 0:1172 new_error = errors.neg_numb(expression)1173 else:1174 new_error = errors.chg_numb(expression)1175 elif error.error_type == mut.ErrorType.rsv_numb:1176 if other_value.sym_type == sym.CSymbolType.Constant and \1177 sym.sym_evaluator.__number__(other_value.content) == 0:1178 new_error = errors.rsv_numb(expression)1179 else:1180 new_error = errors.chg_numb(expression)1181 elif error.error_type == mut.ErrorType.dif_numb:1182 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1183 new_error = errors.dif_numb(expression, -parameter)1184 elif error.error_type == mut.ErrorType.inc_numb:1185 new_error = errors.dec_numb(expression)1186 elif error.error_type == mut.ErrorType.dec_numb:1187 new_error = errors.inc_numb(expression)1188 elif error.error_type == mut.ErrorType.chg_numb:1189 new_error = errors.chg_numb(expression)1190 elif error.error_type == mut.ErrorType.set_addr:1191 if other_value.sym_type == sym.CSymbolType.Constant:1192 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1193 parameter = sym.sym_evaluator.__number__(other_value.content) - parameter1194 new_error = errors.set_numb(expression, parameter)1195 else:1196 new_error = errors.chg_numb(expression)1197 elif error.error_type == mut.ErrorType.dif_addr:1198 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1199 new_error = errors.dif_numb(expression, -parameter)1200 elif error.error_type == mut.ErrorType.chg_addr:1201 new_error = errors.chg_numb(expression)1202 elif error.error_type == mut.ErrorType.mut_expr:1203 new_error = errors.mut_expr(expression)1204 elif error.error_type == mut.ErrorType.mut_refer:1205 new_error = errors.mut_expr(expression)1206 else:1207 pass1208 # 3. save the error and its constraints1209 if new_error is not None:1210 error_dict[new_error] = constraints1211 return error_dict12121213 def __generate_on_arith_mul__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):1214 """1215 :param expression:1216 :param error:1217 :param error_dict:1218 :return:1219 """1220 # 1. declarations1221 errors, new_error = self.graph.get_error_set(), None1222 # 2. determine another operand and its constraints1223 if expression.get_child(0) == error.get_cir_location(): # expression := error * another1224 other_operand = expression.get_child(1)1225 else: # expression := another * error1226 other_operand = expression.get_child(0)1227 constraints = StateErrorBuilder.__boolean_constraint__(other_operand, True)1228 # 3. determine the constant value hold by another operand or None1229 other_sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(other_operand))1230 if other_sym_operand.sym_type == sym.CSymbolType.Constant:1231 other_value = sym.sym_evaluator.__number__(other_sym_operand.content)1232 else:1233 other_value = None1234 # 4. type-based analysis1235 if error.error_type == mut.ErrorType.set_bool:1236 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1237 if parameter == 0:1238 new_error = errors.set_numb(expression, 0)1239 elif other_value is not None:1240 new_error = errors.set_numb(expression, parameter * other_value)1241 else:1242 new_error = errors.chg_numb(expression)1243 elif error.error_type == mut.ErrorType.chg_bool:1244 new_error = errors.chg_bool(expression)1245 elif error.error_type == mut.ErrorType.set_numb:1246 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1247 if parameter == 0:1248 new_error = errors.set_numb(expression, 0)1249 elif other_value is not None:1250 new_error = errors.set_numb(expression, parameter * other_value)1251 else:1252 new_error = errors.chg_numb(expression)1253 elif error.error_type == mut.ErrorType.neg_numb:1254 new_error = errors.neg_numb(expression)1255 elif error.error_type == mut.ErrorType.rsv_numb:1256 if other_value is not None and other_value == 1:1257 new_error = errors.rsv_numb(expression)1258 else:1259 new_error = errors.chg_bool(expression)1260 elif error.error_type == mut.ErrorType.dif_numb:1261 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1262 if other_value is not None:1263 new_error = errors.dif_numb(expression, parameter * other_value)1264 else:1265 new_error = errors.chg_numb(expression)1266 elif error.error_type == mut.ErrorType.inc_numb:1267 if other_value is not None:1268 if other_value > 0:1269 new_error = errors.inc_numb(expression)1270 else:1271 new_error = errors.dec_numb(expression)1272 else:1273 new_error = errors.chg_numb(expression)1274 elif error.error_type == mut.ErrorType.dec_numb:1275 if other_value is not None:1276 if other_value > 0:1277 new_error = errors.dec_numb(expression)1278 else:1279 new_error = errors.inc_numb(expression)1280 else:1281 new_error = errors.chg_numb(expression)1282 elif error.error_type == mut.ErrorType.chg_numb:1283 new_error = errors.chg_numb(expression)1284 elif error.error_type == mut.ErrorType.set_addr:1285 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1286 if parameter == 0:1287 new_error = errors.set_numb(expression, 0)1288 elif other_value is not None:1289 new_error = errors.set_numb(expression, parameter * other_value)1290 else:1291 new_error = errors.chg_numb(expression)1292 elif error.error_type == mut.ErrorType.dif_addr:1293 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1294 if other_value is not None:1295 new_error = errors.dif_numb(expression, parameter * other_value)1296 else:1297 new_error = errors.chg_numb(expression)1298 elif error.error_type == mut.ErrorType.chg_addr:1299 new_error = errors.chg_numb(expression)1300 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:1301 new_error = errors.chg_numb(expression)1302 else:1303 pass1304 # 5. save the result in error_dict1305 if new_error is not None:1306 error_dict[new_error] = constraints1307 return error_dict13081309 def __generate_on_arith_div__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):1310 """1311 :param expression:1312 :param error:1313 :param error_dict:1314 :return:1315 """1316 # 1. declaration1317 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)1318 # 2. generate new-error and constraints based on error-type1319 if expression.get_child(0) == error.get_cir_location(): # expression = error / operand1320 # 2.1. get the operand, symbolic representation and constant of another1321 cir_operand = expression.get_child(1)1322 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))1323 sym_constant = None1324 if sym_operand.sym_type == sym.CSymbolType.Constant:1325 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)1326 # 2. error based propagation1327 if error.error_type == mut.ErrorType.set_bool:1328 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1329 if parameter == 0:1330 new_error = errors.set_numb(expression, 0)1331 elif sym_constant is not None:1332 new_error = errors.set_numb(expression, parameter / sym_constant)1333 else:1334 new_error = errors.chg_numb(expression)1335 elif error.error_type == mut.ErrorType.chg_bool:1336 new_error = errors.chg_numb(expression)1337 elif error.error_type == mut.ErrorType.set_numb:1338 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1339 if parameter == 0:1340 new_error = errors.set_numb(expression, 0)1341 elif sym_constant is not None:1342 new_error = errors.set_numb(expression, parameter / sym_constant)1343 else:1344 new_error = errors.chg_numb(expression)1345 elif error.error_type == mut.ErrorType.neg_numb:1346 new_error = errors.neg_numb(expression)1347 elif error.error_type == mut.ErrorType.rsv_numb:1348 if sym_constant is not None and sym_constant == 1:1349 new_error = errors.rsv_numb(expression)1350 else:1351 new_error = errors.chg_numb(expression)1352 elif error.error_type == mut.ErrorType.dif_numb:1353 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1354 if parameter != 0:1355 if sym_constant is not None:1356 new_error = errors.dif_numb(expression, parameter / sym_constant)1357 else:1358 new_error = errors.chg_numb(expression)1359 else:1360 pass1361 elif error.error_type == mut.ErrorType.inc_numb:1362 if sym_constant is not None:1363 if sym_constant > 0:1364 new_error = errors.inc_numb(expression)1365 else:1366 new_error = errors.dec_numb(expression)1367 else:1368 new_error = errors.chg_numb(expression)1369 elif error.error_type == mut.ErrorType.dec_numb:1370 if sym_constant is not None:1371 if sym_constant > 0:1372 new_error = errors.dec_numb(expression)1373 else:1374 new_error = errors.inc_numb(expression)1375 else:1376 new_error = errors.chg_numb(expression)1377 elif error.error_type == mut.ErrorType.chg_numb:1378 new_error = errors.chg_numb(expression)1379 elif error.error_type == mut.ErrorType.set_addr:1380 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1381 if parameter == 0:1382 new_error = errors.set_numb(expression, 0)1383 elif sym_constant is not None:1384 new_error = errors.set_numb(expression, parameter / sym_constant)1385 else:1386 new_error = errors.chg_numb(expression)1387 elif error.error_type == mut.ErrorType.dif_addr:1388 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1389 if parameter != 0:1390 if sym_constant is not None:1391 new_error = errors.dif_numb(expression, parameter / sym_constant)1392 else:1393 new_error = errors.chg_numb(expression)1394 else:1395 pass1396 elif error.error_type == mut.ErrorType.chg_addr:1397 new_error = errors.chg_numb(expression)1398 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:1399 new_error = errors.chg_numb(expression)1400 else:1401 pass1402 else: # expression = operand / error1403 # 3.1. get the operand, symbolic expression and constant of the other1404 cir_operand = expression.get_child(0)1405 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))1406 sym_constant = None1407 if sym_operand.sym_type == sym.CSymbolType.Constant:1408 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)1409 constraints = StateErrorBuilder.__boolean_constraint__(cir_operand, True) # operand != 01410 # 3.2. generate error propagation for expression := operand / error1411 if error.error_type == mut.ErrorType.set_bool:1412 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1413 if parameter == 0:1414 new_error = errors.failure()1415 elif sym_constant is not None:1416 new_error = errors.set_numb(expression, sym_constant / parameter)1417 else:1418 new_error = errors.chg_numb(expression)1419 elif error.error_type == mut.ErrorType.chg_bool:1420 new_error = errors.chg_numb(expression)1421 elif error.error_type == mut.ErrorType.set_numb:1422 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1423 if parameter == 0:1424 new_error = errors.failure()1425 elif sym_constant is not None:1426 new_error = errors.set_numb(expression, sym_constant / parameter)1427 else:1428 new_error = errors.chg_numb(expression)1429 elif error.error_type == mut.ErrorType.neg_numb:1430 new_error = errors.neg_numb(expression)1431 elif error.error_type == mut.ErrorType.rsv_numb:1432 new_error = errors.chg_numb(expression)1433 elif error.error_type == mut.ErrorType.dif_numb:1434 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1435 if parameter > 0:1436 if sym_constant is not None:1437 if sym_constant > 0:1438 new_error = errors.dec_numb(expression)1439 else:1440 new_error = errors.inc_numb(expression)1441 else:1442 new_error = errors.chg_numb(expression)1443 else:1444 if sym_constant is not None:1445 if sym_constant > 0:1446 new_error = errors.inc_numb(expression)1447 else:1448 new_error = errors.dec_numb(expression)1449 else:1450 new_error = errors.chg_numb(expression)1451 elif error.error_type == mut.ErrorType.inc_numb:1452 if sym_constant is not None:1453 if sym_constant > 0:1454 new_error = errors.dec_numb(expression)1455 else:1456 new_error = errors.inc_numb(expression)1457 else:1458 new_error = errors.chg_numb(expression)1459 elif error.error_type == mut.ErrorType.dec_numb:1460 if sym_constant is not None:1461 if sym_constant > 0:1462 new_error = errors.inc_numb(expression)1463 else:1464 new_error = errors.dec_numb(expression)1465 else:1466 new_error = errors.chg_numb(expression)1467 elif error.error_type == mut.ErrorType.chg_numb:1468 new_error = errors.chg_numb(expression)1469 elif error.error_type == mut.ErrorType.set_addr:1470 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1471 if parameter == 0:1472 new_error = errors.failure()1473 elif sym_constant is not None:1474 new_error = errors.set_numb(expression, sym_constant / parameter)1475 else:1476 new_error = errors.chg_numb(expression)1477 elif error.error_type == mut.ErrorType.dif_addr:1478 parameter = sym.sym_evaluator.__number__(error.get_operand(1))1479 if parameter > 0:1480 if sym_constant is not None:1481 if sym_constant > 0:1482 new_error = errors.dec_numb(expression)1483 else:1484 new_error = errors.inc_numb(expression)1485 else:1486 new_error = errors.chg_numb(expression)1487 else:1488 if sym_constant is not None:1489 if sym_constant > 0:1490 new_error = errors.inc_numb(expression)1491 else:1492 new_error = errors.dec_numb(expression)1493 else:1494 new_error = errors.chg_numb(expression)1495 elif error.error_type == mut.ErrorType.chg_addr:1496 new_error = errors.chg_numb(expression)1497 elif error.error_type == mut.ErrorType.mut_expr:1498 new_error = errors.chg_numb(expression)1499 elif error.error_type == mut.ErrorType.mut_refer:1500 new_error = errors.chg_numb(expression)1501 else:1502 pass1503 # 3. save the result in error-dict1504 if new_error is not None:1505 error_dict[new_error] = constraints1506 return error_dict15071508 @staticmethod1509 def __add_number_constraint__(constraints: mut.StateConstraints,1510 expression: cirtree.CirNode, operator: base.COperator, constant):1511 """1512 :param expression:1513 :param operator:1514 :param constant:1515 :return: operand operator value1516 """1517 sym_operand = sym.sym_parser.parse_by_cir_tree(expression)1518 sym_constant = sym.CSymbolNode(sym.CSymbolType.Constant, expression.data_type, constant)1519 sym_condition = sym.CSymbolNode(sym.CSymbolType.BinaryExpression, base.CType(base.CMetaType.BoolType), operator)1520 sym_condition.add_child(sym_operand)1521 sym_condition.add_child(sym_constant)1522 execution = StateErrorBuilder.__execution_of_cir_location__(expression)1523 return constraints.add_constraint(execution, sym_condition)15241525 def __generate_on_arith_mod__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):1526 """1527 :param expression:1528 :param error:1529 :param error_dict:1530 :return:1531 """1532 # 1. declaration1533 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)1534 # 2. generate new-error and constraints based on error-type1535 if expression.get_child(0) == error.get_cir_location(): # expression := error % operand1536 # 2.1. determine the operand, symbolic expression and its operand value1537 operand = expression.get_child(1)1538 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(operand))1539 sym_constant = None1540 if sym_operand.sym_type == sym.CSymbolType.Constant:1541 sym_constant = sym.sym_evaluator.__integer__(sym_operand.content)1542 # 2.2. reconstruct the state constraints1543 StateErrorBuilder.__add_number_constraint__(constraints, operand, base.COperator.not_equals, 1)1544 StateErrorBuilder.__add_number_constraint__(constraints, operand, base.COperator.not_equals, -1)1545 # 2.3. error type based analysis1546 if error.error_type == mut.ErrorType.set_bool:1547 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1548 if parameter == 0:1549 new_error = errors.set_numb(expression, 0)1550 elif sym_constant is not None:1551 new_error = errors.set_numb(expression, parameter % sym_constant)1552 elif parameter == 1 or parameter == -1:1553 new_error = errors.set_numb(expression, 1)1554 else:1555 new_error = errors.chg_numb(expression)1556 elif error.error_type == mut.ErrorType.chg_bool:1557 new_error = errors.chg_numb(expression)1558 elif error.error_type == mut.ErrorType.set_numb:1559 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1560 if parameter == 0:1561 new_error = errors.set_numb(expression, 0)1562 elif sym_constant is not None:1563 new_error = errors.set_numb(expression, parameter % sym_constant)1564 elif parameter == 1 or parameter == -1:1565 new_error = errors.set_numb(expression, 1)1566 else:1567 new_error = errors.chg_numb(expression)1568 elif error.error_type == mut.ErrorType.neg_numb:1569 pass1570 elif error.error_type == mut.ErrorType.rsv_numb:1571 new_error = errors.chg_numb(expression)1572 elif error.error_type == mut.ErrorType.dif_numb:1573 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1574 if sym_constant is not None:1575 new_error = errors.dif_numb(expression, parameter % sym_constant)1576 else:1577 new_error = errors.chg_numb(expression)1578 elif error.error_type == mut.ErrorType.inc_numb or error.error_type == mut.ErrorType.dec_numb:1579 new_error = errors.chg_numb(expression)1580 elif error.error_type == mut.ErrorType.chg_numb:1581 new_error = errors.chg_numb(expression)1582 elif error.error_type == mut.ErrorType.set_addr:1583 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1584 if parameter == 0:1585 new_error = errors.set_numb(expression, 0)1586 elif sym_constant is not None:1587 new_error = errors.set_numb(expression, parameter % sym_constant)1588 elif parameter == 1 or parameter == -1:1589 new_error = errors.set_numb(expression, 1)1590 else:1591 new_error = errors.chg_numb(expression)1592 elif error.error_type == mut.ErrorType.dif_addr:1593 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1594 if sym_constant is not None:1595 new_error = errors.dif_numb(expression, parameter % sym_constant)1596 else:1597 new_error = errors.chg_numb(expression)1598 elif error.error_type == mut.ErrorType.chg_addr:1599 new_error = errors.chg_numb(expression)1600 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:1601 new_error = errors.chg_numb(expression)1602 else:1603 pass1604 else: # expression := operand % error1605 # 2.1. determine the operand, symbolic expression and its operand value1606 operand = expression.get_child(0)1607 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(operand))1608 sym_constant = None1609 if sym_operand.sym_type == sym.CSymbolType.Constant:1610 sym_constant = sym.sym_evaluator.__integer__(sym_operand.content)1611 # 2.2. reconstruct the state constraints1612 StateErrorBuilder.__add_number_constraint__(constraints, operand, base.COperator.not_equals, 0)1613 StateErrorBuilder.__add_number_constraint__(constraints, operand, base.COperator.not_equals, 1)1614 StateErrorBuilder.__add_number_constraint__(constraints, operand, base.COperator.not_equals, -1)1615 # 2.3. generate new-error by source error's type1616 if error.error_type == mut.ErrorType.set_bool:1617 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1618 if parameter == 0:1619 new_error = errors.failure()1620 elif parameter == 1 or parameter == -1:1621 new_error = errors.set_numb(expression, 0)1622 elif sym_constant is not None:1623 new_error = errors.set_numb(expression, sym_constant % parameter)1624 else:1625 new_error = errors.chg_numb(expression)1626 elif error.error_type == mut.ErrorType.chg_bool:1627 new_error = errors.failure()1628 elif error.error_type == mut.ErrorType.set_numb:1629 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1630 if parameter == 0:1631 new_error = errors.failure()1632 elif parameter == 1 or parameter == -1:1633 new_error = errors.set_numb(expression, 0)1634 elif sym_constant is not None:1635 new_error = errors.set_numb(expression, sym_constant % parameter)1636 else:1637 new_error = errors.chg_numb(expression)1638 elif error.error_type == mut.ErrorType.neg_numb:1639 pass1640 elif error.error_type == mut.ErrorType.rsv_numb:1641 new_error = errors.chg_numb(expression)1642 elif error.error_type == mut.ErrorType.dif_numb:1643 new_error = errors.chg_numb(expression)1644 elif error.error_type == mut.ErrorType.inc_numb or error.error_type == mut.ErrorType.dec_numb:1645 new_error = errors.chg_numb(expression)1646 elif error.error_type == mut.ErrorType.chg_numb:1647 new_error = errors.chg_numb(expression)1648 elif error.error_type == mut.ErrorType.set_addr:1649 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1650 if parameter == 0:1651 new_error = errors.failure()1652 elif parameter == 1 or parameter == -1:1653 new_error = errors.set_numb(expression, 0)1654 elif sym_constant is not None:1655 new_error = errors.set_numb(expression, sym_constant % parameter)1656 else:1657 new_error = errors.chg_numb(expression)1658 elif error.error_type == mut.ErrorType.dif_addr:1659 new_error = errors.chg_numb(expression)1660 elif error.error_type == mut.ErrorType.chg_addr:1661 new_error = errors.chg_numb(expression)1662 elif error.error_type == mut.ErrorType.mut_expr:1663 new_error = errors.chg_numb(expression)1664 elif error.error_type == mut.ErrorType.mut_refer:1665 new_error = errors.chg_numb(expression)1666 else:1667 pass1668 # 3. save the result in error-dict1669 if new_error is not None:1670 error_dict[new_error] = constraints1671 return error_dict16721673 def __generate_on_bitws_and__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):1674 """1675 :param expression:1676 :param error:1677 :param error_dict:1678 :return:1679 """1680 # 1. declarations and get operand with its constant1681 errors, new_error = self.graph.get_error_set(), None1682 if expression.get_child(0) == error.get_cir_location():1683 cir_operand = expression.get_child(1)1684 else:1685 cir_operand = expression.get_child(0)1686 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))1687 if sym_operand.sym_type == sym.CSymbolType.Constant:1688 sym_constant = sym.sym_evaluator.__integer__(sym_operand.content)1689 else:1690 sym_constant = None1691 constraints = StateErrorBuilder.__boolean_constraint__(cir_operand, True)1692 # 2. generate new-error w.r.t the type of source state error1693 if error.error_type == mut.ErrorType.set_bool:1694 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1695 if parameter == 0:1696 new_error = errors.set_numb(expression, 0)1697 elif sym_constant is not None:1698 new_error = errors.set_numb(expression, parameter & sym_constant)1699 else:1700 new_error = errors.chg_numb(expression)1701 elif error.error_type == mut.ErrorType.chg_bool:1702 new_error = errors.chg_numb(expression)1703 elif error.error_type == mut.ErrorType.set_numb:1704 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1705 if parameter == 0:1706 new_error = errors.set_numb(expression, 0)1707 elif sym_constant is not None:1708 new_error = errors.set_numb(expression, parameter & sym_constant)1709 else:1710 new_error = errors.chg_numb(expression)1711 elif error.error_type == mut.ErrorType.neg_numb:1712 if sym_constant is not None and sym_constant == -1:1713 new_error = errors.neg_numb(expression)1714 else:1715 new_error = errors.chg_numb(expression)1716 elif error.error_type == mut.ErrorType.rsv_numb:1717 if sym_constant is not None and sym_constant == -1:1718 new_error = errors.rsv_numb(expression)1719 else:1720 new_error = errors.chg_numb(expression)1721 elif error.error_type == mut.ErrorType.dif_numb:1722 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1723 if sym_constant is not None:1724 new_error = errors.dif_numb(expression, parameter & sym_constant)1725 else:1726 new_error = errors.chg_numb(expression)1727 elif error.error_type == mut.ErrorType.inc_numb:1728 if sym_constant is not None and sym_constant == -1:1729 new_error = errors.inc_numb(expression)1730 else:1731 new_error = errors.chg_numb(expression)1732 elif error.error_type == mut.ErrorType.dec_numb:1733 if sym_constant is not None and sym_constant == -1:1734 new_error = errors.dec_numb(expression)1735 else:1736 new_error = errors.chg_numb(expression)1737 elif error.error_type == mut.ErrorType.chg_numb:1738 new_error = errors.chg_numb(expression)1739 elif error.error_type == mut.ErrorType.set_addr:1740 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1741 if parameter == 0:1742 new_error = errors.set_numb(expression, 0)1743 elif sym_constant is not None:1744 new_error = errors.set_numb(expression, parameter & sym_constant)1745 else:1746 new_error = errors.chg_numb(expression)1747 elif error.error_type == mut.ErrorType.dif_addr:1748 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1749 if sym_constant is not None:1750 new_error = errors.dif_numb(expression, parameter & sym_constant)1751 else:1752 new_error = errors.chg_numb(expression)1753 elif error.error_type == mut.ErrorType.chg_addr:1754 new_error = errors.chg_numb(expression)1755 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:1756 new_error = errors.chg_numb(expression)1757 else:1758 pass1759 # 3. save the new-error with its state constraints1760 if new_error is not None:1761 error_dict[new_error] = constraints1762 return error_dict17631764 def __generate_on_bitws_ior__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):1765 """1766 :param expression:1767 :param error:1768 :param error_dict:1769 :return:1770 """1771 # 1. declarations and get operand with its constant1772 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)1773 if expression.get_child(0) == error.get_cir_location():1774 cir_operand = expression.get_child(1)1775 else:1776 cir_operand = expression.get_child(0)1777 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))1778 if sym_operand.sym_type == sym.CSymbolType.Constant:1779 sym_constant = sym.sym_evaluator.__integer__(sym_operand.content)1780 else:1781 sym_constant = None1782 StateErrorBuilder.__add_number_constraint__(constraints, cir_operand, base.COperator.not_equals, -1)1783 # 2. generate new-error w.r.t the type of source state error1784 if error.error_type == mut.ErrorType.set_bool:1785 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1786 if parameter == -1:1787 new_error = errors.set_numb(expression, -1)1788 elif sym_constant is not None:1789 new_error = errors.set_numb(expression, parameter | sym_constant)1790 else:1791 new_error = errors.chg_numb(expression)1792 elif error.error_type == mut.ErrorType.chg_bool:1793 new_error = errors.chg_numb(expression)1794 elif error.error_type == mut.ErrorType.set_numb:1795 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1796 if parameter == -1:1797 new_error = errors.set_numb(expression, -1)1798 elif sym_constant is not None:1799 new_error = errors.set_numb(expression, parameter | sym_constant)1800 else:1801 new_error = errors.chg_numb(expression)1802 elif error.error_type == mut.ErrorType.neg_numb:1803 if sym_constant is not None and sym_constant == 0:1804 new_error = errors.neg_numb(expression)1805 else:1806 new_error = errors.chg_numb(expression)1807 elif error.error_type == mut.ErrorType.rsv_numb:1808 if sym_constant is not None and sym_constant == 0:1809 new_error = errors.rsv_numb(expression)1810 else:1811 new_error = errors.chg_numb(expression)1812 elif error.error_type == mut.ErrorType.dif_numb:1813 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1814 if sym_constant is not None:1815 new_error = errors.dif_numb(expression, parameter | sym_constant)1816 else:1817 new_error = errors.chg_numb(expression)1818 elif error.error_type == mut.ErrorType.inc_numb:1819 if sym_constant is not None and sym_constant == 0:1820 new_error = errors.inc_numb(expression)1821 else:1822 new_error = errors.chg_numb(expression)1823 elif error.error_type == mut.ErrorType.dec_numb:1824 if sym_constant is not None and sym_constant == 0:1825 new_error = errors.dec_numb(expression)1826 else:1827 new_error = errors.chg_numb(expression)1828 elif error.error_type == mut.ErrorType.chg_numb:1829 new_error = errors.chg_numb(expression)1830 elif error.error_type == mut.ErrorType.set_addr:1831 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1832 if parameter == -1:1833 new_error = errors.set_numb(expression, -1)1834 elif sym_constant is not None:1835 new_error = errors.set_numb(expression, parameter | sym_constant)1836 else:1837 new_error = errors.chg_numb(expression)1838 elif error.error_type == mut.ErrorType.dif_addr:1839 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1840 if sym_constant is not None:1841 new_error = errors.dif_numb(expression, parameter | sym_constant)1842 else:1843 new_error = errors.chg_numb(expression)1844 elif error.error_type == mut.ErrorType.chg_addr:1845 new_error = errors.chg_numb(expression)1846 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:1847 new_error = errors.chg_numb(expression)1848 else:1849 pass1850 # 3. save the new-error with its state constraints1851 if new_error is not None:1852 error_dict[new_error] = constraints1853 return error_dict18541855 def __generate_on_bitws_xor__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):1856 """1857 :param expression:1858 :param error:1859 :param error_dict:1860 :return:1861 """1862 # 1. declarations and get operand with its constant1863 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)1864 if expression.get_child(0) == error.get_cir_location():1865 cir_operand = expression.get_child(1)1866 else:1867 cir_operand = expression.get_child(0)1868 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))1869 if sym_operand.sym_type == sym.CSymbolType.Constant:1870 sym_constant = sym.sym_evaluator.__integer__(sym_operand.content)1871 else:1872 sym_constant = None1873 # 2. generate new-error w.r.t the type of source state error1874 if error.error_type == mut.ErrorType.set_bool:1875 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1876 if sym_constant is not None:1877 new_error = errors.set_numb(expression, sym_constant ^ parameter)1878 else:1879 new_error = errors.chg_numb(expression)1880 elif error.error_type == mut.ErrorType.chg_bool:1881 new_error = errors.chg_numb(expression)1882 elif error.error_type == mut.ErrorType.set_numb:1883 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1884 if sym_constant is not None:1885 new_error = errors.set_numb(expression, sym_constant ^ parameter)1886 else:1887 new_error = errors.chg_numb(expression)1888 elif error.error_type == mut.ErrorType.neg_numb:1889 if sym_constant is not None and sym_constant == 0:1890 new_error = errors.neg_numb(expression)1891 else:1892 new_error = errors.chg_numb(expression)1893 elif error.error_type == mut.ErrorType.rsv_numb:1894 new_error = errors.rsv_numb(expression)1895 elif error.error_type == mut.ErrorType.dif_numb:1896 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1897 if sym_constant is not None:1898 new_error = errors.dif_numb(expression, sym_constant ^ parameter)1899 else:1900 new_error = errors.chg_numb(expression)1901 elif error.error_type == mut.ErrorType.inc_numb:1902 if sym_constant is not None and sym_constant == 0:1903 new_error = errors.inc_numb(expression)1904 else:1905 new_error = errors.chg_numb(expression)1906 elif error.error_type == mut.ErrorType.dec_numb:1907 if sym_constant is not None and sym_constant == 0:1908 new_error = errors.dec_numb(expression)1909 else:1910 new_error = errors.chg_numb(expression)1911 elif error.error_type == mut.ErrorType.chg_numb:1912 new_error = errors.chg_numb(expression)1913 elif error.error_type == mut.ErrorType.set_addr:1914 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1915 if sym_constant is not None:1916 new_error = errors.set_numb(expression, sym_constant ^ parameter)1917 else:1918 new_error = errors.chg_numb(expression)1919 elif error.error_type == mut.ErrorType.dif_addr:1920 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1921 if sym_constant is not None:1922 new_error = errors.dif_numb(expression, sym_constant ^ parameter)1923 else:1924 new_error = errors.chg_numb(expression)1925 elif error.error_type == mut.ErrorType.chg_addr:1926 new_error = errors.chg_numb(expression)1927 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:1928 new_error = errors.chg_numb(expression)1929 else:1930 pass1931 # 3. save the new-error with its state constraints1932 if new_error is not None:1933 error_dict[new_error] = constraints1934 return error_dict19351936 def __generate_on_bitws_lsh__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):1937 """1938 :param expression:1939 :param error:1940 :param error_dict:1941 :return:1942 """1943 # 1. declarations1944 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)1945 # 2. generate new-error based on type of source error1946 if expression.get_child(0) == error.get_cir_location(): # expression := error << operand1947 # 2.1. determine another operand with its symbolic expression and constant1948 cir_operand = expression.get_child(1)1949 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))1950 if sym_operand.sym_type == sym.CSymbolType.Constant:1951 sym_constant = sym.sym_evaluator.__integer__(sym_operand.content)1952 else:1953 sym_constant = None1954 StateErrorBuilder.__add_number_constraint__(constraints, cir_operand, base.COperator.smaller_eq, 32)1955 # 2.2. error propagation based on type of source state error1956 if error.error_type == mut.ErrorType.set_bool:1957 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1958 if parameter == 0:1959 new_error = errors.set_numb(expression, 0)1960 elif sym_constant is not None:1961 new_error = errors.set_numb(expression, parameter << sym_constant)1962 else:1963 new_error = errors.chg_numb(expression)1964 elif error.error_type == mut.ErrorType.chg_bool:1965 new_error = errors.chg_numb(expression)1966 elif error.error_type == mut.ErrorType.set_numb:1967 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1968 if parameter == 0:1969 new_error = errors.set_numb(expression, 0)1970 elif sym_constant is not None:1971 new_error = errors.set_numb(expression, parameter << sym_constant)1972 else:1973 new_error = errors.chg_numb(expression)1974 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb:1975 new_error = errors.chg_numb(expression)1976 elif error.error_type == mut.ErrorType.dif_numb:1977 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))1978 if parameter == 0:1979 new_error = errors.dif_numb(expression, 0)1980 elif sym_constant is not None:1981 new_error = errors.dif_numb(expression, parameter << sym_constant)1982 elif parameter > 0:1983 new_error = errors.inc_numb(expression)1984 else:1985 new_error = errors.dec_numb(expression)1986 elif error.error_type == mut.ErrorType.inc_numb:1987 new_error = errors.chg_numb(expression)1988 elif error.error_type == mut.ErrorType.dec_numb:1989 new_error = errors.chg_numb(expression)1990 elif error.error_type == mut.ErrorType.chg_numb:1991 new_error = errors.chg_numb(expression)1992 elif error.error_type == mut.ErrorType.set_addr:1993 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))1994 if parameter == 0:1995 new_error = errors.dif_numb(expression, 0)1996 elif sym_constant is not None:1997 new_error = errors.dif_numb(expression, parameter << sym_constant)1998 else:1999 new_error = errors.chg_numb(expression)2000 elif error.error_type == mut.ErrorType.dif_addr:2001 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2002 if parameter == 0:2003 new_error = errors.dif_numb(expression, 0)2004 elif sym_constant is not None:2005 new_error = errors.dif_numb(expression, parameter << sym_constant)2006 elif parameter > 0:2007 new_error = errors.inc_numb(expression)2008 else:2009 new_error = errors.dec_numb(expression)2010 elif error.error_type == mut.ErrorType.chg_addr:2011 new_error = errors.chg_numb(expression)2012 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2013 new_error = errors.chg_numb(expression)2014 else:2015 pass2016 else: # expression := operand << error2017 # 2.1. determine another operand with its symbolic expression and constant2018 cir_operand = expression.get_child(0)2019 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2020 if sym_operand.sym_type == sym.CSymbolType.Constant:2021 sym_constant = sym.sym_evaluator.__integer__(sym_operand.content)2022 else:2023 sym_constant = None2024 StateErrorBuilder.__add_number_constraint__(constraints, cir_operand, base.COperator.not_equals, 0)2025 # 2.2. error propagation based on type of source state error2026 if error.error_type == mut.ErrorType.set_bool:2027 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2028 if parameter > 32:2029 new_error = errors.set_numb(expression, 0)2030 elif sym_constant is not None:2031 new_error = errors.set_numb(expression, sym_constant << parameter)2032 else:2033 new_error = errors.chg_numb(expression)2034 elif error.error_type == mut.ErrorType.chg_bool:2035 new_error = errors.chg_numb(expression)2036 elif error.error_type == mut.ErrorType.set_numb:2037 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2038 if parameter > 32:2039 new_error = errors.set_numb(expression, 0)2040 elif sym_constant is not None:2041 new_error = errors.set_numb(expression, sym_constant << parameter)2042 else:2043 new_error = errors.chg_numb(expression)2044 elif error.error_type == mut.ErrorType.neg_numb:2045 new_error = errors.chg_numb(expression)2046 elif error.error_type == mut.ErrorType.rsv_numb:2047 new_error = errors.chg_numb(expression)2048 elif error.error_type == mut.ErrorType.dif_numb:2049 new_error = errors.chg_numb(expression)2050 elif error.error_type == mut.ErrorType.inc_numb or error.error_type == mut.ErrorType.dec_numb:2051 new_error = errors.chg_numb(expression)2052 elif error.error_type == mut.ErrorType.chg_numb:2053 new_error = errors.chg_numb(expression)2054 elif error.error_type == mut.ErrorType.set_addr:2055 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2056 if parameter > 32:2057 new_error = errors.set_numb(expression, 0)2058 elif sym_constant is not None:2059 new_error = errors.set_numb(expression, sym_constant << parameter)2060 else:2061 new_error = errors.chg_numb(expression)2062 elif error.error_type == mut.ErrorType.dif_addr:2063 new_error = errors.chg_numb(expression)2064 elif error.error_type == mut.ErrorType.chg_addr:2065 new_error = errors.chg_numb(expression)2066 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2067 new_error = errors.chg_numb(expression)2068 else:2069 pass2070 # 3. save the result in error-dict2071 if new_error is not None:2072 error_dict[new_error] = constraints2073 return error_dict20742075 def __generate_on_bitws_rsh__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2076 """2077 :param expression:2078 :param error:2079 :param error_dict:2080 :return:2081 """2082 # 1. declarations2083 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)2084 # 2. generate new-error based on type of source error2085 if expression.get_child(0) == error.get_cir_location(): # expression := error >> operand2086 # 2.1. determine another operand with its symbolic expression and constant2087 cir_operand = expression.get_child(1)2088 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2089 if sym_operand.sym_type == sym.CSymbolType.Constant:2090 sym_constant = sym.sym_evaluator.__integer__(sym_operand.content)2091 else:2092 sym_constant = None2093 StateErrorBuilder.__add_number_constraint__(constraints, cir_operand, base.COperator.smaller_eq, 32)2094 # 2.2. error propagation based on source error type2095 if error.error_type == mut.ErrorType.set_bool:2096 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2097 if parameter == 0:2098 new_error = errors.set_numb(expression, 0)2099 elif sym_constant is not None:2100 new_error = errors.set_numb(expression, parameter >> parameter)2101 else:2102 new_error = errors.chg_numb(expression)2103 elif error.error_type == mut.ErrorType.chg_bool:2104 new_error = errors.chg_numb(expression)2105 elif error.error_type == mut.ErrorType.set_numb:2106 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2107 if parameter == 0:2108 new_error = errors.set_numb(expression, 0)2109 elif sym_constant is not None:2110 new_error = errors.set_numb(expression, parameter >> sym_constant)2111 else:2112 new_error = errors.chg_numb(expression)2113 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb:2114 new_error = errors.chg_numb(expression)2115 elif error.error_type == mut.ErrorType.dif_numb:2116 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2117 if sym_constant is not None:2118 new_error = errors.dif_numb(expression, parameter << sym_constant)2119 elif parameter > 0:2120 new_error = errors.inc_numb(expression)2121 else:2122 new_error = errors.dec_numb(expression)2123 elif error.error_type == mut.ErrorType.inc_numb or error.error_type == mut.ErrorType.dec_numb:2124 new_error = errors.chg_numb(expression)2125 elif error.error_type == mut.ErrorType.chg_numb:2126 new_error = errors.chg_numb(expression)2127 elif error.error_type == mut.ErrorType.set_addr:2128 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2129 if parameter == 0:2130 new_error = errors.set_numb(expression, 0)2131 elif sym_constant is not None:2132 new_error = errors.set_numb(expression, parameter >> sym_constant)2133 else:2134 new_error = errors.chg_numb(expression)2135 elif error.error_type == mut.ErrorType.dif_addr:2136 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2137 if sym_constant is not None:2138 new_error = errors.dif_numb(expression, parameter >> sym_constant)2139 elif parameter > 0:2140 new_error = errors.inc_numb(expression)2141 else:2142 new_error = errors.dec_numb(expression)2143 elif error.error_type == mut.ErrorType.chg_addr:2144 new_error = errors.chg_numb(expression)2145 elif error.error_type == mut.ErrorType.mut_expr or mut.ErrorType.mut_refer:2146 new_error = errors.chg_numb(expression)2147 else:2148 pass2149 else: # expression := operand >> error2150 # 2.1. determine another operand with its symbolic expression and constant2151 cir_operand = expression.get_child(0)2152 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2153 if sym_operand.sym_type == sym.CSymbolType.Constant:2154 sym_constant = sym.sym_evaluator.__integer__(sym_operand.content)2155 else:2156 sym_constant = None2157 StateErrorBuilder.__add_number_constraint__(constraints, cir_operand, base.COperator.not_equals, 0)2158 # 2.2. error propagation based on source error type2159 if error.error_type == mut.ErrorType.set_bool:2160 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2161 if sym_constant is not None:2162 new_error = errors.set_numb(expression, sym_constant >> parameter)2163 elif parameter > 32:2164 new_error = errors.set_numb(expression, 0)2165 else:2166 new_error = errors.chg_numb(expression)2167 elif error.error_type == mut.ErrorType.chg_bool:2168 new_error = errors.chg_numb(expression)2169 elif error.error_type == mut.ErrorType.set_numb:2170 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2171 if sym_constant is not None:2172 new_error = errors.set_numb(expression, sym_constant >> parameter)2173 elif parameter > 32:2174 new_error = errors.set_numb(expression, 0)2175 else:2176 new_error = errors.chg_numb(expression)2177 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb:2178 new_error = errors.chg_numb(expression)2179 elif error.error_type == mut.ErrorType.dif_numb:2180 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2181 if parameter > 0:2182 new_error = errors.dec_numb(expression)2183 else:2184 new_error = errors.inc_numb(expression)2185 elif error.error_type == mut.ErrorType.inc_numb or error.error_type == mut.ErrorType.dec_numb:2186 new_error = errors.chg_numb(expression)2187 elif error.error_type == mut.ErrorType.chg_numb:2188 new_error = errors.chg_numb(expression)2189 elif error.error_type == mut.ErrorType.set_addr:2190 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2191 if sym_constant is not None:2192 new_error = errors.set_numb(expression, sym_constant >> parameter)2193 elif parameter > 32:2194 new_error = errors.set_numb(expression, 0)2195 else:2196 new_error = errors.chg_numb(expression)2197 elif error.error_type == mut.ErrorType.dif_addr:2198 parameter = sym.sym_evaluator.__integer__(error.get_operand(1))2199 if parameter > 0:2200 new_error = errors.dec_numb(expression)2201 else:2202 new_error = errors.inc_numb(expression)2203 elif error.error_type == mut.ErrorType.chg_addr:2204 new_error = errors.chg_numb(expression)2205 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2206 new_error = errors.chg_numb(expression)2207 else:2208 pass2209 # 3. save the result in error-dict2210 if new_error is not None:2211 error_dict[new_error] = constraints2212 return error_dict22132214 def __generate_on_logic_and__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2215 """2216 :param expression:2217 :param error:2218 :param error_dict:2219 :return:2220 """2221 # 1. determine the operand, symbolic expression and its constant, constraints.2222 errors, new_error = self.graph.get_error_set(), None2223 if expression.get_child(0) == error.get_cir_location():2224 cir_operand = expression.get_child(1)2225 else:2226 cir_operand = expression.get_child(0)2227 constraints = StateErrorBuilder.__boolean_constraint__(cir_operand, True)2228 # 2. determine the error propagation based on source error type2229 if error.error_type == mut.ErrorType.set_bool:2230 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))2231 new_error = errors.set_bool(expression, parameter)2232 elif error.error_type == mut.ErrorType.chg_bool:2233 new_error = errors.chg_bool(expression)2234 elif error.error_type == mut.ErrorType.set_numb:2235 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))2236 new_error = errors.set_bool(expression, parameter)2237 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb:2238 new_error = errors.set_bool(expression, True)2239 elif error.error_type == mut.ErrorType.dif_numb:2240 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2241 if parameter > 0:2242 new_error = errors.set_bool(expression, True)2243 else:2244 new_error = errors.chg_bool(expression)2245 elif error.error_type == mut.ErrorType.inc_numb:2246 new_error = errors.set_bool(expression, True)2247 elif error.error_type == mut.ErrorType.dec_numb:2248 new_error = errors.chg_bool(expression)2249 elif error.error_type == mut.ErrorType.chg_numb:2250 new_error = errors.set_bool(expression, True)2251 elif error.error_type == mut.ErrorType.set_addr:2252 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2253 new_error = errors.set_bool(expression, parameter != 0)2254 elif error.error_type == mut.ErrorType.dif_addr:2255 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2256 if parameter > 0:2257 new_error = errors.set_bool(expression, True)2258 else:2259 new_error = errors.chg_bool(expression)2260 elif error.error_type == mut.ErrorType.chg_addr:2261 new_error = errors.set_bool(expression, True)2262 elif error.error_type == mut.ErrorType.mut_expr or mut.ErrorType.mut_refer:2263 new_error = errors.set_bool(expression, True)2264 else:2265 pass2266 # 3. save the result in error-dict2267 if new_error is not None:2268 error_dict[new_error] = constraints2269 return error_dict22702271 def __generate_on_logic_ior__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2272 """2273 :param expression:2274 :param error:2275 :param error_dict:2276 :return:2277 """2278 # 1. determine the operand, symbolic expression and its constant, constraints.2279 errors, new_error = self.graph.get_error_set(), None2280 if expression.get_child(0) == error.get_cir_location():2281 cir_operand = expression.get_child(1)2282 else:2283 cir_operand = expression.get_child(0)2284 constraints = StateErrorBuilder.__boolean_constraint__(cir_operand, False)2285 # 2. determine the error propagation based on source error type2286 if error.error_type == mut.ErrorType.set_bool:2287 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))2288 new_error = errors.set_bool(expression, parameter)2289 elif error.error_type == mut.ErrorType.chg_bool:2290 new_error = errors.chg_bool(expression)2291 elif error.error_type == mut.ErrorType.set_numb:2292 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))2293 new_error = errors.set_bool(expression, parameter)2294 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb:2295 new_error = errors.set_bool(expression, True)2296 elif error.error_type == mut.ErrorType.dif_numb:2297 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2298 if parameter > 0:2299 new_error = errors.set_bool(expression, True)2300 else:2301 new_error = errors.chg_bool(expression)2302 elif error.error_type == mut.ErrorType.inc_numb:2303 new_error = errors.set_bool(expression, True)2304 elif error.error_type == mut.ErrorType.dec_numb:2305 new_error = errors.chg_bool(expression)2306 elif error.error_type == mut.ErrorType.chg_numb:2307 new_error = errors.chg_bool(expression)2308 elif error.error_type == mut.ErrorType.set_addr:2309 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2310 new_error = errors.set_bool(expression, parameter != 0)2311 elif error.error_type == mut.ErrorType.dif_addr:2312 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2313 if parameter > 0:2314 new_error = errors.set_bool(expression, True)2315 else:2316 new_error = errors.chg_bool(expression)2317 elif error.error_type == mut.ErrorType.chg_addr:2318 new_error = errors.chg_bool(expression)2319 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2320 new_error = errors.chg_bool(expression)2321 else:2322 pass2323 # 3. save the result in error-dict2324 if new_error is not None:2325 error_dict[new_error] = constraints2326 return error_dict23272328 def __generate_on_greater_tn__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2329 """2330 :param expression:2331 :param error:2332 :param error_dict:2333 :return:2334 """2335 # 1. declarations2336 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)2337 # 2. generate new-error based on type of source error2338 if expression.get_child(0) == error.get_cir_location(): # expression := error > operand2339 # 2.1. get the constant and description of another operand2340 cir_operand = expression.get_child(1)2341 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2342 if sym_operand.sym_type == sym.CSymbolType.Constant:2343 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2344 else:2345 sym_constant = None2346 # 2.2. error propagation to new-error2347 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.set_numb or \2348 error.error_type == mut.ErrorType.set_addr:2349 if error.error_type == mut.ErrorType.set_addr:2350 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2351 else:2352 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2353 if sym_constant is not None:2354 new_error = errors.set_bool(expression, parameter > sym_constant)2355 else:2356 new_error = errors.chg_bool(expression)2357 elif error.error_type == mut.ErrorType.dif_addr or error.error_type == mut.ErrorType.dif_numb:2358 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2359 if parameter > 0:2360 new_error = errors.set_bool(expression, True)2361 elif parameter < 0:2362 new_error = errors.set_bool(expression, False)2363 else:2364 pass2365 elif error.error_type == mut.ErrorType.inc_numb:2366 new_error = errors.set_bool(expression, True)2367 elif error.error_type == mut.ErrorType.dec_numb:2368 new_error = errors.set_bool(expression, False)2369 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb or \2370 error.error_type == mut.ErrorType.chg_numb:2371 new_error = errors.chg_bool(expression)2372 elif error.error_type == mut.ErrorType.chg_bool or error.error_type == mut.ErrorType.chg_addr:2373 if sym_constant is not None and sym_constant < 0:2374 pass2375 else:2376 new_error = errors.chg_bool(expression)2377 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2378 new_error = errors.chg_bool(expression)2379 else:2380 pass2381 else: # expression := operand > error2382 # 2.1. get the constant and description of another operand2383 cir_operand = expression.get_child(0)2384 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2385 if sym_operand.sym_type == sym.CSymbolType.Constant:2386 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2387 else:2388 sym_constant = None2389 # 2.2. error propagation to new-error2390 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.set_numb or \2391 error.error_type == mut.ErrorType.set_addr:2392 if error.error_type == mut.ErrorType.set_addr:2393 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2394 else:2395 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2396 if sym_constant is not None:2397 new_error = errors.set_bool(expression, sym_constant > parameter)2398 else:2399 new_error = errors.chg_bool(expression)2400 elif error.error_type == mut.ErrorType.dif_numb or error.error_type == mut.ErrorType.dif_addr:2401 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2402 if parameter > 0:2403 new_error = errors.set_bool(expression, False)2404 elif parameter < 0:2405 new_error = errors.set_bool(expression, True)2406 else:2407 pass2408 elif error.error_type == mut.ErrorType.inc_numb:2409 new_error = errors.set_bool(expression, False)2410 elif error.error_type == mut.ErrorType.dec_numb:2411 new_error = errors.set_bool(expression, True)2412 elif error.error_type == mut.ErrorType.chg_numb or error.error_type == mut.ErrorType.neg_numb or \2413 error.error_type == mut.ErrorType.rsv_numb:2414 new_error = errors.chg_bool(expression)2415 elif error.error_type == mut.ErrorType.chg_addr or error.error_type == mut.ErrorType.chg_bool:2416 if sym_constant is not None and sym_constant < 0:2417 pass2418 else:2419 new_error = errors.chg_bool(expression)2420 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2421 new_error = errors.chg_bool(expression)2422 else:2423 pass2424 # 3. save the result in error-dict2425 if new_error is not None:2426 error_dict[new_error] = constraints2427 return error_dict24282429 def __generate_on_greater_eq__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2430 """2431 :param expression:2432 :param error:2433 :param error_dict:2434 :return:2435 """2436 # 1. declarations2437 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)2438 # 2. generate new-error based on type of source error2439 if expression.get_child(0) == error.get_cir_location(): # expression := error > operand2440 # 2.1. get the constant and description of another operand2441 cir_operand = expression.get_child(1)2442 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2443 if sym_operand.sym_type == sym.CSymbolType.Constant:2444 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2445 else:2446 sym_constant = None2447 # 2.2. error propagation to new-error2448 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.set_numb or \2449 error.error_type == mut.ErrorType.set_addr:2450 if error.error_type == mut.ErrorType.set_addr:2451 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2452 else:2453 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2454 if sym_constant is not None:2455 new_error = errors.set_bool(expression, parameter >= sym_constant)2456 else:2457 new_error = errors.chg_bool(expression)2458 elif error.error_type == mut.ErrorType.dif_addr or error.error_type == mut.ErrorType.dif_numb:2459 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2460 if parameter > 0:2461 new_error = errors.set_bool(expression, True)2462 elif parameter < 0:2463 new_error = errors.set_bool(expression, False)2464 else:2465 pass2466 elif error.error_type == mut.ErrorType.inc_numb:2467 new_error = errors.set_bool(expression, True)2468 elif error.error_type == mut.ErrorType.dec_numb:2469 new_error = errors.set_bool(expression, False)2470 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb or \2471 error.error_type == mut.ErrorType.chg_numb:2472 new_error = errors.chg_bool(expression)2473 elif error.error_type == mut.ErrorType.chg_bool or error.error_type == mut.ErrorType.chg_addr:2474 if sym_constant is not None and sym_constant <= 0:2475 pass2476 else:2477 new_error = errors.chg_bool(expression)2478 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2479 new_error = errors.chg_bool(expression)2480 else:2481 pass2482 else: # expression := operand > error2483 # 2.1. get the constant and description of another operand2484 cir_operand = expression.get_child(0)2485 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2486 if sym_operand.sym_type == sym.CSymbolType.Constant:2487 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2488 else:2489 sym_constant = None2490 # 2.2. error propagation to new-error2491 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.set_numb or \2492 error.error_type == mut.ErrorType.set_addr:2493 if error.error_type == mut.ErrorType.set_addr:2494 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2495 else:2496 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2497 if sym_constant is not None:2498 new_error = errors.set_bool(expression, sym_constant >= parameter)2499 else:2500 new_error = errors.chg_bool(expression)2501 elif error.error_type == mut.ErrorType.dif_numb or error.error_type == mut.ErrorType.dif_addr:2502 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2503 if parameter > 0:2504 new_error = errors.set_bool(expression, False)2505 elif parameter < 0:2506 new_error = errors.set_bool(expression, True)2507 else:2508 pass2509 elif error.error_type == mut.ErrorType.inc_numb:2510 new_error = errors.set_bool(expression, False)2511 elif error.error_type == mut.ErrorType.dec_numb:2512 new_error = errors.set_bool(expression, True)2513 elif error.error_type == mut.ErrorType.chg_numb or error.error_type == mut.ErrorType.neg_numb or \2514 error.error_type == mut.ErrorType.rsv_numb:2515 new_error = errors.chg_bool(expression)2516 elif error.error_type == mut.ErrorType.chg_addr or error.error_type == mut.ErrorType.chg_bool:2517 if sym_constant is not None and sym_constant <= 0:2518 pass2519 else:2520 new_error = errors.chg_bool(expression)2521 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2522 new_error = errors.chg_bool(expression)2523 else:2524 pass2525 # 3. save the result in error-dict2526 if new_error is not None:2527 error_dict[new_error] = constraints2528 return error_dict25292530 def __generate_on_smaller_tn__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2531 """2532 :param expression:2533 :param error:2534 :param error_dict:2535 :return:2536 """2537 # 1. declarations2538 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)2539 # 2. generate new-error based on type of source error2540 if expression.get_child(1) == error.get_cir_location(): # expression := operand < error2541 # 2.1. get the constant and description of another operand2542 cir_operand = expression.get_child(0)2543 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2544 if sym_operand.sym_type == sym.CSymbolType.Constant:2545 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2546 else:2547 sym_constant = None2548 # 2.2. error propagation to new-error2549 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.set_numb or \2550 error.error_type == mut.ErrorType.set_addr:2551 if error.error_type == mut.ErrorType.set_addr:2552 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2553 else:2554 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2555 if sym_constant is not None:2556 new_error = errors.set_bool(expression, parameter > sym_constant)2557 else:2558 new_error = errors.chg_bool(expression)2559 elif error.error_type == mut.ErrorType.dif_addr or error.error_type == mut.ErrorType.dif_numb:2560 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2561 if parameter > 0:2562 new_error = errors.set_bool(expression, True)2563 elif parameter < 0:2564 new_error = errors.set_bool(expression, False)2565 else:2566 pass2567 elif error.error_type == mut.ErrorType.inc_numb:2568 new_error = errors.set_bool(expression, True)2569 elif error.error_type == mut.ErrorType.dec_numb:2570 new_error = errors.set_bool(expression, False)2571 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb or \2572 error.error_type == mut.ErrorType.chg_numb:2573 new_error = errors.chg_bool(expression)2574 elif error.error_type == mut.ErrorType.chg_bool or error.error_type == mut.ErrorType.chg_addr:2575 if sym_constant is not None and sym_constant < 0:2576 pass2577 else:2578 new_error = errors.chg_bool(expression)2579 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2580 new_error = errors.chg_bool(expression)2581 else:2582 pass2583 else: # expression := error < operand2584 # 2.1. get the constant and description of another operand2585 cir_operand = expression.get_child(1)2586 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2587 if sym_operand.sym_type == sym.CSymbolType.Constant:2588 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2589 else:2590 sym_constant = None2591 # 2.2. error propagation to new-error2592 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.set_numb or \2593 error.error_type == mut.ErrorType.set_addr:2594 if error.error_type == mut.ErrorType.set_addr:2595 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2596 else:2597 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2598 if sym_constant is not None:2599 new_error = errors.set_bool(expression, sym_constant > parameter)2600 else:2601 new_error = errors.chg_bool(expression)2602 elif error.error_type == mut.ErrorType.dif_numb or error.error_type == mut.ErrorType.dif_addr:2603 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2604 if parameter > 0:2605 new_error = errors.set_bool(expression, False)2606 elif parameter < 0:2607 new_error = errors.set_bool(expression, True)2608 else:2609 pass2610 elif error.error_type == mut.ErrorType.inc_numb:2611 new_error = errors.set_bool(expression, False)2612 elif error.error_type == mut.ErrorType.dec_numb:2613 new_error = errors.set_bool(expression, True)2614 elif error.error_type == mut.ErrorType.chg_numb or error.error_type == mut.ErrorType.neg_numb or \2615 error.error_type == mut.ErrorType.rsv_numb:2616 new_error = errors.chg_bool(expression)2617 elif error.error_type == mut.ErrorType.chg_addr or error.error_type == mut.ErrorType.chg_bool:2618 if sym_constant is not None and sym_constant < 0:2619 pass2620 else:2621 new_error = errors.chg_bool(expression)2622 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2623 new_error = errors.chg_bool(expression)2624 else:2625 pass2626 # 3. save the result in error-dict2627 if new_error is not None:2628 error_dict[new_error] = constraints2629 return error_dict26302631 def __generate_on_smaller_eq__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2632 """2633 :param expression:2634 :param error:2635 :param error_dict:2636 :return:2637 """2638 # 1. declarations2639 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)2640 # 2. generate new-error based on type of source error2641 if expression.get_child(1) == error.get_cir_location(): # expression := operand <= error2642 # 2.1. get the constant and description of another operand2643 cir_operand = expression.get_child(0)2644 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2645 if sym_operand.sym_type == sym.CSymbolType.Constant:2646 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2647 else:2648 sym_constant = None2649 # 2.2. error propagation to new-error2650 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.set_numb or \2651 error.error_type == mut.ErrorType.set_addr:2652 if error.error_type == mut.ErrorType.set_addr:2653 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2654 else:2655 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2656 if sym_constant is not None:2657 new_error = errors.set_bool(expression, parameter >= sym_constant)2658 else:2659 new_error = errors.chg_bool(expression)2660 elif error.error_type == mut.ErrorType.dif_addr or error.error_type == mut.ErrorType.dif_numb:2661 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2662 if parameter > 0:2663 new_error = errors.set_bool(expression, True)2664 elif parameter < 0:2665 new_error = errors.set_bool(expression, False)2666 else:2667 pass2668 elif error.error_type == mut.ErrorType.inc_numb:2669 new_error = errors.set_bool(expression, True)2670 elif error.error_type == mut.ErrorType.dec_numb:2671 new_error = errors.set_bool(expression, False)2672 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb or \2673 error.error_type == mut.ErrorType.chg_numb:2674 new_error = errors.chg_bool(expression)2675 elif error.error_type == mut.ErrorType.chg_bool or error.error_type == mut.ErrorType.chg_addr:2676 if sym_constant is not None and sym_constant <= 0:2677 pass2678 else:2679 new_error = errors.chg_bool(expression)2680 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2681 new_error = errors.chg_bool(expression)2682 else:2683 pass2684 else: # expression := error <= operand2685 # 2.1. get the constant and description of another operand2686 cir_operand = expression.get_child(1)2687 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2688 if sym_operand.sym_type == sym.CSymbolType.Constant:2689 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2690 else:2691 sym_constant = None2692 # 2.2. error propagation to new-error2693 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.set_numb or \2694 error.error_type == mut.ErrorType.set_addr:2695 if error.error_type == mut.ErrorType.set_addr:2696 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2697 else:2698 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2699 if sym_constant is not None:2700 new_error = errors.set_bool(expression, sym_constant >= parameter)2701 else:2702 new_error = errors.chg_bool(expression)2703 elif error.error_type == mut.ErrorType.dif_numb or error.error_type == mut.ErrorType.dif_addr:2704 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2705 if parameter > 0:2706 new_error = errors.set_bool(expression, False)2707 elif parameter < 0:2708 new_error = errors.set_bool(expression, True)2709 else:2710 pass2711 elif error.error_type == mut.ErrorType.inc_numb:2712 new_error = errors.set_bool(expression, False)2713 elif error.error_type == mut.ErrorType.dec_numb:2714 new_error = errors.set_bool(expression, True)2715 elif error.error_type == mut.ErrorType.chg_numb or error.error_type == mut.ErrorType.neg_numb or \2716 error.error_type == mut.ErrorType.rsv_numb:2717 new_error = errors.chg_bool(expression)2718 elif error.error_type == mut.ErrorType.chg_addr or error.error_type == mut.ErrorType.chg_bool:2719 if sym_constant is not None and sym_constant <= 0:2720 pass2721 else:2722 new_error = errors.chg_bool(expression)2723 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2724 new_error = errors.chg_bool(expression)2725 else:2726 pass2727 # 3. save the result in error-dict2728 if new_error is not None:2729 error_dict[new_error] = constraints2730 return error_dict27312732 def __generate_on_equal_with__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2733 """2734 :param expression:2735 :param error:2736 :param error_dict:2737 :return:2738 """2739 # 1. determine the operand, symbolic expression and its constant, constraints.2740 errors, new_error = self.graph.get_error_set(), None2741 if expression.get_child(0) == error.get_cir_location():2742 cir_operand = expression.get_child(1)2743 else:2744 cir_operand = expression.get_child(0)2745 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2746 if sym_operand.sym_type == sym.CSymbolType.Constant:2747 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2748 else:2749 sym_constant = None2750 constraints = mut.StateConstraints(True)2751 # 2. error propagation based on error type2752 if error.error_type == mut.ErrorType.set_bool:2753 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2754 if sym_constant is not None:2755 new_error = errors.set_bool(expression, parameter == sym_constant)2756 else:2757 new_error = errors.set_bool(expression, False)2758 elif error.error_type == mut.ErrorType.chg_bool:2759 new_error = errors.set_bool(expression, False)2760 elif error.error_type == mut.ErrorType.set_numb:2761 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2762 if sym_constant is not None:2763 new_error = errors.set_bool(expression, parameter == sym_constant)2764 else:2765 new_error = errors.set_bool(expression, False)2766 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb:2767 new_error = errors.set_bool(expression, False)2768 elif error.error_type == mut.ErrorType.dif_numb or error.error_type == mut.ErrorType.inc_numb or \2769 error.error_type == mut.ErrorType.dec_numb or error.error_type == mut.ErrorType.dif_addr:2770 new_error = errors.chg_bool(expression)2771 elif error.error_type == mut.ErrorType.chg_numb or error.error_type == mut.ErrorType.chg_addr:2772 new_error = errors.set_bool(expression, False)2773 elif error.error_type == mut.ErrorType.set_addr:2774 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2775 if sym_constant is not None:2776 new_error = errors.set_bool(expression, parameter == sym_constant)2777 else:2778 new_error = errors.set_bool(expression, False)2779 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2780 new_error = errors.set_bool(expression, False)2781 else:2782 pass2783 # 3. save the result in error-dict2784 if new_error is not None:2785 error_dict[new_error] = constraints2786 return error_dict27872788 def __generate_on_not_equals__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2789 """2790 :param expression:2791 :param error:2792 :param error_dict:2793 :return:2794 """2795 # 1. determine the operand, symbolic expression and its constant, constraints.2796 errors, new_error = self.graph.get_error_set(), None2797 if expression.get_child(0) == error.get_cir_location():2798 cir_operand = expression.get_child(1)2799 else:2800 cir_operand = expression.get_child(0)2801 sym_operand = sym.sym_evaluator.evaluate(sym.sym_parser.parse_by_cir_tree(cir_operand))2802 if sym_operand.sym_type == sym.CSymbolType.Constant:2803 sym_constant = sym.sym_evaluator.__number__(sym_operand.content)2804 else:2805 sym_constant = None2806 constraints = mut.StateConstraints(True)2807 # 2. error propagation based on error type2808 if error.error_type == mut.ErrorType.set_bool:2809 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2810 if sym_constant is not None:2811 new_error = errors.set_bool(expression, parameter != sym_constant)2812 else:2813 new_error = errors.set_bool(expression, True)2814 elif error.error_type == mut.ErrorType.chg_bool:2815 new_error = errors.set_bool(expression, True)2816 elif error.error_type == mut.ErrorType.set_numb:2817 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2818 if sym_constant is not None:2819 new_error = errors.set_bool(expression, parameter != sym_constant)2820 else:2821 new_error = errors.set_bool(expression, True)2822 elif error.error_type == mut.ErrorType.neg_numb or error.error_type == mut.ErrorType.rsv_numb:2823 new_error = errors.set_bool(expression, True)2824 elif error.error_type == mut.ErrorType.dif_numb or error.error_type == mut.ErrorType.inc_numb or \2825 error.error_type == mut.ErrorType.dec_numb or error.error_type == mut.ErrorType.dif_addr:2826 new_error = errors.chg_bool(expression)2827 elif error.error_type == mut.ErrorType.chg_numb or error.error_type == mut.ErrorType.chg_addr:2828 new_error = errors.set_bool(expression, True)2829 elif error.error_type == mut.ErrorType.set_addr:2830 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2831 if sym_constant is not None:2832 new_error = errors.set_bool(expression, parameter != sym_constant)2833 else:2834 new_error = errors.set_bool(expression, True)2835 elif error.error_type == mut.ErrorType.mut_expr or error.error_type == mut.ErrorType.mut_refer:2836 new_error = errors.set_bool(expression, True)2837 else:2838 pass2839 # 3. save the result in error-dict2840 if new_error is not None:2841 error_dict[new_error] = constraints2842 return error_dict28432844 def __generate_on_field_expression__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2845 """2846 :param expression:2847 :param error:2848 :param error_dict:2849 :return:2850 """2851 # 1. declarations2852 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)2853 # 2. propagation based on source error type2854 if expression.get_child(0) == error.get_cir_location(): # error.field2855 if error.error_type == mut.ErrorType.mut_expr:2856 new_error = errors.mut_expr(expression)2857 elif error.error_type == mut.ErrorType.mut_refer:2858 new_error = errors.mut_refer(expression)2859 else:2860 pass2861 else: # body.error2862 new_error = errors.mut_refer(expression)2863 # 3. save the result in error-dict2864 if new_error is not None:2865 error_dict[new_error] = constraints2866 return error_dict28672868 def __generate_on_initializer_body__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2869 """2870 :param expression:2871 :param error:2872 :param error_dict:2873 :return:2874 """2875 errors = self.graph.get_error_set()2876 if error.error_type != mut.ErrorType.syntax_error and error.error_type != mut.ErrorType.failure:2877 error_dict[errors.mut_expr(expression)] = mut.StateConstraints(True)2878 return error_dict28792880 # error propagation in one statement28812882 def __translate_as_condition__(self, expression: cirtree.CirNode, error: mut.StateError, error_dict: dict):2883 """2884 :param expression:2885 :param error:2886 :param error_dict:2887 :return:2888 """2889 # 1. declarations2890 errors, new_error, constraints = self.graph.get_error_set(), None, mut.StateConstraints(True)2891 # 2. error translation2892 if error.error_type == mut.ErrorType.set_bool:2893 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))2894 new_error = errors.set_bool(expression, parameter)2895 elif error.error_type == mut.ErrorType.chg_bool:2896 new_error = errors.chg_bool(expression)2897 elif error.error_type == mut.ErrorType.set_numb:2898 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))2899 new_error = errors.set_bool(expression, parameter)2900 elif error.error_type == mut.ErrorType.neg_numb:2901 pass2902 elif error.error_type == mut.ErrorType.rsv_numb:2903 new_error = errors.set_bool(expression, True)2904 elif error.error_type == mut.ErrorType.dif_numb or error.error_type == mut.ErrorType.dif_addr or \2905 error.error_type == mut.ErrorType.inc_numb:2906 parameter = sym.sym_evaluator.__number__(error.get_operand(1))2907 if parameter > 0:2908 new_error = errors.set_bool(expression, True)2909 else:2910 new_error = errors.chg_bool(expression)2911 elif error.error_type == mut.ErrorType.dec_numb:2912 new_error = errors.chg_bool(expression)2913 elif error.error_type == mut.ErrorType.chg_numb:2914 new_error = errors.chg_bool(expression)2915 elif error.error_type == mut.ErrorType.set_addr:2916 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))2917 new_error = errors.set_bool(expression, parameter != 0)2918 elif error.error_type == mut.ErrorType.chg_addr or \2919 error.error_type == mut.ErrorType.mut_refer or error.error_type == mut.ErrorType.mut_expr:2920 new_error = errors.chg_bool(expression)2921 else:2922 pass2923 # 3. save the result in error-dict2924 if new_error is not None:2925 error_dict[new_error] = constraints2926 return error_dict29272928 def __generate_inner_statement__(self, error: mut.StateError):2929 """2930 :param error:2931 :return: error_dict2932 """2933 error_dict = dict()2934 if error.get_cir_location() is not None:2935 cir_location = error.get_cir_location()2936 cir_parent = cir_location.get_parent()2937 if cir_parent is None:2938 print("\t\t@WARN: None for", cir_location.generate_code(True), "of",2939 cir_location.ast_source.get_code(True), "at line", cir_location.ast_source.get_beg_line() + 1)2940 pass2941 elif cir_parent.cir_type == cirtree.CirType.defer_expression:2942 self.__generate_on_dereference__(cir_parent, error, error_dict)2943 elif cir_parent.cir_type == cirtree.CirType.field_expression:2944 self.__generate_on_field_expression__(cir_parent, error, error_dict)2945 elif cir_parent.cir_type == cirtree.CirType.address_expression:2946 self.__generate_on_address_of__(cir_parent, error, error_dict)2947 elif cir_parent.cir_type == cirtree.CirType.cast_expression:2948 self.__generate_on_type_cast__(cir_parent, error, error_dict)2949 elif cir_parent.cir_type == cirtree.CirType.initializer_body:2950 self.__generate_on_initializer_body__(cir_parent, error, error_dict)2951 elif cir_parent.cir_type == cirtree.CirType.wait_expression:2952 self.__generate_on_wait_expression__(cir_parent, error, error_dict)2953 elif cir_parent.cir_type == cirtree.CirType.arith_expression:2954 operator = cir_parent.get_operator()2955 if operator == base.COperator.positive:2956 self.__generate_on_arith_pos__(cir_parent, error, error_dict)2957 elif operator == base.COperator.negative:2958 self.__generate_on_arith_neg__(cir_parent, error, error_dict)2959 elif operator == base.COperator.arith_add:2960 self.__generate_on_arith_add__(cir_parent, error, error_dict)2961 elif operator == base.COperator.arith_sub:2962 self.__generate_on_arith_sub__(cir_parent, error, error_dict)2963 elif operator == base.COperator.arith_mul:2964 self.__generate_on_arith_mul__(cir_parent, error, error_dict)2965 elif operator == base.COperator.arith_div:2966 self.__generate_on_arith_div__(cir_parent, error, error_dict)2967 elif operator == base.COperator.arith_mod:2968 self.__generate_on_arith_mod__(cir_parent, error, error_dict)2969 else:2970 pass2971 elif cir_parent.cir_type == cirtree.CirType.bitws_expression:2972 operator = cir_parent.get_operator()2973 if operator == base.COperator.bitws_rsv:2974 self.__generate_on_bitws_rsv__(cir_parent, error, error_dict)2975 elif operator == base.COperator.bitws_and:2976 self.__generate_on_bitws_and__(cir_parent, error, error_dict)2977 elif operator == base.COperator.bitws_ior:2978 self.__generate_on_bitws_ior__(cir_parent, error, error_dict)2979 elif operator == base.COperator.bitws_xor:2980 self.__generate_on_bitws_xor__(cir_parent, error, error_dict)2981 elif operator == base.COperator.bitws_lsh:2982 self.__generate_on_bitws_lsh__(cir_parent, error, error_dict)2983 elif operator == base.COperator.bitws_rsh:2984 self.__generate_on_bitws_rsh__(cir_parent, error, error_dict)2985 else:2986 pass2987 elif cir_parent.cir_type == cirtree.CirType.logic_expression:2988 operator = cir_parent.get_operator()2989 if operator == base.COperator.logic_not:2990 self.__generate_on_logic_not__(cir_parent, error, error_dict)2991 elif operator == base.COperator.logic_and:2992 self.__generate_on_logic_and__(cir_parent, error, error_dict)2993 elif operator == base.COperator.logic_ior:2994 self.__generate_on_logic_ior__(cir_parent, error, error_dict)2995 else:2996 pass2997 elif cir_parent.cir_type == cirtree.CirType.relational_expression:2998 operator = cir_parent.get_operator()2999 if operator == base.COperator.greater_tn:3000 self.__generate_on_greater_tn__(cir_parent, error, error_dict)3001 elif operator == base.COperator.greater_eq:3002 self.__generate_on_greater_eq__(cir_parent, error, error_dict)3003 elif operator == base.COperator.smaller_tn:3004 self.__generate_on_smaller_tn__(cir_parent, error, error_dict)3005 elif operator == base.COperator.smaller_eq:3006 self.__generate_on_smaller_eq__(cir_parent, error, error_dict)3007 elif operator == base.COperator.not_equals:3008 self.__generate_on_not_equals__(cir_parent, error, error_dict)3009 elif operator == base.COperator.equal_with:3010 self.__generate_on_equal_with__(cir_parent, error, error_dict)3011 else:3012 pass3013 elif cir_parent.is_assign_statement() and cir_parent.get_child(1) == cir_location:3014 self.__generate_on_assignment__(cir_parent.get_child(0), error, error_dict)3015 elif cir_parent.cir_type == cirtree.CirType.if_statement or \3016 cir_parent.cir_type == cirtree.CirType.case_statement:3017 self.__translate_as_condition__(cir_parent.get_child(0), error, error_dict)3018 else:3019 pass3020 return error_dict30213022 def __propagate_iteration_inner_statement__(self, source: StateErrorNode):3023 """3024 :param source:3025 :return: target_nodes from source to generate in error propagation3026 """3027 # 1. collect all the error-dicts in each necessary error in source3028 target_error_dicts = dict()3029 for source_error in source.get_necessary_errors():3030 target_error_dict = self.__generate_inner_statement__(source_error)3031 for target_error, constraints in target_error_dict.items():3032 if target_error is not None:3033 target_error_dicts[target_error] = constraints3034 # 2. simplify errors until the representative ones3035 target_errors = source.get_error().get_error_set().representative_set(target_error_dicts.keys())3036 # 3. generate propagation from source to each of its target errors nodes3037 target_nodes = set()3038 for target_error in target_errors:3039 constraints = target_error_dicts[target_error]3040 target = self.graph.get_node_of(target_error)3041 if source != target:3042 source.propagate(target, constraints)3043 target_nodes.add(target)3044 return target_nodes30453046 def __propagate_recursive_inner_statement__(self, source: StateErrorNode, solutions: dict):3047 """3048 :param source:3049 :param solutions:3050 :return:3051 """3052 if source not in solutions:3053 targets = self.__propagate_iteration_inner_statement__(source)3054 solutions[source] = targets3055 for target in targets:3056 self.__propagate_recursive_inner_statement__(target, solutions)3057 return30583059 def __propagate_inner_statement__(self, source: StateErrorNode):3060 """3061 :param source:3062 :return: leafs from which the source error propagates3063 """3064 solutions, leafs = dict(), set()3065 self.__propagate_recursive_inner_statement__(source, solutions)3066 for node, target_nodes in solutions.items():3067 node: StateErrorNode3068 if len(target_nodes) == 0:3069 leafs.add(node)3070 return leafs30713072 # error propagation through statements: condition, data-flow {argument-parameter, return-wait, normal} and call-wait30733074 def __information_nodes_of__(self, cir_location: cirtree.CirNode):3075 """3076 :param cir_location:3077 :return: information nodes w.r.t. the location in cir-language3078 """3079 c_program = self.graph.get_program()3080 instance_graph = c_program.get_instance_graph()3081 code_instances = instance_graph.get_instances().get_instances_of_object(cir_location)3082 information_graph = c_program.get_information_graph()3083 information_nodes = set()3084 for code_instance in code_instances:3085 code_instance: cirinst.CirInstanceCode3086 if information_graph.has_node(code_instance):3087 information_node = information_graph.get_node(code_instance)3088 information_nodes.add(information_node)3089 return information_nodes30903091 def __propagate_on_condition__(self, source: StateErrorNode):3092 """3093 :param source:3094 :return: propagate from errors in conditional statement3095 """3096 # 1. collect the statements in true and false branch of condition3097 condition = source.get_error().get_cir_location()3098 information_nodes = self.__information_nodes_of__(condition)3099 true_branch, false_branch = set(), set()3100 for information_node in information_nodes:3101 for information_edge in information_node.get_ou_edges():3102 information_edge: cprog.CInformationEdge3103 target_instance = information_edge.get_target().get_instance()3104 if isinstance(target_instance, cirinst.CirInstanceNode):3105 target_statement = target_instance.get_source_statement()3106 else:3107 target_instance: cirinst.CirInstanceCode3108 target_statement = target_instance.get_cir_source_node()3109 if target_statement.is_statement() and not target_statement.is_tag_statement():3110 if information_edge.get_flow().get_flow_type() == cprog.CInformationFlowType.execute_in_true:3111 true_branch.add(target_statement)3112 elif information_edge.get_flow().get_flow_type() == cprog.CInformationFlowType.execute_in_false:3113 false_branch.add(target_statement)3114 # 2. generate the errors in next generation3115 errors, error_dict = self.graph.get_error_set(), dict()3116 for error in source.get_necessary_errors():3117 if error.error_type == mut.ErrorType.set_bool or error.error_type == mut.ErrorType.set_numb:3118 parameter = sym.sym_evaluator.__boolean__(error.get_operand(1))3119 if parameter:3120 for statement in true_branch:3121 next_error = errors.execute(statement)3122 error_dict[next_error] = mut.StateConstraints(True)3123 for statement in false_branch:3124 next_error = errors.not_execute(statement)3125 error_dict[next_error] = mut.StateConstraints(True)3126 else:3127 for statement in false_branch:3128 next_error = errors.execute(statement)3129 error_dict[next_error] = mut.StateConstraints(True)3130 for statement in true_branch:3131 next_error = errors.not_execute(statement)3132 error_dict[next_error] = mut.StateConstraints(True)3133 break3134 elif error.error_type == mut.ErrorType.set_addr:3135 parameter = sym.sym_evaluator.__memory__.int_address(str(error.get_operand(1)))3136 if parameter != 0:3137 for statement in true_branch:3138 next_error = errors.execute(statement)3139 error_dict[next_error] = mut.StateConstraints(True)3140 for statement in false_branch:3141 next_error = errors.not_execute(statement)3142 error_dict[next_error] = mut.StateConstraints(True)3143 else:3144 for statement in false_branch:3145 next_error = errors.execute(statement)3146 error_dict[next_error] = mut.StateConstraints(True)3147 for statement in true_branch:3148 next_error = errors.not_execute(statement)3149 error_dict[next_error] = mut.StateConstraints(True)3150 break3151 elif error.error_type == mut.ErrorType.chg_bool or error.error_type == mut.ErrorType.chg_numb or error.error_type == mut.ErrorType.chg_addr:3152 for statement in true_branch:3153 error_dict[errors.execute(statement)] = StateErrorBuilder.__boolean_constraint__(condition, False)3154 error_dict[errors.not_execute(statement)] = StateErrorBuilder.__boolean_constraint__(condition, True)3155 for statement in false_branch:3156 error_dict[errors.execute(statement)] = StateErrorBuilder.__boolean_constraint__(condition, True)3157 error_dict[errors.not_execute(statement)] = StateErrorBuilder.__boolean_constraint__(condition, False)3158 break3159 # 3. connect source to the target3160 target_nodes = set()3161 for target_error, constraints in error_dict.items():3162 target = self.graph.get_node_of(target_error)3163 source.propagate(target, constraints)3164 target_nodes.add(target)3165 return target_nodes31663167 def __path_constraints__(self, source: cirflow.CirExecution, target: cirflow.CirExecution):3168 """3169 TODO implement the algorithm!3170 :param source:3171 :param target:3172 :return:3173 """3174 constraints = mut.StateConstraints(True)3175 return constraints31763177 def __execution_of__(self, cir_location: cirtree.CirNode):3178 c_program = self.graph.get_program()3179 function_graph = c_program.get_function_call_graph()3180 c_func = function_graph.get_function_of(cir_location)3181 cir_statement = cir_location.statement_of()3182 if cir_statement is None:3183 return None3184 else:3185 return c_func.get_execution_flow_graph().get_execution_of(cir_statement)31863187 def __propagate_on_data_flow__(self, source: StateErrorNode):3188 """3189 :param source:3190 :return:3191 """3192 # 1. get the information flow from source3193 cir_location = source.get_error().get_cir_location()3194 information_nodes = self.__information_nodes_of__(cir_location)3195 use_expression_executions = dict()3196 for information_node in information_nodes:3197 for information_edge in information_node.get_ou_edges():3198 information_edge: cprog.CInformationEdge3199 if information_edge.get_flow().get_flow_type() == cprog.CInformationFlowType.du_assign:3200 target_instance = information_edge.get_target().get_instance()3201 target_instance: cirinst.CirInstanceCode3202 use_expression_executions[target_instance.get_cir_source_node()] = \3203 target_instance.get_instance_node().get_source_execution()3204 # 2. link the errors through data flow propagation3205 source_execution, target_constraints = self.__execution_of__(cir_location), dict()3206 for use_expression, target_execution in use_expression_executions.items():3207 constraints = self.__path_constraints__(source_execution, target_execution)3208 error_dict = dict()3209 self.__generate_on_assignment__(use_expression, source.get_error(), error_dict)3210 for target_error, _ in error_dict.items():3211 target = self.graph.get_node_of(target_error)3212 target_constraints[target] = constraints3213 # 3. generate the error propagation edges from source3214 target_nodes = set()3215 for target, constraints in target_constraints.items():3216 source.propagate(target, constraints)3217 target_nodes.add(target)3218 return target_nodes32193220 def __propagate_inter_statement__(self, source: StateErrorNode):3221 # 1. propagation through statements3222 cir_location = source.get_error().get_cir_location()3223 if cir_location is not None:3224 cir_parent = cir_location.get_parent()3225 if cir_parent is None:3226 target_nodes = set()3227 elif cir_parent.cir_type == cirtree.CirType.if_statement or \3228 cir_parent.cir_type == cirtree.CirType.case_statement:3229 target_nodes = self.__propagate_on_condition__(source)3230 elif cir_parent.is_assign_statement():3231 target_nodes = self.__propagate_on_data_flow__(source)3232 elif cir_parent.cir_type == cirtree.CirType.argument_list:3233 target_nodes = self.__propagate_on_data_flow__(source)3234 else:3235 target_nodes = set()3236 else:3237 target_nodes = set()3238 # 2. propagation within statement3239 targets = set()3240 for target in target_nodes:3241 target: StateErrorNode3242 next_targets = self.__propagate_inner_statement__(target)3243 for next_target in next_targets:3244 targets.add(next_target)3245 return targets32463247 def __propagate__(self, source: StateErrorNode, distance: int):3248 sources = self.__propagate_inner_statement__(source)3249 if distance > 0:3250 target_nodes = set()3251 for source in sources:3252 targets = self.__propagate_inter_statement__(source)3253 for target in targets:3254 target_nodes.add(target)3255 for target in target_nodes:3256 self.__propagate__(target, distance - 1)3257 return32583259 def generate_propagation(self, distance: int):3260 for source_edge in self.graph.get_faulty_node().get_ou_edges():3261 source_edge: StateErrorEdge3262 source = source_edge.get_target()3263 self.__propagate__(source, distance)3264 return326532663267if __name__ == "__main__":3268 prefix = "C:\\Users\\yukimula\\git\\jcsa\\JCMuta\\results\\data"3269 postfix = "C:\\Users\\yukimula\\git\\jcsa\\PyMuta\\output\\error_graphs"3270 propagation_distance, code_length = 2, 643271 print("Testing start from...")3272 for filename in os.listdir(prefix):3273 directory = os.path.join(prefix, filename)3274 program = cprog.CProgram(directory)3275 mutant_space = mut.MutantSpace(program)3276 print("\tStart to proceed", len(mutant_space.mutants), "mutants in", filename)3277 output_directory = os.path.join(postfix, filename)3278 if not os.path.exists(output_directory):3279 os.mkdir(output_directory)3280 total, pass_number = 0, 03281 for mutant in mutant_space.get_mutants():3282 if mutant.get_features() is not None:3283 # print("\t\t==> Proceed mutant", mutant.get_id())3284 state_error_graph = StateErrorGraph(mutant.get_features(), propagation_distance)3285 output_file = os.path.join(output_directory, filename + "." + str(mutant.id))3286 try:3287 state_error_graph.write_dot_graph(output_file, max_code_length=code_length)3288 pdf_file = os.path.join(output_directory, filename + "." + str(mutant.id) + ".pdf")3289 while not os.path.exists(pdf_file):3290 pass3291 pass_number += 13292 except graphviz.backend.CalledProcessError:3293 print("\t\t==> @Failed-For-Mutant-", mutant.id)3294 finally:3295 os.remove(output_file)3296 total += 13297 print("\tPass-Rate: ", pass_number, "/", total, "for", filename)3298 print()
...
MachineLearning_project1.py
Source:MachineLearning_project1.py
1# -*- coding: utf-8 -*-2"""3Created on Mon Oct 17 11:02:09 20164@author: Xiya Lv5"""6import math7import numpy as np8import matplotlib.pyplot as plt9import random10DataMaxSize = 10 #æ°æ®ä¸ªæ°11ORDER = 9 #æé«ç»´æ°12alpha = 0.03 #æ¥é¿13e=0.000001 #精度14lamda = 0.115def func_(x):16 """17 å½æ°ï¼sinï¼0.4*pi*xï¼18 """19 return sin(0.4*pi*x)20 21def CostFunction(Y,my_Y):22 loss = 023 for i in range(len(Y)):24 loss+=pow((my_Y[i]-Y[i]),2)25 26 loss = 0.5*loss*1.0/DataMaxSize27 return loss28def CostFunctionReg(Y,my_Y,B):29 loss = 030 b_ = array(B).reshape(1,ORDER+1)[0]31 for i in range(len(Y)):32 loss+=pow((my_Y[i]-Y[i]),2)33 for j in b_:34 loss+=lamda*j*j35 loss = 0.5*loss*1.0/DataMaxSize36 return loss37 38def CreatData():39 """40 1.åè½ï¼çææ°æ®ï¼å¹¶å å
¥åªå£°41 2.å®ä¹åï¼-2.5ï¼+2.5ï¼42 3.éç¨å½æ°ï¼func_(x)43 """ 44 RandNumberX = arange(-2.5,2.5,5.0/DataMaxSize)45 RandNumberY=[]46 for x in RandNumberX:47 #RandNumberY.append(func_(x)+random.lognormvariate(0, 1)) #æ£æåå¸48 RandNumberY.append(func_(x)+ uniform(-0.2, 0.2))49 return RandNumberX,RandNumberY50 51def TheLeastSquareMethod(X,Y):52 """53 æå°äºä¹æ³54 """55 '''56 regulation=[]57 r=[]58 for i in range(ORDER+1):59 r.append(0)60 regulation.append(r)61 for i in range(1,ORDER+1):62 r=[]63 for j in range(0, ORDER+1):64 if i==j:65 r.append(1)66 else:67 r.append(0)68 regulation.append(r)69 regula = mat(regulation)70 '''71 regula = eye(ORDER+1)72 X_matrix=[] 73 for i in range(ORDER+1): 74 X_matrix.append(X**i) 75 X_matrix = mat(X_matrix).T76 Y_matrix = array(Y).reshape((len(Y),1)) 77 78 X_matrix_T = X_matrix.T79 #print dot(X_matrix_T,X_matrix)80 B = dot(dot(dot(X_matrix_T,X_matrix).I,X_matrix_T),Y_matrix)81 B1 = dot(dot( (dot(X_matrix_T,X_matrix)+lamda*regula).I,X_matrix_T),Y_matrix)82 result = dot(X_matrix,B)83 result_reg = dot(X_matrix,B1)84 return X_matrix,Y_matrix,B,result,result_reg85def SumMy_Y_Y(my_Y,Y,X,j):86 total=0.087 for i in range(0,len(Y)):88 total += ((my_Y[i]-Y[i])*X[i][j])89 return total 90 91def SumMy_Y_Y_REGULATION(my_Y,Y,X,j,thata):92 total=0.093 if j==0:94 for i in range(0,len(Y)):95 total += (((my_Y[i]-Y[i])*X[i][j]))96 return total97 for i in range(0,len(Y)):98 total += (((my_Y[i]-Y[i])*X[i][j])+lamda/DataMaxSize*thata[j])99 return total 100def BatchGradientDescentReg(my_Y,Y,X_mat,thata):101 """102 æ¹é梯度ä¸é(å æ©ç½é¡¹)103 """ 104 my_copy=[]105 for i in my_Y:106 my_copy.append(i)107 108 error = CostFunctionReg(Y,my_copy,thata)109 X = array(X_mat)110 111 while(1):112 new_thata = []113 for i in range(0,len(thata)):114 #temp = SumMy_Y_Y(my_copy,Y,X, i)115 temp = SumMy_Y_Y_REGULATION(my_copy,Y,X, i,thata)116 flag = thata[i] - alpha*temp/DataMaxSize117 new_thata.append(flag)118 119 thata = new_thata120 121 my_copy = array(dot(X_mat,array(new_thata).reshape(len(thata),1)).reshape(1,len(Y)))[0]122 new_error = CostFunctionReg(Y,my_copy,thata) 123 #print abs(new_error -error)124 if abs(new_error -error) <=e:125 break126 127 error = new_error128 return my_copy129def BatchGradientDescent(my_Y,Y,X_mat,thata):130 """131 æ¹é梯度ä¸é(æªå æ©ç½é¡¹)132 """ 133 my_copy=[]134 for i in my_Y:135 my_copy.append(i)136 137 error = CostFunction(Y,my_copy)138 X = array(X_mat)139 140 while(1):141 new_thata = []142 for i in range(0,len(thata)):143 #temp = SumMy_Y_Y(my_copy,Y,X, i)144 temp = SumMy_Y_Y(my_copy,Y,X, i)145 flag = thata[i] - alpha*temp/DataMaxSize146 new_thata.append(flag)147 148 thata = new_thata149 150 my_copy = array(dot(X_mat,array(new_thata).reshape(len(thata),1)).reshape(1,len(Y)))[0]151 new_error = CostFunction(Y,my_copy) 152 #print abs(new_error -error)153 if abs(new_error -error) <=e:154 break155 156 error = new_error157 return my_copy158def bicgstab(X,Y,my_Y,B):159 '''160 #稳å®åå
±è½æ¢¯åº¦ä¸é161 '''162 my_Y_copy=[]163 for i in my_Y:164 my_Y_copy.append(i)165 166 error = CostFunction(Y,my_Y_copy)167 168 R0star = Y - dot(X,B)169 R0 = Y - dot(X,B)170 rho0 = 1171 alp0 = 1172 w0 = 1173 V0 =mat(zeros(len(Y)).reshape(len(Y),1))174 P0 = mat(zeros(len(Y)).reshape(len(Y),1))175 #print R0176 while 1:177 rho1 = array(dot(R0star.T, R0))[0][0]178 beta = (rho1/rho0) * (alp0/w0)179 P1 = R0 + beta*(P0 - w0*V0)180 181 V1 = dot(X,P1)182 alp0 = rho1/(array(dot(R0star.T,V1))[0][0])183 h = B + alp0 * P1184 my_Y_copy = array(dot(X,array(h).reshape(len(h),1)).reshape(1,len(Y)))[0]185 new_error = CostFunction(Y,my_Y_copy) 186 if abs(new_error -error) <=e:187 break188 error = new_error189 S = R0 - alp0*V1190 191 t = dot(X,S)192 w1 = array(dot(t.T, S))[0][0]/array(dot(t.T, t))[0][0]193 B = h + w1*S194 my_Y_copy = array(dot(X,array(B).reshape(len(B),1)).reshape(1,len(Y)))[0]195 new_error = CostFunction(Y,my_Y_copy) 196 if abs(new_error -error) <=e:197 break198 R0 = S - w1 * t199 rho0 = rho1200 P0 = P1201 V0 =V1202 w0 = w1203 error = new_error 204 return dot(X,B)205def bicgstabReg(X,Y,my_Y,B):206 '''207 #稳å®åå
±è½æ¢¯åº¦ä¸é208 '''209 my_Y_copy=[]210 for i in my_Y:211 my_Y_copy.append(i)212 213 error = CostFunctionReg(Y,my_Y_copy,B)214 215 R0star = Y - dot(X,B)216 R0 = Y - dot(X,B)217 rho0 = 1218 alp0 = 1219 w0 = 1220 V0 =mat(zeros(len(Y)).reshape(len(Y),1))221 P0 = mat(zeros(len(Y)).reshape(len(Y),1))222 #print R0223 while 1:224 rho1 = array(dot(R0star.T, R0))[0][0]225 beta = (rho1/rho0) * (alp0/w0)226 P1 = R0 + beta*(P0 - w0*V0)227 228 V1 = dot(X,P1)229 alp0 = rho1/(array(dot(R0star.T,V1))[0][0])230 h = B + alp0 * P1231 my_Y_copy = array(dot(X,array(h).reshape(len(h),1)).reshape(1,len(Y)))[0]232 new_error = CostFunction(Y,my_Y_copy) 233 if abs(new_error -error) <=e:234 break235 #error = new_error236 S = R0 - alp0*V1237 238 t = dot(X,S)239 w1 = array(dot(t.T, S))[0][0]/array(dot(t.T, t))[0][0]240 B = h + w1*S241 my_Y_copy = array(dot(X,array(B).reshape(len(B),1)).reshape(1,len(Y)))[0]242 new_error = CostFunctionReg(Y,my_Y_copy,B) 243 # print abs(new_error -error)244 if abs(new_error -error) <=e:245 break246 R0 = S - w1 * t247 rho0 = rho1248 P0 = P1249 V0 =V1250 w0 = w1251 error = new_error 252 return dot(X,B)253 254if __name__=="__main__":255 X,Y = CreatData()256 ###############################################################################257 '''258 æå°äºä¹æ³259 '''260 X_matrix, Y_matrix, B,Y_tlsm,Y_tlsm_reg = TheLeastSquareMethod(X,Y)261 #æå°äºä¹æ³æ±å¾çåå½æ²çº¿,ç©éµè¡¨ç¤º262 263 my_Y = array(Y_tlsm.reshape(1,len(Y)))[0]264 loss_tlsm = CostFunction(Y,my_Y)# æ¹åæ ¹è¯¯å·®265 266 #################################################################################267 268 ################################################################################269 '''270 #æ¹é梯度ä¸é271 #åå§çç³»æ°ç©éµåBï¼å³thataï¼272 ''' 273 X_lemad = X/2.5 #ç¹å¾æ¶ç¼© 274 X_mat_=[] 275 for i in range(ORDER+1): 276 X_mat_.append(X_lemad**i) 277 X_mat_ = mat(X_mat_).T 278 #thata = array(B.reshape(1,len(B)))[0] +uniform(0,0.1)279 thata0 = B+uniform(0,0.1)280 thata1 = mat([1,1])281 thata1 = thata0282 #####################283 #thata = []284 #for i in range(10):285 # thata.append(uniform(-1,1))286 ####################287 288 my_Y = array(dot(X_matrix,thata0).reshape(1,len(Y)))[0]289 290 thata = array(thata0.reshape(1,len(B)))[0]291 Y_bgd = BatchGradientDescent(my_Y,Y,X_mat_,thata)292 293 thata = array(thata0.reshape(1,len(B)))[0]294 Y_bgd_reg = BatchGradientDescentReg(my_Y,Y,X_mat_,thata)295 ###################################################################################296 297 ######################################################################################################3298 '''299 #åå
±è½æ¢¯åº¦æ³(BCIG)300 '''301 #thata = array(B.reshape(1,len(B)))[0] 302 if(DataMaxSize==ORDER+1):303 Y_temp = array(Y).reshape(DataMaxSize,1)304 Y_bcig = bicgstab(X_matrix,Y_temp,my_Y,thata0)305 Y_bcig_reg = bicgstabReg(X_matrix,Y_temp,my_Y,thata1)306 ######################################################################################3######307 '''308 ç»å¾æ¾ç¤º309 '''310 plt.figure("MachineLearningProjectOne")311 plt.title("polynomial fit curve in 3 ways")312 plt.xlabel('x axis')# make axis labels313 plt.ylabel('y axis')314 plt.plot(X,Y,'or',label="$origional data$")315 plt.plot(X,Y_tlsm,'r',label = "$LS$")#红è²ç为æå°äºä¹æ³æ±å¾çåå½æ²çº¿316 plt.plot(X,Y_tlsm_reg,'r--',label = "$LS-REG$")#红è²ç为æå°äºä¹æ³æ±å¾çåå½æ²çº¿317 plt.plot(X,Y_bgd,'b',label = '$BGD$')#èè²ä¸ºæ¢¯åº¦ä¸éææ±çåå½æ²çº¿ 318 plt.plot(X,Y_bgd_reg,'b--',label = '$BGD-REG$')#èè²ä¸ºæ¢¯åº¦ä¸éææ±çåå½æ²çº¿ 319 if(DataMaxSize==ORDER+1):320 plt.plot(X,Y_bcig,'y--',label = '$BCIG$')#绿è²ä¸ºç¨³å®åå
±è½æ¢¯åº¦ææ±çåå½æ²çº¿321 plt.plot(X,Y_bcig_reg,color='y',label = '$BCIG-REG$')#绿è²ä¸ºç¨³å®åå
±è½æ¢¯åº¦ææ±çåå½æ²çº¿322 plt.legend(loc=4)# make legend323 plt.show()...
suite.py
Source:suite.py
...11# ############################################################################ #12import config13from test import Test14def suite():15 Test.new_error([])16 Test.new_error(["a", "a", "a", "a"])17 Test.new_error(["aaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "a", "a", "a"])18 Test.new_error(["10"])19 Test.new_error(["10", "10"])20 Test.new_error(["10", "10", "10"])21 Test.new_error(["10", "10", "10", "10", "10", "10"])22 Test.new_error(["-1", "10", "10", "10"])23 Test.new_error(["10", "-1", "10", "10"])24 Test.new_error(["10", "10", "-1", "10"])25 Test.new_error(["10", "10", "10", "-1"])26 Test.new_error(["10", "10", "10", "10", "-1"])27 Test.new_error([str(config.UINT_MAX + 1), "10", "10", "10"])28 Test.new_error(["10", str(config.UINT_MAX + 1), "10", "10"])29 Test.new_error(["10", "10", str(config.UINT_MAX + 1), "10"])30 Test.new_error(["10", "10", "10", str(config.UINT_MAX + 1)])31 Test.new_error(["10", "10", "10", "10", str(config.UINT_MAX + 1)])32 Test.new_error([str(-config.UINT_MAX), "10", "10", "10"])33 Test.new_error(["10", str(-config.UINT_MAX), "10", "10"])34 Test.new_error(["10", "10", str(-config.UINT_MAX), "10"])35 Test.new_error(["10", "10", "10", str(-config.UINT_MAX)])36 Test.new_error(["10", "10", "10", "10", str(-config.UINT_MAX)])37 Test(0, 120, 60, 60)38 Test(1, 120, 60, 60)39 Test(2, 120, 60, 60)40 Test(3, 120, 60, 60)41 Test(4, 120, 60, 60)42 Test(5, 120, 60, 60)43 Test(6, 120, 60, 60)44 Test(7, 120, 60, 60)45 Test(5, 800, 200, 200)46 Test(5, 800, 200, 200, 7)47 Test(4, 410, 200, 200)48 Test(4, 310, 200, 100)49 # Test(100, 100, 50, 50)50 #...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!