flashdb_kvdb1.py 981 B

12345678910111213141516171819202122232425262728293031323334
  1. import flashdb
  2. import struct
  3. DB_PATH = "test/out/fdb_kvdb"
  4. print('test boot_count increment 1')
  5. boot_count = 0
  6. boot_count_blob = struct.pack('i', boot_count)
  7. boot_times = [0, 1, 2, 3, 0, 0, 0, 0, 0, 0]
  8. boot_time_tuple = tuple(boot_times)
  9. boot_time_blob = struct.pack('@10Q', *boot_time_tuple)
  10. default_kv = {
  11. 'username': 'armink', # string KV
  12. 'password': "123456", # string KV
  13. 'boot_count': boot_count_blob, # int type kv
  14. 'boot_time': boot_time_blob, # array type kv
  15. }
  16. # print(default_kv)
  17. fdb = flashdb.KVDB("env", DB_PATH, default_kv, None)
  18. res = fdb.get_blob("boot_count", len(boot_count_blob))
  19. assert res is not None
  20. boot_count = struct.unpack("i", res)[0]
  21. boot_count = boot_count+1
  22. boot_count_blob = struct.pack('i', boot_count)
  23. fdb.set_blob("boot_count", boot_count_blob)
  24. res = fdb.get_blob("boot_count", len(boot_count_blob))
  25. assert res is not None
  26. new_boot_count = struct.unpack("i", res)[0]
  27. assert new_boot_count == boot_count
  28. print('PASS')