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 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 | // SPDX-License-Identifier: GPL-2.0+ /* * Test for sb command * * Copyright (C) 2025 Canonical Ltd */ #include <dm.h> #include <asm/state.h> #include <dm/test.h> #include <test/test.h> #include <test/ut.h> /* Basic test of 'sb devon' and 'sb devoff' commands */ static int dm_test_sb_devon_devoff(struct unit_test_state *uts) { struct udevice *dev; ofnode root, node; /* Find the mmc11 device tree node */ root = oftree_root(oftree_default()); node = ofnode_find_subnode(root, "mmc11"); ut_assert(ofnode_valid(node)); /* Verify device is not initially bound */ ut_assert(device_find_global_by_ofnode(node, &dev)); /* Enable the device using 'sb devon' */ ut_assertok(run_command("sb devon mmc11", 0)); ut_assert_nextline("Device 'mmc11' enabled"); ut_assert_console_end(); /* Verify device is now bound and probed */ ut_assertok(device_find_global_by_ofnode(node, &dev)); ut_assertnonnull(dev); ut_assert(device_active(dev)); /* Disable the device using 'sb devoff' */ ut_assertok(run_command("sb devoff mmc11", 0)); ut_assert_nextline("Device 'mmc11' disabled"); ut_assert_console_end(); /* Verify device is no longer bound */ ut_assert(device_find_global_by_ofnode(node, &dev)); return 0; } DM_TEST(dm_test_sb_devon_devoff, UTF_SCAN_FDT | UTF_CONSOLE); /* Test 'sb devon' with invalid node */ static int dm_test_sb_devon_invalid(struct unit_test_state *uts) { /* Try to enable non-existent device */ ut_asserteq(1, run_command("sb devon nonexistent", 0)); ut_assert_nextline("Device tree node 'nonexistent' not found"); ut_assert_console_end(); return 0; } DM_TEST(dm_test_sb_devon_invalid, UTF_SCAN_FDT | UTF_CONSOLE); /* Test 'sb devoff' with invalid node */ static int dm_test_sb_devoff_invalid(struct unit_test_state *uts) { /* Try to disable non-existent device */ ut_asserteq(1, run_command("sb devoff nonexistent", 0)); ut_assert_nextline("Device tree node 'nonexistent' not found"); ut_assert_console_end(); return 0; } DM_TEST(dm_test_sb_devoff_invalid, UTF_SCAN_FDT | UTF_CONSOLE); /* Test 'sb devon' on device that's already enabled */ static int dm_test_sb_devon_already_enabled(struct unit_test_state *uts) { /* Enable the device first */ ut_assertok(run_command("sb devon mmc11", 0)); ut_assert_nextline("Device 'mmc11' enabled"); ut_assert_console_end(); /* Try to enable it again - should fail */ ut_asserteq(1, run_command("sb devon mmc11", 0)); ut_assert_nextline("Device 'mmc11' is already enabled"); ut_assert_console_end(); /* Clean up - disable the device */ ut_assertok(run_command("sb devoff mmc11", 0)); ut_assert_nextline("Device 'mmc11' disabled"); ut_assert_console_end(); return 0; } DM_TEST(dm_test_sb_devon_already_enabled, UTF_SCAN_FDT | UTF_CONSOLE); /* Test 'sb devoff' on device that's not bound */ static int dm_test_sb_devoff_not_bound(struct unit_test_state *uts) { struct udevice *dev; ofnode root, node; /* Find the mmc11 device tree node */ root = oftree_root(oftree_default()); node = ofnode_find_subnode(root, "mmc11"); ut_assert(ofnode_valid(node)); /* Ensure device is not bound (clean up from any previous test) */ if (!device_find_global_by_ofnode(node, &dev)) { ut_assertok(run_command("sb devoff mmc11", 0)); ut_assert_nextlinen("Device 'mmc11' disabled"); ut_assert_console_end(); } /* Verify device is not bound */ ut_assert(device_find_global_by_ofnode(node, &dev)); /* Try to disable a device that's not bound */ ut_asserteq(1, run_command("sb devoff mmc11", 0)); ut_assert_nextlinen("Device 'mmc11' not found or not bound"); ut_assert_console_end(); return 0; } DM_TEST(dm_test_sb_devoff_not_bound, UTF_SCAN_FDT | UTF_CONSOLE); /* Test 'sb grid' command */ static int dm_test_sb_grid(struct unit_test_state *uts) { struct sandbox_state *state = state_get_current(); /* Ensure grid is initially off */ state->show_grid = false; state->grid_size = 0; /* Enable grid */ ut_assertok(run_command("sb grid 1", 0)); ut_assert_console_end(); ut_asserteq(true, state->show_grid); /* Disable grid */ ut_assertok(run_command("sb grid 0", 0)); ut_assert_console_end(); ut_asserteq(false, state->show_grid); /* Enable grid with custom size (0x14 = 20 decimal) */ ut_assertok(run_command("sb grid 1 14", 0)); ut_assert_console_end(); ut_asserteq(true, state->show_grid); ut_asserteq(0x14, state->grid_size); /* Clean up */ state->show_grid = false; state->grid_size = 0; return 0; } DM_TEST(dm_test_sb_grid, UTF_CONSOLE); |