-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WPE][GTK] Move
WebKitWebsiteData/memory-pressure
API test to a sep…
…arate binary https://bugs.webkit.org/show_bug.cgi?id=260256 Reviewed by Carlos Garcia Campos. This test verifies that the network process will be killed if the memory limit is reached. It's done by calling `webkit_network_session_set_memory_pressure_settings()`. The settings passed as an argument are later applied during the creation of a new network process. Before 259433@main a new network process was created for every network session but now only one network process is created. Since this test is not the first one in the test suite, the network process was already created and the memory pressure settings have no effect. Also, the name of the function is misleading now, because the memory pressure settings are applied to all sessions. * Tools/TestWebKitAPI/Tests/WebKitGLib/TestNetworkProcessMemoryPressure.cpp: Added. (serverCallback): (MemoryPressureTest::setup): (MemoryPressureTest::teardown): (MemoryPressureTest::loadFailedCallback): (MemoryPressureTest::waitUntilLoadFailed): (testMemoryPressureSettings): (beforeAll): (afterAll): * Tools/TestWebKitAPI/Tests/WebKitGLib/TestWebsiteData.cpp: (beforeAll): (MemoryPressureTest::setup): Deleted. (MemoryPressureTest::teardown): Deleted. (MemoryPressureTest::loadFailedCallback): Deleted. (MemoryPressureTest::waitUntilLoadFailed): Deleted. (testMemoryPressureSettings): Deleted. * Tools/TestWebKitAPI/glib/CMakeLists.txt: Canonical link: https://commits.webkit.org/266946@main
- Loading branch information
1 parent
3f543a9
commit 5308465
Showing
3 changed files
with
109 additions
and
57 deletions.
There are no files selected for viewing
108 changes: 108 additions & 0 deletions
108
Tools/TestWebKitAPI/Tests/WebKitGLib/TestNetworkProcessMemoryPressure.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/* | ||
* Copyright (C) 2023 Igalia S.L. | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2.1 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Library General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Library General Public License | ||
* along with this library; see the file COPYING.LIB. If not, write to | ||
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | ||
* Boston, MA 02110-1301, USA. | ||
*/ | ||
|
||
#include "config.h" | ||
|
||
#include "WebKitTestServer.h" | ||
#include "WebViewTest.h" | ||
|
||
static WebKitTestServer* kServer; | ||
|
||
#if USE(SOUP2) | ||
static void serverCallback(SoupServer* server, SoupMessage* message, const char* path, GHashTable*, SoupClientContext*, gpointer) | ||
#else | ||
static void serverCallback(SoupServer* server, SoupServerMessage* message, const char* path, GHashTable*, gpointer) | ||
#endif | ||
{ | ||
if (soup_server_message_get_method(message) != SOUP_METHOD_GET) { | ||
soup_server_message_set_status(message, SOUP_STATUS_NOT_IMPLEMENTED, nullptr); | ||
return; | ||
} | ||
|
||
soup_server_message_set_status(message, SOUP_STATUS_NOT_FOUND, nullptr); | ||
} | ||
|
||
class MemoryPressureTest : public WebViewTest { | ||
public: | ||
MAKE_GLIB_TEST_FIXTURE_WITH_SETUP_TEARDOWN(MemoryPressureTest, setup, teardown); | ||
|
||
static void setup() | ||
{ | ||
WebKitMemoryPressureSettings* settings = webkit_memory_pressure_settings_new(); | ||
webkit_memory_pressure_settings_set_memory_limit(settings, 1); | ||
webkit_memory_pressure_settings_set_poll_interval(settings, 0.001); | ||
webkit_memory_pressure_settings_set_kill_threshold(settings, 1); | ||
webkit_memory_pressure_settings_set_strict_threshold(settings, 0.75); | ||
webkit_memory_pressure_settings_set_conservative_threshold(settings, 0.5); | ||
#if ENABLE(2022_GLIB_API) | ||
webkit_network_session_set_memory_pressure_settings(settings); | ||
#else | ||
webkit_website_data_manager_set_memory_pressure_settings(settings); | ||
#endif | ||
webkit_memory_pressure_settings_free(settings); | ||
} | ||
|
||
static void teardown() | ||
{ | ||
#if ENABLE(2022_GLIB_API) | ||
webkit_network_session_set_memory_pressure_settings(nullptr); | ||
#else | ||
webkit_website_data_manager_set_memory_pressure_settings(nullptr); | ||
#endif | ||
} | ||
|
||
static gboolean loadFailedCallback(WebKitWebView* webView, WebKitLoadEvent loadEvent, const char* failingURI, GError* error, MemoryPressureTest* test) | ||
{ | ||
g_signal_handlers_disconnect_by_func(webView, reinterpret_cast<void*>(loadFailedCallback), test); | ||
g_main_loop_quit(test->m_mainLoop); | ||
|
||
return TRUE; | ||
} | ||
|
||
void waitUntilLoadFailed() | ||
{ | ||
g_signal_connect(m_webView, "load-failed", G_CALLBACK(MemoryPressureTest::loadFailedCallback), this); | ||
g_main_loop_run(m_mainLoop); | ||
} | ||
}; | ||
|
||
static void testMemoryPressureSettings(MemoryPressureTest* test, gconstpointer) | ||
{ | ||
// We have set a memory limit of 1MB with a kill threshold of 1 and a poll interval of 0.001. | ||
// The network process will use around 2MB to load the test. The MemoryPressureHandler will | ||
// kill the process as soon as it detects that it's using more than 1MB, so the network process | ||
// won't be able to complete the resource load. This causes an internal error and the load-failed | ||
// signal is emitted. | ||
GUniquePtr<char> fileURL(g_strdup_printf("file://%s/simple.html", Test::getResourcesDir(Test::WebKit2Resources).data())); | ||
test->loadURI(fileURL.get()); | ||
test->waitUntilLoadFailed(); | ||
} | ||
|
||
void beforeAll() | ||
{ | ||
kServer = new WebKitTestServer(); | ||
kServer->run(serverCallback); | ||
|
||
MemoryPressureTest::add("WebKitWebsiteData", "memory-pressure", testMemoryPressureSettings); | ||
} | ||
|
||
void afterAll() | ||
{ | ||
delete kServer; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters