unity_utils.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. /* Copyright (C) 2017 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _UNITY_UTILS_H_
  13. #define _UNITY_UTILS_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #ifdef __cplusplus
  18. extern "C" {
  19. #endif
  20. /**
  21. * \brief fill memory with pseudo-random bytes
  22. *
  23. * It is a common practice to fill memory with *unique* data. This will
  24. * will with pseudo-random bytes. With the same \p seed, the filled
  25. * pattern will be the same.
  26. *
  27. * \param mem memory to be filled
  28. * \param size memory size
  29. * \param seed initial pseudo-random seed, and will be update
  30. */
  31. void unityFillMem(void *mem, unsigned size, unsigned *seed);
  32. /**
  33. * \brief check memory with pseudo-random bytes
  34. *
  35. * When the memory is filled with same initial pseudo-random seed by
  36. * \p unityFillMem, this check will return true.
  37. *
  38. * \param mem memory to be checked
  39. * \param size memory size
  40. * \param seed initial pseudo-random seed, and will be update
  41. * \return true if the memory matches, false on mismatch
  42. */
  43. bool unityCheckMem(const void *mem, unsigned size, unsigned *seed);
  44. /**
  45. * \brief fill memory with sequential bytes
  46. *
  47. * This will fill memory with unique and sequential bytes. With the same
  48. * \p seq, the filled pattern will be the same.
  49. *
  50. * \param mem memory to be filled
  51. * \param size memory size
  52. * \param seq initial byte value, and will be update
  53. */
  54. void unityFillMemSeq(void *mem, unsigned size, uint8_t *seq);
  55. /**
  56. * \brief check memory with sequential bytes
  57. *
  58. * When the memory is filled with same initial byte value by
  59. * \p unityFillMemSeq, this check will return true.
  60. *
  61. * \param mem memory to be checked
  62. * \param size memory size
  63. * \param seq initial byte value, and will be update
  64. * \return true if the memory matches, false on mismatch
  65. */
  66. bool unityCheckMemSeq(const void *mem, unsigned size, uint8_t *seq);
  67. #ifdef __cplusplus
  68. }
  69. #endif
  70. #endif