#!/bin/sh

# Regression test for archk

# Copyright (C) 2005 The Free Standards Group
# Mats Wichmann <mats@freestandards.org>

# Try executing archk with no arguments
# We expect it to return with error code 1
printf "Running archk with no arguments. Expect an error... "
./archk > /dev/null 2>&1
if [ $? -ne 1 ]; then
	echo "archk did not fail when called without arguments"
	exit 1
else
	echo "OK"
fi

# Try running archk on a ../elfchk/libelfchk.a plus ../tetj/libtetj.a
# This had to be built in order to build archk
# Probably not compliant, but we're looking for "does it work at all"
PROG=../elfchk/libelfchk.a
EXTRA=../tetj/libtetj.a
printf "Running archk on $PROG..."
JOURNAL_FILE=journal.archk.`basename $PROG`
rm -f $JOURNAL_FILE
./archk $PROG -L  $EXTRA > /dev/null 2>&1
if [ $? -ne 0 ]; then
	echo "Failed to run archk on $PROG"
	exit 1
else
	# Check that the journal file is complete (it has an end marker)
	LAST_CODE=`tail -1 $JOURNAL_FILE | cut -f1 -d'|'`
	if [ "$LAST_CODE" -ne "900" ]; then
		echo Journal file is incomplete
		exit 1
	else
		rm -f $JOURNAL_FILE
		echo OK
	fi
fi

echo 
echo All tests succeeded
exit 0
