diff options
author | Suren A. Chilingaryan <csa@suren.me> | 2013-11-25 21:13:53 +0100 |
---|---|---|
committer | Suren A. Chilingaryan <csa@suren.me> | 2013-11-25 21:13:53 +0100 |
commit | ba90c7c942f39b83986e4ed899def33ce79e2f1d (patch) | |
tree | 155b0762262642f8caa83019efd6fc1f8d7f36f9 | |
parent | ba1ef9d055cbb94cd06c92709546174047f02a15 (diff) | |
download | ipecamera-ba90c7c942f39b83986e4ed899def33ce79e2f1d.tar.gz ipecamera-ba90c7c942f39b83986e4ed899def33ce79e2f1d.tar.bz2 ipecamera-ba90c7c942f39b83986e4ed899def33ce79e2f1d.tar.xz ipecamera-ba90c7c942f39b83986e4ed899def33ce79e2f1d.zip |
Some tests are added
-rw-r--r-- | .bzrignore | 4 | ||||
-rw-r--r-- | apps/CMakeLists.txt | 5 | ||||
-rw-r--r-- | apps/compare_to_value.c | 65 | ||||
-rw-r--r-- | apps/pio_test.c | 96 | ||||
-rwxr-xr-x | tests/loopback-test.sh | 71 | ||||
-rwxr-xr-x | tests/run-and-decode-test.sh | 78 |
6 files changed, 319 insertions, 0 deletions
@@ -19,3 +19,7 @@ Makefile *.so.* install_manifest.txt ./xilinx +apps/pio_test +apps/compare_to_value +*.out +apps/xilinx diff --git a/apps/CMakeLists.txt b/apps/CMakeLists.txt index 2f882a3..b3ce318 100644 --- a/apps/CMakeLists.txt +++ b/apps/CMakeLists.txt @@ -6,3 +6,8 @@ link_directories(${UFODECODE_LIBRARY_DIRS}) add_executable(xilinx xilinx.c) target_link_libraries(xilinx pcilib rt) + +add_executable(pio_test pio_test.c) +target_link_libraries(pio_test pcilib rt) + +add_executable(compare_to_value compare_to_value.c) diff --git a/apps/compare_to_value.c b/apps/compare_to_value.c new file mode 100644 index 0000000..b6df9c0 --- /dev/null +++ b/apps/compare_to_value.c @@ -0,0 +1,65 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> + +int main(int argc, char *argv[]) { + long i, j, size, num; + size_t count = 0, total = 0; + int offset = 0, toread = 1, toskip = 0; + uint32_t value; + uint32_t *buf; + + if ((argc != 4)&&(argc != 7)) { + printf("Usage: %s <file> <dwords> <value> [offset_dwords read_dwords skip_dwords] \n", argv[0]); + exit(0); + } + + FILE *f = fopen(argv[1], "r"); + if (!f) { + printf("Can't open %s\n", argv[1]); + exit(1); + } + + size = atol(argv[2]); + if (size <= 0) { + printf("Can't parse size %s\n", argv[2]); + exit(1); + } + + if (sscanf(argv[3], "%x", &value) != 1) { + printf("Can't parse register %s\n", argv[3]); + exit(1); + } + + buf = malloc(size * sizeof(uint32_t)); + if (!buf) { + printf("Can't allocate %lu bytes of memory\n", size * sizeof(uint32_t)); + exit(1); + } + + if (argc == 7) { + offset = atoi(argv[4]); + toread = atoi(argv[5]); + toskip = atoi(argv[6]); + } + + + num = fread(buf, 4, size, f); + if (num != size) { + printf("Only %lu of %lu dwords in the file\n", num, size); + } + fclose(f); + + for (i = offset; i < size; i += toskip) { + for (j = 0; j < toread; j++, i++) { + total++; + if (buf[i] != value) { + count++; + } + } + } + free(buf); + + printf("%lu of %lu is wrong\n", count, total); + +} diff --git a/apps/pio_test.c b/apps/pio_test.c new file mode 100644 index 0000000..7eca362 --- /dev/null +++ b/apps/pio_test.c @@ -0,0 +1,96 @@ +#define _BSD_SOURCE +#define _POSIX_C_SOURCE 199309L +#include <stdio.h> +#include <stdlib.h> +#include <unistd.h> +#include <stdarg.h> +#include <time.h> +#include <sched.h> +#include <sys/time.h> + +#include "pcilib.h" +#include "irq.h" +#include "kmem.h" + +#define DEVICE "/dev/fpga0" +//#define REALTIME + +#define BAR PCILIB_BAR0 +#define BITS 16 +#define MASK ((1ll << BITS) - 1) + + +#define WR(addr, value) { *(uint32_t*)(bar + addr) = value; } +#define RD(addr, value) { value = *(uint32_t*)(bar + addr); } + +unsigned long long bits[BITS]; + +int main(int argc, char *argv[]) { + uint32_t i, j; + pcilib_t *pci; + uint32_t reg, value, diff, errors; + void* volatile bar; + + unsigned long long attempts = 0, failures = 0; + + if (argc < 2) { + printf("Usage: %s <register>\n", argv[0]); + exit(0); + } + + if (sscanf(argv[1], "%x", ®) != 1) { + printf("Can't parse register %s\n", argv[1]); + exit(1); + } + +#ifdef REALTIME + pid_t pid; + struct sched_param sched = {0}; + + pid = getpid(); + sched.sched_priority = sched_get_priority_min(SCHED_FIFO); + if (sched_setscheduler(pid, SCHED_FIFO, &sched)) + printf("Warning: not able to get real-time priority\n"); +#endif /* REALTIME */ + + pci = pcilib_open(DEVICE, PCILIB_MODEL_DETECT); + if (!pci) { + printf("pcilib_open\n"); + exit(1); + } + + bar = pcilib_map_bar(pci, BAR); + if (!bar) { + pcilib_close(pci); + printf("map bar\n"); + exit(1); + } + + for (i = 0; 1; i++) { + WR(reg, (i%MASK)); + RD(reg, value); + + attempts++; + if (value != (i%MASK)) { + failures++; + + diff = value ^ (i%MASK); + for (errors = 0, j = 0; j < BITS; j++) + if (diff&(1<<j)) errors++; + bits[errors]++; + + //printf("written: %x, read: %x\n", i, value); + } + + if ((i % 1048576 ) == 0) { + printf("Attempts %llu, failures %llu (", attempts, failures); + for (j = 1; j < BITS; j++) + printf("%llu ", bits[j]); + printf(")\n"); + } + + } + + pcilib_unmap_bar(pci, BAR, bar); + pcilib_close(pci); +} diff --git a/tests/loopback-test.sh b/tests/loopback-test.sh new file mode 100755 index 0000000..7ae03a4 --- /dev/null +++ b/tests/loopback-test.sh @@ -0,0 +1,71 @@ +#! /bin/bash + +TESTS_PATH="`dirname \"$0\"`" +TESTS_PATH="`( cd \"$TESTS_PATH\" && pwd )`" + +function pci { + PCILIB_PATH=$TESTS_PATH/.. + LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $* +} + +function compare { + PCILIB_PATH=$TESTS_PATH/.. + LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/apps/compare_to_value $* +} + +#size=`expr 1024 "*" 1024` +size=`expr 1024 "*" 1` +multiplier=2 +wait=0 + +/root/pcitool/tests/frame.sh &> /dev/null +rm -f bench.out + +pci --stop-dma dma1 +pci --start-dma dma1 + +pci -r dma1 -s 16777216 --multipacket -o /dev/null &> /dev/null + +pci -r dma1 -s 1024 -o /dev/null | grep -i "Error (62)" &> /dev/null +if [ $? -ne 0 ]; then + echo "There is data on dma..." + exit +fi + +failed=0 +send=0 +errors=0 + +read_size=`expr $multiplier '*' $size` +echo "Starting..." +i=1 +pci -w 0x9040 0x201 +while [ 1 ]; do + pci -w dma1 -s $size "*0x$i" + rm -f /tmp/camera-test.out + pci -r dma1 --multipacket -s $read_size -o /tmp/camera-test.out &> /dev/null + if [ $wait -gt 0 ]; then + wrdone=0 + while [ $wrdone -eq 0 ]; do + pci --list-dma-engines + pci --list-dma-engines | grep "DMA1 S2C" | grep "SD" #&> /dev/null + wrdone=$? + done + fi + + res=`compare /tmp/camera-test.out $read_size "$i" 6 2 6` + if [ $? -eq 0 ]; then + err_cnt=`echo $res | cut -f 1 -d ' '` + byte_cnt=`echo $res | cut -f 3 -d ' '` + send=$(($send + $byte_cnt * 4)) + errors=$(($errors + $err_cnt * 4)) + else + failed=$(($failed + 1)) + fi + + i=$((i + 1)) + if [ $i -eq 100 ]; then + echo "Data send: $send bytes, Errors: $errors bytes, Failed exchanges: $failed" + i=1 + fi +done diff --git a/tests/run-and-decode-test.sh b/tests/run-and-decode-test.sh new file mode 100755 index 0000000..c021c2d --- /dev/null +++ b/tests/run-and-decode-test.sh @@ -0,0 +1,78 @@ +#! /bin/bash + +#location=/mnt/fast/ +location="./" +duration=10000000 +wait_frame=1000000 + +TESTS_PATH="`dirname \"$0\"`" +TESTS_PATH="`( cd \"$TESTS_PATH\" && pwd )`" + +function pci { + PCILIB_PATH=$TESTS_PATH/.. + LD_LIBRARY_PATH="$PCILIB_PATH" $PCILIB_PATH/pci $* +} + +function stop { + usleep $duration + pci -w control 0x201 &> /dev/null +} + +/root/pcitool/tests/frame.sh &> /dev/null +rm -f bench.out + +pci --stop-dma +pci --start-dma dma1 + + +pci -r dma1 -s 16777216 --multipacket -o /dev/null &> /dev/null + +pci -r dma1 -s 1 | grep -i "Error (62)" &> /dev/null +if [ $? -ne 0 ]; then + echo "There is data on dma..." + exit +fi + +echo "Starting ... " + +decode_failures=0 +failures=0 +failed=0 +frames=0 + +iter=0 +while [ 1 ]; do + pci -w control 0xa01 &> /dev/null + stop & + + output="$location/test$iter.out" + rm -f $output + pci -r dma1 -o $output --wait --multipacket -t $wait_frame &> /dev/null + + killall -9 usleep &> /dev/null + usleep 100000 + pci -w control 0x201 &> /dev/null + + if [ -f $output ]; then + result=`ipedec -d -v --continue $output 2>&1 | grep -iE "failed|decoded"` + cur_failed=`echo $result | wc -l` + cur_decoded=`echo $result | tail -n 1 | grep -i decoded` + if [ $? -ne 0 -o $cur_failed -eq 0 ]; then + ipedec -d -v --continue $output > $output.decode + decode_failures=$(($decode_failures + 1)) + else + cur_failed=$(($cur_failed - 1)) + cur_frames=`echo $cur_decoded | cut -f 2 -d ' '` + failed=$(($failed + $cur_failed)) + frames=$(($frames + $cur_frames)) + if [ $cur_failed -eq 0 ]; then + rm -f $output + fi + fi + else + failures=$(($failures + 1)) + fi + + echo "Frames: $frames, Failed Frames: $failed, Failed Exchanges: $failures, Failed Decodings: $decode_failures" + iter=`expr $iter + 1` +done |