return number of error and warning seen
authorLaurent Mazet <mazet@softndesign.org>
Fri, 11 Apr 2025 04:02:20 +0000 (06:02 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Fri, 11 Apr 2025 04:02:20 +0000 (06:02 +0200)
morep_simulator.c
morep_test.c
morep_valid.c
script-control.eth

index b506fd89790d97484fff7dc8369519f80f5a604a..9af642172063cf89f35ac0e4e367adcb5f700755 100644 (file)
@@ -43,6 +43,7 @@ char *progname = NULL;
 int stop = 0;
 
 DECLARE_VERBOSE_LEVEL (morep, INFO);
+DECLARE_VERBOSE_LEVEL (simul, INFO);
 
 #define BUFMAX 4096
 
@@ -129,7 +130,7 @@ void sig_handler (int sig)
 /* read a file */
 char *read_stream (FILE *sd, int *plen)
 {
-    VERBOSE (morep, TRACE, PRINTF ("read_stream\n"));
+    VERBOSE (simul, TRACE, PRINTF ("read_stream\n"));
 
     /* read and store */
     char *buffer = NULL;
@@ -145,7 +146,7 @@ char *read_stream (FILE *sd, int *plen)
     } while (blocklen > 0);
 
     /* check size */
-    VERBOSE (morep, DEBUG, PRINTF ("read length: %d\n", length));
+    VERBOSE (simul, DEBUG, PRINTF ("read length: %d\n", length));
     if (length == 0) {
         free (buffer);
         buffer = NULL;
@@ -190,7 +191,7 @@ int main (int argc, char **argv)
         case 'l':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
             if (arg == NULL) {
-                VERBOSE (morep, ERROR, PRINTF ("%s: log file not specified\n", progname));
+                VERBOSE (simul, ERROR, PRINTF ("%s: log file not specified\n", progname));
                 return 1;
             }
             logname = arg;
@@ -198,7 +199,7 @@ int main (int argc, char **argv)
         case 'r':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
             if (arg == NULL) {
-                VERBOSE (morep, ERROR, PRINTF ("%s: receiver url not specified\n", progname));
+                VERBOSE (simul, ERROR, PRINTF ("%s: receiver url not specified\n", progname));
                 return 1;
             }
             url = arg;
@@ -207,7 +208,7 @@ int main (int argc, char **argv)
         case 's':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
             if (arg == NULL) {
-                VERBOSE (morep, ERROR, PRINTF ("%s: service not specified\n", progname));
+                VERBOSE (simul, ERROR, PRINTF ("%s: service not specified\n", progname));
                 return 1;
             }
             servname = arg;
@@ -215,7 +216,7 @@ int main (int argc, char **argv)
         case 't':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
             if (arg == NULL) {
-                VERBOSE (morep, ERROR, PRINTF ("%s: transmitter url not specified\n", progname));
+                VERBOSE (simul, ERROR, PRINTF ("%s: transmitter url not specified\n", progname));
                 return 1;
             }
             url = arg;
@@ -224,14 +225,22 @@ int main (int argc, char **argv)
         case 'v':
             arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
             if (arg == NULL) {
-                VERBOSE (morep, ERROR, PRINTF ("%s: verbose level not specified\n", progname));
+                VERBOSE (simul, ERROR, PRINTF ("%s: morep verbose level not specified\n", progname));
                 return 1;
             }
             CHANGE_VERBOSE_LEVEL (morep, atoi (arg));
             break;
+        case 'V':
+            arg = (arg[2]) ? arg + 2 : (--argc > 0) ? *(++argv) : NULL;
+            if (arg == NULL) {
+                VERBOSE (simul, ERROR, PRINTF ("%s: simulator verbose level not specified\n", progname));
+                return 1;
+            }
+            CHANGE_VERBOSE_LEVEL (simul, atoi (arg));
+            break;
         case 'h':
         default:
-            printf ("usage: %s [-h] [-l log] [-r url] [-s serv] [-t url] [-v level] [file]\n", progname);
+            printf ("usage: %s [-h] [-l log] [-r url] [-s serv] [-t url] [-v level] [-V level] [file]\n", progname);
             return (c != 'h');
         }
 
@@ -252,11 +261,11 @@ int main (int argc, char **argv)
                     }
                     nbcomms++;
                 } else {
-                    VERBOSE (morep, ERROR, PRINTF ("can't connect on url '%s'\n", url));
+                    VERBOSE (simul, ERROR, PRINTF ("can't connect on url '%s'\n", url));
                     return -1;
                 }
             } else {
-                VERBOSE (morep, ERROR, PRINTF ("no more communication channel avaliable (%d)\n", nbcomms));
+                VERBOSE (simul, ERROR, PRINTF ("no more communication channel avaliable (%d)\n", nbcomms));
                 return -1;
             }
             mode = -1;
@@ -265,7 +274,7 @@ int main (int argc, char **argv)
 
     /* checks */
     if (nbcomms == 0) {
-        VERBOSE (morep, ERROR, PRINTF ("no communication channel\n"));
+        VERBOSE (simul, ERROR, PRINTF ("no communication channel\n"));
         return -1;
     }
 
@@ -274,7 +283,7 @@ int main (int argc, char **argv)
     if (filename != NULL) {
         fid = fopen (filename, "r");
         if (fid == NULL) {
-            VERBOSE (morep, ERROR, PRINTF ("can't open script file '%s' for reading\n", filename));
+            VERBOSE (simul, ERROR, PRINTF ("can't open script file '%s' for reading\n", filename));
             return -1;
         }
     }
@@ -283,7 +292,7 @@ int main (int argc, char **argv)
         fclose (fid);
     }
     if (script == NULL) {
-        VERBOSE (morep, ERROR, PRINTF ("no script read\n"));
+        VERBOSE (simul, ERROR, PRINTF ("no script read\n"));
         return -1;
     }
 
@@ -295,7 +304,7 @@ int main (int argc, char **argv)
         } else {
             log = fopen (logname, "w");
             if (log == NULL) {
-                VERBOSE (morep, ERROR, PRINTF ("can't open log file '%s' for writing\n", logname));
+                VERBOSE (simul, ERROR, PRINTF ("can't open log file '%s' for writing\n", logname));
                 return -1;
             }
         }
@@ -324,7 +333,7 @@ int main (int argc, char **argv)
         /* special keywords */
         if (strncmp (line, "SLEEP", 5) == 0) {
             int duration = atoi (line + 5);
-            VERBOSE (morep, INFO, PRINTF ("sleep %dms\n", duration));
+            VERBOSE (simul, INFO, PRINTF ("sleep %dms\n", duration));
             usleep (duration * 1000);
             continue;
         }
@@ -332,7 +341,7 @@ int main (int argc, char **argv)
         /* analyse line */
         mode = (*line == 'R') ? 0 : (*line == 'T') ? 1 : -1;
         if (mode == -1) {
-            VERBOSE (morep, WARNING, PRINTF ("unrecognize line '%s'\n", line));
+            VERBOSE (simul, WARNING, PRINTF ("unrecognize line '%s'\n", line));
             continue;
         }
         int offset = 1;
@@ -347,7 +356,7 @@ int main (int argc, char **argv)
         /* find MOREP by service name */
         for (int i = 0; ((service_list + i)->service_id != noserv_e) && (serv == NULL); i++) {
             service_t *s = service_list + i;
-            VERBOSE (morep, TRACE, PRINTF ("test %c[%s]\n", *line, s->name));
+            VERBOSE (simul, TRACE, PRINTF ("test %c[%s]\n", *line, s->name));
             if (strncmp (line + offset, s->name, strlen (s->name)) == 0) {
                 comm = mode ? &(s->rx) : &(s->tx);
                 serv = s;
@@ -357,7 +366,7 @@ int main (int argc, char **argv)
         /* find MOREP by ethertype */
         for (int j = 0; (j < nbcomms) && (comm == NULL); j++) {
             comm_t *c = comm_list + j;
-            VERBOSE (morep, TRACE, PRINTF ("test %c[%s]\n", c->mode ? 'T' : 'R', c->etype));
+            VERBOSE (simul, TRACE, PRINTF ("test %c[%s]\n", c->mode ? 'T' : 'R', c->etype));
             if ((strncmp (line + offset, c->etype, strlen (c->etype)) == 0) && (c->mode == mode)) {
                 comm = c;
                 for (int i = 0; ((service_list + i)->service_id != noserv_e) && (serv == NULL); i++) {
@@ -372,10 +381,10 @@ int main (int argc, char **argv)
         }
         /* check media and service */
         if ((comm == NULL) || (serv == NULL)) {
-            VERBOSE (morep, TRACE, PRINTF ("no morep found '%s'\n", line));
+            VERBOSE (simul, TRACE, PRINTF ("no morep found '%s'\n", line));
             continue;
         }
-        VERBOSE (morep, DEBUG, PRINTF ("work with %c[%s]\n", comm->mode ? 'T' : 'R', serv->name));
+        VERBOSE (simul, DEBUG, PRINTF ("work with %c[%s]\n", comm->mode ? 'T' : 'R', serv->name));
 
         /* skip space */
         tmp = line + offset;
@@ -386,7 +395,7 @@ int main (int argc, char **argv)
         /* get message type by name */
         for (int i = 0; ((message_list + i)->service_id != noserv_e) && (msg == NULL); i++) {
             message_t *m = message_list + i;
-            VERBOSE (morep, TRACE, PRINTF ("test %s\n", m->name));
+            VERBOSE (simul, TRACE, PRINTF ("test %s\n", m->name));
             if (strncmp (line + offset, m->name, strlen (m->name)) == 0) {
                 msg = m;
                 offset += strlen (m->name);
@@ -395,7 +404,7 @@ int main (int argc, char **argv)
         /* get message type by id */
         if (msg == NULL) {
             if (strncmp (line + offset, "MSG", 3) != 0) {
-                VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
+                VERBOSE (simul, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
                 continue;
             }
             tmp = line + offset + 3;
@@ -403,7 +412,7 @@ int main (int argc, char **argv)
             uint8_t msgtype = strtol (tmp, &tmp, 0);
             offset = tmp - line;
             if ((*tmp != ' ') && (*tmp != '\t')) {
-                VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
+                VERBOSE (simul, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
                 continue;
             }
             /* find message */
@@ -417,10 +426,10 @@ int main (int argc, char **argv)
 
         /* check message and service */ 
         if (serv->service_id != msg->service_id) {
-            VERBOSE (morep, WARNING, PRINTF ("message %s is not allowed for service %s (line '%s')\n", msg->name, serv->name, line));
+            VERBOSE (simul, WARNING, PRINTF ("message %s is not allowed for service %s (line '%s')\n", msg->name, serv->name, line));
             continue;
         }
-        VERBOSE (morep, DEBUG, PRINTF ("work with message %s\n", msg->name));
+        VERBOSE (simul, DEBUG, PRINTF ("work with message %s\n", msg->name));
 
         CHANNEL_t msg_channel = {0};
         CLEAR_DATA_t msg_clear_data = {0};
@@ -462,7 +471,7 @@ int main (int argc, char **argv)
                 parse_status (line + offset, &msg_status);
                 break;
             default:
-                VERBOSE (morep, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
+                VERBOSE (simul, WARNING, PRINTF ("can't parse line '%s' (%d)\n", line, offset));
                 continue;
             }
 
@@ -514,7 +523,7 @@ int main (int argc, char **argv)
 
             /* check msg type */
             if (msgtype != msg->msgtype) {
-                VERBOSE (morep, WARNING, PRINTF ("R%sx SEQ=%d MSG=%d: expected msgtype %d\n", comm->etype, seqnum, msgtype, msg->msgtype));
+                VERBOSE (simul, WARNING, PRINTF ("R%sx SEQ=%d MSG=%d: expected msgtype %d\n", comm->etype, seqnum, msgtype, msg->msgtype));
             }
 
             /* deserialize message */
@@ -543,7 +552,7 @@ int main (int argc, char **argv)
                 deserial_status (payload, len, &msg_status);
                 break;
             default:
-                VERBOSE (morep, WARNING, PRINTF ("can't deserialize message R%s[%02x]'\n", comm->etype, msgtype));
+                VERBOSE (simul, WARNING, PRINTF ("can't deserialize message R%s[%02x]'\n", comm->etype, msgtype));
                 continue;
             }
 
@@ -594,20 +603,22 @@ int main (int argc, char **argv)
         fclose (log);
     }
 
-    return rc;
+    return rc + GET_VERBOSE_ERRORS (morep) + GET_VERBOSE_ERRORS (simul);
 }
 
 /* test: morep_simulator.exe -h | grep usage */
-/* test: morep_simulator.exe -l 2>&1 | grep 'log file not specified' */
-/* test: morep_simulator.exe -r 2>&1 | grep 'url not specified' */
-/* test: morep_simulator.exe -s 2>&1 | grep 'service not specified' */
-/* test: morep_simulator.exe -t 2>&1 | grep 'url not specified' */
+/* test: morep_simulator.exe -l | grep 'log file not specified' */
+/* test: morep_simulator.exe -r | grep 'url not specified' */
+/* test: morep_simulator.exe -s | grep 'service not specified' */
+/* test: morep_simulator.exe -t | grep 'url not specified' */
+/* test: morep_simulator.exe -v | grep 'morep verbose level not specified' */
+/* test: morep_simulator.exe -V | grep 'simulator verbose level not specified' */
 /* test: morep_simulator.exe -l - -t lo://00:00:00:00:00:00/0809 -v 4 script-lo.eth */
-/* test: morep_simulator.exe -l script-cross_crypto.log -s CROSS_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-cross_crypto.eth */
-/* test: morep_simulator.exe -l script-local_crypto.log -s LOCAL_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-local_crypto.eth */
-/* test: morep_simulator.exe -l script-provisioning.log -s PROVISIONING -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-provisioning.eth */
-/* test: morep_simulator.exe -l script-prng.log -s PRNG -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-prng.eth */
-/* test: morep_simulator.exe -l script-bypass.log -s BYPASS -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-bypass.eth */
-/* test: morep_simulator.exe -l script-control.log -s CONTROL -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-control.eth -v 3 */
+/* test: morep_simulator.exe -l script-cross_crypto.log -s CROSS_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-cross_crypto.eth -V 3 */
+/* test: morep_simulator.exe -l script-local_crypto.log -s LOCAL_CRYPTO -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-local_crypto.eth -V 3 */
+/* test: morep_simulator.exe -l script-provisioning.log -s PROVISIONING -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-provisioning.eth -V 3 */
+/* test: morep_simulator.exe -l script-prng.log -s PRNG -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-prng.eth -V 3 */
+/* test: morep_simulator.exe -l script-bypass.log -s BYPASS -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-bypass.eth -V 3 */
+/* test: morep_simulator.exe -l script-control.log -s CONTROL -t lo://00:00:00:00:00:00/0808 -r lo://00:00:00:00:00:00/0808 script-control.eth -v 3 -V 3 */
 
 /* vim: set ts=4 sw=4 si et: */
index 9599f51c959018baf772e2d2da1503394a1894ca..84eb0711e41e848d6c8534dab80541b8ea9b1c98 100644 (file)
@@ -309,7 +309,7 @@ int main (int argc, char **argv)
         rc = server (url);
     }
 
-    return rc;
+    return rc + GET_VERBOSE_ERRORS (morep);
 }
 
 /* test: morep_test.exe -h | grep usage */
index 04a0de8c9aae6d1a334d7c0dd2e5be24099aa1e2..bcff5123ccde15a5f3718af5bffe7875b69a53c2 100644 (file)
@@ -344,7 +344,7 @@ int main (int argc, char **argv)
         fclose (log);
     }
 
-    return rc;
+    return rc + GET_VERBOSE_ERRORS (morep);
 }
 
 /* test: morep_valid.exe -h | grep usage */
index d5cce3dbf98d526470d2b7772a91060950632f98..942ce1fa7b84d84a1f18f7301ea6f85a2f1723c8 100644 (file)
@@ -6,10 +6,10 @@ R:CONTROL STATUS_REQ
 T:CONTROL STATUS_RESP STATUS=4
 R:CONTROL STATUS_RESP
 
-T:CONTROL AUTHENTIFICATION_REQ DATA="This_is_an_authentification_phrase"
+T:CONTROL AUTHENTIFICATION_REQ DATA="This\ is\ an\ authentification\ phrase"
 R:CONTROL AUTHENTIFICATION_REQ
 
-T:CONTROL AUTHENTIFICATION_RESP DATA="Authentification_completed"
+T:CONTROL AUTHENTIFICATION_RESP DATA="Authentificationcompleted"
 R:CONTROL AUTHENTIFICATION_RESP
 
 T:CONTROL REBOOT_REQ