plugin_msr_index_list.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /*
  2. * Copyright 2018 The ChromiumOS Authors
  3. * Use of this source code is governed by a BSD-style license that can be
  4. * found in the LICENSE file.
  5. */
  6. #include <errno.h>
  7. #include <stdint.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include "crosvm.h"
  12. int main(int argc, char** argv) {
  13. struct crosvm *crosvm;
  14. int ret = crosvm_connect(&crosvm);
  15. if (ret) {
  16. fprintf(stderr, "failed to connect to crosvm: %d\n", ret);
  17. return 1;
  18. }
  19. uint32_t msr_indices[256];
  20. int n_entries;
  21. ret = crosvm_get_msr_index_list(crosvm, 1, msr_indices, &n_entries);
  22. if (ret >= 0) {
  23. fprintf(stderr,
  24. "expected crosvm_get_msr_index_list to fail with E2BIG\n");
  25. return 1;
  26. }
  27. memset(msr_indices, 0, sizeof(msr_indices));
  28. ret = crosvm_get_msr_index_list(crosvm, 256, msr_indices, &n_entries);
  29. if (ret < 0) {
  30. fprintf(stderr,
  31. "unexpected failure of crosvm_get_msr_index_list: %d\n", ret);
  32. return 1;
  33. }
  34. if (n_entries <= 1) {
  35. fprintf(stderr,
  36. "unexpected number of supported msr entries: %d\n",
  37. n_entries);
  38. return 1;
  39. }
  40. return 0;
  41. }