Skip to content

P0 - Compile, Test, Debug ​

Week 2 · 100 points · about 3 hours · submit in Canvas

Overview ​

This project introduces the project template, the build system, and the workflow you will use for every project this semester. There is no networking in it at all. The point is to prove that your toolchain works before the material gets hard.

Fork the starter repository into your own GitHub account using the Use this template button, and name your copy cs425-p0.

DANGER

Your code must compile on GitHub Codespaces and Onyx. If it compiles on only one of them you will receive a zero even if it works on the other. Writing portable code is a learning objective of this class.

Learning Outcomes ​

  • 7.1 Build code with a build system and run it under a unit test framework
  • 7.2 Produce code free of memory leaks and out-of-bounds accesses
  • 7.3 Compile and run code on at least two different systems
  • 7.4 Use continuous integration to test every change
  • 7.5 Use a professional version control system (git)

Task 1 - Update lab.h and lab.c ​

  • Add a function prototype to lab.h that takes two numbers and returns the product.
  • Add a function prototype to lab.h that takes two numbers and returns an incorrect sum. You are going to need something broken to debug in Task 5.
  • Do not forget the include guards for the header.
  • Implement both functions in lab.c.
  • Compile with make all.

Task 2 - Tests ​

We use Unity as the test harness. Read its documentation so you know what assertion macros it gives you.

  • Add a new test for every function in lab.h.
  • Build the project with make all.
  • Run the tests with make check.

Task 3 - Coverage ​

bash
make clean
make all
make report

Open ./build/report/html/coverage_report.html in a browser (or the VS Code preview) to see where your coverage is thin. make report also prints a shorter text summary to the terminal, and that summary is what goes into your submission report.

Fix your code until you have 100% coverage with all tests passing. You may use the annotations below to exclude lines, but you are only allowed to exclude branches that originate from system calls or library calls.

c
// GCOVR_EXCL_START
// GCOVR_EXCL_STOP

Task 4 - Leak and crash check ​

  • Update main.c to crash on purpose. Dereferencing a NULL pointer will do it.
  • Run make all.
  • Run the debug build, ./build/debug/myapp_d.
  • Run the release build, ./build/release/myapp. Notice any difference? Look up the volatile keyword and work out why the release build might not crash.
  • Add a memory leak in main.c and another one somewhere in lab.c.
  • Run make leak, then make leak-test.
  • Read the output carefully so you know what a leak looks like when you cause one by accident later in the semester.
  • Once you have seen both, remove the crash and both leaks. CI runs make leak-test on every push, so a leak you leave in will fail Task 7.

Task 5 - Run the debugger ​

  • Run the VS Code Debug Exe configuration. Put a breakpoint in main, hit it, and step through your code.
  • Run the VS Code Debug Tests configuration. Put a breakpoint inside your broken add function, hit it, and step through until you can see the wrong value.

Task 6 - Replace README.md ​

Replace README.md following this example.

Task 7 - Continuous integration ​

  • Fix your code so coverage is 100% and every test passes.
  • Push everything to GitHub.
  • Open the Actions tab, click Continuous Integration (CI), and confirm your last push is green. If it is not, open the run and fix the problem.
  • Go to Create Submission Report Via GitHub Action and click Run workflow.
  • Refresh once it finishes. Your repository will now contain submission-report.docx.

Submitting ​

  1. Download submission-report.docx from GitHub and submit it to Canvas.
  2. You can view your own submissions in Canvas, so check that everything looks right.
  3. If GitHub Actions is down, or hangs for more than 5 minutes, generate the report on Onyx instead.

Rubric ​

#CriterionPoints
1Both functions are declared in lab.h with include guards and implemented in lab.c16
2Unity tests cover every function in lab.h and make check runs them20
3make report shows 100% coverage with no unjustified exclusions20
4Leak and crash behavior demonstrated; make leak-test output included16
5Debugger used on both the executable and the test target8
6README.md replaced and follows the example format10
7CI is green on the last push and the submission report was generated10

Released under the MIT License.