For v2003.06.00 Release $Revision: 1.46 $ java jar -g DEFAULT_BOOTCLASSPATH <Windows: Read and set from the registry when saved > ENV_PATH <Windows: Read and set from the registry when saved > COMPILER javac VIRTUALMACHINE java JAR jar DEBUGGER jdb Compiles the classes in the classes subdirectory. sub atl_cc($$$$\@\@) { my ( $lang,$src,$outDir,$cflags,$Defines,$Includes) = @_; # build the classpath my $separator = ($OSNAME eq "win32") ? ";" : ":"; my $classpath = &BuildCompleteJavaClassPath("-classpath ", $separator, ""); my $COMP = $Ini{'COMPILER'}; if ( !$COMP ) { print "Error: no compiler known for target (lang:\"$lang\")\n"; return 1; } &CreateDirectory( "$outDir/classes" ); my $status=0; $status=SystemP( "$COMP -d $outDir/classes $classpath \"$src\" $cflags" ); return $status; } 1; Build the jar file with the classes found in the classes subdirectory. sub atl_link($\@$\@$) { my ($OutputFile,$Objects,$Manifest,$JarOtherDir,$OutputDir) = @_; # Build jar file: my $JAR = $Ini{'JAR'}; if ( !$JAR ) { print "Error: no jar command known for target\n"; return 1; } $status=SystemP( "$JAR cfm \"$OutputFile\" $Manifest -C \"$OutputDir/classes\" ." ); return $status if ($status > 0); foreach $res (@$JarOtherDir) { $status=SystemP( "$JAR uf \"$OutputFile\" -C \"$res\" ." ); return $status if ($status > 0); } return $status; } 1; sub atl_exec($$$) { my ($JarFile,$MainClass,$Parameters) = @_; # build the classpath my $separator = ($OSNAME eq "win32") ? ";" : ":"; my $application = $JAVA_BUILDJARFILE ? $JarFile : "$INTDIR/classes"; my $classpath = &BuildCompleteJavaClassPath("-classpath ", $separator, $application); # build the JVMPI args and path if any my $jvmpi_args = &BuildJvmpiArgs("-Xint -Xrun", ""); my $jvmpi_path = &GetJvmpiPath; my $Vm = $Ini{'VIRTUALMACHINE'}; my $status = 0; if ($jvmpi_path) { if ($OSNAME eq "win32") { $ENV{'PATH'} = "$ENV{'PATH'};$jvmpi_path"; } else { $ENV{'LD_LIBRARY_PATH'} = "$ENV{'LD_LIBRARY_PATH'}:$jvmpi_path"; } } $status = SystemP( "$Vm $classpath $jvmpi_args $VIRTUAL_MACHINE_ARGUMENTS $MainClass $Parameters" ); return $status; } sub atl_execdbg($$$) { my ($JarFile,$MainClass,$Parameters) = @_; # build the classpath my $separator = ($OSNAME eq "win32") ? ";" : ":"; my $application = $JAVA_BUILDJARFILE ? $JarFile : "$INTDIR/classes"; my $classpath = &BuildCompleteJavaClassPath("-classpath ", $separator, $application); # build the JVMPI args and path if any my $jvmpi_args = &BuildJvmpiArgs("-Xint -Xrun", ""); my $jvmpi_path = &GetJvmpiPath; my $Vm = $Ini{'VIRTUALMACHINE'}; my $Debugger = $Ini{'DEBUGGER'}; if ($jvmpi_path) { if ($OSNAME eq "win32") { $ENV{'PATH'} = "$ENV{'PATH'};$jvmpi_path"; } else { $ENV{'LD_LIBRARY_PATH'} = "$ENV{'LD_LIBRARY_PATH'}:$jvmpi_path"; } } if ($OSNAME eq "win32") { SystemP( "$ENV{'COMSPEC'} /C START $Vm -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y $classpath $jvmpi_args $VIRTUAL_MACHINE_ARGUMENTS $MainClass" ); SystemP( "$ENV{'COMSPEC'} /C START $Debugger -attach 8000" ); } else { SystemP( "$Vm -Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=y $classpath $jvmpi_args $VIRTUAL_MACHINE_ARGUMENTS $MainClass &" ); SystemP( "xterm -e $Debugger -attach 8000" ); } return 0; } 1; ########################################################################## # # # # Rational Test RealTime # # # ####### # -*- javic command -*- # # # # # ################################################################################ use FileHandle ; STDOUT->autoflush(1); ################################################################################ # Where is the TDP $TARGETDIR = $ENV{'ATLTGT'}; # Where is the instrumentor binary $BINDIR = $ENV{'ATTOLBIN'}; # Where the Product is installed $SCRIPTDIR = $ENV{'TESTRTDIR'} . "/lib/scripts/"; # The name of the log file $LOGFILENAME = "javic.log"; # Which system ? $OSNAME = ($^O=~/win32/i) ? "win32" : "unix"; # Default value for intermediate directory : can be overriden by $UserEnv $INTDIR = "javi.jir"; # Ini File to be used $INIFILE = "tp.ini"; # BootClassPath my $BootClassPath = ""; # ClassPath my $ClassPath = ""; require $SCRIPTDIR . "Fcts.pl"; require $SCRIPTDIR . "Tools.pl"; require $SCRIPTDIR . "Products.pl"; ################################################################################ # List of instrumentation options (the one before --) my @InstrumentorOptions = (); # Maybe -studio_log=<log-file> is found on command-line my $UserLogFileName = ""; # Source Files List my @SourceFiles = (); # Instrumented Source Files List my @InstrSourceFiles = (); # Compiler command (first arg after --) my $Compiler = ""; # ... and its position in the list my $CompilerIndex = -1; # List of instrumentation options (the one after --) my @CompilerOptions = (); # Destination Directory my $DestDir = "."; # Intermediate Directory my $IntDirIndex = -1; # ClassPath Argument position my $ClassPathIndex = -1; ################################################################################ sub JavicFatalError ($) { my ($msg) = @_; print ("$SMALL_PRODUCT_NAME javic Error: " . $msg); exit (1); } ################################################################################ sub JavicVerbose ($) { my ($msg) = @_; print ($msg) if ($ENV{'ATTOLSTUDIO_VERBOSE'}); } ################################################################################ sub JavicDebug ($) { my ($msg) = @_; print ("$SMALL_PRODUCT_NAME javic Debug: " . $msg) if ($ENV{'ATTOLSTUDIO_DEBUG'}); } ################################################################################ sub JavicSystemPError ($) { my ($cmd) = @_; if ($ENV{'ATTOLSTUDIO_VERBOSE'}) { exit (1); } else { &JavicFatalError ("The following command-line caused an error:\n" . $cmd . "\n"); } } ################################################################################ sub JavicEnvironment { &JavicVerbose ("Perl Script Command Line (" . scalar(@ARGV) . " args):\n" . " javic.pl [" . join ("] [", @ARGV) . "]\n"); &JavicVerbose (" ATLTGT = " . $ENV{'ATLTGT'} . "\n"); &JavicVerbose (" ATTOLBIN = " . $ENV{'ATTOLBIN'} . "\n"); &JavicVerbose (" TESTRTDIR = " . $ENV{'TESTRTDIR'} . "\n"); } ################################################################################ sub ParseArgs { my $i = 0; foreach $arg (@ARGV) { &JavicDebug ("\$arg[$i] = [$arg]\n"); if ($arg eq "--") { if ($CompilerIndex >= 0) { &JavicFatalError ("Command string separator (--) found more than once\n"); } $CompilerIndex = $i + 1; &JavicDebug ("Found command string separator (--) at index $i\n"); } else { if ($CompilerIndex >= 0) { my @file_list = glob($arg); if ($i == $CompilerIndex) { $Compiler = @ARGV[$CompilerIndex]; &JavicDebug ("\$CompilerIndex = $CompilerIndex\n"); } elsif (-f $arg) { my $ext = &GetExtension ($arg); &JavicDebug ("Is $arg [$ext] a Java File?\n"); my $language = &LanguageOf ($ext, "Unknown"); &JavicDebug ("\$language = $language\n"); if ($language eq "JAVA") { @SourceFiles = (@SourceFiles, $arg); } else { @CompilerOptions = (@CompilerOptions, $arg); } } elsif (scalar(@file_list)>0 && -f @file_list[0]) { foreach $f (@file_list) { my $ext = &GetExtension ($f); &JavicDebug ("Is $f [$ext] a Java File?\n"); my $language = &LanguageOf ($ext, "Unknown"); &JavicDebug ("\$language = $language\n"); if ($language eq "JAVA") { @SourceFiles = (@SourceFiles, $f); } else { @CompilerOptions = (@CompilerOptions, $f); } } } else { if ($arg eq "-d") { $IntDirIndex = $i + 1; @CompilerOptions = (@CompilerOptions, $arg); } elsif ($arg eq "-bootclasspath") { $BootClassPath .= ( $BootClassPath ? $CLASSPATH_SEPARATOR : "" ) . @ARGV[$i+1]; @CompilerOptions = (@CompilerOptions, $arg); } elsif ($arg eq "-classpath") { $ClassPath .= ( $ClassPath ? $CLASSPATH_SEPARATOR : "" ) . @ARGV[$i+1]; $ClassPathIndex = $i + 1; } elsif ($ClassPathIndex != $i) { @CompilerOptions = (@CompilerOptions, $arg); } } } else { if (lc($arg) =~ /\-studio_log\=.*/) { ($UserLogFileName) = ($arg =~ /\-.*\=(.*)/); &JavicDebug ("\$UserLogFileName=$UserLogFileName\n"); } elsif ( ! &IsASetting($arg) ) { @InstrumentorOptions = (@InstrumentorOptions, $arg); } } } $i += 1; } if ($CompilerIndex == -1) { &JavicFatalError ("Command string separator (--) not found\n"); } if (-z $Compiler) { &JavicFatalError ("Compiler name not found\n"); } if (scalar(@SourceFiles) == 0) { &JavicFatalError ("No existing source files to instrument\n"); } if ($BootClassPath eq "") { $BootClassPath = $Ini{'DEFAULT_BOOTCLASSPATH'}; } if ($ClassPath eq "") { $ClassPath = $ENV{'CLASSPATH'}; } if ($IntDirIndex != -1) { $DestDir = @ARGV[$IntDirIndex]; $INTDIR = "$DestDir/javi.jir"; } &JavicDebug ("BootClassPath=$BootClassPath\n"); &JavicDebug ("ClassPath=$ClassPath\n"); &JavicDebug ("InstrumentorOptions (" . scalar(@InstrumentorOptions) . "):\n" . " [" . join ("] [", @InstrumentorOptions) . "]\n"); &JavicDebug ("SourceFiles (" . scalar(@SourceFiles) . "):\n" . " [" . join ("] [", @SourceFiles) . "]\n"); &JavicDebug ("Compiler:\n [" . $Compiler . "]\n"); &JavicDebug ("CompilerOptions (" . scalar(@CompilerOptions) . "):\n" . " [" . join ("] [", @CompilerOptions) . "]\n"); } ################################################################################ sub Instrument { if (-f $LOGFILENAME) { &ClearLogFile ($LOGFILENAME); } my $command = "$BINDIR" . "$PATH_SEPARATOR" . "javi"; if ($BootClassPath || $ClassPath) { my $classpath = "$BootClassPath" . "$CLASSPATH_SEPARATOR" . "$ClassPath"; $command .= " -classpath=\"$classpath\"" . "$CLASSPATH_SEPARATOR" . "."; if ($ClassPath) { $ClassPath = "$TARGETDIR" . $PATH_SEPARATOR . "lib" . "$CLASSPATH_SEPARATOR" . $ClassPath; } else { $ClassPath = "$TARGETDIR" . $PATH_SEPARATOR . "lib"; } } $command .= " \"-studio_log=$LOGFILENAME\""; $command .= " \"" . join ("\" \"", @InstrumentorOptions) . "\"" if (scalar(@InstrumentorOptions) > 0); $command .= " \"" . join ("\" \"", @SourceFiles) . "\""; $command .= " \"-destdir=$DestDir\""; my $status = SystemP ($command); &JavicDebug ("\$command=($command) returned $status\n"); if ($status) { &JavicSystemPError ($command . "\n"); } if (! open (LOG, "<$LOGFILENAME" )) { &JavicFatalError ("Cannot open $LOGFILENAME"); } if ($UserLogFileName && ! open (USERLOG, ">>$UserLogFileName" )) { &JavicFatalError ("Cannot open $UserLogFileName"); } while ($line = <LOG>) { &JavicDebug ($line); if ( $line =~ /^SRC /) { my ($src) = ($line =~ /^SRC (.*)/); &JavicDebug ("\$src=$src\n"); @InstrSourceFiles = (@InstrSourceFiles, $src); } if ($UserLogFileName) { print USERLOG $line; } } close (USERLOG) if ($UserLogFileName); close (LOG); &ClearLogFile ($LOGFILENAME); # Some late checks if (scalar(@InstrSourceFiles) == 0) { &JavicFatalError ("No instrumented source files to compile\n"); } } ################################################################################ sub Compile { $command = $Compiler; $command .= " \"" . join ("\" \"", @InstrSourceFiles) . "\""; $command .= " \"" . &GetJavaProductFile . "\""; $command .= " \"" . join ("\" \"", @CompilerOptions) . "\"" if (scalar(@CompilerOptions) > 0); $command .= " -classpath \"" . "$ClassPath" . "\""; if ($IntDirIndex == -1) { $command .= " -d ."; } $status = SystemP ($command); &JavicDebug ("\$command=($command) returned $status\n"); if ($status) { &JavicSystemPError ($command . "\n"); } } ################################################################################ # Maybe something to print first &JavicEnvironment; # Let's start here &EnterInScript; # Default settings require $SCRIPTDIR . "BatchJavaDefaults.pl"; # First parse command-line &ParseArgs; # Then Instrument what can be instrumented &Instrument; # Let's prepare TDP &PrepareJavaTargetPackage; # Then Compile the Instrumented Files &Compile; 0; # ################################################################################ use File::Copy; sub postGen() { my $d=shift; my $JavaHome; eval { require Win32::TieRegistry; import Win32::TieRegistry; my $Key = $Registry->{"HKEY_LOCAL_MACHINE\\SOFTWARE\\JavaSoft\\Java Development Kit\\1.4"}; return unless($Key); $JavaHome=$Key->{"JavaHome"}; }; return if($@); return unless($JavaHome ne ""); # Patch the tp.ini file. my $atl_cc_in = $d ."\\tp.ini"; my $atl_cc_out = $d ."\\tp.ini.out"; open (IN, $atl_cc_in) or print "Can't open \"$atl_cc_in\"\n"; open (OUT, ">".$atl_cc_out) or print "Can't open \"$atl_cc_out\"\n"; while (<IN>) { s/DEFAULT_BOOTCLASSPATH=\"<Windows: Read and set from the registry when saved >\"/DEFAULT_BOOTCLASSPATH=\"$JavaHome\\jre\\lib\\rt.jar\"/; s/ENV_PATH=\"<Windows: Read and set from the registry when saved >\"/ENV_PATH=\"$JavaHome\\bin;\$ENV{'PATH'}\"/; print OUT; } close (IN); close (OUT); # Rename the out file as the infile unlink ($atl_cc_in); rename ($atl_cc_out, $atl_cc_in); } 1; import java.io.*; JAVA_USR static { // Nothing to do } JAVA_USR static String UTF_8_unsupported = null; public static void waitForThreads() { Thread tab[] = new Thread[Products.max_threads]; while ( true ) { Thread current = Thread.currentThread ( ); current.yield(); int count = Thread.enumerate ( tab ); //System.err.println ( "Waiting for " + count + " threads" ); boolean wait = false; for ( int i = 0; i < tab.length; i++ ) { if ( tab[i] == null ) continue; if ( ( tab[i] != current ) && ( ! tab[i].isDaemon ( ) ) && ( tab[i].isAlive ( ) ) ) { wait = true; break; } } if ( wait ) { try { current.sleep(1000); } catch(InterruptedException E) { } } else { break; } } //System.err.println ( "All threads are there." ); } public static byte [] threadName() { String name = Thread.currentThread().getName ( ); if ( name != null ) { try { return name.getBytes ( "UTF-8" ); } catch ( java.io.UnsupportedEncodingException e ) { if ( UTF_8_unsupported == null ) { UTF_8_unsupported = new String ( "<UTF-8 unsupported>" ); } return ( UTF_8_unsupported.getBytes ( ) ); } } return null; } JAVA_USR public static FileOutputStream out_testrt = null; public static void outOpen() { try { out_testrt = new FileOutputStream ( Products.out_file ); } catch ( IOException e ) { System.err.println ( "TestRT: java.io.IOException in com.rational.testrealtime.Custom.outOpen()" ); } } public static void outWrite(byte[] buffer, int index) { if ( out_testrt == null ) { return; } try { out_testrt.write ( buffer, 0, index ); } catch ( IOException e ) { System.err.println ( "TestRT: java.io.IOException in com.rational.testrealtime.Custom.outWrite()" ); } } public static void outClose() { if ( out_testrt == null ) { return; } try { out_testrt.close ( ); } catch ( IOException e ) { System.err.println ( "TestRT: java.io.IOException in com.rational.testrealtime.Custom.outClose()" ); } } public static void pushError ( String msg ) { System.err.println ( msg ); } JAVA_USR static byte clock_unit[] = { (byte)'m', (byte)'s' }; public static long getClock() { return java.lang.System.currentTimeMillis ( ); } public static byte[] getClockUnit() { return clock_unit; } /* Add any extra includes or code */ JVMPI_STD JVMPI_USR int void *jvmpi_usr_malloc(JVMPI_SIZE_T size) { /* Code here the memory allocation function */ void *ptr=0; return(ptr); } void jvmpi_usr_free(void *ptr) { /* Code here the free function */ } JVMPI_STD JVMPI_USR FILE * JVMPI_FILE_TYPE jvmpi_usr_open(char *fileName) { /* Code here the open function */ JVMPI_FILE_TYPE f=(JVMPI_FILE_TYPE)0; return(f); } void *jvmpi_usr_write(JVMPI_FILE_TYPE file,char *buffer,int len) { /* Code here the write function */ } void *jvmpi_usr_close(JVMPI_FILE_TYPE file) { /* Code here the close function */ } JVMPI_STD JVMPI_USR void *jvmpi_usr_error(char *message) { /* Code here the error-print function */ printf("%s\n",message); } JVMPI_STD JVMPI_USR int jvmpi_usr_strncmp(const char *s1, const char *s2,JVMPI_SIZE_T n) { /* Code here the strncmp function */ return(0); } char *jvmpi_usr_strcmp(const char *s1, const char *s2) { /* Code here the strcmp function */ return(0); } int jvmpi_usr_strcpy(char *dest,const char *src) { /* Code here the strcpy function */ return(0); } char *jvmpi_usr_strstr(const char *haystack, const char *needle) { /* Code here the strstr function */ return(0); } JVMPI_SIZE_T jvmpi_usr_strlen(const char *s) { /* Code here the strlen function */ return(0); } JVMPI_STD JVMPI_USR unsigned long jvmpi_usr_getDateInMilliSec(void) { /* Code here the getDate function and return milliseconds */ } JVMPI_STD JVMPI_USR JVMPI_NONE int JVMPI_SOCKET_ID jvmpi_usr_connect(char *address,char *port) { /* Code here the connect function */ JVMPI_SOCKET_ID f; return(f); } int jvmpi_usr_recv(JVMPI_SOCKET_ID s,char *buffer,int len) { /* Code here the receive function */ return(0); } int jvmpi_usr_send(JVMPI_SOCKET_ID s,char *buffer,int len) { /* Code here the send function */ } int jvmpi_usr_socket_close(JVMPI_SOCKET_ID s) { /* Code here the close function */ return(0); } /* Add any extra code */ make