test-blob-buflen.c 696 B

12345678910111213141516171819202122232425262728293031
  1. #include <stdio.h>
  2. #include "blobmsg.h"
  3. /* chunks of 64KB to be added to blob-buffer */
  4. #define BUFF_SIZE 0x10000
  5. /* exceed maximum blob buff-length */
  6. #define BUFF_CHUNKS (((BLOB_ATTR_LEN_MASK + 1) / BUFF_SIZE) + 1)
  7. int main(int argc, char **argv)
  8. {
  9. int i;
  10. static struct blob_buf buf;
  11. blobmsg_buf_init(&buf);
  12. int prev_len = buf.buflen;
  13. for (i = 0; i < BUFF_CHUNKS; i++) {
  14. struct blob_attr *attr = blob_new(&buf, 0, BUFF_SIZE);
  15. if (!attr) {
  16. fprintf(stderr, "SUCCESS: failed to allocate attribute\n");
  17. break;
  18. }
  19. if (prev_len < buf.buflen) {
  20. prev_len = buf.buflen;
  21. continue;
  22. }
  23. fprintf(stderr, "ERROR: buffer length did not increase\n");
  24. return -1;
  25. }
  26. return 0;
  27. }