vboot_api_kernel6_tests.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /* Copyright (c) 2013 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. * Tests for vboot_api_kernel.c
  6. */
  7. #include <stdint.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include "test_common.h"
  12. #include "vboot_api.h"
  13. #include "vboot_nvstorage.h"
  14. /* Mock data */
  15. static uint32_t virtual_dev_mode_fail;
  16. /**
  17. * Reset mock data (for use before each test)
  18. */
  19. static void ResetMocks(void)
  20. {
  21. virtual_dev_mode_fail = 0;
  22. }
  23. /* Mocks */
  24. uint32_t SetVirtualDevMode(int val)
  25. {
  26. if (virtual_dev_mode_fail)
  27. return VBERROR_SIMULATED;
  28. return VBERROR_SUCCESS;
  29. }
  30. static void VbUnlockDeviceTest(void)
  31. {
  32. ResetMocks();
  33. TEST_EQ(VbUnlockDevice(), 0, "unlock success");
  34. ResetMocks();
  35. virtual_dev_mode_fail = 1;
  36. TEST_EQ(VbUnlockDevice(), VBERROR_TPM_SET_BOOT_MODE_STATE,
  37. "set dev fail");
  38. }
  39. static void VbLockDeviceTest(void)
  40. {
  41. ResetMocks();
  42. TEST_EQ(VbLockDevice(), 0, "lock success");
  43. }
  44. int main(void)
  45. {
  46. VbUnlockDeviceTest();
  47. VbLockDeviceTest();
  48. return gTestSuccess ? 0 : 255;
  49. }