Blame contrib/mysql/importxml.sh

Packit 62fe53
#!/bin/bash
Packit 62fe53
Packit 62fe53
# importxml.sh -- import a .sum file into MySQL.
Packit 62fe53
#
Packit 62fe53
# Copyright (C) 2016 Free Software Foundation, Inc.
Packit 62fe53
#
Packit 62fe53
# This file is part of DejaGnu.
Packit 62fe53
#
Packit 62fe53
# DejaGnu is free software; you can redistribute it and/or modify it
Packit 62fe53
# under the terms of the GNU General Public License as published by
Packit 62fe53
# the Free Software Foundation; either version 3 of the License, or
Packit 62fe53
# (at your option) any later version.
Packit 62fe53
Packit 62fe53
# This script takes a compressed or uncompressed sum file from a
Packit 62fe53
# DejaGnu test run. It then extracts the relevant information about
Packit 62fe53
# the build and writes that to the dejagnu.testruns control
Packit 62fe53
# table. After that it converts the sum file to XML, and imports it
Packit 62fe53
# into an SQL database, in this case MySQL.
Packit 62fe53
Packit 62fe53
if test x"$1" = x; then
Packit 62fe53
  infile="/tmp/testrun.xml"
Packit 62fe53
  outfile="/tmp/testrun.xml"
Packit 62fe53
else
Packit 62fe53
  infile=$1
Packit 62fe53
  outfile=${1//\.sum.*/.xml}
Packit 62fe53
fi
Packit 62fe53
Packit 62fe53
if test ! -e "$infile"; then
Packit 62fe53
  echo "ERROR: no input file specified!"
Packit 62fe53
  exit
Packit 62fe53
fi
Packit 62fe53
Packit 62fe53
# These are required to access the database
Packit 62fe53
user="USER"
Packit 62fe53
passwd="PASSWD"
Packit 62fe53
Packit 62fe53
# Check the environment for the database access information
Packit 62fe53
if test x"${CBUILD_DBUSER}" != x; then
Packit 62fe53
    user="${CBUILD_DBUSER}"
Packit 62fe53
fi
Packit 62fe53
if test x"${CBUILD_DBPASSWD}" != x; then
Packit 62fe53
    passwd="${CBUILD_DBPASSWD}"
Packit 62fe53
fi
Packit 62fe53
Packit 62fe53
total=$(mysql -u"$user" -p"$passwd" -e "SELECT testrun from testruns ORDER BY testrun DESC LIMIT 1" dejagnu | tail -1)
Packit 62fe53
total=$((total + 1))
Packit 62fe53
Packit 62fe53
type=$(file "$infile")
Packit 62fe53
Packit 62fe53
build_machine=$(dirname "$infile" | cut -d '-' -f 8)
Packit 62fe53
Packit 62fe53
# If compressed, uncompress it
Packit 62fe53
count=$(echo "$type" | grep -c "XZ compressed data")
Packit 62fe53
if test "$count" -gt 0; then
Packit 62fe53
  catprog="xzcat"
Packit 62fe53
  uncomp="xz -d"
Packit 62fe53
else
Packit 62fe53
  count=$(echo "$type" | grep -c "XZ compressed data")
Packit 62fe53
  if test "$count" -gt 0; then
Packit 62fe53
    catprog="gzcat"
Packit 62fe53
    uncomp="gnzip"
Packit 62fe53
  else
Packit 62fe53
    catprog="cat"
Packit 62fe53
    uncomp=""
Packit 62fe53
  fi
Packit 62fe53
fi
Packit 62fe53
Packit 62fe53
# extract the build info from the sum file.
Packit 62fe53
# This goes in the dejagnu.testruns table
Packit 62fe53
tool=$(${catprog} "$infile" | grep "tests ===" | cut -d ' ' -f 2)
Packit 62fe53
target=$(${catprog} "$infile" | head -20 | grep "configuration is " | cut -d ' ' -f 4)
Packit 62fe53
version=$(${catprog} "$infile" | head -20 | grep "Running /" | cut -d '/' -f 7 | sed -e 's:^[a-z-]*-::' -e 's:_:.:' -e 's:-branch::' | tail -1)
Packit 62fe53
date=$(${catprog} "$infile" | head -1 | sed -e 's:Test Run By [a-zA-Z]* on ::')
Packit 62fe53
date=$(date -d "${date}" "+%Y-%m-%d %H:%M:%S")
Packit 62fe53
Packit 62fe53
echo "Adding to DB: $target, $version, $date, $tool"
Packit 62fe53
Packit 62fe53
# Add an entry in the testrun table for this sum file
Packit 62fe53
Packit 62fe53
echo "Adding the test run into the testruns control table."
Packit 62fe53
mysql -u"$user" -p"$passwd" --local -e "INSERT INTO dejagnu.testruns VALUES('${tool}','${date}','${version}','svn','${total}','${target}','${build_machine}');" dejagnu
Packit 62fe53
Packit 62fe53
# Make the temp file copy
Packit 62fe53
if test x"${uncomp}" != x; then
Packit 62fe53
  rm -f tmp.sum
Packit 62fe53
  ${catprog} "$infile" > tmp.sum
Packit 62fe53
fi
Packit 62fe53
Packit 62fe53
# convert the sum file to an xml file so it can be imported
Packit 62fe53
echo "Converting the sum file to XML for importing into MySQL."
Packit 62fe53
bash "$(dirname "$0")/sum2xml.sh" "$infile"
Packit 62fe53
Packit 62fe53
# import the the xml file into MySQL. Note that we add the testrun index which is
Packit 62fe53
# retreived from the database earlier in this script.
Packit 62fe53
echo "Adding the sum file into the testruns control file."
Packit 62fe53
mysql -u"$user" -p"$passwd" --local -e "LOAD XML LOCAL INFILE '${outfile}' INTO TABLE dejagnu.test ROWS IDENTIFIED BY '<test>' SET testrun = '${total}';" dejagnu