From f090511213e1832f07c8e09a0aba8a6daa2c6b3d Mon Sep 17 00:00:00 2001 From: Justin Boswell Date: Wed, 13 Jan 2021 13:33:30 -0800 Subject: [PATCH] Initial Tests & CI (#5) * Added awscrt_version() and test for it * Added builder.json for CI * Added github actions * Added format-check.sh * Force php5.6 on ubuntu * Updated submodules --- .github/PULL_REQUEST_TEMPLATE.md | 6 ++ .github/workflows/ci.yml | 111 +++++++++++++++++++++++++++++ .github/workflows/clang-format.yml | 18 +++++ builder.json | 37 ++++++++++ config.m4 | 1 + crt/aws-c-auth | 2 +- crt/aws-c-cal | 2 +- crt/aws-c-common | 2 +- crt/aws-c-compression | 2 +- crt/aws-c-http | 2 +- crt/aws-c-io | 2 +- crt/s2n | 2 +- format-check.sh | 24 +++++++ src/crt.c | 41 +++++++---- tests/awscrt_000.phpt | 15 ++++ tests/common.inc | 3 + tests/skipif.inc | 3 + 17 files changed, 252 insertions(+), 21 deletions(-) create mode 100644 .github/PULL_REQUEST_TEMPLATE.md create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/clang-format.yml create mode 100644 builder.json create mode 100755 format-check.sh create mode 100644 tests/awscrt_000.phpt create mode 100644 tests/common.inc create mode 100644 tests/skipif.inc diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md new file mode 100644 index 0000000..ab40d21 --- /dev/null +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -0,0 +1,6 @@ +*Issue #, if available:* + +*Description of changes:* + + +By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license. diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..7cca4a6 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,111 @@ +name: CI + +on: + push: + branches: + - '*' + - '!main' + +env: + BUILDER_VERSION: v0.7.7 + BUILDER_SOURCE: releases + BUILDER_HOST: https://d19elf31gohf1l.cloudfront.net + PACKAGE_NAME: aws-crt-php + LINUX_BASE_IMAGE: ubuntu-16-x64 + RUN: ${{ github.run_id }}-${{ github.run_number }} + +jobs: + al2: + runs-on: ubuntu-latest + steps: + # We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages + - name: Build ${{ env.PACKAGE_NAME }} + consumers + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin + export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-al2-x64:${{ env.BUILDER_VERSION }} + docker pull $DOCKER_IMAGE + docker run --env GITHUB_REF --env LC_ALL=C.UTF-8 $DOCKER_IMAGE --version=${{env.BUILDER_VERSION}} build -p ${{ env.PACKAGE_NAME }} --spec=downstream + + clang-compat: + runs-on: ubuntu-latest + strategy: + matrix: + version: [3, 6, 8, 9] + steps: + # We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages + - name: Build ${{ env.PACKAGE_NAME }} + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin + export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }} + docker pull $DOCKER_IMAGE + docker run --env GITHUB_REF --env LC_ALL=C.UTF-8 $DOCKER_IMAGE --version=${{env.BUILDER_VERSION}} build -p ${{ env.PACKAGE_NAME }} --spec=downstream --compiler=clang-${{ matrix.version }} + + gcc-compat: + runs-on: ubuntu-latest + strategy: + matrix: + version: [4.8, 5, 6, 7, 8] + fail-fast: false + steps: + # We can't use the `uses: docker://image` version yet, GitHub lacks authentication for actions -> packages + - name: Build ${{ env.PACKAGE_NAME }} + run: | + echo "${{ secrets.GITHUB_TOKEN }}" | docker login docker.pkg.github.com -u awslabs --password-stdin + export DOCKER_IMAGE=docker.pkg.github.com/awslabs/aws-crt-builder/aws-crt-${{ env.LINUX_BASE_IMAGE }}:${{ env.BUILDER_VERSION }} + docker pull $DOCKER_IMAGE + docker run --env GITHUB_REF --env LC_ALL=C.UTF-8 $DOCKER_IMAGE --version=${{env.BUILDER_VERSION}} build -p ${{ env.PACKAGE_NAME }} --spec=downstream --compiler=gcc-${{ matrix.version }} + +# linux-arm: +# name: ARM (${{ matrix.arch }}) +# runs-on: ubuntu-latest +# strategy: +# matrix: +# arch: [armv6, armv7, arm64] +# steps: +# - name: Build ${{ env.PACKAGE_NAME }} +# run: | +# python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')" +# chmod a+x builder +# ./builder build -p ${{ env.PACKAGE_NAME }} --target=linux-${{ matrix.arch }} --spec=downstream + + # windows-vc16: + # runs-on: windows-latest + # strategy: + # matrix: + # arch: [x64] + # steps: + # - uses: ilammy/msvc-dev-cmd@v1 + # with: + # arch: ${{ matrix.arch }} + # uwp: false + # spectre: true + # - name: Build ${{ env.PACKAGE_NAME }} + consumers + # run: | + # python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')" + # python builder.pyz build -p ${{ env.PACKAGE_NAME }} --spec=downstream + + # windows-vc14: + # runs-on: windows-latest + # strategy: + # matrix: + # arch: [x86, x64] + # steps: + # - uses: ilammy/msvc-dev-cmd@v1 + # with: + # toolset: 14.0 + # arch: ${{ matrix.arch }} + # uwp: false + # spectre: true + # - name: Build ${{ env.PACKAGE_NAME }} + consumers + # run: | + # python -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder.pyz')" + # python builder.pyz build -p ${{ env.PACKAGE_NAME }} downstream + + # osx: + # runs-on: macos-latest + # steps: + # - name: Build ${{ env.PACKAGE_NAME }} + consumers + # run: | + # python3 -c "from urllib.request import urlretrieve; urlretrieve('${{ env.BUILDER_HOST }}/${{ env.BUILDER_SOURCE }}/${{ env.BUILDER_VERSION }}/builder.pyz?run=${{ env.RUN }}', 'builder')" + # chmod a+x builder + # ./builder build -p ${{ env.PACKAGE_NAME }} --spec=downstream diff --git a/.github/workflows/clang-format.yml b/.github/workflows/clang-format.yml new file mode 100644 index 0000000..c784771 --- /dev/null +++ b/.github/workflows/clang-format.yml @@ -0,0 +1,18 @@ +name: Lint + +on: [push] + +jobs: + clang-format: + + runs-on: ubuntu-latest + + steps: + - name: Checkout Sources + uses: actions/checkout@v1 + + - name: clang-format lint + uses: DoozyX/clang-format-lint-action@v0.3.1 + with: + # List of extensions to check + extensions: c,h diff --git a/builder.json b/builder.json new file mode 100644 index 0000000..d57286e --- /dev/null +++ b/builder.json @@ -0,0 +1,37 @@ +{ + "name": "aws-crt-php", + "hosts": { + "ubuntu": { + "pkg_setup": [ + "add-apt-repository -y ppa:ondrej/php" + ], + "packages": [ + "autotools-dev", + "autoconf", + "libtool", + "clang", + "php5.6-dev" + ] + }, + "al2": { + "packages": [ + "autoconf", + "automake", + "libtool", + "clang", + "php-devel" + ] + } + }, + "build_steps": [ + ["phpize"], + ["./configure"], + ["make"] + ], + "test_env": { + "NO_INTERACTION": "1" + }, + "test_steps": [ + ["make", "test"] + ] +} diff --git a/config.m4 b/config.m4 index c087559..eeb4759 100644 --- a/config.m4 +++ b/config.m4 @@ -10,6 +10,7 @@ if test "$PHP_AWSCRT" != "no"; then cwd=`pwd` CRT_LIBPATHS="-L${cwd}/build/install/lib64 -L${cwd}/build/install/lib" CRT_LIBS="-laws-c-auth -laws-c-http -laws-c-cal -laws-c-io -laws-c-compression -laws-c-common -ls2n -l:libcrypto.a" + PHP_ADD_INCLUDE(${cwd}/build/install/include) PHP_EVAL_LIBLINE([$CRT_LIBPATHS $CRT_LIBS], AWSCRT_SHARED_LIBADD) # Shoves the linker line into the Makefile diff --git a/crt/aws-c-auth b/crt/aws-c-auth index a492570..f58e202 160000 --- a/crt/aws-c-auth +++ b/crt/aws-c-auth @@ -1 +1 @@ -Subproject commit a492570cfd0708b56df9efdbf85dfa64ee16579d +Subproject commit f58e2028d183e0e889728249a5aa5097d58a5e5c diff --git a/crt/aws-c-cal b/crt/aws-c-cal index df5da3a..61d6674 160000 --- a/crt/aws-c-cal +++ b/crt/aws-c-cal @@ -1 +1 @@ -Subproject commit df5da3af5b8cb2ad70cb591504bb25d6a74f3ab4 +Subproject commit 61d66740b1469a0caef09932621e3e92ee3967e2 diff --git a/crt/aws-c-common b/crt/aws-c-common index 1efe886..fe6ff91 160000 --- a/crt/aws-c-common +++ b/crt/aws-c-common @@ -1 +1 @@ -Subproject commit 1efe886005caa9568b132f34ba93cce8c4a4bc1e +Subproject commit fe6ff914db8211e3e03da2d730cfefa4d151892b diff --git a/crt/aws-c-compression b/crt/aws-c-compression index 826d92c..f2be13a 160000 --- a/crt/aws-c-compression +++ b/crt/aws-c-compression @@ -1 +1 @@ -Subproject commit 826d92cc39ea4c4a1a2a0ca5dccfdf9397c9a9f4 +Subproject commit f2be13afe410611fcac07b6519b96ce1ad4e4831 diff --git a/crt/aws-c-http b/crt/aws-c-http index cad6279..3836661 160000 --- a/crt/aws-c-http +++ b/crt/aws-c-http @@ -1 +1 @@ -Subproject commit cad62791f14396479e683122ce0ddb7be6967d54 +Subproject commit 3836661844973ae270c8d0beba5273415c5313d7 diff --git a/crt/aws-c-io b/crt/aws-c-io index 7012798..3baeef9 160000 --- a/crt/aws-c-io +++ b/crt/aws-c-io @@ -1 +1 @@ -Subproject commit 701279844ae43f9d275171bbdc80fcb1ba5a0065 +Subproject commit 3baeef9906519363c0e72e3851bf31c9d656af37 diff --git a/crt/s2n b/crt/s2n index 2a7cebb..3c7ae5f 160000 --- a/crt/s2n +++ b/crt/s2n @@ -1 +1 @@ -Subproject commit 2a7cebb0d7c00f5577629c9372cc1e4688cbb774 +Subproject commit 3c7ae5f57aadf53d85e134e6057b45cbec80ca35 diff --git a/format-check.sh b/format-check.sh new file mode 100755 index 0000000..ca5af09 --- /dev/null +++ b/format-check.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [[ -z $CLANG_FORMAT ]] ; then + CLANG_FORMAT=clang-format +fi + +if NOT type $CLANG_FORMAT 2> /dev/null ; then + echo "No appropriate clang-format found." + exit 1 +fi + +FAIL=0 +SOURCE_FILES=`find src -type f \( -name '*.h' -o -name '*.c' \)` +for i in $SOURCE_FILES +do + $CLANG_FORMAT -output-replacements-xml $i | grep -c " /dev/null + if [ $? -ne 1 ] + then + echo "$i failed clang-format check." + FAIL=1 + fi +done + +exit $FAIL diff --git a/src/crt.c b/src/crt.c index d5c88e4..e88ae8e 100644 --- a/src/crt.c +++ b/src/crt.c @@ -9,34 +9,45 @@ ZEND_DECLARE_MODULE_GLOBALS(awscrt); PHP_INI_BEGIN() -STD_PHP_INI_ENTRY("awscrt.log_level", "", PHP_INI_ALL, OnUpdateLongGEZero, log_level, zend_awscrt_globals, awscrt_globals) +STD_PHP_INI_ENTRY("awscrt.log_level", "", PHP_INI_ALL, OnUpdateLongGEZero, + log_level, zend_awscrt_globals, awscrt_globals) PHP_INI_END() -static PHP_MINIT_FUNCTION(awscrt) -{ - REGISTER_INI_ENTRIES(); - return SUCCESS; +static PHP_MINIT_FUNCTION(awscrt) { + REGISTER_INI_ENTRIES(); + return SUCCESS; } -static PHP_MSHUTDOWN_FUNCTION(awscrt) -{ - UNREGISTER_INI_ENTRIES(); +static PHP_MSHUTDOWN_FUNCTION(awscrt) { + UNREGISTER_INI_ENTRIES(); - return SUCCESS; + return SUCCESS; } -static PHP_GINIT_FUNCTION(awscrt) -{ +static PHP_GINIT_FUNCTION(awscrt) { #if defined(COMPILE_DL_ASTKIT) && defined(ZTS) - ZEND_TSRMLS_CACHE_UPDATE(); + ZEND_TSRMLS_CACHE_UPDATE(); #endif - awscrt_globals->log_level = 0; + awscrt_globals->log_level = 0; } +ZEND_BEGIN_ARG_INFO(awscrt_version_arginfo, 0) +ZEND_END_ARG_INFO() + +PHP_FUNCTION(awscrt_version) { + static const char *version = "1.0.0-dev"; + RETURN_STRING(version, 0); +} +/* clang-format off */ +const zend_function_entry awscrt_functions[] = { + PHP_FE(awscrt_version, awscrt_version_arginfo) + PHP_FE_END +}; + zend_module_entry awscrt_module_entry = { STANDARD_MODULE_HEADER, "awscrt", - NULL, /* functions */ + awscrt_functions, /* functions */ PHP_MINIT(awscrt), PHP_MSHUTDOWN(awscrt), NULL, /* RINIT */ @@ -49,6 +60,8 @@ zend_module_entry awscrt_module_entry = { NULL, /* RPOSTSHUTDOWN */ STANDARD_MODULE_PROPERTIES_EX}; +/* clang-format on */ + #ifdef COMPILE_DL_AWSCRT ZEND_GET_MODULE(awscrt) #endif diff --git a/tests/awscrt_000.phpt b/tests/awscrt_000.phpt new file mode 100644 index 0000000..e7daeba --- /dev/null +++ b/tests/awscrt_000.phpt @@ -0,0 +1,15 @@ +--TEST-- +Version: Simple function call +--SKIPIF-- + +--FILE-- + +===DONE=== +--EXPECT-- +1.0.0-dev diff --git a/tests/common.inc b/tests/common.inc new file mode 100644 index 0000000..de45b95 --- /dev/null +++ b/tests/common.inc @@ -0,0 +1,3 @@ + diff --git a/tests/skipif.inc b/tests/skipif.inc new file mode 100644 index 0000000..f0ac746 --- /dev/null +++ b/tests/skipif.inc @@ -0,0 +1,3 @@ +