multi.html 2.8 KB

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