blob: 2cbed6f3117081e191e7a061fc7f652f0a7ff5b9 [file] [log] [blame]
Denis Vlasenko2e157dd2008-07-19 09:27:19 +00001#!/bin/sh
2
3# Copyright 2008 by Denys Vlasenko <vda.linux@googlemail.com>
Denys Vlasenko0ef64bd2010-08-16 20:14:46 +02004# Licensed under GPLv2, see file LICENSE in this source tree.
Denis Vlasenko2e157dd2008-07-19 09:27:19 +00005
Mike Frysingercaa79402009-11-04 18:41:22 -05006. ./testing.sh
Denis Vlasenko2e157dd2008-07-19 09:27:19 +00007
Denys Vlasenko9cf89cd2017-08-05 13:45:22 +02008COLLAPSE=$(( 0x00010000))
9TRIM=$(( 0x00020000))
10GREEDY=$(( 0x00040000))
11MIN_DIE=$(( 0x00100000))
12KEEP_COPY=$(( 0x00200000))
13EOL_COMMENTS=$((0x00400000))
14NORMAL=$(( COLLAPSE | TRIM | GREEDY | EOL_COMMENTS))
Denis Vlasenko2e157dd2008-07-19 09:27:19 +000015
16# testing "description" "command" "result" "infile" "stdin"
17
Denis Vlasenko084266e2008-07-26 23:08:31 +000018testing "parse mdev.conf" \
19 "parse -n 4 -m 3 -f $((NORMAL)) -" \
Denis Vlasenko2e157dd2008-07-19 09:27:19 +000020 "[sda][0:0][644][@echo @echo TEST]\n" \
21 "-" \
22 " sda 0:0 644 @echo @echo TEST # echo trap\n"
23
Denis Vlasenko084266e2008-07-26 23:08:31 +000024testing "parse notrim" \
25 "parse -n 4 -m 3 -f $((NORMAL - TRIM - COLLAPSE)) -" \
Denis Vlasenko2e157dd2008-07-19 09:27:19 +000026 "[][sda][0:0][644 @echo @echo TEST ]\n" \
27 "-" \
28 " sda 0:0 644 @echo @echo TEST \n"
29
Denys Vlasenko9cf89cd2017-08-05 13:45:22 +020030testing "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
Denis Vlasenko9b366f42008-07-20 17:50:58 +000058FILE=__parse
Denis Vlasenko2e157dd2008-07-19 09:27:19 +000059cat >$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]
Denis Vlasenko084266e2008-07-26 23:08:31 +000084[/dev/hdb7][/win2skul][ntfs][rw,root,noauto,nohide][none][0 0]
Denis Vlasenko2e157dd2008-07-19 09:27:19 +000085[none][/dev/pts][devpts][gid=5,mode=620][0][0]
86[none][/proc][proc][defaults][0][0]
87EOF
88
Denis Vlasenko084266e2008-07-26 23:08:31 +000089testing "parse polluted fstab" \
Denis Vlasenko2e157dd2008-07-19 09:27:19 +000090 "parse -n 6 -m 6 $FILE" \
91 "`cat $FILE.res`\n" \
92 "" \
93 ""
Denis Vlasenko9b366f42008-07-20 17:50:58 +000094cp ../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
Denis Vlasenko084266e2008-07-26 23:08:31 +0000109testing "parse inittab from examples" \
110 "parse -n 4 -m 4 -f $((NORMAL - TRIM - COLLAPSE)) -d'#:' $FILE" \
Denis Vlasenko9b366f42008-07-20 17:50:58 +0000111 "`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]
Denys Vlasenko9cf89cd2017-08-05 13:45:22 +0200127[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]
Denys Vlasenkoda947602011-06-18 09:29:21 +0200129[option][0x08][01020304]
Denis Vlasenko9b366f42008-07-20 17:50:58 +0000130EOF
131
Denis Vlasenko084266e2008-07-26 23:08:31 +0000132testing "parse udhcpd.conf from examples" \
Denis Vlasenko9b366f42008-07-20 17:50:58 +0000133 "parse -n 127 $FILE" \
134 "`cat $FILE.res`\n" \
135 "" \
136 ""
137
Denis Vlasenko2e157dd2008-07-19 09:27:19 +0000138rm -f $FILE $FILE.res
139
140exit $FAILCOUNT