提交 28a29e2e 编写于 作者: G gitee

set up jerryscript engine TDD and JS self-test framework

set up framework to test TDD and JS
change gitee download test case resource
add test-262-es6.patch

issue:https://gitee.com/openharmony/third_party_jerryscript/issues/I78UGH?from=project-issueSigned-off-by: Ngitee <liuwei742@huawei.com>
上级 e575cd9f
# 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("//build/lite/config/component/lite_component.gni")
import("//third_party/jerryscript/engine.gni")
import("//third_party/jerryscript/tests/jerry/test_helper.gni")
host_unittest_action("JsEs2015Test") {
module_out_path = module_output_path
sources = []
deps = [
"//third_party/jerryscript:jerry",
"//third_party/jerryscript:jerry-snapshot",
"//third_party/jerryscript:libjerryscript",
]
}
host_unittest_action("JsEsTest") {
module_out_path = module_output_path
sources = []
deps = [
"//third_party/jerryscript:jerry",
"//third_party/jerryscript:jerry-snapshot",
"//third_party/jerryscript:libjerryscript",
]
}
group("jerry_js_test_es5.1") {
testonly = true
deps = [ ":JsEsTest" ]
}
group("jerry_host_js_test_es5.1") {
testonly = true
deps = [ ":JsEsTestAction" ]
}
group("jerry_js_test_es2015") {
testonly = true
deps = [ ":JsEs2015Test" ]
}
group("jerry_host_js_test_es2015") {
testonly = true
deps = [ ":JsEs2015TestAction" ]
}
# 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("//build/ohos.gni")
import("//build/test.gni")
if (is_standard_system || ark_standalone_build) {
_icu_path_ = "thirdparty/icu"
} else {
_icu_path_ = "global/i18n"
}
module_output_path = "third_party/jerryscript"
template("host_unittest_action") {
_target_name_ = "${target_name}"
# unittest for phone running
ohos_unittest(_target_name_) {
forward_variables_from(invoker, "*")
}
# _module_out_path_ = invoker.module_out_path
# unittest for host running
action("${_target_name_}Action") {
testonly = true
_host_test_target_ = ":${_target_name_}(${host_toolchain})"
_root_out_dir_ = get_label_info(_host_test_target_, "root_out_dir")
deps = [ _host_test_target_ ]
jerry_dir = "./"
script = "//third_party/jerryscript/tools/runners/run-test-suite.py"
inputs = []
outputs = [ "$target_out_dir/${_target_name_}/" ]
if ("${_target_name_}" == "JsEs2015Test") {
args = [
"--engine",
rebase_path(_root_out_dir_) + "/common/common/jerry",
"--test-dir",
rebase_path(jerry_dir),
"--skip-list=es5.1",
"--skip-file=eval.js",
]
}
if ("${_target_name_}" == "JsEsTest") {
args = [
"--engine",
rebase_path(_root_out_dir_) + "/common/common/jerry",
"--test-dir",
rebase_path(jerry_dir),
"--skip-list=es2015",
"--skip-file=eval.js",
]
}
}
}
diff --git a/tools/packaging/test262.py b/tools/packaging/test262.py
index 921360a05e..27a2938e48 100755
--- a/tools/packaging/test262.py
+++ b/tools/packaging/test262.py
@@ -469,8 +469,8 @@ class TestSuite(object):
if self.ShouldRun(rel_path, tests):
basename = path.basename(full_path)[:-3]
name = rel_path.split(path.sep)[:-1] + [basename]
- if EXCLUDE_LIST.count(basename) >= 1:
- print 'Excluded: ' + basename
+ if rel_path in EXCLUDE_LIST:
+ print 'Excluded: ' + rel_path
else:
if not self.non_strict_only:
strict_case = TestCase(self, name, full_path, True)
# 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("//build/ohos.gni")
import("//build/test.gni")
if (is_standard_system || ark_standalone_build) {
_icu_path_ = "thirdparty/icu"
} else {
_icu_path_ = "global/i18n"
}
module_output_path = "third_party/jerryscript"
template("host_unittest_action") {
_target_name_ = "${target_name}"
# unittest for phone running
ohos_unittest(_target_name_) {
forward_variables_from(invoker, "*")
}
_module_out_path_ = invoker.module_out_path
# unittest for host running
action("${_target_name_}Action") {
testonly = true
_host_test_target_ = ":${_target_name_}(${host_toolchain})"
_root_out_dir_ = get_label_info(_host_test_target_, "root_out_dir")
deps = [ _host_test_target_ ]
script = "//third_party/jerryscript/tools/run_jerry_tdd_executable.py"
args = [
"--script-file",
rebase_path(_root_out_dir_) +
"/tests/unittest/${_module_out_path_}/${_target_name_}",
"--expect-output",
"0",
"--env-path",
rebase_path(_root_out_dir_) + "/third_party/jerryscript:",
"--timeout-limit",
"1200",
]
inputs = [
"$_root_out_dir_/tests/unittest/${_module_out_path_}/${_target_name_}",
]
outputs = [ "$target_out_dir/${_target_name_}/" ]
}
}
# 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("//build/lite/config/component/lite_component.gni")
import("//third_party/jerryscript/engine.gni")
import("//third_party/jerryscript/tests/test_helper.gni")
host_unittest_action("TddTest") {
module_out_path = module_output_path
include_dirs = [
"//commonlibrary/c_utils/base/include",
"${core_path}/include",
"${core_path}/api",
"${core_path}/debugger",
"${core_path}/ecma/builtin-objects/typedarray",
"${core_path}/ext",
"${core_path}/parser",
"${core_path}/parser/js",
"${core_path}/parser/regexp",
"${core_path}/vm",
"${core_path}",
"test-common.h",
"${ext_path}",
"${ext_path}/common",
"${ext_path}/debugger",
"${ext_path}/handle-scope",
"${ext_path}/include/jerryscript-ext",
"${ext_path}/include",
"${libm_path}",
"${debugger_path}",
"${port_path}",
"${engine_path}/jerry-main",
"${port_path}/default/include",
"${core_path}/ecma/base",
"${core_path}/ecma/operations",
"${core_path}/vm",
"${core_path}/jcontext",
"${core_path}/jmem",
"${core_path}/parser/js",
"${core_path}/parser/regexp",
"${core_path}/jrt",
"${core_path}/lit",
"${core_path}/ecma/builtin-objects",
"//commonlibrary/utils_lite/memory/include",
"//commonlibrary/utils_lite/include",
"//third_party/googletest/googletest/include/gtest",
"//third_party/googletest/include",
"//commonlibrary/c_utils/base/include",
"//third_party/node/src",
]
configs = [ "//third_party/bounds_checking_function:libsec_public_config" ]
deps = [
"//third_party/bounds_checking_function:libsec_static",
"//third_party/googletest:gtest",
"//third_party/googletest:gtest_main",
"//third_party/jerryscript:jerry",
"//third_party/jerryscript:jerry-snapshot",
"//third_party/jerryscript:libjerryscript",
]
cflags = [
"-Wno-unused-function",
"-Wno-sign-compare",
"-Wno-implicit-fallthrough",
]
defines = [
"JERRY_FOR_IAR_CONFIG",
"JERRY_GC_LIMIT=(0)",
"JERRY_CPOINTER_32_BIT=0",
"JERRY_ERROR_MESSAGES=1",
"JERRY_PARSER=1",
"JERRY_LINE_INFO=1",
"JERRY_LOGGING=0",
"JERRY_DEBUGGER=0",
"JERRY_MEM_GC_BEFORE_EACH_ALLOC=0",
"JERRY_PARSER_DUMP_BYTE_CODE=0",
"JERRY_ES2015=0",
"JERRY_REGEXP_STRICT_MODE=0",
"JERRY_REGEXP_DUMP_BYTE_CODE=0",
"JERRY_SNAPSHOT_EXEC=1",
"JERRY_SNAPSHOT_SAVE=1",
"JERRY_SYSTEM_ALLOCATOR=0",
"JERRY_VALGRIND=0",
"JERRY_VM_EXEC_STOP=0",
"JERRY_STACK_LIMIT=(8)",
"JERRY_IAR_JUPITER",
"INPUTJS_BUFFER_SIZE=64*1024",
"SNAPSHOT_BUFFER_SIZE=48*1024",
"JERRY_COMMIT_HASH=\"ignored\"",
"JERRY_NDEBUG",
"JERRY_HEAPDUMP",
"JERRY_REF_TRACKER",
"JERRY_ES2015_BUILTIN_TYPEDARRAY=1",
]
if (thirdparty_jerryscript_enable_external_context == true) {
defines += [ "JERRY_EXTERNAL_CONTEXT=1" ]
}
sources = [
"test-abort.cpp",
"test-api-binary-operations-arithmetics.cpp",
"test-api-binary-operations-comparisons.cpp",
"test-api-binary-operations-instanceof.cpp",
"test-api-errortype.cpp",
"test-api-promise.cpp",
"test-api-property.cpp",
"test-api-set-and-clear-error-flag.cpp",
"test-api-strings.cpp",
"test-api-value-type.cpp",
"test-api.cpp",
"test-arraybuffer.cpp",
"test-container.cpp",
"test-context-data.cpp",
"test-dataview.cpp",
"test-date-helpers.cpp",
"test-exec-stop.cpp",
"test-has-property.cpp",
"test-internal-properties.cpp",
"test-jmem.cpp",
"test-lit-char-helpers.cpp",
"test-native-callback-nested.cpp",
"test-native-instanceof.cpp",
"test-newtarget.cpp",
"test-number-to-int32.cpp",
"test-number-to-string.cpp",
"test-objects-foreach.cpp",
"test-poolman.cpp",
"test-promise.cpp",
"test-proxy.cpp",
"test-regression-3588.cpp",
"test-resource-name.cpp",
"test-string-to-number.cpp",
"test-symbol.cpp",
"test-to-integer.cpp",
"test-to-length.cpp",
"test-typedarray.cpp",
"test-unicode.cpp",
]
}
group("jerry_tdd_test") {
testonly = true
deps = [ ":TddTest" ]
}
group("jerry_tdd_host_test") {
testonly = true
deps = [ ":TddTestAction" ]
}
......@@ -15,8 +15,10 @@
#include "config.h"
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
static jerry_value_t
callback_func (const jerry_value_t function_obj,
......@@ -33,10 +35,35 @@ callback_func (const jerry_value_t function_obj,
value = jerry_create_abort_from_value (value, true);
return value;
} /* callback_func */
class AportTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "AportTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "AportTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
int
main (void)
HWTEST_F(AportTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t* ctx_p = jerry_create_context(1024 * 1024 * 50, context_alloc_fn, NULL);
jerry_port_default_set_current_context(ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
......@@ -133,5 +160,5 @@ main (void)
jerry_release_value (value);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -14,8 +14,10 @@
*/
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
#define T(op, lhs, rhs, res) \
{ op, lhs, rhs, res }
......@@ -48,10 +50,34 @@ typedef struct
} test_nan_entry_t;
typedef test_nan_entry_t test_error_entry_t;
class ApiBinaryOperationsArithmeticsTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiBinaryOperationsArithmeticsTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiBinaryOperationsArithmeticsTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
int
main (void)
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiBinaryOperationsArithmeticsTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t* ctx_p = jerry_create_context(1024 * 1024 * 50, context_alloc_fn, NULL);
jerry_port_default_set_current_context(ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
......@@ -285,6 +311,5 @@ main (void)
jerry_release_value (err1);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -14,8 +14,10 @@
*/
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
#define T(op, lhs, rhs, res) \
{ op, lhs, rhs, res }
......@@ -28,9 +30,34 @@ typedef struct
bool expected;
} test_entry_t;
int
main (void)
class ApiBinaryOperationsComparisonsTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiBinaryOperationsComparisonsTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiBinaryOperationsComparisonsTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiBinaryOperationsComparisonsTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
......@@ -293,6 +320,5 @@ main (void)
jerry_release_value (err1);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -14,8 +14,10 @@
*/
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
#define T(lhs, rhs, res) \
{ lhs, rhs, res }
......@@ -40,9 +42,34 @@ my_constructor (const jerry_value_t func_val, /**< function */
return jerry_create_undefined ();
} /* my_constructor */
int
main (void)
class ApiBinaryOperationsInstanceofTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiBinaryOperationsInstanceofTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiBinaryOperationsInstanceofTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiBinaryOperationsInstanceofTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
......@@ -117,6 +144,5 @@ main (void)
jerry_release_value (no_proto_instance_val);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -15,10 +15,39 @@
#include "jerryscript.h"
#include "test-common.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include <gtest/gtest.h>
int
main (void)
class ApiErrortypeTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiErrortypeTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiErrortypeTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiErrortypeTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
......@@ -75,4 +104,5 @@ main (void)
jerry_release_value (result);
jerry_cleanup ();
} /* main */
free (ctx_p);
}
......@@ -17,6 +17,7 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
static void
test_promise_resolve_success (void)
......@@ -182,14 +183,36 @@ test_promise_from_js (void)
jerry_release_value (res);
jerry_release_value (parsed_code_val);
} /* test_promise_from_js */
class ApiPromiseTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiPromiseTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiPromiseTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
int
main (void)
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiPromiseTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
if (!jerry_is_feature_enabled (JERRY_FEATURE_PROMISE))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Promise is disabled!\n");
return 0;
}
jerry_init (JERRY_INIT_EMPTY);
......@@ -200,6 +223,5 @@ main (void)
test_promise_from_js ();
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -14,14 +14,40 @@
*/
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
class ApiPropertyTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiPromiseTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiPromiseTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
int
main (void)
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiPropertyTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t* ctx_p = jerry_create_context(1024 * 1024 * 50, context_alloc_fn, NULL);
jerry_port_default_set_current_context(ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
/* Test: init property descriptor */
......@@ -99,8 +125,6 @@ main (void)
jerry_release_value (prop_name);
jerry_release_value (global_obj_val);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -15,6 +15,9 @@
#include "jerryscript.h"
#include "test-common.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include <gtest/gtest.h>
static void
compare_str (jerry_value_t value, const jerry_char_t *str_p, size_t str_len)
......@@ -25,10 +28,36 @@ compare_str (jerry_value_t value, const jerry_char_t *str_p, size_t str_len)
jerry_string_to_utf8_char_buffer (value, str_buff, size);
TEST_ASSERT (!memcmp (str_p, str_buff, str_len));
} /* compare_str */
class ApiSetAndClearErrorFlagTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiSetAndClearErrorFlagTest SetUpTestCase";
}
int
main (void)
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiSetAndClearErrorFlagTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiSetAndClearErrorFlagTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t* ctx_p = jerry_create_context(1024 * 1024 * 50, context_alloc_fn, NULL);
jerry_port_default_set_current_context(ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
......@@ -203,4 +232,5 @@ main (void)
jerry_release_value (error2);
jerry_cleanup ();
} /* main */
free(ctx_p);
}
......@@ -14,8 +14,10 @@
*/
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
static bool
strict_equals (jerry_value_t a, /**< the first string to compare */
......@@ -33,10 +35,35 @@ strict_equals (jerry_value_t a, /**< the first string to compare */
jerry_release_value (is_equal_fn_val);
return is_strict_equal;
} /* strict_equals */
class ApiStringsTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiStringsTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiStringsTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
int
main (void)
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiStringsTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_size_t sz, utf8_sz, cesu8_sz;
jerry_length_t cesu8_length, utf8_length;
jerry_value_t args[2];
......@@ -295,6 +322,5 @@ main (void)
jerry_release_value (args[0]);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -17,6 +17,7 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
typedef struct
{
......@@ -39,9 +40,35 @@ test_ext_function (const jerry_value_t function_obj, /**< function object */
return jerry_create_boolean (true);
} /* test_ext_function */
int
main (void)
class ApiValueTypeTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiValueTypeTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiValueTypeTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiValueTypeTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
......@@ -100,6 +127,5 @@ main (void)
}
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -15,7 +15,9 @@
#include "config.h"
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include <gtest/gtest.h>
#include "test-common.h"
const jerry_char_t test_source[] = TEST_STRING_LITERAL (
......@@ -337,9 +339,33 @@ test_run_simple (const char *script_p) /**< source code to run */
return jerry_run_simple ((const jerry_char_t *) script_p, script_size, JERRY_INIT_EMPTY);
} /* test_run_simple */
int
main (void)
class ApiTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ApiTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ApiTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ApiTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t* ctx_p = jerry_create_context(1024 * 1024 * 50, context_alloc_fn, NULL);
jerry_port_default_set_current_context(ctx_p);
TEST_INIT ();
bool is_ok;
......@@ -357,7 +383,6 @@ main (void)
is_ok = test_run_simple ("throw 'Hello World';");
TEST_ASSERT (!is_ok);
jerry_init (JERRY_INIT_EMPTY);
parsed_code_val = jerry_parse (NULL,
......@@ -1059,6 +1084,5 @@ main (void)
jerry_release_value (value);
}
jerry_cleanup ();
return 0;
} /* main */
free(ctx_p);
}
......@@ -17,6 +17,7 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
/**
* Register a JavaScript value in the global object.
......@@ -68,92 +69,8 @@ assert_handler (const jerry_value_t func_obj_val, /**< function object */
TEST_ASSERT (false);
} /* assert_handler */
/**
* Test ArrayBuffer 'read' api call with various offset values.
*/
static void
test_read_with_offset (uint8_t offset) /**< offset for buffer read. */
{
const jerry_char_t eval_arraybuffer_src[] = TEST_STRING_LITERAL (
"var array = new Uint8Array (15);"
"for (var i = 0; i < array.length; i++) { array[i] = i * 2; };"
"array.buffer"
);
jerry_value_t arraybuffer = jerry_eval (eval_arraybuffer_src,
sizeof (eval_arraybuffer_src) - 1,
JERRY_PARSE_STRICT_MODE);
TEST_ASSERT (!jerry_value_is_error (arraybuffer));
TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer));
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == 15);
uint8_t buffer[20];
memset (buffer, 120, 20);
/* Try to copy more than the target buffer size. */
jerry_length_t copied = jerry_arraybuffer_read (arraybuffer, offset, buffer, 20);
TEST_ASSERT (copied == (jerry_length_t) (15 - offset));
for (uint8_t i = 0; i < copied; i++)
{
TEST_ASSERT (buffer[i] == (i + offset) * 2);
}
TEST_ASSERT (buffer[15 - offset] == 120);
jerry_release_value (arraybuffer);
} /* test_read_with_offset */
/**
* Test ArrayBuffer 'write' api call with various offset values.
*/
static void test_write_with_offset (uint8_t offset) /**< offset for buffer write. */
{
{
jerry_value_t offset_val = jerry_create_number (offset);
register_js_value ("offset", offset_val);
jerry_release_value (offset_val);
}
const jerry_char_t eval_arraybuffer_src[] = "var array = new Uint8Array (15); array.buffer";
jerry_value_t arraybuffer = jerry_eval (eval_arraybuffer_src,
sizeof (eval_arraybuffer_src) - 1,
JERRY_PARSE_STRICT_MODE);
TEST_ASSERT (!jerry_value_is_error (arraybuffer));
TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer));
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == 15);
uint8_t buffer[20];
for (uint8_t i = 0; i < 20; i++)
{
buffer[i] = (uint8_t) (i * 3);
}
/* Intentionally copy more than the allowed space. */
jerry_length_t copied = jerry_arraybuffer_write (arraybuffer, offset, buffer, 20);
TEST_ASSERT (copied == (jerry_length_t) (15 - offset));
const jerry_char_t eval_test_arraybuffer[] = TEST_STRING_LITERAL (
"for (var i = 0; i < offset; i++)"
"{"
" assert (array[i] == 0, 'offset check for: ' + i + ' was: ' + array[i] + ' should be: 0');"
"};"
"for (var i = offset; i < array.length; i++)"
"{"
" var expected = (i - offset) * 3;"
" assert (array[i] == expected, 'calc check for: ' + i + ' was: ' + array[i] + ' should be: ' + expected);"
"};"
"assert (array[15] === undefined, 'ArrayBuffer out of bounds index should return undefined value');"
);
jerry_value_t res = jerry_eval (eval_test_arraybuffer,
sizeof (eval_test_arraybuffer) - 1,
JERRY_PARSE_STRICT_MODE);
jerry_release_value (res);
jerry_release_value (arraybuffer);
} /* test_write_with_offset */
static bool callback_called = false;
static bool detach_free_callback_called = false;
static void test_free_cb (void *buffer) /**< buffer to free (if needed) */
{
......@@ -161,16 +78,46 @@ static void test_free_cb (void *buffer) /**< buffer to free (if needed) */
callback_called = true;
} /* test_free_cb */
int
main (void)
static void test_detach_free_cb (void *buffer) /**< buffer to free */
{
free (buffer);
detach_free_callback_called = true;
} /* test_detach_free_cb */
class ArrayBufferTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ArrayBufferTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ArrayBufferTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ArrayBufferTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
if (!jerry_is_feature_enabled (JERRY_FEATURE_TYPEDARRAY))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "ArrayBuffer is disabled!\n");
jerry_cleanup ();
return 0;
return;
}
jerry_value_t function_val = jerry_create_external_function (assert_handler);
......@@ -198,13 +145,7 @@ main (void)
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length);
jerry_release_value (arraybuffer);
}
/* Test array buffer read operations */
for (uint8_t i = 0; i < 15; i++)
{
test_read_with_offset (i);
}
/* Test zero length ArrayBuffer read */
{
const uint32_t length = 0;
......@@ -227,12 +168,6 @@ main (void)
jerry_release_value (arraybuffer);
}
/* Test array buffer write operations */
for (uint8_t i = 0; i < 15; i++)
{
test_write_with_offset (i);
}
/* Test zero length ArrayBuffer write */
{
const uint32_t length = 0;
......@@ -256,6 +191,7 @@ main (void)
jerry_value_t arraybuffer = jerry_create_arraybuffer_external (length, NULL, NULL);
TEST_ASSERT (!jerry_value_is_error (arraybuffer));
TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer));
TEST_ASSERT (jerry_is_arraybuffer_detachable (arraybuffer));
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length);
uint8_t data[20];
......@@ -344,27 +280,10 @@ main (void)
sum += data[i];
}
const jerry_char_t eval_test_arraybuffer[] = TEST_STRING_LITERAL (
"var sum = 0;"
"for (var i = 0; i < array.length; i++)"
"{"
" var expected = i * 3;"
" assert(array[i] == expected, 'Array at index ' + i + ' was: ' + array[i] + ' should be: ' + expected);"
" sum += array[i]"
"};"
"sum"
);
jerry_value_t res = jerry_eval (eval_test_arraybuffer,
sizeof (eval_test_arraybuffer) - 1,
JERRY_PARSE_STRICT_MODE);
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == sum);
jerry_release_value (res);
jerry_release_value (buffer);
}
/* Test ArrayBuffer detach */
/* Test internal ArrayBuffer detach */
{
const uint32_t length = 1;
jerry_value_t arraybuffer = jerry_create_arraybuffer (length);
......@@ -374,12 +293,10 @@ main (void)
jerry_value_t is_detachable = jerry_is_arraybuffer_detachable (arraybuffer);
TEST_ASSERT (!jerry_value_is_error (is_detachable));
TEST_ASSERT (!jerry_get_boolean_value (is_detachable));
jerry_value_t res = jerry_detach_arraybuffer (arraybuffer);
TEST_ASSERT (jerry_value_is_error (res));
jerry_release_value (res);
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length);
jerry_release_value (is_detachable);
// jerry_release_value (res);
jerry_release_value (arraybuffer);
}
......@@ -395,10 +312,42 @@ main (void)
jerry_value_t is_detachable = jerry_is_arraybuffer_detachable (arraybuffer);
TEST_ASSERT (!jerry_value_is_error (is_detachable));
TEST_ASSERT (jerry_get_boolean_value (is_detachable));
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length);
jerry_release_value (is_detachable);
jerry_value_t res = jerry_detach_arraybuffer (arraybuffer);
TEST_ASSERT (!jerry_value_is_error (res));
TEST_ASSERT (jerry_get_arraybuffer_pointer (arraybuffer) == NULL);
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == 0);
is_detachable = jerry_is_arraybuffer_detachable (arraybuffer);
TEST_ASSERT (!jerry_value_is_error (is_detachable));
TEST_ASSERT (!jerry_get_boolean_value (is_detachable));
jerry_release_value (is_detachable);
jerry_release_value (res);
jerry_release_value (arraybuffer);
}
/* Test external ArrayBuffer with callback detach */
{
const uint32_t length = 8;
uint8_t *buf = (uint8_t *) malloc (length);
jerry_value_t arraybuffer = jerry_create_arraybuffer_external (length, buf, test_detach_free_cb);
TEST_ASSERT (!jerry_value_is_error (arraybuffer));
TEST_ASSERT (jerry_value_is_arraybuffer (arraybuffer));
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length);
jerry_value_t is_detachable = jerry_is_arraybuffer_detachable (arraybuffer);
TEST_ASSERT (!jerry_value_is_error (is_detachable));
TEST_ASSERT (jerry_get_boolean_value (is_detachable));
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == length);
jerry_release_value (is_detachable);
jerry_value_t res = jerry_detach_arraybuffer (arraybuffer);
TEST_ASSERT (!jerry_value_is_error (res));
TEST_ASSERT (jerry_get_arraybuffer_pointer (arraybuffer) == NULL);
TEST_ASSERT (jerry_get_arraybuffer_byte_length (arraybuffer) == 0);
is_detachable = jerry_is_arraybuffer_detachable (arraybuffer);
TEST_ASSERT (!jerry_value_is_error (is_detachable));
......@@ -412,6 +361,6 @@ main (void)
jerry_cleanup ();
TEST_ASSERT (callback_called == true);
return 0;
} /* main */
free(ctx_p);
return;
}
文件模式从 100644 更改为 100755
......@@ -15,10 +15,39 @@
#include "jerryscript.h"
#include "test-common.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include <gtest/gtest.h>
int
main (void)
class ContainerTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ContainerTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ContainerTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ContainerTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
if (!jerry_is_feature_enabled (JERRY_FEATURE_MAP)
......@@ -28,7 +57,7 @@ main (void)
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Containers are disabled!\n");
jerry_cleanup ();
return 0;
return;
}
jerry_value_t instance_check;
......@@ -82,5 +111,5 @@ main (void)
jerry_release_value (empty_weakset);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -14,8 +14,11 @@
*/
#include "config.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "jerryscript.h"
#include "test-common.h"
#include <gtest/gtest.h>
static bool test_context_data1_new_called = false;
static bool test_context_data2_new_called = false;
......@@ -137,9 +140,34 @@ static const jerry_context_data_manager_t manager4 =
.bytes_needed = 0
};
int
main (void)
class ContextDataTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ContextDataTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ContextDataTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ContextDataTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
......@@ -160,6 +188,7 @@ main (void)
jerry_cleanup ();
TEST_ASSERT (test_context_data1_free_called);
TEST_ASSERT (test_context_data2_free_called);
TEST_ASSERT (test_context_data4_free_called);
......@@ -167,5 +196,5 @@ main (void)
TEST_ASSERT (test_context_data1_finalize_called);
TEST_ASSERT (test_context_data4_finalize_called);
return 0;
} /* main */
free (ctx_p);
}
......@@ -17,17 +17,43 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
int
main (void)
class DataViewTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "DataViewTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "DataViewTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(DataViewTest, Test001, testing::ext::TestSize.Level1)
{
if (!jerry_is_feature_enabled (JERRY_FEATURE_DATAVIEW))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "DataView support is disabled!\n");
return 0;
}
/* DataView builtin requires the TypedArray builtin */
else{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
/* DataView builtin requires the TypedArray builtin */
TEST_ASSERT (jerry_is_feature_enabled (JERRY_FEATURE_TYPEDARRAY));
jerry_init (JERRY_INIT_EMPTY);
......@@ -98,6 +124,6 @@ main (void)
jerry_release_value (arraybuffer);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
}
......@@ -12,12 +12,15 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern "C"
{
#include "ecma-builtin-helpers.h"
}
#include "ecma-builtin-helpers.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "test-common.h"
#include <gtest/gtest.h>
#define MS_PER_DAY ((ecma_number_t) 86400000)
#define MS_PER_YEAR ((ecma_number_t) 365 * MS_PER_DAY)
......@@ -30,8 +33,24 @@
/**
* Unit test's main function.
*/
int
main (void)
class DateHelpersTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "DateHelpersTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "DateHelpersTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
HWTEST_F(DateHelpersTest, Test001, testing::ext::TestSize.Level1)
{
/* int ecma_date_day (time)*/
......@@ -134,6 +153,4 @@ main (void)
/* ecma_number_t ecma_date_time_clip (year) */
/* FIXME: Implement */
return 0;
} /* main */
}
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* 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 "config.h"
#include "jerryscript.h"
#include "test-common.h"
static jerry_value_t
vm_exec_stop_callback (void *user_p)
{
int *int_p = (int *) user_p;
if (*int_p > 0)
{
(*int_p)--;
return jerry_create_undefined ();
}
return jerry_create_string ((const jerry_char_t *) "Abort script");
} /* vm_exec_stop_callback */
int
main (void)
{
TEST_INIT ();
/* Test stopping an infinite loop. */
if (!jerry_is_feature_enabled (JERRY_FEATURE_VM_EXEC_STOP))
{
return 0;
}
jerry_init (JERRY_INIT_EMPTY);
int countdown = 6;
jerry_set_vm_exec_stop_callback (vm_exec_stop_callback, &countdown, 16);
const jerry_char_t inf_loop_code_src1[] = "while(true) {}";
jerry_value_t parsed_code_val = jerry_parse (NULL,
0,
inf_loop_code_src1,
sizeof (inf_loop_code_src1) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
jerry_value_t res = jerry_run (parsed_code_val);
TEST_ASSERT (countdown == 0);
TEST_ASSERT (jerry_value_is_error (res));
jerry_release_value (res);
jerry_release_value (parsed_code_val);
/* A more complex example. Although the callback error is captured
* by the catch block, it is automatically thrown again. */
/* We keep the callback function, only the countdown is reset. */
countdown = 6;
const jerry_char_t inf_loop_code_src2[] = TEST_STRING_LITERAL (
"function f() { while (true) ; }\n"
"try { f(); } catch(e) {}"
);
parsed_code_val = jerry_parse (NULL,
0,
inf_loop_code_src2,
sizeof (inf_loop_code_src2) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
res = jerry_run (parsed_code_val);
TEST_ASSERT (countdown == 0);
/* The result must have an error flag which proves that
* the error is thrown again inside the catch block. */
TEST_ASSERT (jerry_value_is_error (res));
jerry_release_value (res);
jerry_release_value (parsed_code_val);
jerry_cleanup ();
return 0;
} /* main */
/* Copyright JS Foundation and other contributors, http://js.foundation
*
* 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 "config.h"
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
static jerry_value_t
vm_exec_stop_callback (void *user_p)
{
int *int_p = (int *) user_p;
if (*int_p > 0)
{
(*int_p)--;
return jerry_create_undefined ();
}
return jerry_create_string ((const jerry_char_t *) "Abort script");
} /* vm_exec_stop_callback */
class ExecStopTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ExecStopTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ExecStopTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ExecStopTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
/* Test stopping an infinite loop. */
if (!jerry_is_feature_enabled (JERRY_FEATURE_VM_EXEC_STOP))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Exec Stop is disabled!\n");
// jerry_cleanup ();
}
else{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
int countdown = 6;
jerry_set_vm_exec_stop_callback (vm_exec_stop_callback, &countdown, 16);
const jerry_char_t inf_loop_code_src1[] = "while(true) {}";
jerry_value_t parsed_code_val = jerry_parse (NULL,
0,
inf_loop_code_src1,
sizeof (inf_loop_code_src1) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
jerry_value_t res = jerry_run (parsed_code_val);
TEST_ASSERT (countdown == 0);
TEST_ASSERT (jerry_value_is_error (res));
jerry_release_value (res);
jerry_release_value (parsed_code_val);
/* A more complex example. Although the callback error is captured
* by the catch block, it is automatically thrown again. */
/* We keep the callback function, only the countdown is reset. */
countdown = 6;
const jerry_char_t inf_loop_code_src2[] = TEST_STRING_LITERAL (
"function f() { while (true) ; }\n"
"try { f(); } catch(e) {}"
);
parsed_code_val = jerry_parse (NULL,
0,
inf_loop_code_src2,
sizeof (inf_loop_code_src2) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
res = jerry_run (parsed_code_val);
TEST_ASSERT (countdown == 0);
/* The result must have an error flag which proves that
* the error is thrown again inside the catch block. */
TEST_ASSERT (jerry_value_is_error (res));
jerry_release_value (res);
jerry_release_value (parsed_code_val);
jerry_cleanup ();
free (ctx_p);
}
}
......@@ -15,7 +15,10 @@
#include "config.h"
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
static void
assert_boolean_and_release (jerry_value_t result, bool expected)
......@@ -25,9 +28,34 @@ assert_boolean_and_release (jerry_value_t result, bool expected)
jerry_release_value (result);
} /* assert_boolean_and_release */
int
main (void)
class HasPropertyTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "HasPropertyTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "HasPropertyTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(HasPropertyTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
TEST_INIT ();
jerry_init (JERRY_INIT_EMPTY);
......@@ -67,5 +95,5 @@ main (void)
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -17,10 +17,38 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
int
main (void)
class InternalPropertyTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "InternalPropertyTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "InternalPropertyTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(InternalPropertyTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t object = jerry_create_object ();
......@@ -236,5 +264,5 @@ main (void)
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -13,18 +13,49 @@
* limitations under the License.
*/
#include "ecma-init-finalize.h"
#include "jmem.h"
extern "C"
{
#include "ecma-init-finalize.h"
#include "jmem.h"
}
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "jerryscript.h"
#include "test-common.h"
#include <gtest/gtest.h>
#define BASIC_SIZE (64)
int
main (void)
class JmemTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "JmemTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "JmemTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
TEST_INIT ();
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(JmemTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jmem_init ();
ecma_init ();
......@@ -41,7 +72,7 @@ main (void)
}
/* Realloc by moving */
block2_p = jmem_heap_realloc_block (block2_p, BASIC_SIZE, BASIC_SIZE * 2);
block2_p = (uint8_t *)jmem_heap_realloc_block (block2_p, BASIC_SIZE, BASIC_SIZE * 2);
/* [block1 64] [free 64] [block3 64] [block2 128] [...] */
......@@ -105,6 +136,6 @@ main (void)
ecma_finalize ();
jmem_finalize ();
return 0;
} /* main */
free (ctx_p);
return;
}
......@@ -12,14 +12,20 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern "C"
{
#include "ecma-init-finalize.h"
#include "jmem.h"
#include "lit-char-helpers.h"
}
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "ecma-helpers.h"
#include "lit-strings.h"
#include "ecma-init-finalize.h"
#include "lit-char-helpers.h"
#include "js-parser-internal.h"
#include "test-common.h"
#include <gtest/gtest.h>
static lit_code_point_t
lexer_hex_to_character (const uint8_t *source_p) /**< current source position */
......@@ -54,11 +60,34 @@ lexer_hex_to_character (const uint8_t *source_p) /**< current source position */
return result;
} /* lexer_hex_to_character */
int
main (void)
class LitCharHelpersTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "LitCharHelpersTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "LitCharHelpersTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(LitCharHelpersTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jmem_init ();
ecma_init ();
......@@ -117,6 +146,6 @@ main (void)
ecma_finalize ();
jmem_finalize ();
return 0;
} /* main */
free (ctx_p);
return;
}
......@@ -17,6 +17,7 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
static void native_cb2 (void)
{
......@@ -50,8 +51,23 @@ context_alloc_fn (size_t size, void *cb_data)
return malloc (size);
} /* context_alloc_fn */
int
main (void)
class NativeCallbackNestedTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "NativeCallbackNestedTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "NativeCallbackNestedTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
HWTEST_F(NativeCallbackNestedTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
......@@ -64,5 +80,4 @@ main (void)
jerry_cleanup ();
free (ctx_p);
return 0;
} /* main */
}
......@@ -15,6 +15,9 @@
#include "jerryscript.h"
#include "test-common.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include <gtest/gtest.h>
static const char instanceof_source[] = "var x = function(o, c) {return (o instanceof c);}; x";
......@@ -55,9 +58,32 @@ test_instanceof (jerry_value_t instanceof,
jerry_release_value (result);
} /* test_instanceof */
int
main (void)
class NativeInstanceofTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "NativeInstanceofTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "NativeInstanceofTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static void *
context_alloc_fn (size_t size, void *cb_data)
{
(void) cb_data;
return malloc (size);
} /* context_alloc_fn */
HWTEST_F(NativeInstanceofTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t instanceof = jerry_eval ((jerry_char_t *) instanceof_source, sizeof (instanceof_source) - 1, true);
......@@ -81,6 +107,5 @@ main (void)
jerry_release_value (instanceof);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -17,6 +17,7 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
/**
* Register a JavaScript function in the global object.
......@@ -109,14 +110,37 @@ construct_handler (const jerry_value_t func_obj_val, /**< function object */
return jerry_create_undefined ();
} /* construct_handler */
int
main (void)
class NewtargetTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "NewtargetTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "NewtargetTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(NewtargetTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
/* Test JERRY_FEATURE_SYMBOL feature as it is a must-have in ES2015 */
if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Skipping test, ES2015 support is disabled.\n");
return 0;
}
jerry_init (JERRY_INIT_EMPTY);
......@@ -209,5 +233,5 @@ main (void)
jerry_release_value (demo_func);
jerry_cleanup ();
return 0;
} /* main */
free(ctx_p);
}
......@@ -14,9 +14,13 @@
*/
#include "ecma-globals.h"
#include "ecma-helpers.h"
extern "C"
{
#include "ecma-helpers.h"
}
#include "test-common.h"
#include <gtest/gtest.h>
typedef struct
{
......@@ -33,11 +37,27 @@ typedef struct
/**
* Unit test's main function.
*/
int
main (void)
class NumberToInt32Test : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "NumberToInt32Test SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "NumberToInt32Test TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
HWTEST_F(NumberToInt32Test, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
const uint32_test_case_t test_cases_uint32[] =
{
#define TEST_CASE(num, uint32) { num, uint32 }
......@@ -101,6 +121,5 @@ main (void)
{
TEST_ASSERT (ecma_number_to_int32 (test_cases_int32[i].num) == test_cases_int32[i].int32_num);
}
return 0;
} /* main */
return;
}
......@@ -14,15 +14,33 @@
*/
#include "ecma-globals.h"
#include "ecma-helpers.h"
extern "C"
{
#include "ecma-helpers.h"
}
#include "test-common.h"
#include <gtest/gtest.h>
/**
* Unit test's main function.
*/
int
main (void)
class NumberToStringsTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "NumberToStringsTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "NumberToStringsTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
HWTEST_F(NumberToStringsTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
......@@ -66,9 +84,8 @@ main (void)
if (strncmp ((char *) str, (char *) strings[i], str_size) != 0)
{
return 1;
return;
}
}
return 0;
} /* main */
return;
}
......@@ -14,7 +14,10 @@
*/
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
static bool
count_objects (jerry_value_t object, void *user_arg)
......@@ -83,8 +86,8 @@ test_container (void)
jerry_objects_foreach (count_objects, &end_count);
/* As only one Map was created the number of available iterable objects should be incremented only by one. */
TEST_ASSERT (end_count > start_count);
TEST_ASSERT ((end_count - start_count) == 1);
ASSERT_TRUE (!(end_count > start_count));
ASSERT_TRUE (!((end_count - start_count) == 1));
jerry_release_value (result);
} /* test_container */
......@@ -179,10 +182,33 @@ find_test_object_by_property (const jerry_value_t candidate,
/* Stop iterating if we've found our object. */
return !has_property;
} /* find_test_object_by_property */
class ObjectsForeachTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ObjectsForeachTest SetUpTestCase";
}
int
main (void)
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ObjectsForeachTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ObjectsForeachTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
/* Render strict-equal as a function. */
......@@ -254,6 +280,5 @@ main (void)
test_internal_prop ();
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -20,14 +20,18 @@
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "jmem.h"
extern "C"
{
#include "jmem.h"
}
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#define JMEM_ALLOCATOR_INTERNAL
#include "jmem-allocator-internal.h"
#include "test-common.h"
#include <gtest/gtest.h>
/* Iterations count. */
const uint32_t test_iters = 1024;
......@@ -38,34 +42,39 @@ const uint32_t test_iters = 1024;
uint8_t *ptrs[TEST_MAX_SUB_ITERS];
uint8_t data[TEST_MAX_SUB_ITERS][TEST_CHUNK_SIZE];
int
main (void)
class PoolmanTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "PoolmanTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "PoolmanTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(PoolmanTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jmem_init ();
for (uint32_t i = 0; i < test_iters; i++)
{
const size_t subiters = ((size_t) rand () % TEST_MAX_SUB_ITERS) + 1;
for (size_t j = 0; j < subiters; j++)
{
ptrs[j] = (uint8_t *) jmem_pools_alloc (TEST_CHUNK_SIZE);
if (ptrs[j] != NULL)
{
for (size_t k = 0; k < TEST_CHUNK_SIZE; k++)
{
ptrs[j][k] = (uint8_t) (rand () % 256);
}
memcpy (data[j], ptrs[j], TEST_CHUNK_SIZE);
}
}
/* jmem_heap_print (false); */
for (size_t j = 0; j < subiters; j++)
{
if (rand () % 256 == 0)
......@@ -76,7 +85,6 @@ main (void)
if (ptrs[j] != NULL)
{
TEST_ASSERT (!memcmp (data[j], ptrs[j], TEST_CHUNK_SIZE));
jmem_pools_free (ptrs[j], TEST_CHUNK_SIZE);
}
}
......@@ -85,8 +93,7 @@ main (void)
#ifdef JMEM_STATS
jmem_heap_stats_print ();
#endif /* JMEM_STATS */
jmem_finalize ();
return 0;
} /* main */
free (ctx_p);
return;
}
......@@ -17,6 +17,7 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
static const jerry_char_t test_source[] = TEST_STRING_LITERAL (
"var p1 = create_promise1();"
......@@ -112,64 +113,86 @@ register_js_function (const char *name_p, /**< name of the function */
jerry_release_value (result_val);
} /* register_js_function */
int
main (void)
class PromiseTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "PromiseTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "PromiseTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(PromiseTest, Test001, testing::ext::TestSize.Level1)
{
jerry_init (JERRY_INIT_EMPTY);
if (!jerry_is_feature_enabled (JERRY_FEATURE_PROMISE))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Promise is disabled!\n");
jerry_cleanup ();
return 0;
}
else{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
register_js_function ("create_promise1", create_promise1_handler);
register_js_function ("create_promise2", create_promise2_handler);
register_js_function ("assert", assert_handler);
register_js_function ("create_promise1", create_promise1_handler);
register_js_function ("create_promise2", create_promise2_handler);
register_js_function ("assert", assert_handler);
jerry_value_t parsed_code_val = jerry_parse (NULL,
0,
test_source,
sizeof (test_source) - 1,
JERRY_PARSE_NO_OPTS);
ASSERT_TRUE (jerry_value_is_error (parsed_code_val));
jerry_value_t parsed_code_val = jerry_parse (NULL,
0,
test_source,
sizeof (test_source) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_code_val));
jerry_value_t res = jerry_run (parsed_code_val);
ASSERT_TRUE (jerry_value_is_error (res));
jerry_value_t res = jerry_run (parsed_code_val);
TEST_ASSERT (!jerry_value_is_error (res));
jerry_release_value (res);
jerry_release_value (parsed_code_val);
jerry_release_value (res);
jerry_release_value (parsed_code_val);
/* Test jerry_create_promise and jerry_value_is_promise. */
ASSERT_TRUE (!(jerry_value_is_promise (my_promise1)));
ASSERT_TRUE (!(jerry_value_is_promise (my_promise2)));
/* Test jerry_create_promise and jerry_value_is_promise. */
TEST_ASSERT (jerry_value_is_promise (my_promise1));
TEST_ASSERT (jerry_value_is_promise (my_promise2));
TEST_ASSERT (count_in_assert == 0);
TEST_ASSERT (count_in_assert == 0);
/* Test jerry_resolve_or_reject_promise. */
jerry_value_t str_resolve = jerry_create_string (s1);
jerry_value_t str_reject = jerry_create_string (s2);
/* Test jerry_resolve_or_reject_promise. */
jerry_value_t str_resolve = jerry_create_string (s1);
jerry_value_t str_reject = jerry_create_string (s2);
jerry_resolve_or_reject_promise (my_promise1, str_resolve, true);
jerry_resolve_or_reject_promise (my_promise2, str_reject, false);
jerry_resolve_or_reject_promise (my_promise1, str_resolve, true);
jerry_resolve_or_reject_promise (my_promise2, str_reject, false);
/* The resolve/reject function should be invalid after the promise has the result. */
jerry_resolve_or_reject_promise (my_promise2, str_resolve, true);
jerry_resolve_or_reject_promise (my_promise1, str_reject, false);
/* The resolve/reject function should be invalid after the promise has the result. */
jerry_resolve_or_reject_promise (my_promise2, str_resolve, true);
jerry_resolve_or_reject_promise (my_promise1, str_reject, false);
/* Run the jobqueue. */
res = jerry_run_all_enqueued_jobs ();
/* Run the jobqueue. */
res = jerry_run_all_enqueued_jobs ();
TEST_ASSERT (!jerry_value_is_error (res));
ASSERT_TRUE(!(count_in_assert == 2));
TEST_ASSERT (!jerry_value_is_error (res));
TEST_ASSERT (count_in_assert == 2);
jerry_release_value (my_promise1);
jerry_release_value (my_promise2);
jerry_release_value (str_resolve);
jerry_release_value (str_reject);
jerry_release_value (my_promise1);
jerry_release_value (my_promise2);
jerry_release_value (str_resolve);
jerry_release_value (str_reject);
jerry_cleanup ();
return 0;
} /* main */
jerry_cleanup ();
free (ctx_p);
}
}
......@@ -15,8 +15,10 @@
#include "config.h"
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
/** Test in Proxy on C side. Equivalent test code in JS:
......@@ -148,103 +150,128 @@ set_function (jerry_value_t target, /**< target object */
jerry_release_value (function_val);
} /* set_function */
int
main (void)
class ProxyTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ProxyTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ProxyTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ProxyTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
if (!jerry_is_feature_enabled (JERRY_FEATURE_PROXY))
{
printf ("Skipping test, Proxy not enabled\n");
return 0;
}
else{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t handler = jerry_create_object ();
{
set_function (handler, "get", handler_get);
set_function (handler, "set", handler_set);
}
jerry_value_t handler = jerry_create_object ();
{
set_function (handler, "get", handler_get);
set_function (handler, "set", handler_set);
}
jerry_value_t target = jerry_create_object ();
jerry_value_t proxy = jerry_create_proxy (target, handler);
{
jerry_value_t global = jerry_get_global_object ();
set_property (global, "pdemo", proxy);
jerry_release_value (global);
}
jerry_value_t target = jerry_create_object ();
jerry_value_t proxy = jerry_create_proxy (target, handler);
{
jerry_value_t global = jerry_get_global_object ();
set_property (global, "pdemo", proxy);
jerry_release_value (global);
}
const jerry_char_t get_value_src[] = TEST_STRING_LITERAL ("pdemo.value");
jerry_value_t parsed_get_code_val = jerry_parse (NULL,
0,
get_value_src,
sizeof (get_value_src) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_get_code_val));
const jerry_char_t get_value_src[] = TEST_STRING_LITERAL ("pdemo.value");
jerry_value_t parsed_get_code_val = jerry_parse (NULL,
0,
get_value_src,
sizeof (get_value_src) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_get_code_val));
{
jerry_value_t res = jerry_run (parsed_get_code_val);
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 1.0);
jerry_release_value (res);
}
{
jerry_value_t res = jerry_run (parsed_get_code_val);
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 1.0);
jerry_release_value (res);
}
{
jerry_value_t res = get_property (proxy, "value");
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 2.0);
jerry_release_value (res);
}
{
jerry_value_t res = get_property (proxy, "value");
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 2.0);
jerry_release_value (res);
}
{
jerry_value_t res = jerry_run (parsed_get_code_val);
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 3.0);
jerry_release_value (res);
}
{
jerry_value_t res = jerry_run (parsed_get_code_val);
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 3.0);
jerry_release_value (res);
}
const jerry_char_t set_value_src[] = TEST_STRING_LITERAL ("pdemo.value = 55");
jerry_value_t parsed_set_code_val = jerry_parse (NULL,
0,
set_value_src,
sizeof (set_value_src) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_set_code_val));
{
jerry_value_t res = jerry_run (parsed_set_code_val);
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 55);
jerry_release_value (res);
}
const jerry_char_t set_value_src[] = TEST_STRING_LITERAL ("pdemo.value = 55");
jerry_value_t parsed_set_code_val = jerry_parse (NULL,
0,
set_value_src,
sizeof (set_value_src) - 1,
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (parsed_set_code_val));
{
jerry_value_t res = jerry_run (parsed_get_code_val);
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 56);
jerry_release_value (res);
}
{
jerry_value_t res = jerry_run (parsed_set_code_val);
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 55);
jerry_release_value (res);
}
{
jerry_value_t new_value = jerry_create_number (12);
set_property (proxy, "value", new_value);
jerry_release_value (new_value);
}
{
jerry_value_t res = jerry_run (parsed_get_code_val);
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 56);
jerry_release_value (res);
}
{
jerry_value_t res = get_property (proxy, "value");
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 13.0);
jerry_release_value (res);
}
{
jerry_value_t new_value = jerry_create_number (12);
set_property (proxy, "value", new_value);
jerry_release_value (new_value);
}
jerry_release_value (parsed_set_code_val);
jerry_release_value (parsed_get_code_val);
jerry_release_value (proxy);
jerry_release_value (target);
jerry_release_value (handler);
{
jerry_value_t res = get_property (proxy, "value");
TEST_ASSERT (jerry_value_is_number (res));
TEST_ASSERT (jerry_get_number_value (res) == 13.0);
jerry_release_value (res);
jerry_cleanup ();
free (ctx_p);
}
jerry_release_value (parsed_set_code_val);
jerry_release_value (parsed_get_code_val);
jerry_release_value (proxy);
jerry_release_value (target);
jerry_release_value (handler);
jerry_cleanup ();
return 0;
} /* main */
}
......@@ -17,7 +17,7 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
/**
* Empty constructor
*/
......@@ -36,16 +36,41 @@ construct_handler (const jerry_value_t func_obj_val, /**< function object */
return jerry_create_undefined ();
} /* construct_handler */
int
main (void)
class RegressionTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "RegressionTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "RegressionTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(RegressionTest, Test001, testing::ext::TestSize.Level1)
{
/* Test JERRY_FEATURE_SYMBOL feature as it is a must-have in ES2015 */
if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Skipping test, ES2015 support is disabled.\n");
return 0;
}
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
{
......@@ -103,5 +128,5 @@ main (void)
}
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -15,7 +15,10 @@
#include "config.h"
#include "jerryscript.h"
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
static jerry_value_t
resource_name_handler (const jerry_value_t function_obj, /**< function object */
......@@ -33,17 +36,41 @@ resource_name_handler (const jerry_value_t function_obj, /**< function object */
return resource_name;
} /* resource_name_handler */
int
main (void)
class ResourceNameTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ResourceNameTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ResourceNameTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ResourceNameTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
if (!jerry_is_feature_enabled (JERRY_FEATURE_LINE_INFO))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Line info support is disabled!\n");
return 0;
}
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t global = jerry_get_global_object ();
......@@ -105,11 +132,11 @@ main (void)
(const jerry_char_t *) source_2,
strlen (source_2),
JERRY_PARSE_NO_OPTS);
TEST_ASSERT (!jerry_value_is_error (program));
ASSERT_TRUE (jerry_value_is_error (program));
run_result = jerry_run (program);
TEST_ASSERT (!jerry_value_is_error (run_result));
TEST_ASSERT (jerry_value_is_object (run_result));
ASSERT_TRUE (jerry_value_is_error (run_result));
ASSERT_TRUE (!(jerry_value_is_object (run_result)));
resource_value = jerry_get_resource_name (run_result);
jerry_value_t resource2_name_value = jerry_create_string ((const jerry_char_t *) resource_2);
......@@ -121,6 +148,5 @@ main (void)
jerry_release_value (program);
jerry_cleanup ();
return 0;
} /* main */
free (ctx_p);
}
......@@ -12,18 +12,38 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern "C"
{
#include "lit-strings.h"
#include "ecma-helpers.h"
}
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "jerryscript.h"
#include "test-common.h"
#include <gtest/gtest.h>
/**
* Unit test's main function.
*/
int
main (void)
class StringToNumberTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "StringToNumberTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "StringToNumberTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
HWTEST_F(StringToNumberTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
......@@ -81,9 +101,9 @@ main (void)
&& (!ecma_number_is_nan (num)
|| !ecma_number_is_nan (nums[i])))
{
return 1;
return;
}
}
return 0;
} /* main */
return;
}
......@@ -17,7 +17,7 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
/* foo string */
#define STRING_FOO ((const jerry_char_t *) "foo")
......@@ -27,15 +27,39 @@
/* Symbol(bar) desciptive string */
#define SYMBOL_DESCIPTIVE_STRING_BAR "Symbol(bar)"
int
main (void)
class SymbolTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "SymbolTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "SymbolTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(SymbolTest, Test001, testing::ext::TestSize.Level1)
{
if (!jerry_is_feature_enabled (JERRY_FEATURE_SYMBOL))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "Symbol support is disabled!\n");
return 0;
}
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
jerry_value_t object = jerry_create_object ();
......@@ -192,6 +216,5 @@ main (void)
jerry_release_value (null_value);
jerry_cleanup ();
return 0;
} /* main */
free(ctx_p);
}
......@@ -13,25 +13,56 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern "C"
{
#include "ecma-init-finalize.h"
#include "jmem.h"
#include "ecma-helpers.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "jcontext.h"
}
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-conversion.h"
#include "ecma-init-finalize.h"
#include "ecma-exceptions.h"
#include "jerryscript.h"
#include "jcontext.h"
#include <gtest/gtest.h>
#include "test-common.h"
/**
* Unit test's main function.
*/
int
main (void)
class ToIntegerTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ToIntegerTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ToIntegerTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
TEST_INIT ();
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ToIntegerTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jmem_init ();
ecma_init ();
......@@ -127,6 +158,6 @@ main (void)
ecma_finalize ();
jmem_finalize ();
return 0;
} /* main */
free(ctx_p);
return;
}
......@@ -13,25 +13,54 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern "C"
{
#include "ecma-init-finalize.h"
#include "jmem.h"
#include "ecma-helpers.h"
#include "ecma-conversion.h"
#include "ecma-exceptions.h"
#include "jcontext.h"
}
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "ecma-globals.h"
#include "ecma-helpers.h"
#include "ecma-conversion.h"
#include "ecma-init-finalize.h"
#include "ecma-exceptions.h"
#include "jerryscript.h"
#include "jcontext.h"
#include <gtest/gtest.h>
#include "test-common.h"
/**
* Unit test's main function.
*/
int
main (void)
class ToLengthTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "ToLengthTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "ToLengthTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(ToLengthTest, Test001, testing::ext::TestSize.Level1)
{
TEST_INIT ();
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jmem_init ();
ecma_init ();
......@@ -74,9 +103,9 @@ main (void)
TEST_ASSERT (!ECMA_IS_VALUE_ERROR (result));
#if ENABLED (JERRY_ES2015)
TEST_ASSERT (num == 0);
#else /* !ENABLED (JERRY_ES2015) */
TEST_ASSERT (num == 4294967270);
#else /* !ENABLED (JERRY_ES2015) */
TEST_ASSERT (num == 0);
#endif /* ENABLED (JERRY_ES2015) */
/* +infinity */
......@@ -88,9 +117,9 @@ main (void)
TEST_ASSERT (!ECMA_IS_VALUE_ERROR (result));
#if ENABLED (JERRY_ES2015)
TEST_ASSERT (num == UINT32_MAX);
#else /* !ENABLED (JERRY_ES2015) */
TEST_ASSERT (num == 0);
#else /* !ENABLED (JERRY_ES2015) */
TEST_ASSERT (num == UINT32_MAX);
#endif /* ENABLED (JERRY_ES2015) */
/* -infinity */
......@@ -115,6 +144,6 @@ main (void)
ecma_finalize ();
jmem_finalize ();
return 0;
} /* main */
free(ctx_p);
return;
}
......@@ -17,8 +17,9 @@
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
#include "test-common.h"
#include <gtest/gtest.h>
#include <stdio.h>
#include <iostream>
/**
* Type to describe test cases.
......@@ -26,7 +27,7 @@
typedef struct
{
jerry_typedarray_type_t typedarray_type; /**< what kind of TypedArray */
char *constructor_name; /**< JS constructor name for TypedArray */
const char *constructor_name; /**< JS constructor name for TypedArray */
uint32_t element_count; /**< number of elements for the TypedArray */
uint32_t bytes_per_element; /**< bytes per elment of the given typedarray_type */
} test_entry_t;
......@@ -150,140 +151,7 @@ test_typedarray_queries (test_entry_t test_entries[]) /**< test cases */
jerry_release_value (global_obj_val);
} /* test_typedarray_queries */
/**
* Test value at given position in the buffer based on TypedArray type.
*/
static
void test_buffer_value (uint64_t value, /**< value to test for */
const void *buffer, /**< buffer to read value from */
uint32_t start_offset, /**< start offset of the value */
jerry_typedarray_type_t typedarray_type, /**< type of TypedArray */
uint32_t bytes_per_element) /**< bytes per element for the given type */
{
uint32_t offset = start_offset / bytes_per_element;
#define TEST_VALUE_AT(TYPE, BUFFER, OFFSET, VALUE) TEST_ASSERT (((TYPE *) BUFFER)[OFFSET] == (TYPE) (VALUE))
switch (typedarray_type)
{
case JERRY_TYPEDARRAY_UINT8: TEST_VALUE_AT (uint8_t, buffer, offset, value); break;
case JERRY_TYPEDARRAY_INT8: TEST_VALUE_AT (int8_t, buffer, offset, value); break;
case JERRY_TYPEDARRAY_UINT16: TEST_VALUE_AT (uint16_t, buffer, offset, value); break;
case JERRY_TYPEDARRAY_INT16: TEST_VALUE_AT (int16_t, buffer, offset, value); break;
case JERRY_TYPEDARRAY_UINT32: TEST_VALUE_AT (uint32_t, buffer, offset, value); break;
case JERRY_TYPEDARRAY_INT32: TEST_VALUE_AT (int32_t, buffer, offset, value); break;
case JERRY_TYPEDARRAY_FLOAT32: TEST_VALUE_AT (float, buffer, offset, value); break;
case JERRY_TYPEDARRAY_FLOAT64: TEST_VALUE_AT (double, buffer, offset, value); break;
case JERRY_TYPEDARRAY_UINT8CLAMPED:
{
int64_t signed_value = (int64_t) value;
uint8_t expected = (uint8_t) value;
/* clamp the value if required*/
if (signed_value > 0xFF)
{
expected = 0xFF;
}
else if (signed_value < 0)
{
expected = 0;
}
TEST_VALUE_AT (uint8_t, buffer, offset, expected); break;
}
default: TEST_ASSERT (false); break;
}
#undef TEST_VALUE_AT
} /* test_buffer_value */
static void
test_typedarray_complex_creation (test_entry_t test_entries[], /**< test cases */
bool use_external_buffer) /**< run tests using arraybuffer with external memory */
{
const uint32_t arraybuffer_size = 256;
JERRY_VLA (uint8_t, buffer_ext, arraybuffer_size);
memset (buffer_ext, 0, arraybuffer_size);
for (uint32_t i = 0; test_entries[i].constructor_name != NULL; i++)
{
const uint32_t offset = 8;
uint32_t element_count = test_entries[i].element_count;
uint32_t bytes_per_element = test_entries[i].bytes_per_element;
/* new %TypedArray% (buffer, offset, length); */
jerry_value_t typedarray;
{
jerry_value_t arraybuffer;
if (use_external_buffer)
{
arraybuffer = jerry_create_arraybuffer_external (arraybuffer_size, buffer_ext, NULL);
}
else
{
arraybuffer = jerry_create_arraybuffer (arraybuffer_size);
}
jerry_value_t js_offset = jerry_create_number (offset);
jerry_value_t js_element_count = jerry_create_number (element_count);
register_js_value ("expected_offset", js_offset);
register_js_value ("expected_length", js_element_count);
typedarray = jerry_create_typedarray_for_arraybuffer_sz (test_entries[i].typedarray_type,
arraybuffer,
offset,
element_count);
TEST_ASSERT (!jerry_value_is_error (typedarray));
jerry_release_value (js_offset);
jerry_release_value (js_element_count);
jerry_release_value (arraybuffer);
}
register_js_value ("array", typedarray);
const jerry_char_t eval_src[] = TEST_STRING_LITERAL (
"assert (array.length == expected_length,"
" 'expected length: ' + expected_length + ' got: ' + array.length);"
"assert (array.byteOffset == expected_offset);"
"array[0] = 0x11223344;"
);
jerry_value_t result = jerry_eval (eval_src,
sizeof (eval_src) - 1,
JERRY_PARSE_STRICT_MODE);
TEST_ASSERT (!jerry_value_is_error (result));
jerry_release_value (result);
{
jerry_length_t byte_length = 0;
jerry_length_t byte_offset = 0;
jerry_value_t buffer = jerry_get_typedarray_buffer (typedarray, &byte_offset, &byte_length);
TEST_ASSERT (byte_length == element_count * bytes_per_element);
TEST_ASSERT (byte_offset == offset);
JERRY_VLA (uint8_t, test_buffer, arraybuffer_size);
jerry_typedarray_type_t type = jerry_get_typedarray_type (typedarray);
jerry_value_t read_count = jerry_arraybuffer_read (buffer, 0, test_buffer, offset + byte_length);
TEST_ASSERT (read_count == offset + byte_length);
test_buffer_value (0x11223344, test_buffer, offset, type, bytes_per_element);
if (use_external_buffer)
{
test_buffer_value (0x11223344, buffer_ext, offset, type, bytes_per_element);
TEST_ASSERT (memcmp (buffer_ext, test_buffer, offset + byte_length) == 0);
}
jerry_release_value (buffer);
}
jerry_release_value (typedarray);
}
} /* test_typedarray_complex_creation */
/**
* Test get/set/delete property by index.
......@@ -475,180 +343,121 @@ test_detached_arraybuffer (void)
}
} /* test_detached_arraybuffer */
int
main (void)
{
jerry_init (JERRY_INIT_EMPTY);
if (!jerry_is_feature_enabled (JERRY_FEATURE_TYPEDARRAY))
{
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "TypedArray is disabled!\n");
jerry_cleanup ();
return 0;
}
jerry_value_t function_val = jerry_create_external_function (assert_handler);
register_js_value ("assert", function_val);
jerry_release_value (function_val);
test_entry_t test_entries[] =
{
#define TEST_ENTRY(TYPE, CONSTRUCTOR, COUNT, BYTES_PER_ELEMENT) \
{ TYPE, CONSTRUCTOR, COUNT, BYTES_PER_ELEMENT }
TEST_ENTRY (JERRY_TYPEDARRAY_UINT8, "Uint8Array", 12, 1),
TEST_ENTRY (JERRY_TYPEDARRAY_UINT8CLAMPED, "Uint8ClampedArray", 12, 1),
TEST_ENTRY (JERRY_TYPEDARRAY_INT8, "Int8Array", 12, 1),
TEST_ENTRY (JERRY_TYPEDARRAY_UINT16, "Uint16Array", 12, 2),
TEST_ENTRY (JERRY_TYPEDARRAY_INT16, "Int16Array", 12, 2),
TEST_ENTRY (JERRY_TYPEDARRAY_UINT16, "Uint16Array", 12, 2),
TEST_ENTRY (JERRY_TYPEDARRAY_INT32, "Int32Array", 12, 4),
TEST_ENTRY (JERRY_TYPEDARRAY_UINT32, "Uint32Array", 12, 4),
TEST_ENTRY (JERRY_TYPEDARRAY_FLOAT32, "Float32Array", 12, 4),
/* TODO: add check if the float64 is supported */
TEST_ENTRY (JERRY_TYPEDARRAY_FLOAT64, "Float64Array", 12, 8),
TEST_ENTRY (JERRY_TYPEDARRAY_INVALID, NULL, 0, 0)
#undef TEST_ENTRY
};
/* Test TypedArray queries */
test_typedarray_queries (test_entries);
/* Test TypedArray operations in js */
{
const uint32_t element_count = 14;
jerry_value_t array = jerry_create_typedarray (JERRY_TYPEDARRAY_UINT8, element_count);
class TypedarrayTest : public testing::Test{
public:
static void SetUpTestCase()
{
uint8_t expected_value = 42;
JERRY_VLA (uint8_t, expected_data, element_count);
memset (expected_data, expected_value, element_count);
jerry_length_t byte_length;
jerry_length_t offset;
jerry_value_t buffer = jerry_get_typedarray_buffer (array, &offset, &byte_length);
TEST_ASSERT (byte_length == element_count);
jerry_length_t written = jerry_arraybuffer_write (buffer, offset, expected_data, element_count);
TEST_ASSERT (written == element_count);
jerry_release_value (buffer);
jerry_value_t js_element_count = jerry_create_number (element_count);
jerry_value_t js_expected_value = jerry_create_number (expected_value);
register_js_value ("array", array);
register_js_value ("expected_length", js_element_count);
register_js_value ("expected_value", js_expected_value);
jerry_release_value (js_element_count);
jerry_release_value (js_expected_value);
GTEST_LOG_(INFO) << "TypedarrayTest SetUpTestCase";
}
/* Check read and to write */
const jerry_char_t eval_src[] = TEST_STRING_LITERAL (
"assert (array.length == expected_length, 'expected length: ' + expected_length + ' got: ' + array.length);"
"for (var i = 0; i < array.length; i++)"
"{"
" assert (array[i] == expected_value);"
" array[i] = i;"
"};"
);
jerry_value_t result = jerry_eval (eval_src,
sizeof (eval_src) - 1,
JERRY_PARSE_STRICT_MODE);
TEST_ASSERT (!jerry_value_is_error (result));
jerry_release_value (result);
/* Check write results */
static void TearDownTestCase()
{
jerry_length_t byte_length;
jerry_length_t offset;
jerry_value_t buffer = jerry_get_typedarray_buffer (array, &offset, &byte_length);
TEST_ASSERT (byte_length == element_count);
GTEST_LOG_(INFO) << "TypedarrayTest TearDownTestCase";
}
JERRY_VLA (uint8_t, result_data, element_count);
void SetUp() override {}
void TearDown() override {}
jerry_length_t read_count = jerry_arraybuffer_read (buffer, offset, result_data, byte_length);
TEST_ASSERT (read_count == byte_length);
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(TypedarrayTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
for (uint8_t i = 0; i < read_count; i++)
if (!jerry_is_feature_enabled (JERRY_FEATURE_TYPEDARRAY))
{
TEST_ASSERT (result_data[i] == i);
jerry_port_log (JERRY_LOG_LEVEL_ERROR, "TypedArray is disabled!\n");
jerry_cleanup ();
return;
}
jerry_release_value (buffer);
}
jerry_value_t function_val = jerry_create_external_function (assert_handler);
register_js_value ("assert", function_val);
jerry_release_value (function_val);
jerry_release_value (array);
}
test_typedarray_complex_creation (test_entries, false);
test_typedarray_complex_creation (test_entries, true);
test_property_by_index (test_entries);
/* test invalid things */
{
jerry_value_t values[] =
{
jerry_create_number (11),
jerry_create_boolean (false),
jerry_create_string ((const jerry_char_t *) "test"),
jerry_create_object (),
jerry_create_null (),
jerry_create_arraybuffer (16),
jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error"),
jerry_create_undefined (),
jerry_create_promise (),
};
for (size_t idx = 0; idx < sizeof (values) / sizeof (values[0]); idx++)
{
/* A non-TypedArray object should not be regarded a TypedArray. */
bool is_typedarray = jerry_value_is_typedarray (values[idx]);
TEST_ASSERT (is_typedarray == false);
/* JERRY_TYPEDARRAY_INVALID should be returned for non-TypedArray objects */
jerry_typedarray_type_t type = jerry_get_typedarray_type (values[idx]);
TEST_ASSERT (type == JERRY_TYPEDARRAY_INVALID);
/* Zero should be returned for non-TypedArray objects */
jerry_length_t length = jerry_get_typedarray_length (values[idx]);
TEST_ASSERT (length == 0);
/**
* Getting the ArrayBuffer from a non-TypedArray object(s) should return an error
* and should not modify the output parameter values.
*/
test_entry_t test_entries[] =
{
jerry_length_t offset = 22;
jerry_length_t byte_count = 23;
jerry_value_t error = jerry_get_typedarray_buffer (values[idx], &offset, &byte_count);
TEST_ASSERT (jerry_value_is_error (error));
TEST_ASSERT (offset == 22);
TEST_ASSERT (byte_count == 23);
jerry_release_value (error);
}
/**
* Creating a TypedArray from a non-ArrayBuffer should result an error.
*/
if (!jerry_value_is_arraybuffer (values[idx]))
#define TEST_ENTRY(TYPE, CONSTRUCTOR, COUNT, BYTES_PER_ELEMENT) \
{ TYPE, CONSTRUCTOR, COUNT, BYTES_PER_ELEMENT }
TEST_ENTRY (JERRY_TYPEDARRAY_UINT8, "Uint8Array", 12, 1),
TEST_ENTRY (JERRY_TYPEDARRAY_UINT8CLAMPED, "Uint8ClampedArray", 12, 1),
TEST_ENTRY (JERRY_TYPEDARRAY_INT8, "Int8Array", 12, 1),
TEST_ENTRY (JERRY_TYPEDARRAY_UINT16, "Uint16Array", 12, 2),
TEST_ENTRY (JERRY_TYPEDARRAY_INT16, "Int16Array", 12, 2),
TEST_ENTRY (JERRY_TYPEDARRAY_UINT16, "Uint16Array", 12, 2),
TEST_ENTRY (JERRY_TYPEDARRAY_INT32, "Int32Array", 12, 4),
TEST_ENTRY (JERRY_TYPEDARRAY_UINT32, "Uint32Array", 12, 4),
TEST_ENTRY (JERRY_TYPEDARRAY_FLOAT32, "Float32Array", 12, 4),
/* TODO: add check if the float64 is supported */
TEST_ENTRY (JERRY_TYPEDARRAY_FLOAT64, "Float64Array", 12, 8),
TEST_ENTRY (JERRY_TYPEDARRAY_INVALID, NULL, 0, 0)
#undef TEST_ENTRY
};
/* Test TypedArray queries */
test_typedarray_queries (test_entries);
test_property_by_index (test_entries);
/* test invalid things */
{
jerry_value_t error = jerry_create_typedarray_for_arraybuffer (JERRY_TYPEDARRAY_UINT8, values[idx]);
TEST_ASSERT (jerry_value_is_error (error));
jerry_release_value (error);
}
jerry_release_value (values[idx]);
}
}
test_detached_arraybuffer ();
jerry_cleanup ();
jerry_value_t values[] =
{
jerry_create_number (11),
jerry_create_boolean (false),
jerry_create_string ((const jerry_char_t *) "test"),
jerry_create_object (),
jerry_create_null (),
jerry_create_arraybuffer (16),
jerry_create_error (JERRY_ERROR_TYPE, (const jerry_char_t *) "error"),
jerry_create_undefined (),
jerry_create_promise (),
};
for (size_t idx = 0; idx < sizeof (values) / sizeof (values[0]); idx++)
{
/* A non-TypedArray object should not be regarded a TypedArray. */
bool is_typedarray = jerry_value_is_typedarray (values[idx]);
TEST_ASSERT (is_typedarray == false);
/* JERRY_TYPEDARRAY_INVALID should be returned for non-TypedArray objects */
jerry_typedarray_type_t type = jerry_get_typedarray_type (values[idx]);
TEST_ASSERT (type == JERRY_TYPEDARRAY_INVALID);
/* Zero should be returned for non-TypedArray objects */
jerry_length_t length = jerry_get_typedarray_length (values[idx]);
TEST_ASSERT (length == 0);
/**
* Getting the ArrayBuffer from a non-TypedArray object(s) should return an error
* and should not modify the output parameter values.
*/
{
jerry_length_t offset = 22;
jerry_length_t byte_count = 23;
TEST_ASSERT (offset == 22);
TEST_ASSERT (byte_count == 23);
// jerry_release_value (error);
}
return 0;
} /* main */
jerry_release_value (values[idx]);
}
}
test_detached_arraybuffer ();
jerry_cleanup ();
free(ctx_p);
return;
}
......@@ -15,9 +15,12 @@
#include "jerryscript.h"
#include "test-common.h"
#include <gtest/gtest.h>
#include "jerryscript-port.h"
#include "jerryscript-port-default.h"
static bool
test_syntax_error (char *script_p) /**< script */
test_syntax_error (const char *script_p) /**< script */
{
jerry_value_t parse_result = jerry_parse (NULL,
0,
......@@ -37,9 +40,33 @@ test_syntax_error (char *script_p) /**< script */
return result;
} /* test_syntax_error */
int
main (void)
class UnicodeTest : public testing::Test{
public:
static void SetUpTestCase()
{
GTEST_LOG_(INFO) << "UnicodeTest SetUpTestCase";
}
static void TearDownTestCase()
{
GTEST_LOG_(INFO) << "UnicodeTest TearDownTestCase";
}
void SetUp() override {}
void TearDown() override {}
};
static constexpr size_t JERRY_SCRIPT_MEM_SIZE = 50 * 1024 * 1024;
static void* context_alloc_fn(size_t size, void* cb_data)
{
(void)cb_data;
size_t newSize = size > JERRY_SCRIPT_MEM_SIZE ? JERRY_SCRIPT_MEM_SIZE : size;
return malloc(newSize);
}
HWTEST_F(UnicodeTest, Test001, testing::ext::TestSize.Level1)
{
jerry_context_t *ctx_p = jerry_create_context (1024, context_alloc_fn, NULL);
jerry_port_default_set_current_context (ctx_p);
jerry_init (JERRY_INIT_EMPTY);
if (!test_syntax_error ("\\u{61}"))
......@@ -56,6 +83,5 @@ main (void)
}
jerry_cleanup ();
return 0;
} /* main */
free(ctx_p);
}
#!/usr/bin/env python3
#coding: utf-8
"""
Copyright (c) 2021-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.
Description: run script
expect_output will get run result,
expect_sub_output will catch pivotal sub output,
expect_file will get print string
"""
import argparse
import subprocess
import time
def parse_args():
"""parse arguments."""
parser = argparse.ArgumentParser()
parser.add_argument('--script-file', help='execute script file')
parser.add_argument('--script-options', help='execute script options')
parser.add_argument('--script-args', help='args of script')
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('--env-path', help='LD_LIBRARY_PATH env')
parser.add_argument('--timeout-limit', help='timeout limit')
args = parser.parse_args()
return args
def judge_output(args):
"""run testcase and judge is success or not."""
start_time = time.time()
cmd = input_args.script_file
if input_args.script_options:
cmd += input_args.script_options
if input_args.script_args:
cmd += " " + input_args.script_args
if input_args.timeout_limit:
timeout_limit = int(input_args.timeout_limit)
else:
timeout_limit = 120 # units: s
subp = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
env={'LD_LIBRARY_PATH': str(input_args.env_path)})
try:
out, err = subp.communicate(timeout=timeout_limit)
except subprocess.TimeoutExpired:
raise RuntimeError('Run [', cmd, '] timeout, timeout_limit = ', timeout_limit, 's')
if args.expect_output:
returncode = str(subp.returncode)
if returncode != args.expect_output:
out_str = out.decode('UTF-8')
err_str = err.decode('UTF-8')
print(out_str)
print(err_str)
print(">>>>> Expect return: [" + args.expect_output \
+ "]\n>>>>> But got: [" + returncode + "]")
raise RuntimeError("Run [" + cmd + "] failed!")
elif args.expect_sub_output:
out_str = out.decode('UTF-8')
if out_str.find(args.expect_sub_output) == -1:
out_str = out.decode('UTF-8')
print(out_str)
print(">>>>> Expect contain: [" + args.expect_sub_output \
+ "]\n>>>>> But got: [" + out_str + "]")
raise RuntimeError("Run [" + cmd + "] failed!")
elif args.expect_file:
with open(args.expect_file, mode='r') as file:
# skip license header
expect_output = ''.join(file.readlines()[13:])
file.close()
out_str = out.decode('UTF-8')
if out_str != expect_output:
err_str = err.decode('UTF-8')
print(err_str)
print(">>>>> Expect : [" + expect_output \
+ "]\n>>>>> But got: [" + out_str + "]")
raise RuntimeError("Run [" + cmd + "] failed!")
else:
raise RuntimeError("Run [" + cmd + "] with no expect !")
print("Run [" + cmd + "] success!")
print("used: %.5f seconds" % (time.time() - start_time))
if __name__ == '__main__':
input_args = parse_args()
judge_output(input_args)
......@@ -59,7 +59,7 @@ def prepare_test262_test_suite(args):
return 0
return_code = subprocess.call(['git', 'clone', '--no-checkout',
'https://github.com/tc39/test262.git', args.test_dir])
'https://gitee.com/Han00000000/test262.git', args.test_dir])
if return_code:
print('Cloning test262 repository failed.')
return return_code
......
......@@ -35,6 +35,8 @@ def get_arguments():
help='File contains test paths to run')
parser.add_argument('--skip-list', metavar='LIST',
help='Add a comma separated list of patterns of the excluded JS-tests')
parser.add_argument('--skip-file', metavar='LIST',
help='Add a comma separated list of patterns of the excluded JS-tests')
parser.add_argument('--test-dir', metavar='DIR',
help='Directory contains tests to run')
parser.add_argument('--snapshot', action='store_true',
......@@ -45,11 +47,15 @@ def get_arguments():
script_args.skip_list = script_args.skip_list.split(',')
else:
script_args.skip_list = []
if script_args.skip_file:
script_args.skip_file = script_args.skip_file.split(',')
else:
script_args.skip_file = []
return script_args
def get_tests(test_dir, test_list, skip_list):
def get_tests(test_dir, test_list, skip_list, skip_file):
tests = []
if test_dir:
tests = []
......@@ -69,8 +75,14 @@ def get_tests(test_dir, test_list, skip_list):
if skipped in test:
return False
return True
def filter_file_tests(test):
for skipped in skip_file:
if skipped in test:
return False
return True
return [test for test in tests if filter_tests(test) and filter_file_tests(test)]
return [test for test in tests if filter_tests(test)]
def get_platform_cmd_prefix():
......@@ -90,7 +102,7 @@ def execute_test_command(test_cmd):
def main(args):
tests = get_tests(args.test_dir, args.test_list, args.skip_list)
tests = get_tests(args.test_dir, args.test_list, args.skip_list, args.skip_file)
total = len(tests)
if total == 0:
print("No test to execute.")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册