From 86f215a98250088189118547147ed1f2597a9b93 Mon Sep 17 00:00:00 2001 From: Jorge Niedbalski Date: Tue, 9 Mar 2021 21:31:04 -0300 Subject: [PATCH] ci: workflows , added unit testing workflow. Remove travis (#3199) * Added a new unit-tests.yaml workflow * Updated workflow documentation * Removed travis-ci from the repository * Removed the ci/* directory and moved into fluent-bit-ci Signed-off-by: Jorge Niedbalski --- .github/workflows/README.workflows.md | 1 + .github/workflows/pr-closed-docker.yaml | 2 +- .github/workflows/unit-tests.yaml | 75 +++++++++++++ .travis.yml | 92 ---------------- appveyor.yml | 2 + ci/appveyor-download | 92 ---------------- ci/appveyor-download.ps1 | 139 ------------------------ ci/do-ut | 68 ------------ ci/do-ut.ps1 | 38 ------- 9 files changed, 79 insertions(+), 430 deletions(-) create mode 100644 .github/workflows/unit-tests.yaml delete mode 100644 .travis.yml delete mode 100755 ci/appveyor-download delete mode 100644 ci/appveyor-download.ps1 delete mode 100755 ci/do-ut delete mode 100644 ci/do-ut.ps1 diff --git a/.github/workflows/README.workflows.md b/.github/workflows/README.workflows.md index d6a9f2509e0..e7c055590ab 100644 --- a/.github/workflows/README.workflows.md +++ b/.github/workflows/README.workflows.md @@ -11,4 +11,5 @@ | [integration-build-pr](./integration-build-pr.yaml) | Builds a docker image to be used in integration testing (pr branch) | on new commit/push on PR(s) | | [integration-run-master](./integration-run-master.yaml) | Runs the integration testing suite on master | on new image built| | [integration-run-pr](./integration-run-pr.yaml) | Runs the integration testing suite on a PR branch | pr opened / label created 'ok-to-test' | +| [unit-tests](./unit-tests.yaml) | Runs the unit tests suite on master push or new PR | PR opened, merge in master branch | diff --git a/.github/workflows/pr-closed-docker.yaml b/.github/workflows/pr-closed-docker.yaml index f69b188e7b3..5976cd931d5 100644 --- a/.github/workflows/pr-closed-docker.yaml +++ b/.github/workflows/pr-closed-docker.yaml @@ -11,7 +11,7 @@ jobs: - uses: addnab/docker-run-action@v2 with: image: lumir/remove-dockerhub-tag - run: python3 remove-dockerhub-tag.py --user ${{ env.dockerhub_username }} --password ${{ env.dockerhub_password }} ${{ env.dockerhub_organization }}/fluent-bit:${{ env.arch }}-master-pr-${{ env.pr }} + run: python3 remove-dockerhub-tag.py --user ${{ env.dockerhub_username }} --password ${{ env.dockerhub_password }} ${{ env.dockerhub_organization }}/fluent-bit:${{ env.arch }}-master-pr-${{ env.pr }} || exit 0 env: pr: ${{ github.event.number }} arch: x86_64 diff --git a/.github/workflows/unit-tests.yaml b/.github/workflows/unit-tests.yaml new file mode 100644 index 00000000000..8d1317f5f32 --- /dev/null +++ b/.github/workflows/unit-tests.yaml @@ -0,0 +1,75 @@ +name: Run unit tests +on: + push: + branches: + - master + pull_request: + branches: + - master + types: [opened, edited, synchronize] +jobs: + run-unit-tests-amd64: + name: Run unit tests on amd64 for ${{ matrix.os }} - ${{ matrix.compiler }} - ${{ matrix.flb_option }} + runs-on: ${{ matrix.os }} + strategy: + max-parallel: 48 + fail-fast: false + matrix: + flb_option: [ "-DFLB_JEMALLOC=On", "-DFLB_JEMALLOC=Off", "-DFLB_SMALL=On", "-DSANITIZE_ADDRESS=On", "-DSANITIZE_UNDEFINED=On", "-DFLB_COVERAGE=On"] + os: [ubuntu-18.04, macos-latest] + compiler: [ gcc, clang ] + exclude: + - os: macos-latest + flb_option: "-DFLB_JEMALLOC=On" + - os: macos-latest + flb_option: "-DFLB_SMALL=On" + - os: macos-latest + flb_option: "-DSANITIZE_ADDRESS=On" + - os: macos-latest + flb_option: "-DSANITIZE_UNDEFINED=On" + - os: macos-latest + flb_option: "-DFLB_COVERAGE=On" + - os: macos-latest + flb_option: "-DFLB_JEMALLOC=Off" + compiler: clang + - os: ubuntu-18.04 + flb_option: "-DFLB_COVERAGE=On" + compiler: clang + steps: + - name: Setup environment ubuntu-18.04 + if: matrix.os == 'ubuntu-18.04' + run: | + sudo apt install -yyq gcc-7 g++-7 clang-6.0 libsystemd-dev gcovr + sudo ln -s /usr/bin/llvm-symbolizer-6.0 /usr/bin/llvm-symbolizer || true + + - uses: actions/checkout@v2 + - uses: actions/checkout@v2 + with: + repository: calyptia/fluent-bit-ci + path: ci + + - name: Run ci/s/run-unit-tests.sh on ${{ matrix.os }} with ${{ matrix.compiler }} - ${{ matrix.flb_option }} + if: matrix.os == 'ubuntu-18.04' + run: | + echo "CC = $CC, CXX = $CXX, FLB_OPT = $FLB_OPT" + sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 90 + sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90 + sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 90 + sudo usermod -a -G systemd-journal $(id -un) + sudo -E su -p $(id -un) -c "PATH=$PATH ci/scripts/run-unit-tests.sh" + env: + CC: ${{ matrix.compiler }} + CXX: ${{ matrix.compiler }} + FLB_OPT: ${{ matrix.flb_option }} + + - name: Run ci/s/run-unit-tests.sh on ${{ matrix.os }} with ${{ matrix.compiler }} - ${{ matrix.flb_option }} + if: matrix.os == 'macos-latest' + run: | + echo "CC = $CC, CXX = $CXX, FLB_OPT = $FLB_OPT" + brew update + brew install bison flex || true + ci/scripts/run-unit-tests.sh || true + env: + CC: gcc + CXX: g++ + FLB_OPT: ${{ matrix.flb_option }} \ No newline at end of file diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index da0599247d9..00000000000 --- a/.travis.yml +++ /dev/null @@ -1,92 +0,0 @@ -dist: bionic -language: c - -git: - depth: 3 - -arch: - - amd64 - - arm64 - -compiler: - - gcc - - clang - -env: - - FLB_OPT="-DFLB_JEMALLOC=On" - - FLB_OPT="-DFLB_JEMALLOC=Off" - - FLB_OPT="-DFLB_SMALL=On" - - FLB_OPT="-DSANITIZE_ADDRESS=On" - - FLB_OPT="-DSANITIZE_UNDEFINED=On" - -# Disable Memory Sanitizer since it causes conflicts on coroutines -# interfaces. We need to add the stack registrations otherwise it -# fails with: -# -# ==22536==ERROR: MemorySanitizer: SEGV on unknown...7fe2231f8c48 T22537) -# ==22536==The signal is caused by a READ memory access. -# ==22536==Hint: PC is at a non-executable region. Maybe a wild jump? -# #0 0xaadc6f in _fini (...in/flb-rt-in_cpu+0xaadc6f) -# -# - FLB_OPT="-DSANITIZE_MEMORY=On" - -# Many errors on this -# - FLB_OPT="-DSANITIZE_THREAD=On" - -before_script: - -jobs: - exclude: - - arch: arm64 - compiler: clang - env: FLB_OPT="-DSANITIZE_UNDEFINED=On" - include: - - os: osx - osx_image: xcode12.2 - env: FLB_OPT="-DFLB_JEMALLOC=Off" - script: | - brew update - brew install bison flex || true - ci/do-ut || true - - os: linux - env: FLB_OPT="-DFLB_COVERAGE=On" - dist: bionic - language: c - compiler: gcc - script: | - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 90 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90 - sudo usermod -a -G systemd-journal $(id -un) - sudo -E su -p travis -c "PATH=$PATH ci/do-ut" - - os: linux - services: - - docker - dist: bionic - language: c - compiler: gcc - env: DOCKER_BUILD=1 - script: | - echo "===== BUILD DOCKER IMAGE =======" - docker build -t test-image -f ./dockerfiles/Dockerfile.x86_64-master . - addons: - apt: - sources: {} - packages: {} - -script: | - echo "CC = $CC, CXX = $CXX" - sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-7 90 - sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-7 90 - sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-6.0 90 - sudo usermod -a -G systemd-journal $(id -un) - sudo -E su -p travis -c "PATH=$PATH ci/do-ut" -addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - gcc-7 - - g++-7 - - clang-6.0 - - libsystemd-dev - - gcovr diff --git a/appveyor.yml b/appveyor.yml index a16f1ab3e43..e403de0bab0 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -21,6 +21,8 @@ install: - ps: Copy-Item -Path /WinFlexBison/win_flex.exe /WinFlexBison/flex.exe before_build: + - git clone --depth=1 https://github.com/calyptia/fluent-bit-ci.git ci + - ps: Copy-Item -Path .\ci\scripts\run-unit-tests.ps1 .\ci\do-ut.ps1 - if %PLATFORM%==Win32 call "%vspath%\VC\Auxiliary\Build\vcvars32.bat" - if %PLATFORM%==x64 call "%vspatH%\VC\Auxiliary\Build\vcvars64.bat" diff --git a/ci/appveyor-download b/ci/appveyor-download deleted file mode 100755 index 1f6d5767cd4..00000000000 --- a/ci/appveyor-download +++ /dev/null @@ -1,92 +0,0 @@ -#!/usr/bin/env python3 -# -# This is a simple script to download Windows installers from AppVeyor. -# Use this script to automate the Windows release process. -# -# USAGE -# -# $ appveyor-download v1.2.1 # Download installers for v1.2.1 -# - -import json -import sys -import os -import urllib.request -import datetime - -# -# GLOBAL VARIABLES - -GITHUB_URL = 'https://api.github.com/repos/fluent/fluent-bit/statuses/%s' - -APPVAYOR_JOBS = 'https://ci.appveyor.com/api/projects/fluent/%s/builds/%s' -APPVAYOR_LIST = 'https://ci.appveyor.com/api/buildjobs/%s/artifacts' -APPVAYOR_FILE = 'https://ci.appveyor.com/api/buildjobs/%s/artifacts/%s' - -# -# Util functions - -def now(): - return datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') - -def usage(): - print('Usage: appveyor-download VERSION') - return -1 - -def LOG(*args): - print(now(), *args, file=sys.stderr) - -# -# REST API - -def json_api(url): - LOG('Request %s' % url) - with urllib.request.urlopen(url) as fp: - return json.loads(fp.read().decode()) - -def build_get(version): - resp = json_api(GITHUB_URL % version) - - for item in resp: - if item['description'] == 'AppVeyor build succeeded': - build_url = item['target_url'] - break - else: - raise RuntimeError('No AppVeyor build found: %s' % resp) - - tokens = build_url.split('/') - - return (tokens[-3], tokens[-1]) - -def jobs_get(project_id, build_id): - resp = json_api(APPVAYOR_JOBS % (project_id, build_id)) - return list(node['jobId'] for node in resp['build']['jobs']) - -def filenames_get(job_id): - resp = json_api(APPVAYOR_LIST % job_id) - return list(node['fileName'] for node in resp) - -# -# Main - -def main(args): - if not args: - return usage() - - project_id, build_id = build_get(args[0]) - - for job_id in jobs_get(project_id, build_id): - for filename in filenames_get(job_id): - - with urllib.request.urlopen(APPVAYOR_FILE % (job_id, filename)) as fp: - data = fp.read() - size = len(data) - - outfile = os.path.basename(filename) - with open(outfile, 'wb') as fw: - fw.write(data) - - LOG('* %s (%s bytes)' % (outfile, size)) - -if __name__ == '__main__': - sys.exit(main(sys.argv[1:])) diff --git a/ci/appveyor-download.ps1 b/ci/appveyor-download.ps1 deleted file mode 100644 index 38905db6c85..00000000000 --- a/ci/appveyor-download.ps1 +++ /dev/null @@ -1,139 +0,0 @@ -param ( - [Parameter(Position=0)] - [string] $version, - - [ValidateSet('win32', 'x64')] - [string] $platform, - - [ValidateSet('exe', 'zip')] - [string] $filetype -) - -# URL Paths -$GITHUB_URL = "https://api.github.com/repos/fluent/fluent-bit/statuses/{0}" -$APPVEYOR_JOBS = "https://ci.appveyor.com/api/projects/fluent/{0}/builds/{1}" -$APPVEYOR_LIST = "https://ci.appveyor.com/api/buildjobs/{0}/artifacts" -$APPVEYOR_FILE = "https://ci.appveyor.com/api/buildjobs/{0}/artifacts/{1}" - -# Utility functions -function Usage -{ - $usage = @" - - Usage: appveyor-download [version] [filters] - - version - the fluent-bit version to download (eg. v1.3.3) - - Filters: - - platform - win32 or x64 - filetype - exe or zip - - Examples: - - # Download all fluent-bit artifacts - appveyor-download.ps1 v1.3.3 - - # Download only x64 fluent-bit artifacts (exe and zip) - appveyor-download.ps1 v1.3.3 -platform x64 - - # Download only x64 zip fluent-bit artifacts - appveyor-download.ps1 v1.3.3 -platform x64 -filetype zip - -"@ - Write-Host $usage - exit -} -function Log-Message -{ - param ( $message ) - $now = $(Get-Date((Get-Date).ToUniversalTime()) -UFormat '%Y-%m-%dT%H:%M:%SZ') - Write-Host $("[{0}] {1}" -f $now, $message) -} -function Test-EmptyStringValue -{ - param ( $str ) - return [string]::IsNullOrEmpty($str) -or $str.Trim().length -eq 0 -} - -function Get-WebApiPayload -{ - param ( $url ) - - Log-Message $("Request: {0}" -f $url) - $wc = New-Object System.Net.WebClient - $wc.Headers.Add("User-Agent", "fluent-bit-builder") - $payload = $wc.DownloadString($url) - return $payload -} -function Get-File -{ - param ( $url, $filename, $size ) - - $filename = [System.IO.Path]::GetFileName($filename) - Log-Message $("* {0} ({1} bytes)" -f $filename, $size) - - $state = $ProgressPreference - $ProgressPreference = 'SilentlyContinue' - Invoke-WebRequest -URI $url -OutFile $filename - $ProgressPreference = $state -} - -# GitHub and Appveyor functions -function Get-Build -{ - param ( $version ) - - $builds = Get-WebApiPayload($GITHUB_URL -f $version) | ConvertFrom-Json - foreach ($build in $builds) { - if ($build.description -eq "AppVeyor build succeeded") { $buildUrl = $build.target_url; break } - } - if (Test-EmptyStringValue($buildUrl)) { Log-Message $("No AppVeyor build found: {0}" -f $builds); exit } - - $tokens = $buildUrl.Split('/') - return @{ - ProjectId = $tokens[-3] - BuildId = $tokens[-1] - } -} - -function Get-Jobs -{ - param ( $projectId, $buildId ) - - $url = $APPVEYOR_JOBS -f $projectId, $buildId - $jobs = (Get-WebApiPayload($url) | ConvertFrom-Json).build.jobs - if (!(Test-EmptyStringValue($platform))) { $jobs = $jobs | Where-Object { $_.name.ToLower() -eq "platform: $platform" } } - return $jobs | Select-Object jobId - -} - -function Get-Artifacts -{ - param ( $jobId ) - - $url = $APPVEYOR_LIST -f $jobId - $artifacts = Get-WebApiPayload($url) | ConvertFrom-Json - if (!(Test-EmptyStringValue($filetype))) { $artifacts = $artifacts | Where-Object { $_.fileName.endswith($filetype) } } - return $artifacts | Select-Object filename, size -} - -function Get-Artifact -{ - param ( $jobId, $filename, $size ) - - $url = $APPVEYOR_FILE -f $jobId, $filename - Get-File $url $filename $size -} - -# Main - -if (Test-EmptyStringValue($version)) { Usage } - -$build = Get-Build $version -foreach ($job in Get-Jobs $build.ProjectId $build.BuildId) { - foreach ($artifacts in Get-Artifacts $job.jobId) { - Get-Artifact $job.jobId $artifacts.filename $artifacts.size - } -} - diff --git a/ci/do-ut b/ci/do-ut deleted file mode 100755 index 4047bf3f95a..00000000000 --- a/ci/do-ut +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -nparallel=$(( $(getconf _NPROCESSORS_ONLN) > 8 ? 8 : $(getconf _NPROCESSORS_ONLN) )) - -[ -x /usr/bin/llvm-symbolizer-5.0 ] && export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-5.0 -[ -x /usr/local/clang-5.0.0/bin/llvm-symbolizer ] && export ASAN_SYMBOLIZER_PATH=/usr/local/clang-5.0.0/bin/llvm-symbolizer -[ -x /usr/bin/llvm-symbolizer-6.0 ] && export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer-6.0 -[ -x /usr/bin/llvm-symbolizer ] && export ASAN_SYMBOLIZER_PATH=/usr/bin/llvm-symbolizer - -echo "use $ASAN_SYMBOLIZER_PATH" - -SKIP_TESTS="flb-rt-out_elasticsearch -flb-rt-out_td -flb-rt-out_forward -flb-rt-in_disk -flb-rt-in_proc" - -# On macOS, kubernetes log directory which points to /var/log does not exist. -if [ "$(uname)" = "Darwin" ] -then - SKIP_TESTS+="flb-rt-filter_kubernetes" -fi - -for skip in $SKIP_TESTS -do - SKIP="$SKIP -DFLB_WITHOUT_${skip}=1" -done - -[ -f /etc/lsb-release ] && . /etc/lsb-release -if [ "$DISTRIB_RELEASE" = "14.04" ] -then - # On 'Trusty', gmtime_r doesn't parse this properly: - # {"generic_TZ" , "07/18/2017 01:47:03 +05:30" , 1500322623, 0, 0}, - echo "Skip flb-it-parser (trusty)" - SKIP="$SKIP -DFLB_WITHOUT_flb-it-parser=1" -fi - -# Disable fstore test on Travis -[[ ! -z "$TRAVIS" ]] && SKIP="$SKIP -DFLB_WITHOUT_flb-it-fstore=1" - -# If no v6, disable that test -[[ ! $(ip a) =~ ::1 ]] && SKIP="$SKIP -DFLB_WITHOUT_flb-it-network=1" - -GLOBAL_OPTS="-DFLB_BACKTRACE=Off -DFLB_SHARED_LIB=Off -DFLB_DEBUG=On -DFLB_ALL=On -DFLB_EXAMPLES=Off" -set -e -mkdir -p build -cd build -echo "Build unit tests for $FLB_OPT on $nparallel VCPU" -echo cmake $LDFLAG $GLOBAL_OPTS $FLB_OPT -DFLB_TESTS_INTERNAL=On -DFLB_TESTS_RUNTIME=On $SKIP ../ -cmake $LDFLAG $GLOBAL_OPTS $FLB_OPT -DFLB_TESTS_INTERNAL=On -DFLB_TESTS_RUNTIME=On $SKIP ../ -make -j $nparallel - -echo -echo "Run unit tests for $FLB_OPT on $nparallel VCPU" -echo -ctest -j $nparallel --build-run-dir $PWD --output-on-failure -res=$? - -if [[ "$FLB_OPT" =~ COVERAGE ]] -then - mkdir -p coverage - find lib -name "*.gcda" -o -name "*.gcno" -print0 | xargs -0 -r rm - gcovr -e "build/sql.l" -e "build/sql.y" -e "build/ra.l" -e "build/ra.y" -p -r .. . | cut -c1-100 - gcovr -e "build/sql.l" -e "build/sql.y" -e "build/ra.l" -e "build/ra.y" --html --html-details -p -r .. -o coverage/index.html . - echo - echo "See coverage/index.html for code-coverage details" -fi -exit $res diff --git a/ci/do-ut.ps1 b/ci/do-ut.ps1 deleted file mode 100644 index 536709b4c6b..00000000000 --- a/ci/do-ut.ps1 +++ /dev/null @@ -1,38 +0,0 @@ -cd build - -if ( "x64" -eq $env:PLATFORM ) { - $OPENSSL_DIR = "C:\OpenSSL-v111-Win64" -} -else { - $OPENSSL_DIR = "C:\OpenSSL-v111-Win32" -} - - -# CACHE GENERATION -cmake -G "NMake Makefiles" ` - -D FLB_TESTS_INTERNAL=On ` - -D OPENSSL_ROOT_DIR=$OPENSSL_DIR ` - -D FLB_WITHOUT_flb-rt-out_elasticsearch=On ` - -D FLB_WITHOUT_flb-rt-out_td=On ` - -D FLB_WITHOUT_flb-rt-out_forward=On ` - -D FLB_WITHOUT_flb-rt-in_disk=On ` - -D FLB_WITHOUT_flb-rt-in_proc=On ` - -D FLB_WITHOUT_flb-it-parser=On ` - -D FLB_WITHOUT_flb-it-unit_sizes=On ` - -D FLB_WITHOUT_flb-it-network=On ` - -D FLB_WITHOUT_flb-it-pack=On ` - -D FLB_WITHOUT_flb-it-signv4=On ` - -D FLB_WITHOUT_flb-it-aws_credentials=On ` - -D FLB_WITHOUT_flb-it-aws_credentials_ec2=On ` - -D FLB_WITHOUT_flb-it-aws_credentials_http=On ` - -D FLB_WITHOUT_flb-it-aws_credentials_profile=On ` - -D FLB_WITHOUT_flb-it-aws_credentials_sts=On ` - -D FLB_WITHOUT_flb-it-aws_util=On ` - -D FLB_WITHOUT_flb-it-input_chunk=On ` - ../ - -# COMPILE -cmake --build . - -# RUNNING TESTS -ctest --build-run-dir $PWD --output-on-failure