#2 Add tests to gc
Opened 2 years ago by pingou. Modified 2 years ago
rpms/ pingou/gc rpms  into  master

file modified
+20

@@ -8,6 +8,9 @@ 

  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 @@ 

  %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 @@ 

  

  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 @@ 

  %{_libdir}/pkgconfig/bdw-gc.pc

  %{_mandir}/man3/gc.3*

  

+ %files tests

+ %{_libexecdir}/gc/

  

  %changelog

  * Wed Aug 02 2017 Fedora Release Engineering <releng@fedoraproject.org> - 7.6.0-7

file added
+52

@@ -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

+ 

file added
+23

@@ -0,0 +1,23 @@ 

+ /* Example program snagged from gc's homepage:

+ http://www.hboehm.info/gc/simple_example.html  */

+ 

+ #include "gc.h"

+ #include <assert.h>

+ #include <stdio.h>

+ 

+ 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;

+ }

This is the second approach proposed to add tests to gc, the first one being in https://src.fedoraproject.org/rpms/gc/pull-request/1

I also wanted to point out that there is nothing preventing you as package maintainer to choose an approach today and change it later as tests are added or changed and your needs vary.

Most of this is boilerplate. It should be moved into standard-test-roles. This pull request does that: https://pagure.io/standard-test-roles/pull-request/59