Last Updated: 2024-02-03 Sat 12:44

CMSC216 Lab01: Basic Setup

CODE DISTRIBUTION: lab01-code.zip

  • Download the code distribution
  • See further setup instructions below

CHANGELOG:

Tue Jan 30 12:38:06 PM EST 2024

An early draft of lab01-code.zip had some mistakes in the provided Makefil. These will appear as errors in command like make test-quiz that look like this:

  >> make test-quiz
  ./testy test_dis01.org 1
  ERROR: could not open 'test_dis01.org' for reading
  make: *** [Makefile:55: test-quiz] Error 1

This can be fixed in one of two ways

  1. Open the Makefil in a text editor and replace all occurrences of the string dis01 with lab01 (best done via a text editor "Find/Replace" functionality)
  2. Download the current version of lab01-code.zip and copy over the Makefile in it to your lab code directory. Be careful when unzipping not to overwrite any work you have done. Consider creating a temporary directory via mkdir tmp and download the fresh zip there to avoid conflicting with an existing copy.

Students that downloaded the lab as of noon on Monday should not have this problem as the Makefile was corrected by then.

1 Rationale

This exercise will introduce students to the basic UNIX programming environment which will be used throughout the course. Staff will be on hand to help students set up their environment and complete the exercises.

Associated Reading

Steps to set up your coding environment are in the Coding Environment Setup Guide

Grading Policy

Credit for this exercise is earned by completing the code/asnwers 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 cooperate 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 these exercises 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.
hello.c EDIT C file to; edit it to complete for testing
QUESTIONS.txt.bk Backup Backup copy of the original file to help revert if needed
Makefile Build Enables make test and make zip
test-lab01.org Testing Automated tests for these exercises
test_quiz_filter Testing Filter to extract answers from Questions file, used in testing
testy Testing Test running scripts

3 Programming Environment Setup

The course will require you to do some programming in a UNIX/Linux environment and the course staff have prepared a guide to getting access to such an environment here:

https://docs.google.com/document/d/1lp-6lLY4pdKJusum-WG1NvgjtHsQEom2pQZGqnF4zz8

This guide outlines necessary software to access a UNIX/Linux environment, primarily through remote login to UMD's GRACE server though there are other options. Lab staff will walk through the necessary software to install and demonstrate how to access the server.

4 Overview of Exercises

  1. During discussion, staff will walk students through some of instructions in below and then provide time to complete the exercise. This may be done individually or in groups.
  2. You are NOT required to work in a group but many students find it helpful to form some connections and maintain them throughout the semester. Discussion sections are a place you might do that. Take this as an opportunity to meet some classmates: having a community of support makes any class easier to handle.
  3. If at any point you become confused by what to do next ask for help from your classmates or course staff.
  4. 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/.

  5. 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.
  6. 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
    
  7. When you have filled in all your QUIZ answers, check them via the provided make command. In a terminal, type the command

    > make test-quiz
    

    which checks the quiz questions for correctness. QUIZ Correctness is "all or nothing" : if any errors exist, no credit is earned and you will need to review all answers to figure out which ones are problematic. Fully correct answers give an "OK" for full credit.

  8. 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 a terminal using the command

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

    > make test
    

    which you should always do prior to submitting

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

    > make zip
    

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

5 QUESTIONS.txt File Contents

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

                           _________________

                            LAB01 QUESTIONS
                           _________________





Exercise Instructions
=====================

  Follow the instructions below to experiment with topics related to
  this exercise.
  - 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.

  Follow the instructions below. For sections marked QUIZ, mark one of
  the multiple choices with an X.


Unix Terminal Basics
====================

  Explore the UNIX terminal a bit. Ask for help from a classmate or
  Staff member if you don't know how to open a terminal on your system.

  Type the below commands in and then indicate what their purpose is.


QUIZ Secure Shell
~~~~~~~~~~~~~~~~~

  All recent major platforms (Windows / Mac / Linux) come with the `ssh
  / scp' tools pre-installed.

  What does the following command do?
  ,----
  | > ssh kauf0095@grace.umd.edu
  `----


  - ( ) Silences the user `kauff095' on the machine `grace' so that user
    can no longer type any commands and must reset their password.
  - ( ) Opens an unsecure connection to the machine `grace' for the user
    `kauf0095' and allows anyone typing to the command to act as that
    user on `grace' without password verification and without any
    encryption of the connection.
  - ( ) Opens a secure connection to the machine `grace' for the user
    `kauf0095' and, after verifying a password/2-factor authentication,
    opens a terminal/shell on that machine for further commands.


  What does the following command do?
  ,----
  | > scp ./lab01-code.zip kauf0095@grace.umd.edu:cmsc216/
  `----

  - ( ) Copies a file from the Grace server to a local machine (laptop)
  - ( ) Copies a file from a local machine (laptop) to the Grace
    server's cmsc216 folder

  What does the following command do?
  ,----
  | > scp kauf0095@grace.umd.edu:cmsc216/lab01-complete.zip .
  `----

  - ( ) Copies a file from the Grace server's cmsc216 folder to a local
    machine (laptop)
  - ( ) Copies a file from a local machine (laptop) to the Grace
    server's csmc216 folder


QUIZ Retrieving Codepacks
~~~~~~~~~~~~~~~~~~~~~~~~~

  Which of the following is a viable way to get a codepack like
  `lab01-code.zip' onto Grace?

  - ( ) Download the code to your laptop and use `scp' to transfer the
    codepack from the
  - ( ) On Grace, use `wget' to download the code directly from a web
    address
  - ( ) Use a graphical file transfer program like MobaXTerm or an SFTP
    client to move files over from the local machine
  - ( ) All of these are possible BUT using `wget' is usually the
    quickest way to initially get a codepack to Grace from the web.


QUIZ UNIX Command Basics
~~~~~~~~~~~~~~~~~~~~~~~~

  What does the following command sequence do?
  ,----
  | > cd ~                          # 1 
  | > mkdir csci2021                # 2 
  | > cd csci2021                   # 3 
  | > ls                            # 4 
  | > cd ..                         # 5 
  `----

  ,----
  | - ( ) 1. Changes to your home directory/folder
  |       2. Creates a folder named csci2021
  |       3. Changes the directory csci2021 to be your home folder
  |       4. lists the files in the current folder, 
  |       5. changes the directory .. to be your home folder
  | 
  | - ( ) 1. Creates a directory/folder named ~ (tilde) 
  |       2. creates a file named csci2021, 
  |       3. creates a second folder csci2021, 
  |       4. lists the files in the current folder, 
  |       5. moves up one folder
  | 
  | - ( ) 1. Changes to your home directory/folder, 
  |       2. creates a folder named csci2021
  |       3. changes into the folder csci2021, 
  |       4. lists the files in the current folder,
  |       5. moves up one folder
  `----


Checking Your Quiz Answers
==========================

  To check if your quiz answers are correct, open a terminal and change
  into the `lab01-code' directory.  Type the command
  ,----
  | > make test-quiz
  `----

  which will report either success or a failure.  The test does not
  report WHICH questions are incorrect and if you get stuck, get some
  help from a staff member to sort out which of the multiple choice
  questions above is incorrect.


CODE in hello_c.c
=================

  Open up and examine the file `hello_c.c'.  This is a C program and to
  see what it in action, you will need to compile and run it in a
  terminal.  Navigate your terminal to the `lab01-code' directory.  You
  can use the provided build tools to create the C program by typing
  ,----
  | > make
  `----

  This should provide output which runs the `gcc' compiler and creates
  the runnable program `hello_c': notices the lack of the `.c'
  extension. A session of compiling, running, and testing the program is
  below with commentary on the right.
  ,----
  | > make                # compile the program 'hello_c'
  | gcc -Wall -Wno-comment -Werror -g  -o hello_c hello_c.c
  | 
  | > file hello_c        # check file type of program
  | hello_c: ELF 64-bit LSB pie executable, x86-64, version
  | 
  | > ./hello_c           # run compiled program
  | Goodbye Python. Goodbye Java.
  | ...
  | 
  | > make test-code
  | ./testy test_lab01.org 2
  | ============================================================
  | == test_lab01.org : Lab01 Tests
  | == Running 1 / 2 tests
  | 2)  CODE: hello_c output : FAIL -> results in file 'test-results/lab01-02-result.tmp'
  | ============================================================
  | RESULTS: 0.00 / 1.00 tests passed
  | 
  | 
  | ============================================================
  | == FAILURE RESULTS
  | ============================================================
  | (TEST 2) CODE: hello_c output
  | COMMENTS:
  | Runs the program 'hello_c' which must already be compiled and checks
  | ...
  `----

  As indicated in the comments in `hello_c.c', there are a number of
  typos, missing, and extraneous lines printed by the program.  To make
  the code pass the tests, you will simply need to correct `hello_c.c'
  to match the output expected for the test.  As the Comments for the
  CODE test indicate, failures report differences between the expected
  and actual output with symbols between the side-by-side
  comparison. These symbols are those used by the comparison program
  `diff' and are as follows:
  ,----
  | > means there is an extra ACTUAL line that doesn't match anything in EXPECT
  | < means there is a line missing in ACTUAL that is present in EXPECT
  | | means the lines match closely but some characters differ
  `----

  Edit code in `hello_c.c' so that the output matches and testing the
  code produces a success:
  ,----
  | > make test-code
  | gcc -Wall -Wno-comment -Werror -g  -o hello_c hello_c.c
  | ./testy test_lab01.org 2
  | ============================================================
  | == test_lab01.org : Lab01 Tests
  | == Running 1 / 2 tests
  | 2)  CODE: hello_c output : ok
  | ============================================================
  | RESULTS: 1.00 / 1.00 tests passed
  `----


Submitting a Zip for Gradescope
===============================

  Once you have your QUIZ answers for the `QUESTIONS.txt' file correct
  and your CODE completed, do one final check via `make test':
  ,----
  | > make test
  | ./testy test_lab01.org
  | ============================================================
  | == test_lab01.org : Lab01 Tests
  | == Running 2 / 2 tests
  | 1)  QUIZ: QUESTIONS.txt  : ok
  | 2)  CODE: hello_c output : ok
  | ============================================================
  | RESULTS: 1.00 / 1.00 tests passed
  `----
  If everything looks ok, you are ready to submit.  Do so by creating a
  zip file via `make zip'
  ,----
  | > make zip
  | rm -f hello_c  *.o
  | rm -rf test-results
  | rm -f lab01-code.zip
  | cd .. && zip "lab01-code/lab01-code.zip" -r "lab01-code"
  | 	zip warning: name not matched: lab01-code/test_lab01.org~
  |   adding: lab01-code/ (stored 0%)
  |   adding: lab01-code/QUESTIONS.md5 (stored 0%)
  |   adding: lab01-code/QUESTIONS.txt (deflated 61%)
  |   adding: lab01-code/QUESTIONS.txt.bk (deflated 61%)
  |   adding: lab01-code/testy (deflated 73%)
  |   adding: lab01-code/hello_c.c (deflated 51%)
  |   adding: lab01-code/Makefile (deflated 60%)
  |   adding: lab01-code/test_lab01.org (deflated 47%)
  | Zip created in lab01-code.zip
  `----

  The zip file named `lab01-code.zip' should be uploaded to Gradescope
  under the Lab01 assignment. Once uploaded, the same `make test' check
  will be run and you should verify its success as this will earn you
  your lab Engagement Point (1% of your overall grade).

  IF YOU ARE WORKING IN A GROUP: only one student needs to upload the
  Zip file and can add up to 4 other students (groups of 5) to the
  submission who will also receive credit for the lab work.

6 Submission

6.1 Check via make test

Once you have your QUIZ answers for the QUESTIONS.txt file correct and your CODE completed, do one final check via make test:

> make test
./testy test_lab01.org
============================================================
== test_lab01.org : LAB01 Tests
== Running 2 / 2 tests
1)  QUIZ: QUESTIONS.txt  : ok
2)  CODE: hello_c output : ok
============================================================
RESULTS: 1.00 / 1.00 tests passed

6.2 Create a Zip

If everything looks ok, you are ready to submit. Do so by creating a zip file via make zip

>> make zip
rm -f hello_c  *.o
rm -rf test-results
rm -f lab01-code.zip
cd .. && zip "lab01-code/lab01-code.zip" -r "lab01-code"
	zip warning: name not matched: lab01-code/test_lab01.org~
  adding: lab01-code/ (stored 0%)
  adding: lab01-code/QUESTIONS.md5 (stored 0%)
  adding: lab01-code/QUESTIONS.txt (deflated 61%)
  adding: lab01-code/QUESTIONS.txt.bk (deflated 61%)
  adding: lab01-code/testy (deflated 73%)
  adding: lab01-code/hello_c.c (deflated 51%)
  adding: lab01-code/Makefile (deflated 60%)
  adding: lab01-code/test_lab01.org (deflated 47%)
Zip created in lab01-code.zip

6.3 Submitting to Gradescope

The zip file named lab01-code.zip should be uploaded to Gradescope under the Lab01 assignment. Once uploaded, the same make test check will be run and you should verify its success as this will earn you your Engagement Point (1% of your overall grade).

The following pictures illustrate how to submit the code.

gradescope1.png

gradescope2.png

gradescope3.png

gradescope4.png

gradescope5.png

gradescope6.png

gradescope7.png

Make sure to check that your submission passes tests online; otherwise you'll lose out on your Engagement Point. You can resubmit as many times as you wish up to the assignment deadline (usually Tuesday nights).

No late submission are accepted for Discussion Exercises.

6.4 Adding Group Members

IF YOU ARE WORKING IN A GROUP: only one student needs to upload the Zip file and can add up to 4 other students (groups of 5) to the submission who will also receive credit for the lab work.

The following pictures show where you can add group members AFTER uploading a Zip file.

gradescope-group1.png

gradescope-group2.png


Author: Chris Kauffman (profk@umd.edu)
Date: 2024-02-03 Sat 12:44