Disable compiler optimizations for tests (#133)

This commit is contained in:
Justin Traglia 2023-02-13 12:20:21 -06:00 committed by GitHub
parent 1493f2bf2f
commit 128dd3eb1f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 29 additions and 6 deletions

View File

@ -32,7 +32,7 @@ jobs:
- name: Generate coverage report
run: |
cd src
make test_cov
make coverage
- name: Save coverage report
uses: actions/upload-artifact@v3
with:

View File

@ -13,6 +13,9 @@ CFLAGS += -I../inc
CFLAGS += -Wall -Wextra -Werror -O2
CFLAGS += -DFIELD_ELEMENTS_PER_BLOB=$(FIELD_ELEMENTS_PER_BLOB)
# Disable optimizations. Put after $CFLAGS.
NO_OPTIMIZE = -O0
# Compiler flags for including blst. Put after source files.
BLST = -L../lib -lblst
@ -45,13 +48,13 @@ all: c_kzg_4844.o
@$(CC) $(CFLAGS) -c $<
test_c_kzg_4844: test_c_kzg_4844.c c_kzg_4844.c
@$(CC) $(CFLAGS) -o $@ $< $(BLST)
@$(CC) $(CFLAGS) $(NO_OPTIMIZE) -o $@ $< $(BLST)
test_c_kzg_4844_cov: test_c_kzg_4844.c c_kzg_4844.c
@$(CC) $(CFLAGS) $(COVERAGE) -o $@ $< $(BLST)
@$(CC) $(CFLAGS) $(NO_OPTIMIZE) $(COVERAGE) -o $@ $< $(BLST)
test_c_kzg_4844_prof: test_c_kzg_4844.c c_kzg_4844.c
@$(CC) $(CFLAGS) $(PROFILE) -o $@ $< $(BLST) $(PROFILER)
@$(CC) $(CFLAGS) $(NO_OPTIMIZE) $(PROFILE) -o $@ $< $(BLST) $(PROFILER)
.PHONY: blst
blst:
@ -64,8 +67,8 @@ blst:
test: test_c_kzg_4844
@./test_c_kzg_4844
.PHONY: test_cov
test_cov: test_c_kzg_4844_cov
.PHONY: coverage
coverage: test_c_kzg_4844_cov
@LLVM_PROFILE_FILE="ckzg.profraw" ./$<
@$(XCRUN) llvm-profdata merge --sparse ckzg.profraw -o ckzg.profdata
@$(XCRUN) llvm-cov show --instr-profile=ckzg.profdata --format=html \

View File

@ -105,6 +105,15 @@ static void test_c_kzg_malloc__fails_size_equal_to_zero(void) {
ASSERT_EQUALS(ptr, NULL);
}
static void test_c_kzg_malloc__fails_too_big(void) {
C_KZG_RET ret;
void *ptr = NULL;
ret = c_kzg_malloc(&ptr, UINT64_MAX);
ASSERT_EQUALS(ret, C_KZG_MALLOC);
ASSERT_EQUALS(ptr, NULL);
}
static void test_c_kzg_calloc__succeeds_size_greater_than_zero(void) {
C_KZG_RET ret;
void *ptr = NULL;
@ -133,6 +142,15 @@ static void test_c_kzg_calloc__fails_size_equal_to_zero(void) {
ASSERT_EQUALS(ptr, NULL);
}
static void test_c_kzg_calloc__fails_too_big(void) {
C_KZG_RET ret;
void *ptr = NULL;
ret = c_kzg_calloc(&ptr, UINT64_MAX, UINT64_MAX);
ASSERT_EQUALS(ret, C_KZG_MALLOC);
ASSERT_EQUALS(ptr, NULL);
}
///////////////////////////////////////////////////////////////////////////////
// Tests for blob_to_kzg_commitment
///////////////////////////////////////////////////////////////////////////////
@ -760,9 +778,11 @@ int main(void) {
setup();
RUN(test_c_kzg_malloc__succeeds_size_greater_than_zero);
RUN(test_c_kzg_malloc__fails_size_equal_to_zero);
RUN(test_c_kzg_malloc__fails_too_big);
RUN(test_c_kzg_calloc__succeeds_size_greater_than_zero);
RUN(test_c_kzg_calloc__fails_size_equal_to_zero);
RUN(test_c_kzg_calloc__fails_count_equal_to_zero);
RUN(test_c_kzg_calloc__fails_too_big);
RUN(test_blob_to_kzg_commitment__succeeds_x_less_than_modulus);
RUN(test_blob_to_kzg_commitment__fails_x_equal_to_modulus);
RUN(test_blob_to_kzg_commitment__fails_x_greater_than_modulus);