Skip to content

Commit

Permalink
commit content:
Browse files Browse the repository at this point in the history
- added parameterizable utilities to generate multitrace mutants of three kinds:
  + swap actions within component of a multitrace
  + swap entire components between two multitraces
  + add random noise in multitrace (randomly generated actions that match the co-localization of the component on which it is inserted)
  • Loading branch information
erwanM974 committed Nov 3, 2022
1 parent e9ec2bd commit ff47b7b
Show file tree
Hide file tree
Showing 15 changed files with 696 additions and 143 deletions.
24 changes: 24 additions & 0 deletions src/input/htf/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ limitations under the License.




use std::fs;
use std::path::Path;

Expand Down Expand Up @@ -50,3 +51,26 @@ pub fn parse_htf_file(gen_ctx : &GeneralContext,




use std::collections::HashSet;
use crate::core::execution::trace::trace::TraceAction;

#[allow(unused_imports)]
use crate::pest::Parser;
#[allow(unused_imports)]
use crate::input::htf::parser::{HtfParser,Rule};
use crate::input::htf::trace::trace_element_from_pair;


pub fn multi_action_from_text(gen_ctx : &GeneralContext,
multiact_str : &String) -> Result<HashSet<TraceAction>,HibouParsingError> {
match HtfParser::parse(Rule::TRACE_SEQUENCE_elt, multiact_str) {
Err(e) => {
return Err( HibouParsingError::MatchError(e.to_string()) );
},
Ok( ref mut content ) => {
let trace_elt_pair = content.next().unwrap();
return trace_element_from_pair(gen_ctx,trace_elt_pair,&hashset!{},&mut hashset!{}, true);
}
}
}
83 changes: 57 additions & 26 deletions src/input/htf/trace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ limitations under the License.
use std::collections::HashSet;

use pest::iterators::Pair;
use crate::core::execution::trace::multitrace::Trace;


use crate::core::general_context::GeneralContext;
use crate::core::execution::trace::trace::*;
use crate::core::execution::trace::multitrace::Trace;
use crate::core::execution::trace::trace::{TraceAction, TraceActionKind};
use crate::input::error::HibouParsingError;


Expand All @@ -36,35 +37,65 @@ pub fn trace_sequence_from_pair(gen_ctx : &GeneralContext,
unavailable_lifelines : &HashSet<usize>,
lifelines : &mut HashSet<usize>,
add_lfs : bool) -> Result<Trace,HibouParsingError> {
let mut trace : Vec<HashSet<TraceAction>> = vec![];
for trace_sequence_elt_pair in trace_sequence_pair.into_inner() {
match trace_sequence_elt_pair.as_rule() {
Rule::TRACE_ACTION => {
match get_trace_action(gen_ctx,trace_sequence_elt_pair,unavailable_lifelines,lifelines,add_lfs) {
Err(e) => {return Err(e);},
Ok( action ) => {
trace.push( hashset!{action} );
}
let mut trace : Trace = vec![];
for trace_elt_pair in trace_sequence_pair.into_inner() {
match trace_element_from_pair(gen_ctx,trace_elt_pair,unavailable_lifelines,lifelines,add_lfs) {
Err(e) => {
return Err(e);
}
Ok(trace_elt) => {
trace.push(trace_elt);
}
}
}
return Ok( trace );
}


pub fn trace_element_from_pair(gen_ctx : &GeneralContext,
trace_elt_pair : Pair<Rule>,
unavailable_lifelines : &HashSet<usize>,
lifelines : &mut HashSet<usize>,
add_lfs : bool) -> Result<HashSet<TraceAction>,HibouParsingError> {
match trace_elt_pair.as_rule() {
Rule::TRACE_ACTION => {
match get_trace_action(gen_ctx,trace_elt_pair,unavailable_lifelines,lifelines,add_lfs) {
Err(e) => {return Err(e);},
Ok( action ) => {
return Ok(hashset!{action});
}
},
Rule::TRACE_ACTION_SET => {
let mut multi_action = hashset!{};
for action_pair in trace_sequence_elt_pair.into_inner() {
match get_trace_action(gen_ctx,action_pair,unavailable_lifelines,lifelines,add_lfs) {
Err(e) => {return Err(e);},
Ok( action ) => {
multi_action.insert(action);
}
}
}
},
Rule::TRACE_ACTION_SET => {
match get_trace_multi_action(gen_ctx,trace_elt_pair,unavailable_lifelines,lifelines,add_lfs) {
Err(e) => {return Err(e);},
Ok( multi_action ) => {
return Ok(multi_action);
}
trace.push( multi_action );
},
_ => {
panic!("what rule then ? : {:?}", trace_sequence_elt_pair.as_rule() );
}
},
_ => {
panic!("what rule then ? : {:?}", trace_elt_pair.as_rule() );
}
}
return Ok( trace );
}


fn get_trace_multi_action(gen_ctx : &GeneralContext,
multi_act_pair : Pair<Rule>,
unavailable_lifelines : &HashSet<usize>,
lifelines : &mut HashSet<usize>,
add_lfs : bool) -> Result<HashSet<TraceAction>,HibouParsingError> {
let mut multi_action = hashset!{};
for action_pair in multi_act_pair.into_inner() {
match get_trace_action(gen_ctx,action_pair,unavailable_lifelines,lifelines,add_lfs) {
Err(e) => {return Err(e);},
Ok( action ) => {
multi_action.insert(action);
}
}
}
return Ok(multi_action);
}

fn get_trace_action(gen_ctx : &GeneralContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ pub fn multi_trace_as_text(gen_ctx : &GeneralContext,
for actions in canal_trace {
trace_text_elements.push( trace_actions_as_text(gen_ctx, actions) );
}
canal_string.push_str(&format!( " {:};\n", trace_text_elements.join(".")) );
canal_string.push_str(&trace_text_elements.join(".") );
// ***
canals_strings.push(canal_string);
}
Expand Down
104 changes: 0 additions & 104 deletions src/trace_manip/mutate/insert_actions.rs

This file was deleted.

Loading

0 comments on commit ff47b7b

Please sign in to comment.