From 5f53b4175aac0f9d210254c26ea893eab887e096 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sep 22 2017 09:06:44 +0000 Subject: Add tests to gc The test itself consists of compiling a small C file, executing it and checking its output. This commit it embeds the C file into the rpm, compiles it in the %build section and ships it in a -tests sub-package. This makes the ansible playbook used to run the tests easier as testing gc just becomes: install gc-tests, run the program, grep its output. It also has the advantages that tests can then be linked to a specific version of gc, but the test that is currently being added is quite generic. However, it also has some cons: - Changing/Updating the tests means updating the package (adding more tests means adding more SourceX in the spec file) - More not-really-package-related-lines in the spec file (ie: less clean spec file) Signed-off-by: Pierre-Yves Chibon --- diff --git a/gc.spec b/gc.spec index 83fe14b..5a7fbf7 100644 --- a/gc.spec +++ b/gc.spec @@ -8,6 +8,9 @@ License: BSD Url: http://www.hboehm.info/gc/ Source0: http://www.hboehm.info/gc/gc_source/gc-%{version}%{?pre}.tar.gz +# Simple C program to test the behaviour of gc +Source100: tst-gc.c + ## upstreamable patches ## upstream patches @@ -32,6 +35,14 @@ Provides: libgc-devel = %{version}-%{release} %description devel %{summary}. +%package tests +Summary: Tests for the %{name} package +Requires: %{name}%{?_isa} = %{version}-%{release} + +%description tests +This package contains tests that can be used to verify +the functionality of the installed %{name} package. + %prep %autosetup -n gc-%{version}%{?pre} @@ -57,12 +68,19 @@ CPPFLAGS="-DUSE_GET_STACKBASE_FOR_MAIN"; export CPPFLAGS make %{?_smp_mflags} +# Compile the test program +gcc -o tst-gc -I ./include/ -L ./.libs -l gc ../tst-gc.c + %install make install DESTDIR=%{buildroot} install -p -D -m644 doc/gc.man %{buildroot}%{_mandir}/man3/gc.3 +# Install the compiled test program +mkdir -p %{buildroot}%{_libexecdir}/gc +install -p -D -m755 tst-gc %{buildroot}%{_libexecdir}/gc/tst-gc + ## Unpackaged files rm -rfv %{buildroot}%{_datadir}/gc/ rm -fv %{buildroot}%{_libdir}/lib*.la @@ -99,6 +117,8 @@ make check %{?arch_ignore} %{_libdir}/pkgconfig/bdw-gc.pc %{_mandir}/man3/gc.3* +%files tests +%{_libexecdir}/gc/ %changelog * Wed Aug 02 2017 Fedora Release Engineering - 7.6.0-7 diff --git a/tests/tests.yml b/tests/tests.yml new file mode 100644 index 0000000..1319ff1 --- /dev/null +++ b/tests/tests.yml @@ -0,0 +1,52 @@ +# Tests for gc following the standard test interface defined at: +# https://fedoraproject.org/wiki/CI + +--- +- hosts: localhost + gather_facts: yes + remote_user: root + vars: + artifacts: "{{ lookup('env', 'TEST_ARTIFACTS')|default('./artifacts', true) }}" + subjects: "{{ lookup('env', 'TEST_SUBJECTS')}}" + + # Install the dependencies for atomic + tasks: + - name: Install the dependencies + shell: rpm-ostree install gc-tests && rpm-ostree ex livefs + tags: + - atomic + + # Install the dependencies for Docker and Classic + - name: Install the required packages + package: + name: "{{ item }}" + state: present + with_items: + - gc-tests + - gc + tags: + - classic + - container + + - block: + - name: Make artifacts directory + file: path=/tmp/artifacts state=directory + owner=root mode=755 recurse=yes + + - name: Run the test file + shell: /usr/libexec/gc/tst-gc > out + args: + chdir: /tmp/artifacts + + - name: Check/grep the output + shell: grep "Heap size = [1-9][0-9]*" out + args: + chdir: /tmp/artifacts + + always: + - name: Pull out the logs + synchronize: + dest: "{{ artifacts }}" + src: "/tmp/artifacts/./" + mode: pull + diff --git a/tst-gc.c b/tst-gc.c new file mode 100644 index 0000000..79afb91 --- /dev/null +++ b/tst-gc.c @@ -0,0 +1,23 @@ +/* Example program snagged from gc's homepage: +http://www.hboehm.info/gc/simple_example.html */ + +#include "gc.h" +#include +#include + +int main() +{ + int i; + + GC_INIT(); /* Optional on Linux/X86; see below. */ + for (i = 0; i < 10000000; ++i) + { + int **p = (int **) GC_MALLOC(sizeof(int *)); + int *q = (int *) GC_MALLOC_ATOMIC(sizeof(int)); + assert(*p == 0); + *p = (int *) GC_REALLOC(q, 2 * sizeof(int)); + if (i % 100000 == 0) + printf("Heap size = %d\n", GC_get_heap_size()); + } + return 0; +}