Initial commit

This commit is contained in:
Johannes Kutning
2023-10-31 07:47:27 +01:00
commit 0d1b73e3e0
255 changed files with 16057 additions and 0 deletions
+15
View File
@@ -0,0 +1,15 @@
#!/bin/bash
script_dir=$(cd $(dirname "${BASH_SOURCE[0]}") && pwd)
if [ $# -ne 1 ]
then
echo Usage $0 test-output-file
exit 1
fi
cat $1 | sed -z -e 's/\(py_.* \[\)/ \[/g' | ${script_dir}/highlight_test_results.sh
if grep -q FAIL $1
then
exit 1
fi
+61
View File
@@ -0,0 +1,61 @@
#!/usr/bin/env python3
import os
import sys
import pathlib
from importlib.machinery import SourceFileLoader
def get_test_and_filename( extension ):
filename = sys.argv[ 1 ].replace( '.py', extension )
testname = os.path.basename( sys.argv[ 1 ].replace( '.py', '' ) )
return testname, filename
def convert_to_c( data ):
testname, filename = get_test_and_filename( '.h' )
with open( filename, 'w' ) as f:
f.write( '#pragma once\n' )
f.write( 'float expected_' + testname +'[] = {' )
f.write( '{:e}'.format( data[ 0 ] ) )
for i in data[ 1 : ]:
f.write( ',{:e}'.format( i ) )
f.write( '};\n' )
def convert_to_vhdl( data ):
testname, filename = get_test_and_filename( '.vhd' )
with open( filename, 'w' ) as f:
f.write( 'library ieee;\n' )
f.write( ' use ieee.std_logic_1164.all;\n' )
f.write( '\n' )
f.write( 'library work;\n' )
f.write( ' use work.test_utility.all;\n' )
f.write( '\n' )
f.write( 'package ' + testname + '_data is\n' )
f.write( ' constant expected : real_array( 0 to 1023 ) := (' )
f.write( '{:e}'.format( data[ 0 ] ) )
for i in data[ 1 : ]:
f.write( ',{:e}'.format( i ) )
f.write( ');\n' )
f.write( 'end package ' + testname + '_data;\n' )
def convert():
if ( len( sys.argv ) != 2 ):
raise( Exception( "Usage: {} expected_data.py" ) )
cwd = pathlib.Path( os.getcwd() )
expected_path = cwd.joinpath( sys.argv[ 1 ] )
expected = SourceFileLoader( 'expected', str( expected_path ) ).load_module()
convert_to_c( expected.data )
convert_to_vhdl( expected.data )
def main():
try:
convert()
except Exception as e:
print( e )
if ( __name__ == '__main__' ):
main()
+14
View File
@@ -0,0 +1,14 @@
#!/bin/bash
script_path="$( dirname "$( readlink -f "${BASH_SOURCE[0]}" )" )"
if [ $# -lt 1 ]
then
echo " usage: execute_and_highlight command arguments"
exit 1
fi
cmd=$1
shift 1
$cmd $@ | $script_path/highlight_test_results.sh
test ${PIPESTATUS[0]} -eq 0
+32
View File
@@ -0,0 +1,32 @@
#/bin/bash
if [ $# -ne 2 ]
then
echo Usage $0 elf-file output-file
exit 1
fi
echo -n Loading $1 to device ...
nios2-download -g $1 > /dev/null
err=$?
if [ ${err} -ne 0 ]
then
echo " [ FAIL ]"
exit ${err}
fi
echo " [ OK ]"
echo -n Reading outputs from device via nios2-terminal ...
nios2-terminal -q > $2 &
terminal_pid=$!
kill -CONT ${terminal_pid}
while ! tail -n1 $2 | grep "test done" > /dev/null
do
true
done
kill ${terminal_pid}
echo " [ OK ]"
+21
View File
@@ -0,0 +1,21 @@
#!/bin/bash
if [ $# -ne 1 ]
then
echo " usage: execute_submake subfolder [ FAIL ]"
exit 1
fi
submake=$1
make -C $submake > /dev/null
err=$?
if [ $err -ne 0 ]
then
echo " [ FAIL ]"
exit $err
fi
echo " [ OK ]"
+3
View File
@@ -0,0 +1,3 @@
#!/bin/bash
grep -e "^py_.*" | sed -e 's/py_//g'
+7
View File
@@ -0,0 +1,7 @@
#!/bin/bash
red=$(tput setaf 1)
green=$(tput setaf 2)
default=$(tput sgr0)
sed "s/FAIL/${red}FAIL${default}/" | sed "s/OK/${green}OK${default}/"
+38
View File
@@ -0,0 +1,38 @@
#!/usr/bin/env python3
import sys
import os
import pathlib
import matplotlib.pyplot as plt
cwd = pathlib.Path( os.getcwd() )
data_path = cwd.joinpath( 'data.py' )
expected_path = cwd.joinpath( sys.argv[ 1 ] )
if sys.version_info >= ( 3, 6 ):
from importlib.machinery import SourceFileLoader
data = SourceFileLoader( 'data', str( data_path ) ).load_module()
expected = SourceFileLoader( 'expected', str( expected_path ) ).load_module()
elif sys.version_info >= ( 2, 7 ):
import imp
data = imp.load_source( 'data', str( data_path ) )
expected = imp.load_source( 'expected', str( expected_path ) )
else:
sys.stderr.write( 'Error: python version ' + sys.version + ' not supported!\n')
exit( -1 );
if ( len( sys.argv ) != 2 ):
raise( "Usage: {} expected_data.py" )
time_expected = [ i * expected.interval for i in range( len( expected.data ) ) ]
time_actual = [ i * expected.interval for i in range( len( data.float_data ) ) ]
plt.title( expected.title )
plt.plot( time_expected, expected.data, color = 'orange', label = 'expected' )
plt.plot( time_actual, data.float_data, color = 'cornflowerblue', label = 'actual' )
plt.ylabel( 'y' )
plt.xlabel( expected.xlabel )
plt.legend( bbox_to_anchor = ( 0.9, 1.05 ), ncol = 2 )
plt.show()