• 1 Post
  • 2 Comments
Joined 1 year ago
cake
Cake day: November 21st, 2023

help-circle
  • So I’m testing for three things:

    • Capacity
    • Performance
    • Endurance

    Capacity

    Divide the card up into eight equal segments. Within each segment (except for the first), choose a random starting location. Write 4MB of random data to the very beginning of the card, the very end of the card, and to each of the other 7 randomly selected locations. Then, read back each segment and compare the data read to what was written. If all 9 segments match, the card is considered “not fake flash”. Otherwise, the space between the last “good” segment and the first “bad” segment is bisected until the point at which “bad” sectors begin to appear is determined. The device is considered to be “fake flash”; the capacity is declared to be the amount of space between the start of the device and the last “good” sector.

    It’s not a perfect strategy – cause it doesn’t account for wraparound flash or flash that is bad from the very beginning – but it gets it right 98% of the time.

    Performance

    There’s two components to this: a sequential read/write test and a random read/write test.

    For the sequential read/write test: start from the very beginning of the device. For 30 seconds, read as much data as possible in a sequential fashion, recording the total number of bytes read. At the end of 30 seconds, take the total number of bytes read and divide by 30. The device’s sequential read speed is considered to be this result (measured in bytes per second). For the sequential write test – do the same thing, but generate random data and write it to the device.

    For the random read/write test: Choose a random sector on the device. Read 4KB of data from the chosen sector. Repeat this process for 30 seconds, keeping count of the number of read operations completed. Take the final result and divide by 30. The device’s random read speed is considered to be this result (measured in IOPs per second). For the random write test – do the same thing, but generate random data and write it to the device.

    Again, this isn’t perfect. It’s probably good enough for determining whether a device meets the requirements for Class2/Class4/Class6/Class10, but the video speed classes (V6/V10/V30/V60/V90) require some special commands to be issued to the card that just can’t be issued via most USB card readers. Also, I didn’t read the specific set of conditions for testing for the A1/A2 speed classes – so my program can probably get you in the neighborhood of the right number, but won’t be 100% accurate.

    Endurance

    Divide the card into 16 equal segments. Shuffle the segments into a random order. For each segment, write pseudorandom data to the entire segment.

    Shuffle the segments into a random order again. For each segment, read back the data. Regenerate the pseudorandom data that was originally written to the segment and compare it to what was written. If there is a mismatch in any given sector, the sector is flagged as “bad”.

    (If an I/O error is encountered on any given sector, the operation is retried several times – including resetting the device if necessary and/or waiting for the device to be reconnected. If all attempts fail, the sector is flagged as “bad”.)

    Keep a count of the number of complete read/write cycles that have been performed against the device.

    Repeat until at least 50% of the sectors on the device have been flagged as “bad”, or until an unrecoverable I/O error has occurred.