@ -51,7 +51,10 @@ let tests =
let pp_node_list fmt l = F . pp_print_list ~ pp_sep Procdesc . Node . pp fmt l in
let pp_node_list fmt l = F . pp_print_list ~ pp_sep Procdesc . Node . pp fmt l in
F . fprintf fmt " Expected output %a but got %a " pp_node_list expected pp_node_list actual
F . fprintf fmt " Expected output %a but got %a " pp_node_list expected pp_node_list actual
in
in
let create_test input expected _ = assert_equal ~ cmp ~ pp_diff input expected in
let create_test ~ fold input expected _ =
let input = Container . to_list input ~ fold in
assert_equal ~ cmp ~ pp_diff input expected
in
let instr_test =
let instr_test =
let instr_test_ _ =
let instr_test_ _ =
( match ProcCfg . Normal . instrs n1 with
( match ProcCfg . Normal . instrs n1 with
@ -83,66 +86,70 @@ let tests =
let n1'' = BackwardInstrCfg . underlying_node backward_instr_n1 in
let n1'' = BackwardInstrCfg . underlying_node backward_instr_n1 in
assert_bool " underlying_node should return node of underlying CFG type " ( phys_equal n1 n1'' ) ;
assert_bool " underlying_node should return node of underlying CFG type " ( phys_equal n1 n1'' ) ;
(* test the preds/succs using backward + instr cfg *)
(* test the preds/succs using backward + instr cfg *)
let check_backward_instr_ f backward_instr_node expected_instrs =
let check_backward_instr_ f old backward_instr_node expected_instrs =
match f backward_instr_proc_cfg backward_instr_node with
match Container . to_list ~ f old: ( fold backward_instr_proc_cfg ) backward_instr_node with
| [ n ] ->
| [ n ] ->
assert_equal ( BackwardInstrCfg . instrs n ) expected_instrs
assert_equal ( BackwardInstrCfg . instrs n ) expected_instrs
| _ ->
| _ ->
assert_failure " Expected exactly one node "
assert_failure " Expected exactly one node "
in
in
check_backward_instr_ BackwardInstrCfg . preds backward_instr_n1 [ dummy_instr2 ] ;
check_backward_instr_ BackwardInstrCfg . fold_ preds backward_instr_n1 [ dummy_instr2 ] ;
let backward_instr_n2 = BackwardInstrCfg . of_underlying_node n2 in
let backward_instr_n2 = BackwardInstrCfg . of_underlying_node n2 in
check_backward_instr_ BackwardInstrCfg . preds backward_instr_n2 [] ;
check_backward_instr_ BackwardInstrCfg . fold_ preds backward_instr_n2 [] ;
let backward_instr_n3 = BackwardInstrCfg . of_underlying_node n3 in
let backward_instr_n3 = BackwardInstrCfg . of_underlying_node n3 in
check_backward_instr_ BackwardInstrCfg . preds backward_instr_n3 [] ;
check_backward_instr_ BackwardInstrCfg . fold_ preds backward_instr_n3 [] ;
check_backward_instr_ BackwardInstrCfg . normal_succs backward_instr_n2 [ dummy_instr2 ]
check_backward_instr_ BackwardInstrCfg . fold_ normal_succs backward_instr_n2 [ dummy_instr2 ]
in
in
" instr_test " > :: instr_test_
" instr_test " > :: instr_test_
in
in
let graph_tests =
let graph_tests =
[ (* test the succs of the normal cfg. forward... *)
[ (* test the succs of the normal cfg. forward... *)
( " succs_n1 " , ProcCfg . Normal . succs normal_proc_cfg n1 , [ n2 ] )
( " succs_n1 " , ProcCfg . Normal . fold_ succs normal_proc_cfg , n1 , [ n2 ] )
; ( " normal_succs_n1 " , ProcCfg . Normal . normal_succs normal_proc_cfg n1 , [ n2 ] )
; ( " normal_succs_n1 " , ProcCfg . Normal . fold_ normal_succs normal_proc_cfg , n1 , [ n2 ] )
; ( " succs_n2 " , ProcCfg . Normal . succs normal_proc_cfg n2 , [ n4 ] )
; ( " succs_n2 " , ProcCfg . Normal . fold_ succs normal_proc_cfg , n2 , [ n4 ] )
; ( " normal_succs_n2 " , ProcCfg . Normal . normal_succs normal_proc_cfg n2 , [ n4 ] )
; ( " normal_succs_n2 " , ProcCfg . Normal . fold_ normal_succs normal_proc_cfg , n2 , [ n4 ] )
; ( " succs_n3 " , ProcCfg . Normal . succs normal_proc_cfg n3 , [ n4 ] )
; ( " succs_n3 " , ProcCfg . Normal . fold_ succs normal_proc_cfg , n3 , [ n4 ] )
; ( " normal_succs_n3 " , ProcCfg . Normal . normal_succs normal_proc_cfg n3 , [ n4 ] )
; ( " normal_succs_n3 " , ProcCfg . Normal . fold_ normal_succs normal_proc_cfg , n3 , [ n4 ] )
; (* ... and backward... *)
; (* ... and backward... *)
( " succs_n1_bw " , BackwardCfg . preds backward_proc_cfg n1 , [ n2 ] )
( " succs_n1_bw " , BackwardCfg . fold_ preds backward_proc_cfg , n1 , [ n2 ] )
; ( " normal_succs_n1_bw " , BackwardCfg . normal_preds backward_proc_cfg n1 , [ n2 ] )
; ( " normal_succs_n1_bw " , BackwardCfg . fold_ normal_preds backward_proc_cfg , n1 , [ n2 ] )
; ( " succs_n2_bw " , BackwardCfg . preds backward_proc_cfg n2 , [ n4 ] )
; ( " succs_n2_bw " , BackwardCfg . fold_ preds backward_proc_cfg , n2 , [ n4 ] )
; ( " normal_succs_n2_bw " , BackwardCfg . normal_preds backward_proc_cfg n2 , [ n4 ] )
; ( " normal_succs_n2_bw " , BackwardCfg . fold_ normal_preds backward_proc_cfg , n2 , [ n4 ] )
; ( " succs_n3_bw " , BackwardCfg . preds backward_proc_cfg n3 , [ n4 ] )
; ( " succs_n3_bw " , BackwardCfg . fold_ preds backward_proc_cfg , n3 , [ n4 ] )
; ( " normal_succs_n3_bw " , BackwardCfg . normal_preds backward_proc_cfg n3 , [ n4 ] )
; ( " normal_succs_n3_bw " , BackwardCfg . fold_ normal_preds backward_proc_cfg , n3 , [ n4 ] )
; (* test the preds of the normal cfg... *)
; (* test the preds of the normal cfg... *)
( " preds_n2 " , ProcCfg . Normal . normal_preds normal_proc_cfg n2 , [ n1 ] )
( " preds_n2 " , ProcCfg . Normal . fold_ normal_preds normal_proc_cfg , n2 , [ n1 ] )
; ( " normal_preds_n2 " , ProcCfg . Normal . normal_preds normal_proc_cfg n2 , [ n1 ] )
; ( " normal_preds_n2 " , ProcCfg . Normal . fold_ normal_preds normal_proc_cfg , n2 , [ n1 ] )
; (* ...and the backward cfg... *)
; (* ...and the backward cfg... *)
( " preds_n2_bw " , BackwardCfg . normal_succs backward_proc_cfg n2 , [ n1 ] )
( " preds_n2_bw " , BackwardCfg . fold_ normal_succs backward_proc_cfg , n2 , [ n1 ] )
; ( " normal_preds_n2_bw " , BackwardCfg . normal_succs backward_proc_cfg n2 , [ n1 ] )
; ( " normal_preds_n2_bw " , BackwardCfg . fold_ normal_succs backward_proc_cfg , n2 , [ n1 ] )
; (* we shouldn't see any exn succs or preds even though we added them *)
; (* we shouldn't see any exn succs or preds even though we added them *)
( " no_exn_succs_n1 " , ProcCfg . Normal . exceptional_succs normal_proc_cfg n1 , [] )
( " no_exn_succs_n1 " , ProcCfg . Normal . fold_ exceptional_succs normal_proc_cfg , n1 , [] )
; ( " no_exn_preds_n3 " , ProcCfg . Normal . exceptional_preds normal_proc_cfg n3 , [] )
; ( " no_exn_preds_n3 " , ProcCfg . Normal . fold_ exceptional_preds normal_proc_cfg , n3 , [] )
; (* same in the backward cfg *)
; (* same in the backward cfg *)
( " no_exn_succs_n1_bw " , BackwardCfg . exceptional_preds backward_proc_cfg n1 , [] )
( " no_exn_succs_n1_bw " , BackwardCfg . fold_ exceptional_preds backward_proc_cfg , n1 , [] )
; ( " no_exn_preds_n3_bw " , BackwardCfg . exceptional_succs backward_proc_cfg n3 , [] )
; ( " no_exn_preds_n3_bw " , BackwardCfg . fold_ exceptional_succs backward_proc_cfg , n3 , [] )
; (* now, test the exceptional succs in the exceptional cfg. *)
; (* now, test the exceptional succs in the exceptional cfg. *)
( " exn_succs_n1 " , ProcCfg . Exceptional . exceptional_succs exceptional_proc_cfg n1 , [ n3 ] )
( " exn_succs_n1 " , ProcCfg . Exceptional . fold_ exceptional_succs exceptional_proc_cfg , n1 , [ n3 ] )
; ( " exn_succs_n2 " , ProcCfg . Exceptional . exceptional_succs exceptional_proc_cfg n2 , [ n3 ] )
; ( " exn_succs_n2 " , ProcCfg . Exceptional . fold_ exceptional_succs exceptional_proc_cfg , n2 , [ n3 ] )
; ( " exn_succs_n3 " , ProcCfg . Exceptional . exceptional_succs exceptional_proc_cfg n3 , [ n4 ] )
; ( " exn_succs_n3 " , ProcCfg . Exceptional . fold_ exceptional_succs exceptional_proc_cfg , n3 , [ n4 ] )
; (* test exceptional pred links *)
; (* test exceptional pred links *)
( " exn_preds_n3 " , ProcCfg . Exceptional . exceptional_preds exceptional_proc_cfg n3 , [ n2 ; n1 ] )
( " exn_preds_n3 "
, ProcCfg . Exceptional . fold_exceptional_preds exceptional_proc_cfg
, n3
, [ n2 ; n1 ] )
; (* succs should return both normal and exceptional successors *)
; (* succs should return both normal and exceptional successors *)
( " exn_all_succs_n1 " , ProcCfg . Exceptional . succs exceptional_proc_cfg n1 , [ n3 ; n2 ] )
( " exn_all_succs_n1 " , ProcCfg . Exceptional . fold_ succs exceptional_proc_cfg , n1 , [ n3 ; n2 ] )
; (* but, should not return duplicates *)
; (* but, should not return duplicates *)
( " exn_all_succs_n3 " , ProcCfg . Exceptional . succs exceptional_proc_cfg n3 , [ n4 ] )
( " exn_all_succs_n3 " , ProcCfg . Exceptional . fold_ succs exceptional_proc_cfg , n3 , [ n4 ] )
; (* similarly, preds should return both normal and exceptional predecessors *)
; (* similarly, preds should return both normal and exceptional predecessors *)
( " exn_all_preds_n3 " , ProcCfg . Exceptional . preds exceptional_proc_cfg n3 , [ n2 ; n1 ] )
( " exn_all_preds_n3 " , ProcCfg . Exceptional . fold_ preds exceptional_proc_cfg , n3 , [ n2 ; n1 ] )
; ( " exn_all_preds_n4 " , ProcCfg . Exceptional . preds exceptional_proc_cfg n4 , [ n3 ; n2 ] )
; ( " exn_all_preds_n4 " , ProcCfg . Exceptional . fold_ preds exceptional_proc_cfg , n4 , [ n3 ; n2 ] )
; (* finally, normal_succs/normal_preds shouldn't return exceptional edges *)
; (* finally, normal_succs/normal_preds shouldn't return exceptional edges *)
( " exn_normal_succs_n1 " , ProcCfg . Exceptional . normal_succs exceptional_proc_cfg n1 , [ n2 ] )
( " exn_normal_succs_n1 " , ProcCfg . Exceptional . fold_normal_succs exceptional_proc_cfg , n1 , [ n2 ] )
; ( " exn_normal_preds_n2 " , ProcCfg . Exceptional . normal_preds exceptional_proc_cfg n2 , [ n1 ] ) ]
; ( " exn_normal_preds_n2 " , ProcCfg . Exceptional . fold_normal_preds exceptional_proc_cfg , n2 , [ n1 ] )
| > List . map ~ f : ( fun ( name , test , expected ) -> name > :: create_test test expected )
]
| > List . map ~ f : ( fun ( name , fold , input , expected ) -> name > :: create_test ~ fold input expected )
in
in
let tests = instr_test :: graph_tests in
let tests = instr_test :: graph_tests in
" procCfgSuite " > :: : tests
" procCfgSuite " > :: : tests