Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fiotest Improvements #26

Open
wants to merge 2 commits into
base: nextfio
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
178 changes: 153 additions & 25 deletions fio/src/fiotest/fioapi_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ void print_io(unsigned char *outputs, unsigned char *inputs, int len)
{
static unsigned char last_outputs[128];

printf("Output pattern:");
printf("Out:");
int ones = 0, flips = 0;
for (int i=0; i<len; i++) {
for(int j=0; j<8; j++) {
Expand All @@ -81,24 +81,38 @@ void print_io(unsigned char *outputs, unsigned char *inputs, int len)
flips++;
}
last_outputs[i] = outputs[i];
printf(" %02x", outputs[i]);
printf("%02x", outputs[i]);
}
printf("[%d][%d]\n", ones, flips);
printf("Input pattern :");
//printf("[%d][%d]\n", ones, flips);
printf("\nIn :");
for (int i=0; i<len; i++) {
printf(" %02x", inputs[i]);
printf("%02x", inputs[i]);
}
printf("\n");
}

FIO_APP_HANDLE fio_handle;
FIO_DEV_HANDLE dev_handle;

void wait_for_frame(unsigned int frame_num)
{
//usleep(200000);
fio_signal = false;
fio_fiod_frame_notify_register(fio_handle, dev_handle, frame_num, FIO_NOTIFY_ONCE);
// Wait for next input frame response (notification signal?)
sleep(1);
if(fio_signal == false) {
// Error no response frame after timeout
printf("Response frame %d notification timeout occurred\n", frame_num);
}
}

int loop_test(FIO_DEVICE_TYPE type, unsigned char *outputs_plus, int len)
{
unsigned char outputs_minus[FIO_INPUT_POINTS_BYTES] = {0};
unsigned char inputs[FIO_INPUT_POINTS_BYTES] = {0};
struct timespec to_sleep = { .tv_sec = 0, .tv_nsec = 200000000 };
fio_hm_heartbeat(fio_handle);
int bitpos = 0;

if (type == FIOTS1) {
// Fix quirks in TS1 loopback cable
Expand All @@ -107,35 +121,130 @@ int loop_test(FIO_DEVICE_TYPE type, unsigned char *outputs_plus, int len)
outputs_plus[14] = outputs_plus[12] & 0x3f;
}

fio_fiod_outputs_set(fio_handle, dev_handle, outputs_plus, outputs_minus, FIO_OUTPUT_POINTS_BYTES);
fio_signal = false;
nanosleep(&to_sleep, NULL);
fio_fiod_frame_notify_register(fio_handle, dev_handle, 180, FIO_NOTIFY_ONCE);
// Wait for next input frame response (notification signal?)
sleep(1);
if(fio_signal == false) {
// Error no response frame after timeout
printf("Response frame notification timeout occurred\n");
}
fio_fiod_outputs_set(fio_handle, dev_handle, outputs_plus, outputs_minus, FIO_INPUT_POINTS_BYTES);
wait_for_frame(180);
fio_fiod_inputs_get(fio_handle, dev_handle, FIO_INPUTS_RAW, inputs, sizeof(inputs));
if (type == FIOTS1)
// Fix quirks in TS1 loopback cable
inputs[14] &= 0x3f;

for (int j=0; j<len; j++) {
if (inputs[j] != outputs_plus[j]) {
for (int i=0; i<len; i++) {
if (inputs[i] != outputs_plus[i]) {
// Test failed
if (!quiet_log)
if (!quiet_log) {
print_io(outputs_plus, inputs, len);
return -1;
}
bitpos = outputs_plus[i];
for(int j=0; j<8; j++) {
if (bitpos & (1<<j)) {
return j+1;
}
}
}
}
if (verbose_log)
//if (verbose_log)
print_io(outputs_plus, inputs, len);
printf("\x1b[2A");

return 0;
}

int transbuf_test(FIO_DEVICE_TYPE type, int count)
{
unsigned char outputs_plus[FIO_INPUT_POINTS_BYTES];
unsigned char outputs_minus[FIO_INPUT_POINTS_BYTES] = {0};
FIO_TRANS_BUFFER trans_buf[1024];
FIO_TRANS_STATUS status;
int trans_count = count;
int number_of_input_bytes = (type == FIO332)?8:FIO_INPUT_POINTS_BYTES;
fio_hm_heartbeat(fio_handle);
int ret = 0;
printf("creating %d transitions... \n", count);

// configure inputs for transition reporting
unsigned char transitions[FIO_INPUT_POINTS_BYTES];
for (int iter=0; iter<number_of_input_bytes; iter++) {
transitions[iter] = 0xff;
}
fio_fiod_inputs_trans_set(fio_handle, dev_handle, transitions, number_of_input_bytes);

// schedule transition buffer poll frame 54
FIO_FRAME_SCHD frame_schedule;
frame_schedule.frequency = FIO_HZ_10;
frame_schedule.req_frame = 54;
if (fio_fiod_frame_schedule_set(fio_handle, dev_handle, &frame_schedule, 1) != 0) {
printf("Error setting frame 54 schedule\n");
ret = -1;
goto cleanup;
}

// flush transitions fifo
memset(outputs_plus, 0, sizeof outputs_plus);
fio_fiod_outputs_set(fio_handle, dev_handle, outputs_plus, outputs_minus, sizeof outputs_plus);
wait_for_frame(183);
wait_for_frame(182);
while ((fio_fiod_inputs_trans_read(fio_handle, dev_handle, &status, trans_buf, 1024)) > 0) {
wait_for_frame(182);
};

// Send frame 50 to reset the ms counter to zero
unsigned char zero[4] = { 0x00, 0x00, 0x00, 0x00 };
fio_fiod_frame_write(fio_handle, dev_handle, 50, zero, 4);
wait_for_frame(178);

// Generate transitions
while (trans_count) {
if (count/128 > 0) {
for (int j=0; j<8; j++) {
outputs_plus[j] = 0xff;
}
fio_fiod_outputs_set(fio_handle, dev_handle, outputs_plus, outputs_minus, sizeof outputs_plus);
wait_for_frame(183);
memset(outputs_plus, 0, sizeof outputs_plus);
fio_fiod_outputs_set(fio_handle, dev_handle, outputs_plus, outputs_minus, sizeof outputs_plus);
wait_for_frame(183);
trans_count = trans_count - 128;
} else {
for (int j=0; j<(trans_count/2)+1; j++) {
FIO_BIT_SET(outputs_plus, j);
}
fio_fiod_outputs_set(fio_handle, dev_handle, outputs_plus, outputs_minus, sizeof outputs_plus);
wait_for_frame(183);
memset(outputs_plus, 0, sizeof outputs_plus);
fio_fiod_outputs_set(fio_handle, dev_handle, outputs_plus, outputs_minus, sizeof outputs_plus);
wait_for_frame(183);
trans_count = 0;
}
}
// Process new transitions
wait_for_frame(182);
wait_for_frame(182);
if ((trans_count = fio_fiod_inputs_trans_read(fio_handle, dev_handle, &status, trans_buf, 1024)) > 0) {
if ((trans_count < count) || (status != FIO_TRANS_SUCCESS)) {
if (count <= 1024) {
printf("Error in trans count:exp %d act %d\n", count, trans_count);
ret = -1;
}
printf("Status %d rcvd for trans count %d\n", status, trans_count);
}
printf("read %d transitions from buffer\n", trans_count);
} else {
printf("Error reading transitions: ret=%d\n", trans_count);
ret = -1;
}

cleanup:
// disable input transition reporting
for (int iter=0; iter<number_of_input_bytes; iter++) {
transitions[iter] = 0x00;
}
fio_fiod_inputs_trans_set(fio_handle, dev_handle, transitions, number_of_input_bytes);
wait_for_frame(179);
//wait_for_frame(179);

return ret;
}

int main(int argc, char **argv)
{
unsigned char output_map[FIO_OUTPUT_POINTS_BYTES];
Expand Down Expand Up @@ -229,19 +338,19 @@ int main(int argc, char **argv)
// Enable this FIO module
fio_fiod_enable(fio_handle, dev_handle);
// Perform "walking 1" bit pattern test
printf("walking 1 bit test...\n");
printf("walking 1 bit test... \n");
for (int iter = 0; iter<number_of_input_bytes; iter++) {
memset(outputs_plus, 0, sizeof outputs_plus);
for(int j=0; j<8; j++) {
outputs_plus[iter] = (1<<j);
if (loop_test(fio_dev_type, outputs_plus, number_of_input_bytes) != 0) {
printf("Error after %d iterations\n", iter+1);
if ((err = loop_test(fio_dev_type, outputs_plus, number_of_input_bytes)) != 0) {
printf("Error I/O byte-bit %d-%d\n", iter+1, err);
goto error_dereg;
}
}
}
// Perform muliple bit pattern test
printf("random multiple bits test...\n");
printf("random multiple bits test... \n");
for (int iter=0; iter<100; iter++) {
// Obtain a random bit pattern for outputs of length (8*FIO_OUTPUT_POINTS_BYTES)
//getrandom(outputs_plus, sizeof outputs_plus, 0);
Expand All @@ -258,7 +367,26 @@ int main(int argc, char **argv)
goto error_dereg;
}
}

// Perform transition buffer test
// (The384Test, The640Test, The1152Test, The1276Test, OutputBitTest, TheTBGBitTest)
printf("transition buffer tests... \n");
if (transbuf_test(fio_dev_type, 384) != 0) {
printf("Error: failed 384 transition test\n");
goto error_dereg;
}

if (transbuf_test(fio_dev_type, 640) != 0) {
printf("Error: failed 640 transition test\n");
goto error_dereg;
}

if (transbuf_test(fio_dev_type, 1152) != 0) {

printf("Error: failed 1152 transition test\n");
goto error_dereg;
}

printf("Test Passed\n");
fio_fiod_disable(fio_handle, dev_handle);
fio_fiod_deregister(fio_handle, dev_handle);
Expand Down