Friday, November 26, 2010

SBR600 project 0.2 (man page checker)e

The test I'm trying to implement extracts the man pages from the package uploaded in the koji-build system and see the SEE ALSO section of the man pages to check if any invalid links are contained.
The following script is to get a list of man-pages from RPMs uploaded in the koji-build system

#!/bin/bash
# parameter - directory with rpm
# ouptput - list of its man-pages
rpm_path=$1

for rpm in `ls $rpm_path`; do
if [[ $rpm == *.rpm ]]
then
rpm -qlp $rpm_path/$rpm 2>/dev/null| grep "^/usr/share/man/man.*"
fi
done


After getting a list of man pages, the following script test the man pages extracted

#!/bin/bash
# first parametr - srpm
# second parametr - man-pages list
# output - false SEE ALSO links

rpm=$1
list=$2
#set -x

mkdir ./tmp
cd ./tmp
rpm2cpio ../$1 >tmp.cpio
cpio -i -d --force-local /dev/null

if [ -d ./usr/share/man/ ]; then

for i in `ls ./usr/share/man/man[0-9]*/*`; do
# find the start of SEE ALSO section
if [ `zcat $i | grep -n "SEE ALSO" | grep ".SH" | wc -l` -ne 0 ]; then
# begin of this section
min=`zcat $i | grep -n "SEE ALSO" | grep ".SH" | sed "s|:.*||" | head -n1`
max=`zcat $i | wc -l`

let "suf=$max-$min"
if [ $suf -ne 0 ]; then
# end of SEE ALSO section
end=`zcat $i >/dev/null| tail -n$suf | grep -n ".SH" | head -n1 | sed "s|:.*||"`
if [ "x" = "x$d" ]; then
# there is next section after SEE ALSO
# SEE ALSO is the last section
end=`zcat $i |wc -l`
else
# SEE ALSO is the last section
let end="$end-1"
fi

fil1=`zcat $i | tail -n$suf | head -n$end | grep "^.BR" | sed "s|.BR \([^ ]*\) (\([1-9][^ ]*\)).*|/usr/share/man/man\2/\1.\2.|g" | grep -v BR`
for jj in `echo $fil1`; do
j=`echo $jj | sed 's|\\\-|-|g'`
grep "$j" ../$2 >/dev/null;
if [ $? -ne 0 ]; then
j2=`echo $j | sed "s|/usr/share/man/man\(.*\)/\([^.]*\).*|/usr/share/man/man.*/\2.[0-9]|"`
pom=`grep "$j2" ../$2`
if [ `echo $pom | wc -l` -ne 0 ]; then
printf " BUG - package: %20s, man-page: %30s, link %20s\n" $1 $i $j
fi
else
printf " OK - package: %20s, man-page: %30s, link %20s\n" $1 $i $j
fi
done
fi
fi
done
fi



1. Install and configure AutoQA # Some useful imports
import autoqa.util
from autoqa.test import AutoQATest
from autoqa.decorators import ExceptionCatcher
from autotest_lib.client.bin import utils

# Your class name must match file name (without .py) and also run_test line in
# its control file.
class (AutoQATest): # <-- UPDATE Classname version = 1 # increment this if setup() changes # During the execution fill these variables: # self.result: test result keyword # self.summary: one line test result summary # self.outputs: full test output (string or list of strings) # self.highlights: important lines to notice (string or list of strings) @ExceptionCatcher("self.run_once_failed") def run_once(self, some_params, **kwargs): #**kwargs needs to stay cmd = 'test_binary --param %s' % some_params self.outputs = utils.system_output(cmd, retain_output=True) self.result = "PASSED" #FAILED, INFO, ABORTED, ... self.summary = "This test was awesome!" self.highlights = "Note these important lines, if you miss them,\n" self.highlights += "you'll regret it forever.
  • Get the source code using GIT : git clone git://git.fedorahosted.org/autoqa.git autoqa : #This command downloads the source code us
  • For Fedora, execute the command: wget -P /etc/yum.repos.d http://repos.fedorapeople.org/repos/fedora-qa/autoqa/fedora-autoqa.repo
  • Yum repository for AutoQA server has been set up. Use yum to download it : yum install autoqa
  • Now on the server, event watchers, which triggers corresponding autoqa tests when events occur, are needed to run periodically. :
    cp /usr/share/autoqa/autoqa.cron /etc/cron.d/
2. Setting for the new test.

There's four parts to a test: the test code, the test object, the Autotest control file, and the AutoQA control file. all live in a single directory, located in the tests directory of the autoqa source directory. From the autoqa/doc directory, copy template files, autoqa.template, autoqa.control.template, and test_class.py to the directory /tests/man_page_checker/ and rename them autoqa, autoqa.control, and man_page_checker.py respectively. After that, put the man_page_checker source code in it.

* control file for man_page_checker
AUTHOR = "Jaewoo Park "
TIME="SHORT"
NAME = 'man_page_checker' #name of the test
DOC = """
This test checks validity in man pages
"""
TEST_TYPE = 'CLIENT'
TEST_CLASS = 'General'
TEST_CATEGORY = 'Functional'
job.run_test('man_page_checker', config=autoqa_conf, **autoqa_args)
# should use the name of test for the first value


* control.autoqa file

# this test can be run just once and on any architecture
archs = ['noarch']

# we want to run this test just for post-koji-build hook
if hook not in ['post-koji-build']:
execute = False


* man_page_checker.py file

# Some useful imports
import autoqa.util
from autoqa.test import AutoQATest
from autoqa.decorators import ExceptionCatcher
from autotest_lib.client.bin import utils

# Your class name must match file name (without .py) and also run_test line in
# its control file.
class (AutoQATest): # <-- UPDATE Classname
version = 1 # increment this if setup() changes

# During the execution fill these variables:
# self.result: test result keyword
# self.summary: one line test result summary
# self.outputs: full test output (string or list of strings)
# self.highlights: important lines to notice (string or list of strings)
@ExceptionCatcher("self.run_once_failed")
def run_once(self, some_params, **kwargs): #**kwargs needs to stay
cmd = 'test_binary --param %s' % some_params
self.outputs = utils.system_output(cmd, retain_output=True)
self.result = "PASSED" #FAILED, INFO, ABORTED, ...
self.summary = "This test was awesome!"
self.highlights = "Note these important lines, if you miss them,\n"
self.highlights += "you'll regret it forever.
"


No comments:

Post a Comment