#! /usr/bin/perl
# SCSN Stress Test
# Do stress test for one of the link.
#
# Usage: ./scsn_stress_test.pl Linkpair Link

require "modules/read_setup.pl";

if( $#ARGV != 1 ) {
    die "Give linkpair and link as parameter.";
}

$linkpair = $ARGV[0]; if( $linkpair < 0 || $linkpair > 3 ) { die "Strange linkpair." }
$link     = $ARGV[1]; if( $link     < 0 || $link     > 1 ) { die "Strange link."     }

# Parse _setup
( $DIR_NAME, $DATE, $ROC_SERIAL, $ROC_LAYER, $ROC_TYPE, $DCS_SERIAL, $WITH_PIPES, $INITIAL, $TRD_FEE ) = read_setup();
$ROC_NAME = "L".$ROC_LAYER."C".$ROC_TYPE."-".$ROC_SERIAL;

# Producing the test file.

$temp_wr = "/dcsnfs/scsn_stress_test_temp_wr.dat";
$temp_rd = "/dcsnfs/scsn_stress_test_temp_rd.dat";


open( F1, "> $temp_wr");
open( F2, "> $temp_rd");

printf(F1 "10 53248 0 127\n");
printf(F2 "10 53248 0 127\n");

for( $addr = 0 ; $addr < 1024 ; $addr++ ) {
    $x = int( rand(65536 * 65536) );
    printf(F1 "10  $addr $x 127\n");
    for( $slave = 1 ; $slave <= 36 ; $slave++ ) {
	printf(F2 "9 $addr $x $slave\n");
    }
}

#
# 1
#
printf("\n====\nWrite test.\n====\n");

system("ssh dcs$DCS_SERIAL /usr/local/sbin/dcs2trap -link $linkpair $link -q -i $temp_wr");

printf("\n====\nRead test.\n====\n");

system("ssh dcs$DCS_SERIAL /usr/local/sbin/dcs2trap -link $linkpair $link    -i $temp_rd");

# EOF
