123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657(*
Read and write messages between workers and master used to manage
parallel test execution
This is designed to be simple to debug and to minimize external
dependencies.
*)openPrintftypet=|End_testofstring(* test ID *)|Errorofstring(* error message *)|Junkofstring(* any non-conforming line of input *)letcheck_test_idstr=str<>""&&Helpers.string_for_all(function|'0'..'9'|'a'..'f'->true|_->false)strletof_stringstr=matchString.index_optstr' 'with|None->Junkstr|Somei->(letkind=String.substr0iinletpayload=String.substr(i+1)(String.lengthstr-i-1)inmatchkindwith|"END_TEST"->lettest_id=payloadinifcheck_test_idtest_idthenEnd_testtest_idelseJunkstr|"ERROR"->Errorpayload|_->Junkstr)(* TODO: properly encode newlines so that we can decode long messages such
as stack traces into something more readable *)letreplace_newlinesstr=String.map(function|'\n'->' '|c->c)strletto_stringx=(matchxwith|End_testtest_id->sprintf"END_TEST %s"test_id|Errormsg->sprintf"ERROR %s"msg|Junkdata->(* This should be unused. A writer should not send 'Junk' messages.
If they do, it's by writing junk to stdout without going through
this function. *)sprintf"JUNK %s"data)|>replace_newlines