This is an automated email from the git hooks/post-receive script.
robert.savoye pushed a commit to branch parser in repository toolchain/abe.
commit 96d819806f1576d13252dfb2aa4a6f0a8884371b Author: Rob Savoye rob.savoye@linaro.org Date: Sun Aug 16 14:15:30 2015 -0600
And API for a toolchain component data structure with test cases.
Change-Id: I05d7e722ca2d06fa68fdd28f32b65b3f0c788827 --- lib/component.sh | 258 +++++++++++++++++++++++++++++++++++++++++++ testsuite/component-tests.sh | 189 +++++++++++++++++++++++++++++++ 2 files changed, 447 insertions(+)
diff --git a/lib/component.sh b/lib/component.sh new file mode 100644 index 0000000..d0dce60 --- /dev/null +++ b/lib/component.sh @@ -0,0 +1,258 @@ +#!/bin/bash +# +# Copyright (C) 2015 Linaro, Inc +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +# + +declare -Ag toolchain + +# This file attempts to turn an associative array into a semblance of a +# data structure. Note that this will only work with the bash shell. +# +# The default fields are +# TOOL +# URL +# REVISION +# BRANCH +# SRCDIR +# BUILDDIR +# FILESPEC + +# Initialize the associative array +# parameters: +# $ - Any parameter without a '=' sign becomes the name of the the array. +# +component_init () +{ +# trace "$*" + + local component= + for i in $*; do + if test "`echo $i | grep -c '='`" -gt 0; then + name="`echo $i | cut -d '=' -f 1`" + value="`echo $i | cut -d '=' -f 2`" + eval ${component}[${name}]="${value}" + if test $? -gt 0; then + return 1 + fi + else + component=$i + declare -Ag ${component} + eval ${component}[TOOL]="${component}" + if test $? -gt 0; then + return 1 + fi + fi + done + + return 0 +} + +# Accessor functions for the data structure to set "private" data. This is a crude +# approximation of an object oriented API for this data structure. Each of the setters +# takes two arguments, which are: +# +# $1 - The name of the data structure, which is based on the toolname, ie... gcc, [...] +# $2 - The value to assign the data field. +# +# Returns 0 on success, 1 on error +# +set_component_url () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval ${component}[URL]="$2" + fi + + return 0 +} + +set_component_revision () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval ${component}[REVISION]="$2" + fi + + return 0 +} + +set_component_srcdir () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval ${component}[SRCDIR]="$2" + fi + + return 0 +} + +set_component_builddir () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval ${component}[BUILDDIR]="$2" + fi + + return 0 +} + +set_component_filespec () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval ${component}[FILESPEC]="$2" + fi + + return 0 +} + +set_component_branch () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval ${component}[BRANCH]="$2" + fi + + return 0 +} + +# Accessor functions for the data structure to get "private" data. This is a crude +# approximation of an object oriented API for this data structure. All of the getters +# take only one argument, which is the toolname, ie... gcc, gdb, etc... +# +# $1 - The name of the data structure, which is based on the toolname, ie... gcc, [...] +# +# Returns 0 on success, 1 on error, and the value is returned as a string. +# +get_component_url () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval "echo ${${component}[URL]}" + fi + + return 0 +} + +get_component_revision () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval "echo ${${component}[REVISION]}" + fi + + return 0 +} + +get_component_srcdir () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval "echo ${${component}[SRCDIR]}" + fi + + return 0 +} + +get_component_builddir () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval "echo ${${component}[BUILDDIR]}" + fi + + return 0 +} + +get_component_filespec () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval "echo ${${component}[FILESPEC]}" + fi + + return 0 +} + +get_component_branch () +{ +# trace "$*" + local component=$1 + declare -p ${component} 2>&1 > /dev/null + if test $? -gt 0; then + echo "WARNING: ${component} does not exist!" + return 1 + else + eval "echo ${${component}[BRANCH]}" + fi + + return 0 +} diff --git a/testsuite/component-tests.sh b/testsuite/component-tests.sh new file mode 100644 index 0000000..25e7a5d --- /dev/null +++ b/testsuite/component-tests.sh @@ -0,0 +1,189 @@ +# tests for the component data structure + +abe_path=/linaro/src/linaro/abe/parser +. ${abe_path}/testsuite/common.sh +. ${abe_path}/lib/component.sh + +echo "============= *_component_*() tests ================" + +# FIXME: Note these following test cases only PASS if you have the source +# directories created already. + +component_init ld BRANCH="aa" URL="http://cc" gas FILESPEC="bb" +if test $? -eq 0; then + pass "component_init() two data structures" + init="yes" +else + fail "component_init() two data structures" + init="no" +fi + +disp="URL is set" +if test x"${init}" = x"yes"; then + if test x"${ld[URL]}" = x"http://cc"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +disp="FILESPEC is set" +if test x"${init}" = x"yes"; then + if test x"${gas[FILESPEC]}" = x"bb"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +# Test the setter functions +set_component_url ld "aaa" +disp="set_component_url() ld" +if test x"${init}" = x"yes"; then + if test x"${ld[URL]}" = x"aaa"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +set_component_srcdir ld "bbb" +disp="set_component_srcdir() ld" +if test x"${init}" = x"yes"; then + if test x"${ld[SRCDIR]}" = x"bbb"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +set_component_builddir ld "dddd" +disp="set_component_builddir() ld" +if test x"${init}" = x"yes"; then + if test x"${ld[BUILDDIR]}" = x"dddd"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +set_component_revision ld "eeeee" +disp="set_component_revision() ld" +if test x"${init}" = x"yes"; then + if test x"${ld[REVISION]}" = x"eeeee"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +set_component_branch ld "ffff" +disp="set_component_branch() ld" +if test x"${init}" = x"yes"; then + if test x"${ld[BRANCH]}" = x"ffff"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +set_component_filespec ld "ggg" +disp="set_component_filespec() ld" +if test x"${init}" = x"yes"; then + if test x"${ld[FILESPEC]}" = x"ggg"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +# Getter function tests +disp="get_component_url() ld" +out="`get_component_url ld`" +if test x"${init}" = x"yes"; then + if test x"${out}" = x"aaa"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +disp="get_component_srcdir() ld" +out="`get_component_srcdir ld`" +if test x"${init}" = x"yes"; then + if test x"${out}" = x"bbb"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +disp="get_component_builddir() ld" +out="`get_component_builddir ld`" +if test x"${init}" = x"yes"; then + if test x"${out}" = x"dddd"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +disp="get_component_revision() ld" +out="`get_component_revision ld`" +if test x"${init}" = x"yes"; then + if test x"${out}" = x"eeeee"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi + +disp="get_component_filespec() ld" +out="`get_component_filespec ld`" +if test x"${init}" = x"yes"; then + if test x"${out}" = x"ggg"; then + pass "${disp}" + else + fail "${disp}" + fixme "${disp}" + fi +else + untested "${disp}" +fi +