From: Jocelyn Falempe <jfalempe@redhat.com>
To: Maxime Ripard <mripard@kernel.org>
Cc: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>,
Thomas Zimmermann <tzimmermann@suse.de>,
David Airlie <airlied@gmail.com>, Simona Vetter <simona@ffwll.ch>,
Javier Martinez Canillas <javierm@redhat.com>,
linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 3/3] drm/panic: Add a kconfig option to dump kunits results to png
Date: Mon, 1 Sep 2025 15:16:16 +0200 [thread overview]
Message-ID: <29f77752-a4df-4a12-96d3-4ccd52bd5b89@redhat.com> (raw)
In-Reply-To: <20250827-imperial-amigurumi-malkoha-b99a9d@houat>
On 27/08/2025 11:52, Maxime Ripard wrote:
> Hi,
>
> On Thu, Aug 21, 2025 at 11:49:07AM +0200, Jocelyn Falempe wrote:
>> This is a bit hacky, but very handy if you want to customize the
>> panic screen.
>> It allows to dump the generated images to the logs, and then a python
>> script can convert it to .png files. It makes it easy to check how
>> the panic screen will look on different resolutions, without having
>> to crash a VM.
>> To not pollute the logs, it uses a monochrome framebuffer, compress
>> it with zlib, and base64 encode it.
>>
>> Signed-off-by: Jocelyn Falempe <jfalempe@redhat.com>
>> ---
>> drivers/gpu/drm/Kconfig.debug | 14 ++++
>> drivers/gpu/drm/tests/drm_panic_test.c | 111 +++++++++++++++++++++++++
>> scripts/kunitpanic2png.py | 53 ++++++++++++
>> 3 files changed, 178 insertions(+)
>> create mode 100755 scripts/kunitpanic2png.py
>>
>> diff --git a/drivers/gpu/drm/Kconfig.debug b/drivers/gpu/drm/Kconfig.debug
>> index 05dc43c0b8c5..d8ae85132d32 100644
>> --- a/drivers/gpu/drm/Kconfig.debug
>> +++ b/drivers/gpu/drm/Kconfig.debug
>> @@ -84,6 +84,20 @@ config DRM_KUNIT_TEST
>>
>> If in doubt, say "N".
>>
>> +config DRM_PANIC_KUNIT_TEST_DUMP
>> + bool "Enable screen dump to logs in KUnit tests for drm_panic"
>> + default n
>> + depends on DRM && DRM_PANIC && DRM_KUNIT_TEST
>> + select ZLIB_DEFLATE
>> + help
>> + This allows to dump the panic screen to the KUnit tests logs.
>> + It's possible with a small python script to write pngs from the logs.
>> +
>> + This is only to help developers customizing the drm_panic screen,
>> + checking the result for different resolutions.
>> +
>> + If in doubt, say "N"
>> +
>> config DRM_TTM_KUNIT_TEST
>> tristate "KUnit tests for TTM" if !KUNIT_ALL_TESTS
>> default n
>> diff --git a/drivers/gpu/drm/tests/drm_panic_test.c b/drivers/gpu/drm/tests/drm_panic_test.c
>> index 46ff3e5e0e5d..8cddb845aea9 100644
>> --- a/drivers/gpu/drm/tests/drm_panic_test.c
>> +++ b/drivers/gpu/drm/tests/drm_panic_test.c
>> @@ -115,24 +115,135 @@ static void drm_test_panic_screen_user_page(struct kunit *test)
>> kfree(pages);
>> }
>>
>> +#ifdef CONFIG_DRM_PANIC_KUNIT_TEST_DUMP
>> +#include <linux/base64.h>
>> +#include <linux/delay.h>
>> +#include <linux/zlib.h>
>> +
>> +#define LINE_LEN 128
>> +
>> +#define COMPR_LEVEL 6
>> +#define WINDOW_BITS 12
>> +#define MEM_LEVEL 4
>> +
>> +static int compress_image(u8 *src, int size, u8 *dst)
>> +{
>> + struct z_stream_s stream;
>> +
>> + stream.workspace = kmalloc(zlib_deflate_workspacesize(WINDOW_BITS, MEM_LEVEL),
>> + GFP_KERNEL);
>> +
>> + if (zlib_deflateInit2(&stream, COMPR_LEVEL, Z_DEFLATED, WINDOW_BITS,
>> + MEM_LEVEL, Z_DEFAULT_STRATEGY) != Z_OK)
>> + return -EINVAL;
>> +
>> + stream.next_in = src;
>> + stream.avail_in = size;
>> + stream.total_in = 0;
>> + stream.next_out = dst;
>> + stream.avail_out = size;
>> + stream.total_out = 0;
>> +
>> + if (zlib_deflate(&stream, Z_FINISH) != Z_STREAM_END)
>> + return -EINVAL;
>> +
>> + if (zlib_deflateEnd(&stream) != Z_OK)
>> + return -EINVAL;
>> +
>> + kfree(stream.workspace);
>> +
>> + return stream.total_out;
>> +}
>> +
>> +static void dump_image(u8 *fb, unsigned int width, unsigned int height)
>> +{
>> + int len = 0;
>> + char *dst;
>> + char *compressed;
>> + int sent = 0;
>> + int stride = DIV_ROUND_UP(width, 8);
>> + int size = stride * height;
>> +
>> + compressed = vzalloc(size);
>> + if (!compressed)
>> + return;
>> + len = compress_image(fb, size, compressed);
>> + if (len < 0) {
>> + pr_err("Compression failed %d", len);
>> + return;
>> + }
>> +
>> + dst = vzalloc(4 * DIV_ROUND_UP(len, 3) + 1);
>> + if (!dst)
>> + return;
>> +
>> + len = base64_encode(compressed, len, dst);
>> +
>> + pr_info("KUNIT PANIC IMAGE DUMP START %dx%d", width, height);
>> + while (len > 0) {
>> + char save = dst[sent + LINE_LEN];
>> +
>> + dst[sent + LINE_LEN] = 0;
>> + pr_info("%s", dst + sent);
>> + dst[sent + LINE_LEN] = save;
>> + sent += LINE_LEN;
>> + len -= LINE_LEN;
>> + }
>> + pr_info("KUNIT PANIC IMAGE DUMP END");
>
> The kunit test output format is defined, and we should probably use a
> diagnostic line for this:
> https://docs.kernel.org/dev-tools/ktap.html#diagnostic-lines
>
> We should probably cc the kunit maintainers about this too.
Thanks for the pointer, I will also experiment with debugfs, as
suggested by Thomas.
Best regards,
--
Jocelyn
>
> Maxime
next prev parent reply other threads:[~2025-09-01 13:16 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-21 9:49 [PATCH 0/3] drm/panic: Add kunit tests for drm_panic Jocelyn Falempe
2025-08-21 9:49 ` [PATCH 1/3] drm/panic: Rename draw_panic_static_* to draw_panic_screen_* Jocelyn Falempe
2025-08-21 9:49 ` [PATCH 2/3] drm/panic: Add kunit tests for drm_panic Jocelyn Falempe
2025-08-27 9:44 ` Maxime Ripard
2025-09-01 12:59 ` Jocelyn Falempe
2025-08-21 9:49 ` [PATCH 3/3] drm/panic: Add a kconfig option to dump kunits results to png Jocelyn Falempe
2025-08-27 9:52 ` Maxime Ripard
2025-09-01 13:16 ` Jocelyn Falempe [this message]
2025-08-27 10:45 ` Thomas Zimmermann
2025-09-01 13:04 ` Jocelyn Falempe
2025-09-02 16:58 ` Maxime Ripard
2025-09-03 7:30 ` Jocelyn Falempe
2025-09-03 8:19 ` Maxime Ripard
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=29f77752-a4df-4a12-96d3-4ccd52bd5b89@redhat.com \
--to=jfalempe@redhat.com \
--cc=airlied@gmail.com \
--cc=dri-devel@lists.freedesktop.org \
--cc=javierm@redhat.com \
--cc=linux-kernel@vger.kernel.org \
--cc=maarten.lankhorst@linux.intel.com \
--cc=mripard@kernel.org \
--cc=simona@ffwll.ch \
--cc=tzimmermann@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).