flashdb_kvdb2.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import flashdb
  2. import struct
  3. DB_PATH = "test/out/fdb_kvdb"
  4. print('test boot_count increment 2')
  5. boot_count=0
  6. boot_count_fmt='i'
  7. boot_count_blob = struct.pack(boot_count_fmt, boot_count)
  8. boot_count_size = len(boot_count_blob)
  9. boot_time = [0,1,2,3,0,0,0,0,0,0]
  10. boot_time_fmt='@10Q'
  11. boot_time_tuple = tuple(boot_time)
  12. boot_time_blob = struct.pack(boot_time_fmt, *boot_time_tuple)
  13. default_kv={
  14. 'username': 'armink', # string KV
  15. 'password': "123456", # string KV
  16. 'boot_count': boot_count_blob, # int type kv
  17. 'boot_time': boot_time_blob, # array type kv
  18. }
  19. fdb = flashdb.KVDB("env", DB_PATH, default_kv, None)
  20. #print(default_kv)
  21. kvdb = fdb
  22. boot_count = fdb.get_by_fmt("boot_count", boot_count_size, boot_count_fmt)
  23. assert boot_count is not None
  24. print("==================== kvdb_basic_sample ====================")
  25. print( "get the 'boot_count' value is %d" % boot_count)
  26. boot_count = boot_count +1
  27. res =fdb.set_by_fmt("boot_count", boot_count, boot_count_fmt)
  28. new_boot_count = fdb.get_by_fmt("boot_count", boot_count_size, boot_count_fmt)
  29. assert new_boot_count is not None
  30. print( "get the 'boot_count' value is %d" % new_boot_count)
  31. print("===========================================================")
  32. assert new_boot_count == boot_count
  33. print('PASS')