Skip to content

Commit

Permalink
Merge pull request #4 from slashdevops/first-implementation
Browse files Browse the repository at this point in the history
feat: enable memcheck in workflow
  • Loading branch information
christiangda authored Mar 31, 2024
2 parents 475bf29 + 8366ae2 commit 5fa3ff7
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 11 deletions.
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

0 comments on commit 5fa3ff7

Please sign in to comment.