Skip to content

Commit

Permalink
Tests for valgrind-friendly memory fetch.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dmitry Prokoptsev committed Nov 6, 2013
1 parent 529584b commit e53b982
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 6 deletions.
8 changes: 8 additions & 0 deletions configure.ac
Expand Up @@ -85,6 +85,14 @@ AM_CONDITIONAL([ENABLE_EXTRA], [test x"$enable_extra" = xyes])
AM_CONDITIONAL([ENABLE_DEBUG], [test x"$enable_debug" = xyes])
AM_CONDITIONAL([ENABLE_CHECKED], [test x"$enable_checked" = xyes])

AC_ARG_ENABLE([valgrind_safe], AS_HELP_STRING([--enable-valgrind-safe], [Make Pire fetch data in a way which does not upset Valgrind]))
if test x"$enable_valgrind_safe" = xyes; then
AC_DEFINE(ENABLE_VALGRIND_SAFE, 1, [Define to 1 if valgrind-compatible memory fetch is needed])
fi

AC_CACHE_CHECK([[for valgrind]], [pire_cv_have_valgrind], AC_CHECK_PROG([pire_cv_have_valgrind], [valgrind], [yes], [no]))
AM_CONDITIONAL([HAVE_VALGRIND], [test x"$pire_cv_have_valgrind" = xyes])

AC_CONFIG_FILES([
Makefile
pire/Makefile
Expand Down
23 changes: 17 additions & 6 deletions tests/Makefile.am
Expand Up @@ -6,11 +6,15 @@ if ENABLE_CHECKED
AM_CXXFLAGS += -DPIRE_CHECKED
endif

lib_LTLIBRARIES = libpire_unit.la
libpire_unit_la_SOURCES = \
stub/cppunit.cpp \
stub/cppunit.h
libpire_unit_la_CXXFLAGS = -I$(top_srcdir)/pire

check_PROGRAMS = pire_test

pire_test_SOURCES = \
stub/cppunit.cpp \
stub/cppunit.h \
common.h \
pire_ut.cpp \
easy_ut.cpp
Expand All @@ -24,14 +28,21 @@ endif

nodist_pire_test_SOURCES = inline_ut_2.cpp

EXTRA_DIST = inline_ut.cpp
EXTRA_DIST = inline_ut.cpp pire_test_valgrind.sh

pire_test_LDADD = ../pire/libpire.la
pire_test_CXXFLAGS = -I$(top_srcdir)/pire $(CPPUNIT_CFLAGS) $(AM_CXXFLAGS)
pire_test_LDFLAGS = $(CPPUNIT_LIBS)
pire_test_LDADD = ../pire/libpire.la libpire_unit.la
pire_test_CXXFLAGS = -I$(top_srcdir)/pire $(AM_CXXFLAGS)

TESTS = pire_test

if HAVE_VALGRIND
check_PROGRAMS += pire_test_valgrind
pire_test_valgrind_SOURCES = valgrind_ut.cpp
pire_test_valgrind_LDADD = ../pire/libpire.la libpire_unit.la
pire_test_valgrind_CXXFLAGS = -I$(top_srcdir)/pire $(AM_CXXFLAGS)
TESTS += pire_test_valgrind.sh
endif

CLEANFILES = inline_ut_2.cpp

inline_ut_2.cpp: $(srcdir)/inline_ut.cpp
Expand Down
2 changes: 2 additions & 0 deletions tests/pire_test_valgrind.sh
@@ -0,0 +1,2 @@
#!/bin/sh
libtool --mode=execute valgrind ./pire_test_valgrind
49 changes: 49 additions & 0 deletions tests/valgrind_ut.cpp
@@ -0,0 +1,49 @@
/*
* valgrind_ut.cpp -- tests for Pire compatibility with Valgrind
*
* Copyright (c) 2007-2010, Dmitry Prokoptsev <dprokoptsev@gmail.com>,
* Alexander Gololobov <agololobov@gmail.com>
*
* This file is part of Pire, the Perl Incompatible
* Regular Expressions library.
*
* Pire is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Pire 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 Lesser Public License for more details.
* You should have received a copy of the GNU Lesser Public License
* along with Pire. If not, see <http://www.gnu.org/licenses>.
*/

#ifndef PIRE_ENABLE_VALGRIND_SAFE
#define PIRE_ENABLE_VALGRIND_SAFE
#endif

#include <stub/hacks.h>
#include <stub/defaults.h>
#include "stub/cppunit.h"
#include <stdexcept>
#include "common.h"

SIMPLE_UNIT_TEST_SUITE(TestPireValgrind) {

SIMPLE_UNIT_TEST(Valgrind)
{
char* str = (char*) malloc(6);
try {
strcpy(str, "abcde");
REGEXP("abcde") ACCEPTS(str);
free(str);
}
catch (...) {
free(str);
throw;
}
}

}

0 comments on commit e53b982

Please sign in to comment.