fix all tests
authorLaurent Mazet <mazet@softndesign.org>
Thu, 10 Apr 2025 20:28:30 +0000 (22:28 +0200)
committerLaurent Mazet <mazet@softndesign.org>
Thu, 10 Apr 2025 20:28:30 +0000 (22:28 +0200)
morep_simulator.c
parse.h
script-bypass.eth
script-control.eth
script-lo.eth
script-local_crypto.eth
script-prng.eth

index 1a76d84e2e53c8144da93d06e12b41604dae48e0..11cc979a40845dfa255478dc83dd38b30a77388d 100644 (file)
@@ -79,7 +79,7 @@ message_t message_list[] = {
 
     /* PRNG service */
     {"RANDOM_REQ", prng_e, 0x00, prng_param_e},
-    {"RANDOM_RESP", prng_e, 0x01, status_e},
+    {"RANDOM_RESP", prng_e, 0x01, raw_data_e},
 
     /* Control service */
     {"STATUS_REQ", control_e, 0x00, nopdu_e},
@@ -90,8 +90,8 @@ message_t message_list[] = {
     {"REBOOT_RESP", control_e, 0x05, status_e},
     {"ZEROIZE_REQ", control_e, 0x04, nopdu_e},
     {"ZEROIZE_RESP", control_e, 0x05, status_e},
-    {"LOCK_REQ", control_e, 0xFE, nopdu_e},
-    {"LOCK_RESP", control_e, 0xFF, status_e},
+    {"LOCK_CRYPTO_REQ", control_e, 0xFE, nopdu_e},
+    {"LOCK_CRYPTO_RESP", control_e, 0xFF, status_e},
 
     /* End of list */
     {"", noserv_e, 0x00, undef_pdu_e}
@@ -245,7 +245,7 @@ int main (int argc, char **argv)
                     (comm_list + nbcomms)->etype = strrchr (url, '/') + 1;
                     for (int i = 0; (service_list + i)->service_id != noserv_e; i++) {
                         service_t *s = service_list + i;
-                        if (strcmp (s->name, servname) == 0) {
+                        if (s && servname && (strcmp (s->name, servname) == 0)) {
                             memcpy (mode ? &(s->rx) : &(s->tx), comm_list + nbcomms, sizeof (comm_t));
                             break;
                         }
@@ -438,6 +438,8 @@ int main (int argc, char **argv)
             /* parse message */
             pdu = msg->pdu;
             switch (pdu) {
+            case nopdu_e:
+                break;
             case channel_e:
                 parse_channel (line + offset, &msg_channel);
                 break;
@@ -497,7 +499,7 @@ int main (int argc, char **argv)
 
             uint8_t msgtype = 0;
             uint8_t payload[1496] = {0};
-            int seqnum = MOREP_Receive (comm->morep, &msgtype, payload, &len);
+            seqnum = MOREP_Receive (comm->morep, &msgtype, payload, &len);
 
             /* check pdu type */
             pdu = undef_pdu_e;
@@ -517,6 +519,8 @@ int main (int argc, char **argv)
 
             /* deserialize message */
             switch (pdu) {
+            case nopdu_e:
+                break;
             case channel_e:
                 deserial_channel (payload, len, &msg_channel);
                 break;
@@ -551,6 +555,8 @@ int main (int argc, char **argv)
                      serv->name, comm->etype, seqnum, msg->msgtype, len, pdu, msg->name);
             char buffer[1496 * 3 + 256] = {0};
             switch (pdu) {
+            case nopdu_e:
+                break;
             case channel_e:
                 format_channel (&msg_channel, buffer, sizeof (buffer));
                 break;
@@ -596,12 +602,18 @@ int main (int argc, char **argv)
 /* 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 - -t lo://00:00:00:00:00:00/0809 -v 4 script-l0.eth */
+/* 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-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 | grep -v WARNING */
 /* 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-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 | grep -v WARNING */
 /* 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-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 | grep -v WARNING */
 /* 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-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 | grep -v WARNING */
 /* 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 4 */
+/* 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 | grep -v WARNING */
+/* 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-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 | grep -v WARNING */
 
 /* vim: set ts=4 sw=4 si et: */
diff --git a/parse.h b/parse.h
index fd94ad4277ea3906018a5245bc8d47363f05bead..f141972136a8fd2dbdcb18a5f153fa9a26b84026 100644 (file)
--- a/parse.h
+++ b/parse.h
@@ -320,7 +320,7 @@ __BEGIN_DECLS
 */
 #define SERIAL_ARRAY(name, field)                                          \
     if (field##_len < _maxlen - len) {                                     \
-        memcpy (_buffer + len, field, field##_len);                        \
+        memcpy (_buffer + len, field, (uint16_t)field##_len);              \
         len += field##_len;                                                \
     } else {                                                               \
         VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \
@@ -337,7 +337,7 @@ __BEGIN_DECLS
 */
 #define SERIAL_TAB(name, field)                                            \
     if ((int)sizeof (field) < _maxlen - len) {                             \
-        memcpy (_buffer + len, field, sizeof (field));                     \
+        memcpy (_buffer + len, field, (uint16_t)sizeof (field));           \
         len += sizeof (field);                                             \
     } else {                                                               \
         VERBOSE (morep, WARNING, PRINTF ("field '%s' too large\n", name)); \
@@ -444,8 +444,8 @@ __BEGIN_DECLS
 */
 #define DESERIAL_TAB(name, field)                                            \
     if ((int)sizeof (field) < end - ptr) {                                   \
-        memcpy (field, ptr, sizeof (field));                                 \
-        ptr += sizeof (field);                                                \
+        memcpy (field, ptr, (uint16_t)sizeof (field));                       \
+        ptr += sizeof (field);                                               \
     } else {                                                                 \
         VERBOSE (morep, WARNING, PRINTF ("no data for field '%s'\n", name)); \
         ptr = end + 1;                                                       \
@@ -462,13 +462,13 @@ __BEGIN_DECLS
 */
 #define DESERIAL_ARRAY(name, field, ...)                                     \
     if ((0 == __VA_ARGS__ + 0) && (ptr < end)) {                             \
-        memcpy (field, ptr, end - ptr);                                      \
+        memcpy (field, ptr, (uint16_t)(end - ptr));                          \
         field##_len = end - ptr;                                             \
         ptr = end;                                                           \
     } else if (field##_len < end - ptr) {                                    \
-        memcpy (field, ptr, field##_len);                                    \
+        memcpy (field, ptr, (uint16_t)field##_len);                          \
         ptr += field##_len;                                                  \
-    } else {                                                                 \
+    } else if (field##_len > 0) {                                            \
         VERBOSE (morep, WARNING, PRINTF ("no data for field '%s'\n", name)); \
         ptr = end + 1;                                                       \
     }
index 83eed3b2669cac9108179465cfdda79d909c2544..8fed1178a8d26f585b81bdd6005aa55bc77a4272 100644 (file)
@@ -1,7 +1,7 @@
 # Bypass test script
 
-T:BYPASS BYPASS_CROSS_ASYNC DATA=@makefile
+T:BYPASS BYPASS_CROSS_ASYNC DATA=@script-bypass.eth
 R:BYPASS BYPASS_CROSS_ASYNC
 
-T:BYPASS BYPASSED_CROSS_ASYNC DATA=@makefile
+T:BYPASS BYPASSED_CROSS_ASYNC DATA=@script-bypass.eth
 R:BYPASS BYPASSED_CROSS_ASYNC
index 6dd80962fa1d29c201b6fdf2bc67ca34367aa4a7..d5cce3dbf98d526470d2b7772a91060950632f98 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="Authentification_completed"
 R:CONTROL AUTHENTIFICATION_RESP
 
 T:CONTROL REBOOT_REQ
@@ -18,11 +18,11 @@ R:CONTROL REBOOT_REQ
 T:CONTROL REBOOT_RESP STATUS=0
 R:CONTROL REBOOT_RESP
 
-T:CONTROL ZEROISE_REQ
-R:CONTROL ZEROISE_REQ
+T:CONTROL ZEROIZE_REQ
+R:CONTROL ZEROIZE_REQ
 
-T:CONTROL ZEROISE_RESP STATUS=0xFF
-R:CONTROL ZEROISE_RESP
+T:CONTROL ZEROIZE_RESP STATUS=0xFF
+R:CONTROL ZEROIZE_RESP
 
 T:CONTROL LOCK_CRYPTO_REQ
 R:CONTROL LOCK_CRYPTO_REQ
index 515b72962e3d7a48d00d7decc6740c9812dafe67..4b574549668ddb56aa457e2680b950fc777e9d58 100644 (file)
@@ -8,5 +8,5 @@ SLEEP 1000
 T0808 MSG=24 DATA=42796520776f726c64
 R0808 MSG=24 DATA=42796520776f726c64
 
-T0808 MSG=10 DATA=@makefile
-R0808 MSG=10 DATA=@makefile
+T0808 MSG=10 DATA=@script-lo.eth
+R0808 MSG=10 DATA=@script-lo.eth
index 875757a939f7fbd25e8eb7679307894d2f11abdc..cfca6d5e4a2271e2a96196a2d747af5a213b0c38 100644 (file)
@@ -1,6 +1,6 @@
 # Local crypto test script
 
-T:LOCAL_CRYPTO ENCRYPT_LOCAL_ASYNC CHANNELID=2 BYPASSLEN=4 BYPASS=11:22:33:44 DATA=@script-cross_crypto.eth
+T:LOCAL_CRYPTO ENCRYPT_LOCAL_ASYNC CHANNELID=2 BYPASSLEN=4 BYPASS=11223344 DATA=@script-cross_crypto.eth
 R:LOCAL_CRYPTO ENCRYPT_LOCAL_ASYNC
 
 T:LOCAL_CRYPTO ENCRYPTED_LOCAL_ASYNC CHANNELID=9 BYPASSLEN=0 DATA=@script-local_crypto.eth
@@ -9,5 +9,5 @@ R:LOCAL_CRYPTO ENCRYPTED_LOCAL_ASYNC
 T:LOCAL_CRYPTO DECRYPT_LOCAL_ASYNC CHANNELID=5 BYPASSLEN=0 DATA=@script-local_crypto.eth
 R:LOCAL_CRYPTO DECRYPT_LOCAL_ASYNC
 
-T:LOCAL_CRYPTO DECRYPTED_LOCAL_ASYNC CHANNELID=0 BYPASSLEN=4 BYPASS=11:22:33:44 DATA=@script-cross_crypto.eth
+T:LOCAL_CRYPTO DECRYPTED_LOCAL_ASYNC CHANNELID=0 BYPASSLEN=4 BYPASS=11223344 DATA=@script-cross_crypto.eth
 R:LOCAL_CRYPTO DECRYPTED_LOCAL_ASYNC
index 2145b5144c377175c764b1c14bf4c555d068a814..517cce38db57c2e705d38a62f78b3b865394d85f 100644 (file)
@@ -3,5 +3,5 @@
 T:PRNG RANDOM_REQ PRNGID=0 SEQLEN=64 SEED=0102030405060708090A0B0C0D0E0F10
 R:PRNG RANDOM_REQ
 
-T:PRNG RANDOM_RESP DATA=@makefile
+T:PRNG RANDOM_RESP DATA=@script-prng.eth
 R:PRNG RANDOM_RESP