You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
99 lines
2.6 KiB
99 lines
2.6 KiB
/*
|
|
* 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.io.IOException;
|
|
import java.io.InputStream;
|
|
import java.util.ArrayList;
|
|
import org.json.JSONArray;
|
|
|
|
class UnknownCallsTest {
|
|
|
|
private int mBytesToRead;
|
|
|
|
public void jsonArray_linear(JSONArray jsonArray) {
|
|
int length = jsonArray.length();
|
|
for (int i = 0; i < length; ++i) {}
|
|
}
|
|
|
|
public void jsonArray_constant() {
|
|
JSONArray jsonArray = new JSONArray();
|
|
jsonArray.put(1);
|
|
for (int i = 0; i < jsonArray.length(); ++i) {}
|
|
}
|
|
|
|
public int read_sum_cost(
|
|
InputStream in, byte[] buffer, int byteOffset, int byteCount, ArrayList<Integer> list)
|
|
throws IOException {
|
|
int maxBytesToRead = Math.min(byteCount, mBytesToRead);
|
|
int bytesRead = in.read(buffer, byteOffset, maxBytesToRead);
|
|
|
|
for (int index = 0; index < bytesRead + maxBytesToRead; ++index) {}
|
|
return 0;
|
|
}
|
|
|
|
// Expected: linear
|
|
public int read_max_cost(
|
|
InputStream in, byte[] buffer, int byteOffset, int byteCount, ArrayList<Integer> list)
|
|
throws IOException {
|
|
int maxBytesToRead = Math.min(byteCount, mBytesToRead);
|
|
int bytesRead = in.read(buffer, byteOffset, maxBytesToRead);
|
|
if (bytesRead > 0) {
|
|
maxBytesToRead = bytesRead + 1;
|
|
}
|
|
for (int index = 0; index < maxBytesToRead; ++index) {}
|
|
return 0;
|
|
}
|
|
|
|
private static void loop_over_charArray_FP(StringBuilder builder, String input) {
|
|
for (Character c : input.toCharArray()) {}
|
|
}
|
|
|
|
private static void call_loop_over_charArray_FP(StringBuilder out, String in) {
|
|
loop_over_charArray_FP(out, in);
|
|
}
|
|
|
|
// hashCode is impure but we don't invalidate all other library
|
|
// calls such as size()
|
|
void unmodeled_impure_linear(ArrayList<Integer> list) {
|
|
for (int i = 0; i < list.size(); i++) {
|
|
list.get(i).hashCode();
|
|
}
|
|
}
|
|
|
|
int throw_exception() {
|
|
throw new IllegalStateException();
|
|
}
|
|
|
|
// specifically for exceptions, we generate a symbolic value to
|
|
// prevent poisoning the callees with Tops.
|
|
void call_throw_exception_linear() {
|
|
for (int i = 0; i < throw_exception(); i++) {}
|
|
}
|
|
|
|
boolean unknown_bool;
|
|
|
|
int may_throw_exception() {
|
|
if (unknown_bool) {
|
|
throw new IllegalStateException();
|
|
} else {
|
|
return 10;
|
|
}
|
|
}
|
|
|
|
void call_may_throw_exception_constant() {
|
|
for (int i = 0; i < may_throw_exception(); i++) {}
|
|
}
|
|
|
|
abstract class AbstractC {
|
|
abstract int[] abstract_func();
|
|
}
|
|
|
|
void call_concrete_func_linear_FP(AbstractC x) {
|
|
int[] a = x.abstract_func();
|
|
for (int i = 0; i < a.length; i++) {}
|
|
}
|
|
}
|