busybox/testsuite/parse.tests
<<
>>
Prefs
   1#!/bin/sh
   2
   3# Copyright 2008 by Denys Vlasenko <vda.linux@googlemail.com>
   4# Licensed under GPLv2, see file LICENSE in this source tree.
   5
   6. ./testing.sh
   7
   8COLLAPSE=$((    0x00010000))
   9TRIM=$((        0x00020000))
  10GREEDY=$((      0x00040000))
  11MIN_DIE=$((     0x00100000))
  12KEEP_COPY=$((   0x00200000))
  13EOL_COMMENTS=$((0x00400000))
  14NORMAL=$((   COLLAPSE | TRIM | GREEDY | EOL_COMMENTS))
  15
  16# testing "description" "command" "result" "infile" "stdin"
  17
  18testing "parse mdev.conf" \
  19        "parse -n 4 -m 3 -f $((NORMAL)) -" \
  20        "[sda][0:0][644][@echo @echo TEST]\n" \
  21        "-" \
  22        " sda 0:0 644 @echo @echo TEST # echo trap\n"
  23
  24testing "parse notrim" \
  25        "parse -n 4 -m 3 -f $((NORMAL - TRIM - COLLAPSE)) -" \
  26        "[][sda][0:0][644 @echo @echo TEST ]\n" \
  27        "-" \
  28        " sda 0:0 644 @echo @echo TEST \n"
  29
  30testing "parse comments" \
  31        "parse -n 4 -m 3 -f $((NORMAL - EOL_COMMENTS)) -" \
  32        "[sda][0:0][644][@echo @echo TEST #this is not eaten]\n" \
  33        "-" \
  34        "\
  35# sda 0:0 644 @echo @echo TEST - this gets eaten
  36 sda 0:0 644 @echo @echo TEST #this is not eaten
  37"
  38
  39testing "parse bad comment" \
  40        "parse -n 2 -m 2 -d '#=' -f $((GREEDY)) - 2>&1" \
  41        "\
  42[var][val]
  43parse: bad line 3: 1 tokens found, 2 needed
  44[  #this][ok]
  45[  #this][=ok]
  46[  #this][=ok=ok=ok=]
  47" \
  48        "-" \
  49        "\
  50# this gets eaten
  51var=val
  52  #this causes error msg
  53  #this=ok
  54  #this==ok
  55  #this==ok=ok=ok=
  56"
  57
  58FILE=__parse
  59cat >$FILE <<EOF
  60#
  61# Device         Point               System                       Options
  62#_______________________________________________________________
  63/dev/hdb3       /                       ext2                 defaults      1          0
  64   /dev/hdb1       /dosc               hpfs                 ro      1          0
  65 /dev/fd0          /dosa              vfat                  rw,user,noauto,nohide        0              0
  66        /dev/fd1          /dosb              vfat                  rw,user,noauto,nohide         0              0
  67#
  68 /dev/cdrom     /cdrom            iso9660          ro,user,noauto,nohide         0              0
  69/dev/hdb5       /redhat            ext2                 rw,root,noauto,nohide    0              0 #sssd
  70        /dev/hdb6       /win2home     ntfs                  rw,root,noauto,nohide        0              0# ssdsd
  71/dev/hdb7       /win2skul        ntfs                  rw,root,noauto,nohide none        0              0
  72none     /dev/pts           devpts             gid=5,mode=620                 0    0 
  73     none                /proc               proc                defaults     0          0
  74EOF
  75
  76cat >$FILE.res <<EOF
  77[/dev/hdb3][/][ext2][defaults][1][0]
  78[/dev/hdb1][/dosc][hpfs][ro][1][0]
  79[/dev/fd0][/dosa][vfat][rw,user,noauto,nohide][0][0]
  80[/dev/fd1][/dosb][vfat][rw,user,noauto,nohide][0][0]
  81[/dev/cdrom][/cdrom][iso9660][ro,user,noauto,nohide][0][0]
  82[/dev/hdb5][/redhat][ext2][rw,root,noauto,nohide][0][0]
  83[/dev/hdb6][/win2home][ntfs][rw,root,noauto,nohide][0][0]
  84[/dev/hdb7][/win2skul][ntfs][rw,root,noauto,nohide][none][0             0]
  85[none][/dev/pts][devpts][gid=5,mode=620][0][0]
  86[none][/proc][proc][defaults][0][0]
  87EOF
  88
  89testing "parse polluted fstab" \
  90        "parse -n 6 -m 6 $FILE" \
  91        "`cat $FILE.res`\n" \
  92        "" \
  93        ""
  94cp ../examples/inittab $FILE
  95cat >$FILE.res <<EOF
  96[][][sysinit][/etc/init.d/rcS]
  97[][][askfirst][-/bin/sh]
  98[tty2][][askfirst][-/bin/sh]
  99[tty3][][askfirst][-/bin/sh]
 100[tty4][][askfirst][-/bin/sh]
 101[tty4][][respawn][/sbin/getty 38400 tty5]
 102[tty5][][respawn][/sbin/getty 38400 tty6]
 103[][][restart][/sbin/init]
 104[][][ctrlaltdel][/sbin/reboot]
 105[][][shutdown][/bin/umount -a -r]
 106[][][shutdown][/sbin/swapoff -a]
 107EOF
 108
 109testing "parse inittab from examples" \
 110        "parse -n 4 -m 4 -f $((NORMAL - TRIM - COLLAPSE)) -d'#:' $FILE" \
 111        "`cat $FILE.res`\n" \
 112        "" \
 113        ""
 114
 115cp ../examples/udhcp/udhcpd.conf $FILE
 116cat >$FILE.res <<EOF
 117[start][192.168.0.20]
 118[end][192.168.0.254]
 119[interface][eth0]
 120[opt][dns][192.168.10.2][192.168.10.10]
 121[option][subnet][255.255.255.0]
 122[opt][router][192.168.10.2]
 123[opt][wins][192.168.10.10]
 124[option][dns][129.219.13.81]
 125[option][domain][local]
 126[option][lease][864000]
 127[option][msstaticroutes][10.0.0.0/8][10.127.0.1]
 128[option][staticroutes][10.0.0.0/8][10.127.0.1,][10.11.12.0/24][10.11.12.1]
 129[option][0x08][01020304]
 130EOF
 131
 132testing "parse udhcpd.conf from examples" \
 133        "parse -n 127 $FILE" \
 134        "`cat $FILE.res`\n" \
 135        "" \
 136        ""
 137
 138rm -f $FILE $FILE.res
 139
 140exit $FAILCOUNT
 141