Add TS Aot Test Framework

Add TS Aot test framework: supprot running aot whole process test automatically and throwing error messages at each step.

Add tonumber, not, neg module test.

Fix assembler judement in RunPipeline

Add --snapshot-output-file option.

Signed-off-by: ding <dingding5@huawei.com>
Change-Id: Ica09e907c1f03547c1ba80bf639a53d923c01a16
This commit is contained in:
ding 2022-04-25 21:23:42 +08:00
parent 10df7b2d21
commit 671630a0fd
61 changed files with 579 additions and 250 deletions

2
.gitignore vendored
View File

@ -13,3 +13,5 @@ tags
.cache .cache
*.swp *.swp
*.abc *.abc
*.ll
*.m

View File

@ -92,8 +92,8 @@ group("ark_js_host_unittest") {
# js bytecode test # js bytecode test
deps += [ "//ark/js_runtime/test/moduletest:ark_js_moduletest" ] deps += [ "//ark/js_runtime/test/moduletest:ark_js_moduletest" ]
# ts bytecode test # ts aot test
# deps += [ "//ark/js_runtime/test/aottest:ark_aottest"] deps += [ "//ark/js_runtime/test/aottest:ark_aot_test" ]
} }
} }

View File

@ -139,6 +139,6 @@ int Main(const int argc, const char **argv)
int main(const int argc, const char **argv) int main(const int argc, const char **argv)
{ {
auto result = panda::ecmascript::kungfu::Main(argc, argv); auto result = panda::ecmascript::kungfu::Main(argc, argv);
COMPILER_LOG(INFO) << (result == 0 ? "ts aot execute success" : "ts aot execute failed"); COMPILER_LOG(INFO) << (result == 0 ? "ts aot compile success" : "ts aot compile failed");
return result; return result;
} }

View File

@ -66,7 +66,8 @@ bool PassManager::Compile(const std::string &fileName, const std::string &triple
TSLoader *tsLoader = vm_->GetTSLoader(); TSLoader *tsLoader = vm_->GetTSLoader();
SnapShot snapShot(vm_); SnapShot snapShot(vm_);
CVector<JSTaggedType> constStringTable = tsLoader->GetConstStringTable(); CVector<JSTaggedType> constStringTable = tsLoader->GetConstStringTable();
snapShot.MakeSnapShot(reinterpret_cast<uintptr_t>(constStringTable.data()), constStringTable.size(), "snapshot"); const CString snapshotPath(vm_->GetJSOptions().GetSnapshotOutputFile().c_str());
snapShot.MakeSnapShot(reinterpret_cast<uintptr_t>(constStringTable.data()), constStringTable.size(), snapshotPath);
return true; return true;
} }

View File

@ -104,7 +104,7 @@ void StubCompiler::RunPipeline(LLVMModule &module)
for (size_t i = 0; i < callSigns.size(); i++) { for (size_t i = 0; i < callSigns.size(); i++) {
Circuit circuit; Circuit circuit;
if (!callSigns[i]->HasConstructor()) { if (!callSigns[i]->HasConstructor() || callSigns[i]->IsAsmStub()) {
continue; continue;
} }
Stub* stub = static_cast<Stub*>(callSigns[i]->GetConstructor()(reinterpret_cast<void*>(&circuit))); Stub* stub = static_cast<Stub*>(callSigns[i]->GetConstructor()(reinterpret_cast<void*>(&circuit)));

View File

@ -120,10 +120,11 @@ EcmaVM::EcmaVM(JSRuntimeOptions options)
void EcmaVM::TryLoadSnapshotFile() void EcmaVM::TryLoadSnapshotFile()
{ {
if (VerifyFilePath("snapshot")) { const CString snapshotPath(options_.GetSnapshotOutputFile().c_str());
if (VerifyFilePath(snapshotPath)) {
SnapShot snapShot(this); SnapShot snapShot(this);
#if !defined(PANDA_TARGET_WINDOWS) && !defined(PANDA_TARGET_MAC) #if !defined(PANDA_TARGET_WINDOWS) && !defined(PANDA_TARGET_MAC)
snapShot.SnapShotDeserialize(SnapShotType::TS_LOADER, "snapshot"); snapShot.SnapShotDeserialize(SnapShotType::TS_LOADER, snapshotPath);
#endif #endif
} }
} }

View File

@ -71,6 +71,7 @@ public:
parser->Add(&snapshot_deserialize_enabled_); parser->Add(&snapshot_deserialize_enabled_);
parser->Add(&icu_data_path_); parser->Add(&icu_data_path_);
parser->Add(&startup_time_); parser->Add(&startup_time_);
parser->Add(&snapshotOutputFile_);
} }
bool IsEnableArkTools() const bool IsEnableArkTools() const
@ -515,6 +516,16 @@ public:
return startup_time_.WasSet(); return startup_time_.WasSet();
} }
std::string GetSnapshotOutputFile() const
{
return snapshotOutputFile_.GetValue();
}
void SetSnapshotOutputFile(std::string value)
{
snapshotOutputFile_.SetValue(std::move(value));
}
private: private:
static constexpr uint64_t INTERNAL_MEMORY_SIZE_LIMIT_DEFAULT = 2147483648; static constexpr uint64_t INTERNAL_MEMORY_SIZE_LIMIT_DEFAULT = 2147483648;
static constexpr uint32_t HEAP_SIZE_LIMIT_DEFAULT = 536870912; static constexpr uint32_t HEAP_SIZE_LIMIT_DEFAULT = 536870912;
@ -595,6 +606,9 @@ private:
PandArg<std::string> logCompiledMethods {"log-compiled-methods", PandArg<std::string> logCompiledMethods {"log-compiled-methods",
R"(none)", R"(none)",
R"(print stub or aot logs in units of method, "none": no log, "all": every method)"}; R"(print stub or aot logs in units of method, "none": no log, "all": every method)"};
PandArg<std::string> snapshotOutputFile_ {"snapshot-output-file",
R"(snapshot)",
R"(Path to snapshot output file. Default: "snapshot")"};
}; };
} // namespace panda::ecmascript } // namespace panda::ecmascript

View File

@ -78,7 +78,7 @@ void JSPandaFile::Initialize()
isModule_ = true; isModule_ = true;
} }
if (!HasTsTypes() && std::strcmp(TS_TYPES_CLASS, desc) == 0) { if (!HasTSTypes() && std::strcmp(TS_TYPES_CLASS, desc) == 0) {
cda.EnumerateFields([&](panda_file::FieldDataAccessor &fieldAccessor) -> void { cda.EnumerateFields([&](panda_file::FieldDataAccessor &fieldAccessor) -> void {
panda_file::File::EntityId fieldNameId = fieldAccessor.GetNameId(); panda_file::File::EntityId fieldNameId = fieldAccessor.GetNameId();
panda_file::File::StringData sd = pf_->GetStringData(fieldNameId); panda_file::File::StringData sd = pf_->GetStringData(fieldNameId);

View File

@ -101,7 +101,7 @@ public:
bool IsModule() const; bool IsModule() const;
bool HasTsTypes() const bool HasTSTypes() const
{ {
return hasTSTypes_; return hasTSTypes_;
} }

View File

@ -47,7 +47,7 @@ const JSPandaFile *JSPandaFileManager::LoadAotInfoFromPf(const CString &filename
return nullptr; return nullptr;
} }
if (!jsPandaFile->HasTsTypes()) { if (!jsPandaFile->HasTSTypes()) {
LOG_ECMA(ERROR) << filename << " has no type info"; LOG_ECMA(ERROR) << filename << " has no type info";
return nullptr; return nullptr;
} }

View File

@ -11,10 +11,22 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
group("ark_aottest") { group("ark_aot_test") {
testonly = true testonly = true
deps = [ deps = [
"add:addAction", "add:addAction",
"helloworld:helloworldAction", "and:andAction",
"ashr:ashrAction",
"definefunc:definefuncAction",
"exp:expAction",
"helloaot:helloaotAction",
"neg:negAction",
"not:notAction",
"or:orAction",
"shl:shlAction",
"shr:shrAction",
"sub:subAction",
"tonumber:tonumberAction",
"xor:xorAction",
] ]
} }

View File

@ -13,6 +13,6 @@
import("//ark/js_runtime/test/test_helper.gni") import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("expdyn") { host_aot_test_action("add") {
deps = [] deps = []
} }

23
test/aottest/add/add.ts Normal file
View File

@ -0,0 +1,23 @@
/*
* 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.
*/
declare function print(num:number):string;
var a:number = 3;
var b:number = 5;
print(a + b);
var c:number = 3.1;
var d:number = 5.2;
print(c + d);

View File

@ -11,4 +11,5 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
hello world 8
8.3

View File

@ -13,6 +13,6 @@
import("//ark/js_runtime/test/test_helper.gni") import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("or2dyn") { host_aot_test_action("and") {
deps = [] deps = []
} }

View File

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

View File

@ -11,10 +11,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
r1 = 1 1
r2 = 1 1
r3 = 1 1
r4 = 1 1
r5 = 1 1
r6 = 1 1
r7 = 15 15

View File

@ -13,6 +13,6 @@
import("//ark/js_runtime/test/test_helper.gni") import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("shl2dyn") { host_aot_test_action("ashr") {
deps = [] deps = []
} }

View File

@ -17,36 +17,36 @@ declare function print(str:any):string;
var x1 = 16; var x1 = 16;
var y1 = 1; var y1 = 1;
var r1 = x1 >>> y1; var r1 = x1 >>> y1;
print("r1 = " + r1); print(r1);
var x2 = 16.8; var x2 = 16.8;
var y2 = 1; var y2 = 1;
var r2 = x2 >>> y2; var r2 = x2 >>> y2;
print("r2 = " + r2); print(r2);
var x3 = 16; var x3 = 16;
var y3 = 1.8; var y3 = 1.8;
var r3 = x3 >>> y3; var r3 = x3 >>> y3;
print("r3 = " + r3); print(r3);
var x4 = 16.8; var x4 = 16.8;
var y4 = 1.8; var y4 = 1.8;
var r4 = x4 >>> y4; var r4 = x4 >>> y4;
print("r4 = " + r4); print(r4);
var x5:any = "16"; var x5:any = "16";
var y5:number = 1; var y5:number = 1;
var r5 = x5 >>> y5; var r5 = x5 >>> y5;
print("r5 = " + r5); print(r5);
var x6 = -16; var x6 = -16;
var y6 = 1; var y6 = 1;
var r6 = x6 >>> y6; var r6 = x6 >>> y6;
print("r6 = " + r6); print(r6);
var x7 = 16; var x7 = 16;
var y7 = -1; var y7 = -1;
var r7 = x7 >>> y7; var r7 = x7 >>> y7;
print("r7 = " + r7); print(r7);
// not supported type: string, bigint // not supported type: string, bigint

View File

@ -11,10 +11,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
r1 = 8 8
r2 = 8 8
r3 = 8 8
r4 = 8 8
r5 = 8 8
r6 = -8 2147483640
r7 = 0 0

View File

@ -13,6 +13,6 @@
import("//ark/js_runtime/test/test_helper.gni") import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("definefunc") { host_aot_test_action("definefunc") {
deps = [] deps = []
} }

View File

@ -11,4 +11,4 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
hello world hello world

18
test/aottest/exp/BUILD.gn Normal file
View File

@ -0,0 +1,18 @@
# 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.
import("//ark/js_runtime/test/test_helper.gni")
host_aot_test_action("exp") {
deps = []
}

View File

@ -17,36 +17,36 @@ declare function print(str:any):string;
var x1 = 16; var x1 = 16;
var y1 = 2; var y1 = 2;
var r1 = x1 ** y1; var r1 = x1 ** y1;
print("r1 = " + r1); print(r1);
var x2 = 16.8; var x2 = 16.8;
var y2 = 2; var y2 = 2;
var r2 = x2 ** y2; var r2 = x2 ** y2;
print("r2 = " + r2); print(r2);
var x3 = 16; var x3 = 16;
var y3 = 1.8; var y3 = 1.8;
var r3 = x3 ** y3; var r3 = x3 ** y3;
print("r3 = " + r3); print(r3);
var x4 = 16.8; var x4 = 16.8;
var y4 = 1.8; var y4 = 1.8;
var r4 = x4 ** y4; var r4 = x4 ** y4;
print("r4 = " + r4); print(r4);
var x5:any = "16"; var x5:any = "16";
var y5:number = 2; var y5:number = 2;
var r5 = x5 ** y5; var r5 = x5 ** y5;
print("r5 = " + r5); print(r5);
var x6 = -16; var x6 = -16;
var y6 = 2; var y6 = 2;
var r6 = x6 ** y6; var r6 = x6 ** y6;
print("r6 = " + r6); print(r6);
var x7 = 16; var x7 = 16;
var y7 = -2; var y7 = -2;
var r7 = x7 ** y7; var r7 = x7 ** y7;
print("r7 = " + r7); print(r7);
// not supported type: string, bigint // not supported type: string, bigint

View File

@ -11,10 +11,10 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
r1 = 8 256
r2 = 8 282.24
r3 = 8 147.0333894396205
r4 = 8 160.53018533925774
r5 = 8 256
r6 = 2147483640 256
r7 = 0 0.00390625

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.
r1 = 256
r2 = 282.24
r3 = 147.0333894396205
r4 = 160.53018533925774
r5 = 256
r6 = 256
r7 = 0.00390625

View File

@ -13,6 +13,6 @@
import("//ark/js_runtime/test/test_helper.gni") import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("and2dyn") { host_aot_test_action("helloaot") {
deps = [] deps = []
} }

View File

@ -11,10 +11,4 @@
# See the License for the specific language governing permissions and # See the License for the specific language governing permissions and
# limitations under the License. # limitations under the License.
r1 = 32 hello aot !
r2 = 32
r3 = 32
r4 = 32
r5 = 32
r6 = -32
r7 = 0

View File

@ -14,4 +14,4 @@
*/ */
declare function print(str:string):string; declare function print(str:string):string;
print("hello world"); print("hello aot !");

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.
import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("helloworld") {
deps = []
}

View File

@ -14,7 +14,7 @@
debug=no debug=no
root_dir=$(shell pwd) root_dir=$(shell pwd)
ifeq ($(test), ) ifeq ($(test), )
test_name=helloworld test_name=helloaot
else else
test_name=$(test) test_name=$(test)
endif endif

18
test/aottest/neg/BUILD.gn Normal file
View File

@ -0,0 +1,18 @@
# 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.
import("//ark/js_runtime/test/test_helper.gni")
host_aot_test_action("neg") {
deps = []
}

View File

@ -0,0 +1,17 @@
# 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.
-5
-6.7
NaN
NaN

27
test/aottest/neg/neg.ts Normal file
View File

@ -0,0 +1,27 @@
/*
* 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.
*/
declare function print(num:number):string;
var a:number = 5;
print(-a);
var b:number = 6.7;
print(-b);
var c:number = NaN;
print(-c)
var d:string = "abc";
print(-d);

18
test/aottest/not/BUILD.gn Normal file
View File

@ -0,0 +1,18 @@
# 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.
import("//ark/js_runtime/test/test_helper.gni")
host_aot_test_action("not") {
deps = []
}

View File

@ -0,0 +1,17 @@
# 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.
-6
-7
-1
-1

27
test/aottest/not/not.ts Normal file
View File

@ -0,0 +1,27 @@
/*
* 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.
*/
declare function print(num:number):string;
var a:number = 5;
print(~a);
var b:number = 6.7;
print(~b);
var c:number = NaN;
print(~c)
var d:string = "abc";
print(~d);

View File

@ -13,6 +13,6 @@
import("//ark/js_runtime/test/test_helper.gni") import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("sub") { host_aot_test_action("or") {
deps = [] deps = []
} }

View File

@ -0,0 +1,20 @@
# 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.
17
17
17
17
17
-15
-1

View File

@ -17,36 +17,36 @@ declare function print(str:any):string;
var x1 = 16; var x1 = 16;
var y1 = 1; var y1 = 1;
var r1 = x1 | y1; var r1 = x1 | y1;
print("r1 = " + r1); print(r1);
var x2 = 16.8; var x2 = 16.8;
var y2 = 1; var y2 = 1;
var r2 = x2 | y2; var r2 = x2 | y2;
print("r2 = " + r2); print(r2);
var x3 = 16; var x3 = 16;
var y3 = 1.8; var y3 = 1.8;
var r3 = x3 | y3; var r3 = x3 | y3;
print("r3 = " + r3); print(r3);
var x4 = 16.8; var x4 = 16.8;
var y4 = 1.8; var y4 = 1.8;
var r4 = x4 | y4; var r4 = x4 | y4;
print("r4 = " + r4); print(r4);
var x5:any = "16"; var x5:any = "16";
var y5:number = 1; var y5:number = 1;
var r5 = x5 | y5; var r5 = x5 | y5;
print("r5 = " + r5); print(r5);
var x6 = -16; var x6 = -16;
var y6 = 1; var y6 = 1;
var r6 = x6 | y6; var r6 = x6 | y6;
print("r6 = " + r6); print(r6);
var x7 = 16; var x7 = 16;
var y7 = -1; var y7 = -1;
var r7 = x7 | y7; var r7 = x7 | y7;
print("r7 = " + r7); print(r7);
// not supported type: string, bigint // 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.
r1 = 17
r2 = 17
r3 = 17
r4 = 17
r5 = 17
r6 = -15
r7 = -1

18
test/aottest/shl/BUILD.gn Normal file
View File

@ -0,0 +1,18 @@
# 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.
import("//ark/js_runtime/test/test_helper.gni")
host_aot_test_action("shl") {
deps = []
}

View File

@ -0,0 +1,20 @@
# 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.
32
32
32
32
32
-32
0

View File

@ -17,36 +17,36 @@ declare function print(str:any):string;
var x1 = 16; var x1 = 16;
var y1 = 1; var y1 = 1;
var r1 = x1 << y1; var r1 = x1 << y1;
print("r1 = " + r1); print(r1);
var x2 = 16.8; var x2 = 16.8;
var y2 = 1; var y2 = 1;
var r2 = x2 << y2; var r2 = x2 << y2;
print("r2 = " + r2); print(r2);
var x3 = 16; var x3 = 16;
var y3 = 1.8; var y3 = 1.8;
var r3 = x3 << y3; var r3 = x3 << y3;
print("r3 = " + r3); print(r3);
var x4 = 16.8; var x4 = 16.8;
var y4 = 1.8; var y4 = 1.8;
var r4 = x4 << y4; var r4 = x4 << y4;
print("r4 = " + r4); print(r4);
var x5:any = "16"; var x5:any = "16";
var y5:number = 1; var y5:number = 1;
var r5 = x5 << y5; var r5 = x5 << y5;
print("r5 = " + r5); print(r5);
var x6 = -16; var x6 = -16;
var y6 = 1; var y6 = 1;
var r6 = x6 << y6; var r6 = x6 << y6;
print("r6 = " + r6); print(r6);
var x7 = 16; var x7 = 16;
var y7 = -1; var y7 = -1;
var r7 = x7 << y7; var r7 = x7 << y7;
print("r7 = " + r7); print(r7);
// not supported type: string, bigint // not supported type: string, bigint

18
test/aottest/shr/BUILD.gn Normal file
View File

@ -0,0 +1,18 @@
# 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.
import("//ark/js_runtime/test/test_helper.gni")
host_aot_test_action("shr") {
deps = []
}

View File

@ -0,0 +1,20 @@
# 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.
8
8
8
8
8
-8
0

View File

@ -17,36 +17,36 @@ declare function print(str:any):string;
var x1 = 16; var x1 = 16;
var y1 = 1; var y1 = 1;
var r1 = x1 >> y1; var r1 = x1 >> y1;
print("r1 = " + r1); print(r1);
var x2 = 16.8; var x2 = 16.8;
var y2 = 1; var y2 = 1;
var r2 = x2 >> y2; var r2 = x2 >> y2;
print("r2 = " + r2); print(r2);
var x3 = 16; var x3 = 16;
var y3 = 1.8; var y3 = 1.8;
var r3 = x3 >> y3; var r3 = x3 >> y3;
print("r3 = " + r3); print(r3);
var x4 = 16.8; var x4 = 16.8;
var y4 = 1.8; var y4 = 1.8;
var r4 = x4 >> y4; var r4 = x4 >> y4;
print("r4 = " + r4); print(r4);
var x5:any = "16"; var x5:any = "16";
var y5:number = 1; var y5:number = 1;
var r5 = x5 >> y5; var r5 = x5 >> y5;
print("r5 = " + r5); print(r5);
var x6 = -16; var x6 = -16;
var y6 = 1; var y6 = 1;
var r6 = x6 >> y6; var r6 = x6 >> y6;
print("r6 = " + r6); print(r6);
var x7 = 16; var x7 = 16;
var y7 = -1; var y7 = -1;
var r7 = x7 >> y7; var r7 = x7 >> y7;
print("r7 = " + r7); print(r7);
// not supported type: string, bigint // not supported type: string, bigint

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.
import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("shr2dyn") {
deps = []
}

18
test/aottest/sub/BUILD.gn Normal file
View File

@ -0,0 +1,18 @@
# 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.
import("//ark/js_runtime/test/test_helper.gni")
host_aot_test_action("sub") {
deps = []
}

View File

@ -13,6 +13,6 @@
import("//ark/js_runtime/test/test_helper.gni") import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("ashr2dyn") { host_aot_test_action("tonumber") {
deps = [] deps = []
} }

View File

@ -0,0 +1,16 @@
# 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.
6
8.7
NaN

View File

@ -0,0 +1,25 @@
/*
* 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.
*/
declare function print(str:number):string;
var a:number = 5;
a++;
print(a);
var b:number = 7.7;
b++;
print(b);
var c:number = NaN;
c++;
print(c);

18
test/aottest/xor/BUILD.gn Normal file
View File

@ -0,0 +1,18 @@
# 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.
import("//ark/js_runtime/test/test_helper.gni")
host_aot_test_action("xor") {
deps = []
}

View File

@ -0,0 +1,20 @@
# 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.
14
14
14
14
14
-16
-16

View File

@ -17,36 +17,36 @@ declare function print(str:any):string;
var x1 = 15; var x1 = 15;
var y1 = 1; var y1 = 1;
var r1 = x1 ^ y1; var r1 = x1 ^ y1;
print("r1 = " + r1); print(r1);
var x2 = 15.8; var x2 = 15.8;
var y2 = 1; var y2 = 1;
var r2 = x2 ^ y2; var r2 = x2 ^ y2;
print("r2 = " + r2); print(r2);
var x3 = 15; var x3 = 15;
var y3 = 1.8; var y3 = 1.8;
var r3 = x3 ^ y3; var r3 = x3 ^ y3;
print("r3 = " + r3); print(r3);
var x4 = 15.8; var x4 = 15.8;
var y4 = 1.8; var y4 = 1.8;
var r4 = x4 ^ y4; var r4 = x4 ^ y4;
print("r4 = " + r4); print(r4);
var x5:any = "15"; var x5:any = "15";
var y5:number = 1; var y5:number = 1;
var r5 = x5 ^ y5; var r5 = x5 ^ y5;
print("r5 = " + r5); print(r5);
var x6 = -15; var x6 = -15;
var y6 = 1; var y6 = 1;
var r6 = x6 ^ y6; var r6 = x6 ^ y6;
print("r6 = " + r6); print(r6);
var x7 = 15; var x7 = 15;
var y7 = -1; var y7 = -1;
var r7 = x7 ^ y7; var r7 = x7 ^ y7;
print("r7 = " + r7); print(r7);
// not supported type: string, bigint // not supported type: string, bigint

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.
import("//ark/js_runtime/test/test_helper.gni")
host_aottest_action("xor2dyn") {
deps = []
}

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.
r1 = 14
r2 = 14
r3 = 14
r4 = 14
r5 = 14
r6 = -16
r7 = -16

View File

@ -33,6 +33,7 @@ def parse_args():
parser.add_argument('--script-options', help='execute script options') parser.add_argument('--script-options', help='execute script options')
parser.add_argument('--script-args', help='args of script') parser.add_argument('--script-args', help='args of script')
parser.add_argument('--expect-output', help='expect output') parser.add_argument('--expect-output', help='expect output')
parser.add_argument('--expect-sub-output', help='expect sub output')
parser.add_argument('--expect-file', help='expect file') parser.add_argument('--expect-file', help='expect file')
parser.add_argument('--env-path', help='LD_LIBRARY_PATH env') parser.add_argument('--env-path', help='LD_LIBRARY_PATH env')
args = parser.parse_args() args = parser.parse_args()
@ -47,7 +48,7 @@ def judge_output(args):
cmd += input_args.script_options cmd += input_args.script_options
if input_args.script_args: if input_args.script_args:
cmd += " " + input_args.script_args cmd += " " + input_args.script_args
subp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, subp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env={'LD_LIBRARY_PATH': str(input_args.env_path)}) env={'LD_LIBRARY_PATH': str(input_args.env_path)})
try: try:
out, err = subp.communicate(timeout=300) # units: s out, err = subp.communicate(timeout=300) # units: s
@ -61,6 +62,10 @@ def judge_output(args):
print_str = out.decode('UTF-8') print_str = out.decode('UTF-8')
print(print_str) print(print_str)
raise RuntimeError("Run [" + cmd + "] failed!") raise RuntimeError("Run [" + cmd + "] failed!")
elif args.expect_sub_output:
err_str = err.decode('UTF-8') # log system use std::cerr
if err_str.find(args.expect_sub_output) == -1:
raise RuntimeError("Run [" + cmd + "] failed!")
elif args.expect_file: elif args.expect_file:
with open(args.expect_file, mode='r') as file: with open(args.expect_file, mode='r') as file:
# skip license header # skip license header

View File

@ -158,47 +158,63 @@ template("host_moduletest_action") {
} }
} }
template("host_aottest_action") { template("host_aot_test_action") {
_target_name_ = "${target_name}" _target_name_ = "${target_name}"
_deps_ = invoker.deps _deps_ = invoker.deps
_is_aot_ = false
if (defined(invoker.is_aot) && invoker.is_aot) {
_is_aot_ = true
}
_test_js_path_ = "./${_target_name_}.ts" _test_ts_path_ = "./${_target_name_}.ts"
_test_abc_path_ = "$target_out_dir/${_target_name_}.abc" _test_abc_path_ = "$target_out_dir/${_target_name_}.abc"
_test_m_path_ = "$target_out_dir/${_target_name_}.m"
_test_snapshot_path_ = "$target_out_dir/snapshot"
_test_expect_path_ = "./expect_output.txt" _test_expect_path_ = "./expect_output.txt"
ts2abc_gen_abc("gen_${_target_name_}_abc") { ts2abc_gen_abc("gen_${_target_name_}_abc") {
extra_visibility = [ ":*" ] # Only targets in this file can depend on this. extra_visibility = [ ":*" ] # Only targets in this file can depend on this.
extra_dependencies = _deps_ extra_dependencies = _deps_
src_js = rebase_path(_test_js_path_) src_js = rebase_path(_test_ts_path_)
dst_file = rebase_path(_test_abc_path_) dst_file = rebase_path(_test_abc_path_)
extra_args = [ "--debug" ] extra_args = [ "--debug" ]
if (_is_aot_) {
extra_args += [ "--aot" ]
}
in_puts = [ in_puts = [
_test_js_path_, _test_ts_path_,
_test_expect_path_, _test_expect_path_,
] ]
out_puts = [ _test_abc_path_ ] out_puts = [ _test_abc_path_ ]
} }
_extra_aots_ = [] _script_args_ = rebase_path(_test_abc_path_)
if (defined(invoker._extra_aots_)) {
foreach(aot, invoker.extra_aots) { action("genStubAction") {
_extra_aots_ += [ "$target_out_dir/${aot}.abc" ] testonly = true
}
} _host_stub_target_ = "//ark/js_runtime/ecmascript/compiler:ark_stub_compiler(${host_toolchain})"
_test_abc_paths_ = rebase_path(_test_abc_path_) _root_out_dir_ = get_label_info(_host_stub_target_, "root_out_dir")
foreach(extra_aot, _extra_aots_) { deps = [ _host_stub_target_ ]
_test_abc_paths_ += ":" + rebase_path(extra_aot) deps += _deps_
script = "//ark/js_runtime/test/run_ark_executable.py"
_stub_compile_options_ =
" --com-stub-out=com_stub.m --bc-stub-out=bc_stub.m"
args = [
"--script-file",
rebase_path(_root_out_dir_) + "/ark/ark_js_runtime/ark_stub_compiler",
"--script-options",
_stub_compile_options_,
"--expect-sub-output",
"stub compiler run finish, result condition(T/F):true",
"--env-path",
rebase_path(_root_out_dir_) + "/ark/ark:" + rebase_path(_root_out_dir_) +
"/ark/ark_js_runtime:" + rebase_path(_root_out_dir_) +
"/common/${icu_path}:" +
rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
]
outputs = [ "$target_out_dir/" ]
} }
action("${_target_name_}Action") { action("${_target_name_}AotCompileAction") {
testonly = true testonly = true
_host_aot_target_ = "//ark/js_runtime/ecmascript/compiler:ark_aot_compiler(${host_toolchain})" _host_aot_target_ = "//ark/js_runtime/ecmascript/compiler:ark_aot_compiler(${host_toolchain})"
@ -211,19 +227,59 @@ template("host_aottest_action") {
script = "//ark/js_runtime/test/run_ark_executable.py" script = "//ark/js_runtime/test/run_ark_executable.py"
aot_options = " " _aot_compile_options_ =
if (defined(invoker.is_set_maxNonmovableSpaceCapacity) && " --aot-output-file=" + rebase_path(_test_m_path_) +
invoker.is_set_maxNonmovableSpaceCapacity) { " --snapshot-output-file=" + rebase_path(_test_snapshot_path_)
aot_options += "--maxNonmovableSpaceCapacity=524288" # 0.5M
}
args = [ args = [
"--script-file", "--script-file",
rebase_path(_root_out_dir_) + "/ark/ark_js_runtime/ark_aot_compiler", rebase_path(_root_out_dir_) + "/ark/ark_js_runtime/ark_aot_compiler",
"--script-options", "--script-options",
aot_options, _aot_compile_options_,
"--script-args", "--script-args",
_test_abc_paths_, _script_args_,
"--expect-sub-output",
"ts aot compile success",
"--env-path",
rebase_path(_root_out_dir_) + "/ark/ark:" + rebase_path(_root_out_dir_) +
"/ark/ark_js_runtime:" + rebase_path(_root_out_dir_) +
"/common/${icu_path}:" +
rebase_path("//prebuilts/clang/ohos/linux-x86_64/llvm/lib/"),
]
inputs = [ _test_abc_path_ ]
outputs = [ "$target_out_dir/${_target_name_}/compile_${_target_name_}/" ]
}
action("${_target_name_}Action") {
testonly = true
_host_jsvm_target_ =
"//ark/js_runtime/ecmascript/js_vm:ark_js_vm(${host_toolchain})"
_root_out_dir_ = get_label_info(_host_jsvm_target_, "root_out_dir")
deps = [
":${_target_name_}AotCompileAction",
":genStubAction",
":gen_${_target_name_}_abc",
_host_jsvm_target_,
]
deps += _deps_
script = "//ark/js_runtime/test/run_ark_executable.py"
_aot_run_options_ =
" --aot-output-file=" + rebase_path(_test_m_path_) +
" --snapshot-output-file=" + rebase_path(_test_snapshot_path_) +
" --enable-ts-aot=true" + " --enable-stub-aot=true" + " --asmInter=1"
args = [
"--script-file",
rebase_path(_root_out_dir_) + "/ark/ark_js_runtime/ark_js_vm",
"--script-options",
_aot_run_options_,
"--script-args",
_script_args_,
"--expect-file", "--expect-file",
rebase_path(_test_expect_path_), rebase_path(_test_expect_path_),
"--env-path", "--env-path",
@ -234,7 +290,6 @@ template("host_aottest_action") {
] ]
inputs = [ _test_abc_path_ ] inputs = [ _test_abc_path_ ]
inputs += _extra_aots_
outputs = [ "$target_out_dir/${_target_name_}/" ] outputs = [ "$target_out_dir/${_target_name_}/" ]
} }