[Spice-devel] [vdagent-win PATCH v4 5/5] Add test for PNG files
Frediano Ziglio
fziglio at redhat.com
Mon Jul 17 09:21:29 UTC 2017
>
> Test various image and formats.
> The idea is to decode and encode again an image and
> check for differences. ImageMagick is used to create
> some test image and compare results.
> Wine is used to execute a test helper.
>
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
A bit OT. I was trying to execute a "make check" during RPM build.
I need some additional support, specifically wine and ImageMagick.
ImageMagick is not a big issue, just add a BuildRequires however
wine requires:
- wine-core(x86-32) and wine-core(x86-64)
- the build system to be x64
Now in some system (like RHEL 7) you cannot install wine-core(x86-32) and wine-core(x86-64)
together so the BuildRequires will fail (works on fedora 25/26 for instance).
How to check all these in the spec file so to run in either way?
Actually I have this:
diff --git a/mingw-spice-vdagent.spec.in b/mingw-spice-vdagent.spec.in
index 8cfd01a..8b6a0b2 100644
--- a/mingw-spice-vdagent.spec.in
+++ b/mingw-spice-vdagent.spec.in
@@ -26,6 +26,7 @@ BuildRequires: mingw64-zlib-static
BuildRequires: mingw32-winpthreads-static
BuildRequires: mingw64-winpthreads-static
BuildRequires: pkgconfig
+BuildRequires: ImageMagick wine-core(x86-32) wine-core(x86-64)
BuildArch: noarch
@@ -77,6 +78,8 @@ Features:
%mingw_configure --enable-debug
%mingw_make %{?_smp_mflags} V=1
+%check
+%mingw_make check
%install
%mingw_make_install DESTDIR=$RPM_BUILD_ROOT
I miss to add these lines only on some conditions (the system with version
and architecture).
Frediano
> ---
> Makefile.am | 20 +++++++++++++
> test-png | 50 ++++++++++++++++++++++++++++++++
> vdagent/imagetest.cpp | 79
> +++++++++++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 149 insertions(+)
> create mode 100755 test-png
> create mode 100644 vdagent/imagetest.cpp
>
> diff --git a/Makefile.am b/Makefile.am
> index 175d8f7..411bf0d 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -68,6 +68,26 @@ vdservice_rc.$(OBJEXT): vdservice/vdservice.rc
>
> MAINTAINERCLEANFILES += vdservice_rc.$(OBJEXT)
>
> +check_PROGRAMS = imagetest
> +
> +imagetest_LDADD = $(LIBPNG_LIBS) $(ZLIB_LIBS) -lwtsapi32 -lgdi32
> +imagetest_CXXFLAGS = $(AM_CXXFLAGS) $(LIBPNG_CFLAGS)
> +imagetest_LDFLAGS = $(AM_LDFLAGS) -Wl,--subsystem,console
> +imagetest_SOURCES = \
> + common/vdcommon.cpp \
> + common/vdcommon.h \
> + common/vdlog.cpp \
> + common/vdlog.h \
> + vdagent/imagetest.cpp \
> + vdagent/image.cpp \
> + vdagent/image.h \
> + vdagent/imagepng.cpp \
> + vdagent/imagepng.h \
> + $(NULL)
> +
> +TESTS = test-png
> +EXTRA_DIST += test-png
> +
> deps.txt:
> $(AM_V_GEN)rpm -qa | grep $(host_os) | sort | unix2dos > $@
>
> diff --git a/test-png b/test-png
> new file mode 100755
> index 0000000..92fcff7
> --- /dev/null
> +++ b/test-png
> @@ -0,0 +1,50 @@
> +#!/bin/bash
> +
> +VERBOSE=${VERBOSE:-0}
> +
> +IN=in.png
> +OUT=out.png
> +OUT_BMP=out.bmp
> +
> +error() {
> + echo "$*" >&2
> + exit 1
> +}
> +
> +verbose() {
> + if [ $VERBOSE != 0 ]; then
> + "$@"
> + fi
> +}
> +
> +do_test() {
> + echo "Running image $IMAGE with '$*'..."
> + convert $IMAGE "$@" $IN
> + wine imagetest.exe $IN $OUT_BMP $OUT
> + verbose ls -lh $IN
> + verbose identify $IN
> + verbose identify $OUT_BMP
> + DIFF=$(compare -metric AE $IN $OUT - 2>&1 > /dev/null || true)
> + if [ "$DIFF" != "0" ]; then
> + error "Images are too different, diff $DIFF"
> + fi
> +}
> +
> +do_test_all() {
> + IMAGE="$1"
> + do_test
> + do_test -type Palette
> + do_test -type Palette -colors 14
> + do_test -type Palette -colors 3
> + do_test -type TrueColor
> + do_test -type Grayscale
> +}
> +
> +set -e
> +# test with small image
> +do_test_all rose:
> +# test with larger image
> +do_test_all logo:
> +rm -f $IN $OUT $OUT_BMP
> +
> +verbose echo Finish
> diff --git a/vdagent/imagetest.cpp b/vdagent/imagetest.cpp
> new file mode 100644
> index 0000000..d79f759
> --- /dev/null
> +++ b/vdagent/imagetest.cpp
> @@ -0,0 +1,79 @@
> +/*
> + Copyright (C) 2017 Red Hat, 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 2 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, see <http://www.gnu.org/licenses/>.
> +*/
> +
> +#undef NDEBUG
> +#include <assert.h>
> +#include <vector>
> +
> +#include "vdcommon.h"
> +#include "image.h"
> +#include "imagepng.h"
> +
> +int main(int argc, char **argv)
> +{
> + ImageCoder *coder = create_png_coder();
> +
> + assert(coder);
> + assert(argc > 1);
> +
> + // read all file into memory
> + FILE *f = fopen(argv[1], "rb");
> + assert(f);
> + assert(fseek(f, 0, SEEK_END) == 0);
> + long len = ftell(f);
> + assert(len > 0);
> + assert(fseek(f, 0, SEEK_SET) == 0);
> +
> + std::vector<uint8_t> data(len);
> + assert(fread(&data[0], 1, len, f) == (unsigned long) len);
> + fclose(f);
> +
> + size_t dib_size = coder->get_dib_size(&data[0], len);
> + assert(dib_size);
> + std::vector<uint8_t> out(dib_size);
> + memset(&out[0], 0xcc, dib_size);
> + coder->get_dib_data(&out[0], &data[0], len);
> +
> + // looks like many tools wants this header so craft it
> + BITMAPFILEHEADER head;
> + memset(&head, 0, sizeof(head));
> + head.bfType = 'B'+'M'*256u;
> + head.bfSize = sizeof(head) + dib_size;
> + BITMAPINFOHEADER& info(*(BITMAPINFOHEADER*)&out[0]);
> + head.bfOffBits = sizeof(head) + sizeof(BITMAPINFOHEADER) + 4 *
> info.biClrUsed;
> +
> + f = fopen(argc > 2 ? argv[2] : "out.bmp", "wb");
> + assert(f);
> + assert(fwrite(&head, 1, sizeof(head), f) == sizeof(head));
> + assert(fwrite(&out[0], 1, dib_size, f) == dib_size);
> + fclose(f);
> +
> + // convert back to PNG
> + long png_size = 0;
> + uint8_t *png = coder->from_bitmap(*((BITMAPINFO*)&out[0]),
> &out[sizeof(BITMAPINFOHEADER) + 4 * info.biClrUsed], png_size);
> + assert(png && png_size > 0);
> +
> + f = fopen(argc > 3 ? argv[3] : "out.png", "wb");
> + assert(f);
> + assert(fwrite(png, 1, png_size, f) == (unsigned long) png_size);
> + fclose(f);
> + free(png);
> + png = NULL;
> +
> + return 0;
> +}
> +
More information about the Spice-devel
mailing list