Starts an analysis for a specific test case. @param clz the class to be analyzed @param isMainClass if the class contains main method @param classPath where the main class is located @param id ID of the analysis to be executed @param opts options for the analysis
(String clz, boolean isMainClass,
String classPath, String id, String... opts)
| 107 | * @param opts options for the analysis |
| 108 | */ |
| 109 | private static void test(String clz, boolean isMainClass, |
| 110 | String classPath, String id, String... opts) { |
| 111 | List<String> args = new ArrayList<>(); |
| 112 | args.add("-pp"); |
| 113 | Collections.addAll(args, "-cp", classPath); |
| 114 | Collections.addAll(args, isMainClass ? "-m" : "--input-classes", clz); |
| 115 | if (DUMP_IR) { |
| 116 | // dump IR |
| 117 | Collections.addAll(args, "-a", IRDumper.ID); |
| 118 | } |
| 119 | if (DUMP_CFG) { |
| 120 | // dump control-flow graphs |
| 121 | Collections.addAll(args, "-a", |
| 122 | String.format("%s=dump:true", CFGBuilder.ID)); |
| 123 | } |
| 124 | // set up the analysis |
| 125 | if (opts.length > 0 && !opts[0].equals("-a")) { |
| 126 | // if the opts is not empty, and the opts[0] is not "-a", |
| 127 | // then this option is given to analysis *id*. |
| 128 | Collections.addAll(args, "-a", id + "=" + opts[0]); |
| 129 | args.addAll(Arrays.asList(opts).subList(1, opts.length)); |
| 130 | } else { |
| 131 | Collections.addAll(args, "-a", id); |
| 132 | Collections.addAll(args, opts); |
| 133 | } |
| 134 | // set up result processor |
| 135 | String action = GENERATE_EXPECTED_RESULTS ? "dump" : "compare"; |
| 136 | String file = getExpectedFile(classPath, clz, id); |
| 137 | String processArg = String.format("%s=analyses:[%s];action:%s;action-file:%s", |
| 138 | ResultProcessor.ID, id, action, file); |
| 139 | Collections.addAll(args, "-a", processArg); |
| 140 | Main.main(args.toArray(new String[0])); |
| 141 | if (action.equals("compare")) { |
| 142 | Set<String> mismatches = World.get().getResult(ResultProcessor.ID); |
| 143 | assertTrue(mismatches.isEmpty(), |
| 144 | "Mismatches of analysis \"" + id + "\":\n" + |
| 145 | String.join("\n", mismatches)); |
| 146 | } |
| 147 | } |
| 148 | |
| 149 | public static void testPTA(String dir, String main, String... opts) { |
| 150 | testPTA(true, dir, main, opts); |