Principles of Programming Languages - F16

CSE 340

Project 1

Project 1 is due 8/29/16 on or before 11:59:59pm MST.

Part 1 (10 points)

Sign up for the course mailing list. Please provide your ASURITE ID number when you register so that we can give you credit for signing up.

Part 2 (45 points)

The goal of this project is to get your CSE 340 assignment enviornment installed and configured. This will save you many hours of grief in the future.

Part 2.1

You need to install CentOS 7 on a virtual machine. Read the document CSE340F16_CentOS_Guide.pdf carefully and follow the instructions in that guide to install CentOS 7 on a virtual machine.

If you don’t have a system to do this, you can use the computers in the Brickyard 214 lab.

Part 2.2

Register for the course submission website at: https://cse340.fulton.asu.edu/cse340/

You should use this website to submit all programming assignments in this course. If you run into problems using this website, send an email to our amazing TA Mohsen Zohrevandi [email protected].

Part 2.3

After finishing part 2.1, download secret.h and secret_64bit.o (or secret_32bit.o) depending on the installed CentOS 7 architecture. Then, copy the following code in a new text file and change the number on line 5 to match your ASU Id:

1
2
3
4
5
6
7
#include "secret.h"

int main()
{
    secret_function("1234567890"); // TODO: replace the number with your ASU Id
    return 0;
}

Save this file with name project1.c in the same folder as secret.h. Then open a terminal window to compile and link the program with the following command:

gcc secret_64bit.o project1.c

If running on a 32-bit architecture, use secret_32bit.o instead of secret_64bit.o.

If all goes well, you should have an executable file named a.out. Execute it with the following command:

./a.out > p1_output.txt

Submit the resulting file p1_output.txt in the course submission website.

Part 3 (45 points)

A key element of success in the course projects is to create additional test cases beyond what we provide you. Thinking about how to properly test your code and create test cases is a valuable skill that will benefit your future career.

The goal of this project is to get familiar with creating test cases that exercise all code in a program. A side benefit of this project is practicing reading other people’s code, which you will do significantly throughout your career.

On the submission site you will find program.c

You need to write a test suite that achieves 100% code coverage of program.c.

Code Coverage

Code Coverage is a measurement that describes how much of a program is exercised by a test suite. A test suite with high code coverage will increase the assurance that the program meets the specification, while a test suite with low code coverage does not properly exercise all of the program’s functionality.

We will use the program gcov to measure the code coverage of your test suite. It is imperative that you use gcov to test the code coverage of your test suite before you submit.

To measure the code coverage of your test suite using gcov, you must first compile program.c with special GCC flags (note that only -fprofile-arcs and -ftest-coverage are required, however -Wall, which displays all warnings, is an excellent habit to create and continue in the rest of the course):

gcc -Wall -fprofile-arcs -ftest-coverage program.c

After running this command, gcc will create an executable file a.out in the current directory. Now, every time a.out is executed, the code coverage will be measured.

Say we have two test cases in our test suite, test_1 and test_2, both in the test_cases directory. We can then run the test cases against a.out like so:

./a.out < test_cases/test_1
./a.out < test_cases/test_2

Now, we can generate the code coverage percentage with gcov:

gcov program.c

It is important that you run gcov in the same directory that you ran ./a.out.

The code coverage score that gcov reports will be your score on this part of the assignment. gcov will also generate a file program.c.gcov, and this file contains valuable information about the lines of code in program.c that your test suite executed (as well as how many times it was executed).

Evaluation System

The evaluation system is running the same OS that you set up in part 2, so you must use this when running gcc and gcov.

Submission

Your submission for this part of the project is the test suite. You must submit a file called test_cases.tar.gz, and that file must contain a directory called test_cases will all the test cases inside (it does not matter what you call the test cases).

test_cases.tar.gz can be created by the following command (run in the same directory that contains test_cases):

tar -czvf test_cases.tar.gz test_cases

Then submit test_cases.tar.gz to the online submission system for immediate evaluation and feedback.

Further Exploration

There are many different measurements for code coverage, and we are using statement coverage in this project. Some are coarse-grained, such as function/method coverage. Others are more fine-grained, such as branch coverage or condition coverage. If you want to expand your knowledge, study the differences between these, and challenge yourself to achieve 100% branch coverage in this project.

Credit

Part 2 of this project description was created by Mohsen Zohrevandi, and is used with permission.