FormattersTest.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package info.hkzlab.dupal.analyzer;
  2. import static org.junit.Assert.*;
  3. import java.util.Arrays;
  4. import org.junit.Test;
  5. import info.hkzlab.dupal.analyzer.devices.PAL16L8Specs;
  6. import info.hkzlab.dupal.analyzer.exceptions.DuPALAnalyzerException;
  7. import info.hkzlab.dupal.analyzer.palanalisys.formatter.EspressoFormatter;
  8. import info.hkzlab.dupal.analyzer.palanalisys.graph.OutLink;
  9. import info.hkzlab.dupal.analyzer.palanalisys.graph.OutState;
  10. import info.hkzlab.dupal.analyzer.palanalisys.graph.OutStatePins;
  11. public class FormattersTest {
  12. @Test
  13. public void espressoFormatterShouldBuildCorrect16L8Header() {
  14. PAL16L8Specs pSpecs = new PAL16L8Specs();
  15. int ioAsOutMask = 0x03;
  16. String header = EspressoFormatter.formatEspressoTableHeader(pSpecs, ioAsOutMask);
  17. String expectedHeader = "# PAL16L8\n" + ".i 16\n" + ".o 8\n"
  18. + ".ilb i1 i2 i3 i4 i5 i6 i7 i8 i9 i11 io16 io15 io14 io13 fio18 fio17 \n"
  19. + ".ob o19 o12 io18 io17 o19oe o12oe io18oe io17oe \n" + ".phase 00001111\n\n";
  20. assertEquals("EspressoFormatter should build a correct 16L8 header", expectedHeader, header);
  21. header = EspressoFormatter.formatEspressoTableHeader(pSpecs, ioAsOutMask, true);
  22. expectedHeader = "# PAL16L8\n" + ".i 14\n" + ".o 8\n"
  23. + ".ilb i1 i2 i3 i4 i5 i6 i7 i8 i9 i11 io16 io15 io14 io13 \n"
  24. + ".ob o19 o12 io18 io17 o19oe o12oe io18oe io17oe \n" + ".phase 00001111\n\n";
  25. assertEquals("EspressoFormatter should build a correct 16L8 header ignoring feedback IOs", expectedHeader, header);
  26. }
  27. @Test
  28. public void espressoFormatterShouldBuildCorrect16L8TableWithoutRegLinks() throws DuPALAnalyzerException {
  29. PAL16L8Specs pSpecs = new PAL16L8Specs();
  30. int ioAsOutMask = 0x38;
  31. OutState[] states = new OutState[3];
  32. states[0] = new OutState(new OutStatePins(0x38, 0xC0), 3);
  33. states[1] = new OutState(new OutStatePins(0xAF, 0x20), 3);
  34. states[2] = new OutState(new OutStatePins(0x00, 0x00), 3);
  35. states[0].addOutLink(new OutLink(states[0], states[0], 0x00));
  36. states[0].addOutLink(new OutLink(states[0], states[1], 0x3800));
  37. states[0].addOutLink(new OutLink(states[0], states[2], 0x04));
  38. states[1].addOutLink(new OutLink(states[1], states[0], 0x00));
  39. states[1].addOutLink(new OutLink(states[1], states[1], 0x07));
  40. states[1].addOutLink(new OutLink(states[1], states[2], 0x04));
  41. states[2].addOutLink(new OutLink(states[2], states[2], 0x09));
  42. states[2].addOutLink(new OutLink(states[2], states[1], 0x2800));
  43. states[2].addOutLink(new OutLink(states[2], states[1], 0x04));
  44. String[] rows = EspressoFormatter.formatEspressoTable(pSpecs, ioAsOutMask, states);
  45. String[] expected = new String[] {
  46. "0000000000000111 --11111000\n",
  47. "0000000000011111 0110-00001\n",
  48. "0010000000000111 0000000000\n",
  49. "000000000000010- --11111000\n",
  50. "111000000000010- 0110-00001\n",
  51. "001000000000010- 0000000000\n",
  52. "1001000000000000 0000000000\n",
  53. "0000000000010000 0110-00001\n",
  54. "0010000000000000 0110-00001\n",
  55. };
  56. // Sort them, as we cannot guarantee the order of the formatted espresso table
  57. Arrays.sort(expected);
  58. Arrays.sort(rows);
  59. assertArrayEquals("EspressoFormatter should build the correct truth table for specified states", expected, rows);
  60. rows = EspressoFormatter.formatEspressoTable(pSpecs, ioAsOutMask, states, true);
  61. expected = new String[] {
  62. "0000000000000 --11111000\n",
  63. "0000000000011 0110-00001\n",
  64. "1110000000000 0110-00001\n",
  65. "0010000000000 0000000000\n",
  66. "1001000000000 0000000000\n",
  67. "0000000000010 0110-00001\n",
  68. "0010000000000 0110-00001\n",
  69. };
  70. // Sort them, as we cannot guarantee the order of the formatted espresso table
  71. Arrays.sort(expected);
  72. Arrays.sort(rows);
  73. assertArrayEquals("EspressoFormatter should build the correct truth table for specified states when ignoring feedback IOs", expected, rows);
  74. }
  75. }