#3 Adds tests according to the CI
Opened 4 years ago by ssahani. Modified 4 years ago
rpms/ ssahani/libcap-ng tests  into  rawhide

Adds tests according to the CI
Susant Sahani • 4 years ago  
@@ -0,0 +1,46 @@ 

+ # SPDX-License-Identifier: LGPL-2.1+

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ #

+ #   Makefile of /CoreOS/libcap-ng

+ #   Description: Test if libcap-ng working ok

+ #   Author: Susant Sahani<susant@redhat.com>

+ #

+ # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

+ export TEST=/CoreOS/libcap-ng

+ export TESTVERSION=1.0

+ 

+ OBJS =  test-libcap-ng.c

+ CFLAG = -Wall -g3

+ CC = gcc

+ LIBS = -lcap-ng -lcmocka

+ 

+ test-libcap-ng:${OBJ}

+ 	${CC} ${CFLAGS} ${INCLUDES} -o $@ ${OBJS} ${LIBS}

+ 

+ run: test-libcap-ng

+ 	./runtest.sh

+ clean:

+ 	-rm -f *~ test-libcap-ng

+ 

+ .c.o:

+ 	${CC} ${CFLAGS} ${INCLUDES} -c $<

+ 

+ CC = gcc

+ 

+ include /usr/share/rhts/lib/rhts-make.include

+ $(METADATA): Makefile

+         @echo "Owner:           Susant Sahani<susant@redhat.com>" > $(METADATA)

+         @echo "Name:            $(TEST)" >> $(METADATA)

+         @echo "TestVersion:     $(TESTVERSION)" >> $(METADATA)

+         @echo "Path:            $(TEST_DIR)" >> $(METADATA)

+         @echo "Description:     Test libcap-ng works ok" >> $(METADATA)

+         @echo "Type:            Sanity" >> $(METADATA)

+         @echo "TestTime:        5m" >> $(METADATA)

+         @echo "RunFor:          libcap-ng" >> $(METADATA)

+         @echo "Requires:        libcap-ng libcap-ng-devel" >> $(METADATA)

+         @echo "Priority:        Normal" >> $(METADATA)

+         @echo "License:         GPLv2" >> $(METADATA)

+         @echo "Confidential:    no" >> $(METADATA)

+         @echo "Destructive:     no" >> $(METADATA)

+         @echo "Releases:        -Fedora 29" >> $(METADATA)

+ 	rhts-lint $(METADATA)

@@ -0,0 +1,34 @@ 

+ #!/bin/bash

+ # SPDX-License-Identifier: LGPL-2.1+

+ # ~~~

+ #   runtest.sh of libcap-ng

+ #   Description: Tests for libcap-ng

+ #

+ #   Author: Susant Sahani <susant@redhat.com>

+ #   Copyright (c) 2018 Red Hat, Inc.

+ # ~~~

+ 

+ # Include Beaker environment

+ . /usr/share/beakerlib/beakerlib.sh || exit 1

+ 

+ PACKAGE="libcap-ng"

+ 

+ rlJournalStart

+     rlPhaseStartSetup

+         rlAssertRpm $PACKAGE

+         rlRun "cp test-libcap-ng /usr/bin/"

+     rlPhaseEnd

+ 

+     rlPhaseStartTest

+         rlLog "Starting libcap-ng tests ..."

+         rlRun "/usr/bin/test-libcap-ng"

+     rlPhaseEnd

+ 

+     rlPhaseStartCleanup

+         rlRun "rm /usr/bin/test-libcap-ng"

+         rlLog "libcap-ng tests done"

+     rlPhaseEnd

+ rlJournalPrintText

+ rlJournalEnd

+ 

+ rlGetTestState

@@ -0,0 +1,51 @@ 

+ /*

+ # SPDX-License-Identifier: LGPL-2.1+

+ # ~~~

+ #   Description: libcap tests

+ #

+ #   Author: Susant Sahani <susant@redhat.com>

+ #   Copyright (c) 2018 Red Hat, Inc.

+ # ~~~

+ */

+ #include <stdlib.h>

+ #include <stdarg.h>

+ #include <string.h>

+ #include <netinet/in.h>

+ #include <setjmp.h>

+ #include <inttypes.h>

+ #include <cmocka.h>

+ #include <sys/capability.h>

+ #include <netdb.h>

+ #include <netinet/in.h>

+ #include <arpa/inet.h>

+ #include <errno.h>

+ #include <unistd.h>

+ #include <cap-ng.h>

+ 

+ static void drop_cap(uint32_t cap) {

+ 

+         capng_clear(CAPNG_SELECT_BOTH);

+ 

+ 	assert_return_code(capng_update(CAPNG_DROP, CAPNG_PERMITTED, cap), 0);

+         assert_return_code(capng_update(CAPNG_DROP, CAPNG_EFFECTIVE, cap), 0);

+         assert_return_code(capng_apply(CAPNG_SELECT_CAPS), 0);

+ }

+ 

+ static void test_drop_cap_net_raw(void **state) {

+         int s, r;

+ 

+         assert_true((s = socket(PF_INET, SOCK_RAW, IPPROTO_UDP)) >= 0);

+         close(s);

+ 

+         drop_cap(CAP_NET_RAW);

+ 

+         assert_false((s = socket(PF_INET, SOCK_RAW, IPPROTO_UDP) >= 0));

+ }

+ 

+ int main(int argc, char *argv[]) {

+         const struct CMUnitTest libcap_ng_tests[] = {

+                                                   cmocka_unit_test(test_drop_cap_net_raw),

+         };

+ 

+         return cmocka_run_group_tests(libcap_ng_tests, NULL, NULL);

+ }

file added
+13
@@ -0,0 +1,13 @@ 

+ - hosts: localhost

+   roles:

+     - role: standard-test-beakerlib

+       tags:

+         - classic

+       tests:

+         - sanity-tests

+       required_packages:

+         - libcap-ng

+         - libcap-ng-devel

+         - libcmocka

+         - libcmocka-devel

+         - gcc

justification
Adds tests according to the CI wiki specifically the standard test interface in the spec.
The playbook includes Tier1 level test cases that have been tested in the following contexts and
is passing reliably: Classic. Test logs are stored in the artifacts directory.
The following steps are used to execute the tests using the standard test interface:

Test enveronment
Make sure you have installed packages from the spec

ansible-2.4.1.0-2.fc28.noarch
python2-dnf-2.7.5-1.fc28.noarch
libselinux-python-2.7-2.fc28.x86_64
standard-test-roles-2.5-1.fc28.noarch
Run tests for Classic
Snip of the example test run for Classic tests:

/runtest.sh

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: TEST PROTOCOL
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

Package       : libcap-ng
Installed     : libcap-ng-0.7.9-1.fc28.x86_64
beakerlib RPM : beakerlib-1.17-13.fc28.noarch
Test version  : 1.0
Test started  : 2018-06-26 15:23:08 IST
Test finished :
Test duration :
Test name     : /CoreOS/libcap-ng
Distro        : Fedora release 28 (Twenty Eight)
Hostname      : Zeus
Architecture  : x86_64
CPUs          : 8 x Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
RAM size      : 31542 MB
HDD size      : 452.94 GB

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Setup
:: Setup
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

libcap-ng-0.7.9-1.fc28.x86_64
:: [ 15:23:09 ] :: [ PASS ] :: Checking for the presence of libcap-ng rpm
:: [ 15:23:09 ] :: [ PASS ] :: Checking for the presence of libcap-ng rpm
:: [ 15:23:09 ] :: [ LOG ] :: Package versions:
:: [ 15:23:09 ] :: [ LOG ] :: Package versions:
:: [ 15:23:09 ] :: [ LOG ] :: libcap-ng-0.7.9-1.fc28.x86_64
:: [ 15:23:09 ] :: [ LOG ] :: libcap-ng-0.7.9-1.fc28.x86_64
:: [ 15:23:09 ] :: [ BEGIN ] :: Running 'cp test-libcap-ng /usr/bin/'
:: [ 15:23:09 ] :: [ PASS ] :: Command 'cp test-libcap-ng /usr/bin/' (Expected 0, got 0)
:: [ 15:23:09 ] :: [ PASS ] :: Command 'cp test-libcap-ng /usr/bin/' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 0s
:: Duration: 0s
:: Assertions: 2 good, 0 bad
:: Assertions: 2 good, 0 bad
:: RESULT: PASS
:: RESULT: PASS
`

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Test
:: Test
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

:: [ 15:23:09 ] :: [ LOG ] :: Starting libcap-ng tests ...
:: [ 15:23:09 ] :: [ LOG ] :: Starting libcap-ng tests ...
:: [ 15:23:09 ] :: [ BEGIN ] :: Running '/usr/bin/test-libcap-ng'
[==========] Running 1 test(s).
[ RUN ] test_drop_cap_net_raw
[ OK ] test_drop_cap_net_raw
[==========] 1 test(s) run.
[ PASSED ] 1 test(s).
:: [ 15:23:09 ] :: [ PASS ] :: Command '/usr/bin/test-libcap-ng' (Expected 0, got 0)
:: [ 15:23:09 ] :: [ PASS ] :: Command '/usr/bin/test-libcap-ng' (Expected 0, got 0)
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:: Duration: 0s
:: Duration: 0s
:: Assertions: 1 good, 0 bad
:: Assertions: 1 good, 0 bad
:: RESULT: PASS
:: RESULT: PASS