Example #1
0
  public void sendMeta(
      final ShadowString className,
      final ShadowString methodID,
      final int classBranch,
      final int methodBranch,
      final int classBasicBlock,
      final int methodBasicBlock) {
    if (methodID.getState() == null) {
      if (className.getState() == null) {
        className.setStateIfAbsent(new ClassStatistic(classBranch, classBasicBlock));
      }

      methodID.setStateIfAbsent(new MethodStatistic(className, methodBranch, methodBasicBlock));
    }
  }
Example #2
0
  public void commitBasicBlock(final ShadowString methodID, final int index) {
    MethodStatistic status;

    if ((status = methodID.getState(MethodStatistic.class)) != null) {
      status.basicblocks[index] = true;
    }
  }
Example #3
0
  // TODO write map-reduce friendly code
  public void printSPResult(final Context context) {
    final HashSet<ShadowString> classes = new HashSet<>();

    System.out.println("############### Methods ###############");

    for (final ShadowObject object : context.getShadowObjectIterator()) {
      final Object state = object.getState();

      if (state == null) {
        continue;
      } else if (state instanceof ClassStatistic) {
        classes.add((ShadowString) object);
      } else if (state instanceof MethodStatistic) {
        final MethodStatistic methodStatistic = (MethodStatistic) state;
        methodStatistic.updateCoverageData();

        System.out.printf(
            "PROCESS-%d-METHODS: %s %s\n",
            context.pid(), object.toString(), methodStatistic.toString());

        final ClassStatistic classStatistic =
            methodStatistic.className.getState(ClassStatistic.class);

        classStatistic.coveredBranches += methodStatistic.coveredBranches;
        classStatistic.coveredBasicBlocks += methodStatistic.coveredBasicBlocks;
        classStatistic.coveredMethod++;
      }
    }

    System.out.println("############### Classes ###############");

    for (final ShadowString klass : classes) {
      final ClassStatistic statistic = klass.getState(ClassStatistic.class);

      System.out.printf(
          "PROCESS-%d-CLASSES: %s %s\n", context.pid(), klass.toString(), statistic.toString());
    }

    System.out.println("############### Package ###############");

    final HashMap<String, ClassStatistic> packageCovered = new HashMap<>();

    for (final ShadowString klass : classes) {
      final String packageName = getPackageName(klass.toString());
      ClassStatistic packageStatistic = packageCovered.get(packageName);

      if (packageStatistic == null) {
        packageStatistic = new ClassStatistic(0, 0);
        packageCovered.put(packageName, packageStatistic);
      }

      final ClassStatistic classStatistic = klass.getState(ClassStatistic.class);
      packageStatistic.merge(classStatistic);
    }

    for (final String key : packageCovered.keySet()) {
      final ClassStatistic packageStatistic = packageCovered.get(key);
      System.out.printf(
          "PROCESS-%d-PACKAGE: %s %s\n", context.pid(), key, packageStatistic.toString());
    }

    System.out.println("############### Tex Output ###############");

    for (final String key : packageCovered.keySet()) {
      final ClassStatistic packageStatistic = packageCovered.get(key);
      System.out.printf("%s %s \\\\\n", key, packageStatistic.toTexString());
    }

    System.out.println("############### Summary ###############");

    final HashMap<String, ClassStatistic> summaryCovered = new HashMap<>();

    for (final ShadowString klass : classes) {
      final String summaryName = getSummaryName(klass.toString());
      ClassStatistic packageStatistic = summaryCovered.get(summaryName);

      if (packageStatistic == null) {
        packageStatistic = new ClassStatistic(0, 0);
        summaryCovered.put(summaryName, packageStatistic);
      }

      final ClassStatistic classStatistic = klass.getState(ClassStatistic.class);
      packageStatistic.merge(classStatistic);
    }

    for (final String key : summaryCovered.keySet()) {
      final ClassStatistic packageStatistic = summaryCovered.get(key);
      System.out.printf(
          "PROCESS-%d-SUMMARY: %s %s\n", context.pid(), key, packageStatistic.toString());
    }
  }