tests/unit: add unit test for qemu_hexdump()
PATCH v3 1/1 tests/unit: add unit test for qemu_hexdump()
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', move hexdump.c out of "if have_block"
in meson.build.
---
v3: change meson.build to compile hexdump.c always
tests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-)
tests/unit/test-cutils.c +43 -0
@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". +* +* We use data that is not aligned to 16 bytes, so last line +* is incomplete. +*/ +const uint8_t data[] = { +/* First line: 16 bytes */ +0x48 ,0x65 ,0x6c ,0x6c ,0x6f ,0x20 ,0x57 ,0x6f ,/* "Hello Wo" */ +0x72 ,0x6c ,0x64 ,0x21 ,0x20 ,0x54 ,0x68 ,0x69 ,/* "rld! Thi" */ +/* Second line: 5 bytes (incomplete) */ +0x73 ,0x20 ,0x69 ,0x73 ,0x20 /* "s is " */ + }; +char *output =NULL ; +size_t size; +FILE *stream =open_memstream (&output, &size); + +g_assert_nonnull (stream); + +qemu_hexdump (stream,"test" , data,sizeof (data)); +fclose (stream); + +g_assert_nonnull (output); + +/* We expect proper alignment of "s is" part on the second line */ +const char *expected = +"test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" +"test: 0010: 73 20 69 73 20 s is \n" ; + + g_assert_cmpstr(output, ==, expected); + +free (output); +} +int main (int argc,char **argv) {g_test_init (&argc, &argv,NULL );
@@ -3995,5 +4033,10 @@ int main(int argc, char **argv) test_iec_binary_prefix);g_test_add_func ("/cutils/si_prefix" , test_si_prefix); + +/* qemu_hexdump() test */ +g_test_add_func ("/cutils/qemu_hexdump/alignment" , + test_qemu_hexdump_alignment); +return g_test_run (); }
util/meson.build +1 -1
@@ -36,6 +36,7 @@ endif util_ss.add(files('defer-call.c')) util_ss.add(files('envlist.c', 'path.c', 'module.c')) util_ss.add(files('event.c')) +util_ss.add(files('hexdump.c')) util_ss.add(files('host-utils.c')) util_ss.add(files('bitmap.c', 'bitops.c')) util_ss.add(files('fifo8.c'))
@@ -96,7 +97,6 @@ if have_block util_ss.add(files('buffer.c')) util_ss.add(files('bufferiszero.c')) util_ss.add(files('hbitmap.c')) - util_ss.add(files('hexdump.c')) util_ss.add(files('iova-tree.c')) util_ss.add(files('iov.c')) util_ss.add(files('nvdimm-utils.c'))
Signature · 1 line
2.48.1
Quoted 23 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calwaystests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +8
-0+static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". +* +* We use data that is not aligned to 16 bytes, so last line
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3646
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+* is incomplete. +*/ +const uint8_t data[] = { +/* First line: 16 bytes */ +0x48 ,0x65 ,0x6c ,0x6c ,0x6f ,0x20 ,0x57 ,0x6f ,/* "Hello Wo" */ +0x72 ,0x6c ,0x64 ,0x21 ,0x20 ,0x54 ,0x68 ,0x69 ,/* "rld! Thi" */ +/* Second line: 5 bytes (incomplete) */ +0x73 ,0x20 ,0x69 ,0x73 ,0x20 /* "s is " */ + }; +char *output =NULL ;
Could be g_autofree, and avoid the later 'free()' call.
Quoted 9 lines
tests/unit/test-cutils.c +9
-0+size_t size; +FILE *stream =open_memstream (&output, &size); + +g_assert_nonnull (stream); + +qemu_hexdump (stream,"test" , data,sizeof (data)); +fclose (stream); + +g_assert_nonnull (output);
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3665
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ +/* We expect proper alignment of "s is" part on the second line */ +const char *expected = +"test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" +"test: 0010: 73 20 69 73 20 s is \n" ; + + g_assert_cmpstr(output, ==, expected); + +free (output); +}
The above comment is trivial, so
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calwaystests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +12
-0+static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". +* +* We use data that is not aligned to 16 bytes, so last line +* is incomplete. +*/ +const uint8_t data[] = { +/* First line: 16 bytes */
Quoted 8 lines
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3646
Quoted 6 lines
tests/unit/test-cutils.c +6
-0+0x48 ,0x65 ,0x6c ,0x6c ,0x6f ,0x20 ,0x57 ,0x6f ,/* "Hello Wo" */ +0x72 ,0x6c ,0x64 ,0x21 ,0x20 ,0x54 ,0x68 ,0x69 ,/* "rld! Thi" */ +/* Second line: 5 bytes (incomplete) */ +0x73 ,0x20 ,0x69 ,0x73 ,0x20 /* "s is " */ + }; +char *output =NULL ;Could be
g_autofree, and avoid the later 'free()' call.
I'm not sure that it's correct to replace free() by g_free()..
Documentation says "bad things can happen" https://docs.gtk.org/glib/memory.html
Quoted 29 lines
Quoted 10 lines
tests/unit/test-cutils.c +9
-0+size_t size; +FILE *stream =open_memstream (&output, &size); + +g_assert_nonnull (stream); + +qemu_hexdump (stream,"test" , data,sizeof (data)); +fclose (stream); + +g_assert_nonnull (output);tests/unit/test-cutils.c static void test_si_prefix(void) · line 3665
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ +/* We expect proper alignment of "s is" part on the second line */ +const char *expected = +"test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" +"test: 0010: 73 20 69 73 20 s is \n" ; + + g_assert_cmpstr(output, ==, expected); + +free (output); +}The above comment is trivial, so
Reviewed-by Daniel P. Berrangé <[email protected]>With regards,
Daniel
Signature · 2 lines
Best regards, Vladimir
Quoted 38 lines · Vladimir Sementsov-Ogievskiy
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calwaystests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +12
-0+static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". +* +* We use data that is not aligned to 16 bytes, so last line +* is incomplete. +*/ +const uint8_t data[] = { +/* First line: 16 bytes */ Quoted 8 lines
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3646
Quoted 6 lines
tests/unit/test-cutils.c +6
-0+0x48 ,0x65 ,0x6c ,0x6c ,0x6f ,0x20 ,0x57 ,0x6f ,/* "Hello Wo" */ +0x72 ,0x6c ,0x64 ,0x21 ,0x20 ,0x54 ,0x68 ,0x69 ,/* "rld! Thi" */ +/* Second line: 5 bytes (incomplete) */ +0x73 ,0x20 ,0x69 ,0x73 ,0x20 /* "s is " */ + }; +char *output =NULL ;Could be
g_autofree, and avoid the later 'free()' call.
Quoted 3 lines
I'm not sure that it's correct to replace
free()byg_free()..Documentation says "bad things can happen" https://docs.gtk.org/glib/memory.html
Note where it says:
"Since GLib 2.46, g_malloc() is hardcoded to always use the system
malloc implementation."
I added that guarantee to glib docs specifically so apps no longer have to match free with g_free. You should still not mix up the C free vs C++ delete, or free vs g_slice_free, but that's not an issue for QEMU.
Quoted 24 lines
Quoted 24 lines
Quoted 11 lines
tests/unit/test-cutils.c +9
-0+size_t size; +FILE *stream =open_memstream (&output, &size); + +g_assert_nonnull (stream); + +qemu_hexdump (stream,"test" , data,sizeof (data)); +fclose (stream); + +g_assert_nonnull (output);tests/unit/test-cutils.c static void test_si_prefix(void) · line 3665
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ +/* We expect proper alignment of "s is" part on the second line */ +const char *expected = +"test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" +"test: 0010: 73 20 69 73 20 s is \n" ; + + g_assert_cmpstr(output, ==, expected); + +free (output); +}The above comment is trivial, so
Quoted 12 lines
Quoted 6 lines
Reviewed-by Daniel P. Berrangé <[email protected]>With regards,
DanielSignature · 2 lines
Best regards, Vladimir
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 43 lines · Daniel P. Berrangé
Quoted 38 lines · Vladimir Sementsov-Ogievskiy
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calwaystests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +12
-0+static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". +* +* We use data that is not aligned to 16 bytes, so last line +* is incomplete. +*/ +const uint8_t data[] = { +/* First line: 16 bytes */ Quoted 8 lines
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3646
Quoted 6 lines
tests/unit/test-cutils.c +6
-0+0x48 ,0x65 ,0x6c ,0x6c ,0x6f ,0x20 ,0x57 ,0x6f ,/* "Hello Wo" */ +0x72 ,0x6c ,0x64 ,0x21 ,0x20 ,0x54 ,0x68 ,0x69 ,/* "rld! Thi" */ +/* Second line: 5 bytes (incomplete) */ +0x73 ,0x20 ,0x69 ,0x73 ,0x20 /* "s is " */ + }; +char *output =NULL ;Could be
g_autofree, and avoid the later 'free()' call.Quoted 3 lines
I'm not sure that it's correct to replace
free()byg_free()..Documentation says "bad things can happen" https://docs.gtk.org/glib/memory.html
Quoted 9 lines
Note where it says:
"Since GLib 2.46,
g_malloc()is hardcoded to always use the system
malloc implementation."Quoted 1 line
I added that guarantee to glib docs specifically so apps no longer
have to match free with
g_free. You should still not mix up the C free vs C++ delete, or free vsg_slice_free, but that's not an issue for QEMU.
O, that's cool. Still the previous paragraph better be adjusted too, to match this last sentence. Otherwise they are in contradiction. I'll send v4.
Quoted 39 lines
Quoted 24 lines
Quoted 24 lines
Quoted 11 lines
tests/unit/test-cutils.c +9
-0+size_t size; +FILE *stream =open_memstream (&output, &size); + +g_assert_nonnull (stream); + +qemu_hexdump (stream,"test" , data,sizeof (data)); +fclose (stream); + +g_assert_nonnull (output);tests/unit/test-cutils.c static void test_si_prefix(void) · line 3665
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ +/* We expect proper alignment of "s is" part on the second line */ +const char *expected = +"test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" +"test: 0010: 73 20 69 73 20 s is \n" ; + + g_assert_cmpstr(output, ==, expected); + +free (output); +}The above comment is trivial, so
Quoted 12 lines
Quoted 6 lines
Reviewed-by Daniel P. Berrangé <[email protected]>With regards,
DanielSignature · 2 lines
Best regards, VladimirWith regards,
Daniel
Signature · 2 lines
Best regards, Vladimir
Quoted 46 lines · Daniel P. Berrangé
Quoted 38 lines · Vladimir Sementsov-Ogievskiy
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calwaystests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +12
-0+static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". +* +* We use data that is not aligned to 16 bytes, so last line +* is incomplete. +*/ +const uint8_t data[] = { +/* First line: 16 bytes */ Quoted 8 lines
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3646
Quoted 6 lines
tests/unit/test-cutils.c +6
-0+0x48 ,0x65 ,0x6c ,0x6c ,0x6f ,0x20 ,0x57 ,0x6f ,/* "Hello Wo" */ +0x72 ,0x6c ,0x64 ,0x21 ,0x20 ,0x54 ,0x68 ,0x69 ,/* "rld! Thi" */ +/* Second line: 5 bytes (incomplete) */ +0x73 ,0x20 ,0x69 ,0x73 ,0x20 /* "s is " */ + }; +char *output =NULL ;Could be
g_autofree, and avoid the later 'free()' call.Quoted 3 lines
I'm not sure that it's correct to replace
free()byg_free()..Documentation says "bad things can happen" https://docs.gtk.org/glib/memory.html
Note where it says:
Quoted 7 lines
"Since GLib 2.46,
g_malloc()is hardcoded to always use the system
malloc implementation."I added that guarantee to glib docs specifically so apps no longer have to match free with
g_free. You should still not mix up the C free vs C++ delete, or free vsg_slice_free, but that's not an issue for QEMU.
I think for this specific case (the buffer allocated by open_memstream()) it's probably better to use explicit free(), because the criterion for "when is it OK to free this?" is not "when the pointer goes out of scope" but "when we have called fclose() on the stream". Auto-freeing the buffer by returning without closing the file would be a bug.
-- PMM
Quoted 55 lines · Peter Maydell
Quoted 46 lines · Daniel P. Berrangé
Quoted 38 lines · Vladimir Sementsov-Ogievskiy
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calwaystests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +12
-0+static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". +* +* We use data that is not aligned to 16 bytes, so last line +* is incomplete. +*/ +const uint8_t data[] = { +/* First line: 16 bytes */ Quoted 8 lines
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3646
Quoted 6 lines
tests/unit/test-cutils.c +6
-0+0x48 ,0x65 ,0x6c ,0x6c ,0x6f ,0x20 ,0x57 ,0x6f ,/* "Hello Wo" */ +0x72 ,0x6c ,0x64 ,0x21 ,0x20 ,0x54 ,0x68 ,0x69 ,/* "rld! Thi" */ +/* Second line: 5 bytes (incomplete) */ +0x73 ,0x20 ,0x69 ,0x73 ,0x20 /* "s is " */ + }; +char *output =NULL ;Could be
g_autofree, and avoid the later 'free()' call.Quoted 3 lines
I'm not sure that it's correct to replace
free()byg_free()..Documentation says "bad things can happen" https://docs.gtk.org/glib/memory.html
Note where it says:
Quoted 7 lines
"Since GLib 2.46,
g_malloc()is hardcoded to always use the system
malloc implementation."I added that guarantee to glib docs specifically so apps no longer have to match free with
g_free. You should still not mix up the C free vs C++ delete, or free vsg_slice_free, but that's not an issue for QEMU.
Quoted 7 lines
I think for this specific case (the buffer allocated by
open_memstream()) it's probably better to use explicitfree(), because the criterion for "when is it OK to free this?" is not "when the pointer goes out of scope" but "when we have calledfclose()on the stream". Auto-freeing the buffer by returning without closing the file would be a bug.
Oh good point, lets just leave this as-is.
With regards,
Daniel
Signature · 3 lines
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
Quoted 64 lines · Daniel P. Berrangé
Quoted 55 lines · Peter Maydell
Quoted 46 lines · Daniel P. Berrangé
Quoted 38 lines · Vladimir Sementsov-Ogievskiy
Quoted 28 lines · Daniel P. Berrangé
Quoted 27 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calwaystests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +12
-0+static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". +* +* We use data that is not aligned to 16 bytes, so last line +* is incomplete. +*/ +const uint8_t data[] = { +/* First line: 16 bytes */ Quoted 8 lines
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3646
Quoted 6 lines
tests/unit/test-cutils.c +6
-0+0x48 ,0x65 ,0x6c ,0x6c ,0x6f ,0x20 ,0x57 ,0x6f ,/* "Hello Wo" */ +0x72 ,0x6c ,0x64 ,0x21 ,0x20 ,0x54 ,0x68 ,0x69 ,/* "rld! Thi" */ +/* Second line: 5 bytes (incomplete) */ +0x73 ,0x20 ,0x69 ,0x73 ,0x20 /* "s is " */ + }; +char *output =NULL ;Could be
g_autofree, and avoid the later 'free()' call.Quoted 3 lines
I'm not sure that it's correct to replace
free()byg_free()..Documentation says "bad things can happen" https://docs.gtk.org/glib/memory.html
Note where it says:
Quoted 7 lines
"Since GLib 2.46,
g_malloc()is hardcoded to always use the system
malloc implementation."I added that guarantee to glib docs specifically so apps no longer have to match free with
g_free. You should still not mix up the C free vs C++ delete, or free vsg_slice_free, but that's not an issue for QEMU.Quoted 7 lines
I think for this specific case (the buffer allocated by
open_memstream()) it's probably better to use explicitfree(), because the criterion for "when is it OK to free this?" is not "when the pointer goes out of scope" but "when we have calledfclose()on the stream". Auto-freeing the buffer by returning without closing the file would be a bug.
Quoted 3 lines
Oh good point, lets just leave this as-is.
Ok.
Signature · 2 lines
Best regards, Vladimir
Quoted 1 line · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
"previous commit" is ambiguous, when this patch is not part of a larger series. Maybe use the term "recent commit" and call out its title and/or commit hash?
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3634
Quoted 11 lines
+++
b/tests/unit/test-cutils.ctests/unit/test-cutils.c +6
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic".
Ah - that's the line I was expecting in the commit message; and I found commit 20aa05ed from there.
Signature · 3 lines
Eric Blake, Principal Software Engineer Red Hat, Inc. Virtualization: qemu.org | libguestfs.org
Quoted 6 lines · Eric Blake
Quoted 1 line · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
"previous commit" is ambiguous, when this patch is not part of a larger series. Maybe use the term "recent commit" and call out its title and/or commit hash?
Good caught! So we need to rewrite first line into
Test for the fix in recent commit
20aa05ed "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic"
Quoted 17 lines
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3634
Quoted 12 lines
+++
b/tests/unit/test-cutils.ctests/unit/test-cutils.c +6
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". Ah - that's the line I was expecting in the commit message; and I found commit
20aa05edfrom there.
Signature · 2 lines
Best regards, Vladimir
Quoted 45 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calwaystests/unit/test-cutils.c | 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +- 2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +22
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ +/* +* Test that ASCII part is properly aligned for incomplete lines. +* This test catches the bug that was fixed in previous commit +* "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". +* +* We use data that is not aligned to 16 bytes, so last line +* is incomplete. +*/ +const uint8_t data[] = { +/* First line: 16 bytes */ +0x48 ,0x65 ,0x6c ,0x6c ,0x6f ,0x20 ,0x57 ,0x6f ,/* "Hello Wo" */ +0x72 ,0x6c ,0x64 ,0x21 ,0x20 ,0x54 ,0x68 ,0x69 ,/* "rld! Thi" */ +/* Second line: 5 bytes (incomplete) */ +0x73 ,0x20 ,0x69 ,0x73 ,0x20 /* "s is " */ + }; +char *output =NULL ; +size_t size; +FILE *stream =open_memstream (&output, &size); + +g_assert_nonnull (stream);
tests/unit/test-cutils.c static void test_si_prefix(void) · line 3660
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ +qemu_hexdump (stream,"test" , data,sizeof (data)); +fclose (stream); + +g_assert_nonnull (output); + +/* We expect proper alignment of "s is" part on the second line */ +const char *expected = +"test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" +"test: 0010: 73 20 69 73 20 s is \n" ;
Thanks, queued wrapping the long lines to pass checkpatch.pl, as in:
https://lore.kernel.org/qemu-devel/[email protected]/
Hi! Isn't this patch lost?
Quoted 59 lines · Philippe Mathieu-Daudé
Quoted 44 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calways
tests/unit/test-cutils.c| 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +-2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +22
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ + /* + * Test that ASCII part is properly aligned for incomplete lines. + * This test catches the bug that was fixed in previous commit + * "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". + * + * We use data that is not aligned to 16 bytes, so last line + * is incomplete. + */ + const uint8_t data[] = { + /* First line: 16 bytes */ + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, /* "Hello Wo" */ + 0x72, 0x6c, 0x64, 0x21, 0x20, 0x54, 0x68, 0x69, /* "rld! Thi" */ + /* Second line: 5 bytes (incomplete) */ + 0x73, 0x20, 0x69, 0x73, 0x20 /* "s is " */ + }; + char *output = NULL; + size_t size; + FILE *stream = open_memstream(&output, &size); + + g_assert_nonnull(stream);tests/unit/test-cutils.c static void test_si_prefix(void) · line 3659
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ + qemu_hexdump(stream, "test", data, sizeof(data)); + fclose(stream); + + g_assert_nonnull(output); + + /* We expect proper alignment of "s is" part on the second line */ + const char *expected = + "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" + "test: 0010: 73 20 69 73 20 s is \n";Thanks, queued wrapping the long lines to pass checkpatch.pl, as in:
https://lore.kernel.org/qemu-devel/[email protected]/
Signature · 2 lines
Best regards, Vladimir
Quoted 66 lines · Vladimir Sementsov-Ogievskiy
Hi! Isn't this patch lost?
Quoted 63 lines · Philippe Mathieu-Daudé
Quoted 55 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calways
tests/unit/test-cutils.c| 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +-2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +13
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ + /* + * Test that ASCII part is properly aligned for incomplete lines. + * This test catches the bug that was fixed in previous commit + * "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". + * + * We use data that is not aligned to 16 bytes, so last line + * is incomplete. + */ + const uint8_t data[] = { + /* First line: 16 bytes */ + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, /* "HelloWo" */
+0x72,0x6c,0x64,0x21,0x20,0x54,0x68, 0x69, /* "rld! Thi" */
+ /* Second line: 5 bytes (incomplete) */
+0x73,0x20,0x69,0x73, 0x20 /* "s is " */ + };
+ char *output = NULL;
+size_tsize;
+ FILE *stream =open_memstream(&output, &size);tests/unit/test-cutils.c +11
-0+ + g_assert_nonnull(stream); + + qemu_hexdump(stream, "test", data, sizeof(data)); + fclose(stream); + + g_assert_nonnull(output); + + /* We expect proper alignment of "s is" part on the second line */ + const char *expected = + "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68Quoted 3 lines
69 Hello World! Thi\n"
+ "test: 0010: 73 20 69 73
20 s is \n";Thanks, queued wrapping the long lines to pass checkpatch.pl,
as in:
https://lore.kernel.org/qemu-devel/20251031211518.38503-9- [email protected]/
I have it tagged but there is still a meson issue. I should revisit but it is low in my priority queue.
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 62 lines · Vladimir Sementsov-Ogievskiy
Hi! Isn't this patch lost?
Quoted 59 lines · Philippe Mathieu-Daudé
Quoted 44 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <[email protected]>---
v3: change meson.build to compile
hexdump.calways
tests/unit/test-cutils.c| 43 ++++++++++++++++++++++++++++++++++++++++ util/meson.build | 2 +-2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +22
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ + /* + * Test that ASCII part is properly aligned for incomplete lines. + * This test catches the bug that was fixed in previous commit + * "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". + * + * We use data that is not aligned to 16 bytes, so last line + * is incomplete. + */ + const uint8_t data[] = { + /* First line: 16 bytes */ + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, /* "Hello Wo" */ + 0x72, 0x6c, 0x64, 0x21, 0x20, 0x54, 0x68, 0x69, /* "rld! Thi" */ + /* Second line: 5 bytes (incomplete) */ + 0x73, 0x20, 0x69, 0x73, 0x20 /* "s is " */ + }; + char *output = NULL; + size_t size; + FILE *stream = open_memstream(&output, &size); + + g_assert_nonnull(stream);tests/unit/test-cutils.c static void test_si_prefix(void) · line 3659
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ + qemu_hexdump(stream, "test", data, sizeof(data)); + fclose(stream); + + g_assert_nonnull(output); + + /* We expect proper alignment of "s is" part on the second line */ + const char *expected = + "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" + "test: 0010: 73 20 69 73 20 s is \n";Thanks, queued wrapping the long lines to pass checkpatch.pl,
as in:
https://lore.kernel.org/qemu-devel/20251031211518.38503-9- [email protected]/
Quoted 2 lines
I have it tagged but there is still a meson issue. I should revisit but it is low in my priority queue.
Ok, thanks
Signature · 2 lines
Best regards, Vladimir
Quoted 72 lines · Vladimir Sementsov-Ogievskiy
Quoted 71 lines · Philippe Mathieu-Daudé
Quoted 69 lines · Vladimir Sementsov-Ogievskiy
Hi! Isn't this patch lost?
Quoted 66 lines · Philippe Mathieu-Daudé
Quoted 55 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <vsementsov@yandex- team.ru>---
v3: change meson.build to compile
hexdump.calways
tests/unit/test-cutils.c| 43 +++++++++++++++++++++++++++++++++++
+++++
util/meson.build | 2 +-2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +13
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ + /* + * Test that ASCII part is properly aligned for incomplete lines. + * This test catches the bug that was fixed in previous commit + * "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". + * + * We use data that is not aligned to 16 bytes, so last line + * is incomplete. + */ + const uint8_t data[] = { + /* First line: 16 bytes */ + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, /* "HelloWo" */
+0x72,0x6c,0x64,0x21,0x20,0x54,0x68, 0x69, /* "rld! Thi" */
+ /* Second line: 5 bytes (incomplete) */
+0x73,0x20,0x69,0x73, 0x20 /* "s is " */
+ };
+ char *output = NULL;
+size_tsize;
+ FILE *stream =open_memstream(&output, &size);tests/unit/test-cutils.c +9
-0+ + g_assert_nonnull(stream); + + qemu_hexdump(stream, "test", data, sizeof(data)); + fclose(stream); + + g_assert_nonnull(output); + + /* We expect proper alignment of "s is" part on the secondQuoted 6 lines
line */
+ const char *expected =
+ "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n"
+ "test: 0010: 73 20 69 73
20 s is \n";Thanks, queued wrapping the long lines to pass checkpatch.pl,
as in:
https://lore.kernel.org/qemu-devel/20251031211518.38503-9- [email protected]/
Quoted 2 lines
Quoted 2 lines
I have it tagged but there is still a meson issue. I should revisit but it is low in my priority queue.
Found it, see that pipeline:
https://gitlab.com/philmd/qemu/-/pipelines/2238533614
configuring with: '../configure' ... '--disable-system'
...
FAILED: tests/unit/test-cutils/usr/bin/ld: tests/unit/test-cutils.p/test-cutils.c.o: in function `test_qemu_hexdump_alignment':
test-cutils.c:(.text+0x71): undefined reference to `qemu_hexdump'
collect2: error: ld returned 1 exit status
Quoted 72 lines · Philippe Mathieu-Daudé
Quoted 65 lines · Vladimir Sementsov-Ogievskiy
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 62 lines · Vladimir Sementsov-Ogievskiy
Hi! Isn't this patch lost?
Quoted 59 lines · Philippe Mathieu-Daudé
Quoted 44 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <vsementsov@yandex- team.ru>---
v3: change meson.build to compile
hexdump.calways
tests/unit/test-cutils.c| 43 +++++++++++++++++++++++++++++++++++ +++++ util/meson.build | 2 +-2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +22
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ + /* + * Test that ASCII part is properly aligned for incomplete lines. + * This test catches the bug that was fixed in previous commit + * "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". + * + * We use data that is not aligned to 16 bytes, so last line + * is incomplete. + */ + const uint8_t data[] = { + /* First line: 16 bytes */ + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, /* "Hello Wo" */ + 0x72, 0x6c, 0x64, 0x21, 0x20, 0x54, 0x68, 0x69, /* "rld! Thi" */ + /* Second line: 5 bytes (incomplete) */ + 0x73, 0x20, 0x69, 0x73, 0x20 /* "s is " */ + }; + char *output = NULL; + size_t size; + FILE *stream = open_memstream(&output, &size); + + g_assert_nonnull(stream);tests/unit/test-cutils.c static void test_si_prefix(void) · line 3659
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ + qemu_hexdump(stream, "test", data, sizeof(data)); + fclose(stream); + + g_assert_nonnull(output); + + /* We expect proper alignment of "s is" part on the second line */ + const char *expected = + "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" + "test: 0010: 73 20 69 73 20 s is \n";Thanks, queued wrapping the long lines to pass checkpatch.pl,
as in:
https://lore.kernel.org/qemu-devel/20251031211518.38503-9- [email protected]/Quoted 2 lines
Quoted 2 lines
I have it tagged but there is still a meson issue. I should revisit but it is low in my priority queue.
Found it, see that pipeline:
https://gitlab.com/philmd/qemu/-/pipelines/2238533614
Quoted 7 lines
configuring with: '../configure' ... '--disable-system'
...
FAILED: tests/unit/test-cutils/usr/bin/ld:tests/unit/test-cutils.p/test-cutils.c.o: in function `test_qemu_hexdump_alignment':
test-cutils.c:(.text+0x71): undefined reference to `qemu_hexdump'
collect2: error: ld returned 1 exit status
Hmm. Interesting, locally it builds for me with same configure line..
Signature · 2 lines
Best regards, Vladimir
Quoted 66 lines · Philippe Mathieu-Daudé
Quoted 65 lines · Vladimir Sementsov-Ogievskiy
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 62 lines · Vladimir Sementsov-Ogievskiy
Hi! Isn't this patch lost?
Quoted 59 lines · Philippe Mathieu-Daudé
Quoted 44 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <vsementsov@yandex- team.ru>---
v3: change meson.build to compile
hexdump.calways
tests/unit/test-cutils.c| 43 +++++++++++++++++++++++++++++++++++ +++++ util/meson.build | 2 +-2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +22
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ + /* + * Test that ASCII part is properly aligned for incomplete lines. + * This test catches the bug that was fixed in previous commit + * "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". + * + * We use data that is not aligned to 16 bytes, so last line + * is incomplete. + */ + const uint8_t data[] = { + /* First line: 16 bytes */ + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, /* "Hello Wo" */ + 0x72, 0x6c, 0x64, 0x21, 0x20, 0x54, 0x68, 0x69, /* "rld! Thi" */ + /* Second line: 5 bytes (incomplete) */ + 0x73, 0x20, 0x69, 0x73, 0x20 /* "s is " */ + }; + char *output = NULL; + size_t size; + FILE *stream = open_memstream(&output, &size); + + g_assert_nonnull(stream);tests/unit/test-cutils.c static void test_si_prefix(void) · line 3659
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ + qemu_hexdump(stream, "test", data, sizeof(data)); + fclose(stream); + + g_assert_nonnull(output); + + /* We expect proper alignment of "s is" part on the second line */ + const char *expected = + "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" + "test: 0010: 73 20 69 73 20 s is \n";Thanks, queued wrapping the long lines to pass checkpatch.pl,
as in:
https://lore.kernel.org/qemu-devel/20251031211518.38503-9- [email protected]/
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
I have it tagged but there is still a meson issue. I should revisit but it is low in my priority queue.
Found it, see that pipeline:
https://gitlab.com/philmd/qemu/-/pipelines/2238533614
This build contains previous version of the patch. v3 should fix it.
Quoted 8 lines
configuring with: '../configure' ... '--disable-system'
...
FAILED: tests/unit/test-cutils/usr/bin/ld:tests/unit/test-cutils.p/test-cutils.c.o: in function `test_qemu_hexdump_alignment':
test-cutils.c:(.text+0x71): undefined reference to `qemu_hexdump'
collect2: error: ld returned 1 exit status
Signature · 2 lines
Best regards, Vladimir
Quoted 75 lines · Vladimir Sementsov-Ogievskiy
Quoted 74 lines · Philippe Mathieu-Daudé
Quoted 73 lines · Vladimir Sementsov-Ogievskiy
Quoted 72 lines · Philippe Mathieu-Daudé
Quoted 70 lines · Vladimir Sementsov-Ogievskiy
Hi! Isn't this patch lost?
Quoted 67 lines · Philippe Mathieu-Daudé
Quoted 56 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <vsementsov@yandex- team.ru>---
v3: change meson.build to compile
hexdump.calways
tests/unit/test-cutils.c| 43 +++++++++++++++++++++++++++++++++ ++ +++++
util/meson.build | 2 +-2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +4
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ + /* +* Test that ASCII part is properly aligned for incomplete lines.
+ * This test catches the bug that was fixed in previous commit + * "util/hexdump: fixQEMU_HEXDUMP_LINE_WIDTHlogic". + *
+ * We use data that is not aligned to 16 bytes, so last line + * is incomplete.
+ */
+ constuint8_tdata[] = {
+ /* First line: 16 bytes */
+0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57, 0x6f, /* "Hello Wo" */
+0x72,0x6c,0x64,0x21,0x20,0x54,0x68, 0x69, /* "rld! Thi" */
+ /* Second line: 5 bytes (incomplete) */
+0x73,0x20,0x69,0x73, 0x20 /* "s is " */
+ };
+ char *output = NULL;
+size_tsize;
+ FILE *stream =open_memstream(&output, &size);tests/unit/test-cutils.c +9
-0+ + g_assert_nonnull(stream); + + qemu_hexdump(stream, "test", data, sizeof(data)); + fclose(stream); + + g_assert_nonnull(output); + + /* We expect proper alignment of "s is" part on the secondQuoted 6 lines
line */
+ const char *expected =
+ "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n"
+ "test: 0010: 73 20 69 73
20 s is \n";Thanks, queued wrapping the long lines to pass checkpatch.pl,
as in:
https://lore.kernel.org/qemu-devel/20251031211518.38503-9- [email protected]/
Quoted 7 lines
Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
I have it tagged but there is still a meson issue. I should revisit but it is low in my priority queue.
Found it, see that pipeline:
https://gitlab.com/philmd/qemu/-/pipelines/2238533614This build contains previous version of the patch. v3 should fix it.
Doh sorry, maybe I tested v2 then, I don't remember :(
Quoted 11 lines
Quoted 9 lines
configuring with: '../configure' ... '--disable-system'
...
FAILED: tests/unit/test-cutils/usr/bin/ld:tests/unit/test-cutils.p/test-cutils.c.o: in function `test_qemu_hexdump_alignment':
test-cutils.c:(.text+0x71): undefined reference to `qemu_hexdump'
collect2: error: ld returned 1 exit status
Quoted 79 lines · Philippe Mathieu-Daudé
Quoted 78 lines · Vladimir Sementsov-Ogievskiy
Quoted 77 lines · Philippe Mathieu-Daudé
Quoted 75 lines · Vladimir Sementsov-Ogievskiy
Quoted 74 lines · Philippe Mathieu-Daudé
Quoted 70 lines · Vladimir Sementsov-Ogievskiy
Hi! Isn't this patch lost?
Quoted 67 lines · Philippe Mathieu-Daudé
Quoted 56 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <vsementsov@yandex- team.ru>---
v3: change meson.build to compile
hexdump.calways
tests/unit/test-cutils.c| 43 ++++++++++++++++++++++++++++++++
+ ++ +++++
util/meson.build | 2 +-2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +4
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ + /* +* Test that ASCII part is properly aligned for incomplete lines.
+ * This test catches the bug that was fixed in previous commit + * "util/hexdump: fixQEMU_HEXDUMP_LINE_WIDTHlogic". + *
+ * We use data that is not aligned to 16 bytes, so last line + * is incomplete.
+ */
+ constuint8_tdata[] = {
+ /* First line: 16 bytes */
+0x48,0x65,0x6c,0x6c,0x6f,0x20,0x57, 0x6f, /* "Hello Wo" */
+0x72,0x6c,0x64,0x21,0x20,0x54,0x68, 0x69, /* "rld! Thi" */
+ /* Second line: 5 bytes (incomplete) */
+0x73,0x20,0x69,0x73, 0x20 /* "s is " */
+ };
+ char *output = NULL;
+size_tsize;
+ FILE *stream =open_memstream(&output, &size);tests/unit/test-cutils.c +9
-0+ + g_assert_nonnull(stream); + + qemu_hexdump(stream, "test", data, sizeof(data)); + fclose(stream); + + g_assert_nonnull(output); + + /* We expect proper alignment of "s is" part on the secondQuoted 6 lines
line */
+ const char *expected =
+ "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n"
+ "test: 0010: 73 20 69 73
20 s is \n";Thanks, queued wrapping the long lines to pass checkpatch.pl,
as in:
https://lore.kernel.org/qemu-devel/20251031211518.38503-9- [email protected]/I have it tagged but there is still a meson issue. I should revisit but it is low in my priority queue.
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
Found it, see that pipeline:
https://gitlab.com/philmd/qemu/-/pipelines/2238533614This build contains previous version of the patch. v3 should fix it.
Doh sorry, maybe I tested v2 then, I don't remember :(
On MinGW (v3):
../tests/unit/test-cutils.c: In function 'test_qemu_hexdump_alignment':../tests/unit/test-cutils.c:3648:20: error: implicit declaration of function 'open_memstream' [-Wimplicit-function-declaration]
3648 | FILE *stream = open_memstream(&output, &size);
| ^~~~~~~~~~~~~~Quoted 13 lines
Quoted 12 lines
Quoted 10 lines
configuring with: '../configure' ... '--disable-system'
...
FAILED: tests/unit/test-cutils/usr/bin/ld:tests/unit/test-cutils.p/test-cutils.c.o: in function `test_qemu_hexdump_alignment':
test-cutils.c:(.text+0x71): undefined reference to `qemu_hexdump'
collect2: error: ld returned 1 exit status
Quoted 77 lines · Philippe Mathieu-Daudé
Quoted 76 lines · Philippe Mathieu-Daudé
Quoted 74 lines · Vladimir Sementsov-Ogievskiy
Quoted 66 lines · Philippe Mathieu-Daudé
Quoted 65 lines · Vladimir Sementsov-Ogievskiy
Quoted 64 lines · Philippe Mathieu-Daudé
Quoted 62 lines · Vladimir Sementsov-Ogievskiy
Hi! Isn't this patch lost?
Quoted 59 lines · Philippe Mathieu-Daudé
Quoted 44 lines · Vladimir Sementsov-Ogievskiy
Test, that fix in previous commit make sense.
To not break compilation when we build without
'block', movehexdump.cout of "ifhave_block"
in meson.build.Signed-off-by Vladimir Sementsov-Ogievskiy <vsementsov@yandex- team.ru>---
v3: change meson.build to compile
hexdump.calways
tests/unit/test-cutils.c| 43 ++++++++++++++++++++++++++++++++ + ++ +++++ util/meson.build | 2 +-2 files changed, 44 insertions(+), 1 deletion(-)tests/unit/test-cutils.c +22
-0@@ -3626,6 +3626,44 @@ static void test_si_prefix(void) g_assert_cmpstr(si_prefix(18), ==, "E"); } +static void test_qemu_hexdump_alignment (void ) +{ + /* + * Test that ASCII part is properly aligned for incomplete lines. + * This test catches the bug that was fixed in previous commit + * "util/hexdump: fix QEMU_HEXDUMP_LINE_WIDTH logic". + * + * We use data that is not aligned to 16 bytes, so last line + * is incomplete. + */ + const uint8_t data[] = { + /* First line: 16 bytes */ + 0x48, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x57, 0x6f, /* "Hello Wo" */ + 0x72, 0x6c, 0x64, 0x21, 0x20, 0x54, 0x68, 0x69, /* "rld! Thi" */ + /* Second line: 5 bytes (incomplete) */ + 0x73, 0x20, 0x69, 0x73, 0x20 /* "s is " */ + }; + char *output = NULL; + size_t size; + FILE *stream = open_memstream(&output, &size); + + g_assert_nonnull(stream);tests/unit/test-cutils.c static void test_si_prefix(void) · line 3659
Quoted 10 lines
tests/unit/test-cutils.c +10
-0+ + qemu_hexdump(stream, "test", data, sizeof(data)); + fclose(stream); + + g_assert_nonnull(output); + + /* We expect proper alignment of "s is" part on the second line */ + const char *expected = + "test: 0000: 48 65 6c 6c 6f 20 57 6f 72 6c 64 21 20 54 68 69 Hello World! Thi\n" + "test: 0010: 73 20 69 73 20 s is \n";Thanks, queued wrapping the long lines to pass checkpatch.pl,
as in:
https://lore.kernel.org/qemu-devel/20251031211518.38503-9- [email protected]/Quoted 5 lines
Quoted 2 lines
Quoted 2 lines
I have it tagged but there is still a meson issue. I should revisit but it is low in my priority queue.
Found it, see that pipeline:
https://gitlab.com/philmd/qemu/-/pipelines/2238533614This build contains previous version of the patch. v3 should fix it.
Quoted 9 lines
Quoted 1 line
Doh sorry, maybe I tested v2 then, I don't remember :(
On MinGW (v3):
../tests/unit/test-cutils.c: In function 'test_qemu_hexdump_alignment':../tests/unit/test-cutils.c:3648:20: error: implicit declaration of function 'open_memstream' [-Wimplicit-function-declaration]
3648 | FILE *stream =open_memstream(&output, &size);
| ^~~~~~~~~~~~~~
Ogh. Let's try without open_memstream, I'll send a v4.
Signature · 2 lines
Best regards, Vladimir