Heinrich Schuchardt | 8208dde | 2024-03-22 08:57:30 +0100 | [diff] [blame] | 1 | .. SPDX-License-Identifier: GPL-2.0+ |
| 2 | |
| 3 | .. index:: |
| 4 | single: itest (command) |
| 5 | |
| 6 | itest command |
| 7 | ============= |
| 8 | |
| 9 | Synopsis |
| 10 | -------- |
| 11 | |
| 12 | :: |
| 13 | |
| 14 | itest[.b | .w | .l | .q | .s] [*]<value1> <op> [*]<value2> |
| 15 | |
| 16 | Description |
| 17 | ----------- |
| 18 | |
| 19 | The itest command is used to compare two values. The return value $? is set |
| 20 | accordingly. |
| 21 | |
| 22 | By default it is assumed that the values are 4 byte integers. By appending a |
| 23 | postfix (.b, .w, .l, .q, .s) the size can be specified: |
| 24 | |
| 25 | ======= ====================================================== |
| 26 | postfix meaning |
| 27 | ======= ====================================================== |
| 28 | .b 1 byte integer |
| 29 | .w 2 byte integer |
| 30 | .l 4 byte integer |
| 31 | .q 8 byte integer (only available if CONFIG_PHYS_64BIT=y) |
| 32 | .s string |
| 33 | ======= ====================================================== |
| 34 | |
| 35 | value1, value2 |
| 36 | values to compare. Numeric values are hexadecimal. If '*' is prefixed a |
| 37 | hexadecimal address is passed, which points to the value to be compared. |
| 38 | |
| 39 | op |
| 40 | operator, see table |
| 41 | |
| 42 | ======== ====================== |
| 43 | operator meaning |
| 44 | ======== ====================== |
| 45 | -lt less than |
| 46 | < less than |
| 47 | -le less or equal |
| 48 | <= less or equal |
| 49 | -eq equal |
| 50 | == equal |
| 51 | -ne not equal |
| 52 | != not equal |
| 53 | <> not equal |
| 54 | -ge greater or equal |
| 55 | >= greater or equal |
| 56 | -gt greater than |
| 57 | > greater than |
| 58 | ======== ====================== |
| 59 | |
| 60 | Examples |
| 61 | ======== |
| 62 | |
| 63 | The itest command sets the result variable $? to true (0) or false (1): |
| 64 | |
| 65 | :: |
| 66 | |
| 67 | => itest 3 < 4; echo $? |
| 68 | 0 |
| 69 | => itest 3 == 4; echo $? |
| 70 | 1 |
| 71 | |
| 72 | This value can be used in the :doc:`if <if>` command: |
| 73 | |
| 74 | :: |
| 75 | |
| 76 | => if itest 0x3002 < 0x4001; then echo true; else echo false; fi |
| 77 | true |
| 78 | |
| 79 | Numbers will be truncated according to the postfix before comparing: |
| 80 | |
| 81 | :: |
| 82 | |
| 83 | => if itest.b 0x3002 < 0x4001; then echo true; else echo false; fi |
| 84 | false |
| 85 | |
| 86 | Postfix .s causes a string compare. The string '0xa1234' is alphabetically |
| 87 | smaller than '0xb'. |
| 88 | |
Heinrich Schuchardt | 5f7c0ec | 2024-03-28 21:16:54 +0100 | [diff] [blame] | 89 | :: |
| 90 | |
Heinrich Schuchardt | 8208dde | 2024-03-22 08:57:30 +0100 | [diff] [blame] | 91 | => if itest.s 0xa1234 < 0xb; then echo true; else echo false; fi |
| 92 | true |
| 93 | |
| 94 | A value prefixed by '*' is a pointer to the value in memory. |
| 95 | |
| 96 | :: |
| 97 | |
| 98 | => mm 0x4000 |
| 99 | 00004000: 00000004 ? |
| 100 | 00004004: 00000003 ? => |
| 101 | => if itest *0x4000 == 4; then echo true; else echo false; fi |
| 102 | true |
| 103 | => if itest *0x4004 == 3; then echo true; else echo false; fi |
| 104 | true |
| 105 | |
| 106 | Configuration |
| 107 | ------------- |
| 108 | |
| 109 | The command is only available if CONFIG_CMD_ITEST=y. |
| 110 | |
| 111 | Return value |
| 112 | ------------ |
| 113 | |
| 114 | The return value $? is 0 (true) if the condition is true and 1 (false) |
| 115 | otherwise. |