test_crc8.c 763 B

1234567891011121314151617181920212223242526272829
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright 2023, Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
  4. *
  5. * Unit test for crc8
  6. */
  7. #include <test/lib.h>
  8. #include <test/ut.h>
  9. #include <u-boot/crc.h>
  10. static int lib_crc8(struct unit_test_state *uts) {
  11. const char str[] = {0x20, 0xf4, 0xd8, 0x24, 0x6f, 0x41, 0x91, 0xae,
  12. 0x46, 0x61, 0xf6, 0x55, 0xeb, 0x38, 0x47, 0x0f,
  13. 0xec, 0xd8};
  14. int actual1, actual2, actual3;
  15. int expected1 = 0x47, expected2 = 0xea, expected3 = expected1;
  16. actual1 = crc8(0, str, sizeof(str));
  17. ut_asserteq(expected1, actual1);
  18. actual2 = crc8(0, str, 7);
  19. ut_asserteq(expected2, actual2);
  20. actual3 = crc8(actual2, str + 7, sizeof(str) - 7);
  21. ut_asserteq(expected3, actual3);
  22. return 0;
  23. }
  24. LIB_TEST(lib_crc8, 0);