Commit 05718ae2 authored by Miguel Gómez Sexto's avatar Miguel Gómez Sexto Committed by Samuel Iglesias Gonsálvez

Removed unused chan-test.c Renamed test.c to sanity-test.c, and updated the code…

Removed unused chan-test.c Renamed test.c to sanity-test.c, and updated the code to test basic library functionality.
Signed-off-by: Miguel Gómez Sexto's avatarMiguel Gomez <magomez@igalia.com>
Signed-off-by: Samuel Iglesias Gonsálvez's avatarSamuel Iglesias Gonsalvez <siglesias@igalia.com>
parent 6adb71aa
......@@ -6,17 +6,14 @@ LOBJ := libtdc.o
CFLAGS = -Wall -ggdb -I.. -I../lib -I$(ZIO)/include
LDFLAGS = -L../lib/ -ltdc
modules all: lib test test-chan
modules all: lib sanity-test
lib:
$(MAKE) -C ../lib
test:
$(CC) $(CFLAGS) $@.c $(LDFLAGS) -o $@
test-chan:
sanity-test:
$(CC) $(CFLAGS) $@.c $(LDFLAGS) -o $@
clean:
$(MAKE) clean -C ../lib
rm -f *.o *~ test test-chan
rm -f *.o *~ sanity-test
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <inttypes.h>
......@@ -20,8 +21,6 @@ int main(int argc, char **argv)
exit(1);
}
#if 0
/* set/get UTC time */
set = 123;
if (tdc_set_utc_time(b, set))
......@@ -45,7 +44,7 @@ int main(int argc, char **argv)
printf("DAC word functions OK\n");
/* set/get time threshold */
set = 123;
set = 12;
if (tdc_set_time_threshold(b, set))
printf("Error setting time thresh\n");
if (tdc_get_time_threshold(b, &get))
......@@ -56,7 +55,7 @@ int main(int argc, char **argv)
printf("Time threshold functions OK\n");
/* set/get timestamps threshold */
set = 123;
set = 12;
if (tdc_set_timestamp_threshold(b, set))
printf("Error setting timestamps thresh\n");
if (tdc_get_timestamp_threshold(b, &get))
......@@ -66,100 +65,26 @@ int main(int argc, char **argv)
else
printf("Timestamps threshold functions OK\n");
/* set/get channel activation */
tdc_activate_all_channels(b);
set = CHAN0 | CHAN2 | CHAN4;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
if (tdc_get_active_channels(b, &get))
printf("Error getting active channels\n");
if (set != get)
printf("Active channels set and get don't match\n");
else
printf("Channel activation functions OK\n");
/* set/get active channels with general deactivation */
tdc_deactivate_all_channels(b);
set = CHAN0 | CHAN2 | CHAN4;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
if (tdc_get_active_channels(b, &get))
printf("Error getting active channels\n");
if (set != get)
printf("Active channels set and get don't match\n");
else
printf("Channel activation functions OK\n");
/* set/get active channels with general activation change */
tdc_activate_all_channels(b);
/* set/get channel termination */
set = CHAN0 | CHAN2 | CHAN4;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
tdc_deactivate_all_channels(b);
if (tdc_get_active_channels(b, &get))
printf("Error getting active channels\n");
if (tdc_set_channels_term(b, set))
printf("Error setting channels termination\n");
if (tdc_get_channels_term(b, &get))
printf("Error getting channels term\n");
if (set != get)
printf("Active channels set and get don't match\n");
printf("Channels termination set and get don't match\n");
else
printf("Channel activation functions OK\n");
/* set/get active channels with general activation change */
tdc_deactivate_all_channels(b);
set = CHAN0 | CHAN2 | CHAN4;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
tdc_activate_all_channels(b);
if (tdc_get_active_channels(b, &get))
printf("Error getting active channels\n");
if (set != get)
printf("Active channels set and get don't match\n");
else
printf("Channel activation functions OK\n");
/* read from invalid chan */
tdc_activate_all_channels(b);
set = CHAN0;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
res = tdc_read(b, 6, &t, 1, O_NONBLOCK);
if (res == -1 && errno == EINVAL)
printf("Read from invalid chan OK\n");
else
printf("Read from invalid chan wrong\n");
/* read from disabled chan */
tdc_activate_all_channels(b);
set = CHAN0;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
res = tdc_read(b, 1, &t, 1, O_NONBLOCK);
if (res == -1 && errno == EINVAL)
printf("Read from disabled chan OK\n");
else
printf("Read from disabled chan wrong\n");
/* read with all chans disabled */
tdc_deactivate_all_channels(b);
set = CHAN0;
if (tdc_set_active_channels(b, set))
printf("Error setting active channels\n");
res = tdc_read(b, 0, &t, 1, O_NONBLOCK);
if (res == -1 && errno == EINVAL)
printf("Read with disabled chans OK\n");
else
printf("Read with disabled chans wrong\n");
#endif
printf("Channel termination functions OK\n");
/* read from valid chan */
tdc_set_host_utc_time(b);
tdc_activate_channels(b);
tdc_set_channels_term(b, CHAN0);
tdc_set_time_threshold(b, 10);
tdc_set_timestamp_threshold(b, 10);
tdc_set_time_threshold(b, 1);
tdc_set_timestamp_threshold(b, 100);
tdc_start_acquisition(b);
t = tdc_zalloc(1);
for (i = 0; i <100; i++) {
// wait 2 seconds to ensure that there are samples
sleep(2);
for (i = 0; i <10; i++) {
/* this should be a blocking read */
res = tdc_read(b, CHAN0, t, 1, 0);
if (res == 1) {
......@@ -168,7 +93,6 @@ int main(int argc, char **argv)
} else {
printf("Error reading sample\n");
}
// sleep(1);
}
tdc_stop_acquisition(b);
......
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <fcntl.h>
#include <errno.h>
#include <inttypes.h>
#include "libtdc.h"
int main(int argc, char **argv)
{
struct tdc_board *b;
struct tdc_time t;
int res;
int i;
unsigned int chan, time_thres, tstamp_thres;
if (argc != 4){
fprintf(stderr, "Usage: %s <chan> <time_threshold> <tstamp_threshold>\n", argv[0]);
fprintf(stderr, "\t<chan>: from 0 to 4.\n");
fprintf(stderr, "\t<time_threshold>: from 0 to 4294967295 seconds.\n");
fprintf(stderr, "\t<tstamp_threshold>: from 0 to 255 timestamps.\n");
fflush(NULL);
exit(1);
}
switch (atoi(argv[1])) {
case 0:
chan = CHAN0;
break;
case 1:
chan = CHAN1;
break;
case 2:
chan = CHAN2;
break;
case 3:
chan = CHAN3;
break;
case 4:
chan = CHAN4;
break;
default:
fprintf(stderr, "Invalid chan number %d. Valid values from 0 to 4\n", atoi(argv[1]));
fflush(NULL);
exit(1);
}
time_thres = atoi(argv[2]);
tstamp_thres = atoi(argv[3]);
if(tstamp_thres > 255) {
fprintf(stderr, "Invalid timestamp threshold number %d. Valid values from 0 to 255\n", tstamp_thres);
fflush(NULL);
exit(1);
}
b = tdc_open(1);
if (!b) {
printf("Unable to open device with lun 1\n");
fflush(NULL);
exit(1);
}
/* read from valid chan */
tdc_set_host_utc_time(b);
tdc_activate_channels(b);
tdc_set_channels_term(b, chan);
tdc_set_time_threshold(b, time_thres);
tdc_set_timestamp_threshold(b, tstamp_thres);
tdc_start_acquisition(b);
for (i = 0; i <10000; i++) {
/* this should be a blocking read */
res = tdc_read(b, chan, &t, 1, 0);
if (res == 1) {
printf("Got sample chan [%d]: utc %"PRIu64" ticks %"PRIu64" bins %"PRIu64" dacapo %i\n",
atoi(argv[1]), t.utc, t.ticks, t.bins, t.da_capo);
} else {
printf("Error reading sample\n");
}
// sleep(1);
}
tdc_stop_acquisition(b);
tdc_close(b);
return 0;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment