Skip to content
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
27 changes: 27 additions & 0 deletions .github/workflows/gtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: gtest

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Cache gtest library
uses: actions/cache@v2
env:
cache-name: cache-gtest-lib
with:
key: $${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/usr/local/lib/libgtest.a') }}
path: /usr/local/lib/libgtest.a
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install gtest manually
run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
- name: Check out the code
uses: actions/checkout@v2
- name: Compile test code
run: g++ -Wall -g -o check_whitespace_test check_whitespace.c check_whitespace_test.cpp -lgtest -pthread
- name: Run test
run: ./check_whitespace_test
29 changes: 29 additions & 0 deletions .github/workflows/main_valgrind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: main-valgrind

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Cache gtest library
uses: actions/cache@v2
env:
cache-name: cache-gtest-lib
with:
key: $${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/usr/local/lib/libgtest.a') }}
path: /usr/local/lib/libgtest.a
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install gtest manually
run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
- name: Install valgrind
run: sudo apt-get install -y valgrind
- name: Check out the code
uses: actions/checkout@v2
- name: Compile code
run: gcc -Wall -g -o check_whitespace check_whitespace.c main.c
- name: Run test
run: valgrind -v --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./check_whitespace < main.c
29 changes: 29 additions & 0 deletions .github/workflows/test_valgrind.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: test-valgrind

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Cache gtest library
uses: actions/cache@v2
env:
cache-name: cache-gtest-lib
with:
key: $${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('/usr/local/lib/libgtest.a') }}
path: /usr/local/lib/libgtest.a
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install gtest manually
run: sudo apt-get install libgtest-dev && cd /usr/src/gtest && sudo cmake CMakeLists.txt && sudo make && sudo cp lib/*.a /usr/lib && sudo ln -s /usr/lib/libgtest.a /usr/local/lib/libgtest.a && sudo ln -s /usr/lib/libgtest_main.a /usr/local/lib/libgtest_main.a
- name: Install valgrind
run: sudo apt-get install -y valgrind
- name: Check out the code
uses: actions/checkout@v2
- name: Compile code
run: g++ -Wall -g -o check_whitespace_test check_whitespace.c check_whitespace_test.cpp -lgtest -pthread
- name: Run test
run: valgrind -v --leak-check=full --show-leak-kinds=all --error-exitcode=1 ./check_whitespace_test
42 changes: 42 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
# C-programming-pre-lab <!-- omit in toc -->

[![Tests](../../workflows/gtest/badge.svg)](../../actions?query=workflow%3A"gtest")
[![Main Valgrind](../../workflows/main-valgrind/badge.svg)](../../actions?query=workflow%3A"main-valgrind")
[![Test Valgrind](../../workflows/test-valgrind/badge.svg)](../../actions?query=workflow%3A"test-valgrind")


This is a pre-lab to get you started started on compiling and running C programs
and using `valgrind` to identify memory leaks.

- [Background](#background)
- [Compiling and running a C program](#compiling-and-running-a-c-program)
- [Compiling and running the tests](#compiling-and-running-the-tests)
- [Using valgrind to find memory leaks](#using-valgrind-to-find-memory-leaks)
- [GitHub Actions and badges](#github-actions-and-badges)
- [What to do](#what-to-do)

## Background
Expand Down Expand Up @@ -313,6 +319,42 @@ Once you have everything happy, you will hopefully get a line like:

at the end indicating that you now have 0 errors and all is well.

## GitHub Actions and badges

We've set up GitHub Actions to automatically run three checks on your
code every time you push changes to GitHub:

- The code compiles and the tests pass.
- Valgrind returns no errors when running the `main` function.
- Valgrind returns no errors when running the test code.

You should be able to see the status of these in a commit or pull request
in GitHub. Here, for example, is a status from a pull request:

![Screen grab of GitHub Action status showing success, failure, and pending](images/GitHub_action_status.png)

We have all three possible status indicators here:

- The red x indicates a failing check
- The orange dot indicates a check that's still in progress
- The green checkmark indicates a check that passed

When you initially check out the code for the pre-lab, the `gtest`
check should pass (the tests pass), but the other two should fail
because there are memory issues with both the `check_whitespace`
`main()` and the tests.

We have also added three badges to the top of this README that indicate
the status of each of these three status checks. The tests badge should
be green from the beginning (and stay green throughout the process).
The two `valgrind` badges will both start off red (because the `valgrind`
checks fail initially) but turn green after you've fixed the memory
management issue.

> :warning: The badges won't update instantly, so don't fret if
> your status checks are green but the badge is still red. That
> should update in a few minutes.

## What to do

- [ ] Compile the program `check_whitespace`
Expand Down
Binary file added images/GitHub_action_status.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.