LabelSplicer_test.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* vim: set expandtab ts=4 sw=4: */
  2. /*
  3. * You may redistribute this program and/or modify it under the terms of
  4. * the GNU General Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  14. */
  15. #include "switch/LabelSplicer.h"
  16. #include "util/Endian.h"
  17. #include "util/Constant.h"
  18. #include "util/Assert.h"
  19. #include <stdio.h>
  20. #include <inttypes.h>
  21. static void unsplice()
  22. {
  23. Assert_true(0x13 == LabelSplicer_unsplice(0x13, 1));
  24. }
  25. static void splice()
  26. {
  27. uint64_t goHere = Constant_base2(000000100);
  28. uint64_t viaHere = Constant_base2(000000100);
  29. uint64_t expected = Constant_base2(000010000);
  30. uint64_t out = LabelSplicer_splice(goHere, viaHere);
  31. printf("Splicing %" PRIu64 " with %" PRIu64 " yields %" PRIu64 ", expecting %" PRIu64 "\n",
  32. goHere, viaHere, out, expected);
  33. Assert_true(expected == out);
  34. }
  35. static void routesThrough()
  36. {
  37. uint64_t dst = Constant_base2(0000000000000000100100000000101011101010100101011100101001010101);
  38. uint64_t mid = Constant_base2(0000000000000000000000010110010100100110001110011100011001010101);
  39. Assert_true(!LabelSplicer_routesThrough(dst, mid));
  40. Assert_true(LabelSplicer_routesThrough(dst, 1));
  41. }
  42. int main()
  43. {
  44. splice();
  45. routesThrough();
  46. unsplice();
  47. return 0;
  48. }