Upgrade bluez5_37 :Merge the code from private
[platform/upstream/bluez.git] / tools / check-selftest.c
1 /*
2  *
3  *  BlueZ - Bluetooth protocol stack for Linux
4  *
5  *  Copyright (C) 2012-2014  Intel Corporation. All rights reserved.
6  *
7  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21  *
22  */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <stdio.h>
29 #include <unistd.h>
30 #include <stdlib.h>
31 #include <string.h>
32 #include <sys/stat.h>
33
34 static void check_result(const char *name, const char *pathname)
35 {
36         FILE *fp;
37         int i;
38
39         for (i = 0; i < 50; i++) {
40                 struct stat st;
41
42                 if (!stat(pathname, &st)) {
43                         printf("Found %s selftest result\n", name);
44                         break;
45                 }
46
47                 usleep(25 * 1000);
48         }
49
50         fp = fopen(pathname, "re");
51         if (fp) {
52                 char result[32], *ptr;
53
54                 ptr = fgets(result, sizeof(result), fp);
55                 fclose(fp);
56
57                 ptr = strpbrk(result, "\r\n");
58                 if (ptr)
59                         *ptr = '\0';
60
61                 printf("%s: %s\n", name, result);
62         }
63 }
64
65 int main(int argc, char *argv[])
66 {
67         check_result("ECDH", "/sys/kernel/debug/bluetooth/selftest_ecdh");
68         check_result("SMP",  "/sys/kernel/debug/bluetooth/selftest_smp");
69
70         return 0;
71 }