Signed-off-by: caolili123 <caolili14@huawei.com>
This commit is contained in:
caolili123 2024-02-07 10:14:45 +08:00
parent 5212133062
commit 2958cf417a
28 changed files with 1504 additions and 146 deletions

View File

@ -323,7 +323,6 @@ Expected<JSTaggedValue, bool> EcmaContext::CommonInvokeEcmaEntrypoint(const JSPa
if (!executeFromJob && !thread_->HasPendingException()) {
job::MicroJobQueue::ExecutePendingJob(thread_, GetMicroJobQueue());
}
return result;
}

View File

@ -165,7 +165,8 @@ const std::string PUBLIC_API HELP_OPTION_MSG =
"--compiler-force-jit-compile-main: Enable jit compile main function: Default: 'false'\n"
"--compiler-trace-jit: Enable trace jit: Default: 'false'\n\n"
"--compiler-typed-op-profiler: Enable Typed Opcode Statistics for aot runtime. Default: 'false'\n"
"--compiler-opt-branch-profiling: Enable branch profiling for aot compiler. Default: 'true'\n";
"--compiler-opt-branch-profiling: Enable branch profiling for aot compiler. Default: 'true'\n"
"--test-assert: Set Assert Model. Default: 'false'\n";
bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{
@ -272,6 +273,7 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
{"compiler-force-jit-compile-main", required_argument, nullptr, OPTION_COMPILER_FORCE_JIT_COMPILE_MAIN},
{"compiler-typed-op-profiler", required_argument, nullptr, OPTION_COMPILER_TYPED_OP_PROFILER},
{"compiler-opt-branch-profiling", required_argument, nullptr, OPTION_COMPILER_OPT_BRANCH_PROFILING},
{"test-assert", required_argument, nullptr, OPTION_TEST_ASSERT},
{nullptr, 0, nullptr, 0},
};
@ -964,6 +966,14 @@ bool JSRuntimeOptions::ParseCommand(const int argc, const char **argv)
return false;
}
break;
case OPTION_TEST_ASSERT:
ret = ParseBoolParam(&argBool);
if (ret) {
SetTestAssert(argBool);
} else {
return false;
}
break;
default:
LOG_ECMA(ERROR) << "Invalid option\n";
return false;

View File

@ -162,6 +162,7 @@ enum CommandValues {
OPTION_ENABLE_ELEMENTSKIND,
OPTION_COMPILER_TYPED_OP_PROFILER,
OPTION_COMPILER_OPT_BRANCH_PROFILING,
OPTION_TEST_ASSERT,
};
class PUBLIC_API JSRuntimeOptions {
@ -1445,6 +1446,16 @@ public:
enableBranchProfiling_ = value;
}
void SetTestAssert(bool value)
{
testAssert_ = value;
}
bool GetTestAssert() const
{
return testAssert_;
}
private:
static bool StartsWith(const std::string &haystack, const std::string &needle)
{
@ -1564,6 +1575,7 @@ private:
bool enableLiteCG_ {false};
bool enableTypedOpProfiler_ {false};
bool enableBranchProfiling_ {true};
bool testAssert_ {false};
};
} // namespace panda::ecmascript

View File

@ -49,6 +49,55 @@ std::string GetHelper()
return str;
}
Local<JSValueRef> AssertEqual(JsiRuntimeCallInfo *runtimeInfo)
{
EcmaVM *vm = runtimeInfo->GetVM();
uint32_t argsCount = runtimeInfo->GetArgsNumber();
if (argsCount < 2) { // 2: at least have two arguments
std::string errStr = "Assertion failed: At least have two arguments.";
auto error = panda::Exception::TypeError(vm, StringRef::NewFromUtf8(vm, errStr.c_str()));
panda::JSNApi::ThrowException(vm, error);
return JSValueRef::Undefined(vm);
}
Local<JSValueRef> jsArg0 = runtimeInfo->GetCallArgRef(0);
Local<JSValueRef> jsArg1 = runtimeInfo->GetCallArgRef(1);
if (!jsArg0->IsStrictEquals(vm, jsArg1)) {
std::string errStr = std::string("Assertion failed: ").append(jsArg0->ToString(vm)->ToString())
.append(" != ").append(jsArg1->ToString(vm)->ToString());
auto error = panda::Exception::TypeError(vm, StringRef::NewFromUtf8(vm, errStr.c_str()));
panda::JSNApi::ThrowException(vm, error);
}
return JSValueRef::Undefined(vm);
}
Local<JSValueRef> AssertTrue(JsiRuntimeCallInfo *runtimeInfo)
{
EcmaVM *vm = runtimeInfo->GetVM();
uint32_t argsCount = runtimeInfo->GetArgsNumber();
if (argsCount < 1) {
std::string errStr = "Assertion failed: At least have one argument.";
auto error = panda::Exception::TypeError(vm, StringRef::NewFromUtf8(vm, errStr.c_str()));
panda::JSNApi::ThrowException(vm, error);
return JSValueRef::Undefined(vm);
}
Local<JSValueRef> jsArg0 = runtimeInfo->GetCallArgRef(0);
if (!jsArg0->IsTrue()) {
std::string errStr = std::string("Assertion failed: Expect ").append(jsArg0->ToString(vm)->ToString())
.append(" equals True.");
auto error = panda::Exception::TypeError(vm, StringRef::NewFromUtf8(vm, errStr.c_str()));
panda::JSNApi::ThrowException(vm, error);
}
return JSValueRef::Undefined(vm);
}
bool ExecutePandaFile(EcmaVM *vm, JSRuntimeOptions &runtimeOptions, std::string &files)
{
bool ret = true;
@ -64,6 +113,13 @@ bool ExecutePandaFile(EcmaVM *vm, JSRuntimeOptions &runtimeOptions, std::string
context1 = JSNApi::CreateJSContext(vm);
JSNApi::SwitchCurrentContext(vm, context1);
}
if (runtimeOptions.GetTestAssert()) {
Local<ObjectRef> globalObj = JSNApi::GetGlobalObject(vm);
Local<FunctionRef> assertEqual = FunctionRef::New(vm, AssertEqual);
globalObj->Set(vm, StringRef::NewFromUtf8(vm, "assert_equal"), assertEqual);
Local<FunctionRef> assertTrue = FunctionRef::New(vm, AssertTrue);
globalObj->Set(vm, StringRef::NewFromUtf8(vm, "assert_true"), assertTrue);
}
if (runtimeOptions.WasAOTOutputFileSet()) {
JSNApi::LoadAotFile(vm, "");
}

View File

@ -20,7 +20,6 @@ group("ark_aot_js_test") {
"constructor_returns_non_object",
"tryldglobalbyname",
"dynamicimport",
"emptyif",
"formatrangetoparts",
"module",
"undefined",
@ -43,11 +42,21 @@ group("ark_aot_js_test") {
}
}
group("ark_aot_js_assert_test") {
testonly = true
deps = []
test_assert_list = [ "emptyif" ]
foreach(test, test_assert_list) {
deps += [ "${test}:${test}AotAssertAction" ]
if (!is_debug) {
deps += [ "${test}:${test}AotContextAssertAction" ]
}
}
}
group("ark_aot_ts_test") {
testonly = true
test_list = [
"add",
"and",
"array",
"array_bounds_check_elimination",
"array_foreach_inline",
@ -317,10 +326,28 @@ group("ark_aot_ts_test") {
}
}
group("ark_aot_ts_assert_test") {
testonly = true
deps = []
assert_test_list = [
"add",
"and",
]
foreach(test, assert_test_list) {
deps += [ "${test}:${test}AotAssertAction" ]
if (!is_debug) {
deps += [ "${test}:${test}AotContextAssertAction" ]
}
}
}
group("ark_aot_test") {
testonly = true
deps = [
":ark_aot_js_assert_test",
":ark_aot_js_test",
":ark_aot_ts_assert_test",
":ark_aot_ts_test",
"analyze_property:analyze_property_test",
"aot_compatibility_test:aot_compatibility_test",
@ -332,7 +359,9 @@ group("ark_aot_test") {
if (is_mac) {
deps -= [
":ark_aot_js_assert_test",
":ark_aot_js_test",
":ark_aot_ts_assert_test",
":ark_aot_ts_test",
"aot_type_test:aot_type_test",
]

View File

@ -13,6 +13,6 @@
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_aot_test_action("add") {
host_aot_assert_test_action("add") {
deps = []
}

View File

@ -13,13 +13,12 @@
* limitations under the License.
*/
declare function print(arg:any):string;
print(1 + 1);
assert_equal(1 + 1, 2);
print(1 + 1.1);
assert_equal(1 + 1.1, 2.1);
print(0.1 + 1.1)
assert_equal(0.1 + 1.1, 1.2000000000000002);
print("hello" + "world");
assert_equal("hello" + "world", "helloworld");
print("hello" + 1);
assert_equal("hello" + 1, "hello1");

View File

@ -1,18 +0,0 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
2
2.1
1.2000000000000002
helloworld
hello1

View File

@ -13,6 +13,6 @@
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_aot_test_action("and") {
host_aot_assert_test_action("and") {
deps = []
}

View File

@ -13,40 +13,39 @@
* limitations under the License.
*/
declare function print(str:any):string;
var x1 = 15;
var y1 = 1;
var r1 = x1 & y1;
print(r1);
assert_equal(r1, 1);
var x2 = 15.8;
var y2 = 1;
var r2 = x2 & y2;
print(r2);
assert_equal(r2, 1);
var x3 = 15;
var y3 = 1.8;
var r3 = x3 & y3;
print(r3);
assert_equal(r3, 1);
var x4 = 15.8;
var y4 = 1.8;
var r4 = x4 & y4;
print(r4);
assert_equal(r4, 1);
var x5:any = "15";
var y5:number = 1;
var r5 = x5 & y5;
print(r5);
assert_equal(r5, 1);
var x6 = -15;
var y6 = 1;
var r6 = x6 & y6;
print(r6);
assert_equal(r6, 1);
var x7 = 15;
var y7 = -1;
var r7 = x7 & y7;
print(r7);
assert_equal(r7, 15);
// not supported type: string, bigint

View File

@ -1,20 +0,0 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
1
1
1
1
1
1
15

View File

@ -13,6 +13,6 @@
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_aot_js_test_action("emptyif") {
host_aot_js_assert_test_action("emptyif") {
deps = []
}

View File

@ -23,5 +23,5 @@ function emptyiftrue() {
return 2;
}
print(emptycompare(2, 3));
print(emptyiftrue());
assert_equal(emptycompare(2, 3), 1);
assert_equal(emptyiftrue(), 2);

View File

@ -1,15 +0,0 @@
# Copyright (c) 2022 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
1
2

View File

@ -13,10 +13,8 @@
group("ark_js_moduletest") {
testonly = true
test_list = [
"addelementinternal",
"addpropertybyname",
"allocatearraybuffer",
"array",
"arrayfindlast",
@ -183,8 +181,6 @@ group("ark_js_moduletest") {
if (!is_debug) {
release_test_list = [
"hugearray",
"multiconstpoolarray",
"multiconstpoolclass",
"multiconstpoolconstructor",
"multiconstpoolfunc",
@ -200,12 +196,37 @@ group("ark_js_moduletest") {
}
}
group("ark_js_assert_moduletest") {
testonly = true
assert_test_list = [ "addpropertybyname" ]
deps = []
foreach(test, assert_test_list) {
deps += [ "${test}:${test}AssertAction" ]
if (!is_debug) {
deps += [ "${test}:${test}ContextAssertAction" ]
}
}
if (!is_debug) {
release_test_assert_list = [
"hugearray",
"multiconstpoolarray",
]
foreach(test, release_test_assert_list) {
deps += [
"${test}:${test}AssertAction",
"${test}:${test}ContextAssertAction",
]
}
}
}
group("ark_asm_test") {
testonly = true
test_list = [
"addelementinternal",
"addpropertybyname",
"allocatearraybuffer",
"allocatesizeoverflow",
"array",
@ -339,8 +360,6 @@ group("ark_asm_test") {
if (!is_debug) {
release_test_list = [
"hugearray",
"multiconstpoolarray",
"multiconstpoolclass",
"multiconstpoolconstructor",
"multiconstpoolfunc",
@ -356,12 +375,37 @@ group("ark_asm_test") {
}
}
group("ark_asm_assert_test") {
testonly = true
assert_test_list = [ "addpropertybyname" ]
deps = []
foreach(test, assert_test_list) {
deps += [ "${test}:${test}AsmAssertAction" ]
if (!is_debug) {
deps += [ "${test}:${test}AsmContextAssertAction" ]
}
}
if (!is_debug) {
release_test_assert_list = [
"hugearray",
"multiconstpoolarray",
]
foreach(test, release_test_assert_list) {
deps += [
"${test}:${test}AsmAssertAction",
"${test}:${test}AsmContextAssertAction",
]
}
}
}
group("ark_asm_single_step_test") {
testonly = true
test_list = [
"addelementinternal",
"addpropertybyname",
"allocatearraybuffer",
"allocatesizeoverflow",
"arrayfindindex",
@ -468,10 +512,8 @@ group("ark_asm_single_step_test") {
deps += [ "${test}:${test}AsmSingleStepContextAction" ]
}
}
if (!is_debug) {
release_test_list = [
"multiconstpoolarray",
"multiconstpoolclass",
"multiconstpoolconstructor",
"multiconstpoolfunc",
@ -486,3 +528,26 @@ group("ark_asm_single_step_test") {
}
}
}
group("ark_asm_single_step_assert_test") {
testonly = true
assert_test_list = [ "addpropertybyname" ]
deps = []
foreach(test, assert_test_list) {
deps += [ "${test}:${test}AsmSingleStepAssertAction" ]
if (!is_debug) {
deps += [ "${test}:${test}AsmSingleStepContextAssertAction" ]
}
}
if (!is_debug) {
release_test_assert_list = [ "multiconstpoolarray" ]
foreach(test, release_test_assert_list) {
deps += [
"${test}:${test}AsmSingleStepAssertAction",
"${test}:${test}AsmSingleStepContextAssertAction",
]
}
}
}

View File

@ -13,6 +13,6 @@
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("addpropertybyname") {
host_moduletest_assert_action("addpropertybyname") {
deps = []
}

File diff suppressed because one or more lines are too long

View File

@ -1,14 +0,0 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
3.3

View File

@ -13,19 +13,19 @@
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("hugearray_first") {
host_moduletest_assert_action("hugearray_first") {
deps = []
}
host_moduletest_action("hugearray_second") {
host_moduletest_assert_action("hugearray_second") {
deps = []
}
host_moduletest_action("hugearray_third") {
host_moduletest_assert_action("hugearray_third") {
deps = []
}
host_moduletest_action("hugearray") {
host_moduletest_assert_action("hugearray") {
extra_modules = [
"hugearray_first",
"hugearray_second",

View File

@ -1,17 +0,0 @@
# Copyright (c) 2023 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
hugearray test start
33333
18001
0

View File

@ -20,4 +20,4 @@
* @tc.require: issueI5NO8G
*/
var string = "hugearray test start"
print(string)
assert_equal(string, "hugearray test start")

View File

@ -27,4 +27,4 @@ for (let i = 0; i < 100000; i++) {
arr.push({val : i});
}
}
print(arr.length);
assert_equal(arr.length, 33333);

View File

@ -26,4 +26,4 @@ do {
v2["lastIndexOf"](...16);
} catch (e) {}
} while (t++ < 18000)
print(t);
assert_equal(t, 18001);

View File

@ -24,4 +24,4 @@ let arr2 = [].slice.call(bytes);
while (arr2.length) {
arr2.pop();
}
print(arr2.length);
assert_equal(arr2.length, 0);

View File

@ -13,6 +13,6 @@
import("//arkcompiler/ets_runtime/test/test_helper.gni")
host_moduletest_action("multiconstpoolarray") {
host_moduletest_assert_action("multiconstpoolarray") {
deps = []
}

View File

@ -1,14 +0,0 @@
# Copyright (c) 2021 Huawei Device Co., Ltd.
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
foo foo2

View File

@ -12794,4 +12794,5 @@ var arr = [
}
]
print(arr[0](), arr[1]())
assert_equal(arr[0](), "foo")
assert_equal(arr[1](), "foo2")

File diff suppressed because it is too large Load Diff