Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: enable memcheck in workflow #4

Merged
merged 5 commits into from
Mar 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions .github/workflows/c-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
workflow_dispatch:

jobs:
build:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
Expand All @@ -35,7 +35,31 @@ jobs:
- name: make test
run: make test

# - name: make memcheck
# run: make memcheck
- name: make memcheck
run: make memcheck

build:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
steps:
- uses: actions/checkout@v4

- name: Install dependencies
run: |
sudo apt install software-properties-common -y
sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y
sudo apt-get update -y
sudo apt-get install -y gcc-13 valgrind

- name: Set up gcc-13
run: |
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-13 90

- name: Check versions
run: |
gcc --version
make --version

- name: make build
run: make build
18 changes: 10 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,27 @@
TEST_APP = test_linkedlist
TARGET_LIB = linkedlistlib.so

CC_MACOS = "/opt/homebrew/bin/gcc-13"
CC_LINUX = "/usr/bin/gcc"
CC_MACOS ?= /opt/homebrew/bin/gcc-13
CC_LINUX ?= /usr/bin/gcc

AR_MACOS = "/opt/homebrew/bin/gcc-ar-13"
AR_LINUX = "/usr/bin/ar"
AR_MACOS ?= /opt/homebrew/bin/gcc-ar-13
AR_LINUX ?= /usr/bin/ar

MEMCHECK_MACOS = "/usr/bin/leaks"
MEMCHECK_LINUX = "/usr/bin/valgrind"
MEMCHECK_MACOS ?= /usr/bin/leaks
MEMCHECK_LINUX ?= /usr/bin/valgrind

# Determine OS
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S),Darwin)
MEMCHECK = $(MEMCHECK_MACOS)
MEMCHECK_ARGS = --atExit --
CC = $(CC_MACOS)
AR = $(AR_MACOS)
endif
ifeq ($(UNAME_S),Linux)
MEMCHECK = $(MEMCHECK_LINUX)
MEMCHECK_ARGS =
CC = $(CC_LINUX)
AR = $(AR_LINUX)
endif
Expand Down Expand Up @@ -97,8 +99,8 @@ test: clean build $(TEST_APP) ## Run tests

.PHONY: memcheck
memcheck: test ## Run tests and check for memory leaks
@echo "Running tests with valgrind..."
leaks --atExit -- ./$(BUILD_DIR)/$(TEST_APP)
@echo "Running tests with memory check..."
$(MEMCHECK) $(MEMCHECK_ARGS) ./$(BUILD_DIR)/$(TEST_APP)

##@ Clean commands
.PHONY: clean
Expand Down