Run C tests on all platforms (#270)
* Run C tests on all platforms * Don't install llvm on mac & add windows define * Update blst settings for windows * Install msvc on windows * Don't specify blst as a library * Try including -lmingw32 * Clean up makefile & test setting target * Try using gcc for windows * Don't treat warnings as errors on windows * Test upping stack size * Ignore some tasks on windows * Clean up some things * Fix indentations * Delete extra blank line * More organization * Remove windows check around sanitize * Move XCRUN initialization back to top * Move extra sanitize cflags out like the others
This commit is contained in:
parent
6b9b636c1b
commit
6bac4e1b6c
|
@ -9,12 +9,19 @@ on:
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
tests:
|
tests:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ${{matrix.os}}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os:
|
||||||
|
- ubuntu-latest
|
||||||
|
- macos-latest
|
||||||
|
- windows-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
submodules: recursive
|
submodules: recursive
|
||||||
- name: Check formatting
|
- name: Check formatting
|
||||||
|
if: matrix.os == 'ubuntu-latest'
|
||||||
working-directory: src
|
working-directory: src
|
||||||
run: |
|
run: |
|
||||||
make format
|
make format
|
||||||
|
@ -23,17 +30,22 @@ jobs:
|
||||||
working-directory: src
|
working-directory: src
|
||||||
run: make
|
run: make
|
||||||
- name: Clang Sanitizers
|
- name: Clang Sanitizers
|
||||||
|
if: matrix.os != 'windows-latest'
|
||||||
working-directory: src
|
working-directory: src
|
||||||
run: make sanitize
|
run: make sanitize
|
||||||
- name: Clang Static Analyzer
|
- name: Clang Static Analyzer
|
||||||
|
if: matrix.os != 'windows-latest'
|
||||||
working-directory: src
|
working-directory: src
|
||||||
run: make analyze
|
run: make analyze
|
||||||
- name: Install LLVM
|
- name: Install LLVM
|
||||||
|
if: matrix.os == 'ubuntu-latest'
|
||||||
uses: egor-tensin/setup-clang@v1
|
uses: egor-tensin/setup-clang@v1
|
||||||
- name: Generate coverage report
|
- name: Generate coverage report
|
||||||
|
if: matrix.os != 'windows-latest'
|
||||||
working-directory: src
|
working-directory: src
|
||||||
run: make coverage
|
run: make coverage
|
||||||
- name: Save coverage report
|
- name: Save coverage report
|
||||||
|
if: matrix.os != 'windows-latest'
|
||||||
uses: actions/upload-artifact@v3
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: coverage
|
name: coverage
|
||||||
|
|
122
src/Makefile
122
src/Makefile
|
@ -1,47 +1,51 @@
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Configuration Options
|
# Configuration
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
# We use clang. Some versions of GCC report missing-braces warnings.
|
# Platform detection.
|
||||||
CC = clang
|
ifeq ($(OS),Windows_NT)
|
||||||
|
PLATFORM = Windows
|
||||||
|
else
|
||||||
|
UNAME_S := $(shell uname -s)
|
||||||
|
ifeq ($(UNAME_S),Darwin)
|
||||||
|
PLATFORM = Darwin
|
||||||
|
else
|
||||||
|
PLATFORM = Linux
|
||||||
|
endif
|
||||||
|
endif
|
||||||
|
|
||||||
|
# Some commands need xcode.
|
||||||
|
ifeq ($(PLATFORM),Darwin)
|
||||||
|
XCRUN = xcrun
|
||||||
|
endif
|
||||||
|
|
||||||
# By default, this is set to the mainnet value.
|
# By default, this is set to the mainnet value.
|
||||||
FIELD_ELEMENTS_PER_BLOB ?= 4096
|
FIELD_ELEMENTS_PER_BLOB ?= 4096
|
||||||
|
|
||||||
# The base compiler flags. More can be added on command line.
|
# The base compiler flags. More can be added on command line.
|
||||||
CFLAGS += -I../inc
|
CFLAGS += -I../inc
|
||||||
CFLAGS += -Wall -Wextra -Werror -O2
|
|
||||||
CFLAGS += -DFIELD_ELEMENTS_PER_BLOB=$(FIELD_ELEMENTS_PER_BLOB)
|
CFLAGS += -DFIELD_ELEMENTS_PER_BLOB=$(FIELD_ELEMENTS_PER_BLOB)
|
||||||
|
CFLAGS += -O2 -Wall -Wextra
|
||||||
|
|
||||||
# Disable optimizations. Put after $CFLAGS.
|
# Cross-platform compilation settings.
|
||||||
NO_OPTIMIZE = -O0
|
ifeq ($(PLATFORM),Windows)
|
||||||
|
CC = gcc
|
||||||
|
CFLAGS += -D_CRT_SECURE_NO_WARNINGS
|
||||||
|
CFLAGS += -Wl,--stack,8388608 # 8MB
|
||||||
|
else
|
||||||
|
CC = clang
|
||||||
|
CFLAGS += -fPIC -Werror
|
||||||
|
endif
|
||||||
|
|
||||||
# Settings for blst.
|
# Settings for blst.
|
||||||
BLST_LIBRARY = ../lib/libblst.a
|
BLST_LIBRARY = ../lib/libblst.a
|
||||||
BLST_BUILDSCRIPT = ../blst/build.sh
|
BLST_BUILDSCRIPT = ../blst/build.sh
|
||||||
BLST = -L../lib -lblst
|
|
||||||
|
|
||||||
# Compiler flags for generating coverage data.
|
# Libraries to build with.
|
||||||
COVERAGE = -fprofile-instr-generate -fcoverage-mapping
|
LIBS = $(BLST_LIBRARY)
|
||||||
|
|
||||||
# Settings for performance profiling.
|
|
||||||
PROFILE = -DPROFILE
|
|
||||||
PROFILER = -lprofiler
|
|
||||||
PROFILER_OPTS = CPUPROFILE_FREQUENCY=1000000000
|
|
||||||
|
|
||||||
# Platform specific options.
|
|
||||||
ifneq ($(OS),Windows_NT)
|
|
||||||
CFLAGS += -fPIC
|
|
||||||
UNAME_S := $(shell uname -s)
|
|
||||||
ifeq ($(UNAME_S),Darwin)
|
|
||||||
XCRUN = xcrun
|
|
||||||
PROFILE += -L$(shell brew --prefix gperftools)/lib
|
|
||||||
PROFILE += -I$(shell brew --prefix gperftools)/include
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
###############################################################################
|
###############################################################################
|
||||||
# Makefile Rules
|
# Core
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
all: c_kzg_4844.o test
|
all: c_kzg_4844.o test
|
||||||
|
@ -61,19 +65,22 @@ blst: $(BLST_LIBRARY)
|
||||||
c_kzg_4844.o: c_kzg_4844.c $(BLST_LIBRARY)
|
c_kzg_4844.o: c_kzg_4844.c $(BLST_LIBRARY)
|
||||||
@$(CC) $(CFLAGS) -c $<
|
@$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
|
test_c_kzg_4844: CFLAGS += -O0
|
||||||
test_c_kzg_4844: test_c_kzg_4844.c c_kzg_4844.c
|
test_c_kzg_4844: test_c_kzg_4844.c c_kzg_4844.c
|
||||||
@$(CC) $(CFLAGS) $(NO_OPTIMIZE) -o $@ $< $(BLST)
|
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
||||||
|
|
||||||
test_c_kzg_4844_cov: test_c_kzg_4844.c c_kzg_4844.c
|
|
||||||
@$(CC) $(CFLAGS) $(NO_OPTIMIZE) $(COVERAGE) -o $@ $< $(BLST)
|
|
||||||
|
|
||||||
test_c_kzg_4844_prof: test_c_kzg_4844.c c_kzg_4844.c
|
|
||||||
@$(CC) $(CFLAGS) $(NO_OPTIMIZE) $(PROFILE) -o $@ $< $(BLST) $(PROFILER)
|
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test: test_c_kzg_4844
|
test: test_c_kzg_4844
|
||||||
@./test_c_kzg_4844
|
@./test_c_kzg_4844
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Coverage
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
test_c_kzg_4844_cov: CFLAGS += -O0 -fprofile-instr-generate -fcoverage-mapping
|
||||||
|
test_c_kzg_4844_cov: test_c_kzg_4844.c c_kzg_4844.c
|
||||||
|
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
||||||
|
|
||||||
.PHONY: coverage
|
.PHONY: coverage
|
||||||
coverage: test_c_kzg_4844_cov
|
coverage: test_c_kzg_4844_cov
|
||||||
@LLVM_PROFILE_FILE="ckzg.profraw" ./$<
|
@LLVM_PROFILE_FILE="ckzg.profraw" ./$<
|
||||||
|
@ -83,9 +90,22 @@ coverage: test_c_kzg_4844_cov
|
||||||
@$(XCRUN) llvm-cov report --instr-profile=ckzg.profdata \
|
@$(XCRUN) llvm-cov report --instr-profile=ckzg.profdata \
|
||||||
--show-functions $< c_kzg_4844.c
|
--show-functions $< c_kzg_4844.c
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Profile
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
test_c_kzg_4844_prof: LIBS += -lprofiler
|
||||||
|
test_c_kzg_4844_prof: CFLAGS += -O0 -DPROFILE
|
||||||
|
ifeq ($(PLATFORM),Darwin)
|
||||||
|
test_c_kzg_4844_prof: CFLAGS += -L$(shell brew --prefix gperftools)/lib
|
||||||
|
test_c_kzg_4844_prof: CFLAGS += -I$(shell brew --prefix gperftools)/include
|
||||||
|
endif
|
||||||
|
test_c_kzg_4844_prof: test_c_kzg_4844.c c_kzg_4844.c
|
||||||
|
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
||||||
|
|
||||||
.PHONY: run_profiler
|
.PHONY: run_profiler
|
||||||
run_profiler: test_c_kzg_4844_prof
|
run_profiler: test_c_kzg_4844_prof
|
||||||
@$(PROFILER_OPTS) ./$<
|
@CPUPROFILE_FREQUENCY=1000000000 ./$<
|
||||||
|
|
||||||
.PHONY: profile_%
|
.PHONY: profile_%
|
||||||
profile_%: run_profiler
|
profile_%: run_profiler
|
||||||
|
@ -102,29 +122,35 @@ profile: \
|
||||||
profile_verify_blob_kzg_proof \
|
profile_verify_blob_kzg_proof \
|
||||||
profile_verify_blob_kzg_proof_batch
|
profile_verify_blob_kzg_proof_batch
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Sanitize
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
.PHONY: sanitize_%
|
.PHONY: sanitize_%
|
||||||
|
sanitize_%: CFLAGS += -O0 -fsanitize=$*
|
||||||
sanitize_%: test_c_kzg_4844.c c_kzg_4844.c
|
sanitize_%: test_c_kzg_4844.c c_kzg_4844.c
|
||||||
@echo Running sanitize=$*...
|
@echo Running sanitize=$*...
|
||||||
@$(CC) $(CFLAGS) $(NO_OPTIMIZE) -fsanitize=$* -o $@ $< $(BLST)
|
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
|
||||||
@ASAN_OPTIONS=allocator_may_return_null=1 \
|
@ASAN_OPTIONS=allocator_may_return_null=1 \
|
||||||
LSAN_OPTIONS=allocator_may_return_null=1 \
|
LSAN_OPTIONS=allocator_may_return_null=1 \
|
||||||
./$@; rm $@
|
./$@; rm $@
|
||||||
|
|
||||||
ifneq ($(OS),Windows_NT)
|
|
||||||
UNAME_S := $(shell uname -s)
|
|
||||||
.PHONY: sanitize
|
.PHONY: sanitize
|
||||||
ifeq ($(UNAME_S),Darwin)
|
ifeq ($(PLATFORM),Darwin)
|
||||||
sanitize: \
|
sanitize: \
|
||||||
sanitize_address \
|
sanitize_address \
|
||||||
sanitize_undefined
|
sanitize_undefined
|
||||||
else
|
else ifeq ($(PLATFORM),Linux)
|
||||||
sanitize: \
|
sanitize: \
|
||||||
sanitize_address \
|
sanitize_address \
|
||||||
sanitize_leak \
|
sanitize_leak \
|
||||||
sanitize_safe-stack \
|
sanitize_safe-stack \
|
||||||
sanitize_undefined
|
sanitize_undefined
|
||||||
endif
|
endif
|
||||||
endif
|
|
||||||
|
###############################################################################
|
||||||
|
# Analyze
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
.PHONY: analyze
|
.PHONY: analyze
|
||||||
analyze: c_kzg_4844.c
|
analyze: c_kzg_4844.c
|
||||||
|
@ -132,12 +158,16 @@ analyze: c_kzg_4844.c
|
||||||
-o analysis-report $(CFLAGS) -c $<
|
-o analysis-report $(CFLAGS) -c $<
|
||||||
@[ -d analysis-report ] && exit 1 || exit 0
|
@[ -d analysis-report ] && exit 1 || exit 0
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# Cleanup
|
||||||
|
###############################################################################
|
||||||
|
|
||||||
|
.PHONY: format
|
||||||
|
format:
|
||||||
|
@clang-format -i --sort-includes c_kzg_4844.* test_c_kzg_4844.c
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
@rm -f *.o *.profraw *.profdata *.html xray-log.* *.prof *.pdf \
|
@rm -f *.o *.profraw *.profdata *.html xray-log.* *.prof *.pdf \
|
||||||
test_c_kzg_4844 test_c_kzg_4844_cov test_c_kzg_4844_prof
|
test_c_kzg_4844 test_c_kzg_4844_cov test_c_kzg_4844_prof
|
||||||
@rm -rf analysis-report
|
@rm -rf analysis-report
|
||||||
|
|
||||||
.PHONY: format
|
|
||||||
format:
|
|
||||||
@clang-format -i --sort-includes c_kzg_4844.* test_c_kzg_4844.c
|
|
||||||
|
|
Loading…
Reference in New Issue