Commit 3508f70c authored by jameslahm's avatar jameslahm Committed by V8 LUCI CQ

[test] Move cctest/test-concurrent-js-array to unittests

... /objects/concurrent-js-array-unittest.

Bug: v8:12781
Change-Id: Ie23432df7ffa785f96684060f5f2df3716713fd6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3600549Reviewed-by: 's avatarLeszek Swirski <leszeks@chromium.org>
Commit-Queue: 王澳 <wangao.james@bytedance.com>
Cr-Commit-Position: refs/heads/main@{#80115}
parent 2056305c
...@@ -199,7 +199,6 @@ v8_source_set("cctest_sources") { ...@@ -199,7 +199,6 @@ v8_source_set("cctest_sources") {
"test-code-layout.cc", "test-code-layout.cc",
"test-code-pages.cc", "test-code-pages.cc",
"test-code-stub-assembler.cc", "test-code-stub-assembler.cc",
"test-concurrent-js-array.cc",
"test-concurrent-prototype.cc", "test-concurrent-prototype.cc",
"test-concurrent-script-context-table.cc", "test-concurrent-script-context-table.cc",
"test-concurrent-transition-array.cc", "test-concurrent-transition-array.cc",
......
...@@ -371,6 +371,7 @@ v8_source_set("unittests_sources") { ...@@ -371,6 +371,7 @@ v8_source_set("unittests_sources") {
"objects/array-list-unittest.cc", "objects/array-list-unittest.cc",
"objects/concurrent-descriptor-array-unittest.cc", "objects/concurrent-descriptor-array-unittest.cc",
"objects/concurrent-feedback-vector-unittest.cc", "objects/concurrent-feedback-vector-unittest.cc",
"objects/concurrent-js-array-unittest.cc",
"objects/concurrent-string-unittest.cc", "objects/concurrent-string-unittest.cc",
"objects/object-unittest.cc", "objects/object-unittest.cc",
"objects/osr-optimized-code-cache-unittest.cc", "objects/osr-optimized-code-cache-unittest.cc",
......
// Copyright 2021 the V8 project authors. All rights reserved. // Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
...@@ -12,10 +12,13 @@ ...@@ -12,10 +12,13 @@
#include "src/heap/local-heap.h" #include "src/heap/local-heap.h"
#include "src/heap/parked-scope.h" #include "src/heap/parked-scope.h"
#include "src/objects/js-array-inl.h" #include "src/objects/js-array-inl.h"
#include "test/cctest/cctest.h" #include "test/unittests/test-utils.h"
#include "test/cctest/heap/heap-utils.h" #include "testing/gtest/include/gtest/gtest.h"
namespace v8 { namespace v8 {
using ConcurrentJsArrayTest = TestWithContext;
namespace internal { namespace internal {
static constexpr int kNumArrays = 1024; static constexpr int kNumArrays = 1024;
...@@ -68,7 +71,7 @@ class BackgroundThread final : public v8::base::Thread { ...@@ -68,7 +71,7 @@ class BackgroundThread final : public v8::base::Thread {
if (result.has_value()) { if (result.has_value()) {
// On any success, the elements at index 1 must be the original value // On any success, the elements at index 1 must be the original value
// Smi(1). // Smi(1).
CHECK(result.value().IsSmi()); EXPECT_TRUE(result.value().IsSmi());
CHECK_EQ(Smi::ToInt(result.value()), 1); CHECK_EQ(Smi::ToInt(result.value()), 1);
} }
} }
...@@ -81,26 +84,24 @@ class BackgroundThread final : public v8::base::Thread { ...@@ -81,26 +84,24 @@ class BackgroundThread final : public v8::base::Thread {
base::Semaphore* sema_started_; base::Semaphore* sema_started_;
}; };
TEST(ArrayWithCowElements) { TEST_F(ConcurrentJsArrayTest, ArrayWithCowElements) {
CcTest::InitializeVM(); std::unique_ptr<PersistentHandles> ph = i_isolate()->NewPersistentHandles();
Isolate* isolate = CcTest::i_isolate();
std::unique_ptr<PersistentHandles> ph = isolate->NewPersistentHandles();
std::vector<Handle<JSArray>> handles; std::vector<Handle<JSArray>> handles;
std::vector<Handle<JSArray>> persistent_handles; std::vector<Handle<JSArray>> persistent_handles;
HandleScope handle_scope(isolate); HandleScope handle_scope(i_isolate());
// Create kNumArrays arrays with COW backing stores. // Create kNumArrays arrays with COW backing stores.
CompileRun( RunJS(
"function f() { return [0,1,2,3,4]; }\n" "function f() { return [0,1,2,3,4]; }\n"
"const xs = [];\n" "const xs = [];\n"
"let i = 0;\n"); "let i = 0;\n");
for (int i = 0; i < kNumArrays; i++) { for (int i = 0; i < kNumArrays; i++) {
Handle<JSArray> x = Handle<JSArray>::cast(Utils::OpenHandle( Handle<JSArray> x =
*CompileRunChecked(CcTest::isolate(), "xs[i++] = f();"))); Handle<JSArray>::cast(Utils::OpenHandle(*RunJS("xs[i++] = f();")));
CHECK_EQ(x->elements().map(), ReadOnlyRoots(isolate).fixed_cow_array_map()); EXPECT_EQ(x->elements().map(),
ReadOnlyRoots(i_isolate()).fixed_cow_array_map());
handles.push_back(x); handles.push_back(x);
persistent_handles.push_back(ph->NewHandle(x)); persistent_handles.push_back(ph->NewHandle(x));
} }
...@@ -109,8 +110,8 @@ TEST(ArrayWithCowElements) { ...@@ -109,8 +110,8 @@ TEST(ArrayWithCowElements) {
// Pass persistent handles to background thread. // Pass persistent handles to background thread.
std::unique_ptr<BackgroundThread> thread(new BackgroundThread( std::unique_ptr<BackgroundThread> thread(new BackgroundThread(
isolate->heap(), persistent_handles, std::move(ph), &sema_started)); i_isolate()->heap(), persistent_handles, std::move(ph), &sema_started));
CHECK(thread->Start()); EXPECT_TRUE(thread->Start());
sema_started.Wait(); sema_started.Wait();
...@@ -124,9 +125,9 @@ TEST(ArrayWithCowElements) { ...@@ -124,9 +125,9 @@ TEST(ArrayWithCowElements) {
static const int kNumMutators = arraysize(kMutators); static const int kNumMutators = arraysize(kMutators);
for (int i = kNumArrays - 1; i >= 0; i--) { for (int i = kNumArrays - 1; i >= 0; i--) {
CompileRunChecked(CcTest::isolate(), kMutators[i % kNumMutators]); RunJS(kMutators[i % kNumMutators]);
CHECK_NE(handles[i]->elements().map(), EXPECT_NE(handles[i]->elements().map(),
ReadOnlyRoots(isolate).fixed_cow_array_map()); ReadOnlyRoots(i_isolate()).fixed_cow_array_map());
} }
thread->Join(); thread->Join();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment