bdb_nvm_test.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /* Copyright 2015 The Chromium OS Authors. All rights reserved.
  2. * Use of this source code is governed by a BSD-style license that can be
  3. * found in the LICENSE file.
  4. *
  5. * Unit tests NVM
  6. */
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "bdb_api.h"
  11. #include "test_common.h"
  12. static void test_nvmrw(void)
  13. {
  14. struct vba_context ctx;
  15. uint32_t val;
  16. memset(&ctx.nvmrw, 0, sizeof(ctx.nvmrw));
  17. TEST_SUCC(nvmrw_set(&ctx, NVMRW_VAR_UPDATE_COUNT, 1), NULL);
  18. TEST_SUCC(nvmrw_get(&ctx, NVMRW_VAR_UPDATE_COUNT, &val), NULL);
  19. TEST_EQ(val, 1, NULL);
  20. TEST_SUCC(nvmrw_set(&ctx, NVMRW_VAR_MIN_KERNEL_DATA_KEY_VERSION, 1),
  21. NULL);
  22. TEST_SUCC(nvmrw_get(&ctx, NVMRW_VAR_MIN_KERNEL_DATA_KEY_VERSION, &val),
  23. NULL);
  24. TEST_EQ(val, 1, NULL);
  25. TEST_SUCC(nvmrw_set(&ctx, NVMRW_VAR_MIN_KERNEL_VERSION, 1), NULL);
  26. TEST_SUCC(nvmrw_get(&ctx, NVMRW_VAR_MIN_KERNEL_VERSION, &val), NULL);
  27. TEST_EQ(val, 1, NULL);
  28. TEST_SUCC(nvmrw_set(&ctx, NVMRW_VAR_BUC_TYPE, 1), NULL);
  29. TEST_SUCC(nvmrw_get(&ctx, NVMRW_VAR_BUC_TYPE, &val), NULL);
  30. TEST_EQ(val, 1, NULL);
  31. TEST_SUCC(nvmrw_set(&ctx, NVMRW_VAR_FLAG_BUC_PRESENT, 1), NULL);
  32. TEST_SUCC(nvmrw_get(&ctx, NVMRW_VAR_FLAG_BUC_PRESENT, &val), NULL);
  33. TEST_TRUE(val, NULL);
  34. TEST_SUCC(nvmrw_set(&ctx, NVMRW_VAR_FLAG_DFM_DISABLE, 1), NULL);
  35. TEST_SUCC(nvmrw_get(&ctx, NVMRW_VAR_FLAG_DFM_DISABLE, &val), NULL);
  36. TEST_TRUE(val, NULL);
  37. TEST_SUCC(nvmrw_set(&ctx, NVMRW_VAR_FLAG_DOSM, 1), NULL);
  38. TEST_SUCC(nvmrw_get(&ctx, NVMRW_VAR_FLAG_DOSM, &val), NULL);
  39. TEST_TRUE(val, NULL);
  40. }
  41. int main(int argc, char *argv[])
  42. {
  43. printf("Running BDB NVM tests...\n");
  44. test_nvmrw();
  45. return gTestSuccess ? 0 : 255;
  46. }