Initial LinuxCNC WebAssembly workspace snapshot
This commit is contained in:
26
wasm-core/tests/sim_api_test.c
Normal file
26
wasm-core/tests/sim_api_test.c
Normal file
@@ -0,0 +1,26 @@
|
||||
#include "sim_api.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
int main(void) {
|
||||
uint8_t snapshot[sizeof(uint64_t)] = {0};
|
||||
uint8_t state[32] = {0};
|
||||
assert(sim_step(1) == SIM_ERR_NOT_CREATED);
|
||||
assert(sim_create(NULL, 0) == SIM_OK);
|
||||
assert(sim_load_workspace("/workspace") == SIM_OK);
|
||||
assert(sim_step(7) == SIM_OK);
|
||||
assert(sim_read_snapshot(snapshot, sizeof(snapshot)) == sizeof(snapshot));
|
||||
uint64_t tick = 0;
|
||||
memcpy(&tick, snapshot, sizeof(tick));
|
||||
assert(tick == 7);
|
||||
assert(sim_export_state(state, sizeof(state)) > 0);
|
||||
assert(sim_step(3) == SIM_OK);
|
||||
assert(sim_import_state(state, sizeof(state)) == SIM_OK);
|
||||
assert(sim_read_snapshot(snapshot, sizeof(snapshot)) == sizeof(snapshot));
|
||||
memcpy(&tick, snapshot, sizeof(tick));
|
||||
assert(tick == 7);
|
||||
sim_destroy();
|
||||
return 0;
|
||||
}
|
||||
28
wasm-core/tests/sim_event_test.c
Normal file
28
wasm-core/tests/sim_event_test.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include "sim_event.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
int main(void) {
|
||||
uint8_t record[sizeof(sim_event_record)] = {0};
|
||||
uint8_t exported[16384] = {0};
|
||||
const uint8_t payload[] = {'o', 'k'};
|
||||
|
||||
sim_event_reset();
|
||||
assert(sim_event_append(2, 0, "bad", payload, sizeof(payload)) == SIM_EVENT_ERR_SEQUENCE);
|
||||
assert(sim_event_append(1, 2, "STEP", payload, sizeof(payload)) == SIM_EVENT_OK);
|
||||
assert(sim_event_append(2, 1, "BAD_TICK", NULL, 0) == SIM_EVENT_ERR_TICK);
|
||||
assert(sim_event_read(0, NULL, 0) == sizeof(sim_event_record));
|
||||
assert(sim_event_read(0, record, sizeof(record)) == sizeof(record));
|
||||
assert(((sim_event_record *)record)->seq == 1);
|
||||
assert(sim_event_count() == 1);
|
||||
assert(sim_event_cursor() == 1);
|
||||
uint32_t export_size = sim_event_export(NULL, 0);
|
||||
assert(export_size > 0 && export_size < sizeof(exported));
|
||||
assert(sim_event_export(exported, sizeof(exported)) == export_size);
|
||||
sim_event_reset();
|
||||
assert(sim_event_import(exported, export_size) == SIM_EVENT_OK);
|
||||
assert(sim_event_count() == 1);
|
||||
assert(sim_event_import(exported, export_size - 1) == SIM_EVENT_ERR_ARGUMENT);
|
||||
return 0;
|
||||
}
|
||||
29
wasm-core/tests/sim_hal_test.c
Normal file
29
wasm-core/tests/sim_hal_test.c
Normal file
@@ -0,0 +1,29 @@
|
||||
#include "sim_hal.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void) {
|
||||
sim_hal_value bit = {SIM_HAL_BIT, {.bit = 1}};
|
||||
sim_hal_value wrong = {SIM_HAL_S32, {.s32 = 1}};
|
||||
sim_hal_value out = {0};
|
||||
|
||||
sim_hal_reset();
|
||||
assert(sim_hal_register_pin("source", SIM_HAL_BIT) == SIM_HAL_OK);
|
||||
assert(sim_hal_register_pin("target", SIM_HAL_BIT) == SIM_HAL_OK);
|
||||
assert(sim_hal_register_pin("source", SIM_HAL_BIT) == SIM_HAL_ERR_DUPLICATE);
|
||||
assert(sim_hal_set_pin("source", bit) == SIM_HAL_OK);
|
||||
assert(sim_hal_set_pin("source", wrong) == SIM_HAL_ERR_TYPE);
|
||||
assert(sim_hal_connect("source", "target") == SIM_HAL_OK);
|
||||
assert(sim_hal_get_pin("target", &out) == SIM_HAL_OK && out.value.bit == 1);
|
||||
assert(sim_hal_register_thread("servo", 2) == SIM_HAL_OK);
|
||||
assert(sim_hal_register_thread("servo", 2) == SIM_HAL_ERR_DUPLICATE);
|
||||
assert(sim_hal_register_function("servo", "update") == SIM_HAL_OK);
|
||||
assert(sim_hal_register_function("missing", "bad") == SIM_HAL_ERR_NOT_FOUND);
|
||||
assert(sim_hal_step(5) == SIM_HAL_OK);
|
||||
assert(sim_hal_tick() == 5 && sim_hal_function_calls("update") == 2);
|
||||
assert(sim_hal_set_function_failure("update", 1) == SIM_HAL_OK);
|
||||
assert(sim_hal_step(1) == SIM_HAL_ERR_FUNCTION);
|
||||
assert(sim_hal_tick() == 5);
|
||||
assert(sim_hal_register_thread("invalid", 0) == SIM_HAL_ERR_RANGE);
|
||||
return 0;
|
||||
}
|
||||
23
wasm-core/tests/sim_posemath_test.c
Normal file
23
wasm-core/tests/sim_posemath_test.c
Normal file
@@ -0,0 +1,23 @@
|
||||
#include "sim_posemath.h"
|
||||
|
||||
#include <assert.h>
|
||||
#include <math.h>
|
||||
|
||||
int main(void) {
|
||||
sim_posemath_cartesian input = {3.0, 4.0, 0.0};
|
||||
sim_posemath_cartesian output = {0};
|
||||
sim_posemath_cartesian end = {10.0, 10.0, 10.0};
|
||||
double dot = 0;
|
||||
|
||||
assert(sim_posemath_normalize(&input, &output) == SIM_POSEMATH_OK);
|
||||
assert(fabs(output.x - 0.6) < 1e-12 && fabs(output.y - 0.8) < 1e-12);
|
||||
assert(sim_posemath_dot(&input, &end, &dot) == SIM_POSEMATH_OK && dot == 70.0);
|
||||
assert(sim_posemath_line_point(&input, &end, 0.5, &output) == SIM_POSEMATH_OK);
|
||||
assert(output.x == 6.5 && output.y == 7.0 && output.z == 5.0);
|
||||
assert(sim_posemath_line_point(&input, &end, 1.1, &output) == SIM_POSEMATH_ERR_RANGE);
|
||||
input.x = NAN;
|
||||
assert(sim_posemath_normalize(&input, &output) == SIM_POSEMATH_ERR_ARGUMENT);
|
||||
input.x = 0.0; input.y = 0.0; input.z = 0.0;
|
||||
assert(sim_posemath_normalize(&input, &output) == SIM_POSEMATH_ERR_DEGENERATE);
|
||||
return 0;
|
||||
}
|
||||
25
wasm-core/tests/sim_protocol_test.c
Normal file
25
wasm-core/tests/sim_protocol_test.c
Normal file
@@ -0,0 +1,25 @@
|
||||
#include "sim_protocol.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
||||
int main(void) {
|
||||
sim_protocol_reset();
|
||||
assert(sim_protocol_state_value() == SIM_PROTOCOL_NEW);
|
||||
assert(sim_protocol_accept(1, 1, "HELLO", NULL, 0) == SIM_PROTOCOL_OK);
|
||||
assert(sim_protocol_accept(1, 3, "SESSION_ATTACH", NULL, 0) == SIM_PROTOCOL_ERR_SEQUENCE);
|
||||
assert(sim_protocol_accept(1, 2, "SESSION_ATTACH", NULL, 0) == SIM_PROTOCOL_OK);
|
||||
assert(sim_protocol_state_value() == SIM_PROTOCOL_READY);
|
||||
assert(sim_protocol_accept(1, 3, "MDI_EXECUTE", NULL, 0) == SIM_PROTOCOL_ERR_OPERATION_ID);
|
||||
assert(sim_protocol_accept(1, 3, "MDI_EXECUTE", "op-3", 2) == SIM_PROTOCOL_OK);
|
||||
assert(sim_protocol_accept(1, 4, "PROGRAM_PAUSE", "op-4", 2) == SIM_PROTOCOL_OK);
|
||||
assert(sim_protocol_accept(1, 5, "MDI_EXECUTE", "op-5", 2) == SIM_PROTOCOL_ERR_STATE);
|
||||
assert(sim_protocol_accept(1, 5, "PROGRAM_RESUME", "op-5", 2) == SIM_PROTOCOL_OK);
|
||||
assert(sim_protocol_accept(2, 6, "PING", NULL, 2) == SIM_PROTOCOL_ERR_SCHEMA);
|
||||
assert(sim_protocol_accept(1, 6, "PING", NULL, 1) == SIM_PROTOCOL_ERR_TICK);
|
||||
assert(sim_protocol_accept(1, 6, "DESTROY", NULL, 2) == SIM_PROTOCOL_OK);
|
||||
assert(sim_protocol_accept(1, 7, "PING", NULL, 2) == SIM_PROTOCOL_ERR_STATE);
|
||||
assert(sim_protocol_accept(1, 8, "RESET", "reset-1", 0) == SIM_PROTOCOL_OK);
|
||||
assert(sim_protocol_state_value() == SIM_PROTOCOL_NEW);
|
||||
assert(sim_protocol_set_tick(4) == SIM_PROTOCOL_ERR_TICK);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user