Skip to content

Commit 414f123

Browse files
authored
Merge pull request #79 from phalcon/feature/docs [skip appveyor]
Tests for memory leaks [skip appveyor]
2 parents 229e472 + 00cf312 commit 414f123

File tree

9 files changed

+328
-134
lines changed

9 files changed

+328
-134
lines changed

.ci/after-failure.sh

Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,39 +7,34 @@
77
# For the full copyright and license information, please view
88
# the LICENSE file that was distributed with this source code.
99

10-
$(phpenv which php) -v
11-
$(phpenv which php) -m
12-
13-
PROJECT_ROOT=$(readlink -enq "$(dirname $0)/../")
14-
cd ${PROJECT_ROOT}
15-
1610
shopt -s nullglob
1711

18-
for i in `find ./tests -name "*.out" 2>/dev/null`; do
19-
echo "-- START ${i}"; cat ${i}; echo "-- END";
20-
done
21-
22-
for i in `find ./tests -name "*.mem" 2>/dev/null`; do
23-
echo "-- START ${i}"; cat ${i}; echo "-- END";
24-
done
25-
26-
if [ -f "./configure.log" ]; then
27-
cat "./configure.log"
28-
fi
29-
30-
ls -al ${PROJECT_ROOT}
31-
3212
export LC_ALL=C
3313

34-
for i in core core.*; do
35-
if [ -f "$i" -a "$(file "$i" | grep -o 'core file')" ]; then
36-
gdb -q $(file "${i}" | grep -oE "'[^ ']+" | sed "s/^'//g") "$i" <<EOF
14+
while IFS= read -r -d '' file
15+
do
16+
(( count++ ))
17+
(>&1 printf ">>> START (%d)\\n%s\\n<<< END (%d)\\n\\n" $count "$(cat "$file")" $count)
18+
done < <(find ./tests -type f \( -name '*.out' -o -name '*.mem' \) -print0)
19+
20+
# for some reason Ubuntu 18.04 on Travis CI doesn't install gdb
21+
function install_gdb() {
22+
if [ "${CI}" = "true" ] && [ "$(command -v gdb 2>/dev/null)" = "" ]
23+
then
24+
(>&1 echo "Install gdb...")
25+
sudo apt-get install --no-install-recommends --quiet --assume-yes gdb 1> /dev/null
26+
fi
27+
}
28+
29+
for i in /tmp/core.php.*; do
30+
install_gdb
31+
(>&1 printf "Found core dump file: %s\\n\\n" "$i")
32+
gdb -q "$(phpenv which php)" "$i" <<EOF
3733
set pagination 0
3834
backtrace full
3935
info registers
4036
x/16i \$pc
4137
thread apply all backtrace
4238
quit
4339
EOF
44-
fi
4540
done

.ci/install-re2c.sh

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -8,65 +8,64 @@
88
# the LICENSE file that was distributed with this source code.
99

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

1515
if [ "${RE2C_VERSION}" == "system" ]; then
16-
echo "Use system re2c. Skip."
17-
exit 0
16+
echo "Use system re2c. Skip."
17+
exit 0
1818
fi
1919

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

2626
if [ ! -f "${bindir}/re2c" ]; then
27-
if [ ! -d `dirname ${downloaddir}` ]; then
28-
mkdir -p `dirname ${downloaddir}`
29-
fi
30-
31-
cd `dirname ${downloaddir}`
27+
if [ ! -d `dirname ${downloaddir}` ]; then
28+
mkdir -p `dirname ${downloaddir}`
29+
fi
30+
cd "$(dirname "$downloaddir")" || exit 1
3231

33-
if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.gz" ]; then
34-
curl -sSL "$source" -o "${pkgname}-${RE2C_VERSION}.tar.gz"
35-
fi
32+
if [ ! -f "${pkgname}-${RE2C_VERSION}.tar.xz" ]; then
33+
curl -sSL "$source" -o "${pkgname}-${RE2C_VERSION}.tar.xz"
34+
fi
3635

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

42-
if [ ! -d "${downloaddir}" ]; then
43-
mkdir -p "${downloaddir}"
44-
tar -zxf "${pkgname}-${RE2C_VERSION}.tar.gz"
45-
fi
41+
if [ ! -d "${downloaddir}" ]; then
42+
mkdir -p "${downloaddir}"
43+
tar -xf "${pkgname}-${RE2C_VERSION}.tar.xz" || exit 1
44+
fi
4645

47-
if [ ! -d "${downloaddir}" ]; then
48-
>&2 echo "Unable to locate re2c source. Stop."
49-
exit 1
50-
fi
46+
if [ ! -d "${downloaddir}" ]; then
47+
>&2 echo "Unable to locate re2c source. Stop."
48+
exit 1
49+
fi
5150

52-
if [ ! -d "${prefix}" ]; then
53-
mkdir -p "${prefix}"
54-
fi
51+
if [ ! -d "${prefix}" ]; then
52+
mkdir -p "${prefix}"
53+
fi
5554

56-
cd "${downloaddir}"
57-
./configure --prefix="${prefix}"
55+
cd "${downloaddir}" || exit 1
56+
./configure --prefix="${prefix}"
5857

59-
make -j"$(getconf _NPROCESSORS_ONLN)"
60-
make install
58+
make -j"$(getconf _NPROCESSORS_ONLN)"
59+
make install
6160
fi
6261

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

68-
mkdir -p ${HOME}/bin
69-
ln -s "${bindir}/re2c" ${HOME}/bin/re2c
67+
mkdir -p "${HOME}/bin"
68+
ln -s "${bindir}/re2c" "${HOME}/bin/re2c"
7069

7170
re2c --version
7271
exit 0

.ci/run-tests.sh

Lines changed: 0 additions & 45 deletions
This file was deleted.

.travis.yml

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@ addons:
2323

2424
env:
2525
global:
26-
- MAKEJOBS="-j$(getconf _NPROCESSORS_ONLN)"
27-
- COVERAGE=ON
26+
- MAKEFLAGS="-j$(getconf _NPROCESSORS_ONLN)"
27+
- ZEND_DONT_UNLOAD_MODULES=1
28+
- USE_ZEND_ALLOC=0
2829
- TRAVIS_COMMIT_LOG=`git log --format=fuller -2`
2930
matrix:
3031
- RE2C_VERSION="0.13.6"
31-
- RE2C_VERSION="1.1.1"
32+
- RE2C_VERSION="1.2.1"
3233

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

4749
install:
4850
- .ci/install-re2c.sh
4951
- phpize
5052
- |
51-
./configure \
52-
--with-php-config=$(phpenv which php-config) \
53-
--enable-zephir-parser \
54-
--enable-zephir-parser-debug \
55-
--enable-coverage
56-
- make $MAKEJOBS
53+
./configure \
54+
--with-php-config=$(phpenv which php-config) \
55+
--enable-zephir-parser \
56+
--enable-zephir-parser-debug \
57+
--enable-coverage
58+
- make
5759

5860
before_script:
59-
- if [ $COVERAGE = "ON" ]; then make coverage-initial; fi
61+
- make coverage-initial
62+
- |
63+
if [ "$(php-config --vernum)" -ge "70300" ]; then
64+
echo "Patching PHP tests runner to silence messages about PHP memory leaks ¯\_(ツ)_/¯"
65+
66+
# TODO: Move to makefile
67+
search_str="valgrind -q --tool=.* --trace-children=yes"
68+
add_str="--suppressions=./tests/php-$(php-config --version | cut -d'.' -f1,2).supp"
69+
sed -e "s|[\"']\($search_str\)[\"']|\"\1 $add_str\"|" run-tests.php > tmp.php
70+
mv tmp.php run-tests.php
71+
grep 'valgrind -q --tool=' run-tests.php
72+
73+
echo "Done"
74+
fi
6075
6176
script:
62-
- .ci/run-tests.sh
77+
- make test NO_INTERACTION=1 REPORT_EXIT_STATUS=1 TEST_PHP_ARGS=-m
6378

6479
after_failure:
80+
- echo "$($(phpenv which php) -v)"
81+
- echo "$($(phpenv which php) -m)"
6582
- .ci/after-failure.sh
6683

6784
after_success:
68-
- |
69-
if [ $COVERAGE = "ON" ]; then
70-
make coverage-capture
71-
bash <(curl -s https://codecov.io/bash)
72-
fi
85+
- make coverage-capture
86+
- bash <(curl -s https://codecov.io/bash)
7387

7488
after_script:
7589
- printf "$TRAVIS_COMMIT_RANGE\n"

parser.mk

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,27 @@ clean: parser-clean tests-clean
1313

1414
.PHONY: parser-clean
1515
parser-clean:
16-
find . -name \*.loT -o -name \*.out | xargs rm -f
16+
find . \( -name '*.loT' -o -name '*.out' \) -exec rm -f {} +
1717
find ./parser \
18-
-name zephir.c \
18+
\( -name zephir.c \
1919
-o -name zephir.h \
2020
-o -name scanner.c \
21-
-o -name parser.c | xargs rm -f
21+
-o -name parser.c \) -exec rm -f {} +
2222

2323

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

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

3938
$(srcdir)/parser/scanner.c: $(srcdir)/parser/scanner.re
4039
$(RE2C) $(RE2C_FLAGS) -d --no-generation-date -o $@ $<

parser/zephir.lemon

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,36 @@
88
* the LICENSE file that was distributed with this source code.
99
*/
1010

11+
// All token codes are small integers with #defines that begin with "XX_"
1112
%token_prefix XX_
13+
14+
// The type of the data attached to each token is xx_parser_token.
1215
%token_type {xx_parser_token*}
16+
17+
// Default type for non-terminals is zval.
1318
%default_type {zval}
19+
20+
// The generated parser function takes a 4th argument as follows:
21+
%extra_argument {xx_parser_status *status}
22+
1423
%default_destructor {
1524
if (&$$) {
1625
zval_ptr_dtor(&$$);
1726
}
1827
}
19-
%extra_argument {xx_parser_status *status}
28+
29+
// The name of the generated procedure that implements the parser
30+
// is as follows:
2031
%name xx_
2132

33+
// Define operator precedence early so that this is the first occurrence
34+
// of the operator tokens in the grammer. Keeping the operators together
35+
// causes them to be assigned integer values that are close together,
36+
// which keeps parser tables smaller.
37+
//
38+
// The token values assigned to these symbols is determined by the order
39+
// in which lemon first sees them.
2240
%left INTERNAL PUBLIC PROTECTED STATIC PRIVATE SCOPED .
23-
2441
%left COMMA .
2542
%right REQUIRE .
2643
%right DOUBLEARROW .
@@ -45,16 +62,18 @@
4562
%right SBRACKET_OPEN .
4663
%right ARROW .
4764

65+
// The following text is included near the beginning of the C source
66+
// code file that implements the parser.
4867
%include {
4968
#include "parser.h"
5069
}
70+
// end %include
5171

72+
// This code runs whenever there is a syntax error
5273
%syntax_error {
53-
5474
zval syntax_error;
5575

5676
array_init(&syntax_error);
57-
5877
parser_add_str(&syntax_error, "type", "error");
5978

6079
if (status->scanner_state->start_length) {
@@ -80,7 +99,7 @@
8099
}
81100
}
82101

83-
program ::= xx_language(Q) . {
102+
input ::= xx_language(Q) . {
84103
status->ret = Q;
85104
}
86105

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
*.diff
55
*.php
66
*.log
7+
*.mem

0 commit comments

Comments
 (0)