~vcs-imports/busybox/trunk

« back to all changes in this revision

Viewing changes to testsuite/awk.tests

  • Committer: Denys Vlasenko
  • Author(s): Christian Franke
  • Date: 2023-11-13 10:32:35 UTC
  • Revision ID: git-v1:a63b60bdd6fa26b867c80d44074118babbae7ffd
Cygwin: regenerate defconfig

Signed-off-by: Christian Franke <christian.franke@t-online.de>
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
        "" ""
46
46
 
47
47
prg='
 
48
function empty_fun(){}
 
49
END {empty_fun()
 
50
  print "Ok"
 
51
}'
 
52
testing "awk handles empty function f(){}" \
 
53
        "awk '$prg'" \
 
54
        "Ok\n" \
 
55
        "" ""
 
56
 
 
57
prg='
48
58
function outer_fun() {
49
59
  return 1
50
60
}
71
81
        "L1\n\nawk: cmd. line:5: Call to undefined function\n" \
72
82
        "" ""
73
83
 
 
84
prg='
 
85
BEGIN {
 
86
  v=1
 
87
  a=2
 
88
  print v (a)
 
89
}'
 
90
testing "awk 'v (a)' is not a function call, it is a concatenation" \
 
91
        "awk '$prg' 2>&1" \
 
92
        "12\n" \
 
93
        "" ""
 
94
 
 
95
prg='func f(){print"F"};func g(){print"G"};BEGIN{f(g(),g())}'
 
96
testing "awk unused function args are evaluated" \
 
97
        "awk '$prg' 2>&1" \
 
98
        "G\nG\nF\n" \
 
99
        "" ""
 
100
 
74
101
 
75
102
optional DESKTOP
76
103
testing "awk hex const 1" "awk '{ print or(0xffffffff,1) }'" "4294967295\n" "" "\n"
77
104
testing "awk hex const 2" "awk '{ print or(0x80000000,1) }'" "2147483649\n" "" "\n"
78
 
testing "awk oct const"   "awk '{ print or(01234,1) }'"      "669\n"         "" "\n"
 
105
testing "awk oct const"   "awk '{ print or(01234,1) }'"      "669\n"        "" "\n"
79
106
SKIP=
80
107
 
 
108
# check that "hex/oct integer" heuristic doesn't kick in on input
 
109
# (must be done only when parsing program text)
 
110
testing "awk input is never oct" "awk '{ print \$1, \$1+1 }'" "011 12\n"    "" "011\n"
 
111
 
81
112
# check that "hex/oct integer" heuristic doesn't kick in on 00NN.NNN
82
113
testing "awk floating const with leading zeroes" \
83
114
        "awk '{ printf \"%f %f\n\", \"000.123\", \"009.123\" }'" \
352
383
        ""
353
384
SKIP=
354
385
 
355
 
# The examples are in fact not valid awk programs (break/continue
356
 
# can only be used inside loops).
357
 
# But we do accept them outside of loops.
358
 
# We had a bug with misparsing "break ; else" sequence.
359
 
# Test that *that* bug is fixed, using simplest possible scripts:
360
386
testing "awk break" \
361
387
        "awk -f - 2>&1; echo \$?" \
362
 
        "0\n" \
 
388
        "awk: -:1: 'break' not in a loop\n1\n" \
363
389
        "" \
364
390
        'BEGIN { if (1) break; else a = 1 }'
365
391
testing "awk continue" \
366
392
        "awk -f - 2>&1; echo \$?" \
367
 
        "0\n" \
 
393
        "awk: -:1: 'continue' not in a loop\n1\n" \
368
394
        "" \
369
395
        'BEGIN { if (1) continue; else a = 1 }'
370
396
 
383
409
        "awk -e '{delete}' 2>&1" "awk: cmd. line:1: Too few arguments\n" "" ""
384
410
SKIP=
385
411
 
 
412
optional FEATURE_AWK_GNU_EXTENSIONS
 
413
testing "awk printf('%c') can output NUL" \
 
414
        "awk '{printf(\"hello%c null\n\", 0)}'" "hello\0 null\n" "" "\n"
 
415
SKIP=
 
416
 
 
417
optional FEATURE_AWK_GNU_EXTENSIONS DESKTOP
 
418
testing "awk printf('%-10c') can output NUL" \
 
419
        "awk 'BEGIN { printf \"[%-10c]\n\", 0 }' | od -tx1" "\
 
420
0000000 5b 00 20 20 20 20 20 20 20 20 20 5d 0a
 
421
0000015
 
422
" "" ""
 
423
SKIP=
 
424
 
386
425
# testing "description" "command" "result" "infile" "stdin"
387
426
testing 'awk negative field access' \
388
427
        'awk 2>&1 -- '\''{ $(-1) }'\' \
390
429
        '' \
391
430
        'anything'
392
431
 
 
432
# was misinterpreted as (("str"++) i) instead of ("str" (++i))
 
433
# (and was executed: "str"++ is "0", thus concatenating "0" and "1"):
 
434
testing 'awk do not allow "str"++' \
 
435
        'awk -v i=1 "BEGIN {print \"str\" ++i}"' \
 
436
        "str2\n" \
 
437
        '' \
 
438
        'anything'
 
439
 
 
440
# gawk compat: FS regex matches only non-empty separators:
 
441
# with -*, the splitting is NOT f o o b a r, but foo bar:
 
442
testing 'awk FS regex which can match empty string' \
 
443
        "awk -F '-*' '{print \$1 \"-\" \$2 \"=\" \$3 \"*\" \$4}'" \
 
444
        "foo-bar=*\n" \
 
445
        '' \
 
446
        'foo--bar'
 
447
 
 
448
# last+1 field should be empty (had a bug where it wasn't)
 
449
testing 'awk $NF is empty' \
 
450
        "awk -F '=+' '{print \$NF}'" \
 
451
        "\n" \
 
452
        '' \
 
453
        'a=====123='
 
454
 
 
455
testing "awk exit N propagates through END's exit" \
 
456
        "awk 'BEGIN { exit 42 } END { exit }'; echo \$?" \
 
457
        "42\n" \
 
458
        '' ''
 
459
 
 
460
testing "awk print + redirect" \
 
461
        "awk 'BEGIN { print \"STDERR %s\" >\"/dev/stderr\" }' 2>&1" \
 
462
        "STDERR %s\n" \
 
463
        '' ''
 
464
 
 
465
testing "awk \"cmd\" | getline" \
 
466
        "awk 'BEGIN { \"echo HELLO\" | getline; print }'" \
 
467
        "HELLO\n" \
 
468
        '' ''
 
469
 
 
470
# printf %% should print one % (had a bug where it didn't)
 
471
testing 'awk printf %% prints one %' \
 
472
        "awk 'BEGIN { printf \"%%\n\" }'" \
 
473
        "%\n" \
 
474
        '' ''
 
475
 
 
476
testing 'awk backslash+newline eaten with no trace' \
 
477
        "awk 'BEGIN { printf \"Hello\\
 
478
 world\n\" }'" \
 
479
        "Hello world\n" \
 
480
        '' ''
 
481
 
 
482
testing 'awk assign while test' \
 
483
        "awk '\$1==\$1=\"foo\" {print \$1}'" \
 
484
        "foo\n" \
 
485
        "" \
 
486
        "foo"
 
487
 
 
488
# User-supplied bug (SEGV) example, was causing use-after-realloc
 
489
testing 'awk assign while assign' \
 
490
        "awk '\$5=\$\$5=\$0'; echo \$?" \
 
491
        "\
 
492
─ process timing ────────────────────────────────────┬─ ─ process timing ────────────────────────────────────┬─ overall results ────┐ results ────┐
 
493
│ run time : │        run time : 0 days, 0 hrs, 0 min, 56 sec      │  cycles done : 0     │ days, 0 hrs, 0 min, 56 sec │ cycles done : 0 │
 
494
│ last new find │   last new find : 0 days, 0 hrs, 0 min, 1 sec       │ corpus count : 208   │ 0 days, 0 hrs, 0 min, 1 sec │ corpus count : 208 │
 
495
│last saved crash : │last saved crash : none seen yet                     │saved crashes : 0     │ seen yet │saved crashes : 0 │
 
496
│ last saved hang │ last saved hang : none seen yet                     │  saved hangs : 0     │ none seen yet │ saved hangs : 0 │
 
497
├─ cycle progress ─────────────────────┬─ ├─ cycle progress ─────────────────────┬─ map coverage┴──────────────────────┤ coverage┴──────────────────────┤
 
498
│ now processing : │  now processing : 184.1 (88.5%)      │    map density : 0.30% / 0.52%      │ (88.5%) │ map density : 0.30% / 0.52% │                                                                                                                                                                          │  now processing : 184.1 (88.5%)      │    map density : 0.30% / 0.52%      │
 
499
│ runs timed out │  runs timed out : 0 (0.00%)          │ count coverage : 2.18 bits/tuple    │ 0 (0.00%) │ count coverage : 2.18 bits/tuple │
 
500
├─ stage progress ─────────────────────┼─ ├─ stage progress ─────────────────────┼─ findings in depth ─────────────────┤ in depth ─────────────────┤
 
501
│ now trying : │  now trying : havoc                  │ favored items : 43 (20.67%)         │ │ favored items : 43 (20.67%) │
 
502
│ stage execs : │ stage execs : 11.2k/131k (8.51%)     │  new edges on : 52 (25.00%)         │ (8.51%) │ new edges on │ stage execs : 11.2k/131k (8.51%)     │  new edges on : 52 (25.00%)         │ 52 (25.00%) │
 
503
│ total execs : │ total execs : 179k                   │ total crashes : 0 (0 saved)         │ │ total crashes : 0 (0 saved) │                                                                                                                                                                      │ total execs : 179k                   │ total crashes : 0 (0 saved)         │
 
504
│ exec speed : │  exec speed : 3143/sec               │  total tmouts : 0 (0 saved)         │ │ total tmouts : 0 (0 saved) │                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          │  exec speed : 3143/sec               │  total tmouts : 0 (0 saved)         │
 
505
├─ fuzzing strategy yields ├─ fuzzing strategy yields ────────────┴─────────────┬─ item geometry ───────┤ item geometry ───────┤
 
506
│ bit flips : │   bit flips : 11/648, 4/638, 5/618                 │    levels : 4         │ 4/638, 5/618 │ levels : │   bit flips : 11/648, 4/638, 5/618                 │    levels : 4         │ │
 
507
│ byte flips : │  byte flips : 0/81, 0/71, 0/52                     │   pending : 199       │ 0/71, 0/52 │ pending : 199 │
 
508
│ arithmetics : 11/4494, │ arithmetics : 11/4494, 0/1153, 0/0                 │  pend fav : 35        │ 0/0 │ pend fav : 35 │
 
509
│  known ints : 1/448, 0/1986, 0/2288                │ own finds : 207       │ known ints : │  known ints : 1/448, 0/1986, 0/2288                │ own finds : 207       │ 0/1986, 0/2288 │ own finds : 207 │
 
510
│ dictionary : 0/0, │  dictionary : 0/0, 0/0, 0/0, 0/0                   │  imported : 0         │ 0/0, 0/0 │ imported : 0 │
 
511
│havoc/splice : 142/146k, 23/7616 │havoc/splice : 142/146k, 23/7616                    │ stability : 100.00%   │ stability : 100.00% │
 
512
│py/custom/rq : unused, unused, │py/custom/rq : unused, unused, unused, unused       ├───────────────────────┘ unused ├───────────────────────┘
 
513
│ trim/eff : 57.02%/26, │    trim/eff : 57.02%/26, 0.00%                     │          [cpu000:100%] │ [cpu000:100%]
 
514
└────────────────────────────────────────────────────┘^C    └────────────────────────────────────────────────────┘^C
 
515
0
 
516
" \
 
517
        "" \
 
518
        "\
 
519
─ process timing ────────────────────────────────────┬─ overall results ────┐
 
520
│        run time : 0 days, 0 hrs, 0 min, 56 sec      │  cycles done : 0     │
 
521
│   last new find : 0 days, 0 hrs, 0 min, 1 sec       │ corpus count : 208   │
 
522
│last saved crash : none seen yet                     │saved crashes : 0     │
 
523
│ last saved hang : none seen yet                     │  saved hangs : 0     │
 
524
├─ cycle progress ─────────────────────┬─ map coverage┴──────────────────────┤
 
525
│  now processing : 184.1 (88.5%)      │    map density : 0.30% / 0.52%      │
 
526
│  runs timed out : 0 (0.00%)          │ count coverage : 2.18 bits/tuple    │
 
527
├─ stage progress ─────────────────────┼─ findings in depth ─────────────────┤
 
528
│  now trying : havoc                  │ favored items : 43 (20.67%)         │
 
529
│ stage execs : 11.2k/131k (8.51%)     │  new edges on : 52 (25.00%)         │
 
530
│ total execs : 179k                   │ total crashes : 0 (0 saved)         │
 
531
│  exec speed : 3143/sec               │  total tmouts : 0 (0 saved)         │
 
532
├─ fuzzing strategy yields ────────────┴─────────────┬─ item geometry ───────┤
 
533
│   bit flips : 11/648, 4/638, 5/618                 │    levels : 4         │
 
534
│  byte flips : 0/81, 0/71, 0/52                     │   pending : 199       │
 
535
│ arithmetics : 11/4494, 0/1153, 0/0                 │  pend fav : 35        │
 
536
│  known ints : 1/448, 0/1986, 0/2288                │ own finds : 207       │
 
537
│  dictionary : 0/0, 0/0, 0/0, 0/0                   │  imported : 0         │
 
538
│havoc/splice : 142/146k, 23/7616                    │ stability : 100.00%   │
 
539
│py/custom/rq : unused, unused, unused, unused       ├───────────────────────┘
 
540
│    trim/eff : 57.02%/26, 0.00%                     │          [cpu000:100%]
 
541
└────────────────────────────────────────────────────┘^C"
 
542
 
 
543
# If field separator FS=' ' (default), fields are split only on
 
544
# space or tab or linefeed, NOT other whitespace.
 
545
testing 'awk does not split on CR (char 13)' \
 
546
        "awk '{ \$1=\$0; print }'" \
 
547
        'word1 word2 word3\r word2 word3\r\n' \
 
548
        '' 'word1 word2 word3\r'
 
549
 
 
550
testing "awk = has higher precedence than == (despite what gawk manpage claims)" \
 
551
        "awk 'BEGIN { v=1; print 2==v; print 2==v=2; print v; print v=3==3; print v}'" \
 
552
        '0\n1\n2\n1\n3\n' \
 
553
        '' ''
 
554
 
 
555
sq="'"
 
556
testing 'awk gensub backslashes \' \
 
557
        'awk '$sq'BEGIN { s="\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \
 
558
        's=\\
 
559
\\|\\
 
560
' '' ''
 
561
testing 'awk gensub backslashes \\' \
 
562
        'awk '$sq'BEGIN { s="\\\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \
 
563
        's=\\\\
 
564
\\|\\
 
565
' '' ''
 
566
# gawk 5.1.1 handles trailing unpaired \ inconsistently.
 
567
# If replace string is single \, it is used verbatim,
 
568
# but if it is \\\ (three slashes), gawk uses "\<NUL>" (!!!), not "\\" as you would expect.
 
569
testing 'awk gensub backslashes \\\' \
 
570
        'awk '$sq'BEGIN { s="\\\\\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \
 
571
        's=\\\\\\
 
572
\\\\|\\\\
 
573
' '' ''
 
574
testing 'awk gensub backslashes \\\\' \
 
575
        'awk '$sq'BEGIN { s="\\\\\\\\"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \
 
576
        's=\\\\\\\\
 
577
\\\\|\\\\
 
578
' '' ''
 
579
testing 'awk gensub backslashes \&' \
 
580
        'awk '$sq'BEGIN { s="\\&"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \
 
581
        's=\\&
 
582
&|&
 
583
' '' ''
 
584
testing 'awk gensub backslashes \0' \
 
585
        'awk '$sq'BEGIN { s="\\0"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \
 
586
        's=\\0
 
587
a|a
 
588
' '' ''
 
589
testing 'awk gensub backslashes \\0' \
 
590
        'awk '$sq'BEGIN { s="\\\\0"; print "s=" s; print gensub("a", s, "g", "a|a") }'$sq \
 
591
        's=\\\\0
 
592
\\0|\\0
 
593
' '' ''
 
594
 
 
595
# The "b" in "abc" should not match <b* pattern.
 
596
# Currently we use REG_STARTEND ("This flag is a BSD extension, not present in POSIX")
 
597
# to implement the code to handle this correctly, but if your libc has no REG_STARTEND,
 
598
# the alternative code mishandles this case.
 
599
testing 'awk gsub erroneous word start match' \
 
600
        "awk 'BEGIN { a=\"abc\"; gsub(/\<b*/,\"\",a); print a }'" \
 
601
        'abc\n' \
 
602
        '' ''
393
603
 
394
604
exit $FAILCOUNT