135 lines
4.9 KiB
C
135 lines
4.9 KiB
C
#include "sph_worker_reports.h"
|
|
#include "sph_worker_protocol.h"
|
|
|
|
#include <stdio.h>
|
|
#include <string.h>
|
|
|
|
static int fail(const char *message)
|
|
{
|
|
fprintf(stderr, "%s\n", message);
|
|
return 1;
|
|
}
|
|
|
|
static int contains(const char *text, const char *needle)
|
|
{
|
|
return strstr(text, needle) != 0;
|
|
}
|
|
|
|
int main(void)
|
|
{
|
|
char record[512];
|
|
char path[512];
|
|
sphlite_worker_log_record_t log_record;
|
|
sphlite_worker_particle_record_t particle;
|
|
sphlite_worker_force_record_t force;
|
|
if (strcmp(sphlite_worker_report_filename(SPHLITE_WORKER_REPORT_LOG),
|
|
"sphlite_cclite_worker.log") != 0) {
|
|
return fail("worker log filename mismatch");
|
|
}
|
|
if (!contains(sphlite_worker_report_header(SPHLITE_WORKER_REPORT_LOG),
|
|
"command_block") ||
|
|
!contains(sphlite_worker_report_header(SPHLITE_WORKER_REPORT_LOG),
|
|
"ack_sequence") ||
|
|
!contains(sphlite_worker_report_header(SPHLITE_WORKER_REPORT_LOG),
|
|
"total_fx") ||
|
|
!contains(sphlite_worker_report_header(SPHLITE_WORKER_REPORT_PARTICLE),
|
|
"external_id") ||
|
|
!contains(sphlite_worker_report_header(SPHLITE_WORKER_REPORT_PARTICLE),
|
|
"internal_index") ||
|
|
!contains(sphlite_worker_report_header(SPHLITE_WORKER_REPORT_FORCE),
|
|
"contact_state") ||
|
|
!contains(sphlite_worker_report_header(SPHLITE_WORKER_REPORT_PARTICLE),
|
|
"reject_reason") ||
|
|
!contains(sphlite_worker_report_header(SPHLITE_WORKER_REPORT_FORCE),
|
|
"reject_reason")) {
|
|
return fail("worker report header mismatch");
|
|
}
|
|
if (!sphlite_worker_report_vtk_supported()) {
|
|
return fail("VTU/PVD support was not advertised");
|
|
}
|
|
sphlite_worker_log_record_clear(&log_record);
|
|
log_record.solver_id = "SPH";
|
|
log_record.case_file = "case.inp";
|
|
log_record.ipc_name = "ipc";
|
|
log_record.command_block = "cmd";
|
|
log_record.data_prefix = "data";
|
|
log_record.command_event = "cmd_evt";
|
|
log_record.done_event = "done_evt";
|
|
log_record.timeout_ms = 30;
|
|
log_record.worker_id = "worker";
|
|
log_record.command_id = SPHLITE_WORKER_COMMAND_ADVANCE;
|
|
log_record.step_id = 12;
|
|
log_record.ack_sequence = 44;
|
|
log_record.worker_state = SPHLITE_WORKER_STATE_DONE;
|
|
log_record.exported_particles = 3;
|
|
log_record.exported_facets = 4;
|
|
log_record.received_forces = 5;
|
|
log_record.total_force[0] = 1.0;
|
|
log_record.total_force[1] = 2.0;
|
|
log_record.total_force[2] = 3.0;
|
|
log_record.total_moment[0] = 4.0;
|
|
log_record.total_moment[1] = 5.0;
|
|
log_record.total_moment[2] = 6.0;
|
|
log_record.error_message = "ok";
|
|
if (sphlite_worker_format_log_record(record, (int)sizeof(record),
|
|
&log_record) != 0) {
|
|
return fail("log record formatting failed");
|
|
}
|
|
if (!contains(record, "SPH,case.inp,ipc,cmd,data,cmd_evt,done_evt") ||
|
|
!contains(record, ",44,DONE,") ||
|
|
!contains(record, ",3,4,5,") ||
|
|
!contains(record, ",0,ok")) {
|
|
return fail("log record content mismatch");
|
|
}
|
|
if (sphlite_worker_format_log_record(record, 8, &log_record) == 0) {
|
|
return fail("small log record buffer was accepted");
|
|
}
|
|
if (sphlite_worker_report_path(path, (int)sizeof(path),
|
|
"build-codex-unix/worker_test.log",
|
|
SPHLITE_WORKER_REPORT_PARTICLE) != 0 ||
|
|
!contains(path, "build-codex-unix/") ||
|
|
!contains(path, "sphlite_cclite_particle_report.csv")) {
|
|
return fail("worker report path parsing failed");
|
|
}
|
|
if (sphlite_worker_report_write_header(path,
|
|
SPHLITE_WORKER_REPORT_PARTICLE) != 0 ||
|
|
sphlite_worker_report_append_line(path, "1,2,3") != 0) {
|
|
return fail("worker report file write failed");
|
|
}
|
|
sphlite_worker_particle_record_clear(&particle);
|
|
particle.particle_id_ext = 12;
|
|
particle.export_index = 2;
|
|
particle.internal_index = 3;
|
|
particle.phase = 1;
|
|
particle.status = 0;
|
|
particle.material_id = 4;
|
|
particle.section_id = 5;
|
|
particle.x[0] = 1.0;
|
|
particle.v[2] = 2.0;
|
|
particle.reject_reason = SPHLITE_WORKER_REJECT_INVALID_WEIGHT;
|
|
if (sphlite_worker_format_particle_record(record, (int)sizeof(record),
|
|
7, 2, &particle) != 0 ||
|
|
!contains(record, "7,2,2,3,12,1,0,4,5") ||
|
|
!contains(record, "invalid_weight")) {
|
|
return fail("particle record formatting failed");
|
|
}
|
|
sphlite_worker_force_record_clear(&force);
|
|
force.particle_id_ext = 12;
|
|
force.export_index = 2;
|
|
force.internal_index = 3;
|
|
force.source_id = 8;
|
|
force.pair_id = 9;
|
|
force.force[0] = 3.0;
|
|
force.moment[1] = 4.0;
|
|
force.contact_state = SPHLITE_WORKER_CONTACT_ACTIVE;
|
|
force.reject_reason = SPHLITE_WORKER_REJECT_NONFINITE_FORCE;
|
|
if (sphlite_worker_format_force_record(record, (int)sizeof(record),
|
|
7, 2, &force) != 0 ||
|
|
!contains(record, "7,2,8,9,12,2,3") ||
|
|
!contains(record, "active") ||
|
|
!contains(record, "nonfinite_force")) {
|
|
return fail("force record formatting failed");
|
|
}
|
|
return 0;
|
|
}
|