1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <html>
- <head>
- <title>Testing multiple files</title>
- </head>
- <body bgcolor="FFFFFF">
- <h1>Testing multiple files</h1>
- <p>In the classroom example, you will have many files that you wish to test
- for their equivalence, and you won't want to read the output for each
- of the student's solutions.</p>
- <h2>Building comparison into the circuit</h2>
- <p>One approach is to build a test circuit that does the comparison directly.
- Here, we create an additional circuit within the testing file that contains
- our solution circuit. In our overall testing circuit, we include both the
- subcircuit from <tt>adder-master.circ</tt> and the subcircuit from the solution
- circuit located directly into the nested circuit. We wire it so that there is
- just one output, which is 1 as long as the two subcircuits agree.</p>
- <blockquote><img src="../../../img-guide/verify-adder-test2.png" width="274" height="92"></blockquote>
- <p>Now we can simply run Logisim substituting each query file. For any correct
- solution, the only output will be <q>1</q>.</p>
- <h2>Using redirection and shell scripts</h2>
- <p>If you're quite comfortable with the command line,
- you can build your own shell script to accomplish this.
- Here, we'll use redirection (the > operator) to save the output of each
- circuit into a file.
- For instance, we might issue the following two commands to collect the output
- of the master circuit and the query circuit.
- <blockquote><tt>java -jar logisim-filename.jar adder-test.circ -tty table > output-master.txt
- <br>java -jar logisim-filename.jar adder-test.circ -tty table -sub adder-master.circ adder-query.circ > output-query.txt</tt></blockquote>
- <p>Now we've created two different files.
- We can then compare the two output files using a program built for that purpose.
- Under Linux or MacOS X, you might want to use the <em>cmp</em> or <em>diff</em>
- command-line utilities. Under Windows, you might want to use WinMerge.</p>
- <p>To process several query files, you would like want to build a simple program
- such as a shell script to iterate through each and comparing the output.
- Here is how I would do it under Linux's <em>bash</em>:</p>
- <blockquote><tt>RUN_TEST="java -jar logisim-filename.jar adder-test.circ -tty table"<br>
- ${RUN_TEST} > output-master.txt<br>
- for QUERY_FILE in adder-query*.circ<br>
- do<br>
- if ${RUN_TEST} -sub adder-master.circ ${QUERY_FILE} | cmp -s output-master.txt<br>
- then<br>
- echo "${QUERY_FILE} OK"<br>
- else<br>
- echo "${QUERY_FILE} different"<br>
- fi<br>
- done</tt></blockquote>
- <p><strong>Next:</strong> <em><a href="../index.html"><em>User's Guide</em></a></em>.</p>
- </body>
- </html>
|