From 2d6d4f7db9f022ef6065b397fc6947ec57a1006d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ezgi=20=C3=87i=C3=A7ek?= Date: Fri, 5 Jun 2020 09:49:58 -0700 Subject: [PATCH] [cost] Brush up tests (1) Summary: Fix misleading test names. Correct FP/ok/bad markers. To be continued... Reviewed By: skcho Differential Revision: D21905556 fbshipit-source-id: 161801f9c --- .../performance/{A.java => AllocTest.java} | 17 +++++++------- .../codetoanalyze/java/performance/Array.java | 8 +++---- .../java/performance/ArrayCost.java | 5 ++-- .../java/performance/cost-issues.exp | 23 +++++++++---------- .../codetoanalyze/java/performance/issues.exp | 2 +- 5 files changed, 26 insertions(+), 29 deletions(-) rename infer/tests/codetoanalyze/java/performance/{A.java => AllocTest.java} (67%) diff --git a/infer/tests/codetoanalyze/java/performance/A.java b/infer/tests/codetoanalyze/java/performance/AllocTest.java similarity index 67% rename from infer/tests/codetoanalyze/java/performance/A.java rename to infer/tests/codetoanalyze/java/performance/AllocTest.java index a81dfcfd8..2dc673514 100644 --- a/infer/tests/codetoanalyze/java/performance/A.java +++ b/infer/tests/codetoanalyze/java/performance/AllocTest.java @@ -4,24 +4,27 @@ * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. */ -public class A {} +class A {} -class B { +// The tests in this class were intended to test allocation counts. +// To be revived later once we support them. - void error() { +class AllocTest { + + void new_alloc_mult() { A a1 = new A(); A a2 = new A(); A a3 = new A(); A a4 = new A(); } - void ok() { + void new_alloc_one() { A a1 = new A(); } class BArray { - void error() { + void array_alloc_mult() { A[] ar1 = new A[5]; A[] ar2 = new A[6]; A[] ar3 = new A[7]; @@ -29,9 +32,5 @@ class B { A[] ar5 = new A[4]; } - void ok() { - A[] ar1 = new A[5]; - A[] ar2 = new A[5]; - } } } diff --git a/infer/tests/codetoanalyze/java/performance/Array.java b/infer/tests/codetoanalyze/java/performance/Array.java index de7b6edd6..ba8f3dfa2 100644 --- a/infer/tests/codetoanalyze/java/performance/Array.java +++ b/infer/tests/codetoanalyze/java/performance/Array.java @@ -10,7 +10,7 @@ import java.util.Arrays; public class Array { - public void array_access_good() { + public void array_access_constant() { float[] radii = new float[8]; for (int i = 0; i < 4; ++i) { radii[i * 2] = radii[i]; @@ -18,7 +18,7 @@ public class Array { } } - public void array_access_overrun_bad() { + public void array_access_overrun_constant() { float[] radii = new float[8]; for (int i = 0; i < 4; ++i) { radii[i * 2] = radii[i]; @@ -26,7 +26,7 @@ public class Array { } } - void array_access_weird_ok(long[] optionNumerators, int length) { + void array_access_weird_linear(long[] optionNumerators, int length) { for (int j = 0; j < length; ++j) { if (10 < optionNumerators[j] + 1) {} } @@ -49,7 +49,7 @@ public class Array { String[] new_arr = Arrays.copyOf(arr, 10); } - void init_array_linear() { + void init_array_constant() { int[] table = new int[256]; for (int i = 0; i < table.length; ++i) { table[i] = i; diff --git a/infer/tests/codetoanalyze/java/performance/ArrayCost.java b/infer/tests/codetoanalyze/java/performance/ArrayCost.java index 193c39de3..f481b73b9 100644 --- a/infer/tests/codetoanalyze/java/performance/ArrayCost.java +++ b/infer/tests/codetoanalyze/java/performance/ArrayCost.java @@ -6,7 +6,7 @@ */ public class ArrayCost { - // expected: Theta(mag.length) + // expected: O(mag.length) private void ArrayCost(int[] mag) { int i = 0; @@ -17,8 +17,7 @@ public class ArrayCost { } } - // expected: ~31 - private static boolean isPowOfTwo_FP(int value) { + private static boolean isPowOfTwo_constant(int value) { int ones = 0; int v = value; diff --git a/infer/tests/codetoanalyze/java/performance/cost-issues.exp b/infer/tests/codetoanalyze/java/performance/cost-issues.exp index c852d1ea5..7dfa66bce 100644 --- a/infer/tests/codetoanalyze/java/performance/cost-issues.exp +++ b/infer/tests/codetoanalyze/java/performance/cost-issues.exp @@ -1,18 +1,17 @@ -codetoanalyze/java/performance/A.java, A.(), 3, OnUIThread:false, [] -codetoanalyze/java/performance/A.java, B$BArray.(B), 6, OnUIThread:false, [] -codetoanalyze/java/performance/A.java, B$BArray.error():void, 11, OnUIThread:false, [] -codetoanalyze/java/performance/A.java, B$BArray.ok():void, 5, OnUIThread:false, [] -codetoanalyze/java/performance/A.java, B.(), 3, OnUIThread:false, [] -codetoanalyze/java/performance/A.java, B.error():void, 21, OnUIThread:false, [] -codetoanalyze/java/performance/A.java, B.ok():void, 6, OnUIThread:false, [] +codetoanalyze/java/performance/AllocTest.java, A.(), 3, OnUIThread:false, [] +codetoanalyze/java/performance/AllocTest.java, AllocTest$BArray.(AllocTest), 6, OnUIThread:false, [] +codetoanalyze/java/performance/AllocTest.java, AllocTest$BArray.array_alloc_mult():void, 11, OnUIThread:false, [] +codetoanalyze/java/performance/AllocTest.java, AllocTest.(), 3, OnUIThread:false, [] +codetoanalyze/java/performance/AllocTest.java, AllocTest.new_alloc_mult():void, 21, OnUIThread:false, [] +codetoanalyze/java/performance/AllocTest.java, AllocTest.new_alloc_one():void, 6, OnUIThread:false, [] codetoanalyze/java/performance/AndroidXCollectionTest.java, AndroidXCollectionTest.(), 3, OnUIThread:false, [] codetoanalyze/java/performance/AndroidXCollectionTest.java, AndroidXCollectionTest.call_iterate_over_sparsearraycompat_const():void, 24, OnUIThread:false, [] codetoanalyze/java/performance/AndroidXCollectionTest.java, AndroidXCollectionTest.iterate_over_sparsearraycompat_linear(androidx.collection.SparseArrayCompat):void, 8 + 5 ⋅ sa.length, OnUIThread:false, [{sa.length},Loop at line 12] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.():void, 9, OnUIThread:false, [] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.(), 3, OnUIThread:false, [] -codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_good():void, 70, OnUIThread:false, [] -codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_overrun_bad():void, 70, OnUIThread:false, [] -codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_weird_ok(long[],int):void, 5 + 13 ⋅ length, OnUIThread:false, [{length},Loop at line 30] +codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_constant():void, 70, OnUIThread:false, [] +codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_overrun_constant():void, 70, OnUIThread:false, [] +codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_weird_linear(long[],int):void, 5 + 13 ⋅ length, OnUIThread:false, [{length},Loop at line 30] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.binary_search_log(java.lang.String[]):int, 5 + log(arr.length), OnUIThread:false, [{arr.length},Modeled call to Arrays.binarySearch] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.bsearch_log(int):void, 6 + log(i), OnUIThread:false, [{i},Modeled call to Arrays.binarySearch] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.call_gen_and_iter_types(int):void, 19 + 6 ⋅ x + 5 ⋅ x, OnUIThread:false, [{x},call to String[] Array.gen_and_iter_types(int),Loop at line 76,{x},Loop at line 82] @@ -22,13 +21,13 @@ codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array. codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.fill_big_constant():void, 307, OnUIThread:false, [] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.fill_linear(java.lang.String[]):void, 2 + arr.length, OnUIThread:false, [{arr.length},Modeled call to Arrays.fill] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.gen_and_iter_types(int):java.lang.String[], 10 + 5 ⋅ length, OnUIThread:false, [{length},Loop at line 76] -codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.init_array_linear():void, 2568, OnUIThread:false, [] +codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.init_array_constant():void, 2568, OnUIThread:false, [] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.sort_array_nlogn(int):void, 5 + size × log(size), OnUIThread:false, [{size},Modeled call to Arrays.sort,{size},Modeled call to Arrays.sort] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.toArray_linear(java.util.ArrayList):void, 6 + 6 ⋅ list.length + 3 ⋅ (list.length + 1), OnUIThread:false, [{list.length + 1},Loop at line 92,{list.length},Loop at line 92] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.use_static_final_array_field_constant():void, 18, OnUIThread:false, [] codetoanalyze/java/performance/ArrayCost.java, ArrayCost.(), 3, OnUIThread:false, [] codetoanalyze/java/performance/ArrayCost.java, ArrayCost.ArrayCost(int[]):void, 8 + 5 ⋅ mag.length, OnUIThread:false, [{mag.length},Loop at line 15] -codetoanalyze/java/performance/ArrayCost.java, ArrayCost.isPowOfTwo_FP(int):boolean, 895, OnUIThread:false, [] +codetoanalyze/java/performance/ArrayCost.java, ArrayCost.isPowOfTwo_constant(int):boolean, 895, OnUIThread:false, [] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest$Elt.(ArrayListTest), 6, OnUIThread:false, [] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest$Elt.get_boolean():boolean, 4, OnUIThread:false, [] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.(), 15, OnUIThread:false, [] diff --git a/infer/tests/codetoanalyze/java/performance/issues.exp b/infer/tests/codetoanalyze/java/performance/issues.exp index 97fc6f3ac..8666d28e0 100644 --- a/infer/tests/codetoanalyze/java/performance/issues.exp +++ b/infer/tests/codetoanalyze/java/performance/issues.exp @@ -1,4 +1,4 @@ -codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_overrun_bad():void, 4, BUFFER_OVERRUN_L2, no_bucket, ERROR, [,Assignment,,Array declaration,Array access: Offset: [2, 8] Size: 8] +codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.array_access_overrun_constant():void, 4, BUFFER_OVERRUN_L2, no_bucket, ERROR, [,Assignment,,Array declaration,Array access: Offset: [2, 8] Size: 8] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.call_gen_and_iter_types_linear_FP(int,int):void, 0, INFINITE_EXECUTION_TIME, no_bucket, ERROR, [Unbounded loop,Loop at line 88] codetoanalyze/java/performance/Array.java, codetoanalyze.java.performance.Array.call_gen_and_iter_types_linear_FP(int,int):void, 3, INTEGER_OVERFLOW_L5, no_bucket, ERROR, [,Assignment,Binary operation: ([0, +oo] + 1):signed32] codetoanalyze/java/performance/ArrayListTest.java, ArrayListTest.arraylist_add3_overrun_bad():void, 5, BUFFER_OVERRUN_L1, no_bucket, ERROR, [,Array declaration,Through,Through,Through,Array access: Offset added: 4 Size: 3]