/test/kilim/test/TestUsage.java

http://github.com/kilim/kilim · Java · 56 lines · 36 code · 5 blank · 15 comment · 2 complexity · 70ca0ea045d2729a6fe33828a7d26cb8 MD5 · raw file

  1. /* Copyright (c) 2006, Sriram Srinivasan
  2. *
  3. * You may distribute this software under the terms of the license
  4. * specified in the file "License"
  5. */
  6. package kilim.test;
  7. import java.util.ArrayList;
  8. import kilim.analysis.Usage;
  9. import junit.framework.TestCase;
  10. public class TestUsage extends TestCase {
  11. /**
  12. * Tests whether a bunch of reads and writes produces the appropriate live-in
  13. */
  14. public void testReadWrite() {
  15. Usage u = new Usage(4);
  16. u.read(1);
  17. u.read(2);
  18. u.write(2);
  19. u.write(3);
  20. u.evalLiveIn(new ArrayList<Usage>(),null);
  21. assertFalse(u.isLiveIn(0));
  22. assertTrue(u.isLiveIn(1));
  23. assertTrue(u.isLiveIn(2));
  24. assertFalse(u.isLiveIn(3));
  25. }
  26. public void testChange() {
  27. Usage u = new Usage(31);
  28. Usage ufollow1 = new Usage(31);
  29. Usage ufollow2 = new Usage(31);
  30. // 29:R
  31. // 30:W
  32. // Usage 1 and 2.
  33. // 28:in 28:not_in
  34. // 29:in 29:not_in
  35. // 30:in 30:in
  36. // Expected usage.in : 28:in 29:in 30:not_in
  37. u.read(29); u.write(30);
  38. for (int ii=0; ii < 31; ii++) u.setBornIn(ii);
  39. ufollow1.setLiveIn(28); ufollow1.setLiveIn(29); ufollow1.setLiveIn(30);
  40. ufollow2.setLiveIn(30);
  41. ArrayList<Usage> ua = new ArrayList<Usage>(2);
  42. ua.add(ufollow1); ua.add(ufollow2);
  43. assertTrue(u.evalLiveIn(ua,null)); // should return changed == true
  44. for (int i = 0; i < 28; i++) {
  45. assertFalse(u.isLiveIn(i));
  46. }
  47. assertTrue(u.isLiveIn(28));
  48. assertTrue(u.isLiveIn(29));
  49. assertFalse(u.isLiveIn(30));
  50. }
  51. }