mirror of
https://github.com/codex-storage/nim-bearssl.git
synced 2025-01-10 13:26:07 +00:00
CI: test with multiple Nim versions (#24)
* CI: test with multiple Nim versions and add a real test
This commit is contained in:
parent
9ca2e9fe87
commit
b39f3d2975
137
.github/workflows/ci.yml
vendored
137
.github/workflows/ci.yml
vendored
@ -1,13 +1,16 @@
|
|||||||
name: CI
|
name: CI
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
workflow_dispatch:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
max-parallel: 20
|
|
||||||
matrix:
|
matrix:
|
||||||
test_lang: [c, cpp]
|
|
||||||
target:
|
target:
|
||||||
- os: linux
|
- os: linux
|
||||||
cpu: amd64
|
cpu: amd64
|
||||||
@ -17,27 +20,35 @@ jobs:
|
|||||||
cpu: amd64
|
cpu: amd64
|
||||||
- os: windows
|
- os: windows
|
||||||
cpu: amd64
|
cpu: amd64
|
||||||
- os: windows
|
#- os: windows
|
||||||
cpu: i386
|
#cpu: i386
|
||||||
|
branch: [version-1-2, version-1-4, version-1-6, devel]
|
||||||
include:
|
include:
|
||||||
- target:
|
- target:
|
||||||
os: linux
|
os: linux
|
||||||
builder: ubuntu-18.04
|
builder: ubuntu-18.04
|
||||||
|
shell: bash
|
||||||
- target:
|
- target:
|
||||||
os: macos
|
os: macos
|
||||||
builder: macos-10.15
|
builder: macos-10.15
|
||||||
|
shell: bash
|
||||||
- target:
|
- target:
|
||||||
os: windows
|
os: windows
|
||||||
builder: windows-2019
|
builder: windows-2019
|
||||||
|
shell: msys2 {0}
|
||||||
|
|
||||||
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ matrix.test_lang }}'
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: ${{ matrix.shell }}
|
||||||
|
|
||||||
|
name: '${{ matrix.target.os }}-${{ matrix.target.cpu }} (Nim ${{ matrix.branch }})'
|
||||||
runs-on: ${{ matrix.builder }}
|
runs-on: ${{ matrix.builder }}
|
||||||
|
continue-on-error: ${{ matrix.branch == 'version-1-6' || matrix.branch == 'devel' }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout nim-bearssl
|
- name: Checkout
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
with:
|
with:
|
||||||
path: nim-bearssl
|
submodules: true
|
||||||
submodules: false
|
|
||||||
|
|
||||||
- name: Install build dependencies (Linux i386)
|
- name: Install build dependencies (Linux i386)
|
||||||
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
|
if: runner.os == 'Linux' && matrix.target.cpu == 'i386'
|
||||||
@ -59,13 +70,26 @@ jobs:
|
|||||||
chmod 755 external/bin/gcc external/bin/g++
|
chmod 755 external/bin/gcc external/bin/g++
|
||||||
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
|
echo '${{ github.workspace }}/external/bin' >> $GITHUB_PATH
|
||||||
|
|
||||||
- name: Restore MinGW-W64 (Windows) from cache
|
- name: MSYS2 (Windows i386)
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows' && matrix.target.cpu == 'i386'
|
||||||
id: windows-mingw-cache
|
uses: msys2/setup-msys2@v2
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
with:
|
||||||
path: external/mingw-${{ matrix.target.cpu }}
|
path-type: inherit
|
||||||
key: 'mingw-${{ matrix.target.cpu }}'
|
msystem: MINGW32
|
||||||
|
install: >-
|
||||||
|
base-devel
|
||||||
|
git
|
||||||
|
mingw-w64-i686-toolchain
|
||||||
|
|
||||||
|
- name: MSYS2 (Windows amd64)
|
||||||
|
if: runner.os == 'Windows' && matrix.target.cpu == 'amd64'
|
||||||
|
uses: msys2/setup-msys2@v2
|
||||||
|
with:
|
||||||
|
path-type: inherit
|
||||||
|
install: >-
|
||||||
|
base-devel
|
||||||
|
git
|
||||||
|
mingw-w64-x86_64-toolchain
|
||||||
|
|
||||||
- name: Restore Nim DLLs dependencies (Windows) from cache
|
- name: Restore Nim DLLs dependencies (Windows) from cache
|
||||||
if: runner.os == 'Windows'
|
if: runner.os == 'Windows'
|
||||||
@ -75,24 +99,6 @@ jobs:
|
|||||||
path: external/dlls-${{ matrix.target.cpu }}
|
path: external/dlls-${{ matrix.target.cpu }}
|
||||||
key: 'dlls-${{ matrix.target.cpu }}'
|
key: 'dlls-${{ matrix.target.cpu }}'
|
||||||
|
|
||||||
- name: Install MinGW64 dependency (Windows)
|
|
||||||
if: >
|
|
||||||
steps.windows-mingw-cache.outputs.cache-hit != 'true' &&
|
|
||||||
runner.os == 'Windows'
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
mkdir -p external
|
|
||||||
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
|
|
||||||
MINGW_URL="https://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win64/Personal Builds/mingw-builds/8.1.0/threads-posix/seh/x86_64-8.1.0-release-posix-seh-rt_v6-rev0.7z"
|
|
||||||
ARCH=64
|
|
||||||
else
|
|
||||||
MINGW_URL="https://sourceforge.net/projects/mingw-w64/files/Toolchains targetting Win32/Personal Builds/mingw-builds/8.1.0/threads-posix/dwarf/i686-8.1.0-release-posix-dwarf-rt_v6-rev0.7z"
|
|
||||||
ARCH=32
|
|
||||||
fi
|
|
||||||
curl -L "$MINGW_URL" -o "external/mingw-${{ matrix.target.cpu }}.7z"
|
|
||||||
7z x -y "external/mingw-${{ matrix.target.cpu }}.7z" -oexternal/
|
|
||||||
mv external/mingw$ARCH external/mingw-${{ matrix.target.cpu }}
|
|
||||||
|
|
||||||
- name: Install DLLs dependencies (Windows)
|
- name: Install DLLs dependencies (Windows)
|
||||||
if: >
|
if: >
|
||||||
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
|
steps.windows-dlls-cache.outputs.cache-hit != 'true' &&
|
||||||
@ -111,44 +117,51 @@ jobs:
|
|||||||
echo '${{ github.workspace }}'"/external/mingw-${{ matrix.target.cpu }}/bin" >> $GITHUB_PATH
|
echo '${{ github.workspace }}'"/external/mingw-${{ matrix.target.cpu }}/bin" >> $GITHUB_PATH
|
||||||
echo '${{ github.workspace }}'"/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH
|
echo '${{ github.workspace }}'"/external/dlls-${{ matrix.target.cpu }}" >> $GITHUB_PATH
|
||||||
|
|
||||||
- name: Get latest nimbus-build-system commit hash
|
- name: Derive environment variables
|
||||||
id: versions
|
|
||||||
shell: bash
|
|
||||||
run: |
|
run: |
|
||||||
getHash() {
|
|
||||||
git ls-remote "https://github.com/$1" "${2:-HEAD}" | cut -f 1
|
|
||||||
}
|
|
||||||
nbsHash=$(getHash status-im/nimbus-build-system)
|
|
||||||
echo "::set-output name=nimbus_build_system::$nbsHash"
|
|
||||||
|
|
||||||
- name: Restore prebuilt Nim from cache
|
|
||||||
id: nim-cache
|
|
||||||
uses: actions/cache@v2
|
|
||||||
with:
|
|
||||||
path: NimBinaries
|
|
||||||
key: 'NimBinaries-${{ matrix.target.os }}-${{ matrix.target.cpu }}-${{ steps.versions.outputs.nimbus_build_system }}'
|
|
||||||
|
|
||||||
- name: Build Nim and associated tools
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
|
|
||||||
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
|
if [[ '${{ matrix.target.cpu }}' == 'amd64' ]]; then
|
||||||
PLATFORM=x64
|
PLATFORM=x64
|
||||||
else
|
else
|
||||||
PLATFORM=x86
|
PLATFORM=x86
|
||||||
fi
|
fi
|
||||||
if [[ '${{ matrix.target.os }}' == 'windows' ]]; then
|
echo "PLATFORM=$PLATFORM" >> $GITHUB_ENV
|
||||||
MAKE_CMD="mingw32-make"
|
|
||||||
else
|
ncpu=
|
||||||
MAKE_CMD="make"
|
MAKE_CMD="make"
|
||||||
fi
|
case '${{ runner.os }}' in
|
||||||
env MAKE="$MAKE_CMD -j2" ARCH_OVERRIDE=$PLATFORM CC=gcc bash build_nim.sh nim csources dist/nimble NimBinaries
|
'Linux')
|
||||||
|
ncpu=$(nproc)
|
||||||
|
;;
|
||||||
|
'macOS')
|
||||||
|
ncpu=$(sysctl -n hw.ncpu)
|
||||||
|
;;
|
||||||
|
'Windows')
|
||||||
|
ncpu=$NUMBER_OF_PROCESSORS
|
||||||
|
MAKE_CMD="mingw32-make"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
[[ -z "$ncpu" || $ncpu -le 0 ]] && ncpu=1
|
||||||
|
echo "ncpu=$ncpu" >> $GITHUB_ENV
|
||||||
|
echo "MAKE_CMD=${MAKE_CMD}" >> $GITHUB_ENV
|
||||||
|
|
||||||
|
- name: Build Nim and associated tools
|
||||||
|
shell: bash
|
||||||
|
run: |
|
||||||
|
curl -O -L -s -S https://raw.githubusercontent.com/status-im/nimbus-build-system/master/scripts/build_nim.sh
|
||||||
|
env MAKE="${MAKE_CMD} -j${ncpu}" ARCH_OVERRIDE=${PLATFORM} NIM_COMMIT=${{ matrix.branch }} \
|
||||||
|
QUICK_AND_DIRTY_COMPILER=1 QUICK_AND_DIRTY_NIMBLE=1 CC=gcc \
|
||||||
|
bash build_nim.sh nim csources dist/nimble NimBinaries
|
||||||
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
|
echo '${{ github.workspace }}/nim/bin' >> $GITHUB_PATH
|
||||||
|
|
||||||
- name: Run nim-bearssl tests
|
- name: Run tests
|
||||||
shell: bash
|
shell: bash
|
||||||
working-directory: nim-bearssl
|
|
||||||
run: |
|
run: |
|
||||||
git submodule update --init --recursive
|
if [[ "${{ matrix.target.os }}" == "windows" ]]; then
|
||||||
|
# https://github.com/status-im/nimbus-eth2/issues/3121
|
||||||
|
export NIMFLAGS="-d:nimRawSetjmp"
|
||||||
|
fi
|
||||||
|
nim --version
|
||||||
|
nimble --version
|
||||||
nimble install -y --depsOnly
|
nimble install -y --depsOnly
|
||||||
env TEST_LANG="${{ matrix.test_lang }}" nimble test
|
env TEST_LANG="c" nimble test
|
||||||
|
env TEST_LANG="cpp" nimble test
|
||||||
|
@ -1,3 +1,5 @@
|
|||||||
|
import os, strutils
|
||||||
|
|
||||||
# Package
|
# Package
|
||||||
version = "0.1.5"
|
version = "0.1.5"
|
||||||
author = "Status Research & Development GmbH"
|
author = "Status Research & Development GmbH"
|
||||||
@ -6,20 +8,20 @@ license = "MIT or Apache License 2.0"
|
|||||||
mode = ScriptMode.Verbose
|
mode = ScriptMode.Verbose
|
||||||
|
|
||||||
# Dependencies
|
# Dependencies
|
||||||
requires "nim >= 1.2.0"
|
requires "nim >= 1.2.0",
|
||||||
|
"unittest2"
|
||||||
|
|
||||||
### Helper functions
|
### Helper functions
|
||||||
proc test(env, path: string) =
|
proc test(env, path: string) =
|
||||||
# Compilation language is controlled by TEST_LANG
|
# Compilation language is controlled by TEST_LANG
|
||||||
var lang = "c"
|
exec "nim " & getEnv("TEST_LANG", "c") & " " & getEnv("NIMFLAGS") & " " & env &
|
||||||
if existsEnv"TEST_LANG":
|
" -rf --hints:off --skipParentCfg --styleCheck:usages --styleCheck:error " & path
|
||||||
lang = getEnv"TEST_LANG"
|
|
||||||
|
|
||||||
exec "nim " & lang & " " & env &
|
|
||||||
" -r --hints:off --skipParentCfg --styleCheck:usages --styleCheck:error " & path
|
|
||||||
|
|
||||||
task test, "Run tests":
|
task test, "Run tests":
|
||||||
exec "nim -v"
|
for path in listFiles(thisDir() / "tests"):
|
||||||
test "-d:debug", "tests/test1"
|
if path.split(".")[^1] != "nim":
|
||||||
test "-d:release", "tests/test1"
|
continue
|
||||||
test "--gc:arc -d:release", "tests/test1"
|
test "-d:debug", path
|
||||||
|
test "-d:release", path
|
||||||
|
test "--gc:arc -d:release", path
|
||||||
|
rmFile(path[0..^5].toExe())
|
||||||
|
31
tests/hashing.nim
Normal file
31
tests/hashing.nim
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import std/[strutils, sequtils],
|
||||||
|
unittest2,
|
||||||
|
../bearssl
|
||||||
|
|
||||||
|
suite "Hashing":
|
||||||
|
test "MD5":
|
||||||
|
let
|
||||||
|
input = ["",
|
||||||
|
"a",
|
||||||
|
"abc",
|
||||||
|
"message digest",
|
||||||
|
"abcdefghijklmnopqrstuvwxyz",
|
||||||
|
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",
|
||||||
|
"12345678901234567890123456789012345678901234567890123456789012345678901234567890"]
|
||||||
|
output = ["d41d8cd98f00b204e9800998ecf8427e",
|
||||||
|
"0cc175b9c0f1b6a831c399e269772661",
|
||||||
|
"900150983cd24fb0d6963f7d28e17f72",
|
||||||
|
"f96b697d7cb7938d525a2f31aaf161d0",
|
||||||
|
"c3fcd3d76192e4007dfb496cca67e13b",
|
||||||
|
"d174ab98d277d9f5a5611c2c9f419d9f",
|
||||||
|
"57edf4a22be3c955ac49da2e2107b67a"]
|
||||||
|
|
||||||
|
for i in 0 ..< input.len:
|
||||||
|
var
|
||||||
|
ctx = Md5Context()
|
||||||
|
res: array[md5SIZE, uint8]
|
||||||
|
|
||||||
|
md5Init(addr ctx)
|
||||||
|
md5Update(addr ctx, input[i].cstring, input[i].len)
|
||||||
|
md5Out(addr ctx, addr res[0])
|
||||||
|
check res.foldl(a & b.toHex(), "").toLower() == output[i]
|
@ -1,11 +0,0 @@
|
|||||||
# This is just an example to get you started. You may wish to put all of your
|
|
||||||
# tests into a single file, or separate them into multiple `test1`, `test2`
|
|
||||||
# etc. files (better names are recommended, just make sure the name starts with
|
|
||||||
# the letter 't').
|
|
||||||
#
|
|
||||||
# To run these tests, simply execute `nimble test`.
|
|
||||||
import unittest
|
|
||||||
import ../bearssl
|
|
||||||
|
|
||||||
test "dummy":
|
|
||||||
check true
|
|
Loading…
x
Reference in New Issue
Block a user