test.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* -*- linux-c -*- ------------------------------------------------------- *
  2. *
  3. * Copyright 2002 H. Peter Anvin - All Rights Reserved
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
  8. * Bostom MA 02111-1307, USA; either version 2 of the License, or
  9. * (at your option) any later version; incorporated herein by reference.
  10. *
  11. * ----------------------------------------------------------------------- */
  12. /*
  13. * raid6test.c
  14. *
  15. * Test RAID-6 recovery with various algorithms
  16. */
  17. #include <stdlib.h>
  18. #include <stdio.h>
  19. #include <string.h>
  20. #include "raid6.h"
  21. #define NDISKS 16 /* Including P and Q */
  22. const char raid6_empty_zero_page[PAGE_SIZE] __attribute__((aligned(256)));
  23. struct raid6_calls raid6_call;
  24. char *dataptrs[NDISKS];
  25. char data[NDISKS][PAGE_SIZE];
  26. char recovi[PAGE_SIZE], recovj[PAGE_SIZE];
  27. void makedata(void)
  28. {
  29. int i, j;
  30. for ( i = 0 ; i < NDISKS ; i++ ) {
  31. for ( j = 0 ; j < PAGE_SIZE ; j++ ) {
  32. data[i][j] = rand();
  33. }
  34. dataptrs[i] = data[i];
  35. }
  36. }
  37. int main(int argc, char *argv[])
  38. {
  39. const struct raid6_calls * const * algo;
  40. int i, j;
  41. int erra, errb;
  42. makedata();
  43. for ( algo = raid6_algos ; *algo ; algo++ ) {
  44. if ( !(*algo)->valid || (*algo)->valid() ) {
  45. raid6_call = **algo;
  46. /* Nuke syndromes */
  47. memset(data[NDISKS-2], 0xee, 2*PAGE_SIZE);
  48. /* Generate assumed good syndrome */
  49. raid6_call.gen_syndrome(NDISKS, PAGE_SIZE, (void **)&dataptrs);
  50. for ( i = 0 ; i < NDISKS-1 ; i++ ) {
  51. for ( j = i+1 ; j < NDISKS ; j++ ) {
  52. memset(recovi, 0xf0, PAGE_SIZE);
  53. memset(recovj, 0xba, PAGE_SIZE);
  54. dataptrs[i] = recovi;
  55. dataptrs[j] = recovj;
  56. raid6_dual_recov(NDISKS, PAGE_SIZE, i, j, (void **)&dataptrs);
  57. erra = memcmp(data[i], recovi, PAGE_SIZE);
  58. errb = memcmp(data[j], recovj, PAGE_SIZE);
  59. if ( i < NDISKS-2 && j == NDISKS-1 ) {
  60. /* We don't implement the DQ failure scenario, since it's
  61. equivalent to a RAID-5 failure (XOR, then recompute Q) */
  62. } else {
  63. printf("algo=%-8s faila=%3d(%c) failb=%3d(%c) %s\n",
  64. raid6_call.name,
  65. i, (i==NDISKS-2)?'P':'D',
  66. j, (j==NDISKS-1)?'Q':(j==NDISKS-2)?'P':'D',
  67. (!erra && !errb) ? "OK" :
  68. !erra ? "ERRB" :
  69. !errb ? "ERRA" :
  70. "ERRAB");
  71. }
  72. dataptrs[i] = data[i];
  73. dataptrs[j] = data[j];
  74. }
  75. }
  76. }
  77. printf("\n");
  78. }
  79. printf("\n");
  80. /* Pick the best algorithm test */
  81. raid6_select_algo();
  82. return 0;
  83. }