Skip to content

Commit

Permalink
[topl] Added tests for inefficient iteration
Browse files Browse the repository at this point in the history
Summary:
The test shows what that TOPL can express, in addition to bugs,
efficiency properties. However, there seems to be an underlying problem
in biabdaction that prevents this particular problem from being caught.

Reviewed By: ngorogiannis

Differential Revision: D20005404

fbshipit-source-id: 466f79050
  • Loading branch information
rgrig authored and facebook-github-bot committed Feb 26, 2020
1 parent 3538cae commit 2888a90
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
13 changes: 13 additions & 0 deletions infer/tests/codetoanalyze/java/topl/slowIter/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright (c) Facebook, Inc. and its affiliates.
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.

TESTS_DIR = ../../../..

INFER_OPTIONS = --seconds-per-iteration 10 --symops-per-iteration 20000 --topl-properties slowIter.topl --biabduction-only
INFERPRINT_OPTIONS = --issues-tests

SOURCES = $(wildcard *.java)

include $(TESTS_DIR)/javac.make
34 changes: 34 additions & 0 deletions infer/tests/codetoanalyze/java/topl/slowIter/SlowIterTests.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/

import java.util.Map;

class SlowIterTests {
// T62611635
static <K, V> void FN_aBad(Map<K, V> m) {
for (K k : m.keySet()) {
System.out.printf("%s -> %s\n", k, m.get(k));
}
}

static <K, V> void aOk(Map<K, V> m) {
for (Map.Entry<K, V> e : m.entrySet()) {
System.out.printf("%s -> %s\n", e.getKey(), e.getValue());
}
}

// Inter-procedural variant of aBad.
static <K, V> void FN_bBad(Map<K, V> m) {
for (K k : m.keySet()) {
print(k, m);
}
}

static <K, V> void print(K k, Map<K, V> m) {
System.out.printf("%s -> %s\n", k, m.get(k));
}
}
8 changes: 8 additions & 0 deletions infer/tests/codetoanalyze/java/topl/slowIter/slowIter.topl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
property ShouldUseEntries
nondet (start iteratingKeys)
start -> start: *
start -> gotKeys: S = "Map.keySet"(M)
gotKeys -> iteratingKeys: I = "Set.iterator"(s)
iteratingKeys -> iteratingKeys: *
iteratingKeys -> gotOneKey: K = "Iterator.next"(i)
gotOneKey -> error: ".*Map.get"(m, k)

0 comments on commit 2888a90

Please sign in to comment.