LCOV - code coverage report
Current view: top level - libflash/test - test-ecc.c (source / functions) Hit Total Coverage
Test: skiboot.info Lines: 45 88 51.1 %
Date: 2024-09-10 18:37:41 Functions: 1 1 100.0 %
Branches: 0 0 -

           Branch data     Line data    Source code
       1                 :            : // SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
       2                 :            : /* Copyright 2013-2018 IBM Corp. */
       3                 :            : 
       4                 :            : #include <stdio.h>
       5                 :            : #include <stdlib.h>
       6                 :            : #include <stdint.h>
       7                 :            : #include <string.h>
       8                 :            : 
       9                 :            : #include <libflash/ecc.h>
      10                 :            : 
      11                 :            : #include "../ecc.c"
      12                 :            : 
      13                 :            : #define __unused                __attribute__((unused))
      14                 :            : 
      15                 :            : #define ERR(fmt...) fprintf(stderr, fmt)
      16                 :            : 
      17                 :            : #define NUM_ECC_ROWS 320
      18                 :            : 
      19                 :            : /*
      20                 :            :  * Note this data is big endian as this is what the ecc code expects.
      21                 :            :  * The ECC code returns IBM bit numbers assuming the word was in CPU
      22                 :            :  * endian!
      23                 :            :  */
      24                 :            : 
      25                 :            : /* 8 data bytes 1 ecc byte per row */
      26                 :            : struct ecc64 ecc_data[] = {
      27                 :            :         { 0xfeffffffffffffff, 0x00 }, /* This row will have ecc correct bit 63 */
      28                 :            :         { 0xfdffffffffffffff, 0x00 }, /* This row will have ecc correct bit 62 */
      29                 :            :         { 0xfbffffffffffffff, 0x00 }, /* This row will have ecc correct bit 61 */
      30                 :            :         { 0xf7ffffffffffffff, 0x00 }, /* This row will have ecc correct bit 60 */
      31                 :            :         { 0xefffffffffffffff, 0x00 }, /* This row will have ecc correct bit 59 */
      32                 :            :         { 0xdfffffffffffffff, 0x00 }, /* This row will have ecc correct bit 58 */
      33                 :            :         { 0xbfffffffffffffff, 0x00 }, /* This row will have ecc correct bit 57 */
      34                 :            :         { 0x7fffffffffffffff, 0x00 }, /* This row will have ecc correct bit 56 */
      35                 :            :         { 0xfffeffffffffffff, 0x00 }, /* This row will have ecc correct bit 55 */
      36                 :            :         { 0xfffdffffffffffff, 0x00 }, /* This row will have ecc correct bit 54 */
      37                 :            :         { 0xfffbffffffffffff, 0x00 }, /* This row will have ecc correct bit 53 */
      38                 :            :         { 0xfff7ffffffffffff, 0x00 }, /* This row will have ecc correct bit 52 */
      39                 :            :         { 0xffefffffffffffff, 0x00 }, /* This row will have ecc correct bit 51 */
      40                 :            :         { 0xffdfffffffffffff, 0x00 }, /* This row will have ecc correct bit 50 */
      41                 :            :         { 0xffbfffffffffffff, 0x00 }, /* This row will have ecc correct bit 49 */
      42                 :            :         { 0xff7fffffffffffff, 0x00 }, /* This row will have ecc correct bit 48 */
      43                 :            :         { 0xfffffeffffffffff, 0x00 }, /* This row will have ecc correct bit 47 */
      44                 :            :         { 0xfffffdffffffffff, 0x00 }, /* This row will have ecc correct bit 46 */
      45                 :            :         { 0xfffffbffffffffff, 0x00 }, /* This row will have ecc correct bit 45 */
      46                 :            :         { 0xfffff7ffffffffff, 0x00 }, /* This row will have ecc correct bit 44 */
      47                 :            :         { 0xffffefffffffffff, 0x00 }, /* This row will have ecc correct bit 43 */
      48                 :            :         { 0xffffdfffffffffff, 0x00 }, /* This row will have ecc correct bit 42 */
      49                 :            :         { 0xffffbfffffffffff, 0x00 }, /* This row will have ecc correct bit 41 */
      50                 :            :         { 0xffff7fffffffffff, 0x00 }, /* This row will have ecc correct bit 40 */
      51                 :            :         { 0xfffffffeffffffff, 0x00 }, /* This row will have ecc correct bit 39 */
      52                 :            :         { 0xfffffffdffffffff, 0x00 }, /* This row will have ecc correct bit 38 */
      53                 :            :         { 0xfffffffbffffffff, 0x00 }, /* This row will have ecc correct bit 37 */
      54                 :            :         { 0xfffffff7ffffffff, 0x00 }, /* This row will have ecc correct bit 36 */
      55                 :            :         { 0xffffffefffffffff, 0x00 }, /* This row will have ecc correct bit 35 */
      56                 :            :         { 0xffffffdfffffffff, 0x00 }, /* This row will have ecc correct bit 34 */
      57                 :            :         { 0xffffffbfffffffff, 0x00 }, /* This row will have ecc correct bit 33 */
      58                 :            :         { 0xffffff7fffffffff, 0x00 }, /* This row will have ecc correct bit 32 */
      59                 :            :         { 0xfffffffffeffffff, 0x00 }, /* This row will have ecc correct bit 31 */
      60                 :            :         { 0xfffffffffdffffff, 0x00 }, /* This row will have ecc correct bit 30 */
      61                 :            :         { 0xfffffffffbffffff, 0x00 }, /* This row will have ecc correct bit 29 */
      62                 :            :         { 0xfffffffff7ffffff, 0x00 }, /* This row will have ecc correct bit 28 */
      63                 :            :         { 0xffffffffefffffff, 0x00 }, /* This row will have ecc correct bit 27 */
      64                 :            :         { 0xffffffffdfffffff, 0x00 }, /* This row will have ecc correct bit 26 */
      65                 :            :         { 0xffffffffbfffffff, 0x00 }, /* This row will have ecc correct bit 25 */
      66                 :            :         { 0xffffffff7fffffff, 0x00 }, /* This row will have ecc correct bit 24 */
      67                 :            :         { 0xfffffffffffeffff, 0x00 }, /* This row will have ecc correct bit 23 */
      68                 :            :         { 0xfffffffffffdffff, 0x00 }, /* This row will have ecc correct bit 22 */
      69                 :            :         { 0xfffffffffffbffff, 0x00 }, /* This row will have ecc correct bit 21 */
      70                 :            :         { 0xfffffffffff7ffff, 0x00 }, /* This row will have ecc correct bit 20 */
      71                 :            :         { 0xffffffffffefffff, 0x00 }, /* This row will have ecc correct bit 19 */
      72                 :            :         { 0xffffffffffdfffff, 0x00 }, /* This row will have ecc correct bit 18 */
      73                 :            :         { 0xffffffffffbfffff, 0x00 }, /* This row will have ecc correct bit 17 */
      74                 :            :         { 0xffffffffff7fffff, 0x00 }, /* This row will have ecc correct bit 16 */
      75                 :            :         { 0xfffffffffffffeff, 0x00 }, /* This row will have ecc correct bit 15 */
      76                 :            :         { 0xfffffffffffffdff, 0x00 }, /* This row will have ecc correct bit 14 */
      77                 :            :         { 0xfffffffffffffbff, 0x00 }, /* This row will have ecc correct bit 13 */
      78                 :            :         { 0xfffffffffffff7ff, 0x00 }, /* This row will have ecc correct bit 12 */
      79                 :            :         { 0xffffffffffffefff, 0x00 }, /* This row will have ecc correct bit 11 */
      80                 :            :         { 0xffffffffffffdfff, 0x00 }, /* This row will have ecc correct bit 10 */
      81                 :            :         { 0xffffffffffffbfff, 0x00 }, /* This row will have ecc correct bit 9 */
      82                 :            :         { 0xffffffffffff7fff, 0x00 }, /* This row will have ecc correct bit 8 */
      83                 :            :         { 0xfffffffffffffffe, 0x00 }, /* This row will have ecc correct bit 7 */
      84                 :            :         { 0xfffffffffffffffd, 0x00 }, /* This row will have ecc correct bit 6 */
      85                 :            :         { 0xfffffffffffffffb, 0x00 }, /* This row will have ecc correct bit 5 */
      86                 :            :         { 0xfffffffffffffff7, 0x00 }, /* This row will have ecc correct bit 4 */
      87                 :            :         { 0xffffffffffffffef, 0x00 }, /* This row will have ecc correct bit 3 */
      88                 :            :         { 0xffffffffffffffdf, 0x00 }, /* This row will have ecc correct bit 2 */
      89                 :            :         { 0xffffffffffffffbf, 0x00 }, /* This row will have ecc correct bit 1 */
      90                 :            :         { 0xffffffffffffff7f, 0x00 }, /* This row will have ecc correct bit 0 */
      91                 :            :         /*
      92                 :            :          * 'Randomised' input into eccgenerate 0x54f7c5d1 was seeded to rand()
      93                 :            :          * Note: eccgenerate from skiboot commit 6cfaa3ba1015c6ac9cc4a06f878b4289022cff54
      94                 :            :          * was used to generate these ecc numbers
      95                 :            :          */
      96                 :            :         { 0x29d87c7c8ab7d46d, 0xb9 }, /* Use this row to check eccgenerate() */
      97                 :            :         { 0x9064174098381641, 0x3b }, /* Use this row to check eccgenerate() */
      98                 :            :         { 0x77fd7d2fc7d22154, 0xe4 }, /* Use this row to check eccgenerate() */
      99                 :            :         { 0x6b02ba39b64a6168, 0xbf }, /* Use this row to check eccgenerate() */
     100                 :            :         { 0x68fa9c633eef0544, 0x2a }, /* Use this row to check eccgenerate() */
     101                 :            :         { 0xe814b258b3f92e55, 0x35 }, /* Use this row to check eccgenerate() */
     102                 :            :         { 0xc3e2bd658db4db6d, 0xda }, /* Use this row to check eccgenerate() */
     103                 :            :         { 0xe1dd487b6209876a, 0x45 }, /* Use this row to check eccgenerate() */
     104                 :            :         { 0x309f9e6b91831433, 0xe4 }, /* Use this row to check eccgenerate() */
     105                 :            :         { 0xd8b77d39f4d66410, 0x6c }, /* Use this row to check eccgenerate() */
     106                 :            :         { 0x83ba293cf30a9e6a, 0xc9 }, /* Use this row to check eccgenerate() */
     107                 :            :         { 0x3aeaef79af97ec1a, 0x09 }, /* Use this row to check eccgenerate() */
     108                 :            :         { 0xa90ef431e4778c43, 0x91 }, /* Use this row to check eccgenerate() */
     109                 :            :         { 0xa74bbf1e6b6fda00, 0xc5 }, /* Use this row to check eccgenerate() */
     110                 :            :         { 0x67b5a872efa57c30, 0xb9 }, /* Use this row to check eccgenerate() */
     111                 :            :         { 0x795d511e3605ff67, 0x03 }, /* Use this row to check eccgenerate() */
     112                 :            :         { 0xce3d1529918d256f, 0x36 }, /* Use this row to check eccgenerate() */
     113                 :            :         { 0x586047430ac2685e, 0xab }, /* Use this row to check eccgenerate() */
     114                 :            :         { 0xc00cca46463b9358, 0x42 }, /* Use this row to check eccgenerate() */
     115                 :            :         { 0x842a991cc362017d, 0xb2 }, /* Use this row to check eccgenerate() */
     116                 :            :         { 0x765c30522807672a, 0x26 }, /* Use this row to check eccgenerate() */
     117                 :            :         { 0xb5bb42186c3f4b75, 0x2b }, /* Use this row to check eccgenerate() */
     118                 :            :         { 0xce48d25f393fee37, 0x90 }, /* Use this row to check eccgenerate() */
     119                 :            :         { 0xcbc2026b96998b13, 0x40 }, /* Use this row to check eccgenerate() */
     120                 :            :         { 0x8b70f023ffe7704b, 0x23 }, /* Use this row to check eccgenerate() */
     121                 :            :         { 0xf2f20e36a37a8024, 0x19 }, /* Use this row to check eccgenerate() */
     122                 :            :         { 0x52126d3f0e2b1a60, 0xa0 }, /* Use this row to check eccgenerate() */
     123                 :            :         { 0xf2a2a6232dddfe2f, 0xc4 }, /* Use this row to check eccgenerate() */
     124                 :            :         { 0x984cd930fb206171, 0xa5 }, /* Use this row to check eccgenerate() */
     125                 :            :         { 0xeac6dd2199ee6542, 0xea }, /* Use this row to check eccgenerate() */
     126                 :            :         { 0xd0f3642aff018223, 0x3b }, /* Use this row to check eccgenerate() */
     127                 :            :         { 0x908fa71263242f40, 0x0a }, /* Use this row to check eccgenerate() */
     128                 :            :         { 0x6de6971e9e317a53, 0xa6 }, /* Use this row to check eccgenerate() */
     129                 :            :         { 0xe46c0d2ce8efee55, 0xa4 }, /* Use this row to check eccgenerate() */
     130                 :            :         { 0xab52f0522df36165, 0x06 }, /* Use this row to check eccgenerate() */
     131                 :            :         { 0x55fac80f6997a648, 0x9a }, /* Use this row to check eccgenerate() */
     132                 :            :         { 0xd5d6f13d21af2025, 0xed }, /* Use this row to check eccgenerate() */
     133                 :            :         { 0x5bee0e5d0bb60b28, 0x66 }, /* Use this row to check eccgenerate() */
     134                 :            :         { 0xa14f973ba41fc41d, 0xa8 }, /* Use this row to check eccgenerate() */
     135                 :            :         { 0xa307356926b11148, 0x5a }, /* Use this row to check eccgenerate() */
     136                 :            :         { 0xc92b926c2cc0875f, 0x7e }, /* Use this row to check eccgenerate() */
     137                 :            :         { 0x3aeba13f95fa431f, 0x92 }, /* Use this row to check eccgenerate() */
     138                 :            :         { 0xc2d7424f1b3eff2b, 0xe6 }, /* Use this row to check eccgenerate() */
     139                 :            :         { 0x165f601d2c8e4863, 0x2b }, /* Use this row to check eccgenerate() */
     140                 :            :         { 0xc67cae255a241c00, 0x78 }, /* Use this row to check eccgenerate() */
     141                 :            :         { 0x5a269e2300263e3f, 0x07 }, /* Use this row to check eccgenerate() */
     142                 :            :         { 0x634a6d7f96701350, 0xe9 }, /* Use this row to check eccgenerate() */
     143                 :            :         { 0x34a28d23eab54536, 0xd2 }, /* Use this row to check eccgenerate() */
     144                 :            :         { 0xd3a5340cd130051e, 0x48 }, /* Use this row to check eccgenerate() */
     145                 :            :         { 0xfe236703190f9b4f, 0x7e }, /* Use this row to check eccgenerate() */
     146                 :            :         { 0x82a641187ef8245f, 0x20 }, /* Use this row to check eccgenerate() */
     147                 :            :         { 0xa0a74504541e3013, 0xc7 }, /* Use this row to check eccgenerate() */
     148                 :            :         { 0x5fd43b3b577d3356, 0x85 }, /* Use this row to check eccgenerate() */
     149                 :            :         { 0xfb9cf773fb955461, 0x06 }, /* Use this row to check eccgenerate() */
     150                 :            :         { 0x214766290024d376, 0x80 }, /* Use this row to check eccgenerate() */
     151                 :            :         { 0x2de45a569ea42c5d, 0x22 }, /* Use this row to check eccgenerate() */
     152                 :            :         { 0x349f707cea72f815, 0xf3 }, /* Use this row to check eccgenerate() */
     153                 :            :         { 0x05b1f74167cffc15, 0xe9 }, /* Use this row to check eccgenerate() */
     154                 :            :         { 0x945d4579f676b34b, 0x63 }, /* Use this row to check eccgenerate() */
     155                 :            :         { 0x519bcf4b1b10585f, 0x47 }, /* Use this row to check eccgenerate() */
     156                 :            :         { 0x1b36961e5adaf31e, 0x25 }, /* Use this row to check eccgenerate() */
     157                 :            :         { 0xf04a076fabc16d6f, 0x20 }, /* Use this row to check eccgenerate() */
     158                 :            :         { 0x9577b3257e80031e, 0xef }, /* Use this row to check eccgenerate() */
     159                 :            :         { 0x4fb1083c24ed9412, 0x97 }, /* Use this row to check eccgenerate() */
     160                 :            :         { 0x3dfc2f62681de831, 0x1f }, /* Use this row to check eccgenerate() */
     161                 :            :         { 0xe7150d114ed56f3f, 0x10 }, /* Use this row to check eccgenerate() */
     162                 :            :         { 0xa2f39f52bfa2717a, 0x40 }, /* Use this row to check eccgenerate() */
     163                 :            :         { 0x1720a55087bd5215, 0xb3 }, /* Use this row to check eccgenerate() */
     164                 :            :         { 0x8253a77601c8db0d, 0x45 }, /* Use this row to check eccgenerate() */
     165                 :            :         { 0x01ecae0412bd9c44, 0x5f }, /* Use this row to check eccgenerate() */
     166                 :            :         { 0xb161c921a39a0d20, 0x51 }, /* Use this row to check eccgenerate() */
     167                 :            :         { 0x8d0d06362ed0095b, 0x94 }, /* Use this row to check eccgenerate() */
     168                 :            :         { 0x969f0671e5003a1e, 0x9b }, /* Use this row to check eccgenerate() */
     169                 :            :         { 0xdb77ed6992befd77, 0x63 }, /* Use this row to check eccgenerate() */
     170                 :            :         { 0xadce55572afd4b6a, 0x3e }, /* Use this row to check eccgenerate() */
     171                 :            :         { 0x84d73f092c13bd35, 0x50 }, /* Use this row to check eccgenerate() */
     172                 :            :         { 0xd7d42a25c804ec75, 0x05 }, /* Use this row to check eccgenerate() */
     173                 :            :         { 0x4685ef1374224778, 0x72 }, /* Use this row to check eccgenerate() */
     174                 :            :         { 0x980fdc0a6d4cde4a, 0x9d }, /* Use this row to check eccgenerate() */
     175                 :            :         { 0xd569c67c9636f84f, 0x81 }, /* Use this row to check eccgenerate() */
     176                 :            :         { 0xe40b680fd60b0c6d, 0x2c }, /* Use this row to check eccgenerate() */
     177                 :            :         { 0x95ae7d67bc7fd30d, 0x72 }, /* Use this row to check eccgenerate() */
     178                 :            :         { 0x433d262386ff0762, 0xf4 }, /* Use this row to check eccgenerate() */
     179                 :            :         { 0x87c7e36facce2238, 0x5a }, /* Use this row to check eccgenerate() */
     180                 :            :         { 0xbf8bbf7cc590cd19, 0xe0 }, /* Use this row to check eccgenerate() */
     181                 :            :         { 0x682bdb3988b39274, 0x4f }, /* Use this row to check eccgenerate() */
     182                 :            :         { 0xb7839c4f70ed881e, 0x6b }, /* Use this row to check eccgenerate() */
     183                 :            :         { 0x55eec23cf538e16f, 0x72 }, /* Use this row to check eccgenerate() */
     184                 :            :         { 0x87f7de674d23a340, 0xb4 }, /* Use this row to check eccgenerate() */
     185                 :            :         { 0x7720ef2a3066b026, 0x7c }, /* Use this row to check eccgenerate() */
     186                 :            :         { 0x5d796d5c34c6343f, 0x5e }, /* Use this row to check eccgenerate() */
     187                 :            :         { 0xfcca2035fbf72e34, 0xc6 }, /* Use this row to check eccgenerate() */
     188                 :            :         { 0x6f1a762c344e9801, 0x87 }, /* Use this row to check eccgenerate() */
     189                 :            :         { 0xa19a764c43501049, 0x35 }, /* Use this row to check eccgenerate() */
     190                 :            :         { 0xd9860819072a5237, 0x6a }, /* Use this row to check eccgenerate() */
     191                 :            :         { 0xdd355e2477043d49, 0x2d }, /* Use this row to check eccgenerate() */
     192                 :            :         { 0x33841057bd927028, 0xaa }, /* Use this row to check eccgenerate() */
     193                 :            :         { 0x4392780a73e4db0b, 0xfa }, /* Use this row to check eccgenerate() */
     194                 :            :         { 0x1fb3fe4377c1367a, 0x47 }, /* Use this row to check eccgenerate() */
     195                 :            :         { 0x3c520414ca595c7a, 0x58 }, /* Use this row to check eccgenerate() */
     196                 :            :         { 0x520def6ede3ebe40, 0xac }, /* Use this row to check eccgenerate() */
     197                 :            :         { 0x4e2c475fa57ddf4d, 0x5c }, /* Use this row to check eccgenerate() */
     198                 :            :         { 0x9ab6c03d09918b3e, 0x95 }, /* Use this row to check eccgenerate() */
     199                 :            :         { 0x56b42e7fa31a0a1c, 0x5d }, /* Use this row to check eccgenerate() */
     200                 :            :         { 0xd480ba4222ae9f25, 0x87 }, /* Use this row to check eccgenerate() */
     201                 :            :         { 0x5674d464cdd41d2a, 0xc7 }, /* Use this row to check eccgenerate() */
     202                 :            :         { 0xc8cc4c5e31fa271f, 0x6e }, /* Use this row to check eccgenerate() */
     203                 :            :         { 0x6548c020533ff519, 0x00 }, /* Use this row to check eccgenerate() */
     204                 :            :         { 0x968f056337e7c20a, 0x0e }, /* Use this row to check eccgenerate() */
     205                 :            :         { 0x3f11154207e3366d, 0xbe }, /* Use this row to check eccgenerate() */
     206                 :            :         { 0x7ee773366f160e7c, 0x53 }, /* Use this row to check eccgenerate() */
     207                 :            :         { 0x2ca97e241c477366, 0x1c }, /* Use this row to check eccgenerate() */
     208                 :            :         { 0x8f2b4f72b16b840d, 0x88 }, /* Use this row to check eccgenerate() */
     209                 :            :         { 0x282dbb076f3bf72e, 0xd0 }, /* Use this row to check eccgenerate() */
     210                 :            :         { 0x39955329afde4d36, 0xc7 }, /* Use this row to check eccgenerate() */
     211                 :            :         { 0x8d1d0c77657fbf1b, 0x22 }, /* Use this row to check eccgenerate() */
     212                 :            :         { 0x0afd9e698ba24218, 0x1a }, /* Use this row to check eccgenerate() */
     213                 :            :         { 0x9533ce56dc495356, 0x2a }, /* Use this row to check eccgenerate() */
     214                 :            :         { 0x7f645d72a4b35f27, 0x80 }, /* Use this row to check eccgenerate() */
     215                 :            :         { 0xc661ff4cebe7fc55, 0xe2 }, /* Use this row to check eccgenerate() */
     216                 :            :         { 0xb9bc1a0053e51735, 0xff }, /* Use this row to check eccgenerate() */
     217                 :            :         { 0x84df3f541dd6d331, 0x54 }, /* Use this row to check eccgenerate() */
     218                 :            :         { 0x7015c94b8189675e, 0x02 }, /* Use this row to check eccgenerate() */
     219                 :            :         { 0xb9702a69ea270075, 0x1f }, /* Use this row to check eccgenerate() */
     220                 :            :         { 0xf10a376206a5ce2e, 0x6f }, /* Use this row to check eccgenerate() */
     221                 :            :         { 0x75bbdc2af8813f2b, 0xb1 }, /* Use this row to check eccgenerate() */
     222                 :            :         { 0x14c9b2116ff2aa18, 0x7a }, /* Use this row to check eccgenerate() */
     223                 :            :         { 0x205e2f26a1645b4f, 0x2b }, /* Use this row to check eccgenerate() */
     224                 :            :         { 0x10a0527ea4f40104, 0xf6 }, /* Use this row to check eccgenerate() */
     225                 :            :         { 0x53d34f3a498bea2d, 0x93 }, /* Use this row to check eccgenerate() */
     226                 :            :         { 0xae0aaa494935a627, 0xbf }, /* Use this row to check eccgenerate() */
     227                 :            :         { 0xd4d7e83fe0f05b31, 0x58 }, /* Use this row to check eccgenerate() */
     228                 :            :         { 0xbc3aaf07b8074933, 0x74 }, /* Use this row to check eccgenerate() */
     229                 :            :         { 0x5cbba85a690bb716, 0xbf }, /* Use this row to check eccgenerate() */
     230                 :            :         { 0x55f3b36c3c9f0c7a, 0x3a }, /* Use this row to check eccgenerate() */
     231                 :            :         { 0x8f84242f231da827, 0x50 }, /* Use this row to check eccgenerate() */
     232                 :            :         { 0x40f37b590eb0ce6c, 0x9c }, /* Use this row to check eccgenerate() */
     233                 :            :         { 0x8f39364b14646403, 0x0b }, /* Use this row to check eccgenerate() */
     234                 :            :         { 0xfe8b6478b0084525, 0x21 }, /* Use this row to check eccgenerate() */
     235                 :            :         { 0xb6ad135448aa6034, 0x1c }, /* Use this row to check eccgenerate() */
     236                 :            :         { 0x402ca05fef969b5a, 0x90 }, /* Use this row to check eccgenerate() */
     237                 :            :         { 0x5e8946732b69f07e, 0xaa }, /* Use this row to check eccgenerate() */
     238                 :            :         { 0xcccd4b4e55f55271, 0xe8 }, /* Use this row to check eccgenerate() */
     239                 :            :         { 0xf9e954757ee77519, 0xf8 }, /* Use this row to check eccgenerate() */
     240                 :            :         { 0xc7726047dc6d9e4c, 0x67 }, /* Use this row to check eccgenerate() */
     241                 :            :         { 0x25a344744cbda42f, 0x77 }, /* Use this row to check eccgenerate() */
     242                 :            :         { 0x2cae0061757d0a11, 0xca }, /* Use this row to check eccgenerate() */
     243                 :            :         { 0x2d855344f97a2d34, 0x9b }, /* Use this row to check eccgenerate() */
     244                 :            :         { 0x6386e44ae9e8af68, 0x6c }, /* Use this row to check eccgenerate() */
     245                 :            :         { 0x2588bc628a40fc1e, 0x4c }, /* Use this row to check eccgenerate() */
     246                 :            :         { 0xad5da446b8799837, 0x31 }, /* Use this row to check eccgenerate() */
     247                 :            :         { 0xc6296724b40ce111, 0xde }, /* Use this row to check eccgenerate() */
     248                 :            :         { 0xc8704515ed502020, 0x72 }, /* Use this row to check eccgenerate() */
     249                 :            :         { 0x9d59654555639d6f, 0x16 }, /* Use this row to check eccgenerate() */
     250                 :            :         { 0x9e0dfe23c6fca90d, 0x37 }, /* Use this row to check eccgenerate() */
     251                 :            :         { 0xb593456853077919, 0xee }, /* Use this row to check eccgenerate() */
     252                 :            :         { 0x7e706918de399e03, 0xe7 }, /* Use this row to check eccgenerate() */
     253                 :            :         { 0x332ff174131d8c5b, 0x34 }, /* Use this row to check eccgenerate() */
     254                 :            :         { 0x920402754a3eb566, 0x2f }, /* Use this row to check eccgenerate() */
     255                 :            :         { 0x26ac53332c19466a, 0x0c }, /* Use this row to check eccgenerate() */
     256                 :            :         { 0x78d6ea195977623c, 0x6f }, /* Use this row to check eccgenerate() */
     257                 :            :         { 0xcff46c4d4b4f9827, 0x20 }, /* Use this row to check eccgenerate() */
     258                 :            :         { 0x44cac55ba584eb7a, 0x5f }, /* Use this row to check eccgenerate() */
     259                 :            :         { 0x8e6d9b63fc79c011, 0xc8 }, /* Use this row to check eccgenerate() */
     260                 :            :         { 0x86babc30a750aa26, 0x20 }, /* Use this row to check eccgenerate() */
     261                 :            :         { 0x5fca425eb3f55746, 0x12 }, /* Use this row to check eccgenerate() */
     262                 :            :         { 0x6702395833186177, 0xaf }, /* Use this row to check eccgenerate() */
     263                 :            :         { 0x2069811725f4a902, 0x87 }, /* Use this row to check eccgenerate() */
     264                 :            :         { 0x7b57477230737e6d, 0xd9 }, /* Use this row to check eccgenerate() */
     265                 :            :         { 0xf66f287bbdc2e65c, 0xfa }, /* Use this row to check eccgenerate() */
     266                 :            :         { 0x10ca5f7619654516, 0x52 }, /* Use this row to check eccgenerate() */
     267                 :            :         { 0xf79ee319ac036e63, 0x58 }, /* Use this row to check eccgenerate() */
     268                 :            :         { 0xbf20fa3e8e3ac90e, 0x82 }, /* Use this row to check eccgenerate() */
     269                 :            :         { 0xd8787e752bced40e, 0x54 }, /* Use this row to check eccgenerate() */
     270                 :            :         { 0x57e71a795125fc33, 0xfe }, /* Use this row to check eccgenerate() */
     271                 :            :         { 0xab9c5e70fe24d228, 0xfc }, /* Use this row to check eccgenerate() */
     272                 :            :         { 0x49746a50d0bd0513, 0x9d }, /* Use this row to check eccgenerate() */
     273                 :            :         { 0x7542f10d7a91cb3d, 0xb9 }, /* Use this row to check eccgenerate() */
     274                 :            :         { 0x760b8c4f8e3e302c, 0x82 }, /* Use this row to check eccgenerate() */
     275                 :            :         { 0x358fda5203b08c71, 0x23 }, /* Use this row to check eccgenerate() */
     276                 :            :         { 0xb6a5e437fdc54800, 0xb6 }, /* Use this row to check eccgenerate() */
     277                 :            :         { 0x30dea97795591d31, 0x7c }, /* Use this row to check eccgenerate() */
     278                 :            :         { 0xba4dc7331da81d10, 0x11 }, /* Use this row to check eccgenerate() */
     279                 :            :         { 0x4d1b9c7d51472b0f, 0x37 }, /* Use this row to check eccgenerate() */
     280                 :            :         { 0x0e0a126c35a50e26, 0xd6 }, /* Use this row to check eccgenerate() */
     281                 :            :         { 0x4e0a543c448bc478, 0x0f }, /* Use this row to check eccgenerate() */
     282                 :            :         { 0xf08e325c1fd47162, 0x6b }, /* Use this row to check eccgenerate() */
     283                 :            :         { 0xad0e3b7146a93756, 0x86 }, /* Use this row to check eccgenerate() */
     284                 :            :         { 0x71770c65afaf2c1b, 0xae }, /* Use this row to check eccgenerate() */
     285                 :            :         { 0x01d5284f8687b966, 0x37 }, /* Use this row to check eccgenerate() */
     286                 :            :         { 0x84ac8b0fc85e275e, 0x86 }, /* Use this row to check eccgenerate() */
     287                 :            :         { 0x981c2d71ac71873f, 0x4e }, /* Use this row to check eccgenerate() */
     288                 :            :         { 0x2603537dce20f65f, 0xb5 }, /* Use this row to check eccgenerate() */
     289                 :            :         { 0x5c5f260c0d5f1e7f, 0x0b }, /* Use this row to check eccgenerate() */
     290                 :            :         { 0x100fab709c0edf4c, 0xc9 }, /* Use this row to check eccgenerate() */
     291                 :            :         { 0x99d4274d91ee005f, 0x83 }, /* Use this row to check eccgenerate() */
     292                 :            :         { 0x26481e10c6b48f28, 0x16 }, /* Use this row to check eccgenerate() */
     293                 :            :         { 0xe45cad38cab2d144, 0x9c }, /* Use this row to check eccgenerate() */
     294                 :            :         { 0x1bfafc53e195e543, 0x8e }, /* Use this row to check eccgenerate() */
     295                 :            :         { 0x163bf46931784936, 0xdc }, /* Use this row to check eccgenerate() */
     296                 :            :         { 0x75030e2f29040f40, 0x48 }, /* Use this row to check eccgenerate() */
     297                 :            :         { 0x48d8802265454826, 0x2a }, /* Use this row to check eccgenerate() */
     298                 :            :         { 0xabee7f7c6592400b, 0x2b }, /* Use this row to check eccgenerate() */
     299                 :            :         { 0x15426d26f6e6bb13, 0x89 }, /* Use this row to check eccgenerate() */
     300                 :            :         { 0x7c6e757a1c668c61, 0x6d }, /* Use this row to check eccgenerate() */
     301                 :            :         { 0xe4c4b33f16179675, 0x74 }, /* Use this row to check eccgenerate() */
     302                 :            :         { 0xc2881d35001b010a, 0xd4 }, /* Use this row to check eccgenerate() */
     303                 :            :         { 0xce3bf7697de1e030, 0x65 }, /* Use this row to check eccgenerate() */
     304                 :            :         { 0x8a40ff2fe88b7032, 0x19 }, /* Use this row to check eccgenerate() */
     305                 :            :         { 0x849a4f7f2a9b1d76, 0x58 }, /* Use this row to check eccgenerate() */
     306                 :            :         { 0xbc891e559b4faa20, 0x4c }, /* Use this row to check eccgenerate() */
     307                 :            :         { 0x61043a491e6f774c, 0x28 }, /* Use this row to check eccgenerate() */
     308                 :            :         { 0xe8214911e2d13c65, 0x9e }, /* Use this row to check eccgenerate() */
     309                 :            :         { 0xc36722294561e701, 0x3d }, /* Use this row to check eccgenerate() */
     310                 :            :         { 0x77d93038031c4665, 0x55 }, /* Use this row to check eccgenerate() */
     311                 :            :         { 0x2c205525daa21613, 0x85 }, /* Use this row to check eccgenerate() */
     312                 :            :         { 0x3fe85e39ecdc3e67, 0x20 }, /* Use this row to check eccgenerate() */
     313                 :            :         { 0x526f7f7275f8d547, 0xa4 }, /* Use this row to check eccgenerate() */
     314                 :            :         { 0x6bdf915bead6de35, 0xac }, /* Use this row to check eccgenerate() */
     315                 :            :         { 0x063d6b1767b1ec18, 0x78 }, /* Use this row to check eccgenerate() */
     316                 :            :         { 0x7dc8820ee74d0756, 0x31 }, /* Use this row to check eccgenerate() */
     317                 :            :         { 0xe7680860ea011f57, 0x3f }, /* Use this row to check eccgenerate() */
     318                 :            :         { 0x67e3ff073f51a043, 0xd6 }, /* Use this row to check eccgenerate() */
     319                 :            :         { 0x27dd1076b6a4ff49, 0x10 }, /* Use this row to check eccgenerate() */
     320                 :            :         { 0xe03f1d40f223ff37, 0xec }, /* Use this row to check eccgenerate() */
     321                 :            :         { 0x8d73a958ab776075, 0x6f }, /* Use this row to check eccgenerate() */
     322                 :            :         { 0xc9e6d7419cc93b15, 0x8f }, /* Use this row to check eccgenerate() */
     323                 :            :         { 0x7f9b787aee77e321, 0xb7 }, /* Use this row to check eccgenerate() */
     324                 :            :         { 0x34d9ca23b1082153, 0xa9 }, /* Use this row to check eccgenerate() */
     325                 :            :         { 0xb424673842039b23, 0xe2 }, /* Use this row to check eccgenerate() */
     326                 :            :         { 0x1ca6b136abb2fb5b, 0xe1 }, /* Use this row to check eccgenerate() */
     327                 :            :         { 0x978f3a43e144bc5d, 0x64 }, /* Use this row to check eccgenerate() */
     328                 :            :         { 0x563d92255b8e1070, 0x14 }, /* Use this row to check eccgenerate() */
     329                 :            :         { 0x4565ef25e9feb935, 0x2d }, /* Use this row to check eccgenerate() */
     330                 :            :         { 0x50b0a64ec11c2401, 0x3c }, /* Use this row to check eccgenerate() */
     331                 :            :         { 0xa86a2b574ba25a3d, 0x8b }, /* Use this row to check eccgenerate() */
     332                 :            :         { 0x36a47914cd78295d, 0xf1 }, /* Use this row to check eccgenerate() */
     333                 :            :         { 0x0ccac9208fd33337, 0xe4 }, /* Use this row to check eccgenerate() */
     334                 :            :         { 0x457833019d87791c, 0xc4 }, /* Use this row to check eccgenerate() */
     335                 :            :         { 0x8fab785433a7da16, 0x0c }, /* Use this row to check eccgenerate() */
     336                 :            :         { 0xdf1e3b0c26b85041, 0x94 }, /* Use this row to check eccgenerate() */
     337                 :            :         { 0xc2818c561c1f222d, 0x9a }, /* Use this row to check eccgenerate() */
     338                 :            :         { 0x0b97054fa805134e, 0xec }, /* Use this row to check eccgenerate() */
     339                 :            :         { 0x5a0e3421411d0551, 0x57 }, /* Use this row to check eccgenerate() */
     340                 :            :         { 0x8420a0743f70d072, 0xa8 }, /* Use this row to check eccgenerate() */
     341                 :            :         { 0xea22cc4e0e339b59, 0x15 }, /* Use this row to check eccgenerate() */
     342                 :            :         { 0xef775737a0c6512b, 0xe7 }, /* Use this row to check eccgenerate() */
     343                 :            :         { 0xfc54621b81b20612, 0x9a }, /* Use this row to check eccgenerate() */
     344                 :            :         { 0x6bb1c04745b5e95c, 0x1e }, /* Use this row to check eccgenerate() */
     345                 :            :         { 0x06d20d5e41ba5141, 0x56 }, /* Use this row to check eccgenerate() */
     346                 :            :         { 0x8d5cac7ebb616716, 0x43 }, /* Use this row to check eccgenerate() */
     347                 :            :         { 0x89da9073ae3c3935, 0xb1 }, /* Use this row to check eccgenerate() */
     348                 :            :         { 0x3e106d6cc3002613, 0xec }, /* Use this row to check eccgenerate() */
     349                 :            :         { 0x60889f2f95a45a14, 0x69 }, /* Use this row to check eccgenerate() */
     350                 :            :         { 0xc94b352b8388a06d, 0x53 }, /* Use this row to check eccgenerate() */
     351                 :            :         { 0xa940f12ef0331804, 0x7a }, /* Use this row to check eccgenerate() */
     352                 :            : 
     353                 :            : };
     354                 :            : 
     355                 :          1 : int main(void)
     356                 :            : {
     357                 :            :         int i;
     358                 :            :         uint8_t ret_memcpy;
     359                 :            :         uint8_t ret_verify;
     360                 :            :         uint64_t dst;
     361                 :            :         uint64_t *buf;
     362                 :            :         struct ecc64 *ret_buf;
     363                 :            : 
     364                 :            :         /*
     365                 :            :          * Test that eccgenerate() still works, but skip the first 64 because they
     366                 :            :          * have intentional bitflips
     367                 :            :          */
     368                 :          1 :         printf("Checking eccgenerate()\n");
     369                 :        257 :         for (i = 64; i < NUM_ECC_ROWS; i++) {
     370                 :        256 :                 if (eccgenerate(be64toh(ecc_data[i].data)) != ecc_data[i].ecc) {
     371                 :          0 :                         ERR("ECC did not generate the correct value, expecting 0x%02x, got 0x%02x\n",
     372                 :            :                                         ecc_data[i].ecc, eccgenerate(be64toh(ecc_data[i].data)));
     373                 :            :                 }
     374                 :            :         }
     375                 :            : 
     376                 :            :         /* Test that the ecc code can detect and recover bitflips */
     377                 :          1 :         printf("Testing bitflip recovery\n");
     378                 :         65 :         for (i = 0; i < 64; i++) {
     379                 :         64 :                 ret_memcpy = memcpy_from_ecc(&dst, &ecc_data[i], sizeof(dst));
     380                 :         64 :                 if (dst != 0xffffffffffffffff || ret_memcpy) {
     381                 :          0 :                         ERR("ECC code didn't correct bad bit %d in 0x%016lx\n", 63 - i, be64toh(ecc_data[i].data));
     382                 :          0 :                         exit(1);
     383                 :            :                 }
     384                 :            : 
     385                 :         64 :                 ret_verify = eccverify(be64toh(ecc_data[i].data), ecc_data[i].ecc);
     386                 :         64 :                 if (ret_verify != 63 - i) {
     387                 :          0 :                         ERR("ECC did not catch incorrect bit %d in row 0x%016lx 0x%02x, got 0x%02x\n",
     388                 :            :                                         i, ecc_data[i].data, ecc_data[i].ecc, ret_verify);
     389                 :          0 :                         exit(1);
     390                 :            :                 }
     391                 :            :         }
     392                 :            : 
     393                 :          1 :         buf = malloc(NUM_ECC_ROWS * sizeof(*buf));
     394                 :          1 :         if (!buf) {
     395                 :          0 :                 ERR("malloc #1 failed during ecc test\n");
     396                 :          0 :                 exit(1);
     397                 :            :         }
     398                 :          1 :         printf("pass\n");
     399                 :            : 
     400                 :            :         /* Test a large memcpy */
     401                 :          1 :         printf("Testing a large(ish) memcpy_from_ecc()\n");
     402                 :          1 :         ret_memcpy = memcpy_from_ecc(buf, ecc_data, NUM_ECC_ROWS * sizeof(*buf));
     403                 :          1 :         if (ret_memcpy) {
     404                 :          0 :                 ERR("ECC Couldn't memcpy entire buffer\n");
     405                 :          0 :                 exit(1);
     406                 :            :         }
     407                 :            : 
     408                 :        321 :         for (i = 0; i < NUM_ECC_ROWS; i++) {
     409                 :            :                 /* Large memcpy should have fixed the bitflips */
     410                 :        320 :                 if (i < 64 && buf[i] != 0xffffffffffffffff) {
     411                 :          0 :                         ERR("memcpy_from_ecc got it wrong for uint64_t number %d, got 0x%016lx, expecting 0xffffffffffffffff\n",
     412                 :            :                                         i, buf[i]);
     413                 :          0 :                         exit(1);
     414                 :            :                 }
     415                 :            : 
     416                 :            :                 /* But not changed any of the correct data */
     417                 :        320 :                 if (i > 63 && buf[i] != ecc_data[i].data) {
     418                 :          0 :                         ERR("memcpy_from_ecc got it wrong for uint64_t number %d, git 0x%016lx, expecting 0x%016lx\n",
     419                 :            :                                         i, buf[i], ecc_data[i].data);
     420                 :          0 :                         exit(1);
     421                 :            :                 }
     422                 :            :         }
     423                 :          1 :         printf("pass\n");
     424                 :            : 
     425                 :            :         /* Test a memcpy to add ecc data */
     426                 :          1 :         printf("Testing a large(ish) memcpy_to_ecc()\n");
     427                 :          1 :         ret_buf = malloc(ecc_buffer_size(NUM_ECC_ROWS * sizeof(*buf)));
     428                 :          1 :         if (!buf) {
     429                 :          0 :                 ERR("malloc #2 failed during ecc test\n");
     430                 :          0 :                 exit(1);
     431                 :            :         }
     432                 :            : 
     433                 :          1 :         ret_memcpy = memcpy_to_ecc(ret_buf, buf, NUM_ECC_ROWS * sizeof(*buf));
     434                 :          1 :         if (ret_memcpy) {
     435                 :          0 :                 ERR("ECC Couldn't memcpy entire buffer\n");
     436                 :          0 :                 exit(1);
     437                 :            :         }
     438                 :            : 
     439                 :        321 :         for (i = 0; i < NUM_ECC_ROWS; i++) {
     440                 :            :                 /* The data should be the same */
     441                 :        320 :                 if (ret_buf[i].data != buf[i]) {
     442                 :          0 :                         ERR("memcpy_to_ecc got it wrong on uint64_t %d, expecting 0x%016lx, got 0x%016lx\n",
     443                 :            :                                         i, buf[i], ret_buf[i].data);
     444                 :          0 :                         exit(1);
     445                 :            :                 }
     446                 :            : 
     447                 :            :                 /* Check the correctness of ecc bytes */
     448                 :        320 :                 if (ret_buf[i].ecc != ecc_data[i].ecc) {
     449                 :          0 :                         ERR("memcpy_to_ecc got it on the ecc for uint64_t %d, expecting 0x%02x, got 0x%02x\n",
     450                 :            :                                         i, ecc_data[i].ecc, ret_buf[i].ecc);
     451                 :          0 :                         exit(1);
     452                 :            :                 }
     453                 :            :         }
     454                 :          1 :         printf("ECC tests pass\n");
     455                 :            : 
     456                 :          1 :         printf("ECC test error conditions\n");
     457                 :          1 :         if (memcpy_to_ecc(ret_buf, buf, 7) == 0) {
     458                 :          0 :                 ERR("memcpy_to_ecc didn't detect bad size 7\n");
     459                 :          0 :                 exit(1);
     460                 :            :         }
     461                 :            : 
     462                 :          1 :         if (memcpy_to_ecc(ret_buf, buf, 15) == 0) {
     463                 :          0 :                 ERR("memcpy_to_ecc didn't detect bad size 15\n");
     464                 :          0 :                 exit(1);
     465                 :            :         }
     466                 :          1 :         if (memcpy_from_ecc(buf, ret_buf, 7) == 0) {
     467                 :          0 :                 ERR("memcpy_from_ecc didn't detect bad size 7\n");
     468                 :          0 :                 exit(1);
     469                 :            :         }
     470                 :          1 :         if (memcpy_from_ecc(buf, ret_buf, 15) == 0) {
     471                 :          0 :                 ERR("memcpy_from_ecc didn't detect bad size 15\n");
     472                 :          0 :                 exit(1);
     473                 :            :         }
     474                 :          1 :         printf("ECC error conditions pass\n");
     475                 :            : 
     476                 :          1 :         free(buf);
     477                 :          1 :         free(ret_buf);
     478                 :            : 
     479                 :            :         /* Check that unaligned address become aligned */
     480                 :          1 :         if (ecc_buffer_align(0, 5) != 0) {
     481                 :          0 :                 ERR("ecc_buffer_align(0, 5) not 0 -> %ld\n", ecc_buffer_align(0, 5));
     482                 :          0 :                 exit(1);
     483                 :            :         }
     484                 :            : 
     485                 :          1 :         if (ecc_buffer_align(0, 8) != 0) {
     486                 :          0 :                 ERR("ecc_buffer_align(0, 8) not 0 -> %ld\n", ecc_buffer_align(0, 8));
     487                 :          0 :                 exit(1);
     488                 :            :         }
     489                 :          1 :         if (ecc_buffer_align(0, 9) != 9) {
     490                 :          0 :                 ERR("ecc_buffer_align(0, 9) not 9 -> %ld\n", ecc_buffer_align(0, 9));
     491                 :          0 :                 exit(1);
     492                 :            :         }
     493                 :          1 :         if (ecc_buffer_align(0, 15) != 9) {
     494                 :          0 :                 ERR("ecc_buffer_align(0, 15) not 9 -> %ld\n", ecc_buffer_align(0, 15));
     495                 :          0 :                 exit(1);
     496                 :            :         }
     497                 :          1 :         if (ecc_buffer_align(5, 10) != 5) {
     498                 :          0 :                 ERR("ecc_buffer_align(5, 10) not 5 -> %ld\n", ecc_buffer_align(5, 10));
     499                 :          0 :                 exit(1);
     500                 :            :         }
     501                 :          1 :         if (ecc_buffer_align(5, 18) != 14) {
     502                 :          0 :                 ERR("ecc_buffer_align(5, 18) not 14 -> %ld\n", ecc_buffer_align(5, 18));
     503                 :          0 :                 exit(1);
     504                 :            :         }
     505                 :          1 :         if (ecc_buffer_align(0, 50) != 45) {
     506                 :          0 :                 ERR("ecc_buffer_align(0, 50) not 45 -> %ld\n", ecc_buffer_align(0, 50));
     507                 :          0 :                 exit(1);
     508                 :            :         }
     509                 :          1 :         return 0;
     510                 :            : }

Generated by: LCOV version 1.14