helpers.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (c) International Business Machines Corp., 2006
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  12. * the GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. *
  18. * Author: Artem B. Bityutskiy
  19. *
  20. * The stuff which is common for many tests.
  21. */
  22. #ifndef __HELPERS_H__
  23. #define __HELPERS_H__
  24. #include <string.h>
  25. #include <stdio.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #define UBI_VOLUME_PATTERN "/dev/ubi%d_%d"
  30. #define MIN_AVAIL_EBS 5
  31. #define MAX_NAND_PAGE_SIZE 65536
  32. #define errorm(fmt, ...) ({ \
  33. __errorm(PROGRAM_NAME, __FUNCTION__, __LINE__, fmt, ##__VA_ARGS__); \
  34. -1; \
  35. })
  36. #define failed(name) ({ \
  37. __failed(PROGRAM_NAME, __FUNCTION__, __LINE__, name); \
  38. -1; \
  39. })
  40. #define initial_check(argc, argv) \
  41. __initial_check(PROGRAM_NAME, argc, argv)
  42. #define check_volume(vol_id, req) \
  43. __check_volume(libubi, &dev_info, PROGRAM_NAME, __FUNCTION__, \
  44. __LINE__, vol_id, req)
  45. #define check_vol_patt(node, byte) \
  46. __check_vol_patt(libubi, PROGRAM_NAME, __FUNCTION__, __LINE__, node, byte)
  47. #define update_vol_patt(node, bytes, byte) \
  48. __update_vol_patt(libubi, PROGRAM_NAME, __FUNCTION__, __LINE__, \
  49. node, bytes, byte)
  50. #define check_failed(ret, error, func, fmt, ...) ({ \
  51. int __ret = 0; \
  52. \
  53. if (!ret) { \
  54. errorm("%s() returned success but should have failed", func); \
  55. errorm(fmt, ##__VA_ARGS__); \
  56. __ret = -1; \
  57. } else if (errno != (error)) { \
  58. errorm("%s failed with error %d (%s), expected %d (%s)", \
  59. func, errno, strerror(errno), error, strerror(error)); \
  60. errorm(fmt, ##__VA_ARGS__); \
  61. __ret = -1; \
  62. } \
  63. __ret; \
  64. })
  65. /* Alignments to test, @s is eraseblock size */
  66. #define ALIGNMENTS(s) \
  67. {3, 5, 27, 666, 512, 1024, 2048, (s)/2-3, (s)/2-2, (s)/2-1, (s)/2+1, \
  68. (s)/2+2, (s)/2+3, (s)/3-3, (s)/3-2, (s)/3-1, (s)/3+1, (s)/3+2, \
  69. (s)/3+3, (s)/4-3, (s)/4-2, (s)/4-1, (s)/4+1, (s)/4+2, (s)/4+3, \
  70. (s)/5-3, (s)/5-2, (s)/5-1, (s)/5+1, (s)/5+2, (s)/5+3, (s)-17, (s)-9, \
  71. (s)-8, (s)-6, (s)-4, (s)-1, (s)};
  72. extern int seed_random_generator(void);
  73. extern void __errorm(const char *test, const char *func, int line,
  74. const char *fmt, ...);
  75. extern void __failed(const char *test, const char *func, int line,
  76. const char *failed);
  77. extern int __initial_check(const char *test, int argc, char * const argv[]);
  78. extern int __check_volume(libubi_t libubi, struct ubi_dev_info *dev_info,
  79. const char *test, const char *func, int line,
  80. int vol_id, const struct ubi_mkvol_request *req);
  81. extern int __check_vol_patt(libubi_t libubi, const char *test, const char *func,
  82. int line, const char *node, uint8_t byte);
  83. extern int __update_vol_patt(libubi_t libubi, const char *test, const char *func,
  84. int line, const char *node, long long bytes,
  85. uint8_t byte);
  86. #ifdef __cplusplus
  87. }
  88. #endif
  89. #endif /* !__HELPERS_H__ */