From 409b9922ea66a5ddca9ad27223e5079928c7fbd5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C4=99drzej=20Boczar?= <jboczar@antmicro.com>
Date: Tue, 11 Feb 2020 13:00:04 +0100
Subject: [PATCH] test: add random address generation in benchmarks

---
 test/benchmark.py   |  19 +++-
 test/benchmarks.yml | 268 +++++++++++++++++++++++++++++++-------------
 test/gen_config.py  |   2 +-
 3 files changed, 204 insertions(+), 85 deletions(-)

diff --git a/test/benchmark.py b/test/benchmark.py
index f720c96..29a25b5 100755
--- a/test/benchmark.py
+++ b/test/benchmark.py
@@ -26,7 +26,8 @@ class LiteDRAMBenchmarkSoC(SimSoC):
     def __init__(self,
         sdram_module     = "MT48LC16M16",
         sdram_data_width = 32,
-        bist_base        = 0x00000000,
+        bist_base        = 0x0000000,
+        bist_end         = 0x0100000,
         bist_length      = 1024,
         bist_random      = False,
         bist_alternating = False,
@@ -41,27 +42,37 @@ class LiteDRAMBenchmarkSoC(SimSoC):
             **kwargs
         )
 
+        # BIST Generator / Checker -----------------------------------------------------------------
+
         # make sure that we perform at least one access
         bist_length = max(bist_length, self.sdram.controller.interface.data_width // 8)
 
-        # BIST Generator / Checker -----------------------------------------------------------------
         if pattern_init is None:
             bist_generator = _LiteDRAMBISTGenerator(self.sdram.crossbar.get_port())
             bist_checker = _LiteDRAMBISTChecker(self.sdram.crossbar.get_port())
 
             generator_config = [
                 bist_generator.base.eq(bist_base),
+                bist_generator.end.eq(bist_end),
                 bist_generator.length.eq(bist_length),
-                bist_generator.random.eq(bist_random),
+                bist_generator.random_addr.eq(bist_random),
             ]
             checker_config = [
                 bist_checker.base.eq(bist_base),
+                bist_checker.end.eq(bist_end),
                 bist_checker.length.eq(bist_length),
-                bist_checker.random.eq(bist_random),
+                bist_checker.random_addr.eq(bist_random),
             ]
 
             assert not (bist_random and not bist_alternating), \
                 'Write to random address may overwrite previously written data before reading!'
+
+            # check address correctness
+            assert bist_end > bist_base
+            assert bist_end <= 2**(len(bist_generator.end)) - 1, 'End address outside of range'
+            bist_addr_range = bist_end - bist_base
+            assert bist_addr_range > 0 and bist_addr_range & (bist_addr_range - 1) == 0, \
+                'Length of the address range must be a power of 2'
         else:
             if not bist_alternating:
                 address_set = set()
diff --git a/test/benchmarks.yml b/test/benchmarks.yml
index 7d3177a..a399832 100644
--- a/test/benchmarks.yml
+++ b/test/benchmarks.yml
@@ -5,7 +5,7 @@
         "bist_alternating": true,
         "access_pattern": {
             "bist_length": 1,
-            "bist_random": false
+            "bist_random": true
         }
     },
     "test_1": {
@@ -13,7 +13,7 @@
         "sdram_data_width": 32,
         "bist_alternating": true,
         "access_pattern": {
-            "bist_length": 1024,
+            "bist_length": 1,
             "bist_random": false
         }
     },
@@ -22,59 +22,59 @@
         "sdram_data_width": 32,
         "bist_alternating": true,
         "access_pattern": {
-            "bist_length": 8192,
-            "bist_random": false
+            "bist_length": 1024,
+            "bist_random": true
         }
     },
     "test_3": {
         "sdram_module": "MT41K128M16",
         "sdram_data_width": 32,
-        "bist_alternating": false,
+        "bist_alternating": true,
         "access_pattern": {
-            "bist_length": 1,
+            "bist_length": 1024,
             "bist_random": false
         }
     },
     "test_4": {
         "sdram_module": "MT41K128M16",
         "sdram_data_width": 32,
-        "bist_alternating": false,
+        "bist_alternating": true,
         "access_pattern": {
-            "bist_length": 1024,
-            "bist_random": false
+            "bist_length": 8192,
+            "bist_random": true
         }
     },
     "test_5": {
         "sdram_module": "MT41K128M16",
         "sdram_data_width": 32,
-        "bist_alternating": false,
+        "bist_alternating": true,
         "access_pattern": {
             "bist_length": 8192,
             "bist_random": false
         }
     },
     "test_6": {
-        "sdram_module": "MT46V32M16",
+        "sdram_module": "MT41K128M16",
         "sdram_data_width": 32,
-        "bist_alternating": true,
+        "bist_alternating": false,
         "access_pattern": {
             "bist_length": 1,
             "bist_random": false
         }
     },
     "test_7": {
-        "sdram_module": "MT46V32M16",
+        "sdram_module": "MT41K128M16",
         "sdram_data_width": 32,
-        "bist_alternating": true,
+        "bist_alternating": false,
         "access_pattern": {
             "bist_length": 1024,
             "bist_random": false
         }
     },
     "test_8": {
-        "sdram_module": "MT46V32M16",
+        "sdram_module": "MT41K128M16",
         "sdram_data_width": 32,
-        "bist_alternating": true,
+        "bist_alternating": false,
         "access_pattern": {
             "bist_length": 8192,
             "bist_random": false
@@ -83,41 +83,32 @@
     "test_9": {
         "sdram_module": "MT46V32M16",
         "sdram_data_width": 32,
-        "bist_alternating": false,
+        "bist_alternating": true,
         "access_pattern": {
             "bist_length": 1,
-            "bist_random": false
+            "bist_random": true
         }
     },
     "test_10": {
         "sdram_module": "MT46V32M16",
         "sdram_data_width": 32,
-        "bist_alternating": false,
+        "bist_alternating": true,
         "access_pattern": {
-            "bist_length": 1024,
+            "bist_length": 1,
             "bist_random": false
         }
     },
     "test_11": {
         "sdram_module": "MT46V32M16",
         "sdram_data_width": 32,
-        "bist_alternating": false,
+        "bist_alternating": true,
         "access_pattern": {
-            "bist_length": 8192,
-            "bist_random": false
+            "bist_length": 1024,
+            "bist_random": true
         }
     },
     "test_12": {
-        "sdram_module": "MT47H64M16",
-        "sdram_data_width": 32,
-        "bist_alternating": true,
-        "access_pattern": {
-            "bist_length": 1,
-            "bist_random": false
-        }
-    },
-    "test_13": {
-        "sdram_module": "MT47H64M16",
+        "sdram_module": "MT46V32M16",
         "sdram_data_width": 32,
         "bist_alternating": true,
         "access_pattern": {
@@ -125,8 +116,17 @@
             "bist_random": false
         }
     },
+    "test_13": {
+        "sdram_module": "MT46V32M16",
+        "sdram_data_width": 32,
+        "bist_alternating": true,
+        "access_pattern": {
+            "bist_length": 8192,
+            "bist_random": true
+        }
+    },
     "test_14": {
-        "sdram_module": "MT47H64M16",
+        "sdram_module": "MT46V32M16",
         "sdram_data_width": 32,
         "bist_alternating": true,
         "access_pattern": {
@@ -135,7 +135,7 @@
         }
     },
     "test_15": {
-        "sdram_module": "MT47H64M16",
+        "sdram_module": "MT46V32M16",
         "sdram_data_width": 32,
         "bist_alternating": false,
         "access_pattern": {
@@ -144,7 +144,7 @@
         }
     },
     "test_16": {
-        "sdram_module": "MT47H64M16",
+        "sdram_module": "MT46V32M16",
         "sdram_data_width": 32,
         "bist_alternating": false,
         "access_pattern": {
@@ -153,7 +153,7 @@
         }
     },
     "test_17": {
-        "sdram_module": "MT47H64M16",
+        "sdram_module": "MT46V32M16",
         "sdram_data_width": 32,
         "bist_alternating": false,
         "access_pattern": {
@@ -162,105 +162,111 @@
         }
     },
     "test_18": {
-        "sdram_module": "MT48LC16M16",
+        "sdram_module": "MT47H64M16",
         "sdram_data_width": 32,
         "bist_alternating": true,
         "access_pattern": {
             "bist_length": 1,
-            "bist_random": false
+            "bist_random": true
         }
     },
     "test_19": {
-        "sdram_module": "MT48LC16M16",
+        "sdram_module": "MT47H64M16",
         "sdram_data_width": 32,
         "bist_alternating": true,
         "access_pattern": {
-            "bist_length": 1024,
+            "bist_length": 1,
             "bist_random": false
         }
     },
     "test_20": {
-        "sdram_module": "MT48LC16M16",
+        "sdram_module": "MT47H64M16",
         "sdram_data_width": 32,
         "bist_alternating": true,
         "access_pattern": {
-            "bist_length": 8192,
-            "bist_random": false
+            "bist_length": 1024,
+            "bist_random": true
         }
     },
     "test_21": {
-        "sdram_module": "MT48LC16M16",
+        "sdram_module": "MT47H64M16",
         "sdram_data_width": 32,
-        "bist_alternating": false,
-        "access_pattern": {
-            "bist_length": 1,
-            "bist_random": false
-        }
-    },
-    "test_22": {
-        "sdram_module": "MT48LC16M16",
-        "sdram_data_width": 32,
-        "bist_alternating": false,
+        "bist_alternating": true,
         "access_pattern": {
             "bist_length": 1024,
             "bist_random": false
         }
     },
-    "test_23": {
-        "sdram_module": "MT48LC16M16",
+    "test_22": {
+        "sdram_module": "MT47H64M16",
         "sdram_data_width": 32,
-        "bist_alternating": false,
+        "bist_alternating": true,
+        "access_pattern": {
+            "bist_length": 8192,
+            "bist_random": true
+        }
+    },
+    "test_23": {
+        "sdram_module": "MT47H64M16",
+        "sdram_data_width": 32,
+        "bist_alternating": true,
         "access_pattern": {
             "bist_length": 8192,
             "bist_random": false
         }
     },
     "test_24": {
-        "sdram_module": "MT41K128M16",
+        "sdram_module": "MT47H64M16",
         "sdram_data_width": 32,
-        "bist_alternating": true,
+        "bist_alternating": false,
         "access_pattern": {
-            "pattern_file": "access_pattern.csv"
+            "bist_length": 1,
+            "bist_random": false
         }
     },
     "test_25": {
-        "sdram_module": "MT41K128M16",
+        "sdram_module": "MT47H64M16",
         "sdram_data_width": 32,
         "bist_alternating": false,
         "access_pattern": {
-            "pattern_file": "access_pattern.csv"
+            "bist_length": 1024,
+            "bist_random": false
         }
     },
     "test_26": {
-        "sdram_module": "MT46V32M16",
+        "sdram_module": "MT47H64M16",
         "sdram_data_width": 32,
-        "bist_alternating": true,
+        "bist_alternating": false,
         "access_pattern": {
-            "pattern_file": "access_pattern.csv"
+            "bist_length": 8192,
+            "bist_random": false
         }
     },
     "test_27": {
-        "sdram_module": "MT46V32M16",
-        "sdram_data_width": 32,
-        "bist_alternating": false,
-        "access_pattern": {
-            "pattern_file": "access_pattern.csv"
-        }
-    },
-    "test_28": {
-        "sdram_module": "MT47H64M16",
+        "sdram_module": "MT48LC16M16",
         "sdram_data_width": 32,
         "bist_alternating": true,
         "access_pattern": {
-            "pattern_file": "access_pattern.csv"
+            "bist_length": 1,
+            "bist_random": true
+        }
+    },
+    "test_28": {
+        "sdram_module": "MT48LC16M16",
+        "sdram_data_width": 32,
+        "bist_alternating": true,
+        "access_pattern": {
+            "bist_length": 1,
+            "bist_random": false
         }
     },
     "test_29": {
-        "sdram_module": "MT47H64M16",
+        "sdram_module": "MT48LC16M16",
         "sdram_data_width": 32,
-        "bist_alternating": false,
+        "bist_alternating": true,
         "access_pattern": {
-            "pattern_file": "access_pattern.csv"
+            "bist_length": 1024,
+            "bist_random": true
         }
     },
     "test_30": {
@@ -268,10 +274,112 @@
         "sdram_data_width": 32,
         "bist_alternating": true,
         "access_pattern": {
-            "pattern_file": "access_pattern.csv"
+            "bist_length": 1024,
+            "bist_random": false
         }
     },
     "test_31": {
+        "sdram_module": "MT48LC16M16",
+        "sdram_data_width": 32,
+        "bist_alternating": true,
+        "access_pattern": {
+            "bist_length": 8192,
+            "bist_random": true
+        }
+    },
+    "test_32": {
+        "sdram_module": "MT48LC16M16",
+        "sdram_data_width": 32,
+        "bist_alternating": true,
+        "access_pattern": {
+            "bist_length": 8192,
+            "bist_random": false
+        }
+    },
+    "test_33": {
+        "sdram_module": "MT48LC16M16",
+        "sdram_data_width": 32,
+        "bist_alternating": false,
+        "access_pattern": {
+            "bist_length": 1,
+            "bist_random": false
+        }
+    },
+    "test_34": {
+        "sdram_module": "MT48LC16M16",
+        "sdram_data_width": 32,
+        "bist_alternating": false,
+        "access_pattern": {
+            "bist_length": 1024,
+            "bist_random": false
+        }
+    },
+    "test_35": {
+        "sdram_module": "MT48LC16M16",
+        "sdram_data_width": 32,
+        "bist_alternating": false,
+        "access_pattern": {
+            "bist_length": 8192,
+            "bist_random": false
+        }
+    },
+    "test_36": {
+        "sdram_module": "MT41K128M16",
+        "sdram_data_width": 32,
+        "bist_alternating": true,
+        "access_pattern": {
+            "pattern_file": "access_pattern.csv"
+        }
+    },
+    "test_37": {
+        "sdram_module": "MT41K128M16",
+        "sdram_data_width": 32,
+        "bist_alternating": false,
+        "access_pattern": {
+            "pattern_file": "access_pattern.csv"
+        }
+    },
+    "test_38": {
+        "sdram_module": "MT46V32M16",
+        "sdram_data_width": 32,
+        "bist_alternating": true,
+        "access_pattern": {
+            "pattern_file": "access_pattern.csv"
+        }
+    },
+    "test_39": {
+        "sdram_module": "MT46V32M16",
+        "sdram_data_width": 32,
+        "bist_alternating": false,
+        "access_pattern": {
+            "pattern_file": "access_pattern.csv"
+        }
+    },
+    "test_40": {
+        "sdram_module": "MT47H64M16",
+        "sdram_data_width": 32,
+        "bist_alternating": true,
+        "access_pattern": {
+            "pattern_file": "access_pattern.csv"
+        }
+    },
+    "test_41": {
+        "sdram_module": "MT47H64M16",
+        "sdram_data_width": 32,
+        "bist_alternating": false,
+        "access_pattern": {
+            "pattern_file": "access_pattern.csv"
+        }
+    },
+    "test_42": {
+        "sdram_module": "MT48LC16M16",
+        "sdram_data_width": 32,
+        "bist_alternating": true,
+        "access_pattern": {
+            "pattern_file": "access_pattern.csv"
+        }
+    },
+    "test_43": {
         "sdram_module": "MT48LC16M16",
         "sdram_data_width": 32,
         "bist_alternating": false,
diff --git a/test/gen_config.py b/test/gen_config.py
index 9a02d12..7c01602 100755
--- a/test/gen_config.py
+++ b/test/gen_config.py
@@ -42,7 +42,7 @@ default_modules = [
 default_bist_alternatings = [True, False]
 default_data_widths = [32]
 default_bist_lengths = [1, 1024, 8192]
-default_bist_randoms = [False]
+default_bist_randoms = [True, False]
 default_access_patterns = ['access_pattern.csv']