<commit_before>package dmtest.writeboost

import dmtest._
import dmtest.stack._

class WriteAroundCachingTest extends DMTestSuite {
  test("read caching work") {
    slowDevice(Sector.G(1)) { backing =><commit_msg>wip<commit_after>package dmtest.writeboost

import dmtest._
import dmtest.stack._

class WriteAroundCachingTest extends DMTestSuite {
  test("read-hit and assert") {
    slowDevice(Sector.G(1)) { backing =>
      fastDevice(Sector.M(32)) { caching =>
        Writeboost.sweepCaches(caching)
        val table = Writeboost.Table(backing, caching,
          Map("nr_read_cache_cells" -> 1, "write_around_mode" -> 1, "read_cache_threshold" -> 1))
        table.create { s =>
          val orig = DataBuffer.random(4096)
          s.bdev.write(Sector.K(4), orig)
          assert(s.status.stat(Writeboost.StatKey(true, false, false, true)) === 1)

          val read1 = s.bdev.read(Sector.K(4), Sector.K(4))
          assert(s.status.stat(Writeboost.StatKey(false, false, false, true)) === 1)
          assert(s.status.stat(Writeboost.StatKey(false, true, false, true)) === 0)
          assert(read1 isSameAs orig)
          Thread.sleep(5000) // wait for injection
          s.dropTransient()

          val read2 = s.bdev.read(Sector.K(4), Sector.K(4))
          assert(s.status.stat(Writeboost.StatKey(false, true, false, true)) === 1)
          assert(read2 isSameAs orig)
        }
      }
    }
  }
  test("read caching work") {
    slowDevice(Sector.G(1)) { backing =>
{'fraction_non_alphanumeric': 0.13804713804713806, 'fraction_numerical': 0.019528619528619527, 'mean_word_length': 2.962666666666667, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4554022', 'n_tokens_mistral': 518, 'n_tokens_neox': 486, 'n_words': 94}