check-selftest.c 1014 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. *
  4. * BlueZ - Bluetooth protocol stack for Linux
  5. *
  6. * Copyright (C) 2012-2014 Intel Corporation. All rights reserved.
  7. *
  8. *
  9. */
  10. #ifdef HAVE_CONFIG_H
  11. #include <config.h>
  12. #endif
  13. #define _GNU_SOURCE
  14. #include <stdio.h>
  15. #include <unistd.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <sys/stat.h>
  19. static void check_result(const char *name, const char *pathname)
  20. {
  21. FILE *fp;
  22. int i;
  23. for (i = 0; i < 50; i++) {
  24. struct stat st;
  25. if (!stat(pathname, &st)) {
  26. printf("Found %s selftest result\n", name);
  27. break;
  28. }
  29. usleep(25 * 1000);
  30. }
  31. fp = fopen(pathname, "re");
  32. if (fp) {
  33. char result[32], *ptr;
  34. ptr = fgets(result, sizeof(result), fp);
  35. fclose(fp);
  36. ptr = strpbrk(result, "\r\n");
  37. if (ptr)
  38. *ptr = '\0';
  39. printf("%s: %s\n", name, result);
  40. }
  41. }
  42. int main(int argc, char *argv[])
  43. {
  44. check_result("ECDH", "/sys/kernel/debug/bluetooth/selftest_ecdh");
  45. check_result("SMP", "/sys/kernel/debug/bluetooth/selftest_smp");
  46. return 0;
  47. }