24 const RunResult &result,
bool thermal,
const char *kind,
26 const std::vector<ArtifactDigest> &artifacts) {
28 std::FILE *file = std::fopen(path,
"wx");
31 const std::array<const char *, 4> faults = {
"drop",
"delay",
"freeze",
"overload_request"};
35 "{\n \"schema\": \"loop-timing-witness.native-run.v1\",\n"
36 " \"source_kind\": \"%s\",\n \"controller\": \"%s\",\n"
37 " \"cycles\": %u, \"period_ticks\": %u, \"thermal\": %s,\n"
38 " \"coefficients\": {\"kp\": %d, \"ki_period\": %d, \"derivative_decay\": %d,"
39 " \"derivative_gain\": %d, \"position_gain\": %d, \"velocity_gain\": %d,"
40 " \"reference_gain\": %d, \"output_min\": %d, \"output_max\": %d,"
41 " \"integral_min\": %d, \"integral_max\": %d},\n"
42 " \"reference\": {\"mode\": %u, \"amplitude\": %d, \"offset\": %d,"
43 " \"ramp\": %d, \"phase\": %u},\n"
44 " \"fault\": {\"kind\": \"%s\", \"cycle\": %u, \"duration_periods\": %u},\n"
45 " \"overload\": {\"iterations\": %u, \"modeled_nanoseconds\": %u},\n"
46 " \"result\": {\"samples\": %llu, \"records\": %llu, \"misses\": %u,"
47 " \"overflow\": %u, \"safe\": %s},\n",
49 thermal ?
"true" :
"false", c.kp, c.ki_period, c.derivative_decay,
50 c.derivative_gain, c.position_gain, c.velocity_gain, c.reference_gain,
51 c.output_min, c.output_max, c.integral_min, c.integral_max,
56 static_cast<unsigned long long>(result.
records), result.
misses,
58 bool artifact_failed = std::fputs(
" \"artifacts\": {", file) < 0;
59 for (std::size_t index = 0; index < artifacts.size(); ++index) {
60 const auto &artifact = artifacts[index];
61 if (std::fprintf(file,
"%s\"%s\": {\"sha256\": \"%s\", \"bytes\": %llu}", index ?
", " :
"",
62 artifact.role, artifact.digest.sha256.c_str(),
63 static_cast<unsigned long long>(artifact.digest.bytes)) < 0)
64 artifact_failed =
true;
66 artifact_failed = std::fputs(
"},\n", file) < 0 || artifact_failed;
67 const bool crypto_failed =
70 " \"crypto_library\": {\"algorithm\": \"sha256\", \"header_version_number\": %llu, "
71 "\"runtime_version_number\": %llu},\n",
72 static_cast<unsigned long long>(OPENSSL_VERSION_NUMBER),
73 static_cast<unsigned long long>(OpenSSL_version_num())) < 0;
75 const bool end_failed = std::fprintf(file,
"}\n") < 0;
76 const int status = std::fclose(file);
77 if (failed || artifact_failed || crypto_failed || policy_failed || end_failed || status)