LabelSplicer_test.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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 <https://www.gnu.org/licenses/>.
  14. */
  15. #include "switch/LabelSplicer.h"
  16. #include "util/Endian.h"
  17. #include "util/Assert.h"
  18. #include <stdio.h>
  19. #include <inttypes.h>
  20. static void unsplice()
  21. {
  22. Assert_true(0x13 == LabelSplicer_unsplice(0x13, 1));
  23. }
  24. static void splice()
  25. {
  26. uint64_t goHere = 0x04; // 000000100
  27. uint64_t viaHere = 0x04; // 000000100
  28. uint64_t expected = 0x10; // 000010000
  29. uint64_t out = LabelSplicer_splice(goHere, viaHere);
  30. printf("Splicing %" PRIu64 " with %" PRIu64 " yields %" PRIu64 ", expecting %" PRIu64 "\n",
  31. goHere, viaHere, out, expected);
  32. Assert_true(expected == out);
  33. }
  34. static void routesThrough()
  35. {
  36. // 0000000000000000100100000000101011101010100101011100101001010101
  37. uint64_t dst = 0x0000900aea95ca55;
  38. // 0000000000000000000000010110010100100110001110011100011001010101
  39. uint64_t mid = 0x000001652639c655;
  40. Assert_true(!LabelSplicer_routesThrough(dst, mid));
  41. Assert_true(LabelSplicer_routesThrough(dst, 1));
  42. }
  43. int main()
  44. {
  45. splice();
  46. routesThrough();
  47. unsplice();
  48. return 0;
  49. }