From bced02de6be98a1d2551e31629d02990ea8d4923 Mon Sep 17 00:00:00 2001 From: Priest <priest> Date: Mon, 24 Oct 2016 07:49:17 +0000 Subject: [PATCH] Initial commit --- .../tb/python/stress_test.py | 237 ++++++++++++++++++ 1 file changed, 237 insertions(+) create mode 100644 applications/compaan/designs/compaan_io_test_fn/tb/python/stress_test.py diff --git a/applications/compaan/designs/compaan_io_test_fn/tb/python/stress_test.py b/applications/compaan/designs/compaan_io_test_fn/tb/python/stress_test.py new file mode 100644 index 0000000000..1036ffdbc2 --- /dev/null +++ b/applications/compaan/designs/compaan_io_test_fn/tb/python/stress_test.py @@ -0,0 +1,237 @@ +#! /usr/bin/env python +############################################################################### +# +# Copyright (dC) 2015 +# ASTRON (Netherlands Institute for Radio Astronomy) <http://www.astron.nl/> +# P.O.Box 2, 7990 AA Dwingeloo, The Netherlands +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. +# +############################################################################### + +# Purpose: +# . Test Compaan's capability to send data to a terminal + + +from common import * +from random import randint +import sys +import threading +import test_case +import node_io +import pi_diag_block_gen +import pi_diag_data_buffer +import pi_dp_offload_tx_hdr_dat_compaan_unb1_10g_terminal +import pi_eth +import pi_compaan +from eth import * + +################################################################################ +## Constants and variables +################################################################################ +# System definitions +c_10g_data_w = 32 # <= 32 for terminal +c_blocksize = 8 # = frame_len +c_nof_blocks_per_sync = 200000 + +# Block gen definitions +c_bg_ram_size = 512 +c_bg_nof_streams = 1 +c_bg_gap_size = 3000 +c_write_block_gen = True + +# UDP header definitions +eth_src_mac = 0x2286080008 # 10G MAC base address for UniBoard +eth_dst_mac = 0x074306C700 #0x00074306C700 # 10G MAC address DOP36 +ip_src_addr_fn0 = 0xc0a80164 # 0xc0a80164 = 192.168.1.100 +ip_src_addr_fn1 = 0xc0a80165 # 0xc0a80165 = 192.168.1.101 +ip_src_addr_fn2 = 0xc0a80166 # 0xc0a80164 = 192.168.1.102 +ip_src_addr_fn3 = 0xc0a80167 # 0xc0a80165 = 192.168.1.103 +ip_dst_addr = 0xc0a80102 # 0xc0a80102 = 192.168.1.2 = IP-address 10G in DOP36 + +genLock = threading.Lock() +checkLock = threading.Lock() + +# Instantiate testcase and IO +tc = test_case.Testcase('TB -', '') +io = node_io.NodeIO(tc.nodeImages, tc.base_ip) + +# Instantiate compaan +ca = pi_compaan.PiCompaan(tc, io, nof_inst=1) + +# Create block generator/data buffer instance +bg = pi_diag_block_gen.PiDiagBlockGen(tc, io, c_bg_nof_streams, c_bg_ram_size, tc.nodeFn1Nrs ) +db = pi_diag_data_buffer.PiDiagDataBuffer(tc, io, instanceName = '', nofStreams=c_bg_nof_streams, ramSizePerStream=2048, nodeNr = tc.nodeBn0Nrs ) #nodeFn1Nrs + +# Create dp_offload_tx instance +dpotx_hdr_dat = pi_dp_offload_tx_hdr_dat_compaan_unb1_10g_terminal.PiDpOffloadTxHdrDatCompaanUnb110GTerminal(tc, io, nof_inst=1) + +############################################################################### +# Calculate and print the IP header checksum for FN0 +############################################################################### +# Fixed header constants +IP_HEADER_LENGTH = 20 +UDP_HEADER_LENGTH = 8 +USR_HEADER_LENGTH = 20 +USR_HDR_WORD_ALIGN = 2 +NOF_PAYLOAD_BYTES = c_blocksize * 8 + +ip_version = 4 +ip_header_length = 5 # 5 32b words +ip_services = 0 +ip_total_length = IP_HEADER_LENGTH+UDP_HEADER_LENGTH+USR_HEADER_LENGTH+USR_HDR_WORD_ALIGN+NOF_PAYLOAD_BYTES - 7 # 6196B +ip_identification = 0 +ip_flags = 2 +ip_fragment_offset = 0 +ip_time_to_live = 127 +ip_protocol = 17 +ip_header_checksum = 0 # to be calculated +hdr_bits_common = CommonBits(ip_version ,4) & \ + CommonBits(ip_header_length ,4) & \ + CommonBits(ip_services ,8) & \ + CommonBits(ip_total_length ,16) & \ + CommonBits(ip_identification ,16) & \ + CommonBits(ip_flags ,3) & \ + CommonBits(ip_fragment_offset ,13) & \ + CommonBits(ip_time_to_live ,8) & \ + CommonBits(ip_protocol ,8) & \ + CommonBits(ip_header_checksum ,16) + +hdr_bits_fn0 = hdr_bits_common & \ + CommonBits(ip_src_addr_fn0 ,32) & \ + CommonBits(ip_dst_addr ,32) + +hdr_bits_fn1 = hdr_bits_common & \ + CommonBits(ip_src_addr_fn1 ,32) & \ + CommonBits(ip_dst_addr ,32) + +hdr_bits_fn2 = hdr_bits_common & \ + CommonBits(ip_src_addr_fn2 ,32) & \ + CommonBits(ip_dst_addr ,32) + +hdr_bits_fn3 = hdr_bits_common & \ + CommonBits(ip_src_addr_fn3 ,32) & \ + CommonBits(ip_dst_addr ,32) + +hdr_bytes_fn0 = CommonBytes(hdr_bits_fn0.data, IP_HEADER_LENGTH) +hdr_bytes_fn1 = CommonBytes(hdr_bits_fn1.data, IP_HEADER_LENGTH) +hdr_bytes_fn2 = CommonBytes(hdr_bits_fn2.data, IP_HEADER_LENGTH) +hdr_bytes_fn3 = CommonBytes(hdr_bits_fn3.data, IP_HEADER_LENGTH) + +tc.append_log(3, 'IP header checksum FN0: %d' % ip_hdr_checksum(hdr_bytes_fn0)) +tc.append_log(3, 'IP header checksum FN1: %d' % ip_hdr_checksum(hdr_bytes_fn1)) +tc.append_log(3, 'IP header checksum FN2: %d' % ip_hdr_checksum(hdr_bytes_fn2)) +tc.append_log(3, 'IP header checksum FN3: %d' % ip_hdr_checksum(hdr_bytes_fn3)) + +################################################################################ +## Write settings +################################################################################ +tc.append_log(3, 'Setting DPOTX for node FN0') + +dpotx_hdr_dat.write(node_nrs=tc.nodeFn0Nrs, inst_nrs=tc.gpNumbers, registers=[('eth_src_mac', eth_src_mac + 0)], regmap=dpotx_hdr_dat.regmap) +dpotx_hdr_dat.write(node_nrs=tc.nodeFn0Nrs, inst_nrs=tc.gpNumbers, registers=[('eth_dst_mac', eth_dst_mac)], regmap=dpotx_hdr_dat.regmap) +dpotx_hdr_dat.write(node_nrs=tc.nodeFn0Nrs, inst_nrs=tc.gpNumbers, registers=[('ip_src_addr', ip_src_addr_fn0)], regmap=dpotx_hdr_dat.regmap) +dpotx_hdr_dat.write(node_nrs=tc.nodeFn0Nrs, inst_nrs=tc.gpNumbers, registers=[('ip_dst_addr', ip_dst_addr)], regmap=dpotx_hdr_dat.regmap) +dpotx_hdr_dat.write(node_nrs=tc.nodeFn0Nrs, inst_nrs=tc.gpNumbers, registers=[('ip_header_checksum', ip_hdr_checksum(hdr_bytes_fn0))], regmap=dpotx_hdr_dat.regmap) + +dpotx_hdr_dat.read(node_nrs=tc.nodeFn0Nrs, inst_nrs=tc.gpNumbers, regmap=dpotx_hdr_dat.regmap) + +tc.append_log(3, 'Setting BG for node BN0') +bg.write_block_gen_settings(samplesPerPacket=c_blocksize, blocksPerSync=c_nof_blocks_per_sync, gapSize=c_bg_gap_size, memLowAddr=0, memHighAddr=c_bg_ram_size-1, BSNInit=10) +bg.read_block_gen_settings() +############################################################################### +## Data generator thread class +############################################################################### +class Generator(threading.Thread): + def __init__(self, lock, amount = 0, low = 1, high = 1000): + threading.Thread.__init__(self) + self.amount = amount + self.low = low + self.high = high + self.lock = lock + self.dataArr = [] + def generate(self): + with self.lock: + #print('Acquired lock') + self.dataArr = [] + for i in range(self.amount): + self.dataArr.append(randint(self.low, self.high)) + +class Checker(threading.Thread): + def __init__(self, lock): + threading.Thread.__init__(self) + self.lock = lock + self.dataArr = [] + self.checkArr = [] + # Set array as reference for checking + def setCheck(self, checkArr): + self.checkArr = checkArr + # Set array to check on and strip 0's + def setDataAndStrip(self, dataArr): + self.dataArr = filter(lambda a: a != 0, dataArr) + # Check with earlier given arrays + def check(self): + for i in range(len(self.checkArr)): + if(self.dataArr[i] != self.checkArr[i]*2): + self.doNothing = True + #tc.set_result("FAILED") + #sys.exit("{} != {} *2".format(self.dataArr[i], self.checkArr[i])) + +################################################################################ +## Write data to the block generator +################################################################################ +# Define threads +gen_t = Generator(genLock, c_bg_ram_size/2) +che_t = Checker(checkLock) +# Start threads +gen_t.start() +che_t.start() +# Generate initial data +gen_t.generate() + +# Start by reading the current data in the databuffer to enable overwriting it +#read_e = [] +#for i in range(1): +# read_e.append(flatten(db.read_data_buffer(streamNr=i, n=2048, radix='uns', width=c_10g_data_w, nofColumns=16))) + +while True: + # Wait for the data to be generated + gen_t.join() + # Copy the data so a new set can be generated in the meantime + dataArr = gen_t.dataArr + # Set as check array for Checker() + che_t.setCheck(gen_t.dataArr) + # Generate a new set of data in the background for next iteration + gen_t.generate() + + # Send data to the block_gen + print('Sending data:') + print(dataArr) + for i in range(c_bg_nof_streams): + bg.write_waveform_ram(data=dataArr, channelNr=i) + bg.write_enable() + + do_until_ge(db.read_nof_words, ms_retry=1000, val=1024, s_timeout=3600) + + # Clear and refill db_out + db_out = [] + for i in range(1): + db_out.append(flatten(db.read_data_buffer(streamNr=i, n=2048, radix='uns', width=c_10g_data_w, nofColumns=16))) + + che_t.setDataAndStrip(db_out[0]) + che_t.check() + + #print db_out + + #repeat \ No newline at end of file -- GitLab