Loading...
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 | // SPDX-License-Identifier: GPL-2.0+ /* * Test for chid command * * Copyright 2025 Simon Glass <sjg@chromium.org> */ #include <command.h> #include <console.h> #include <env.h> #include <test/cmd.h> #include <test/ut.h> #include <version.h> /* Test the 'chid show' command */ static int cmd_chid_show_test(struct unit_test_state *uts) { /* Test chid show command and verify expected output */ ut_assertok(run_command("chid show", 0)); ut_assert_nextline("Manufacturer: Sandbox Corp"); ut_assert_nextline("Family: Sandbox_Family"); ut_assert_nextline("Product Name: Sandbox Computer"); ut_assert_nextline("Product SKU: SANDBOX-SKU"); ut_assert_nextline("Baseboard Manuf: Sandbox Boards"); ut_assert_nextline("Baseboard Product: Sandbox Motherboard"); ut_assert_nextline("BIOS Vendor: U-Boot"); ut_assert_nextlinen("BIOS Version: " PLAIN_VERSION); ut_assert_nextline("BIOS Major: %u", U_BOOT_VERSION_NUM % 100); ut_assert_nextline("BIOS Minor: %u", U_BOOT_VERSION_NUM_PATCH); ut_assert_nextline("Enclosure Type: 2"); ut_assert_console_end(); return 0; } CMD_TEST(cmd_chid_show_test, UTF_CONSOLE); /* Test invalid chid subcommand */ static int cmd_chid_invalid_test(struct unit_test_state *uts) { /* Test chid command with invalid arguments */ ut_asserteq(1, run_command("chid invalid", 0)); return 0; } CMD_TEST(cmd_chid_invalid_test, UTF_CONSOLE); /* Test the 'chid list' command */ static int cmd_chid_list_test(struct unit_test_state *uts) { /* Test chid list command runs successfully */ ut_assertok(run_command("chid list", 0)); /* Just verify that some output is produced - exact CHIDs vary */ return 0; } CMD_TEST(cmd_chid_list_test, UTF_CONSOLE); /* Test the 'chid detail' command */ static int cmd_chid_detail_test(struct unit_test_state *uts) { /* Test chid detail command for variant 14 (manufacturer only) */ ut_assertok(run_command("chid detail 14", 0)); ut_assert_nextlinen("HardwareID-14: "); ut_assert_nextline("Fields: Manufacturer"); ut_assert_console_end(); /* Test chid detail command for variant 0 (most specific) */ ut_assertok(run_command("chid detail 0", 0)); ut_assert_nextlinen("HardwareID-00: "); ut_assert_nextline( "Fields: Manufacturer + Family + ProductName + ProductSku + " "BiosVendor + BiosVersion + BiosMajorRelease + " "BiosMinorRelease"); ut_assert_console_end(); return 0; } CMD_TEST(cmd_chid_detail_test, UTF_CONSOLE); /* Test chid detail with invalid variant */ static int cmd_chid_detail_invalid_test(struct unit_test_state *uts) { /* Test chid detail with invalid variant number - should fail */ ut_asserteq(1, run_command("chid detail 15", 0)); /* Test chid detail with negative variant number - should fail */ ut_asserteq(1, run_command("chid detail -1", 0)); return 0; } CMD_TEST(cmd_chid_detail_invalid_test, 0); /* Test the 'chid compat' command */ static int cmd_chid_compat_test(struct unit_test_state *uts) { const char *fdtcompat_val; int ret; /* Clear any existing fdtcompat environment variable */ env_set("fdtcompat", NULL); ut_assertnull(env_get("fdtcompat")); /* Run chid compat command - may succeed or fail depending on devicetree */ ret = run_command("chid compat", 0); if (ret == 0) { /* Command succeeded, check that fdtcompat was set */ fdtcompat_val = env_get("fdtcompat"); ut_assertnonnull(fdtcompat_val); ut_assert(strlen(fdtcompat_val) > 0); /* Command should print the compatible string it found */ ut_assert_nextline(fdtcompat_val); } else { /* Command failed, check expected failure message and no env var set */ ut_assert_nextline("No compatible string found"); ut_assertnull(env_get("fdtcompat")); } ut_assert_console_end(); return 0; } CMD_TEST(cmd_chid_compat_test, UTF_CONSOLE); |