Last Updated: 2021-09-15 Wed 12:17

CSCI 2021 Lab02: Compiling / Testing C Code

CODE DISTRIBUTION: lab02-code.zip

CHANGELOG:

Wed Sep 15 11:36:26 AM CDT 2021
Some problems with the Lab02 autograder have been resolved. Tests should always have run correctly when done locally but now the problems on Gradscope have been resolved.

1 Rationale

This lab demonstrates a number of C programming conventions through a small application. Studying the code, correcting some mistakes in it, and adding some new functionality will familiarize students with the basic edit/compile/test cycle common to coding projects. Completing the lab will also show students a common application structure for C programs, dividing code between a main routine and a one or more "service" libraries that manipulate data structures. This approach will be used in an upcoming project.

Grading Policy

Credit for this Lab is earned by completing the exercises here and submitting a Zip of the work to Gradescope. Students are responsible to check that the results produced locally via make test are reflected on Gradescope after submitting their completed Zip. Successful completion earns 1 Engagement Point.

Lab Exercises are open resource/open collaboration and students are encouraged to coopearte on labs. Students may submit work as groups of up to 5 to Gradescope: one person submits then adds the names of their group members to the submission.

See the full policies in the course syllabus.

2 Codepack

The codepack for this lab is linked at the top of this document. Always download it and unzip/unpack it. It should contain the following files which are briefly described.

File Use Description
QUESTIONS.txt EDIT Questions to answer: fill in the multiple choice selections in this file.
list_main.c EDIT Main routine for linked list application to; edit it to complete for testing
list_funcs.c EDIT Library routine for linked list application to; edit it to complete for testing
Makefile Build Enables make test and make zip
list.h Header Header file for list types and functions
QUESTIONS.txt.bk Backup Backup copy of the original file to help revert if needed
QUESTIONS.md5 Testing Checksum for answers in questions file
test_quiz_filter Testing Filter to extract answers from Questions file, used in testing
testy Testing Test running scripts
test-lab01.org Testing Tests for this lab

3 Overview of Labwork

  1. If at any point you become confused by what to do next ask for help from your labmates or course staff.
  2. Download the lab01-code.zip file linked at the top of this document into your Unix environment and unzip it. In most UNIX environments you can use the terminal command

    > unzip lab01-code.zip
    

    to accomplish this. A number of files will be created in a the new folder lab01-code/.

  3. Find and open the QUESTIONS.txt file in a text editor which contains further instructions on what to do. There are several asks to play with basic UNIX commands. Execute the commands indicated and observer their results.
  4. Some parts of the text file are marked with QUESTION and have multiple choices. Mark the correct response as follows:

       QUESTION: Which of these is correct?
       - ( ) This is a wrong answer
       - ( ) This is also wrong
       - (X) This is the correct answer
       - ( ) And another wrong answer
    

    When you have filled in all your answers, check them via

    > make test-quiz
    
  5. Some activities will be based on writing CODE and marked as such. These will involve editing a file like the provided hello.c to complete it. Once you have completed the code necessary check it via

    > make test-code
    
  6. You can run tests for both the QUIZ and CODE sections with

    > make test
    

    which you should always do prior to submitting

  7. When you complete the QUIZ and CODE questions, create a zip of your lab work via

    > make zip
    

    and then upload the file to Gradscope as per the instructions in the last section.

4 QUESTIONS.txt File Contents

Below are the contents of the QUESTIONS.txt file for the lab. Follow the instructions in it to complete the QUIZ and CODE questions for the lab.

                           __________________

                            LAB 02 QUESTIONS
                           __________________





Lab Instructions
================

  Follow the instructions below to experiment with topics related to
  this lab.
  - For sections marked QUIZ, fill in an (X) for the appropriate
    response in this file. Use the command `make test-quiz' to see if
    all of your answers are correct.
  - For sections marked CODE, complete the code indicated. Use the
    command `make test-code' to check if your code is complete.
  - DO NOT CHANGE any parts of this file except the QUIZ sections as it
    may interfere with the tests otherwise.
  - If your `QUESTIONS.txt' file seems corrupted, restore it by copying
    over the `QUESTIONS.txt.bk' backup file.
  - When you complete the exercises, check your answers with `make test'
    and if all is well, create a zip file with `make zip' and upload it
    to Gradescope. Ensure that the Autograder there reflects your local
    results.
  - IF YOU WORK IN A GROUP only one member needs to submit and then add
    the names of their group.


Linked List Application
=======================

QUIZ Build Commands
~~~~~~~~~~~~~~~~~~~

  After downloading and unzipping the lab code, TAs will demonstrate how
  to compile the `list_main' application using a provided `Makefile' and
  the command `make'. They will demonstrate how to run several other
  useful commands via `make'. These are as follows:

  To remove all the compiled files (executable programs and `.o' files),
  the use `make' as follows:
  - ( ) make sanitize
  - ( ) make clean
  - ( ) make remove
  - ( ) make gc

  To run ALL the automated tests for the code through the given
  `Makefile' use the following command
  - ( ) make test
  - ( ) make verify
  - ( ) make examine
  - ( ) make unit
  Note: the default is to run all tests and you may need to specify WHAT
  to test, like a quiz, code, or an individual problem.

  To run only test #2 for the CODE portion of the tests and show the
  results, use the following `make' command:
  - ( ) make test2
  - ( ) make test-code 2
  - ( ) make unit test=2
  - ( ) make test-code testnum=2

  If I change code and want to see if any more tests pass after the
  change, I should type
  - ( ) `make' to rebuild followed by `make test' to run tests
  - ( ) `make clean' followed by `make' followed by `make test'
  - ( ) `make test' will rebuild based on changes AND then run tests
  - ( ) ALL of these will work but `make test' is the shortest and
    sweetest.

  Since compiling C programs involving several files is a bit painful,
  we will provide a `Makefile' on all of the course projects and the
  conventions outlined here will be followed to make life easier.
  Importantly, **passing automated tests will be part of project
  grades** so make sure you know how to run the tests.


CODE for Linked List Application
================================

  This lab's code pack contains an application featuring a linked
  list. The code is divided into an interactive `main()' function in
  `list_main.c' and a number of application. This application is
  described in some more detail in HW02 which is released this
  week. Refer to HW02 for more information on it.  You are encouraged to
  *study this program carefully* because
  - It demonstrates MANY common and useful techniques in C
  - You will need to write one like it in an upcoming project

  The `list_main' program has several problems that must be corrected to
  complete it.

  1. The builtin `get' command produces some errors. This will require
     editing the associated C function in `list_funcs.c' to correct it.
  2. The `contains' command is not implemented which will require adding
     a function to `list_funcs.c' and adding that command to
     `list_main.c'.
  3. The `list_insert()' function has a problem with its return value
     which causes `main()' to report incorrect results for it.

  Refer to HW02 for more detail. The objective is to fix the code so all
  tests for it pass:
  ,----
  | > make test-code
  | gcc -Wall -Wno-comment -Werror -g  -c list_main.c
  | gcc -Wall -Wno-comment -Werror -g  -c list_funcs.c
  | gcc -Wall -Wno-comment -Werror -g  -o list_main list_main.o list_funcs.o list.h
  | ./testy test_list_main.org 
  | ============================================================
  | == test_list_main.org : list_main application tests
  | == Running 4 / 4 tests
  | 1)  Print then Exit      : ok
  | 2)  Insert 3 and Print   : ok
  | 3)  Get Command          : ok
  | 4)  Contains Items       : ok
  | ============================================================
  | RESULTS: 4 / 4 tests passed
  `----

  NOTE: Initially the code for `list_main' will not compile. This is
  because the `main()' function uses the `list_contains()' function
  which is not present. Compiling will give an error like the following:

  ,----
  | > make
  | gcc -Wall -Werror -g  -c list_main.c
  | gcc -Wall -Werror -g  -c list_funcs.c
  | gcc -Wall -Werror -g  -o list_main list_main.o list_funcs.o list.h
  | /usr/bin/ld: list_main.o: in function `main':
  | lab02-code/list_main.c:91: undefined reference to `list_contains'   <<< missing function
  | collect2: error: ld returned 1 exit status
  | make: *** [Makefile:51: list_main] Error 1
  `----

  To initially fix this, you can uncommon the prototype for
  `list_contains()' at the end of the `list_funcs.c' file and add a
  return value as in
  ,----
  | int list_contains(list_t *list, char *query){
  |   //IMPLEMENT ME
  |   return 0;
  | }
  `----

  This should allow you to compile and run the tests. Most will fail but
  runnable tests are the first step to victory.
  ,----
  | > make
  | gcc -Wall -Werror -g  -c list_main.c
  | gcc -Wall -Werror -g  -c list_funcs.c
  | gcc -Wall -Werror -g  -o list_main list_main.o list_funcs.o list.h
  | 
  | > make test-code
  | ./testy test_list_main.org 
  | ============================================================
  | == test_list_main.org : list_main application tests
  | == Running 4 / 4 tests
  | 1)  Print then Exit      : ok
  | 2)  Insert 3 and Print   : FAIL -> results in file 'test-results/list_main-02-result.tmp'
  | 3)  Get Command          : FAIL -> results in file 'test-results/list_main-03-result.tmp'
  | 4)  Contains Items       : FAIL -> results in file 'test-results/list_main-04-result.tmp'
  | ============================================================
  | RESULTS: 1 / 4 tests passed
  `----

5 Submission

Follow the instructions at the end of Lab01 if you need a refresher on how to upload your completed lab zip to Gradescope.


Author: Chris Kauffman (kauffman@umn.edu)
Date: 2021-09-15 Wed 12:17