Add TDD test cases

Add TDD test cases to verify code correctness.

Issue: I63A8K
Tests: host/device ut, ark standalone build
Signed-off-by: songqi <songqi32@huawei.com>
Change-Id: Ib8b4675ee9f3fb25193f2fee1c28316468a44622
This commit is contained in:
songqi 2022-11-26 17:59:39 +08:00
parent 6f9df73c6b
commit 4bb9132b76
7 changed files with 186 additions and 4 deletions

View File

@ -321,6 +321,7 @@ if (!ark_standalone_build) {
"$ark_root/libpandabase/tests:unittest",
"$ark_root/libpandafile/tests:unittest",
"$ark_root/libziparchive/tests:unittest",
"$ark_root/plugins/ecmascript/tests:unittest",
"$ark_root/runtime/tests:unittest",
]
}
@ -331,6 +332,7 @@ if (!ark_standalone_build) {
"$ark_root/libpandabase/tests:host_unittest",
"$ark_root/libpandafile/tests:host_unittest",
"$ark_root/libziparchive/tests:host_unittest",
"$ark_root/plugins/ecmascript/tests:host_unittest",
"$ark_root/runtime/tests:host_unittest",
]
}

View File

@ -25,7 +25,6 @@ host_unittest_action("LibPandaBaseTest") {
"bit_vector_test.cpp",
"cframe_layout_test.cpp",
"code_allocator_test.cpp",
"error_test.cpp",
"json_parser_test.cpp",
"logger_test.cpp",
"math_helpers_test.cpp",
@ -39,10 +38,13 @@ host_unittest_action("LibPandaBaseTest") {
"utf_test.cpp",
]
if (!is_mingw && !is_mac && target_os != "ios") {
if (is_linux) {
sources += [
"genmc/mutex_test_2.cpp",
"unix_error_test.cpp",
"unix_exec_test.cpp",
"unix_file_test.cpp",
"unix_library_loader_test.cpp",
"unix_native_stack_test.cpp",
]
}

View File

@ -21,8 +21,11 @@ namespace panda::test {
HWTEST(ErrorTest, ToStringTest, testing::ext::TestSize.Level0)
{
panda::os::Error err("error");
ASSERT_STREQ(err.ToString().c_str(), "error");
panda::os::Error err1("error");
ASSERT_EQ(err1.ToString(), "error");
panda::os::Error err2(1);
ASSERT_EQ(err2.ToString(), "Operation not permitted");
}
} // namespace panda::test

View File

@ -0,0 +1,29 @@
/*
* 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.
*/
#include <gtest/gtest.h>
#include "os/exec.h"
namespace panda::test {
HWTEST(UnixExecTest, ExecTest, testing::ext::TestSize.Level0)
{
auto res = os::exec::Exec("ls", " -l", "/data");
ASSERT_TRUE(res.HasValue());
ASSERT_EQ(res.Value(), 1);
}
} // namespace panda::test

View File

@ -0,0 +1,31 @@
/*
* 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.
*/
#include <gtest/gtest.h>
#include "os/library_loader.h"
namespace panda::test {
HWTEST(LibraryLoaderTest, LoadTest, testing::ext::TestSize.Level0)
{
remove("./test_library_loader.txt");
auto res = os::library_loader::Load("./test_library_loader.txt");
ASSERT_FALSE(res.HasValue());
ASSERT_EQ(res.Error().ToString(),
"./test_library_loader.txt: cannot open shared object file: No such file or directory");
}
} // namespace panda::test

View File

@ -0,0 +1,44 @@
# 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("//arkcompiler/runtime_core/ark_config.gni")
import("$ark_root/tests/test_helper.gni")
host_unittest_action("PluginsTest") {
module_out_path = module_output_path
sources = [ "ecmascript_meta_test.cpp" ]
configs = [
"$ark_root:ark_config",
"$ark_root/assembler:arkassembler_public_config",
"$ark_root/libpandabase:arkbase_public_config",
sdk_libc_secshared_config,
]
deps = [
"$ark_root/assembler:libarkassembler_static",
"$ark_root/libpandabase:libarkbase_static",
sdk_libc_secshared_dep,
]
}
group("unittest") {
testonly = true
deps = [ ":PluginsTest" ]
}
group("host_unittest") {
testonly = true
deps = [ ":PluginsTestAction" ]
}

View File

@ -0,0 +1,71 @@
/*
* 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.
*/
#include <gtest/gtest.h>
#include "plugins/ecmascript/assembler/extension/ecmascript_meta.h"
namespace panda::test {
HWTEST(EcmaScriptMetaTest, ValidateTest, testing::ext::TestSize.Level0)
{
pandasm::extensions::ecmascript::RecordMetadata rmd;
pandasm::Metadata::Error err("Attribute 'ecmascript.extends' must have a value",
pandasm::Metadata::Error::Type::MISSING_VALUE);
std::optional<pandasm::Metadata::Error> result1 = rmd.SetAttribute("ecmascript.extends");
ASSERT_TRUE(result1.has_value());
ASSERT_EQ(err.GetMessage(), result1->GetMessage());
ASSERT_EQ(err.GetType(), result1->GetType());
std::optional<pandasm::Metadata::Error> result2 = rmd.SetAttribute("ecmascript.annotation");
ASSERT_FALSE(result2.has_value());
std::optional<pandasm::Metadata::Error> result3 = rmd.SetAttributeValue("ecmascript.extends", "value");
ASSERT_FALSE(result3.has_value());
std::optional<pandasm::Metadata::Error> result4 = rmd.SetAttributeValue("ecmascript.annotation", "value");
ASSERT_TRUE(result4.has_value());
ASSERT_EQ(result4->GetMessage(), "Attribute 'ecmascript.annotation' must not have a value");
ASSERT_EQ(result4->GetType(), pandasm::Metadata::Error::Type::UNEXPECTED_VALUE);
std::optional<pandasm::Metadata::Error> result5 = rmd.SetAttributeValue("attribute", "bool");
ASSERT_TRUE(result5.has_value());
ASSERT_EQ(result5->GetMessage(), "Unknown attribute 'attribute'");
std::optional<pandasm::Metadata::Error> result6 = rmd.SetAttribute("ecmascript.annotation");
ASSERT_TRUE(result6.has_value());
ASSERT_EQ(result6->GetMessage(), "Attribute 'ecmascript.annotation' already defined");
}
HWTEST(EcmaScriptMetaTest, SetAndRemoveFlagsTest, testing::ext::TestSize.Level0)
{
pandasm::extensions::ecmascript::RecordMetadata rmd;
rmd.SetAttribute("attribute");
rmd.SetAttribute("external");
rmd.SetAttribute("ecmascript.annotation");
ASSERT_FALSE(rmd.GetAttribute("attribute"));
ASSERT_TRUE(rmd.GetAttribute("external"));
ASSERT_TRUE(rmd.GetAttribute("ecmascript.annotation"));
rmd.RemoveAttribute("attribute");
ASSERT_FALSE(rmd.GetAttribute("attribute"));
rmd.RemoveAttribute("external");
ASSERT_FALSE(rmd.GetAttribute("external"));
rmd.RemoveAttribute("ecmascript.annotation");
ASSERT_FALSE(rmd.GetAttribute("ecmascript.annotation"));
}
} // namespace panda::test