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.hthat takes two numbers and returns the product. - Add a function prototype to
lab.hthat 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
make clean
make all
make reportOpen ./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.
// GCOVR_EXCL_START
// GCOVR_EXCL_STOPTask 4 - Leak and crash check
- Update
main.cto 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 thevolatilekeyword and work out why the release build might not crash. - Add a memory leak in
main.cand another one somewhere inlab.c. - Run
make leak, thenmake 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-teston 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
- Download
submission-report.docxfrom GitHub and submit it to Canvas. - You can view your own submissions in Canvas, so check that everything looks right.
- If GitHub Actions is down, or hangs for more than 5 minutes, generate the report on Onyx instead.
Rubric
| # | Criterion | Points |
|---|---|---|
| 1 | Both functions are declared in lab.h with include guards and implemented in lab.c | 16 |
| 2 | Unity tests cover every function in lab.h and make check runs them | 20 |
| 3 | make report shows 100% coverage with no unjustified exclusions | 20 |
| 4 | Leak and crash behavior demonstrated; make leak-test output included | 16 |
| 5 | Debugger used on both the executable and the test target | 8 |
| 6 | README.md replaced and follows the example format | 10 |
| 7 | CI is green on the last push and the submission report was generated | 10 |