1#!/bin/sh
2#
3#	aegis - project change supervisor
4#	Copyright (C) 1994-1998, 2004-2008 Peter Miller
5#
6#	This program is free software; you can redistribute it and/or modify
7#	it under the terms of the GNU General Public License as published by
8#	the Free Software Foundation; either version 3 of the License, or
9#	(at your option) any later version.
10#
11#	This program is distributed in the hope that it will be useful,
12#	but WITHOUT ANY WARRANTY; without even the implied warranty of
13#	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14#	GNU General Public License for more details.
15#
16#	You should have received a copy of the GNU General Public License
17#	along with this program. If not, see
18#	<http://www.gnu.org/licenses/>.
19#
20
21unset AEGIS_PROJECT
22unset AEGIS_CHANGE
23unset AEGIS_PATH
24unset AEGIS
25unset LINES
26unset COLS
27umask 022
28
29USER=${USER:-${LOGNAME:-`whoami`}}
30
31work=${AEGIS_TMP:-/tmp}/$$
32
33here=`pwd`
34if test $? -ne 0 ; then exit 2; fi
35
36if test "$1" != "" ; then bin="$here/$1/bin"; else bin="$here/bin"; fi
37
38if test "$EXEC_SEARCH_PATH" != ""
39then
40    tpath=
41    hold="$IFS"
42    IFS=":$IFS"
43    for tpath2 in $EXEC_SEARCH_PATH
44    do
45	tpath=${tpath}${tpath2}/${1-.}/bin:
46    done
47    IFS="$hold"
48    PATH=${tpath}${PATH}
49else
50    PATH=${bin}:${PATH}
51fi
52export PATH
53
54no_result()
55{
56	set +x
57	echo "NO RESULT for test of symlink farm functionality ($activity)" 1>&2
58	cd $here
59	find $work -type d -user $USER -exec chmod u+w {} \;
60	rm -rf $work
61	exit 2
62}
63fail()
64{
65	set +x
66	echo "FAILED test of symlink farm functionality ($activity)" 1>&2
67	cd $here
68	find $work -type d -user $USER -exec chmod u+w {} \;
69	rm -rf $work
70	exit 1
71}
72pass()
73{
74	set +x
75	echo PASSED 1>&2
76	cd $here
77	find $work -type d -user $USER -exec chmod u+w {} \;
78	rm -rf $work
79	exit 0
80}
81trap "no_result" 1 2 3 15
82
83#
84# some variable to make things earier to read
85#
86PAGER=cat
87export PAGER
88
89AEGIS_FLAGS="delete_file_preference = no_keep; \
90	lock_wait_preference = always; \
91	diff_preference = automatic_merge; \
92	pager_preference = never; \
93	persevere_preference = all; \
94	log_file_preference = never;"
95export AEGIS_FLAGS
96AEGIS_THROTTLE=-1
97export AEGIS_THROTTLE
98
99worklib=$work/lib
100workproj=$work/foo.proj
101workchan=$work/foo.chan
102tmp=$work/tmp
103AEGIS_PATH=$worklib ; export AEGIS_PATH
104AEGIS_PROJECT=foo ; export AEGIS_PROJECT
105
106#
107# make the directories
108#
109activity="working directory 96"
110mkdir $work $work/lib
111if test $? -ne 0 ; then no_result; fi
112chmod 777 $work/lib
113if test $? -ne 0 ; then no_result; fi
114cd $work
115if test $? -ne 0 ; then no_result; fi
116
117#
118# If the C++ compiler is called something other than "c++", as
119# discovered by the configure script, create a shell script called
120# "c++" which invokes the correct C++ compiler.  Make sure the current
121# directory is in the path, so that it will be invoked.
122#
123if test "$CXX" != "c++"
124then
125	cat >> $work/c++ << fubar
126#!/bin/sh
127exec ${CXX-g++} \$*
128fubar
129	if test $? -ne 0 ; then no_result; fi
130	chmod a+rx $work/c++
131	if test $? -ne 0 ; then no_result; fi
132	PATH=${work}:${PATH}
133	export PATH
134fi
135
136#
137# program to ask questions about symlinks
138#
139cat > symlink.cc << 'fubar'
140#include <sys/types.h>
141#include <sys/stat.h>
142int
143main(int argc, char **argv)
144{
145#ifdef S_IFLNK
146	if (argc == 2)
147	{
148		struct stat st;
149		if (lstat(argv[1], &st))
150			return 0;
151		/* fails if file exists */
152		return 1;
153	}
154	return 0;
155#else
156	return 2;
157#endif
158}
159fubar
160if test $? -ne 0 ; then no_result; fi
161c++ -o symlink symlink.cc
162if test $? -ne 0 ; then no_result; fi
163
164#
165# if this system has no symlinks
166# automagically pass the test
167#
168./symlink
169if test $? -ge 2
170then
171	echo ""
172	echo ""
173	echo "	This system does not have symbolic links"
174	echo "	so this test automagically passes."
175	echo ""
176	echo ""
177	pass
178fi
179
180#
181# use the built-in error messages
182#
183AEGIS_MESSAGE_LIBRARY=$work/no-such-dir
184export AEGIS_MESSAGE_LIBRARY
185unset LANG
186unset LANGUAGE
187
188#
189# make a new project
190#	and check files it should have made
191#
192activity="new project 179"
193$bin/aegis -npr foo -vers "" -dir $workproj > log 2>&1
194if test $? -ne 0 ; then cat log; no_result; fi
195
196#
197# change project attributes
198#
199activity="project attributes 186"
200cat > $tmp << 'end'
201description = "A bogus project created to test the symlink farm functionality.";
202developer_may_review = true;
203developer_may_integrate = true;
204reviewer_may_integrate = true;
205end
206if test $? -ne 0 ; then no_result; fi
207$bin/aegis -pa -f $tmp > log 2>&1
208if test $? -ne 0 ; then cat log; no_result; fi
209
210#
211# create a new change
212#	make sure it creates the files it should
213#
214activity="new change 201"
215cat > $tmp << 'end'
216brief_description = "The first change";
217cause = internal_bug;
218end
219if test $? -ne 0 ; then no_result; fi
220$bin/aegis -nc 1 -f $tmp -p foo > log 2>&1
221if test $? -ne 0 ; then cat log; no_result; fi
222
223#
224# create a second change
225#
226activity="new change 213"
227cat > $tmp << 'end'
228brief_description = "The second change";
229cause = internal_bug;
230end
231if test $? -ne 0 ; then no_result; fi
232$bin/aegis -nc 2 -f $tmp -p foo > log 2>&1
233if test $? -ne 0 ; then cat log; no_result; fi
234
235#
236# add the staff
237#
238activity="staff 225"
239$bin/aegis -nd $USER > log 2>&1
240if test $? -ne 0 ; then cat log; no_result; fi
241$bin/aegis -nrv $USER > log 2>&1
242if test $? -ne 0 ; then cat log; no_result; fi
243$bin/aegis -ni $USER > log 2>&1
244if test $? -ne 0 ; then cat log; no_result; fi
245
246#
247# begin development of a change
248#
249$bin/aegis -db 1 -dir $workchan > log 2>&1
250if test $? -ne 0 ; then cat log; no_result; fi
251
252#
253# add a new files to the change
254#
255activity="new file 242"
256$bin/aegis -nf $workchan/main.cc $workchan/test.cc $workchan/Makefile \
257	$workchan/aegis.conf -nl > log 2>&1
258if test $? -ne 0 ; then cat log; no_result; fi
259cat > $workchan/main.cc << 'end'
260extern void test();
261
262int
263main(int argc, char **argv)
264{
265	test();
266	return 0;
267}
268end
269if test $? -ne 0 ; then no_result; fi
270cat > $workchan/test.cc << 'end'
271void
272test()
273{
274}
275end
276if test $? -ne 0 ; then no_result; fi
277cat > $workchan/Makefile << 'end'
278# SGImake doesn't have .cc in its default suffix list
279.SUFFIXES: .cc
280
281.cc.o:
282	rm -f $*.o
283	c++ $(CFLAGS) -D'VERSION="$(VERSION)"' -c $*.cc
284
285foo: main.o test.o
286	rm -f foo
287	c++ -o foo main.o test.o
288end
289if test $? -ne 0 ; then no_result; fi
290cat > $workchan/aegis.conf << 'end'
291// The sleep is necessary, because the files could all have time stamps
292// within the same second on fast machines.
293build_command = "sleep 1; test -r foo && rm foo; make VERSION=$version";
294link_integration_directory = true;
295development_directory_style =
296{
297    source_file_symlink = true;
298};
299
300history_get_command = "aesvt -check-out -edit ${quote $edit} "
301    "-history ${quote $history} -f ${quote $output}";
302history_put_command = "aesvt -check-in -history ${quote $history} "
303    "-f ${quote $input}";
304history_query_command = "aesvt -query -history ${quote $history}";
305history_content_limitation = binary_capable;
306
307diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
308diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
309	echo '1,$$p' ) | ed - $mr > $out";
310end
311if test $? -ne 0 ; then no_result; fi
312
313#
314# create a new test
315#
316activity="new test 298"
317$bin/aegis -nt > log 2>&1
318if test $? -ne 0 ; then cat log; no_result; fi
319cat > $workchan/test/00/t0001a.sh << 'end'
320#!/bin/sh
321
322no_result()
323{
324	echo WHIMPER 1>&2
325	exit 2
326}
327fail()
328{
329	echo SHUZBUTT 1>&2
330	exit 1
331}
332pass()
333{
334	exit 0
335}
336trap "no_result" 1 2 3 15
337
338./foo
339if test $? -ne 0 ; then fail ; fi
340
341# it probably worked
342pass
343end
344if test $? -ne 0 ; then no_result; fi
345
346#
347# build the change
348#
349# This will try to do symlink stuff.
350#
351activity="build 333"
352$bin/aegis -build -nl -v > log 2>&1
353if test $? -ne 0 ; then cat log; fail; fi
354
355#
356# difference the change
357#
358activity="diff 340"
359$bin/aegis -diff > log 2>&1
360if test $? -ne 0 ; then cat log; no_result; fi
361
362#
363# test the change
364#
365activity="test 347"
366$bin/aegis -t -v > log 2>&1
367if test $? -ne 0 ; then cat log; no_result; fi
368
369#
370# finish development of the change
371#
372#	It must ignore the symlinks when it chmod's
373#
374activity="develop end 356"
375$bin/aegis -de > log 2>&1
376if test $? -ne 0 ; then cat log; fail; fi
377
378#
379# pass the review
380#
381activity="review pass 363"
382$bin/aegis -rpass -c 1 > log 2>&1
383if test $? -ne 0 ; then cat log; no_result; fi
384
385#
386# start integrating
387#
388activity="integrate begin 370"
389$bin/aegis -ib 1 > log 2>&1
390if test $? -ne 0 ; then cat log; no_result; fi
391
392#
393# integrate build and test
394#
395activity="build 377"
396$bin/aegis -b -nl -v > log 2>&1
397if test $? -ne 0 ; then cat log; no_result; fi
398activity="test 380"
399$bin/aegis -t -nl -v > log 2>&1
400if test $? -ne 0 ; then cat log; no_result; fi
401
402#
403# pass the integration
404#
405activity="integrate pass 387"
406$bin/aegis -intpass -nl > log 2>&1
407if test $? -ne 0 ; then cat log; no_result; fi
408
409#
410# start work on change 2
411#
412#	It will create symlinks into the baseline
413#
414workchan=$work/chan2.dir
415activity="develop begin 396"
416$bin/aegis -db -c 2 -dir $workchan > log 2>&1
417if test $? -ne 0 ; then cat log; fail; fi
418
419#
420# copy a file into the change
421#
422#	It will have to remove the symlink before copying
423#
424activity="copy file 405"
425$bin/aegis -cp $workchan/main.cc -nl > log 2>&1
426if test $? -ne 0 ; then cat log; fail; fi
427
428#
429# change the file
430#
431cat > $workchan/main.cc << 'end'
432#include <stdio.h>
433extern void test();
434
435int
436main(int argc, char **argv)
437{
438	if (argc != 1)
439	{
440		fprintf(stderr, "usage: %s\n", argv[0]);
441		return 1;
442	}
443	test();
444	return 0;
445}
446end
447if test $? -ne 0 ; then no_result; fi
448
449#
450# need another test
451#
452activity="new test 433"
453$bin/aegis -nt > log 2>&1
454if test $? -ne 0 ; then cat log; no_result; fi
455cat > $workchan/test/00/t0002a.sh << 'end'
456#!/bin/sh
457
458no_result()
459{
460	echo WHIMPER 1>&2
461	exit 2
462}
463fail()
464{
465	echo SHUZBUTT 1>&2
466	exit 1
467}
468pass()
469{
470	exit 0
471}
472trap "no_result" 1 2 3 15
473
474./foo > /dev/null 2>&1
475test $? -eq 0 || fail
476
477./foo ickky
478if test $? -ne 1 ; then fail ; fi
479
480# it probably worked
481pass
482end
483if test $? -ne 0 ; then no_result; fi
484
485#
486# build the change - will double check symlinks
487#	and the make will fail if the symlinks are not there
488# diff the change
489# test the change
490#
491activity="build 472"
492$bin/aegis -b -nl -v > log 2>&1
493if test $? -ne 0 ; then cat log; fail; fi
494activity="diff 475"
495$bin/aegis -diff -nl > log 2>&1
496if test $? -ne 0 ; then cat log; no_result; fi
497activity="test 478"
498$bin/aegis -t -nl -v > log 2>&1
499if test $? -ne 0 ; then cat log; no_result; fi
500activity="test baseline 481"
501$bin/aegis -t -bl -nl -v > log 2>&1
502if test $? -ne 0 ; then cat log; no_result; fi
503
504#
505# end development
506# review pass
507# start integrating
508#
509activity="develop end 490"
510$bin/aegis -de > log 2>&1
511if test $? -ne 0 ; then cat log; no_result; fi
512activity="review pass 493"
513$bin/aegis -revpass -c 2 > log 2>&1
514if test $? -ne 0 ; then cat log; no_result; fi
515activity="integrate begin 496"
516$bin/aegis -intbeg -c 2 > log 2>&1
517if test $? -ne 0 ; then cat log; no_result; fi
518
519#
520# build the integration
521# test the integration
522# test the integration against the baseline
523#
524activity="build 505"
525$bin/aegis -b -nl -v > log 2>&1
526if test $? -ne 0 ; then cat log; no_result; fi
527activity="test 508"
528$bin/aegis -t -nl -v > log 2>&1
529if test $? -ne 0 ; then cat log; no_result; fi
530activity="test baseline 511"
531$bin/aegis -t -bl -nl -v > log 2>&1
532if test $? -ne 0 ; then cat log; no_result; fi
533
534#
535# pass the integration
536#
537activity="integrate pass 518"
538$bin/aegis -intpass -nl > log 2>&1
539if test $? -ne 0 ; then cat log; no_result; fi
540
541# should be no automatic logging
542if test "`find $work -name 'aegis.log' -print`" != "" ; then no_result; fi
543
544#
545# the things tested in this test, worked
546#
547pass
548