Skip to content

Commit

Permalink
Merge pull request #79 from phalcon/feature/docs [skip appveyor]
Browse files Browse the repository at this point in the history
Tests for memory leaks [skip appveyor]
  • Loading branch information
sergeyklay authored Sep 29, 2019
2 parents 229e472 + 00cf312 commit 414f123
Show file tree
Hide file tree
Showing 9 changed files with 328 additions and 134 deletions.
43 changes: 19 additions & 24 deletions .ci/after-failure.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,39 +7,34 @@
# For the full copyright and license information, please view
# the LICENSE file that was distributed with this source code.

$(phpenv which php) -v
$(phpenv which php) -m

PROJECT_ROOT=$(readlink -enq "$(dirname $0)/../")
cd ${PROJECT_ROOT}

shopt -s nullglob

for i in `find ./tests -name "*.out" 2>/dev/null`; do
echo "-- START ${i}"; cat ${i}; echo "-- END";
done

for i in `find ./tests -name "*.mem" 2>/dev/null`; do
echo "-- START ${i}"; cat ${i}; echo "-- END";
done

if [ -f "./configure.log" ]; then
cat "./configure.log"
fi

ls -al ${PROJECT_ROOT}

export LC_ALL=C

for i in core core.*; do
if [ -f "$i" -a "$(file "$i" | grep -o 'core file')" ]; then
gdb -q $(file "${i}" | grep -oE "'[^ ']+" | sed "s/^'//g") "$i" <<EOF
while IFS= read -r -d '' file
do
(( count++ ))
(>&1 printf ">>> START (%d)\\n%s\\n<<< END (%d)\\n\\n" $count "$(cat "$file")" $count)
done < <(find ./tests -type f \( -name '*.out' -o -name '*.mem' \) -print0)

# for some reason Ubuntu 18.04 on Travis CI doesn't install gdb
function install_gdb() {
if [ "${CI}" = "true" ] && [ "$(command -v gdb 2>/dev/null)" = "" ]
then
(>&1 echo "Install gdb...")
sudo apt-get install --no-install-recommends --quiet --assume-yes gdb 1> /dev/null
fi
}

for i in /tmp/core.php.*; do
install_gdb
(>&1 printf "Found core dump file: %s\\n\\n" "$i")
gdb -q "$(phpenv which php)" "$i" <<EOF
set pagination 0
backtrace full
info registers
x/16i \$pc
thread apply all backtrace
quit
EOF
fi
done
71 changes: 35 additions & 36 deletions .ci/install-re2c.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,65 +8,64 @@
# the LICENSE file that was distributed with this source code.

if [ -z ${RE2C_VERSION+x} ]; then
>&2 echo "The RE2C_VERSION value is not set. Stop."
exit 1
>&2 echo "The RE2C_VERSION value is not set. Stop."
exit 1
fi

if [ "${RE2C_VERSION}" == "system" ]; then
echo "Use system re2c. Skip."
exit 0
echo "Use system re2c. Skip."
exit 0
fi

pkgname=re2c
source="https://github.com/skvadrik/${pkgname}/releases/download/${RE2C_VERSION}/${pkgname}-${RE2C_VERSION}.tar.gz"
source="https://github.com/skvadrik/${pkgname}/releases/download/${RE2C_VERSION}/${pkgname}-${RE2C_VERSION}.tar.xz"
downloaddir="${HOME}/.cache/${pkgname}/${pkgname}-${RE2C_VERSION}"
prefix="${HOME}/.local/opt/${pkgname}/${pkgname}-${RE2C_VERSION}"
bindir="${prefix}/bin"

if [ ! -f "${bindir}/re2c" ]; then
if [ ! -d `dirname ${downloaddir}` ]; then
mkdir -p `dirname ${downloaddir}`
fi

cd `dirname ${downloaddir}`
if [ ! -d `dirname ${downloaddir}` ]; then
mkdir -p `dirname ${downloaddir}`
fi
cd "$(dirname "$downloaddir")" || exit 1

if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then
curl -sSL "$source" -o "${pkgname}-${RE2C_VERSION}.tar.gz"
fi
if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.xz" ]; then
curl -sSL "$source" -o "${pkgname}-${RE2C_VERSION}.tar.xz"
fi

if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then
>&2 echo "Unable to locate ${pkgname}-${RE2C_VERSION}.tar.gz file. Stop."
exit 1
fi
if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.xz" ]; then
>&2 echo "Unable to locate ${pkgname}-${RE2C_VERSION}.tar.xz file. Stop."
exit 1
fi

if [ ! -d "${downloaddir}" ]; then
mkdir -p "${downloaddir}"
tar -zxf "${pkgname}-${RE2C_VERSION}.tar.gz"
fi
if [ ! -d "${downloaddir}" ]; then
mkdir -p "${downloaddir}"
tar -xf "${pkgname}-${RE2C_VERSION}.tar.xz" || exit 1
fi

if [ ! -d "${downloaddir}" ]; then
>&2 echo "Unable to locate re2c source. Stop."
exit 1
fi
if [ ! -d "${downloaddir}" ]; then
>&2 echo "Unable to locate re2c source. Stop."
exit 1
fi

if [ ! -d "${prefix}" ]; then
mkdir -p "${prefix}"
fi
if [ ! -d "${prefix}" ]; then
mkdir -p "${prefix}"
fi

cd "${downloaddir}"
./configure --prefix="${prefix}"
cd "${downloaddir}" || exit 1
./configure --prefix="${prefix}"

make -j"$(getconf _NPROCESSORS_ONLN)"
make install
make -j"$(getconf _NPROCESSORS_ONLN)"
make install
fi

if [ ! -x "${bindir}/re2c" ]; then
>&2 echo "Unable to locate re2c executable. Stop."
exit 1
>&2 echo "Unable to locate re2c executable. Stop."
exit 1
fi

mkdir -p ${HOME}/bin
ln -s "${bindir}/re2c" ${HOME}/bin/re2c
mkdir -p "${HOME}/bin"
ln -s "${bindir}/re2c" "${HOME}/bin/re2c"

re2c --version
exit 0
45 changes: 0 additions & 45 deletions .ci/run-tests.sh

This file was deleted.

46 changes: 30 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,13 @@ addons:

env:
global:
- MAKEJOBS="-j$(getconf _NPROCESSORS_ONLN)"
- COVERAGE=ON
- MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
- ZEND_DONT_UNLOAD_MODULES=1
- USE_ZEND_ALLOC=0
- TRAVIS_COMMIT_LOG=`git log --format=fuller -2`
matrix:
- RE2C_VERSION="0.13.6"
- RE2C_VERSION="1.1.1"
- RE2C_VERSION="1.2.1"

matrix:
fast_finish: true
Expand All @@ -43,33 +44,46 @@ cache:
before_install:
- phpenv config-rm xdebug.ini || true
- ulimit -c unlimited -S || true
- echo '/tmp/core.%e.%p.%t' | sudo tee /proc/sys/kernel/core_pattern

install:
- .ci/install-re2c.sh
- phpize
- |
./configure \
--with-php-config=$(phpenv which php-config) \
--enable-zephir-parser \
--enable-zephir-parser-debug \
--enable-coverage
- make $MAKEJOBS
./configure \
--with-php-config=$(phpenv which php-config) \
--enable-zephir-parser \
--enable-zephir-parser-debug \
--enable-coverage
- make

before_script:
- if [ $COVERAGE = "ON" ]; then make coverage-initial; fi
- make coverage-initial
- |
if [ "$(php-config --vernum)" -ge "70300" ]; then
echo "Patching PHP tests runner to silence messages about PHP memory leaks ¯\_(ツ)_/¯"
# TODO: Move to makefile
search_str="valgrind -q --tool=.* --trace-children=yes"
add_str="--suppressions=./tests/php-$(php-config --version | cut -d'.' -f1,2).supp"
sed -e "s|[\"']\($search_str\)[\"']|\"\1 $add_str\"|" run-tests.php > tmp.php
mv tmp.php run-tests.php
grep 'valgrind -q --tool=' run-tests.php
echo "Done"
fi
script:
- .ci/run-tests.sh
- make test NO_INTERACTION=1 REPORT_EXIT_STATUS=1 TEST_PHP_ARGS=-m

after_failure:
- echo "$($(phpenv which php) -v)"
- echo "$($(phpenv which php) -m)"
- .ci/after-failure.sh

after_success:
- |
if [ $COVERAGE = "ON" ]; then
make coverage-capture
bash <(curl -s https://codecov.io/bash)
fi
- make coverage-capture
- bash <(curl -s https://codecov.io/bash)

after_script:
- printf "$TRAVIS_COMMIT_RANGE\n"
Expand Down
15 changes: 7 additions & 8 deletions parser.mk
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,27 @@ clean: parser-clean tests-clean

.PHONY: parser-clean
parser-clean:
find . -name \*.loT -o -name \*.out | xargs rm -f
find . \( -name '*.loT' -o -name '*.out' \) -exec rm -f {} +
find ./parser \
-name zephir.c \
\( -name zephir.c \
-o -name zephir.h \
-o -name scanner.c \
-o -name parser.c | xargs rm -f
-o -name parser.c \) -exec rm -f {} +


.PHONY: tests-clean
tests-clean:
find ./tests -name \*.php -o -name \*.sh | xargs rm -f
find ./tests -name \*.diff -o -name \*.exp -o -name \*.log | xargs rm -f
find ./tests -name \*.tmp | xargs rm -f
find ./tests \( -name '*.php' -o -name '*.sh' \) -exec rm -f {} +
find ./tests \( -name '*.diff' -o -name '*.exp' \) -exec rm -f {} +
find ./tests \( -name '*.tmp' -o -name '*.mem' \) -exec rm -f {} +
find ./tests -name '*.log' -exec rm -f {} +

.PHONY: maintainer-clean
maintainer-clean:
@echo 'This command is intended for maintainers to use; it'
@echo 'deletes files that may need special tools to rebuild.'
@echo
-rm -f $(srcdir)/parser/lemon
-rm -f $(srcdir)/parser/scanner.c
-rm -f $(srcdir)/parser/parser.c

$(srcdir)/parser/scanner.c: $(srcdir)/parser/scanner.re
$(RE2C) $(RE2C_FLAGS) -d --no-generation-date -o $@ $<
Expand Down
29 changes: 24 additions & 5 deletions parser/zephir.lemon
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,36 @@
* the LICENSE file that was distributed with this source code.
*/

// All token codes are small integers with #defines that begin with "XX_"
%token_prefix XX_

// The type of the data attached to each token is xx_parser_token.
%token_type {xx_parser_token*}

// Default type for non-terminals is zval.
%default_type {zval}

// The generated parser function takes a 4th argument as follows:
%extra_argument {xx_parser_status *status}

%default_destructor {
if (&$$) {
zval_ptr_dtor(&$$);
}
}
%extra_argument {xx_parser_status *status}

// The name of the generated procedure that implements the parser
// is as follows:
%name xx_

// Define operator precedence early so that this is the first occurrence
// of the operator tokens in the grammer. Keeping the operators together
// causes them to be assigned integer values that are close together,
// which keeps parser tables smaller.
//
// The token values assigned to these symbols is determined by the order
// in which lemon first sees them.
%left INTERNAL PUBLIC PROTECTED STATIC PRIVATE SCOPED .

%left COMMA .
%right REQUIRE .
%right DOUBLEARROW .
Expand All @@ -45,16 +62,18 @@
%right SBRACKET_OPEN .
%right ARROW .

// The following text is included near the beginning of the C source
// code file that implements the parser.
%include {
#include "parser.h"
}
// end %include

// This code runs whenever there is a syntax error
%syntax_error {

zval syntax_error;

array_init(&syntax_error);

parser_add_str(&syntax_error, "type", "error");

if (status->scanner_state->start_length) {
Expand All @@ -80,7 +99,7 @@
}
}

program ::= xx_language(Q) . {
input ::= xx_language(Q) . {
status->ret = Q;
}

Expand Down
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
*.diff
*.php
*.log
*.mem
Loading

0 comments on commit 414f123

Please sign in to comment.