1*640235e2SEnji Cooper# $NetBSD: t_arith.sh,v 1.5 2016/05/12 14:25:11 kre Exp $ 2*640235e2SEnji Cooper# 3*640235e2SEnji Cooper# Copyright (c) 2016 The NetBSD Foundation, Inc. 4*640235e2SEnji Cooper# All rights reserved. 5*640235e2SEnji Cooper# 6*640235e2SEnji Cooper# Redistribution and use in source and binary forms, with or without 7*640235e2SEnji Cooper# modification, are permitted provided that the following conditions 8*640235e2SEnji Cooper# are met: 9*640235e2SEnji Cooper# 1. Redistributions of source code must retain the above copyright 10*640235e2SEnji Cooper# notice, this list of conditions and the following disclaimer. 11*640235e2SEnji Cooper# 2. Redistributions in binary form must reproduce the above copyright 12*640235e2SEnji Cooper# notice, this list of conditions and the following disclaimer in the 13*640235e2SEnji Cooper# documentation and/or other materials provided with the distribution. 14*640235e2SEnji Cooper# 15*640235e2SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 16*640235e2SEnji Cooper# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 17*640235e2SEnji Cooper# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18*640235e2SEnji Cooper# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 19*640235e2SEnji Cooper# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 20*640235e2SEnji Cooper# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 21*640235e2SEnji Cooper# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 22*640235e2SEnji Cooper# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 23*640235e2SEnji Cooper# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 24*640235e2SEnji Cooper# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25*640235e2SEnji Cooper# POSSIBILITY OF SUCH DAMAGE. 26*640235e2SEnji Cooper# 27*640235e2SEnji Cooper# the implementation of "sh" to test 28*640235e2SEnji Cooper: ${TEST_SH:="/bin/sh"} 29*640235e2SEnji Cooper 30*640235e2SEnji Cooper# Requirement is to support at least "signed long" whatever that means 31*640235e2SEnji Cooper# (number of bits in "long" is not specified - but should be at least 32). 32*640235e2SEnji Cooper 33*640235e2SEnji Cooper# These tests use -o inline:"..." rather than -o match:'...' as we have 34*640235e2SEnji Cooper# only digits to examine, and it is good to be sure that 1 + 1 really gives 2 35*640235e2SEnji Cooper# and that 42 or 123 don't look like success because there is a 2 in them. 36*640235e2SEnji Cooper 37*640235e2SEnji CooperARITH_BITS='?' 38*640235e2SEnji Cooperdiscover_range() 39*640235e2SEnji Cooper{ 40*640235e2SEnji Cooper # cannot use arithmetic "test" operators, range of test in 41*640235e2SEnji Cooper # ATF_SHELL (or even TEST_SH) might not be as big as that 42*640235e2SEnji Cooper # supported by $(( )) in TEST_SH 43*640235e2SEnji Cooper 44*640235e2SEnji Cooper if ! ${TEST_SH} -c ': $(( 0x10000 ))' 2>/dev/null 45*640235e2SEnji Cooper then 46*640235e2SEnji Cooper # 16 bits or less, or hex unsupported, just give up... 47*640235e2SEnji Cooper return 48*640235e2SEnji Cooper fi 49*640235e2SEnji Cooper test $( ${TEST_SH} -c 'echo $(( 0x1FFFF ))' ) = 131071 || return 50*640235e2SEnji Cooper 51*640235e2SEnji Cooper # when attempting to exceed the number of available bits 52*640235e2SEnji Cooper # the shell may react in any of 3 (rational) ways 53*640235e2SEnji Cooper # 1. syntax error (maybe even core dump...) and fail 54*640235e2SEnji Cooper # 2. represent a positive number input as negative value 55*640235e2SEnji Cooper # 3. keep the number positive, but not the value expected 56*640235e2SEnji Cooper # (perhaps pegged at the max possible value) 57*640235e2SEnji Cooper # any of those may be accompanied by a message to stderr 58*640235e2SEnji Cooper 59*640235e2SEnji Cooper # Must check all 3 possibilities for each plausible size 60*640235e2SEnji Cooper # Tests do not use 0x8000... because that value can have weird 61*640235e2SEnji Cooper # other side effects that are not relevant to discover here. 62*640235e2SEnji Cooper # But we do want to try and force the sign bit set. 63*640235e2SEnji Cooper 64*640235e2SEnji Cooper if ! ${TEST_SH} -c ': $(( 0xC0000000 ))' 2>/dev/null 65*640235e2SEnji Cooper then 66*640235e2SEnji Cooper # proobably shell detected overflow and complained 67*640235e2SEnji Cooper ARITH_BITS=32 68*640235e2SEnji Cooper return 69*640235e2SEnji Cooper fi 70*640235e2SEnji Cooper if ${TEST_SH} 2>/dev/null \ 71*640235e2SEnji Cooper -c 'case $(( 0xC0000000 )); in (-*) exit 0;; esac; exit 1' 72*640235e2SEnji Cooper then 73*640235e2SEnji Cooper ARITH_BITS=32 74*640235e2SEnji Cooper return 75*640235e2SEnji Cooper fi 76*640235e2SEnji Cooper if ${TEST_SH} -c '[ $(( 0xC0000000 )) != 3221225472 ]' 2>/dev/null 77*640235e2SEnji Cooper then 78*640235e2SEnji Cooper ARITH_BITS=32 79*640235e2SEnji Cooper return 80*640235e2SEnji Cooper fi 81*640235e2SEnji Cooper 82*640235e2SEnji Cooper if ! ${TEST_SH} -c ': $(( 0xC000000000000000 ))' 2>/dev/null 83*640235e2SEnji Cooper then 84*640235e2SEnji Cooper ARITH_BITS=64 85*640235e2SEnji Cooper return 86*640235e2SEnji Cooper fi 87*640235e2SEnji Cooper if ${TEST_SH} 2>/dev/null \ 88*640235e2SEnji Cooper -c 'case $(( 0xC000000000000000 )); in (-*) exit 0;; esac; exit 1' 89*640235e2SEnji Cooper then 90*640235e2SEnji Cooper ARITH_BITS=64 91*640235e2SEnji Cooper return 92*640235e2SEnji Cooper fi 93*640235e2SEnji Cooper if ${TEST_SH} 2>/dev/null \ 94*640235e2SEnji Cooper -c '[ $((0xC000000000000000)) != 13835058055282163712 ]' 95*640235e2SEnji Cooper then 96*640235e2SEnji Cooper ARITH_BITS=64 97*640235e2SEnji Cooper return 98*640235e2SEnji Cooper fi 99*640235e2SEnji Cooper 100*640235e2SEnji Cooper if ${TEST_SH} 2>/dev/null -c \ 101*640235e2SEnji Cooper '[ $((0x123456781234567812345678)) = 5634002657842756053938493048 ]' 102*640235e2SEnji Cooper then 103*640235e2SEnji Cooper # just assume... (for now anyway, revisit when it happens...) 104*640235e2SEnji Cooper ARITH_BITS=96 105*640235e2SEnji Cooper return 106*640235e2SEnji Cooper fi 107*640235e2SEnji Cooper} 108*640235e2SEnji Cooper 109*640235e2SEnji Cooperatf_test_case constants 110*640235e2SEnji Cooperconstants_head() 111*640235e2SEnji Cooper{ 112*640235e2SEnji Cooper atf_set "descr" "Tests that arithmetic expansion can handle constants" 113*640235e2SEnji Cooper} 114*640235e2SEnji Cooperconstants_body() 115*640235e2SEnji Cooper{ 116*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 117*640235e2SEnji Cooper 'echo $(( 1 ))' 118*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 119*640235e2SEnji Cooper 'echo $(( 0 ))' 120*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 121*640235e2SEnji Cooper 'echo $((0x0))' 122*640235e2SEnji Cooper 123*640235e2SEnji Cooper # atf_expect_fail "PR bin/50959" 124*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 125*640235e2SEnji Cooper 'echo $((0X0))' 126*640235e2SEnji Cooper # atf_expect_pass 127*640235e2SEnji Cooper 128*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 129*640235e2SEnji Cooper 'echo $((000))' 130*640235e2SEnji Cooper 131*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty \ 132*640235e2SEnji Cooper ${TEST_SH} -c 'echo $(( 000000001 ))' 133*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty \ 134*640235e2SEnji Cooper ${TEST_SH} -c 'echo $(( 0x000000 ))' 135*640235e2SEnji Cooper 136*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'99999\n' -e empty \ 137*640235e2SEnji Cooper ${TEST_SH} -c 'echo $((99999))' 138*640235e2SEnji Cooper 139*640235e2SEnji Cooper [ ${ARITH_BITS} -gt 44 ] && 140*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'9191919191919\n' -e empty \ 141*640235e2SEnji Cooper ${TEST_SH} -c 'echo $((9191919191919))' 142*640235e2SEnji Cooper 143*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'13\n' -e empty ${TEST_SH} -c \ 144*640235e2SEnji Cooper 'echo $(( 0xD ))' 145*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'11\n' -e empty ${TEST_SH} -c \ 146*640235e2SEnji Cooper 'echo $(( 013 ))' 147*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'7\n' -e empty ${TEST_SH} -c \ 148*640235e2SEnji Cooper 'x=7;echo $(($x))' 149*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'9\n' -e empty ${TEST_SH} -c \ 150*640235e2SEnji Cooper 'x=9;echo $((x))' 151*640235e2SEnji Cooper 152*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'11\n' -e empty \ 153*640235e2SEnji Cooper ${TEST_SH} -c 'x=0xB; echo $(( $x ))' 154*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'27\n' -e empty \ 155*640235e2SEnji Cooper ${TEST_SH} -c 'x=0X1B; echo $(( x ))' 156*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'27\n' -e empty \ 157*640235e2SEnji Cooper ${TEST_SH} -c 'X=033; echo $(( $X ))' 158*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'219\n' -e empty \ 159*640235e2SEnji Cooper ${TEST_SH} -c 'X=0333; echo $(( X ))' 160*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty \ 161*640235e2SEnji Cooper ${TEST_SH} -c 'NULL=; echo $(( NULL ))' 162*640235e2SEnji Cooper 163*640235e2SEnji Cooper # Not clear if this is 0, nothing, or an error, so omit for now 164*640235e2SEnji Cooper # atf_check -s exit:0 -o inline:'0\n' -e empty \ 165*640235e2SEnji Cooper # ${TEST_SH} -c 'echo $(( ))' 166*640235e2SEnji Cooper 167*640235e2SEnji Cooper # not clear whether this should return 0 or an error, so omit for now 168*640235e2SEnji Cooper # atf_check -s exit:0 -o inline:'0\n' -e empty \ 169*640235e2SEnji Cooper # ${TEST_SH} -c 'echo $(( UNDEFINED_VAR ))' 170*640235e2SEnji Cooper} 171*640235e2SEnji Cooper 172*640235e2SEnji Cooper 173*640235e2SEnji Cooperatf_test_case do_unary_plus 174*640235e2SEnji Cooperdo_unary_plus_head() 175*640235e2SEnji Cooper{ 176*640235e2SEnji Cooper atf_set "descr" "Tests that unary plus works as expected" 177*640235e2SEnji Cooper} 178*640235e2SEnji Cooperdo_unary_plus_body() 179*640235e2SEnji Cooper{ 180*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 181*640235e2SEnji Cooper 'echo $(( +0 ))' 182*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 183*640235e2SEnji Cooper 'echo $(( +1 ))' 184*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \ 185*640235e2SEnji Cooper 'echo $(( + 6 ))' 186*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'4321\n' -e empty ${TEST_SH} -c \ 187*640235e2SEnji Cooper 'echo $(( + 4321 ))' 188*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'17185\n' -e empty ${TEST_SH} -c \ 189*640235e2SEnji Cooper 'echo $(( + 0x4321 ))' 190*640235e2SEnji Cooper} 191*640235e2SEnji Cooper 192*640235e2SEnji Cooperatf_test_case do_unary_minus 193*640235e2SEnji Cooperdo_unary_minus_head() 194*640235e2SEnji Cooper{ 195*640235e2SEnji Cooper atf_set "descr" "Tests that unary minus works as expected" 196*640235e2SEnji Cooper} 197*640235e2SEnji Cooperdo_unary_minus_body() 198*640235e2SEnji Cooper{ 199*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \ 200*640235e2SEnji Cooper 'echo $(( -1 ))' 201*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 202*640235e2SEnji Cooper 'echo $(( - 0 ))' 203*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \ 204*640235e2SEnji Cooper 'echo $(( - 1 ))' 205*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-6\n' -e empty ${TEST_SH} -c \ 206*640235e2SEnji Cooper 'echo $(( - 6 ))' 207*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-4321\n' -e empty ${TEST_SH} -c \ 208*640235e2SEnji Cooper 'echo $(( - 4321 ))' 209*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-2257\n' -e empty ${TEST_SH} -c \ 210*640235e2SEnji Cooper 'echo $(( - 04321 ))' 211*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-7\n' -e empty ${TEST_SH} -c \ 212*640235e2SEnji Cooper 'echo $((-7))' 213*640235e2SEnji Cooper} 214*640235e2SEnji Cooper 215*640235e2SEnji Cooperatf_test_case do_unary_not 216*640235e2SEnji Cooperdo_unary_not_head() 217*640235e2SEnji Cooper{ 218*640235e2SEnji Cooper atf_set "descr" "Tests that unary not (boolean) works as expected" 219*640235e2SEnji Cooper} 220*640235e2SEnji Cooperdo_unary_not_body() 221*640235e2SEnji Cooper{ 222*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 223*640235e2SEnji Cooper 'echo $(( ! 1 ))' 224*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 225*640235e2SEnji Cooper 'echo $(( ! 0 ))' 226*640235e2SEnji Cooper 227*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 228*640235e2SEnji Cooper 'echo $(( !1234 ))' 229*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 230*640235e2SEnji Cooper 'echo $(( !0xFFFF ))' 231*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 232*640235e2SEnji Cooper 'echo $(( ! 000000 ))' 233*640235e2SEnji Cooper} 234*640235e2SEnji Cooper 235*640235e2SEnji Cooperatf_test_case do_unary_tilde 236*640235e2SEnji Cooperdo_unary_tilde_head() 237*640235e2SEnji Cooper{ 238*640235e2SEnji Cooper atf_set "descr" "Tests that unary not (bitwise) works as expected" 239*640235e2SEnji Cooper} 240*640235e2SEnji Cooperdo_unary_tilde_body() 241*640235e2SEnji Cooper{ 242*640235e2SEnji Cooper # definitely 2's complement arithmetic here... 243*640235e2SEnji Cooper 244*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \ 245*640235e2SEnji Cooper 'echo $(( ~ 0 ))' 246*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-2\n' -e empty ${TEST_SH} -c \ 247*640235e2SEnji Cooper 'echo $(( ~ 1 ))' 248*640235e2SEnji Cooper 249*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-1235\n' -e empty ${TEST_SH} -c \ 250*640235e2SEnji Cooper 'echo $(( ~1234 ))' 251*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-256\n' -e empty ${TEST_SH} -c \ 252*640235e2SEnji Cooper 'echo $(( ~0xFF ))' 253*640235e2SEnji Cooper} 254*640235e2SEnji Cooper 255*640235e2SEnji Cooperatf_test_case elementary_add 256*640235e2SEnji Cooperelementary_add_head() 257*640235e2SEnji Cooper{ 258*640235e2SEnji Cooper atf_set "descr" "Tests that simple addition works as expected" 259*640235e2SEnji Cooper} 260*640235e2SEnji Cooperelementary_add_body() 261*640235e2SEnji Cooper{ 262*640235e2SEnji Cooper # some of these tests actually test unary ops & op precedence... 263*640235e2SEnji Cooper 264*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 265*640235e2SEnji Cooper 'echo $(( 0 + 0 ))' 266*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 267*640235e2SEnji Cooper 'echo $(( 1 + 0 ))' 268*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 269*640235e2SEnji Cooper 'echo $(( 0 + 1 ))' 270*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 271*640235e2SEnji Cooper 'echo $(( 1 + 1 ))' 272*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'10\n' -e empty ${TEST_SH} -c \ 273*640235e2SEnji Cooper 'echo $(( 4 + 6 ))' 274*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'10\n' -e empty ${TEST_SH} -c \ 275*640235e2SEnji Cooper 'echo $(( 6 + 4 ))' 276*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'5555\n' -e empty ${TEST_SH} -c \ 277*640235e2SEnji Cooper 'echo $(( 1234 + 4321 ))' 278*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'3333\n' -e empty ${TEST_SH} -c \ 279*640235e2SEnji Cooper 'echo $((1111+2222))' 280*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'5555\n' -e empty ${TEST_SH} -c \ 281*640235e2SEnji Cooper 'echo $((+3333+2222))' 282*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'7777\n' -e empty ${TEST_SH} -c \ 283*640235e2SEnji Cooper 'echo $((+3333 + +4444))' 284*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-7777\n' -e empty ${TEST_SH} -c \ 285*640235e2SEnji Cooper 'echo -$((+4125+ +3652))' 286*640235e2SEnji Cooper} 287*640235e2SEnji Cooper 288*640235e2SEnji Cooperatf_test_case elementary_sub 289*640235e2SEnji Cooperelementary_sub_head() 290*640235e2SEnji Cooper{ 291*640235e2SEnji Cooper atf_set "descr" "Tests that simple subtraction works as expected" 292*640235e2SEnji Cooper} 293*640235e2SEnji Cooperelementary_sub_body() 294*640235e2SEnji Cooper{ 295*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 296*640235e2SEnji Cooper 'echo $(( 0 - 0 ))' 297*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 298*640235e2SEnji Cooper 'echo $(( 1 - 0 ))' 299*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 300*640235e2SEnji Cooper 'echo $(( 1 - 1 ))' 301*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \ 302*640235e2SEnji Cooper 'echo $(( 0 - 1 ))' 303*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'488\n' -e empty ${TEST_SH} -c \ 304*640235e2SEnji Cooper 'echo $(( 1066 - 578 ))' 305*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-3662\n' -e empty ${TEST_SH} -c \ 306*640235e2SEnji Cooper 'echo $(( 2016-5678 ))' 307*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-3662\n' -e empty ${TEST_SH} -c \ 308*640235e2SEnji Cooper 'echo $(( 2016+-5678 ))' 309*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-3662\n' -e empty ${TEST_SH} -c \ 310*640235e2SEnji Cooper 'echo $(( 2016-+5678 ))' 311*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-7694\n' -e empty ${TEST_SH} -c \ 312*640235e2SEnji Cooper 'echo $(( -2016-5678 ))' 313*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'--1\n' -e empty ${TEST_SH} -c \ 314*640235e2SEnji Cooper 'echo -$(( -1018 - -1017 ))' 315*640235e2SEnji Cooper} 316*640235e2SEnji Cooper 317*640235e2SEnji Cooperatf_test_case elementary_mul 318*640235e2SEnji Cooperelementary_mul_head() 319*640235e2SEnji Cooper{ 320*640235e2SEnji Cooper atf_set "descr" "Tests that simple multiplication works as expected" 321*640235e2SEnji Cooper} 322*640235e2SEnji Cooperelementary_mul_body() 323*640235e2SEnji Cooper{ 324*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 325*640235e2SEnji Cooper 'echo $(( 0 * 0 ))' 326*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 327*640235e2SEnji Cooper 'echo $(( 1 * 0 ))' 328*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 329*640235e2SEnji Cooper 'echo $(( 0 * 1 ))' 330*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 331*640235e2SEnji Cooper 'echo $(( 1 * 1 ))' 332*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \ 333*640235e2SEnji Cooper 'echo $(( -1 * 1 ))' 334*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \ 335*640235e2SEnji Cooper 'echo $(( 1 * -1 ))' 336*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 337*640235e2SEnji Cooper 'echo $(( -1 * -1 ))' 338*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'391\n' -e empty ${TEST_SH} -c \ 339*640235e2SEnji Cooper 'echo $(( 17 * 23 ))' 340*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'169\n' -e empty ${TEST_SH} -c \ 341*640235e2SEnji Cooper 'echo $(( 13*13 ))' 342*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-11264\n' -e empty ${TEST_SH} -c \ 343*640235e2SEnji Cooper 'echo $(( -11 *1024 ))' 344*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-16983\n' -e empty ${TEST_SH} -c \ 345*640235e2SEnji Cooper 'echo $(( 17* -999 ))' 346*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'9309\n' -e empty ${TEST_SH} -c \ 347*640235e2SEnji Cooper 'echo $(( -29*-321 ))' 348*640235e2SEnji Cooper} 349*640235e2SEnji Cooper 350*640235e2SEnji Cooperatf_test_case elementary_div 351*640235e2SEnji Cooperelementary_div_head() 352*640235e2SEnji Cooper{ 353*640235e2SEnji Cooper atf_set "descr" "Tests that simple division works as expected" 354*640235e2SEnji Cooper} 355*640235e2SEnji Cooperelementary_div_body() 356*640235e2SEnji Cooper{ 357*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 358*640235e2SEnji Cooper 'echo $(( 0 / 1 ))' 359*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 360*640235e2SEnji Cooper 'echo $(( 1 / 1 ))' 361*640235e2SEnji Cooper test ${ARITH_BITS} -ge 38 && 362*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'99999999999\n' -e empty \ 363*640235e2SEnji Cooper ${TEST_SH} -c 'echo $(( 99999999999 / 1 ))' 364*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 365*640235e2SEnji Cooper 'echo $(( 2 / 1 ))' 366*640235e2SEnji Cooper 367*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \ 368*640235e2SEnji Cooper 'echo $(( 3 / 1 ))' 369*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 370*640235e2SEnji Cooper 'echo $(( 3 / 2 ))' 371*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 372*640235e2SEnji Cooper 'echo $(( 3 / 3 ))' 373*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 374*640235e2SEnji Cooper 'echo $(( 3 / 4 ))' 375*640235e2SEnji Cooper 376*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'173\n' -e empty ${TEST_SH} -c \ 377*640235e2SEnji Cooper 'echo $(( 123456 / 713 ))' 378*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'13\n' -e empty ${TEST_SH} -c \ 379*640235e2SEnji Cooper 'echo $(( 169 / 13 ))' 380*640235e2SEnji Cooper} 381*640235e2SEnji Cooper 382*640235e2SEnji Cooperatf_test_case elementary_rem 383*640235e2SEnji Cooperelementary_rem_head() 384*640235e2SEnji Cooper{ 385*640235e2SEnji Cooper atf_set "descr" "Tests that simple modulus works as expected" 386*640235e2SEnji Cooper} 387*640235e2SEnji Cooperelementary_rem_body() 388*640235e2SEnji Cooper{ 389*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 390*640235e2SEnji Cooper 'echo $(( 0 % 1 ))' 391*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 392*640235e2SEnji Cooper 'echo $(( 1 % 1 ))' 393*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 394*640235e2SEnji Cooper 'echo $(( 2 % 1 ))' 395*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 396*640235e2SEnji Cooper 'echo $(( 9999 % 1 ))' 397*640235e2SEnji Cooper 398*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 399*640235e2SEnji Cooper 'echo $(( 0 % 2 ))' 400*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 401*640235e2SEnji Cooper 'echo $(( 1 % 2 ))' 402*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 403*640235e2SEnji Cooper 'echo $(( 2 % 2 ))' 404*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 405*640235e2SEnji Cooper 'echo $(( 0xFFFF % 2 ))' 406*640235e2SEnji Cooper 407*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 408*640235e2SEnji Cooper 'echo $(( 0 % 3 ))' 409*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 410*640235e2SEnji Cooper 'echo $(( 1 % 3 ))' 411*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 412*640235e2SEnji Cooper 'echo $(( 2 % 3 ))' 413*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 414*640235e2SEnji Cooper 'echo $(( 3 % 3 ))' 415*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 416*640235e2SEnji Cooper 'echo $(( 3123 % 3 ))' 417*640235e2SEnji Cooper 418*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 419*640235e2SEnji Cooper 'echo $(( 9999 % 2 ))' 420*640235e2SEnji Cooper 421*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'107\n' -e empty ${TEST_SH} -c \ 422*640235e2SEnji Cooper 'echo $(( 123456%173 ))' 423*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 424*640235e2SEnji Cooper 'echo $((169%13))' 425*640235e2SEnji Cooper} 426*640235e2SEnji Cooper 427*640235e2SEnji Cooperatf_test_case elementary_shl 428*640235e2SEnji Cooperelementary_shl_head() 429*640235e2SEnji Cooper{ 430*640235e2SEnji Cooper atf_set "descr" "Tests that simple shift left works as expected" 431*640235e2SEnji Cooper} 432*640235e2SEnji Cooperelementary_shl_body() 433*640235e2SEnji Cooper{ 434*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 435*640235e2SEnji Cooper 'echo $(( 0 << 0 ))' 436*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 437*640235e2SEnji Cooper 'echo $(( 0 << 1 ))' 438*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 439*640235e2SEnji Cooper 'echo $(( 0 << 17 ))' 440*640235e2SEnji Cooper 441*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 442*640235e2SEnji Cooper 'echo $(( 1 << 0 ))' 443*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 444*640235e2SEnji Cooper 'echo $(( 1 << 1 ))' 445*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'131072\n' -e empty ${TEST_SH} -c \ 446*640235e2SEnji Cooper 'echo $(( 1 << 17 ))' 447*640235e2SEnji Cooper 448*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2021161080\n' -e empty ${TEST_SH} -c \ 449*640235e2SEnji Cooper 'echo $(( 0x3C3C3C3C << 1 ))' 450*640235e2SEnji Cooper 451*640235e2SEnji Cooper test "${ARITH_BITS}" -ge 40 && 452*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'129354309120\n' -e empty \ 453*640235e2SEnji Cooper ${TEST_SH} -c 'echo $(( 0x3C3C3C3C << 7 ))' 454*640235e2SEnji Cooper test "${ARITH_BITS}" -ge 72 && 455*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1111145054534149079040\n' \ 456*640235e2SEnji Cooper -e empty ${TEST_SH} -c 'echo $(( 0x3C3C3C3C << 40 ))' 457*640235e2SEnji Cooper 458*640235e2SEnji Cooper return 0 459*640235e2SEnji Cooper} 460*640235e2SEnji Cooper 461*640235e2SEnji Cooperatf_test_case elementary_shr 462*640235e2SEnji Cooperelementary_shr_head() 463*640235e2SEnji Cooper{ 464*640235e2SEnji Cooper atf_set "descr" "Tests that simple shift right works as expected" 465*640235e2SEnji Cooper} 466*640235e2SEnji Cooperelementary_shr_body() 467*640235e2SEnji Cooper{ 468*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 469*640235e2SEnji Cooper 'echo $(( 0 >> 0 ))' 470*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 471*640235e2SEnji Cooper 'echo $(( 0 >> 1 ))' 472*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 473*640235e2SEnji Cooper 'echo $(( 0 >> 17 ))' 474*640235e2SEnji Cooper 475*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 476*640235e2SEnji Cooper 'echo $(( 1 >> 0 ))' 477*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 478*640235e2SEnji Cooper 'echo $(( 1 >> 1 ))' 479*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 480*640235e2SEnji Cooper 'echo $(( 2 >> 1 ))' 481*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 482*640235e2SEnji Cooper 'echo $(( 3 >> 1 ))' 483*640235e2SEnji Cooper 484*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \ 485*640235e2SEnji Cooper 'echo $(( 0x10 >> 2 ))' 486*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \ 487*640235e2SEnji Cooper 'echo $(( 022 >> 2 ))' 488*640235e2SEnji Cooper 489*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 490*640235e2SEnji Cooper 'echo $(( 131072 >> 17 ))' 491*640235e2SEnji Cooper 492*640235e2SEnji Cooper test ${ARITH_BITS} -ge 40 && 493*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'8\n' -e empty ${TEST_SH} -c \ 494*640235e2SEnji Cooper 'echo $(( 0x4000000000 >> 35 ))' 495*640235e2SEnji Cooper test ${ARITH_BITS} -ge 80 && 496*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'4464\n' -e empty ${TEST_SH} -c \ 497*640235e2SEnji Cooper 'echo $(( 0x93400FACE005C871000 >> 64 ))' 498*640235e2SEnji Cooper 499*640235e2SEnji Cooper return 0 500*640235e2SEnji Cooper} 501*640235e2SEnji Cooper 502*640235e2SEnji Cooperatf_test_case elementary_eq 503*640235e2SEnji Cooperelementary_eq_head() 504*640235e2SEnji Cooper{ 505*640235e2SEnji Cooper atf_set "descr" "Tests that simple equality test works as expected" 506*640235e2SEnji Cooper} 507*640235e2SEnji Cooperelementary_eq_body() 508*640235e2SEnji Cooper{ 509*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 510*640235e2SEnji Cooper 'echo $(( 0 == 0 ))' 511*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 512*640235e2SEnji Cooper 'echo $(( 0 == 0000 ))' 513*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 514*640235e2SEnji Cooper 'echo $(( 0 == 0x00 ))' 515*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 516*640235e2SEnji Cooper 'echo $(( 1 == 1 ))' 517*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 518*640235e2SEnji Cooper 'X=30; Y=0x1E; echo $(( X == Y ))' 519*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 520*640235e2SEnji Cooper 'echo $(( 0x1234 == 4660 ))' 521*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 522*640235e2SEnji Cooper 'echo $(( 0x1234 == 011064 ))' 523*640235e2SEnji Cooper 524*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 525*640235e2SEnji Cooper 'echo $(( 0 == 1 ))' 526*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 527*640235e2SEnji Cooper 'echo $(( 0 == 0000000000000001 ))' 528*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 529*640235e2SEnji Cooper 'echo $(( 0 == 0x10000000000000 ))' 530*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 531*640235e2SEnji Cooper 'echo $(( 1 == 2 ))' 532*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 533*640235e2SEnji Cooper 'X=3; Y=7; echo $(( X == Y ))' 534*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 535*640235e2SEnji Cooper 'echo $(( 1234 == 0x4660 ))' 536*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 537*640235e2SEnji Cooper 'echo $(( 01234 == 0x11064 ))' 538*640235e2SEnji Cooper} 539*640235e2SEnji Cooperatf_test_case elementary_ne 540*640235e2SEnji Cooperelementary_ne_head() 541*640235e2SEnji Cooper{ 542*640235e2SEnji Cooper atf_set "descr" "Tests that simple inequality test works as expected" 543*640235e2SEnji Cooper} 544*640235e2SEnji Cooperelementary_ne_body() 545*640235e2SEnji Cooper{ 546*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 547*640235e2SEnji Cooper 'echo $(( 1 != 0 ))' 548*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 549*640235e2SEnji Cooper 'echo $(( 0x71 != 17 ))' 550*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 551*640235e2SEnji Cooper 'echo $(( 1234 != 01234 ))' 552*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 553*640235e2SEnji Cooper 'echo $(( 0x1234 != 01234 ))' 554*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 555*640235e2SEnji Cooper 'X=3; echo $(( X != 0 ))' 556*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 557*640235e2SEnji Cooper 'X=3; Y=0x11; echo $(( X != Y ))' 558*640235e2SEnji Cooper 559*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 560*640235e2SEnji Cooper 'echo $(( 3 != 3 ))' 561*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 562*640235e2SEnji Cooper 'echo $(( 0 != 0x0 ))' 563*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 564*640235e2SEnji Cooper 'echo $(( 0xA != 012 ))' 565*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 566*640235e2SEnji Cooper 'X=1; echo $(( X != 1 ))' 567*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 568*640235e2SEnji Cooper 'X=0xC; Y=014; echo $(( X != Y ))' 569*640235e2SEnji Cooper} 570*640235e2SEnji Cooperatf_test_case elementary_lt 571*640235e2SEnji Cooperelementary_lt_head() 572*640235e2SEnji Cooper{ 573*640235e2SEnji Cooper atf_set "descr" "Tests that simple less than test works as expected" 574*640235e2SEnji Cooper} 575*640235e2SEnji Cooperelementary_lt_body() 576*640235e2SEnji Cooper{ 577*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 578*640235e2SEnji Cooper 'echo $(( 0 < 1 ))' 579*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 580*640235e2SEnji Cooper 'echo $(( -1 < 0 ))' 581*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 582*640235e2SEnji Cooper 'echo $(( 0 < 10 ))' 583*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 584*640235e2SEnji Cooper 'echo $(( 100 < 101 ))' 585*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 586*640235e2SEnji Cooper 'echo $(( 0xA1 < 200 ))' 587*640235e2SEnji Cooper 588*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 589*640235e2SEnji Cooper 'echo $(( 0 < 0 ))' 590*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 591*640235e2SEnji Cooper 'echo $(( 1 < 0 ))' 592*640235e2SEnji Cooper 593*640235e2SEnji Cooper test ${ARITH_BITS} -ge 40 && 594*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 595*640235e2SEnji Cooper 'echo $(( 0x1BEEFF00D < 0x1FACECAFE ))' 596*640235e2SEnji Cooper 597*640235e2SEnji Cooper return 0 598*640235e2SEnji Cooper} 599*640235e2SEnji Cooperatf_test_case elementary_le 600*640235e2SEnji Cooperelementary_le_head() 601*640235e2SEnji Cooper{ 602*640235e2SEnji Cooper atf_set "descr" "Tests that simple less or equal test works as expected" 603*640235e2SEnji Cooper} 604*640235e2SEnji Cooperelementary_le_body() 605*640235e2SEnji Cooper{ 606*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 607*640235e2SEnji Cooper 'echo $(( 0 <= 1 ))' 608*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 609*640235e2SEnji Cooper 'echo $(( -1 <= 0 ))' 610*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 611*640235e2SEnji Cooper 'echo $(( 0 <= 0 ))' 612*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 613*640235e2SEnji Cooper 'echo $(( 0 <= 10 ))' 614*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 615*640235e2SEnji Cooper 'echo $(( 100 <= 101 ))' 616*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 617*640235e2SEnji Cooper 'echo $(( 0xA1 <= 161 ))' 618*640235e2SEnji Cooper 619*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 620*640235e2SEnji Cooper 'echo $(( 1 <= 0 ))' 621*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 622*640235e2SEnji Cooper 'echo $(( -100 <= -200 ))' 623*640235e2SEnji Cooper 624*640235e2SEnji Cooper test ${ARITH_BITS} -ge 40 && 625*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 626*640235e2SEnji Cooper 'cost=; AUD=; echo $(( $cost 0x2FEEDBABE <= $AUD 12866927294 ))' 627*640235e2SEnji Cooper 628*640235e2SEnji Cooper return 0 629*640235e2SEnji Cooper} 630*640235e2SEnji Cooperatf_test_case elementary_gt 631*640235e2SEnji Cooperelementary_gt_head() 632*640235e2SEnji Cooper{ 633*640235e2SEnji Cooper atf_set "descr" "Tests that simple greater than works as expected" 634*640235e2SEnji Cooper} 635*640235e2SEnji Cooperelementary_gt_body() 636*640235e2SEnji Cooper{ 637*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 638*640235e2SEnji Cooper 'echo $(( 1 > 0 ))' 639*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 640*640235e2SEnji Cooper 'echo $(( 1 > -1 ))' 641*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 642*640235e2SEnji Cooper 'echo $(( 11 > 012 ))' 643*640235e2SEnji Cooper 644*640235e2SEnji Cooper # atf_expect_fail "PR bin/50959" 645*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 646*640235e2SEnji Cooper 'echo $(( 2147483647 > 0X7FFFFF0 ))' 647*640235e2SEnji Cooper # atf_expect_pass 648*640235e2SEnji Cooper 649*640235e2SEnji Cooper test ${ARITH_BITS} -gt 32 && 650*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 651*640235e2SEnji Cooper 'echo $(( 0x80000000 > 0x7FFFFFFF ))' 652*640235e2SEnji Cooper 653*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 654*640235e2SEnji Cooper 'echo $(( 0 > 0 ))' 655*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 656*640235e2SEnji Cooper 'echo $(( 0 > 1 ))' 657*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 658*640235e2SEnji Cooper 'echo $(( -1 > 0 ))' 659*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 660*640235e2SEnji Cooper 'echo $(( 0 > 10 ))' 661*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 662*640235e2SEnji Cooper 'echo $(( 2015 > 2016 ))' 663*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 664*640235e2SEnji Cooper 'echo $(( 0xA1 > 200 ))' 665*640235e2SEnji Cooper 666*640235e2SEnji Cooper test ${ARITH_BITS} -ge 44 && 667*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 668*640235e2SEnji Cooper 'echo $(( 0x7F07F07F0 > 34099628014 ))' 669*640235e2SEnji Cooper 670*640235e2SEnji Cooper return 0 671*640235e2SEnji Cooper} 672*640235e2SEnji Cooperatf_test_case elementary_ge 673*640235e2SEnji Cooperelementary_ge_head() 674*640235e2SEnji Cooper{ 675*640235e2SEnji Cooper atf_set "descr" "Tests that simple greater or equal works as expected" 676*640235e2SEnji Cooper} 677*640235e2SEnji Cooperelementary_ge_body() 678*640235e2SEnji Cooper{ 679*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 680*640235e2SEnji Cooper 'echo $(( 0 >= 0 ))' 681*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 682*640235e2SEnji Cooper 'echo $(( 1 >= 0 ))' 683*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 684*640235e2SEnji Cooper 'echo $(( -100 >= -101 ))' 685*640235e2SEnji Cooper 686*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 687*640235e2SEnji Cooper 'echo $(( -1 >= 0 ))' 688*640235e2SEnji Cooper} 689*640235e2SEnji Cooper 690*640235e2SEnji Cooperatf_test_case fiddle_bits_and 691*640235e2SEnji Cooperfiddle_bits_and_head() 692*640235e2SEnji Cooper{ 693*640235e2SEnji Cooper atf_set "descr" "Test bitwise and operations in arithmetic expressions" 694*640235e2SEnji Cooper} 695*640235e2SEnji Cooperfiddle_bits_and_body() 696*640235e2SEnji Cooper{ 697*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 698*640235e2SEnji Cooper 'echo $(( 0 & 0 ))' 699*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 700*640235e2SEnji Cooper 'echo $(( 1 & 0 ))' 701*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 702*640235e2SEnji Cooper 'echo $(( 0 & 1 ))' 703*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 704*640235e2SEnji Cooper 'echo $(( 1 & 1 ))' 705*640235e2SEnji Cooper 706*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'255\n' -e empty ${TEST_SH} -c \ 707*640235e2SEnji Cooper 'echo $(( 0xFF & 0xFF ))' 708*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'255\n' -e empty ${TEST_SH} -c \ 709*640235e2SEnji Cooper 'echo $(( 0xFFFF & 0377 ))' 710*640235e2SEnji Cooper 711*640235e2SEnji Cooper test "${ARITH_BITS}" -ge 48 && 712*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'70377641607203\n' -e empty \ 713*640235e2SEnji Cooper ${TEST_SH} -c 'echo $(( 0x5432FEDC0123 & 0x42871357BAB3 ))' 714*640235e2SEnji Cooper 715*640235e2SEnji Cooper return 0 716*640235e2SEnji Cooper} 717*640235e2SEnji Cooperatf_test_case fiddle_bits_or 718*640235e2SEnji Cooperfiddle_bits_or_head() 719*640235e2SEnji Cooper{ 720*640235e2SEnji Cooper atf_set "descr" "Test bitwise or operations in arithmetic expressions" 721*640235e2SEnji Cooper} 722*640235e2SEnji Cooperfiddle_bits_or_body() 723*640235e2SEnji Cooper{ 724*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 725*640235e2SEnji Cooper 'echo $(( 0 | 0 ))' 726*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 727*640235e2SEnji Cooper 'echo $(( 1 | 0 ))' 728*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 729*640235e2SEnji Cooper 'echo $(( 0 | 1 ))' 730*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 731*640235e2SEnji Cooper 'echo $(( 1 | 1 ))' 732*640235e2SEnji Cooper 733*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'4369\n' -e empty ${TEST_SH} -c \ 734*640235e2SEnji Cooper 'echo $(( 0x1111 | 0x1111 ))' 735*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'255\n' -e empty ${TEST_SH} -c \ 736*640235e2SEnji Cooper 'echo $(( 0xAA | 0125 ))' 737*640235e2SEnji Cooper 738*640235e2SEnji Cooper test "${ARITH_BITS}" -ge 48 && 739*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'95348271856563\n' -e empty \ 740*640235e2SEnji Cooper ${TEST_SH} -c 'echo $(( 0x5432FEDC0123 | 0x42871357BAB3 ))' 741*640235e2SEnji Cooper 742*640235e2SEnji Cooper return 0 743*640235e2SEnji Cooper} 744*640235e2SEnji Cooperatf_test_case fiddle_bits_xor 745*640235e2SEnji Cooperfiddle_bits_xor_head() 746*640235e2SEnji Cooper{ 747*640235e2SEnji Cooper atf_set "descr" "Test bitwise xor operations in arithmetic expressions" 748*640235e2SEnji Cooper} 749*640235e2SEnji Cooperfiddle_bits_xor_body() 750*640235e2SEnji Cooper{ 751*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 752*640235e2SEnji Cooper 'echo $(( 0 ^ 0 ))' 753*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 754*640235e2SEnji Cooper 'echo $(( 1 ^ 0 ))' 755*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 756*640235e2SEnji Cooper 'echo $(( 0 ^ 1 ))' 757*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 758*640235e2SEnji Cooper 'echo $(( 1 ^ 1 ))' 759*640235e2SEnji Cooper 760*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'255\n' -e empty ${TEST_SH} -c \ 761*640235e2SEnji Cooper 'echo $(( 0xF0 ^ 0x0F ))' 762*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'15\n' -e empty ${TEST_SH} -c \ 763*640235e2SEnji Cooper 'echo $(( 0xF0 ^ 0xFF ))' 764*640235e2SEnji Cooper 765*640235e2SEnji Cooper test "${ARITH_BITS}" -ge 48 && 766*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'24970630249360\n' -e empty \ 767*640235e2SEnji Cooper ${TEST_SH} -c 'echo $(( 0x5432FEDC0123 ^ 0x42871357BAB3 ))' 768*640235e2SEnji Cooper 769*640235e2SEnji Cooper return 0 770*640235e2SEnji Cooper} 771*640235e2SEnji Cooper 772*640235e2SEnji Cooperatf_test_case logical_and 773*640235e2SEnji Cooperlogical_and_head() 774*640235e2SEnji Cooper{ 775*640235e2SEnji Cooper atf_set "descr" "Test logical and operations in arithmetic expressions" 776*640235e2SEnji Cooper} 777*640235e2SEnji Cooperlogical_and_body() 778*640235e2SEnji Cooper{ 779*640235e2SEnji Cooper # cannot test short-circuit eval until sh implements side effects... 780*640235e2SEnji Cooper 781*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 782*640235e2SEnji Cooper 'echo $(( 0 && 0 ))' 783*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 784*640235e2SEnji Cooper 'echo $(( 1 && 0 ))' 785*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 786*640235e2SEnji Cooper 'echo $(( 0 && 1 ))' 787*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 788*640235e2SEnji Cooper 'echo $(( 1 && 1 ))' 789*640235e2SEnji Cooper 790*640235e2SEnji Cooper # atf_expect_fail "PR bin/50960" 791*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 792*640235e2SEnji Cooper 'echo $(( 0x1111 && 01234 ))' 793*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 794*640235e2SEnji Cooper 'echo $(( 0xFFFF && 0xF0F0 ))' 795*640235e2SEnji Cooper} 796*640235e2SEnji Cooperatf_test_case logical_or 797*640235e2SEnji Cooperlogical_or_head() 798*640235e2SEnji Cooper{ 799*640235e2SEnji Cooper atf_set "descr" "Test logical or operations in arithmetic expressions" 800*640235e2SEnji Cooper} 801*640235e2SEnji Cooperlogical_or_body() 802*640235e2SEnji Cooper{ 803*640235e2SEnji Cooper # cannot test short-circuit eval until sh implements side effects... 804*640235e2SEnji Cooper 805*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 806*640235e2SEnji Cooper 'echo $(( 0 || 0 ))' 807*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 808*640235e2SEnji Cooper 'echo $(( 1 || 0 ))' 809*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 810*640235e2SEnji Cooper 'echo $(( 0 || 1 ))' 811*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 812*640235e2SEnji Cooper 'echo $(( 1 || 1 ))' 813*640235e2SEnji Cooper 814*640235e2SEnji Cooper # atf_expect_fail "PR bin/50960" 815*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 816*640235e2SEnji Cooper 'echo $(( 0x1111 || 01234 ))' 817*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 818*640235e2SEnji Cooper 'echo $(( 0x33 || 0xF0F0 ))' 819*640235e2SEnji Cooper} 820*640235e2SEnji Cooper 821*640235e2SEnji Cooperatf_test_case make_selection 822*640235e2SEnji Coopermake_selection_head() 823*640235e2SEnji Cooper{ 824*640235e2SEnji Cooper atf_set "descr" "Test ?: operator in arithmetic expressions" 825*640235e2SEnji Cooper} 826*640235e2SEnji Coopermake_selection_body() 827*640235e2SEnji Cooper{ 828*640235e2SEnji Cooper # atf_expect_fail "PR bin/50958" 829*640235e2SEnji Cooper 830*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \ 831*640235e2SEnji Cooper 'echo $(( 0 ? 2 : 3 ))' 832*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 833*640235e2SEnji Cooper 'echo $(( 1 ? 2 : 3 ))' 834*640235e2SEnji Cooper 835*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'111\n' -e empty ${TEST_SH} -c \ 836*640235e2SEnji Cooper 'echo $(( 0x1234 ? 111 : 222 ))' 837*640235e2SEnji Cooper 838*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \ 839*640235e2SEnji Cooper 'echo $(( 1 < 2 ? -1 : 1 > 2 ? 1 : 0 ))' 840*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 841*640235e2SEnji Cooper 'echo $(( 1 < 1 ? -1 : 1 > 1 ? 1 : 0 ))' 842*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 843*640235e2SEnji Cooper 'echo $(( 2 < 1 ? -1 : 2 > 1 ? 1 : 0 ))' 844*640235e2SEnji Cooper} 845*640235e2SEnji Cooper 846*640235e2SEnji Cooperatf_test_case operator_precedence 847*640235e2SEnji Cooperoperator_precedence_head() 848*640235e2SEnji Cooper{ 849*640235e2SEnji Cooper atf_set "descr" "Test operator precedence without parentheses" 850*640235e2SEnji Cooper} 851*640235e2SEnji Cooperoperator_precedence_body() 852*640235e2SEnji Cooper{ 853*640235e2SEnji Cooper # NB: apart from $(( )) ** NO ** parentheses in the expressions. 854*640235e2SEnji Cooper 855*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \ 856*640235e2SEnji Cooper 'echo $(( 1 + 2 + 3 ))' 857*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 858*640235e2SEnji Cooper 'echo $(( 1 - 2 + 3 ))' 859*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 860*640235e2SEnji Cooper 'echo $(( 3 - 2 - 1 ))' 861*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 862*640235e2SEnji Cooper 'echo $(( 3 - 2 + 1 ))' 863*640235e2SEnji Cooper 864*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \ 865*640235e2SEnji Cooper 'echo $(( - 2 + 1 ))' 866*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 867*640235e2SEnji Cooper 'echo $(( 2 + -1 ))' 868*640235e2SEnji Cooper 869*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 870*640235e2SEnji Cooper 'echo $(( ! 2 + 1 ))' 871*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 872*640235e2SEnji Cooper 'echo $(( 2 + !1 ))' 873*640235e2SEnji Cooper 874*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'8\n' -e empty ${TEST_SH} -c \ 875*640235e2SEnji Cooper 'echo $(( 3 * 2 + 2 ))' 876*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'7\n' -e empty ${TEST_SH} -c \ 877*640235e2SEnji Cooper 'echo $(( 3 + 2 * 2 ))' 878*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'12\n' -e empty ${TEST_SH} -c \ 879*640235e2SEnji Cooper 'echo $(( 3 * 2 * 2 ))' 880*640235e2SEnji Cooper 881*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'5\n' -e empty ${TEST_SH} -c \ 882*640235e2SEnji Cooper 'echo $(( 9 / 3 + 2 ))' 883*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'10\n' -e empty ${TEST_SH} -c \ 884*640235e2SEnji Cooper 'echo $(( 9 + 3 / 2 ))' 885*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 886*640235e2SEnji Cooper 'echo $(( 9 / 3 / 2 ))' 887*640235e2SEnji Cooper 888*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'72\n' -e empty ${TEST_SH} -c \ 889*640235e2SEnji Cooper 'echo $(( 9 << 1 + 2 ))' 890*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'48\n' -e empty ${TEST_SH} -c \ 891*640235e2SEnji Cooper 'echo $(( 9 + 3 << 2 ))' 892*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'288\n' -e empty ${TEST_SH} -c \ 893*640235e2SEnji Cooper 'echo $(( 9 << 3 << 2 ))' 894*640235e2SEnji Cooper 895*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 896*640235e2SEnji Cooper 'echo $(( 9 >> 1 + 2 ))' 897*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \ 898*640235e2SEnji Cooper 'echo $(( 9 + 3 >> 2 ))' 899*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 900*640235e2SEnji Cooper 'echo $(( 19 >> 3 >> 1 ))' 901*640235e2SEnji Cooper 902*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \ 903*640235e2SEnji Cooper 'echo $(( 19 >> 3 << 1 ))' 904*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'76\n' -e empty ${TEST_SH} -c \ 905*640235e2SEnji Cooper 'echo $(( 19 << 3 >> 1 ))' 906*640235e2SEnji Cooper 907*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 908*640235e2SEnji Cooper 'echo $(( 2 + 3 < 3 * 2 ))' 909*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 910*640235e2SEnji Cooper 'echo $(( 2 << 3 >= 3 << 2 ))' 911*640235e2SEnji Cooper 912*640235e2SEnji Cooper # sh inherits C's crazy operator precedence... 913*640235e2SEnji Cooper 914*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 915*640235e2SEnji Cooper 'echo $(( 0xfD & 0xF == 0xF ))' 916*640235e2SEnji Cooper} 917*640235e2SEnji Cooper 918*640235e2SEnji Cooperparentheses_head() 919*640235e2SEnji Cooper{ 920*640235e2SEnji Cooper atf_set "descr" "Test use of () to group sub-expressions" 921*640235e2SEnji Cooper} 922*640235e2SEnji Cooperparentheses_body() 923*640235e2SEnji Cooper{ 924*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \ 925*640235e2SEnji Cooper 'echo $(( (1 + 2) + 3 ))' 926*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-4\n' -e empty ${TEST_SH} -c \ 927*640235e2SEnji Cooper 'echo $(( 1 - (2 + 3) ))' 928*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 929*640235e2SEnji Cooper 'echo $(( 3 - (2 - 1) ))' 930*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 931*640235e2SEnji Cooper 'echo $(( 3 - ( 2 + 1 ) ))' 932*640235e2SEnji Cooper 933*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'-3\n' -e empty ${TEST_SH} -c \ 934*640235e2SEnji Cooper 'echo $(( - (2 + 1) ))' 935*640235e2SEnji Cooper 936*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 937*640235e2SEnji Cooper 'echo $(( ! (2 + 1) ))' 938*640235e2SEnji Cooper 939*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'12\n' -e empty ${TEST_SH} -c \ 940*640235e2SEnji Cooper 'echo $(( 3 * (2 + 2) ))' 941*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'10\n' -e empty ${TEST_SH} -c \ 942*640235e2SEnji Cooper 'echo $(( (3 + 2) * 2 ))' 943*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'12\n' -e empty ${TEST_SH} -c \ 944*640235e2SEnji Cooper 'echo $(( 3 * (2 * 2) ))' 945*640235e2SEnji Cooper 946*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \ 947*640235e2SEnji Cooper 'echo $(( 9 / (3 + 2) ))' 948*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \ 949*640235e2SEnji Cooper 'echo $(( ( 9 + 3 ) / 2 ))' 950*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'9\n' -e empty ${TEST_SH} -c \ 951*640235e2SEnji Cooper 'echo $(( 9 / ( 3 / 2 ) ))' 952*640235e2SEnji Cooper 953*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'20\n' -e empty ${TEST_SH} -c \ 954*640235e2SEnji Cooper 'echo $(( ( 9 << 1 ) + 2 ))' 955*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'21\n' -e empty ${TEST_SH} -c \ 956*640235e2SEnji Cooper 'echo $(( 9 + (3 << 2) ))' 957*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'36864\n' -e empty ${TEST_SH} -c \ 958*640235e2SEnji Cooper 'echo $(( 9 << (3 << 2) ))' 959*640235e2SEnji Cooper 960*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \ 961*640235e2SEnji Cooper 'echo $(( (9 >> 1) + 2 ))' 962*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'9\n' -e empty ${TEST_SH} -c \ 963*640235e2SEnji Cooper 'echo $(( 9 + (3 >> 2) ))' 964*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'9\n' -e empty ${TEST_SH} -c \ 965*640235e2SEnji Cooper 'echo $(( 19 >> (3 >> 1) ))' 966*640235e2SEnji Cooper 967*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 968*640235e2SEnji Cooper 'echo $(( 19 >> (3 << 1) ))' 969*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'38\n' -e empty ${TEST_SH} -c \ 970*640235e2SEnji Cooper 'echo $(( 19 << (3 >> 1) ))' 971*640235e2SEnji Cooper 972*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \ 973*640235e2SEnji Cooper 'echo $(( 2 + (3 < 3) * 2 ))' 974*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'32\n' -e empty ${TEST_SH} -c \ 975*640235e2SEnji Cooper 'echo $(( 2 << ((3 >= 3) << 2) ))' 976*640235e2SEnji Cooper 977*640235e2SEnji Cooper # sh inherits C's crazy operator precedence... 978*640235e2SEnji Cooper 979*640235e2SEnji Cooper atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \ 980*640235e2SEnji Cooper 'echo $(( (0xfD & 0xF) == 0xF ))' 981*640235e2SEnji Cooper} 982*640235e2SEnji Cooper 983*640235e2SEnji Cooperatf_test_case arithmetic_fails 984*640235e2SEnji Cooperarithmetic_fails_head() 985*640235e2SEnji Cooper{ 986*640235e2SEnji Cooper atf_set "descr" "Dummy test to force failure" 987*640235e2SEnji Cooper} 988*640235e2SEnji Cooperarithmetic_fails_body() 989*640235e2SEnji Cooper{ 990*640235e2SEnji Cooper atf_fail "Cannot estimate number of bits supported by $(( ))" 991*640235e2SEnji Cooper} 992*640235e2SEnji Cooper 993*640235e2SEnji Cooperatf_init_test_cases() { 994*640235e2SEnji Cooper 995*640235e2SEnji Cooper discover_range 996*640235e2SEnji Cooper 997*640235e2SEnji Cooper test "${ARITH_BITS}" = '?' && { 998*640235e2SEnji Cooper atf_add_test_case arithmetic_fails 999*640235e2SEnji Cooper return 0 1000*640235e2SEnji Cooper } 1001*640235e2SEnji Cooper 1002*640235e2SEnji Cooper # odd names are to get atf's sort order semi-rational 1003*640235e2SEnji Cooper 1004*640235e2SEnji Cooper atf_add_test_case constants 1005*640235e2SEnji Cooper atf_add_test_case do_unary_plus 1006*640235e2SEnji Cooper atf_add_test_case do_unary_minus 1007*640235e2SEnji Cooper atf_add_test_case do_unary_not 1008*640235e2SEnji Cooper atf_add_test_case do_unary_tilde 1009*640235e2SEnji Cooper atf_add_test_case elementary_add 1010*640235e2SEnji Cooper atf_add_test_case elementary_sub 1011*640235e2SEnji Cooper atf_add_test_case elementary_mul 1012*640235e2SEnji Cooper atf_add_test_case elementary_div 1013*640235e2SEnji Cooper atf_add_test_case elementary_rem 1014*640235e2SEnji Cooper atf_add_test_case elementary_shl 1015*640235e2SEnji Cooper atf_add_test_case elementary_shr 1016*640235e2SEnji Cooper atf_add_test_case elementary_eq 1017*640235e2SEnji Cooper atf_add_test_case elementary_ne 1018*640235e2SEnji Cooper atf_add_test_case elementary_lt 1019*640235e2SEnji Cooper atf_add_test_case elementary_le 1020*640235e2SEnji Cooper atf_add_test_case elementary_gt 1021*640235e2SEnji Cooper atf_add_test_case elementary_ge 1022*640235e2SEnji Cooper atf_add_test_case fiddle_bits_and 1023*640235e2SEnji Cooper atf_add_test_case fiddle_bits_or 1024*640235e2SEnji Cooper atf_add_test_case fiddle_bits_xor 1025*640235e2SEnji Cooper atf_add_test_case logical_and 1026*640235e2SEnji Cooper atf_add_test_case logical_or 1027*640235e2SEnji Cooper atf_add_test_case make_selection 1028*640235e2SEnji Cooper atf_add_test_case operator_precedence 1029*640235e2SEnji Cooper atf_add_test_case parentheses 1030*640235e2SEnji Cooper # atf_add_test_case progressive # build up big expr 1031*640235e2SEnji Cooper # atf_add_test_case test_errors # erroneous input 1032*640235e2SEnji Cooper # atf_add_test_case torture # hard stuff (if there is any) 1033*640235e2SEnji Cooper # atf_add_test_case var_assign # assignment ops 1034*640235e2SEnji Cooper # atf_add_test_case vulgarity # truly evil inputs (syntax in vars...) 1035*640235e2SEnji Cooper} 1036