Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Phpt for extension running in workflow #24

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build-native.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ jobs:
run: |
uname -a
echo "Detected CPUs: $(nproc)"
echo "User: ${CURRENT_UID}:${CURRENT_GID}"
echo "User: $(id -u):$(id -g)}"
echo "PWD: ${PWD}"
echo "Arch: ${BUILD_ARCHITECTURE}"
docker run --rm -t -u ${CURRENT_UID}:${CURRENT_GID} -v ${PWD}:/source -w /source/prod/native elasticobservability/apm-agent-php-dev:native-build-gcc-12.2.0-${BUILD_ARCHITECTURE}-0.0.2 sh -c "cmake --preset ${BUILD_ARCHITECTURE}-release && cmake --build --preset ${BUILD_ARCHITECTURE}-release && ctest --preset ${BUILD_ARCHITECTURE}-release --verbose"
docker run --rm -t -u : -v ${PWD}:/source -w /source/prod/native elasticobservability/apm-agent-php-dev:native-build-gcc-12.2.0-${BUILD_ARCHITECTURE}-0.0.2 sh -c "cmake --preset ${BUILD_ARCHITECTURE}-release && cmake --build --preset ${BUILD_ARCHITECTURE}-release && ctest --preset ${BUILD_ARCHITECTURE}-release --verbose"

- uses: actions/upload-artifact@v4
with:
name: build-native-${{ matrix.arch }}
path: |
prod/native/_build/${{ matrix.arch }}-release/ext/elastic_otel_php*.so
prod/native/_build/${{ matrix.arch }}-release/ext/elastic_otel_php*.debug
prod/native/_build/${{ matrix.arch }}-release/extension/code/elastic_otel_php*.so
prod/native/_build/${{ matrix.arch }}-release/extension/code/elastic_otel_php*.debug
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_otel_php_loader.so
prod/native/_build/${{ matrix.arch }}-release/loader/code/elastic_otel_php_loader.debug
2 changes: 1 addition & 1 deletion .github/workflows/build-packages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ jobs:
echo "Creating debug symbols artifacts"
DBGSYM="${PWD}/build/packages/elastic-otel-php-debugsymbols-${{ matrix.arch }}.tar.gz"
pushd prod/native/_build/${{ matrix.arch }}-release
tar --transform 's/.*\///g' -zcvf ${DBGSYM} ext/*.debug loader/code/*.debug
tar --transform 's/.*\///g' -zcvf ${DBGSYM} extension/code/*.debug loader/code/*.debug
popd

pushd "${PWD}/build/packages"
Expand Down
8 changes: 6 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,12 @@ jobs:
needs:
- build-native
uses: ./.github/workflows/build-packages.yml



tests-phpt:
needs:
- build-native
uses: ./.github/workflows/test-phpt.yml


# The very last job to report whether the Workflow passed.
# This will act as the Branch Protection gatekeeper
Expand Down
76 changes: 76 additions & 0 deletions .github/workflows/test-phpt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
---

# Runs the build based on the provided files in test.yml
name: build

on:
workflow_call:
inputs:
build_arch:
required: false
type: string
default: 'x86_64'
workflow_dispatch:
inputs:
build_arch:
type: choice
description: Build architecture
default: 'x86_64'
options:
- all
- x86_64
- arm64

jobs:
setup-build-matrix:
uses: ./.github/workflows/build-arch-matrix-generator.yml
with:
build_arch: ${{ inputs.build_arch }}

test-phpt:
name: test-phpt
runs-on: ubuntu-latest
needs: setup-build-matrix
timeout-minutes: 300
strategy:
fail-fast: false
matrix: ${{ fromJson(needs.setup-build-matrix.outputs.matrix-combinations) }}
env:
BUILD_ARCHITECTURE: ${{ matrix.arch }}
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v4
with:
name: build-native-${{ matrix.arch }}
path: prod/native/_build/${{ matrix.arch }}-release/
- if: ${{ matrix.run_qemu }}
uses: docker/setup-qemu-action@v3
with:
platforms: arm64
- name: Run phpt tests
run: |
uname -a
echo "Arch: ${BUILD_ARCHITECTURE}"
pushd prod/native/extension/phpt

mkdir ${PWD}/results

PHP_VERSIONS=( 80 81 82 83 )

for PHP_VERSION in "${PHP_VERSIONS[@]}"
do
./run.sh -b ${BUILD_ARCHITECTURE} -p ${PHP_VERSION} -f ${PWD}/results/phpt-${PHP_VERSION}.tar.gz || TEST_ERROR=1
done
popd

if [ $TEST_ERROR -eq 1 ]; then
echo "Some tests failed"
exit 1
fi
- uses: actions/upload-artifact@v4
if: failure()
with:
name: test-phpt-failures-${{ matrix.arch }}
path: |
prod/native/extension/phpt/results/*

2 changes: 1 addition & 1 deletion packaging/nfpm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ contents:
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/loader/code/elastic_otel_php_loader.so
dst: /opt/elastic/elastic-otel-php/
expand: true
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/ext/elastic_otel_php_*.so
- src: /source/prod/native/_build/${ELASTIC_OTEL_PHP_PLATFORM}-release/extension/code/elastic_otel_php_*.so
dst: /opt/elastic/elastic-otel-php/
expand: true
- src: /source/prod/php
Expand Down
3 changes: 1 addition & 2 deletions prod/native/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -119,5 +119,4 @@ enable_testing()
add_subdirectory(libcommon)
add_subdirectory(libphpbridge)
add_subdirectory(loader)

add_subdirectory(ext)
add_subdirectory(extension)
2 changes: 2 additions & 0 deletions prod/native/extension/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

add_subdirectory(code)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
8 changes: 8 additions & 0 deletions prod/native/extension/phpt/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
tests/*.sh
tests/*.diff
tests/*.exp
tests/*.log
tests/*.php



94 changes: 94 additions & 0 deletions prod/native/extension/phpt/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
#!/bin/bash

function show_help {

echo -e "$0 -b build_architecture -p php_version [-t tests]

Arguments description:
-b build_architecture required, architecture of agent so library, f.ex. linux-x86-64
-p php_version PHP version f.ex. 80 or 83
-t tests Tests to run, folder or particular test file name. Default: tests
-f path Generate test failures archive and save it in path
-h print this help
"
}

TESTS_TO_RUN=tests

while getopts "b:p:t:f:h" opt; do
case "$opt" in
h|\?)
show_help
exit 0
;;
b) BUILD_ARCHITECTURE="${OPTARG}"
;;
p) PHP_VERSION="${OPTARG}"
;;
t) TESTS_TO_RUN="${OPTARG}"
;;
f) TESTS_FAILURES_ARCHIVE="${OPTARG}"
;;
esac
done

if [ -z "${BUILD_ARCHITECTURE}" ] || [ -z "${PHP_VERSION}" ]; then
show_help
exit 1
fi

ELASTIC_AGENT_SO_PATH=${PWD}/../../_build/${BUILD_ARCHITECTURE}-release/extension/code/elastic_otel_php_${PHP_VERSION}.so
if [ ! -f ${ELASTIC_AGENT_SO_PATH} ]; then
echo "Native build not found: '${ELASTIC_AGENT_SO_PATH}'"
exit 1
fi

if [[ ! "${BUILD_ARCHITECTURE}" =~ "musl" ]]; then
echo "Running using glibc docker image";
else
echo "Running using musl docker image";
ALPINE_IMAGE=-alpine
fi

ELASTIC_AGENT_PHP_PATH=${PWD}/../../../php


LOCAL_TMP_DIR=$(mktemp -d)

LOCAL_LOG_FAILED_TESTS=${LOCAL_TMP_DIR}/test-run-failures.log
touch ${LOCAL_LOG_FAILED_TESTS}

LOCAL_LOG_TEST_RUN=${LOCAL_TMP_DIR}/test-run.log
touch ${LOCAL_LOG_TEST_RUN}

LOG_FAILED_TESTS=/phpt-tests/test-run-failures.log
LOG_TEST_RUN=/phpt-tests/test-run.log

RUN_TESTS=/usr/local/lib/php/build/run-tests.php

# copy test folder or test file into temp folder
mkdir -p ${LOCAL_TMP_DIR}/$(dirname ${TESTS_TO_RUN})
cp -R ${TESTS_TO_RUN} ${LOCAL_TMP_DIR}/${TESTS_TO_RUN}

docker run --rm \
-v ${LOCAL_TMP_DIR}/tests:/phpt-tests/tests \
-v ./tests_util:/phpt-tests/tests_util \
-v ${LOCAL_LOG_FAILED_TESTS}:${LOG_FAILED_TESTS} \
-v ${LOCAL_LOG_TEST_RUN}:${LOG_TEST_RUN} \
-v ${ELASTIC_AGENT_PHP_PATH}:/elastic/php \
-v ${ELASTIC_AGENT_SO_PATH}:/elastic/elastic_otel_php.so \
-w /phpt-tests \
php:${PHP_VERSION:0:1}.${PHP_VERSION:1:1}-cli${ALPINE_IMAGE} sh -c "php -n ${RUN_TESTS} -w ${LOG_FAILED_TESTS} ${TESTS_TO_RUN} 2>&1 | tee ${LOG_TEST_RUN}"

if [ -s ${LOCAL_LOG_FAILED_TESTS} ]; then
echo "Test failed"

pushd ${LOCAL_TMP_DIR}
tar -czf ${TESTS_FAILURES_ARCHIVE} .
popd
rm -rf ${LOCAL_TMP_DIR}

exit 1
fi

rm -rf ${LOCAL_TMP_DIR}
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 0 (in this case using environment variable) s
ELASTIC_APM_ENABLED=0
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("getenv('ELASTIC_APM_ENABLED')", getenv('ELASTIC_APM_ENABLED'), '0');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 0 (in this case using ini file) should be int
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
elastic_apm.enabled=0
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("ini_get('elastic_apm.enabled')", ini_get('elastic_apm.enabled'), '0');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 1 (in this case using environment variable) s
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
ELASTIC_APM_ENABLED=1
--INI--
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("getenv('ELASTIC_APM_ENABLED')", getenv('ELASTIC_APM_ENABLED'), '1');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 1 (in this case using ini file) should be int
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
elastic_apm.enabled=1
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("ini_get('elastic_apm.enabled')", ini_get('elastic_apm.enabled'), '1');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 'FaLSe' (in this case using environment varia
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
ELASTIC_APM_ENABLED=FaLSe
--INI--
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("getenv('ELASTIC_APM_ENABLED')", getenv('ELASTIC_APM_ENABLED'), 'FaLSe');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 'FaLSe' (in this case using ini file) should
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
elastic_apm.enabled=FaLSe
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertEqual("ini_get('elastic_apm.enabled')", ini_get('elastic_apm.enabled'), false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 'no' (in this case using environment variable
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
ELASTIC_APM_ENABLED=No
--INI--
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("getenv('ELASTIC_APM_ENABLED')", getenv('ELASTIC_APM_ENABLED'), 'No');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 'no' (in this case using ini file) should be
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
elastic_apm.enabled=No
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertEqual("ini_get('elastic_apm.enabled')", ini_get('elastic_apm.enabled'), false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Boolean configuration option value 'OFF' (in this case using environment variabl
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
ELASTIC_APM_ENABLED=OFF
--INI--
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertSame("getenv('ELASTIC_APM_ENABLED')", getenv('ELASTIC_APM_ENABLED'), 'OFF');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ Boolean configuration option value 'OFF' (in this case using ini file) should be
--ENV--
ELASTIC_APM_LOG_LEVEL_STDERR=CRITICAL
--INI--
extension=/elastic/elastic_otel_php.so
elastic_apm.bootstrap_php_part_file=/elastic/php/bootstrap_php_part.php
elastic_apm.enabled=OFF
elastic_apm.bootstrap_php_part_file=../../php/bootstrap_php_part.php
--FILE--
<?php
declare(strict_types=1);
require __DIR__ . '/../tests_util/tests_util.php';
require __DIR__ . '/includes/tests_util.inc';

elasticApmAssertEqual("ini_get('elastic_apm.enabled')", ini_get('elastic_apm.enabled'), false);

Expand Down
Loading
Loading