1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159
|
/*
* Copyright 2020 Advanced Micro Devices, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/
#include "igt.h"
#include "igt_amd.h"
#include <fcntl.h>
#include "lib/amdgpu/amd_mem_leak.h"
IGT_TEST_DESCRIPTION("Test checking memory leaks with suspend-resume and connector hotplug");
/* Common test data. */
typedef struct data {
igt_display_t display;
igt_plane_t *primary;
igt_output_t *output;
igt_pipe_t *pipe;
drmModeModeInfo *mode;
enum pipe pipe_id;
int fd;
int w;
int h;
} data_t;
/* Common test setup. */
static void test_init(data_t *data)
{
igt_display_t *display = &data->display;
/* It doesn't matter which pipe we choose on amdpgu. */
data->pipe_id = PIPE_A;
data->pipe = &data->display.pipes[data->pipe_id];
igt_display_reset(display);
/* find a connected output */
data->output = NULL;
for (int i=0; i < data->display.n_outputs; ++i) {
drmModeConnector *connector = data->display.outputs[i].config.connector;
if (connector->connection == DRM_MODE_CONNECTED) {
data->output = &data->display.outputs[i];
}
}
igt_assert_f(data->output, "Requires connected output\n");
data->mode = igt_output_get_mode(data->output);
igt_assert(data->mode);
data->primary =
igt_pipe_get_plane_type(data->pipe, DRM_PLANE_TYPE_PRIMARY);
igt_output_set_pipe(data->output, data->pipe_id);
data->w = data->mode->hdisplay;
data->h = data->mode->vdisplay;
}
/* Common test cleanup. */
static void test_fini(data_t *data)
{
igt_display_reset(&data->display);
}
static void test_suspend_resume(data_t *data)
{
igt_display_t *display = &data->display;
igt_fb_t rfb;
test_init(data);
if(!clear_memleak(true)) {
igt_skip("kmemleak is not enabled for this kernel\n");
}
igt_create_pattern_fb(data->fd, data->w, data->h, DRM_FORMAT_XRGB8888, 0, &rfb);
igt_plane_set_fb(data->primary, &rfb);
igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
igt_system_suspend_autoresume(SUSPEND_STATE_MEM, SUSPEND_TEST_NONE);
igt_assert_f(is_no_memleak(), "memory leak detected\n");
igt_remove_fb(data->fd, &rfb);
test_fini(data);
}
static void test_hotplug(data_t *data)
{
igt_display_t *display = &data->display;
igt_fb_t rfb;
test_init(data);
igt_amd_require_hpd(&data->display, data->fd);
if(!clear_memleak(true)) {
igt_skip("kmemleak is not enabled for this kernel\n");
}
igt_create_pattern_fb(data->fd, data->w, data->h, DRM_FORMAT_XRGB8888, 0, &rfb);
igt_plane_set_fb(data->primary, &rfb);
igt_display_commit_atomic(display, DRM_MODE_ATOMIC_ALLOW_MODESET, NULL);
igt_amd_trigger_hotplug(data->fd, data->output->name);
igt_assert_f(is_no_memleak(), "memory leak detected\n");
igt_remove_fb(data->fd, &rfb);
test_fini(data);
}
igt_main
{
data_t data;
igt_skip_on_simulation();
memset(&data, 0, sizeof(data));
igt_fixture
{
data.fd = drm_open_driver_master(DRIVER_AMDGPU);
kmstest_set_vt_graphics_mode();
igt_display_require(&data.display, data.fd);
igt_require(data.display.is_atomic);
igt_display_require_output(&data.display);
}
igt_describe("Test memory leaks after resume from suspend");
igt_subtest("connector-suspend-resume") test_suspend_resume(&data);
igt_describe("Test memroy leaks after connector hotplug");
igt_subtest("connector-hotplug") test_hotplug(&data);
igt_fixture
{
igt_display_fini(&data.display);
drm_close_driver(data.fd);
}
}
|