Training courses

Kernel and Embedded Linux

Bootlin training courses

Embedded Linux, kernel,
Yocto Project, Buildroot, real-time,
graphics, boot time, debugging...

Bootlin logo

Elixir Cross Referencer

   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
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
# $NetBSD: t_arith.sh,v 1.8 2017/07/15 18:50:42 kre Exp $
#
# Copyright (c) 2016 The NetBSD Foundation, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
# 1. Redistributions of source code must retain the above copyright
#    notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
#    notice, this list of conditions and the following disclaimer in the
#    documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
# PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
# the implementation of "sh" to test
: ${TEST_SH:="/bin/sh"}

# Requirement is to support at least "signed long" whatever that means
# (number of bits in "long" is not specified - but should be at least 32).

# These tests use -o inline:"..." rather than -o match:'...' as we have
# only digits to examine, and it is good to be sure that 1 + 1 really gives 2
# and that 42 or 123 don't look like success because there is a 2 in them.

ARITH_BITS='?'
discover_range()
{
	# cannot use arithmetic "test" operators, range of test in
	# ATF_SHELL (or even TEST_SH) might not be as big as that
	# supported by $(( )) in TEST_SH

	if ! ${TEST_SH} -c ': $(( 0x10000 ))' 2>/dev/null
	then
		# 16 bits or less, or hex unsupported, just give up...
		return
	fi
	test $( ${TEST_SH} -c 'echo $(( 0x1FFFF ))' ) = 131071 || return

	# when attempting to exceed the number of available bits
	# the shell may react in any of 3 (rational) ways
	# 1. syntax error (maybe even core dump...) and fail
	# 2. represent a positive number input as negative value
	# 3. keep the number positive, but not the value expected
	#    (perhaps pegged at the max possible value)
	# any of those may be accompanied by a message to stderr

	# Must check all 3 possibilities for each plausible size
	# Tests do not use 0x8000... because that value can have weird
	# other side effects that are not relevant to discover here.
	# But we do want to try and force the sign bit set.

	if ! ${TEST_SH} -c ': $(( 0xC0000000 ))' 2>/dev/null
	then
		# proobably shell detected overflow and complained
		ARITH_BITS=32
		return
	fi
	if ${TEST_SH} 2>/dev/null \
	    -c 'case $(( 0xC0000000 )); in (-*) exit 0;; esac; exit 1'
	then
		ARITH_BITS=32
		return
	fi
	if ${TEST_SH} -c '[ $(( 0xC0000000 )) != 3221225472 ]' 2>/dev/null
	then
		ARITH_BITS=32
		return
	fi

	if ! ${TEST_SH} -c ': $(( 0xC000000000000000 ))' 2>/dev/null
	then
		ARITH_BITS=64
		return
	fi
	if ${TEST_SH} 2>/dev/null \
	    -c 'case $(( 0xC000000000000000 )); in (-*) exit 0;; esac; exit 1'
	then
		ARITH_BITS=64
		return
	fi
	if ${TEST_SH} 2>/dev/null \
	    -c '[ $((0xC000000000000000)) != 13835058055282163712 ]'
	then
		ARITH_BITS=64
		return
	fi

	if ${TEST_SH} 2>/dev/null -c \
	   '[ $((0x123456781234567812345678)) = 5634002657842756053938493048 ]'
	then
		# just assume... (for now anyway, revisit when it happens...)
		ARITH_BITS=96
		return
	fi
}

atf_test_case constants
constants_head()
{
        atf_set "descr" "Tests that arithmetic expansion can handle constants"
}
constants_body()
{
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $((0x0))'

	# atf_expect_fail "PR bin/50959"
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $((0X0))'
	# atf_expect_pass

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $((000))'

	atf_check -s exit:0 -o inline:'1\n' -e empty \
		${TEST_SH} -c 'echo $(( 000000001 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty \
		${TEST_SH} -c 'echo $(( 0x000000 ))'

	atf_check -s exit:0 -o inline:'99999\n' -e empty \
		${TEST_SH} -c 'echo $((99999))'

	[ ${ARITH_BITS} -gt 44 ] &&
		atf_check -s exit:0 -o inline:'9191919191919\n' -e empty \
			${TEST_SH} -c 'echo $((9191919191919))'

	atf_check -s exit:0 -o inline:'13\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xD ))'
	atf_check -s exit:0 -o inline:'11\n' -e empty ${TEST_SH} -c \
		'echo $(( 013 ))'
	atf_check -s exit:0 -o inline:'7\n' -e empty ${TEST_SH} -c \
		'x=7;echo $(($x))'
	atf_check -s exit:0 -o inline:'9\n' -e empty ${TEST_SH} -c \
		'x=9;echo $((x))'

	atf_check -s exit:0 -o inline:'11\n' -e empty \
		${TEST_SH} -c 'x=0xB; echo $(( $x ))'
	atf_check -s exit:0 -o inline:'27\n' -e empty \
		${TEST_SH} -c 'x=0X1B; echo $(( x ))'
	atf_check -s exit:0 -o inline:'27\n' -e empty \
		${TEST_SH} -c 'X=033; echo $(( $X ))'
	atf_check -s exit:0 -o inline:'219\n' -e empty \
		${TEST_SH} -c 'X=0333; echo $(( X ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty \
		${TEST_SH} -c 'NULL=; echo $(( NULL ))'

	# Not clear if this is 0, nothing, or an error, so omit for now
	# atf_check -s exit:0 -o inline:'0\n' -e empty \
	# 	${TEST_SH} -c 'echo $(( ))'

	# not clear whether this should return 0 or an error, so omit for now
	# atf_check -s exit:0 -o inline:'0\n' -e empty \
	# 	${TEST_SH} -c 'echo $(( UNDEFINED_VAR ))'
}


atf_test_case do_unary_plus
do_unary_plus_head()
{
        atf_set "descr" "Tests that unary plus works as expected"
}
do_unary_plus_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( +0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( +1 ))'
	atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \
		'echo $(( + 6 ))'
	atf_check -s exit:0 -o inline:'4321\n' -e empty ${TEST_SH} -c \
		'echo $(( + 4321 ))'
	atf_check -s exit:0 -o inline:'17185\n' -e empty ${TEST_SH} -c \
		'echo $(( + 0x4321 ))'
}

atf_test_case do_unary_minus
do_unary_minus_head()
{
        atf_set "descr" "Tests that unary minus works as expected"
}
do_unary_minus_body()
{
	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
		'echo $(( -1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( - 0 ))'
	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
		'echo $(( - 1 ))'
	atf_check -s exit:0 -o inline:'-6\n' -e empty ${TEST_SH} -c \
		'echo $(( - 6 ))'
	atf_check -s exit:0 -o inline:'-4321\n' -e empty ${TEST_SH} -c \
		'echo $(( - 4321 ))'
	atf_check -s exit:0 -o inline:'-2257\n' -e empty ${TEST_SH} -c \
		'echo $(( - 04321 ))'
	atf_check -s exit:0 -o inline:'-7\n' -e empty ${TEST_SH} -c \
		'echo $((-7))'
}

atf_test_case do_unary_not
do_unary_not_head()
{
        atf_set "descr" "Tests that unary not (boolean) works as expected"
}
do_unary_not_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( ! 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( ! 0 ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( !1234 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( !0xFFFF ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( ! 000000 ))'
}

atf_test_case do_unary_tilde
do_unary_tilde_head()
{
        atf_set "descr" "Tests that unary not (bitwise) works as expected"
}
do_unary_tilde_body()
{
	# definitely 2's complement arithmetic here...

	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
		'echo $(( ~ 0 ))'
	atf_check -s exit:0 -o inline:'-2\n' -e empty ${TEST_SH} -c \
		'echo $(( ~ 1 ))'

	atf_check -s exit:0 -o inline:'-1235\n' -e empty ${TEST_SH} -c \
		'echo $(( ~1234 ))'
	atf_check -s exit:0 -o inline:'-256\n' -e empty ${TEST_SH} -c \
		'echo $(( ~0xFF ))'
}

atf_test_case elementary_add
elementary_add_head()
{
        atf_set "descr" "Tests that simple addition works as expected"
}
elementary_add_body()
{
	# some of these tests actually test unary ops &  op precedence...

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 + 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 + 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 + 1 ))'
	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 + 1 ))'
	atf_check -s exit:0 -o inline:'10\n' -e empty ${TEST_SH} -c \
		'echo $(( 4 + 6 ))'
	atf_check -s exit:0 -o inline:'10\n' -e empty ${TEST_SH} -c \
		'echo $(( 6 + 4 ))'
	atf_check -s exit:0 -o inline:'5555\n' -e empty ${TEST_SH} -c \
		'echo $(( 1234 + 4321 ))'
	atf_check -s exit:0 -o inline:'3333\n' -e empty ${TEST_SH} -c \
		'echo $((1111+2222))'
	atf_check -s exit:0 -o inline:'5555\n' -e empty ${TEST_SH} -c \
		'echo $((+3333+2222))'
	atf_check -s exit:0 -o inline:'7777\n' -e empty ${TEST_SH} -c \
		'echo $((+3333 + +4444))'
	atf_check -s exit:0 -o inline:'-7777\n' -e empty ${TEST_SH} -c \
		'echo -$((+4125+ +3652))'
}

atf_test_case elementary_sub
elementary_sub_head()
{
        atf_set "descr" "Tests that simple subtraction works as expected"
}
elementary_sub_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 - 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 - 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 - 1 ))'
	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 - 1 ))'
	atf_check -s exit:0 -o inline:'488\n' -e empty ${TEST_SH} -c \
		'echo $(( 1066 - 578 ))'
	atf_check -s exit:0 -o inline:'-3662\n' -e empty ${TEST_SH} -c \
		'echo $(( 2016-5678 ))'
	atf_check -s exit:0 -o inline:'-3662\n' -e empty ${TEST_SH} -c \
		'echo $(( 2016+-5678 ))'
	atf_check -s exit:0 -o inline:'-3662\n' -e empty ${TEST_SH} -c \
		'echo $(( 2016-+5678 ))'
	atf_check -s exit:0 -o inline:'-7694\n' -e empty ${TEST_SH} -c \
		'echo $(( -2016-5678 ))'
	atf_check -s exit:0 -o inline:'--1\n' -e empty ${TEST_SH} -c \
		'echo -$(( -1018 - -1017 ))'
}

atf_test_case elementary_mul
elementary_mul_head()
{
        atf_set "descr" "Tests that simple multiplication works as expected"
}
elementary_mul_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 * 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 * 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 * 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 * 1 ))'
	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
		'echo $(( -1 * 1 ))'
	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 * -1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( -1 * -1 ))'
	atf_check -s exit:0 -o inline:'391\n' -e empty ${TEST_SH} -c \
		'echo $(( 17 * 23 ))'
	atf_check -s exit:0 -o inline:'169\n' -e empty ${TEST_SH} -c \
		'echo $(( 13*13 ))'
	atf_check -s exit:0 -o inline:'-11264\n' -e empty ${TEST_SH} -c \
		'echo $(( -11 *1024 ))'
	atf_check -s exit:0 -o inline:'-16983\n' -e empty ${TEST_SH} -c \
		'echo $(( 17* -999 ))'
	atf_check -s exit:0 -o inline:'9309\n' -e empty ${TEST_SH} -c \
		'echo $(( -29*-321 ))'
}

atf_test_case elementary_div
elementary_div_head()
{
        atf_set "descr" "Tests that simple division works as expected"
}
elementary_div_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 / 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 / 1 ))'
	test ${ARITH_BITS} -ge 38 &&
	    atf_check -s exit:0 -o inline:'99999999999\n' -e empty \
		${TEST_SH} -c 'echo $(( 99999999999 / 1 ))'
	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 / 1 ))'

	atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 / 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 / 2 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 / 3 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 / 4 ))'

	atf_check -s exit:0 -o inline:'173\n' -e empty ${TEST_SH} -c \
		'echo $(( 123456 / 713 ))'
	atf_check -s exit:0 -o inline:'13\n' -e empty ${TEST_SH} -c \
		'echo $(( 169 / 13 ))'
}

atf_test_case elementary_rem
elementary_rem_head()
{
        atf_set "descr" "Tests that simple modulus works as expected"
}
elementary_rem_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 % 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 % 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 % 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 9999 % 1 ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 % 2 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 % 2 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 % 2 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xFFFF % 2 ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 % 3 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 % 3 ))'
	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 % 3 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 % 3 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 3123 % 3 ))'

	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 9999 % 2 ))'

	atf_check -s exit:0 -o inline:'107\n' -e empty ${TEST_SH} -c \
		'echo $(( 123456%173 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $((169%13))'
}

atf_test_case elementary_shl
elementary_shl_head()
{
        atf_set "descr" "Tests that simple shift left works as expected"
}
elementary_shl_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 << 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 << 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 << 17 ))'

	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 << 0 ))'
	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 << 1 ))'
	atf_check -s exit:0 -o inline:'131072\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 << 17 ))'

	atf_check -s exit:0 -o inline:'2021161080\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x3C3C3C3C << 1 ))'

	test "${ARITH_BITS}" -ge 40 &&
	    atf_check -s exit:0 -o inline:'129354309120\n' -e empty \
		${TEST_SH} -c 'echo $(( 0x3C3C3C3C << 7 ))'
	test "${ARITH_BITS}" -ge 72 &&
	    atf_check -s exit:0 -o inline:'1111145054534149079040\n' \
		-e empty ${TEST_SH} -c 'echo $(( 0x3C3C3C3C << 40 ))'

	return 0
}

atf_test_case elementary_shr
elementary_shr_head()
{
        atf_set "descr" "Tests that simple shift right works as expected"
}
elementary_shr_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 >> 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 >> 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 >> 17 ))'

	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 >> 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 >> 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 >> 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 >> 1 ))'

	atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x10 >> 2 ))'
	atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \
		'echo $(( 022 >> 2 ))'

	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 131072 >> 17 ))'

	test ${ARITH_BITS} -ge 40 &&
		atf_check -s exit:0 -o inline:'8\n' -e empty ${TEST_SH} -c \
			'echo $(( 0x4000000000 >> 35 ))'
	test ${ARITH_BITS} -ge 80 &&
		atf_check -s exit:0 -o inline:'4464\n' -e empty ${TEST_SH} -c \
			'echo $(( 0x93400FACE005C871000 >> 64 ))'

	return 0
}

atf_test_case elementary_eq
elementary_eq_head()
{
        atf_set "descr" "Tests that simple equality test works as expected"
}
elementary_eq_body()
{
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 == 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 == 0000 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 == 0x00 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 == 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'X=30; Y=0x1E; echo $(( X == Y ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x1234 == 4660 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x1234 == 011064 ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 == 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 == 0000000000000001 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 == 0x10000000000000 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 == 2 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'X=3; Y=7; echo $(( X == Y ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1234 == 0x4660 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 01234 == 0x11064 ))'
}
atf_test_case elementary_ne
elementary_ne_head()
{
        atf_set "descr" "Tests that simple inequality test works as expected"
}
elementary_ne_body()
{
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 != 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x71 != 17 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1234 != 01234 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x1234 != 01234 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'X=3; echo $(( X != 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'X=3; Y=0x11; echo $(( X != Y ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 != 3 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 != 0x0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xA != 012 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'X=1; echo $(( X != 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'X=0xC; Y=014; echo $(( X != Y ))'
}
atf_test_case elementary_lt
elementary_lt_head()
{
        atf_set "descr" "Tests that simple less than test works as expected"
}
elementary_lt_body()
{
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 < 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( -1 < 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 < 10 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 100 < 101 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xA1 < 200 ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 < 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 < 0 ))'

	test ${ARITH_BITS} -ge 40 &&
	    atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x1BEEFF00D < 0x1FACECAFE ))'

	return 0
}
atf_test_case elementary_le
elementary_le_head()
{
        atf_set "descr" "Tests that simple less or equal test works as expected"
}
elementary_le_body()
{
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 <= 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( -1 <= 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 <= 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 <= 10 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 100 <= 101 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xA1 <= 161 ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 <= 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( -100 <= -200 ))'

	test ${ARITH_BITS} -ge 40 &&
	    atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'cost=; AUD=; echo $(( $cost 0x2FEEDBABE <= $AUD 12866927294 ))'

	return 0
}
atf_test_case elementary_gt
elementary_gt_head()
{
        atf_set "descr" "Tests that simple greater than works as expected"
}
elementary_gt_body()
{
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 > 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 > -1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 11 > 012 ))'

	# atf_expect_fail "PR bin/50959"
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 2147483647 > 0X7FFFFF0 ))'
	# atf_expect_pass

	test ${ARITH_BITS} -gt 32 &&
	    atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x80000000 > 0x7FFFFFFF ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 > 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 > 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( -1 > 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 > 10 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 2015 > 2016 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xA1 > 200 ))'

	test ${ARITH_BITS} -ge 44 &&
	    atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x7F07F07F0 > 34099628014 ))'

	return 0
}
atf_test_case elementary_ge
elementary_ge_head()
{
        atf_set "descr" "Tests that simple greater or equal works as expected"
}
elementary_ge_body()
{
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 >= 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 >= 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( -100 >= -101 ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( -1 >= 0 ))'
}

atf_test_case fiddle_bits_and
fiddle_bits_and_head()
{
	atf_set "descr" "Test bitwise and operations in arithmetic expressions"
}
fiddle_bits_and_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 & 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 & 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 & 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 & 1 ))'

	atf_check -s exit:0 -o inline:'255\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xFF & 0xFF ))'
	atf_check -s exit:0 -o inline:'255\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xFFFF & 0377 ))'

	test "${ARITH_BITS}" -ge 48 &&
	    atf_check -s exit:0 -o inline:'70377641607203\n' -e empty \
		${TEST_SH} -c 'echo $(( 0x5432FEDC0123 & 0x42871357BAB3 ))'

	return 0
}
atf_test_case fiddle_bits_or
fiddle_bits_or_head()
{
	atf_set "descr" "Test bitwise or operations in arithmetic expressions"
}
fiddle_bits_or_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 | 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 | 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 | 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 | 1 ))'

	atf_check -s exit:0 -o inline:'4369\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x1111 | 0x1111 ))'
	atf_check -s exit:0 -o inline:'255\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xAA | 0125 ))'

	test "${ARITH_BITS}" -ge 48 &&
	    atf_check -s exit:0 -o inline:'95348271856563\n' -e empty \
		${TEST_SH} -c 'echo $(( 0x5432FEDC0123 | 0x42871357BAB3 ))'

	return 0
}
atf_test_case fiddle_bits_xor
fiddle_bits_xor_head()
{
	atf_set "descr" "Test bitwise xor operations in arithmetic expressions"
}
fiddle_bits_xor_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 ^ 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 ^ 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 ^ 1 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 ^ 1 ))'

	atf_check -s exit:0 -o inline:'255\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xF0 ^ 0x0F ))'
	atf_check -s exit:0 -o inline:'15\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xF0 ^ 0xFF ))'

	test "${ARITH_BITS}" -ge 48 &&
	    atf_check -s exit:0 -o inline:'24970630249360\n' -e empty \
		${TEST_SH} -c 'echo $(( 0x5432FEDC0123 ^ 0x42871357BAB3 ))'

	return 0
}

atf_test_case logical_and
logical_and_head()
{
	atf_set "descr" "Test logical and operations in arithmetic expressions"
}
logical_and_body()
{
	# cannot test short-circuit eval until sh implements side effects...

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 && 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 && 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 && 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 && 1 ))'

	# atf_expect_fail "PR bin/50960"
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x1111 && 01234 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xFFFF && 0xF0F0 ))'
}
atf_test_case logical_or
logical_or_head()
{
	atf_set "descr" "Test logical or operations in arithmetic expressions"
}
logical_or_body()
{
	# cannot test short-circuit eval until sh implements side effects...

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 || 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 || 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 || 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 || 1 ))'

	# atf_expect_fail "PR bin/50960"
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x1111 || 01234 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x33 || 0xF0F0 ))'
}

atf_test_case nested_arith
nested_arith_head()
{
	atf_set "descr" 'Test nested arithmetic $(( $(( )) ))'
}
nested_arith_body()
{
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( $(( 0 )) ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 + $(( 2 - 2 )) ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( $(( 3 / 3 )) + $((1*1*1)) - $(( 7 % 6 ))))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(($(($(($(($((1))))))))))'

	atf_check -s exit:0 -o inline:'246\n' -e empty ${TEST_SH} -c \
		'echo $(( 2$((2 * 2))6 ))'
	atf_check -s exit:0 -o inline:'291117\n' -e empty ${TEST_SH} -c \
		'echo $(( $((1 + 1))$((3 * 3))$(( 99-88 ))$(( 17))))'
	atf_check -s exit:0 -o inline:'123456789\n' -e empty ${TEST_SH} -c \
	  'echo $(( 1$((2$((1+2))4$((2 + 2 + 1))6))7$((4 * 2))$(($((81/9))))))'
}

atf_test_case make_selection
make_selection_head()
{
	atf_set "descr" "Test ?: operator in arithmetic expressions"
}
make_selection_body()
{
	# atf_expect_fail "PR bin/50958"

	atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \
		'echo $(( 0 ? 2 : 3 ))'
	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 ? 2 : 3 ))'

	atf_check -s exit:0 -o inline:'111\n' -e empty ${TEST_SH} -c \
		'echo $(( 0x1234 ? 111 : 222 ))'

	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 < 2 ? -1 : 1 > 2 ? 1 : 0 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 < 1 ? -1 : 1 > 1 ? 1 : 0 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 < 1 ? -1 : 2 > 1 ? 1 : 0 ))'
}

atf_test_case operator_precedence
operator_precedence_head()
{
	atf_set "descr" "Test operator precedence without parentheses"
}
operator_precedence_body()
{
	# NB: apart from $(( ))  ** NO ** parentheses in the expressions.

	atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 + 2 + 3 ))'
	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 - 2 + 3 ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 - 2 - 1 ))'
	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 - 2 + 1 ))'

	atf_check -s exit:0 -o inline:'-1\n' -e empty ${TEST_SH} -c \
		'echo $(( - 2 + 1 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 + -1 ))'

	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( ! 2 + 1 ))'
	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 + !1 ))'

	atf_check -s exit:0 -o inline:'8\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 * 2 + 2 ))'
	atf_check -s exit:0 -o inline:'7\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 + 2 * 2 ))'
	atf_check -s exit:0 -o inline:'12\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 * 2 * 2 ))'

	atf_check -s exit:0 -o inline:'5\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 / 3 + 2 ))'
	atf_check -s exit:0 -o inline:'10\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 + 3 / 2 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 / 3 / 2 ))'

	atf_check -s exit:0 -o inline:'72\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 << 1 + 2 ))'
	atf_check -s exit:0 -o inline:'48\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 + 3 << 2 ))'
	atf_check -s exit:0 -o inline:'288\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 << 3 << 2 ))'

	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 >> 1 + 2 ))'
	atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 + 3 >> 2 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 19 >> 3 >> 1 ))'

	atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \
		'echo $(( 19 >> 3 << 1 ))'
	atf_check -s exit:0 -o inline:'76\n' -e empty ${TEST_SH} -c \
		'echo $(( 19 << 3 >> 1 ))'

	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 + 3 < 3 * 2 ))'
	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 << 3 >= 3 << 2 ))'

	# sh inherits C's crazy operator precedence...

	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 0xfD & 0xF == 0xF ))'

	${TEST_SH} -c ': $(( 1 , 2 , 3 ))' 2>/dev/null  && {
		atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
			'echo $(( 3 * 7 , 2 << 8 ,  9 - 7 ))'
		atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \
			'echo $(( 1 ? 2 : 3 , 0 ? 1 : 4 ))'
	}

	return 0
}

atf_test_case optional_comma
optional_comma_head()
{
	atf_set "descr" "Test the optional comma operator"
}
optional_comma_body()
{
	# First, see if it is supported or not.
	${TEST_SH} -c ': $(( 1 , 2 , 3 ))' 2>/dev/null  || atf_skip \
	    "${TEST_SH} does not implement the ',' operator in"' $(( ))'


	# Note ',' should be set off from numbers by spaces, as in some
	# locales it is a valid chacacter in a number, and we want to
	# avoid any possibility of confusing the parser.

	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 , 2 ))'
	atf_check -s exit:0 -o inline:'3\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 , 2 , 3 ))'
	atf_check -s exit:0 -o inline:'4\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 , 2 , 3 , 4 ))'

	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'echo $(( , 2 ))'
	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'echo $(( 2 , ))'
	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'echo $(( 1 , , 2 ))'
}

parentheses_head()
{
	atf_set "descr" "Test use of () to group sub-expressions"
}
parentheses_body()
{
	atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \
		'echo $(( (1 + 2) + 3 ))'
	atf_check -s exit:0 -o inline:'-4\n' -e empty ${TEST_SH} -c \
		'echo $(( 1 - (2 + 3) ))'
	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 - (2 - 1) ))'
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 - ( 2 + 1 ) ))'

	atf_check -s exit:0 -o inline:'-3\n' -e empty ${TEST_SH} -c \
		'echo $(( - (2 + 1) ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( ! (2 + 1) ))'

	atf_check -s exit:0 -o inline:'12\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 * (2 + 2) ))'
	atf_check -s exit:0 -o inline:'10\n' -e empty ${TEST_SH} -c \
		'echo $(( (3 + 2) * 2 ))'
	atf_check -s exit:0 -o inline:'12\n' -e empty ${TEST_SH} -c \
		'echo $(( 3 * (2 * 2) ))'

	atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 / (3 + 2) ))'
	atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \
		'echo $(( ( 9 + 3 ) / 2 ))'
	atf_check -s exit:0 -o inline:'9\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 / ( 3 / 2 ) ))'

	atf_check -s exit:0 -o inline:'20\n' -e empty ${TEST_SH} -c \
		'echo $(( ( 9 << 1 ) + 2 ))'
	atf_check -s exit:0 -o inline:'21\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 + (3 << 2) ))'
	atf_check -s exit:0 -o inline:'36864\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 << (3 << 2) ))'

	atf_check -s exit:0 -o inline:'6\n' -e empty ${TEST_SH} -c \
		'echo $(( (9 >> 1) + 2 ))'
	atf_check -s exit:0 -o inline:'9\n' -e empty ${TEST_SH} -c \
		'echo $(( 9 + (3 >> 2) ))'
	atf_check -s exit:0 -o inline:'9\n' -e empty ${TEST_SH} -c \
		'echo $(( 19 >> (3 >> 1) ))'

	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( 19 >> (3 << 1) ))'
	atf_check -s exit:0 -o inline:'38\n' -e empty ${TEST_SH} -c \
		'echo $(( 19 << (3 >> 1) ))'

	atf_check -s exit:0 -o inline:'2\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 + (3 < 3) * 2 ))'
	atf_check -s exit:0 -o inline:'32\n' -e empty ${TEST_SH} -c \
		'echo $(( 2 << ((3 >= 3) << 2) ))'

	# sh inherits C's crazy operator precedence...
	atf_check -s exit:0 -o inline:'0\n' -e empty ${TEST_SH} -c \
		'echo $(( (0xfD & 0xF) == 0xF ))'

	${TEST_SH} -c ': $(( 1 , 2 , 3 ))' 2>/dev/null  && {
		atf_check -s exit:0 -o inline:'24\n' -e empty ${TEST_SH} -c \
			'echo $(( 3 * (7 , 2) << (8 ,  9 - 7) ))'
		atf_check -s exit:0 -o inline:'1\n' -e empty ${TEST_SH} -c \
			'echo $(( 0 ? 2 : ( ( 0 , 3 ) ? 1 : 4) ))'
	}
	return 0
}

atf_test_case var_assign
var_assign_head()
{
	atf_set "descr" "Test assignment operators in arithmetic expressions"
}
var_assign_body()
{
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'unset x; echo $(( x = 3 )); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'unset x; echo $((x=3)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=5; echo $((x=3)); echo $x'

	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'set +u;unset x; echo $((x+=3)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=2; echo $((x+=1)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=4; echo $((x-=1)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=3; echo $((x*=1)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=3; echo $((x/=1)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=28; echo $((x%=5)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=7; echo $((x&=3)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=2; echo $((x|=1)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=6; echo $((x^=5)); echo $x'
	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'x=7; echo $((x>>=1)); echo $x'
	atf_check -s exit:0 -o inline:'2\n2\n' -e empty ${TEST_SH} -c \
		'x=1; echo $((x<<=1)); echo $x'

	atf_check -s exit:0 -o inline:'2\n3\n' -e empty ${TEST_SH} -c \
		'x=2; echo $(( (x+=1)-1 )); echo $x'
	atf_check -s exit:0 -o inline:'4\n3\n' -e empty ${TEST_SH} -c \
		'x=4; echo $(( (x-=1)+1 )); echo $x'

	atf_check -s exit:0 -o inline:'36\n5 7\n' -e empty ${TEST_SH} -c \
		'unset x y; echo $(( (x=5) * (y=7) + 1 )); echo $x $y'
	atf_check -s exit:0 -o inline:'36\n5 7\n' -e empty ${TEST_SH} -c \
		'x=99; y=17; echo $(( (x=5) * (y=7) + 1 )); echo $x $y'
	atf_check -s exit:0 -o inline:'36\n5 7\n' -e empty ${TEST_SH} -c \
		'x=4; y=9; echo $(( (x+=1) * (y-=2) + 1 )); echo $x $y'

	atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
		'set -u; unset x; echo $(( x = 3 )); echo $x'
	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
		'set -u; unset x; echo $(( x + 3 )); echo $x'
	atf_check -s not-exit:0 -o ignore -e not-empty ${TEST_SH} -c \
		'set -u; unset x; echo $(( x+=3 )); echo $x'

	${TEST_SH} -c ': $(( 1 , 2 , 3 ))' 2>/dev/null  && {
		atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
			'echo $((x=2 , x|=1)); echo $x'
		atf_check -s exit:0 -o inline:'3\n3\n' -e empty ${TEST_SH} -c \
			'set -u; echo $((x = 2   ,x |= 1)); echo $x'
		atf_check -s exit:0 -o inline:'6\n1:2:3:6\n' -e empty \
			${TEST_SH} -c \
		    'echo $((a=1 , b=2 , c = 3 , x=a+b + c)); echo $a:$b:$c:$x'
		atf_check -s exit:0 -o inline:'6\n1:2:3:6\n' -e empty \
			${TEST_SH} -c \
		    'set -u;echo $((a=1 ,b=2 ,c=3 ,x=a+b+c)); echo $a:$b:$c:$x'
	}
	return 0
}

atf_test_case var_postinc
var_postinc_head()
{
	atf_set "descr" "Test suffix ++ operator"
}
var_postinc_body()
{
	${TEST_SH} -c 'X=1; : $(( X++ ))' 2>/dev/null ||
		atf_skip "${TEST_SH} does not support the suffix ++ operator"

	unset X		; # just in case ...

	atf_check -s exit:0 -o inline:'1\n2\n' -e empty ${TEST_SH} -c \
		'X=1; echo $(( X++ )); echo $X'
	atf_check -s exit:0 -o inline:'0\n1\n' -e empty ${TEST_SH} -c \
		'echo $(( X++ )); echo $X'

	atf_check -s exit:0 -o inline:'0\n1:0\n' -e empty ${TEST_SH} -c \
		'unset Y; echo $(( Y = X++ )); echo $X:$Y'
	atf_check -s exit:0 -o inline:'12\n4:5\n' -e empty ${TEST_SH} -c \
		'X=3 Y=4; echo $(( Y++*X++ )); echo $X:$Y'

	atf_check -s exit:0 -o inline:'1\n2\n' -e empty ${TEST_SH} -c \
		'set -u; X=1; echo $(( X++ )); echo $X'
	atf_check -s exit:0 -o inline:'0\n1:0\n' -e empty ${TEST_SH} -c \
		'set -u; X=0; unset Y; echo $(( Y = X++ )); echo $X:$Y'
	atf_check -s exit:0 -o inline:'12\n4:5\n' -e empty ${TEST_SH} -c \
		'set -u; X=3 Y=4; echo $(( Y++*X++ )); echo $X:$Y'

	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'set -u; echo $(( X++ ))'
	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'set -u; unset Y; echo $(( X = Y++ ))'

	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'X=3; readonly X; echo $(( X++ ))'

}
atf_test_case var_postdec
var_postdec_head()
{
	atf_set "descr" "Test suffix -- operator"
}
var_postdec_body()
{
	${TEST_SH} -c 'X=1; : $(( X-- ))' 2>/dev/null ||
		atf_skip "${TEST_SH} does not support the suffix -- operator"

	unset X		; # just in case ...

	atf_check -s exit:0 -o inline:'1\n0\n' -e empty ${TEST_SH} -c \
		'X=1; echo $(( X-- )); echo $X'
	atf_check -s exit:0 -o inline:'0\n-1\n' -e empty ${TEST_SH} -c \
		'echo $(( X-- )); echo $X'

	atf_check -s exit:0 -o inline:'0\n-1:0\n' -e empty ${TEST_SH} -c \
		'unset Y; echo $(( Y = X-- )); echo $X:$Y'
	atf_check -s exit:0 -o inline:'12\n2:3\n' -e empty ${TEST_SH} -c \
		'X=3 Y=4; echo $(( Y--*X-- )); echo $X:$Y'

	atf_check -s exit:0 -o inline:'1\n0\n' -e empty ${TEST_SH} -c \
		'set -u; X=1; echo $(( X-- )); echo $X'
	atf_check -s exit:0 -o inline:'0\n-1:0\n' -e empty ${TEST_SH} -c \
		'set -u; X=0; unset Y; echo $(( Y = X-- )); echo $X:$Y'
	atf_check -s exit:0 -o inline:'12\n2:3\n' -e empty ${TEST_SH} -c \
		'set -u; X=3 Y=4; echo $(( Y--*X-- )); echo $X:$Y'

	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'set -u; echo $(( X-- ))'
	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'set -u; unset Y; echo $(( X = Y-- ))'

	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'X=3; readonly X; echo $(( X-- ))'

}
atf_test_case var_preinc
var_preinc_head()
{
	atf_set "descr" "Test prefix ++ operator"
}
var_preinc_body()
{
	${TEST_SH} -c 'X=1; : $(( ++X ))' 2>/dev/null ||
		atf_skip "${TEST_SH} does not support the prefix ++ operator"

	unset X		; # just in case ...

	atf_check -s exit:0 -o inline:'2\n2\n' -e empty ${TEST_SH} -c \
		'X=1; echo $(( ++X )); echo $X'
	atf_check -s exit:0 -o inline:'1\n1\n' -e empty ${TEST_SH} -c \
		'echo $(( ++X )); echo $X'

	atf_check -s exit:0 -o inline:'1\n1:1\n' -e empty ${TEST_SH} -c \
		'unset Y; echo $(( Y = ++X )); echo $X:$Y'
	atf_check -s exit:0 -o inline:'20\n4:5\n' -e empty ${TEST_SH} -c \
		'X=3 Y=4; echo $(( ++Y*++X )); echo $X:$Y'

	atf_check -s exit:0 -o inline:'2\n2\n' -e empty ${TEST_SH} -c \
		'set -u; X=1; echo $(( ++X )); echo $X'
	atf_check -s exit:0 -o inline:'1\n1:1\n' -e empty ${TEST_SH} -c \
		'set -u; X=0; unset Y; echo $(( Y = ++X )); echo $X:$Y'
	atf_check -s exit:0 -o inline:'20\n4:5\n' -e empty ${TEST_SH} -c \
		'set -u; X=3 Y=4; echo $(( ++Y*++X )); echo $X:$Y'

	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'set -u; echo $(( ++X ))'
	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'set -u; unset Y; echo $(( X = ++Y ))'

	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'X=3; readonly X; echo $(( ++X ))'

}
atf_test_case var_predec
var_predec_head()
{
	atf_set "descr" "Test prefix -- operator"
}
var_predec_body()
{
	${TEST_SH} -c 'X=1; : $(( --X ))' 2>/dev/null ||
		atf_skip "${TEST_SH} does not support the prefix -- operator"

	unset X		; # just in case ...

	atf_check -s exit:0 -o inline:'0\n0\n' -e empty ${TEST_SH} -c \
		'X=1; echo $(( --X )); echo $X'
	atf_check -s exit:0 -o inline:'-1\n-1\n' -e empty ${TEST_SH} -c \
		'echo $(( --X )); echo $X'

	atf_check -s exit:0 -o inline:'-1\n-1:-1\n' -e empty ${TEST_SH} -c \
		'unset Y; echo $(( Y = --X )); echo $X:$Y'
	atf_check -s exit:0 -o inline:'6\n2:3\n' -e empty ${TEST_SH} -c \
		'X=3 Y=4; echo $(( --Y*--X )); echo $X:$Y'

	atf_check -s exit:0 -o inline:'0\n0\n' -e empty ${TEST_SH} -c \
		'set -u; X=1; echo $(( --X )); echo $X'
	atf_check -s exit:0 -o inline:'-1\n-1:-1\n' -e empty ${TEST_SH} -c \
		'set -u; X=0; unset Y; echo $(( Y = --X )); echo $X:$Y'
	atf_check -s exit:0 -o inline:'6\n2:3\n' -e empty ${TEST_SH} -c \
		'set -u; X=3 Y=4; echo $(( --Y*--X )); echo $X:$Y'

	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'set -u; echo $(( --X ))'
	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'set -u; unset Y; echo $(( X = --Y ))'

	atf_check -s not-exit:0 -o empty -e not-empty ${TEST_SH} -c \
		'X=3; readonly X; echo $(( --X ))'

}

atf_test_case arithmetic_fails
arithmetic_fails_head()
{
	atf_set "descr" "Dummy test to force failure"
}
arithmetic_fails_body()
{
	atf_fail "Cannot estimate number of bits supported by $(( ))"
}

atf_init_test_cases() {

	discover_range

	test "${ARITH_BITS}" = '?' && {
		atf_add_test_case arithmetic_fails
		return 0
	}

	# odd names are to get atf's sort order semi-rational

	atf_add_test_case constants
	atf_add_test_case do_unary_plus
	atf_add_test_case do_unary_minus
	atf_add_test_case do_unary_not
	atf_add_test_case do_unary_tilde
	atf_add_test_case elementary_add
	atf_add_test_case elementary_sub
	atf_add_test_case elementary_mul
	atf_add_test_case elementary_div
	atf_add_test_case elementary_rem
	atf_add_test_case elementary_shl
	atf_add_test_case elementary_shr
	atf_add_test_case elementary_eq
	atf_add_test_case elementary_ne
	atf_add_test_case elementary_lt
	atf_add_test_case elementary_le
	atf_add_test_case elementary_gt
	atf_add_test_case elementary_ge
	atf_add_test_case fiddle_bits_and
	atf_add_test_case fiddle_bits_or
	atf_add_test_case fiddle_bits_xor
	atf_add_test_case logical_and
	atf_add_test_case logical_or
	atf_add_test_case make_selection
	atf_add_test_case nested_arith
	atf_add_test_case operator_precedence
	atf_add_test_case optional_comma
	atf_add_test_case parentheses
	# atf_add_test_case progressive			# build up big expr
	# atf_add_test_case test_errors			# erroneous input
	# atf_add_test_case torture		# hard stuff (if there is any)
	atf_add_test_case var_assign			# assignment ops
	atf_add_test_case var_postinc			# var++
	atf_add_test_case var_postdec			# var--
	atf_add_test_case var_preinc			# ++var
	atf_add_test_case var_predec			# --var
	# atf_add_test_case vulgarity	# truly evil inputs (syntax in vars...)
}