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:
Justin Traglia 2023-03-30 23:39:57 -05:00 committed by GitHub
parent 6b9b636c1b
commit 6bac4e1b6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 89 additions and 47 deletions

View File

@ -9,12 +9,19 @@ on:
jobs:
tests:
runs-on: ubuntu-latest
runs-on: ${{matrix.os}}
strategy:
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- name: Check formatting
if: matrix.os == 'ubuntu-latest'
working-directory: src
run: |
make format
@ -23,17 +30,22 @@ jobs:
working-directory: src
run: make
- name: Clang Sanitizers
if: matrix.os != 'windows-latest'
working-directory: src
run: make sanitize
- name: Clang Static Analyzer
if: matrix.os != 'windows-latest'
working-directory: src
run: make analyze
- name: Install LLVM
if: matrix.os == 'ubuntu-latest'
uses: egor-tensin/setup-clang@v1
- name: Generate coverage report
if: matrix.os != 'windows-latest'
working-directory: src
run: make coverage
- name: Save coverage report
if: matrix.os != 'windows-latest'
uses: actions/upload-artifact@v3
with:
name: coverage

View File

@ -1,47 +1,51 @@
###############################################################################
# Configuration Options
# Configuration
###############################################################################
# We use clang. Some versions of GCC report missing-braces warnings.
CC = clang
# Platform detection.
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.
FIELD_ELEMENTS_PER_BLOB ?= 4096
# The base compiler flags. More can be added on command line.
CFLAGS += -I../inc
CFLAGS += -Wall -Wextra -Werror -O2
CFLAGS += -DFIELD_ELEMENTS_PER_BLOB=$(FIELD_ELEMENTS_PER_BLOB)
CFLAGS += -O2 -Wall -Wextra
# Disable optimizations. Put after $CFLAGS.
NO_OPTIMIZE = -O0
# Cross-platform compilation settings.
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.
BLST_LIBRARY = ../lib/libblst.a
BLST_BUILDSCRIPT = ../blst/build.sh
BLST = -L../lib -lblst
# Compiler flags for generating coverage data.
COVERAGE = -fprofile-instr-generate -fcoverage-mapping
# 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
# Libraries to build with.
LIBS = $(BLST_LIBRARY)
###############################################################################
# Makefile Rules
# Core
###############################################################################
all: c_kzg_4844.o test
@ -61,19 +65,22 @@ blst: $(BLST_LIBRARY)
c_kzg_4844.o: c_kzg_4844.c $(BLST_LIBRARY)
@$(CC) $(CFLAGS) -c $<
test_c_kzg_4844: CFLAGS += -O0
test_c_kzg_4844: test_c_kzg_4844.c c_kzg_4844.c
@$(CC) $(CFLAGS) $(NO_OPTIMIZE) -o $@ $< $(BLST)
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)
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
.PHONY: test
test: 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
coverage: test_c_kzg_4844_cov
@LLVM_PROFILE_FILE="ckzg.profraw" ./$<
@ -83,9 +90,22 @@ coverage: test_c_kzg_4844_cov
@$(XCRUN) llvm-cov report --instr-profile=ckzg.profdata \
--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
run_profiler: test_c_kzg_4844_prof
@$(PROFILER_OPTS) ./$<
@CPUPROFILE_FREQUENCY=1000000000 ./$<
.PHONY: profile_%
profile_%: run_profiler
@ -102,29 +122,35 @@ profile: \
profile_verify_blob_kzg_proof \
profile_verify_blob_kzg_proof_batch
###############################################################################
# Sanitize
###############################################################################
.PHONY: sanitize_%
sanitize_%: CFLAGS += -O0 -fsanitize=$*
sanitize_%: test_c_kzg_4844.c c_kzg_4844.c
@echo Running sanitize=$*...
@$(CC) $(CFLAGS) $(NO_OPTIMIZE) -fsanitize=$* -o $@ $< $(BLST)
@$(CC) $(CFLAGS) -o $@ $< $(LIBS)
@ASAN_OPTIONS=allocator_may_return_null=1 \
LSAN_OPTIONS=allocator_may_return_null=1 \
./$@; rm $@
ifneq ($(OS),Windows_NT)
UNAME_S := $(shell uname -s)
.PHONY: sanitize
ifeq ($(UNAME_S),Darwin)
ifeq ($(PLATFORM),Darwin)
sanitize: \
sanitize_address \
sanitize_undefined
else
else ifeq ($(PLATFORM),Linux)
sanitize: \
sanitize_address \
sanitize_leak \
sanitize_safe-stack \
sanitize_undefined
endif
endif
###############################################################################
# Analyze
###############################################################################
.PHONY: analyze
analyze: c_kzg_4844.c
@ -132,12 +158,16 @@ analyze: c_kzg_4844.c
-o analysis-report $(CFLAGS) -c $<
@[ -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
clean:
@rm -f *.o *.profraw *.profdata *.html xray-log.* *.prof *.pdf \
test_c_kzg_4844 test_c_kzg_4844_cov test_c_kzg_4844_prof
@rm -rf analysis-report
.PHONY: format
format:
@clang-format -i --sort-includes c_kzg_4844.* test_c_kzg_4844.c