0018-harness-Use-run-time-_SC_PAGE_SIZE-instead-of-build-.patch 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. From fca5217d524635bed70532aa68baff065d22d790 Mon Sep 17 00:00:00 2001
  2. From: Guillem Jover <guillem@hadrons.org>
  3. Date: Sat, 20 Jul 2019 21:20:59 +0200
  4. Subject: [PATCH libaio 18/28] harness: Use run-time _SC_PAGE_SIZE instead of
  5. build-time PAGESIZE
  6. The getconf(1) command is inherently not cross-compilation friendly.
  7. In addition PAGESIZE depends on the specific system, even within a
  8. specific arch, so using a hard-coded value is never safe.
  9. Signed-off-by: Guillem Jover <guillem@hadrons.org>
  10. Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
  11. ---
  12. harness/Makefile | 2 +-
  13. harness/cases/18.t | 34 ++++++++++++++++++++++++----------
  14. 2 files changed, 25 insertions(+), 11 deletions(-)
  15. diff --git a/harness/Makefile b/harness/Makefile
  16. index 87b33f6..5cc2b25 100644
  17. --- a/harness/Makefile
  18. +++ b/harness/Makefile
  19. @@ -6,7 +6,7 @@ PROGS:=$(PARTPROGS) $(EXTRAPROGS)
  20. HARNESS_SRCS:=main.c
  21. # io_queue.c
  22. -CFLAGS+=-Wall -Werror -I../src -g -O2 -DPAGE_SIZE=$(shell getconf PAGESIZE)
  23. +CFLAGS+=-Wall -Werror -I../src -g -O2
  24. #-lpthread -lrt
  25. # Change this on the build line to run tests against the installed libraries:
  26. diff --git a/harness/cases/18.t b/harness/cases/18.t
  27. index 5587ceb..daa1d26 100644
  28. --- a/harness/cases/18.t
  29. +++ b/harness/cases/18.t
  30. @@ -40,11 +40,17 @@
  31. #define THREADS_NUM 100
  32. +static size_t page_size;
  33. +
  34. void
  35. aio_worker(void *ptr)
  36. {
  37. - int i, j, fd;
  38. - char buffer[PAGE_SIZE] __attribute__((aligned(PAGE_SIZE)));
  39. + int i, j, fd, ret;
  40. + char *buffer = NULL;
  41. +
  42. + ret = posix_memalign((void **)&buffer, page_size, page_size);
  43. + assert(ret == 0);
  44. + assert(buffer != NULL);
  45. fd = open(FILENAME, O_DIRECT|O_RDONLY);
  46. assert(fd >= 0);
  47. @@ -55,19 +61,19 @@ aio_worker(void *ptr)
  48. struct iocb *cbs[1];
  49. assert(!io_queue_init(1, &ctx));
  50. - io_prep_pread(&cb, fd, buffer, PAGE_SIZE, 0);
  51. + io_prep_pread(&cb, fd, buffer, page_size, 0);
  52. cbs[0] = &cb;
  53. - memset(buffer, '0', PAGE_SIZE);
  54. + memset(buffer, '0', page_size);
  55. assert(io_submit(ctx, 1, &cbs[0]) == 1);
  56. // wait random time (0-500ms) ?
  57. io_destroy(ctx);
  58. - memset(buffer, DESTROY_PATTERN, PAGE_SIZE);
  59. + memset(buffer, DESTROY_PATTERN, page_size);
  60. // wait random for (0-500ms) ?
  61. // check it is still DESTROY_PATTERN
  62. - for (j = 0; j < PAGE_SIZE; j++) {
  63. + for (j = 0; j < page_size; j++) {
  64. if (buffer[j] != DESTROY_PATTERN) {
  65. fprintf(stderr,
  66. "Buffer has unexpected character: %c\n",
  67. @@ -77,6 +83,7 @@ aio_worker(void *ptr)
  68. }
  69. }
  70. + free(buffer);
  71. close(fd);
  72. }
  73. @@ -84,15 +91,22 @@ int
  74. test_main(void)
  75. {
  76. int i, fd, ret;
  77. - char buffer[PAGE_SIZE];
  78. + char *buffer = NULL;
  79. pthread_t threads[THREADS_NUM];
  80. + page_size = sysconf(_SC_PAGESIZE);
  81. + assert(page_size >= 1);
  82. +
  83. + ret = posix_memalign((void **)&buffer, page_size, page_size);
  84. + assert(ret == 0);
  85. + assert(buffer != NULL);
  86. +
  87. fd = open(FILENAME, O_CREAT|O_TRUNC|O_APPEND|O_RDWR, S_IRUSR|S_IWUSR);
  88. assert(fd != -1);
  89. - memset(buffer, FILEPATTERN, PAGE_SIZE);
  90. - ret = write(fd, buffer, PAGE_SIZE);
  91. - assert(ret == PAGE_SIZE);
  92. + memset(buffer, FILEPATTERN, page_size);
  93. + ret = write(fd, buffer, page_size);
  94. + assert(ret == page_size);
  95. close(fd);
  96. for (i = 0; i < THREADS_NUM; i++) {
  97. --
  98. 2.26.0.292.g33ef6b2f38