From 0da08289139d3b91987e7729eb0e9652a0b35a37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Ferr=C3=A3o?= <2031761+viniciusferrao@users.noreply.github.com> Date: Thu, 20 Aug 2026 22:41:53 -0300 Subject: [PATCH] test(genesis): cover narrow console headers --- xCAT-test/unit/genesis_openembedded_console.t | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/xCAT-test/unit/genesis_openembedded_console.t b/xCAT-test/unit/genesis_openembedded_console.t index 0d749c462..5ba34746e 100644 --- a/xCAT-test/unit/genesis_openembedded_console.t +++ b/xCAT-test/unit/genesis_openembedded_console.t @@ -17,6 +17,8 @@ my @plain_sources = map { File::Spec->catfile( $source_dir, $_ ) } qw(main.c plain_ui.c shell.c state.c support.c); my $root = tempdir( CLEANUP => 1 ); my $binary = File::Spec->catfile( $root, 'xcat-genesis-console' ); +my $header_test_source = File::Spec->catfile( $root, 'header-test.c' ); +my $header_test_binary = File::Spec->catfile( $root, 'header-test' ); my $compiler = $ENV{CC} || 'cc'; is( @@ -44,6 +46,35 @@ sub read_file { return $contents; } +write_file( + $header_test_source, + <<'C' +#include "console.h" + +#include + +int main(void) { + assert(xcat_header_context_columns(0) == 0); + assert(xcat_header_context_columns(19) == 0); + assert(xcat_header_context_columns(20) == 0); + assert(xcat_header_context_columns(21) == 1); + assert(xcat_header_context_columns(80) == 60); + return 0; +} +C +); +is( + system( + $compiler, '-D_POSIX_C_SOURCE=200809L', '-std=c17', '-Wall', '-Wextra', + '-Wpedantic', '-Werror', '-I', $source_dir, $header_test_source, + File::Spec->catfile( $source_dir, 'support.c' ), '-o', $header_test_binary + ) >> 8, + 0, + 'header bounds test builds with strict warnings' +); +is( system($header_test_binary) >> 8, 0, + 'narrow terminals leave no writable header context' ); + my $cmdline = File::Spec->catfile( $root, 'cmdline' ); my $uptime = File::Spec->catfile( $root, 'uptime' ); my $os_release_real = File::Spec->catfile( $root, 'os-release.real' ); @@ -365,6 +396,8 @@ like( $console_source, qr/state->serial/, 'header shows the firmware serial when available' ); unlike( $header_source, qr/state->architecture/, 'header leaves architecture in diagnostics' ); +like( $header_source, qr/xcat_header_context_columns\(columns\)/, + 'header clamps its context to the available terminal width' ); my ($logs_source) = $newt_source =~ /(static void show_logs.*?)(?=\nstatic void show_maintenance_shell)/s;