xref: /freebsd/tools/tools/build_option_survey/option_survey.sh (revision 0b3105a37d7adcadcb720112fed4dc4e8040be99)
1#!/bin/sh
2# This file is in the public domain
3# $FreeBSD$
4
5set -ex
6
7OPLIST=`sh listallopts.sh`
8
9MDUNIT=47
10export MDUNIT
11
12ODIR=/usr/obj/`pwd`
13FDIR=${ODIR}/files
14MNT=${ODIR}/_.mnt
15RDIR=${ODIR}/_.result
16
17export ODIR MNT RDIR FDIR
18
19bw ( ) (
20	cd ../../..
21	make showconfig \
22		SRCCONF=${ODIR}/src.conf __MAKE_CONF=/dev/null \
23		> ${FDIR}/_.sc 2>&1
24	a=$?
25	echo retval $a
26	if [ $a -ne 0 ] ; then
27		exit 1
28	fi
29	make -j 4 buildworld \
30		SRCCONF=${ODIR}/src.conf __MAKE_CONF=/dev/null \
31		> ${FDIR}/_.bw 2>&1
32	a=$?
33	echo retval $a
34	if [ $a -ne 0 ] ; then
35		exit 1
36	fi
37	make -j 4 buildkernel \
38		KERNCONF=GENERIC \
39		SRCCONF=${ODIR}/src.conf __MAKE_CONF=/dev/null \
40		> ${FDIR}/_.bk 2>&1
41	a=$?
42	echo retval $a
43	if [ $a -ne 0 ] ; then
44		exit 1
45	fi
46	exit 0
47)
48
49iw ( ) (
50	trap "umount ${MNT} || true" 1 2 15 EXIT
51	newfs -O1 -U -b 4096 -f 512 /dev/md$MDUNIT
52	mkdir -p ${MNT}
53	mount /dev/md${MDUNIT} ${MNT}
54
55	cd ../../..
56	make installworld \
57		SRCCONF=${ODIR}/src.conf __MAKE_CONF=/dev/null \
58		DESTDIR=${MNT} \
59		> ${FDIR}/_.iw 2>&1
60	a=$?
61	echo retval $a
62	if [ $a -ne 0 ] ; then
63		exit 1
64	fi
65	cd etc
66	make distribution \
67		SRCCONF=${ODIR}/src.conf __MAKE_CONF=/dev/null \
68		DESTDIR=${MNT} \
69		> ${FDIR}/_.etc 2>&1
70	a=$?
71	echo retval $a
72	if [ $a -ne 0 ] ; then
73		exit 1
74	fi
75	cd ..
76	make installkernel \
77		KERNCONF=GENERIC \
78		DESTDIR=${MNT} \
79		SRCCONF=${ODIR}/src.conf __MAKE_CONF=/dev/null \
80		> ${FDIR}/_.ik 2>&1
81	a=$?
82	echo retval $a
83	if [ $a -ne 0 ] ; then
84		exit 1
85	fi
86
87	sync ${MNT}
88	( cd ${MNT} && mtree -c ) > ${FDIR}/_.mtree
89	( cd ${MNT} && du ) > ${FDIR}/_.du
90	( df -i ${MNT} ) > ${FDIR}/_.df
91	echo success > ${FDIR}/_.success
92	sync
93	sleep 1
94	sync
95	sleep 1
96	trap "" 1 2 15 EXIT
97	umount ${MNT}
98	echo "iw done"
99)
100
101
102# Clean and recreate the ODIR
103
104if true ; then
105	echo "=== Clean and recreate ${ODIR}"
106	if rm -rf ${ODIR} ; then
107		true
108	else
109		chflags -R noschg ${ODIR}
110		rm -rf ${ODIR}
111	fi
112	mkdir -p ${ODIR} ${FDIR} ${MNT}
113
114fi
115
116trap "umount ${MNT} || true; mdconfig -d -u $MDUNIT" 1 2 15 EXIT
117
118umount $MNT || true
119mdconfig -d -u $MDUNIT || true
120dd if=/dev/zero of=${ODIR}/imgfile bs=1m count=250
121mdconfig -a -t vnode -f ${ODIR}/imgfile -u $MDUNIT
122
123# Build & install the reference world
124
125if true ; then
126	echo "=== Build reference world"
127	echo '' > ${ODIR}/src.conf
128	MAKEOBJDIRPREFIX=$ODIR/_.ref
129	export MAKEOBJDIRPREFIX
130	bw
131	echo "=== Install reference world"
132	mkdir -p ${RDIR}/Ref
133	iw
134	mv ${FDIR}/_.* ${RDIR}/Ref
135fi
136
137# Parse option list into subdirectories with src.conf files.
138
139if true ; then
140	rm -rf ${RDIR}/[0-9a-f]*
141	for o in $OPLIST
142	do
143		echo "${o}=foo" > ${FDIR}/_src.conf
144		m=`md5 < ${FDIR}/_src.conf`
145		mkdir -p ${RDIR}/$m
146		mv ${FDIR}/_src.conf ${RDIR}/$m/src.conf
147	done
148fi
149
150# Run through each testtarget in turn
151
152if true ; then
153	for d in ${RDIR}/[0-9a-z]*
154	do
155		if [ ! -d $d ] ; then
156			continue;
157		fi
158		echo '------------------------------------------------'
159		cat $d/src.conf
160		echo '------------------------------------------------'
161		cp $d/src.conf ${ODIR}/src.conf
162
163		if [ ! -f $d/iw/done ] ; then
164			MAKEOBJDIRPREFIX=$ODIR/_.ref
165			export MAKEOBJDIRPREFIX
166			echo "# BW(ref)+IW(ref) `cat $d/src.conf`"
167			rm -rf $d/iw
168			mkdir -p $d/iw
169			iw || true
170			mv ${FDIR}/_.* $d/iw || true
171			touch $d/iw/done
172		fi
173		if [ ! -f $d/bw/done ] ; then
174			MAKEOBJDIRPREFIX=$ODIR/_.tst
175			export MAKEOBJDIRPREFIX
176			echo "# BW(opt) `cat $d/src.conf`"
177			rm -rf $d/w $d/bw
178			mkdir -p $d/w $d/bw
179			if bw ; then
180				mv ${FDIR}/_.* $d/bw || true
181
182				echo "# BW(opt)+IW(opt) `cat $d/src.conf`"
183				iw || true
184				mv ${FDIR}/_.* $d/w || true
185				touch $d/w/done
186
187				echo "# BW(opt)+IW(ref) `cat $d/src.conf`"
188				echo '' > ${ODIR}/src.conf
189				iw || true
190				mv ${FDIR}/_.* $d/bw || true
191				touch $d/bw/done
192			else
193				mv ${FDIR}/_.* $d/bw || true
194				touch $d/bw/done $d/w/done
195			fi
196		fi
197	done
198fi
199