Files
sdk/tests/language/is/optimized_test.dart
T
Alexander Markov 24b8399086 [tests] Avoid small --optimization-counter-threshold in tests
Small --optimization-counter-threshold makes tests very slow,
especially on architectures where kernel service runs from
kernel and not from app-jit snapshot.

TEST=change in tests, *-ia32 bots
Fixes https://github.com/dart-lang/sdk/issues/48627

Change-Id: I63e7e201ef9a0e4f645016c39a5be1819b61822d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/263421
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2022-10-10 21:04:18 +00:00

102 lines
2.5 KiB
Dart

// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// Testing optimized 'is' tests.
// VMOptions=--optimization-counter-threshold=20 --no-use-osr --no-background-compilation
import "package:expect/expect.dart";
bool isInt(x) => x is int;
int isIntRes(x) {
if (x is int) {
return 1;
} else {
return 0;
}
}
int isNotIntRes(x) {
if (x is! int) {
return 1;
} else {
return 0;
}
}
int isIfThenElseIntRes(x) {
return x is int ? 1 : 0;
}
bool isString(x) => x is String;
int isStringRes(x) {
if (x is String) {
return 1;
} else {
return 0;
}
}
int isNotStringRes(x) {
if (x is! String) {
return 1;
} else {
return 0;
}
}
main() {
for (int i = 0; i < 20; i++) {
Expect.isFalse(isInt(3.2));
Expect.isTrue(isInt(3));
Expect.isTrue(isInt(17179869184)); // Mint on ia32.
Expect.isFalse(isString(2.0));
Expect.isTrue(isString("Morgan"));
}
// No deoptimization of isInt possible since all types are known by the compiler
Expect.isFalse(isString(true));
for (int i = 0; i < 20; i++) {
Expect.isFalse(isInt(3.2));
Expect.isTrue(isInt(3));
Expect.isTrue(isInt(17179869184)); // Mint on ia32.
Expect.isFalse(isInt("hu"));
Expect.isFalse(isString(2.0));
Expect.isTrue(isString("Morgan"));
Expect.isFalse(isString(true));
}
for (int i = 0; i < 20; i++) {
Expect.equals(0, isIntRes(3.2));
Expect.equals(1, isIntRes(3));
Expect.equals(0, isIntRes("hi"));
Expect.equals(1, isNotIntRes(3.2));
Expect.equals(0, isNotIntRes(3));
Expect.equals(1, isNotIntRes("hi"));
Expect.equals(0, isIfThenElseIntRes(3.2));
Expect.equals(1, isIfThenElseIntRes(3));
Expect.equals(0, isIfThenElseIntRes("hi"));
}
for (int i = 0; i < 20; i++) {
Expect.equals(0, isStringRes(3.2));
Expect.equals(1, isStringRes("Lotus"));
Expect.equals(1, isNotStringRes(3.2));
Expect.equals(0, isNotStringRes("Lotus"));
}
// Deoptimize 'isStringRes', 'isNotIntRes'.
Expect.equals(0, isStringRes(null));
Expect.equals(1, isNotIntRes(null));
for (int i = 0; i < 20; i++) {
Expect.equals(0, isStringRes(3.2));
Expect.equals(1, isStringRes("Lotus"));
Expect.equals(0, isStringRes(null));
Expect.equals(1, isNotStringRes(3.2));
Expect.equals(0, isNotStringRes("Lotus"));
Expect.equals(1, isNotStringRes(null));
}
}