EECS 2031 Software Tools, Winter 2014
Lab 8
Cellphones and other electronic devices must be off while you are in the lab.
Background Scenario
The objective of this lab is to create a simple test framework for testing commandline
application, such as the bathroom scale program created in the previous labs.
Objective
- Write a Bourne Shell program called lab8 that runs a given program
against a set of files in the current directory and compares the output of said program
with predefined results.
- Test that your program correctly implements the required functionality
- Finally, submit your solution electronically before the end of
the lab test using the command
submit 2031 lab8 lab8
- You may submit your solution more than once. Additional documentation about the submit
command can be viewed by typing man submit.
Now create a new Bourne Shell script that does the following.
Requirements
- The first parameter of the program is the name of the program to test (without
any extension).
- In the following, you can assume that all referenced files exist in the current directory.
If the C source file is missing, print File #### not found,
where #### is replaced by the name of the missing file,
followed by a newline character to standard output and exit the script.
- Your program must first compile the .c file corresponding to this lab, such as lab5.c.
The name of the executable should be the same as the name of the lab.
If the compilation yields errors (not warnings), you must print Cannot compile
followed by a newline character and exit the script.
- Then the program must iterate through all files ending with ".in" and
provide them as standard input to the program compiled in the previous step.
- Before the next step, print Running test #### to standard output,
where #### is replaced by the name of the input file
(without the suffix/extension), followed by a newline character.
- For each ".in" file, the output of the program
should be compared with the corresponding ".out" file with
the diff program. More precisely, the output of the program must
be supplied as the first argument to the diff command, and the ".out" file
as the second argument. The output from the diff program should appear in
the standard output.
- If the diff command does not detect any differences output, you must print
Test #### passed to standard output, where #### is replaced by the name of the input file
(without the suffix/extension), followed by a newline character.
- If the diff command detects differences, you must print
Test #### failed to standard output, where #### is replaced by the name of the input file
(without the suffix/extension), followed by a newline character.
- No other output must be produced.
For the purpose of this lab, you do not need to worry about spaces or other
special characters in filenames.
Here is an example set of input files, provided as a .zip archive:
files.zip. It contains the files
lab5.c (a purposefully broken version), 00.in, 00.out, 01.in, 01.out.
If you start your script with sh lab8 lab5 in the directory where you unpacked
the above zip archive, you should get the following output, also provided as
a file, expectedoutput.txt.
Running test 00
Test 00 passed
Running test 01
1c1
< Invalid times
---
> Invalid time
Test 01 failed
Hints:
- You can use the basename command to strip of the ".in" suffix from
a file name.
- It is easiest if you pipe the output from the compiled
program directly into the diff program.
If you provide a minus sign as an argument to the diff program, it
will read from standard input, i.e., the pipe.
The exit status of a pipe is the status of the last command in the pipe.
- It is usually easier to address each individual requirement to your code only after
you have verified that the previous requirement is met by your program.