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(void);
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(void)
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'
291build_command = "make VERSION=$version";
292link_integration_directory = true;
293create_symlinks_before_build = true;
294
295history_get_command = "aesvt -check-out -edit ${quote $edit} "
296    "-history ${quote $history} -f ${quote $output}";
297history_put_command = "aesvt -check-in -history ${quote $history} "
298    "-f ${quote $input}";
299history_query_command = "aesvt -query -history ${quote $history}";
300history_content_limitation = binary_capable;
301
302diff_command = "set +e; diff $orig $i > $out; test $$? -le 1";
303diff3_command = "(diff3 -e $mr $orig $i | sed -e '/^w$$/d' -e '/^q$$/d'; \
304	echo '1,$$p' ) | ed - $mr > $out";
305end
306if test $? -ne 0 ; then no_result; fi
307
308#
309# create a new test
310#
311activity="new test 298"
312$bin/aegis -nt > log 2>&1
313if test $? -ne 0 ; then cat log; no_result; fi
314cat > $workchan/test/00/t0001a.sh << 'end'
315#!/bin/sh
316
317no_result()
318{
319	echo WHIMPER 1>&2
320	exit 2
321}
322fail()
323{
324	echo SHUZBUTT 1>&2
325	exit 1
326}
327pass()
328{
329	exit 0
330}
331trap "no_result" 1 2 3 15
332
333./foo
334if test $? -ne 0 ; then fail ; fi
335
336# it probably worked
337pass
338end
339if test $? -ne 0 ; then no_result; fi
340
341#
342# build the change
343#
344# This will try to do symlink stuff.
345#
346activity="build 333"
347$bin/aegis -build -nl -v > log 2>&1
348if test $? -ne 0 ; then cat log; fail; fi
349
350#
351# difference the change
352#
353activity="diff 340"
354$bin/aegis -diff > log 2>&1
355if test $? -ne 0 ; then cat log; no_result; fi
356
357#
358# test the change
359#
360activity="test 347"
361$bin/aegis -t -v > log 2>&1
362if test $? -ne 0 ; then cat log; no_result; fi
363
364#
365# finish development of the change
366#
367#	It must ignore the symlinks when it chmod's
368#
369activity="develop end 356"
370$bin/aegis -de > log 2>&1
371if test $? -ne 0 ; then cat log; fail; fi
372
373#
374# pass the review
375#
376activity="review pass 363"
377$bin/aegis -rpass -c 1 > log 2>&1
378if test $? -ne 0 ; then cat log; no_result; fi
379
380#
381# start integrating
382#
383activity="integrate begin 370"
384$bin/aegis -ib 1 > log 2>&1
385if test $? -ne 0 ; then cat log; no_result; fi
386
387#
388# integrate build and test
389#
390activity="build 377"
391$bin/aegis -b -nl -v > log 2>&1
392if test $? -ne 0 ; then cat log; no_result; fi
393activity="test 380"
394$bin/aegis -t -nl -v > log 2>&1
395if test $? -ne 0 ; then cat log; no_result; fi
396
397#
398# pass the integration
399#
400activity="integrate pass 387"
401$bin/aegis -intpass -nl > log 2>&1
402if test $? -ne 0 ; then cat log; no_result; fi
403
404#
405# start work on change 2
406#
407#	It will create symlinks into the baseline
408#
409activity="develop begin 396"
410$bin/aegis -db -c 2 -dir $workchan > log 2>&1
411if test $? -ne 0 ; then cat log; fail; fi
412
413#
414# copy a file into the change
415#
416#	It will have to remove the symlink before copying
417#
418activity="copy file 405"
419$bin/aegis -cp $workchan/main.cc -nl > log 2>&1
420if test $? -ne 0 ; then cat log; fail; fi
421
422#
423# change the file
424#
425cat > $workchan/main.cc << 'end'
426#include <stdio.h>
427extern void test(void);
428
429int
430main(int argc, char **argv)
431{
432	if (argc != 1)
433	{
434		fprintf(stderr, "usage: %s\n", argv[0]);
435		return 1;
436	}
437	test();
438	return 0;
439}
440end
441if test $? -ne 0 ; then no_result; fi
442
443#
444# need another test
445#
446activity="new test 433"
447$bin/aegis -nt > log 2>&1
448if test $? -ne 0 ; then cat log; no_result; fi
449cat > $workchan/test/00/t0002a.sh << 'end'
450#!/bin/sh
451
452no_result()
453{
454	echo WHIMPER 1>&2
455	exit 2
456}
457fail()
458{
459	echo SHUZBUTT 1>&2
460	exit 1
461}
462pass()
463{
464	exit 0
465}
466trap "no_result" 1 2 3 15
467
468./foo > /dev/null 2>&1
469test $? -eq 0 || fail
470
471./foo ickky
472if test $? -ne 1 ; then fail ; fi
473
474# it probably worked
475pass
476end
477if test $? -ne 0 ; then no_result; fi
478
479#
480# build the change - will double check symlinks
481#	and the make will fail if the symlinks are not there
482# diff the change
483# test the change
484#
485activity="build 472"
486$bin/aegis -b -nl -v -minimum > log 2>&1
487if test $? -ne 0 ; then cat log; fail; fi
488activity="diff 475"
489$bin/aegis -diff -nl > log 2>&1
490if test $? -ne 0 ; then cat log; no_result; fi
491activity="test 478"
492$bin/aegis -t -nl -v > log 2>&1
493if test $? -ne 0 ; then cat log; no_result; fi
494activity="test baseline 481"
495$bin/aegis -t -bl -nl -v > log 2>&1
496if test $? -ne 0 ; then cat log; no_result; fi
497
498#
499# end development
500# review pass
501# start integrating
502#
503activity="develop end 490"
504$bin/aegis -de > log 2>&1
505if test $? -ne 0 ; then cat log; no_result; fi
506activity="review pass 493"
507$bin/aegis -revpass -c 2 > log 2>&1
508if test $? -ne 0 ; then cat log; no_result; fi
509activity="integrate begin 496"
510$bin/aegis -intbeg -c 2 > log 2>&1
511if test $? -ne 0 ; then cat log; no_result; fi
512
513#
514# build the integration
515# test the integration
516# test the integration against the baseline
517#
518activity="build 505"
519$bin/aegis -b -nl -v > log 2>&1
520if test $? -ne 0 ; then cat log; no_result; fi
521activity="test 508"
522$bin/aegis -t -nl -v > log 2>&1
523if test $? -ne 0 ; then cat log; no_result; fi
524activity="test baseline 511"
525$bin/aegis -t -bl -nl -v > log 2>&1
526if test $? -ne 0 ; then cat log; no_result; fi
527
528#
529# pass the integration
530#
531activity="integrate pass 518"
532$bin/aegis -intpass -nl > log 2>&1
533if test $? -ne 0 ; then cat log; no_result; fi
534
535# should be no automatic logging
536if test "`find $work -name 'aegis.log' -print`" != "" ; then no_result; fi
537
538#
539# the things tested in this test, worked
540#
541pass
542