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.
This time you have to make your shell script is now robust towards filenames containing spaces
and other special symbols. All changes relative to lab8 are marked by *** below.
Objective
Write a Bourne Shell script called lab9 that runs a given program
against a set of files in the current directory and compares the output of said program
with predefined results.
*** Make sure that this program is robust to unusual file names.
Test that your program correctly implements the required functionality.
*** For this you have to create a C program that can be used to
generate many different of filenames.
More specifically, this program should print out a sequence of commands to copy
two given files, 01.in and 01.out, to a set of files, whose names start
with any ASCII character in the range from 32 to 126, with the
exception of 45 ('-') , 46 ('.'), and 47 ('/').
Finally, submit your solution electronically before the end of
the lab test using the command
submit 2031 lab9 lab9 lab9gen.c
You may submit your solution more than once. Additional documentation about the submit
command can be viewed by typing man submit.
What to do
First, create a new directory for this lab
after logging in, change your subdirectory to your directory for the class with
cd ~/2031. The '~' here refers to your home directory.
create a subdirectory called "lab9" in 2031
change the current directory to the newly created directory with cd lab9
Now create a ANSI-C program, called lab9gen.c, that does the following
Requirements
For every character between ASCII code 32 and 126 (with the exception of 45-47),
prints out two copy commands that copy the files 01.in and 01.out respectively to their new file
names.
For example and for the lines corresponding to character code 65 ("A"), the program should output the following 2 lines
cp 01.in "A.in"
cp 01.out "A.out"
If you capture the output of the C program to a file, said file should contain exactly
2*92 = 184 lines corresponding to 184 copy commands.
If you execute the output, with say sh filename this should create
many duplicates of the two files 01.in and 01.out with different names.
Your program should not produce any other output.
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.
*** For both the name of the C source file as well as the set of ".in" and
the corresponding ".out" files you must ensure that your program is robust to unsual
filenames, such as those containing a space character.
No other output must be produced.
If you start the program lab9gen, capture it's standard output into a file, and then
run the lab9 shell script, you should see a lot of failed tests in the output, similar
to the output for test 01 in the previous lab. If you fix the spelling error in the
version of lab5.c provided for the previous lab, and recompile that, you should see
a lot of passed tests.
Hints:
Note the quotes around the file names in the output of the C program.
Some characters may need special handling in the C program. Check the output of
your C program to discover what these may be.
Remember to quote all shell variables appropriately in your shell script.
'/' is excluded because it is the path name separator. '.' is excluded because it is part of the syntax for the current and parent directory.
The reason that the '-' character is excluded is that it serves as the character
for flags/options in many command line programs, such as "cc -c lab.c". That makes this
character difficult to handle.
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.