Improve gbs coverage ratio 59/238759/20
authorbiao716.wang <biao716.wang@samsung.com>
Fri, 17 Jul 2020 05:42:44 +0000 (13:42 +0800)
committerbiao716.wang <biao716.wang@samsung.com>
Thu, 23 Jul 2020 06:22:53 +0000 (14:22 +0800)
Change-Id: I8a49530c6ee2f90471974bc35bc6793ea1bb82d8
Signed-off-by: biao716.wang <biao716.wang@samsung.com>
gitbuildsys/cmd_build.py
tests/test_export.py [new file with mode: 0644]
tests/testdata/base.cfg [new file with mode: 0644]
tests/testdata/create_proj [new file with mode: 0755]
tests/testdata/fake.spec [new file with mode: 0644]
tests/testdata/sw-tools.spec [new file with mode: 0644]
tools/gbs

index 52a25f8..5288a51 100644 (file)
@@ -698,7 +698,6 @@ def init_buildroot(args, profile):
 
 def main(args):
     """gbs build entry point."""
-    print (args)
     global TMPDIR
     TMPDIR = os.path.join(configmgr.get('tmpdir', 'general'), '%s-gbs' % USERID)
 
diff --git a/tests/test_export.py b/tests/test_export.py
new file mode 100644 (file)
index 0000000..2408bf5
--- /dev/null
@@ -0,0 +1,79 @@
+"""Functionality tests for gbs export."""
+
+import unittest
+import imp
+import os
+import shutil
+import tempfile
+from nose.tools import eq_
+
+GBS = imp.load_source("gbs", "./tools/gbs").main
+
+class TestExport(unittest.TestCase):
+    """Test export output of gbs commands"""
+
+    def setUp(self):
+        self.cdir = os.getcwd()
+        self.testdataDir = os.path.join(self.cdir, "./tests/testdata")
+        os.chdir(self.testdataDir)
+        os.system('./create_proj fake.spec')
+
+    def tearDown(self):
+        shutil.rmtree(os.path.join(self.testdataDir, "./fake"))
+        os.chdir(self.cdir)
+
+    def test_command_export_directory(self):
+        """Test running gbs export commond."""
+        try:
+            GBS(argv=["gbs", "export", "fake", "-o", "tmp_output"])
+            shutil.rmtree(os.path.join(self.testdataDir, "./tmp_output"))
+        except SystemExit as err:
+            eq_(err.code, 0)
+
+    def test_command_export_source_rpm(self):
+        """Test running gbs export source rpm commond."""
+        try:
+            GBS(argv=["gbs", "export", "fake", "--source-rpm", "-o", "tmp_output"])
+            shutil.rmtree(os.path.join(self.testdataDir, "./tmp_output"))
+        except SystemExit as err:
+            eq_(err.code, 0)
+
+    def test_command_export_include_all(self):
+        """Test running gbs export with include-all commond."""
+        try:
+            GBS(argv=["gbs", "export", "fake", "--include-all", "-o", "tmp_output"])
+            shutil.rmtree(os.path.join(self.testdataDir, "./tmp_output"))
+        except SystemExit as err:
+            eq_(err.code, 0)
+
+    def test_command_export_outdir_directly(self):
+        """Test running gbs export with include-all commond."""
+        try:
+            GBS(argv=["gbs", "export", "fake", "--outdir-directly", "-o", "tmp_output"])
+            shutil.rmtree(os.path.join(self.testdataDir, "./tmp_output"))
+        except SystemExit as err:
+            eq_(err.code, 0)
+
+    def test_command_export_special_spec(self):
+        """Test running gbs export with --spec and --no-patch-export commond."""
+        try:
+            GBS(argv=["gbs", "export", "fake", "--spec=fake.spec", "--no-patch-export", "-o", "tmp_output"])
+            shutil.rmtree(os.path.join(self.testdataDir, "./tmp_output"))
+        except SystemExit as err:
+            eq_(err.code, 0)
+
+    def test_command_export_disable_fallback_to_native_packaging(self):
+        """Test running gbs export failed case:disable fallback to native commond."""
+        try:
+            os.system('mkdir -p /tmp/gbs_export_tmp')
+            shutil.copy('./sw-tools.spec', '/tmp/gbs_export_tmp')
+            shutil.copy('./create_proj', '/tmp/gbs_export_tmp')
+            os.chdir('/tmp/gbs_export_tmp')
+            os.system('./create_proj --tizen sw-tools.spec')
+            os.system('sed -i "s/^Version:.*$/Version:0.2/" packaging/sw-tools.spec')
+            os.system('git commit -a -m "upgrade to gbs 0.2"')
+            GBS(argv=["gbs", "export", "sw-tools"])
+            shutil.rmtree('/tmp/gbs_export_tmp')
+        except SystemExit as err:
+            eq_(err.code, 2)
+
diff --git a/tests/testdata/base.cfg b/tests/testdata/base.cfg
new file mode 100644 (file)
index 0000000..f8dab07
--- /dev/null
@@ -0,0 +1,70 @@
+[general]
+profile = profile.tizen
+tmpdir = /var/tmp
+
+[profile.tizen]
+; common authentication info for whole profile
+#user =
+; CAUTION: please use the key name "passwd" to reset plaintext password
+#passwd =
+obs = obs.tizen
+; comma separated list of repositories
+#repos = repo.tizen_base, repo.tizen_main
+repos = repo.tizen_base, repo.tizen_main
+[obs.tizen]
+url = https://api.tizen.org
+; optinal user/passwd, set if differ from proflie's user/passwd
+user = obs_viewer
+passwdx = QlpoOTFBWSZTWWV18UwAAAKDgAAAkiCZgCAAMQZMQQDJ6jQwAvxdyRThQkGV18Uw
+
+[repo.tizen_latest]
+#url = http://download.tizen.org/releases/2.2/latest/
+; optinal user/passwd, set if differ from proflie's user/passwd
+#user =
+#passwdx =
+
+[repo.tizen_main]
+#url = http://download.tizen.org/releases/2.2/latest/repos/tizen-main/ia32/packages/
+url = http://download.tizen.org/releases/milestone/tizen/unified/latest/repos/standard/packages/
+
+[profile.tizen_base]
+repos = repo.tizen_base
+
+[repo.tizen_base]
+#url = http://download.tizen.org/releases/2.2/latest/repos/tizen-base/ia32/packages/
+url = http://download.tizen.org/releases/milestone/tizen/base/latest/repos/standard/packages/
+
+[profile.tizen_ivi]
+repos = repo.tizen_ivi
+
+[repo.tizen_ivi]
+#url = http://download.tizen.org/releases/daily/tizen/ivi/latest/repos/atom/packages/
+url = http://download.tizen.org/releases/milestone/tizen/ivi/latest/repos/atom/packages/
+
+[profile.tizen_negative1]
+repos = repo.tizen_negative1
+
+[repo.tizen_negative1]
+#there is no <data type="build"> in repomd.xml
+url = http://localhost:8881/negativ_1_gbs/packages/
+
+[profile.tizen_negative2]
+repos = repo.tizen_negative2
+
+[repo.tizen_negative2]
+#there is no f113ca67a6b9f572cdbd1bacf3e7364b685dbb7f9f79bf43ca2a55df3c84ff9e-build.conf.gz defined by repomd.xml in repodata
+url = http://localhost:8881/negativ_2_gbs/repos/atom/i586/packages/
+
+[profile.tizen_negative3]
+repos = repo.tizen_negative3
+
+[repo.tizen_negative3]
+#new structure repo
+url = http://localhost:8881/negativ_3_gbs/
+
+[profile.tizen_without_conf]
+repos = repo.tizen_without_conf
+
+[repo.tizen_without_conf]
+#there is no builddata under latest directory
+url = http://localhost:8881/without_conf_gbs/
diff --git a/tests/testdata/create_proj b/tests/testdata/create_proj
new file mode 100755 (executable)
index 0000000..64fa11b
--- /dev/null
@@ -0,0 +1,164 @@
+#!/bin/bash
+
+info() {
+    echo "$@"
+}
+
+error() {
+    echo "$@" >&2
+    exit 1
+}
+
+usage() {
+    echo "Usage: `basename $0` [options] <spec> [files ...]"
+    echo "Create dummy GIT project form spec for testing"
+    echo
+    echo "  spec"
+    echo "      path to spec file"
+    echo "  files"
+    echo "      files that will be copied to project/packaging dir"
+    echo
+    echo "  -h, --help"
+    echo "  -f, --force"
+    echo "      force to create project, delete existed project before creating"
+    echo "  -C DIR, --directory=DIR"
+    echo "      create project in DIR, if not given it will guess the project"
+    echo "  -t, --tizen"
+    echo "      create a standard tizen package including upstream and pristine-tar branch"
+    echo "      name from the spec file name and create the project as a"
+    echo "      subdir of cwd"
+}
+
+guess_project_dir() {
+    if [ -n "$output_dir" ]; then
+        proj_dir=$output_dir
+    else
+        proj_dir=$(basename $spec .spec)
+    fi
+}
+
+check_proj() {
+    if [ -e $proj_dir ]; then
+        if [ "$force" == 1 ]; then
+            info "overwriting project $proj_dir"
+            rm -rf $proj_dir
+        else
+            error "project $proj_dir exists"
+        fi
+    fi
+}
+
+
+make_proj() {
+    info "creating GIT project at $proj_dir using $@"
+
+    pack_dir=$proj_dir/packaging
+
+    local dest_spec=$PWD/$(basename $spec)
+
+    if [ "$tizen_pkg" == 1 ]; then
+        ###Create tarball with source git tree,no packaging dir
+        mkdir -p $proj_dir
+        pushd $proj_dir
+        echo 'this dummy project was created for gbs testing' > README
+
+        git init
+        git add .
+        git commit -m "Initial commit"
+
+        name=`awk '/^Name/ {print $2}' $dest_spec`
+        version=`awk '/^Version/ {print $2}' $dest_spec`
+        fmt=`awk '/^Source0/ {print $2}' $dest_spec|cut -d. -f2,3`
+        git archive --prefix="$name-$version/" --output "../$name-$version.$fmt" HEAD
+        popd
+
+        ###Remove source git tree after archiving
+        rm -rf $proj_dir
+
+        ###Import to non-native git tree with tarball and spec
+        gbs import $dest_spec
+
+        ###For multispec
+        if [ ${#@} -gt 1 ]; then
+            for fname in "$@"; do
+                cp $fname $pack_dir
+            done
+            pushd $proj_dir
+            git add .
+            git commit --amend -m "Imported vendor release 1.0-1"
+            popd
+        fi
+
+        ###Remove tarball
+        rm -f $name-$version.$fmt
+    else
+        ###Create native git tree
+        mkdir -p $pack_dir
+        for fname in "$@"; do
+            cp $fname $pack_dir
+        done
+        pushd $proj_dir
+        echo 'this dummy project was created for gbs testing' > README
+        git init
+        git add .
+        git commit -m "Initial commit"
+        popd
+    fi
+}
+
+### Main
+
+TEMP=$(getopt -o hfC:t --long help,force,directory:,tizen -n "$0" -- "$@")
+if [ $? -ne 0 ]; then
+    usage
+    exit 1
+fi
+
+eval set -- "$TEMP"
+while true; do
+    case "$1" in
+        -h|--help)
+            usage
+            exit 0
+            ;;
+        -f|--force)
+            force=1
+            shift
+            ;;
+         -C|--directory)
+            shift;
+            output_dir=$1
+            shift
+            ;;
+         -t|--tizen)
+            tizen_pkg=1
+            shift
+            ;;
+         --)
+            shift
+            break
+            ;;
+         *)
+            echo "Internal error!"
+            exit 1
+            ;;
+        esac
+done
+
+if [ ${#@} -lt 1 ]; then
+    error "spec file is required"
+fi
+
+for fname in "$@"; do
+    if [ ! -f "$fname" ]; then
+        error "No such file: $fname"
+    fi
+done
+
+spec=$1
+shift
+git config --system user.email "itest@intel.com"
+git config --system user.name "scm"
+guess_project_dir "$@"
+check_proj $proj
+make_proj $spec "$@"
diff --git a/tests/testdata/fake.spec b/tests/testdata/fake.spec
new file mode 100644 (file)
index 0000000..4404df6
--- /dev/null
@@ -0,0 +1,20 @@
+Name:       fake
+Summary:    A fake tizen package for gbs test
+Version:    1.0
+Release:    1
+Group:      Development/Tools
+License:    GPLv2
+Source0:    %{name}-%{version}.tbz2
+
+%description
+A fake tizen package for gbs test
+* download and install gbs
+* use this package to test gbs build, remotebuild, export, import and so on
+%prep
+%setup -q
+
+%install
+mkdir -p %{buildroot}/%{_docdir}
+
+%files
+%doc README
diff --git a/tests/testdata/sw-tools.spec b/tests/testdata/sw-tools.spec
new file mode 100644 (file)
index 0000000..03c380a
--- /dev/null
@@ -0,0 +1,28 @@
+%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
+Name:          sw-tools
+Version:       0.1
+Release:       1
+Summary:       Generate binary update packs
+
+Group:         Development/Tools
+License:       GPL V2
+URL:           http://www.tizen.org
+Source0:       %{name}-%{version}.tar.bz2
+BuildRoot:     %{_tmppath}/%{name}-%{version}-%{release}-root
+
+BuildRequires: python-devel
+Requires:      yum
+Requires:      deltarpm
+Requires:   python-deltarpm
+
+%description
+This is a tool to help genearting binary update packs
+
+%prep
+%setup -q -n %{name}-%{version}
+
+%install
+mkdir -p %{buildroot}/%{_docdir}
+
+%files
+%{_docdir}/
index 43eab50..dac1127 100755 (executable)
--- a/tools/gbs
+++ b/tools/gbs
@@ -27,9 +27,11 @@ from gitbuildsys import __version__
 from gitbuildsys import errors
 from gitbuildsys.parsing import subparser, GbsHelpFormatter, basename_type
 from gitbuildsys import log
-from gitbuildsys import cmd_build
+
 from gitbuildsys.utils import SearchConfAction
 
+SUPPORTED_ARCHS = ['x86_64','i586','armv6l','armv7hl','armv7l','aarch64','mips','mipsel',]
+
 
 @subparser
 def import_parser(parser):
@@ -162,7 +164,7 @@ def build_parser(parser):
 
     group = parser.add_argument_group('build configuration options')
     group.add_argument('-A', '--arch', help='build target arch. Supported arch '
-                       'types are: %s' % ' '.join(cmd_build.SUPPORTEDARCHS))
+                       'types are: %s' % ' '.join(SUPPORTED_ARCHS))
     group.add_argument('-D', '--dist',
                         help='specify project (build) configuration file. '
                         'User can specify build config in [profile.xx] '
@@ -592,7 +594,7 @@ def depends_parser(parser):
 
     group = parser.add_argument_group('depends configuration options')
     group.add_argument('-A', '--arch', help='target arch. Supported arch '
-                       'types are: %s' % ' '.join(cmd_build.SUPPORTEDARCHS))
+                       'types are: %s' % ' '.join(SUPPORTED_ARCHS))
     group.add_argument('-D', '--dist',
                         help='specify project (build) configuration file. '
                         'User can specify build config in [profile.xx] '