summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Zaoui <daniel.zaoui@yahoo.com>2015-12-19 18:46:28 +0200
committerDaniel Zaoui <daniel.zaoui@yahoo.com>2015-12-19 18:46:28 +0200
commit7d8cdfacd712c339293ea0512bae961aea7a1866 (patch)
treea1eea16fe328be72bbebb29d4739d132c2db539d
parent7ec33cc6bb971d1bf6789fcd656f7db9d2880fc4 (diff)
Implement the pattern generator
-rw-r--r--src/bin/edbg_checker.c123
1 files changed, 122 insertions, 1 deletions
diff --git a/src/bin/edbg_checker.c b/src/bin/edbg_checker.c
index a07fa04..6a9f1b2 100644
--- a/src/bin/edbg_checker.c
+++ b/src/bin/edbg_checker.c
@@ -2,6 +2,7 @@
2#include <Eet.h> 2#include <Eet.h>
3 3
4#define _PROFILE_EET_ENTRY "config" 4#define _PROFILE_EET_ENTRY "config"
5#define BUFFER_SIZE 1000000
5 6
6typedef enum 7typedef enum
7{ 8{
@@ -16,9 +17,17 @@ typedef struct
16 const char *script; 17 const char *script;
17 Clouseau_Profile_Type type; 18 Clouseau_Profile_Type type;
18} Clouseau_Profile; 19} Clouseau_Profile;
19
20static Eet_Data_Descriptor *_profile_edd = NULL; 20static Eet_Data_Descriptor *_profile_edd = NULL;
21 21
22static Eina_Debug_Session *_session = NULL;
23static Eina_Debug_Client *_client = NULL;
24
25static int _remaining_tests = 1000;
26static int _pattern_size;
27static char _pattern_buf[BUFFER_SIZE];
28
29static uint32_t _data_test_opcode = EINA_DEBUG_OPCODE_INVALID;
30
22static void 31static void
23_profile_eet_load() 32_profile_eet_load()
24{ 33{
@@ -40,6 +49,75 @@ _profile_eet_load()
40#undef CFG_ADD_BASIC 49#undef CFG_ADD_BASIC
41} 50}
42 51
52static void
53_pattern_generate()
54{
55 int i;
56 if (!_remaining_tests--) exit(0);
57 do
58 {
59 _pattern_size = rand() % BUFFER_SIZE;
60 } while(!_pattern_size);
61 printf("Generating pattern: size %d\n", _pattern_size);
62 for (i = 0; i < _pattern_size; i++)
63 {
64 _pattern_buf[i] = rand() % 256;
65 }
66 eina_debug_session_send(_client, _data_test_opcode, _pattern_buf, _pattern_size);
67}
68
69static Eina_Bool
70_pattern_check_cb(Eina_Debug_Client *src EINA_UNUSED, void *buffer, int size)
71{
72 if (_pattern_size != size)
73 {
74 fprintf(stderr, "Bad size (%d-%d) for received buffer\n", _pattern_size, size);
75 exit(1);
76 }
77 else if (memcmp(_pattern_buf, buffer, _pattern_size))
78 {
79 fprintf(stderr, "Bad contents for received buffer\n");
80 exit(1);
81 }
82 else
83 {
84 printf(" ---- Received buffer (size %d) ok\n", size);
85 _pattern_generate();
86 }
87 return EINA_TRUE;
88}
89
90static void
91_post_register_handle(Eina_Bool flag)
92{
93 if(!flag) return;
94 _client = eina_debug_client_new(_session, 0);
95 _pattern_generate();
96}
97
98static Eina_List *
99_parse_script(const char *script)
100{
101 Eina_List *lines = NULL;
102 while (script && *script)
103 {
104 char *tmp = strchr(script, '\n');
105 Eina_Stringshare *line;
106 if (tmp)
107 {
108 line = eina_stringshare_add_length(script, tmp - script);
109 script = tmp + 1;
110 }
111 else
112 {
113 line = eina_stringshare_add(script);
114 script = NULL;
115 }
116 lines = eina_list_append(lines, line);
117 }
118 return lines;
119}
120
43static Clouseau_Profile * 121static Clouseau_Profile *
44_config_load(const char *path) 122_config_load(const char *path)
45{ 123{
@@ -50,9 +128,50 @@ _config_load(const char *path)
50 return p; 128 return p;
51} 129}
52 130
131static const Eina_Debug_Opcode ops[] =
132{
133 {"daemon/data_test", &_data_test_opcode, _pattern_check_cb},
134 {NULL, NULL, NULL}
135};
136
137static Eina_Bool
138_profile_load(Clouseau_Profile *p)
139{
140 _session = eina_debug_session_new();
141
142 switch (p->type)
143 {
144 case CLOUSEAU_PROFILE_LOCAL:
145 if (!eina_debug_local_connect(_session))
146 {
147 fprintf(stderr, "ERROR: Cannot connect to debug daemon.\n");
148 return EINA_FALSE;
149 }
150 break;
151 case CLOUSEAU_PROFILE_SHELL_REMOTE:
152 eina_debug_session_basic_codec_add(_session, EINA_DEBUG_CODEC_BASE_16);
153 Eina_List *script_lines = _parse_script(p->script);
154 if (!eina_debug_shell_remote_connect(_session, p->command, script_lines))
155 {
156 fprintf(stderr, "ERROR: Cannot connect to shell remote debug daemon.\n");
157 return EINA_FALSE;
158 }
159 break;
160 default:
161 {
162 printf("Profile type %d not supported\n", p->type);
163 return EINA_FALSE;
164 }
165 }
166
167 eina_debug_opcodes_register(_session, ops, _post_register_handle);
168 return EINA_TRUE;
169}
170
53int main(int argc, char **argv) 171int main(int argc, char **argv)
54{ 172{
55 int error = 1; 173 int error = 1;
174 eina_debug_reconnect_set(EINA_FALSE); /* No need to connect as an application*/
56 eina_init(); 175 eina_init();
57 eet_init(); 176 eet_init();
58 _profile_eet_load(); 177 _profile_eet_load();
@@ -70,6 +189,8 @@ int main(int argc, char **argv)
70 fprintf(stderr, "Incorrect path (%s) or bad contents\n", path); 189 fprintf(stderr, "Incorrect path (%s) or bad contents\n", path);
71 goto end; 190 goto end;
72 } 191 }
192 _profile_load(p);
193 while(1) sleep(10);
73 error = 0; 194 error = 0;
74end: 195end:
75 eet_shutdown(); 196 eet_shutdown();