diff --git a/infer/bin/inferlib.py b/infer/bin/inferlib.py index 2ef17e3b0..be9a81b78 100644 --- a/infer/bin/inferlib.py +++ b/infer/bin/inferlib.py @@ -108,6 +108,10 @@ base_group.add_argument('--fail-on-bug', action='store_true', something to report''' % BUG_FOUND_ERROR_CODE) +base_group.add_argument('--android-harness', action='store_true', + help='''[experimental] Create harness to detect bugs + involving the Android lifecycle''') + base_group.add_argument('-l', '--llvm', action='store_true', help='''[experimental] Analyze C or C++ file using the experimental LLVM frontend''') @@ -460,6 +464,8 @@ class Infer: infer_cmd.append('-debug') if self.args.analyzer == TRACING: infer_cmd.append('-tracing') + if self.args.android_harness: + infer_cmd.append('-harness') return run_command( infer_cmd, diff --git a/infer/src/java/jConfig.ml b/infer/src/java/jConfig.ml index a58bca4e6..9b3293aab 100644 --- a/infer/src/java/jConfig.ml +++ b/infer/src/java/jConfig.ml @@ -141,4 +141,4 @@ let normalize_string s = let translate_checks = ref false (* Generate harness for Android code *) -let create_harness = true +let create_harness = ref false diff --git a/infer/src/java/jMain.ml b/infer/src/java/jMain.ml index 04a4e24d0..cb6223308 100644 --- a/infer/src/java/jMain.ml +++ b/infer/src/java/jMain.ml @@ -24,6 +24,8 @@ let arg_desc = "-no-static_final", Arg.Unit (fun () -> JTrans.no_static_final := true), None, "no special treatment for static final fields"; "-tracing", Arg.Unit (fun () -> JConfig.translate_checks := true), None, "Translate JVM checks"; + "-harness", Arg.Unit (fun () -> JConfig.create_harness := true), None, + "Create Android lifecycle harness"; "-verbose_out", Arg.String (fun path -> JClasspath.set_verbose_out path), None, "Set the path to the javac verbose output" ] in @@ -85,7 +87,7 @@ let do_source_file JFrontend.compute_source_icfg never_null_matcher linereader classes program tenv source_basename source_file in store_icfg tenv call_graph cfg source_file; - if JConfig.create_harness then + if !JConfig.create_harness then IList.fold_left (fun proc_file_map pdesc -> Procname.Map.add (Cfg.Procdesc.get_proc_name pdesc) source_file proc_file_map) @@ -161,7 +163,7 @@ let do_all_files classpath sources classes = Procname.Map.empty in if !JConfig.dependency_mode then capture_libs never_null_matcher linereader program tenv; - if JConfig.create_harness then Harness.create_harness proc_file_map tenv; + if !JConfig.create_harness then Harness.create_harness proc_file_map tenv; save_tenv classpath tenv; JUtils.log "done @." diff --git a/infer/tests/utils/InferRunner.java b/infer/tests/utils/InferRunner.java index b9122939b..575edf019 100644 --- a/infer/tests/utils/InferRunner.java +++ b/infer/tests/utils/InferRunner.java @@ -143,7 +143,9 @@ public class InferRunner { public static ImmutableList createJavaInferHarnessCommand( TemporaryFolder folder, ImmutableList sourceFiles) { - ImmutableList args = new ImmutableList.Builder().build(); + ImmutableList args = new ImmutableList.Builder() + .add("--android-harness") + .build(); return createInferJavaCommand(folder, sourceFiles, "infer", args); } @@ -156,7 +158,9 @@ public class InferRunner { public static ImmutableList createJavaInferAngelicHarnessCommand( TemporaryFolder folder, ImmutableList sourceFiles) { - ImmutableList args = (new ImmutableList.Builder()).build(); + ImmutableList args = (new ImmutableList.Builder()) + .add("--android-harness") + .build(); return createInferJavaCommand(folder, sourceFiles, "infer", args); }