Commit ed5b7f6a authored by Erik von Reis's avatar Erik von Reis

Merge branch 'local_dc_reads_rtsystab' into 'master'

Update local_dc to allow reading the model list from a systab file.

See merge request cds/advligorts!182
parents 2abc4570 a23d9256
......@@ -5,6 +5,7 @@ target_link_libraries(local_dc PUBLIC
util)
configure_file(test_local_dc.sh.in test_local_dc.sh @ONLY)
configure_file(test_local_dc_with_systab.sh.in test_local_dc_with_systab.sh @ONLY)
add_executable(test_local_dc_unit_tests tests/test_local_dc_unit_tests.c)
target_include_directories(test_local_dc_unit_tests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
......@@ -13,6 +14,10 @@ add_test(NAME "test_local_dc"
COMMAND /bin/bash ./test_local_dc.sh
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
add_test(NAME "test_local_dc_with_systab"
COMMAND /bin/bash ./test_local_dc_with_systab.sh
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
add_test(NAME "test_local_dc_unit_tests"
COMMAND ./test_local_dc_unit_tests
WORKING_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}")
......
......@@ -378,6 +378,7 @@ send_to_local_memory( int nsys, int len, int do_wait )
int __CDECL
main( int argc, char* argv[] )
{
char systab_buffer[ 1024 ];
int counter = 0;
int nsys = 1;
int ii = 0;
......@@ -402,6 +403,7 @@ int __CDECL
int iter;
int do_wait = 1;
int do_bothways;
const char* systab_fname = NULL;
args_handle arg_parser = NULL;
sysname = NULL;
......@@ -444,9 +446,17 @@ int __CDECL
's',
ARGS_NO_LONG,
"systems",
"Space seperated list of systems.",
"Space seperated list of systems (conflicts with --systab).",
&sysname_,
"" );
args_add_string_ptr(
arg_parser,
ARGS_NO_SHORT,
"systab",
"systab file",
"Read the model list from the given systab file (conflicts with -s).",
&systab_fname,
"" );
args_add_string_ptr( arg_parser,
'l',
ARGS_NO_LONG,
......@@ -479,7 +489,23 @@ int __CDECL
{
exit( 1 );
}
if ( ( strcmp( sysname_, "" ) == 0 && strcmp( systab_fname, "" ) == 0 ) ||
( strcmp( sysname_, "" ) != 0 && strcmp( systab_fname, "" ) != 0 ) )
{
fprintf( stderr, "Exactly one of -s or --systab must be specified.\n" );
exit( 1 );
}
if ( strcmp( systab_fname, "" ) != 0 )
{
if ( extract_models_from_table_file(
systab_fname, systab_buffer, sizeof( systab_buffer ) ) != 0 )
{
fprintf(
stderr, "Unable to extract model list from %s", systab_fname );
exit( 1 );
}
sysname_ = systab_buffer;
}
buffer_name = malloc( strlen( buffer_name_ ) + 1 );
strncpy( buffer_name, buffer_name_, strlen( buffer_name_ ) + 1 );
sysname = malloc( strlen( sysname_ ) + 1 );
......@@ -500,6 +526,7 @@ int __CDECL
fprintf( stderr, "Max data block size is 100 MB\n" );
return -1;
}
fprintf( stderr, "sysnames = %s\n", sysname );
if ( strcmp( logfilename, "-" ) != 0 )
......@@ -523,10 +550,10 @@ int __CDECL
if ( sysname != NULL )
{
fprintf( stderr, "System names: %s\n", sysname );
sprintf( modelnames[ 0 ], "%s", strtok( sysname, " " ) );
sprintf( modelnames[ 0 ], "%s", strtok( sysname, " \t" ) );
for ( ;; )
{
char* s = strtok( 0, " " );
char* s = strtok( 0, " \t" );
if ( !s )
break;
sprintf( modelnames[ nsys ], "%s", s );
......
......@@ -5,8 +5,95 @@
#ifndef DAQD_TRUNK_LOCAL_DC_UTILS_H
#define DAQD_TRUNK_LOCAL_DC_UTILS_H
#include <ctype.h>
#include <limits.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
/*!
* @brief extract a list of models to run from a systab file
* @param f The file to read models from
* @param dest destination buffer
* @param size size of the destination
* @return 0 on success
*/
static int
extract_models_from_table( FILE* f, char* dest, int size )
{
char hostname[ HOST_NAME_MAX + 1 ];
char buffer[ 1024 ];
char* cur = 0;
if ( gethostname( hostname, sizeof( hostname ) ) != 0 )
{
return 1;
}
hostname[ sizeof( hostname ) - 1 ] = '\0';
while ( fgets( buffer, sizeof( buffer ), f ) != NULL )
{
buffer[ sizeof( buffer ) - 1 ] = '\0';
/* end the line at \n or comments */
cur = buffer;
while ( *cur )
{
if ( *cur == '\n' || *cur == ';' || *cur == '#' )
{
*cur = '\0';
break;
}
++cur;
}
cur = buffer;
/* find the first space */
while ( *cur && !isspace( *cur ) )
{
++cur;
}
/* move passed the space if we can */
while ( isspace( *cur ) )
{
*cur = '\0';
++cur;
}
if ( strcmp( hostname, buffer ) == 0 )
{
strncpy( dest, cur, size );
dest[ size - 1 ] = '\0';
return 0;
}
}
return 1;
}
/*!
* @brief extract a list of models to run from a systab file
* @param table The name of the file to read models from
* @param dest destination buffer
* @param size size of the destination
* @return 0 on success
*/
static int
extract_models_from_table_file( const char* table, char* dest, int size )
{
FILE* f = 0;
int rc = 0;
if ( !table || !dest || size < 100 )
{
return 1;
}
f = fopen( table, "rt" );
if ( !f )
{
return 1;
}
rc = extract_models_from_table( f, dest, size );
fclose( f );
return rc;
}
/*!
* @brief given the tail of a system name + dcu + rate, extract the dcu + rate.
......
#!/bin/bash
CWD="@CMAKE_CURRENT_BINARY_DIR@"
TDIR=""
PID_STREAM=0
PID_LOCAL_DC=0
function kill_proc {
if [ $1 -gt 0 ]; then
echo "Closing process $1"
kill $1
fi
}
function cleanup {
if [ "x$TDIR" != "x" ]; then
if [ -d $TDIR ]; then
rm -rf "$TDIR"
fi
fi
kill_proc $PID_STREAM
kill_proc $PID_LOCAL_DC
}
LOCAL_DC="$CWD/local_dc"
if [ ! -x "$LOCAL_DC" ]; then
echo "local_dc is required"
exit 1
fi
FE_STREAM_CHECK="$CWD/../fe_stream_test/fe_stream_check"
if [ ! -x "$FE_STREAM_CHECK" ]; then
echo "fe_stream_check is required"
exit 1
fi
FE_MULTI_STREAM_TEST="$CWD/../fe_stream_test/fe_multi_stream_test"
if [ ! -x "$FE_MULTI_STREAM_TEST" ]; then
echo "fe_multi_stream_test is required"
exit 1
fi
if [ ! -r /dev/gpstime ]; then
echo "the gpstime module must be loaded, configured, and accessible by this user"
exit 1
fi
if [ ! -r /dev/mbuf ]; then
echo "the mbuf module must be loaded, configured, and accessible by this user"
exit 1
fi
PYTHON=""
which python > /dev/null
if [ $? -eq 0 ]; then
PYTHON=`which python`
else
which python3 > /dev/null
if [ $? -eq 0 ]; then
PYTHON=`which python3`
else
echo "Cannot find python or python3"
exit 1
fi
fi
trap cleanup EXIT
TDIR=`$PYTHON -c "from __future__ import print_function; import tempfile; print(tempfile.mkdtemp())"`
mkdir "$TDIR/ini_files"
mkdir "$TDIR/logs"
echo "Ini dir = $TDIR/ini_files"
"$FE_MULTI_STREAM_TEST" -S -i "$TDIR/ini_files" -M "$TDIR/ini_files/master" -k 300 -D 5,6,7,250,255, > "$TDIR/logs/models" &
PID_STREAM=$!
echo "Streamer PID = $PID_STREAM"
sleep 1
echo `hostname` > "$TDIR/rtsystab" mod5 mod6 mod7 mod250 mod255
"$LOCAL_DC" -m 100 --systab "$TDIR/rtsystab" -d "$TDIR/ini_files" -b "local_dc" > "$TDIR/logs/local_dc" &
PID_LOCAL_DC=$!
echo "Local_dc PID = $PID_LOCAL_DC"
"$FE_STREAM_CHECK" -m local_dc -s 100 -v -c "$TDIR/ini_files/mod5.ini" "$TDIR/ini_files/tpchn_mod5.par" \
-c "$TDIR/ini_files/mod6.ini" "$TDIR/ini_files/tpchn_mod6.par" \
-c "$TDIR/ini_files/mod7.ini" "$TDIR/ini_files/tpchn_mod7.par" \
-c "$TDIR/ini_files/mod250.ini" "$TDIR/ini_files/tpchn_mod250.par" \
-c "$TDIR/ini_files/mod255.ini" "$TDIR/ini_files/tpchn_mod255.par"
RESULT=$?
exit $?
#echo "Press enter to continue..."
#DUMMY=""
#read DUMMY
\ No newline at end of file
......@@ -2,8 +2,8 @@
// Created by jonathan.hanks on 7/15/20.
//
#include <stdio.h>
#include "local_dc_utils.h"
#include <stdio.h>
int
test_extract_dcu_rate_from_name( const char* input,
......@@ -185,10 +185,101 @@ do_trim_tests( )
trim_dcuid_and_rate_from_name( NULL );
}
void
do_extract_models_from_table_tests_ok( )
{
char hostname[ HOST_NAME_MAX + 1 ];
char alt_host[ HOST_NAME_MAX + 1 + 10 ];
char buffer[ 1024 ];
int i = 0;
int rc = 0;
FILE* f = 0;
if ( gethostname( hostname, sizeof( hostname ) ) != 0 )
{
fprintf( stderr, "Unable to get system hostname\n" );
exit( 1 );
};
f = tmpfile( );
if ( !f )
{
fprintf( stderr, "Unable to open temp file for test\n" );
exit( 1 );
}
for ( i = 0; i < 10; ++i )
{
sprintf( alt_host, "%s_%d", hostname, i );
fprintf( f, "%s a b c d\n", alt_host );
}
fprintf( f, "%s e f g", hostname );
rewind( f );
rc = extract_models_from_table( f, buffer, sizeof( buffer ) );
fclose( f );
if ( rc != 0 )
{
fprintf( stderr, "bad return code on extract_models_from_table\n" );
exit( 1 );
}
if ( strcmp( buffer, "e f g" ) != 0 )
{
fprintf( stderr,
"bad string from extract_models_from_table '%s'\n",
buffer );
exit( 1 );
}
}
void
do_extract_models_from_table_tests_fail( )
{
char hostname[ HOST_NAME_MAX + 1 ];
char alt_host[ HOST_NAME_MAX + 1 + 10 ];
char buffer[ 1024 ];
int i = 0;
int rc = 0;
FILE* f = 0;
if ( gethostname( hostname, sizeof( hostname ) ) != 0 )
{
fprintf( stderr, "Unable to get system hostname\n" );
exit( 1 );
};
f = tmpfile( );
if ( !f )
{
fprintf( stderr, "Unable to open temp file for test\n" );
exit( 1 );
}
for ( i = 0; i < 10; ++i )
{
sprintf( alt_host, "%s_%d", hostname, i );
fprintf( f, "%s a b c d\n", alt_host );
}
rewind( f );
rc = extract_models_from_table( f, buffer, sizeof( buffer ) );
fclose( f );
if ( rc == 0 )
{
fprintf( stderr,
"unexpected error code on extract_models_from_table, expected "
"to fail.\n" );
exit( 1 );
}
}
do_extract_models_from_table_tests( )
{
do_extract_models_from_table_tests_ok( );
do_extract_models_from_table_tests_fail( );
}
int
main( int argc, char* argv[] )
{
do_extract_tests( );
do_trim_tests( );
do_extract_models_from_table_tests( );
return 0;
}
\ No newline at end of file
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