#!/usr/bin/env rexx /******************************************************************************/ /* */ /* smoke.rex - The quick test of the RVM */ /* ===================================== */ /* */ /* Usage: rexx smoke.rex [rvm | js | both] [PATTERN] */ /* rexx smoke.rex --make [PATTERN] */ /* */ /* Runs every program of cases/ (or those whose name contains PATTERN) on */ /* the RVM of ooRexx (rvm), on the RVM of JavaScript (js) or on both (the */ /* default), and compares what each one writes on its standard output and */ /* standard error, and its return code, with what ooRexx gives: NAME.out, */ /* NAME.err and NAME.rc next to NAME.rex. Prints one line for each program */ /* that differs, and a summary; the return code is the number of programs */ /* that differ (0: OK). */ /* */ /* The programs are chosen so that, together, they use every instruction of */ /* the R-code that the compiler generates, and most of the built-in */ /* functions, errors and directives (see README.md): a change of the parser */ /* that the compiler depends on (the AST, .Parser.BIFInfo, the error */ /* messages, INTERPRET) shows up here in a few minutes. */ /* */ /* --make writes the expected files with ooRexx itself (rexx NAME.rex). */ /* */ /* First it runs astcheck.rex, which checks that every class of the AST has */ /* a compiler (or a reason not to): one more failure if not. */ /* */ /* Needs: ooRexx 5 (rexx) and, for js, Node.js 22 or later (node), on the */ /* PATH. The programs run from a copy of cases/ in the temporary directory */ /* (TMPDIR, TEMP or /tmp: never in the package, which a synchronized folder */ /* may hold), with their standard input empty; a path to that copy in what */ /* they write is shown as "". */ /* */ /* Runs on Unix (sh, timeout from coreutils) and on Windows (cmd.exe; in */ /* place of timeout, timeout.mjs, next to this file, with Node.js). On */ /* Windows the reference is the native ooRexx of that machine, run again */ /* for every program (--live, the default there): the expected files are */ /* made on Unix, and several programs are about Unix (sh, cat, /tmp, */ /* PARSE SOURCE). --files compares with them anyway (see Normal), and */ /* --live does the same as Windows on Unix. */ /* */ /* Usage, in full: rexx smoke.rex [--live | --files] [--dir DIR] */ /* [--batch K [--size N]] [rvm | js | both] [PATTERN] */ /* */ /* --dir runs the programs of another directory of cases (tests/e2e/cases, */ /* tests/oo/cases...: relative to the RVM, or absolute) against the native */ /* ooRexx (--live), with the expected files of those suites (NAME.expected, */ /* NAME.expected-err, NAME.expected-rc; NAME-rvm-only: not run on ooRexx). */ /* --batch K runs only the K-th group of 50 programs (--size N: of N), in */ /* the order of their names. */ /* */ /* A program that differs leaves its expected files and what the engine */ /* gave in rvm-smoke-failed/ of the temporary directory (TMPDIR, TEMP or */ /* /tmp; see Keep), emptied at the start of every run. The last line says */ /* where. */ /* */ /* This file is part of the RVM, the Rexx Virtual Machine */ /* [See https://rexx.epbcn.com/rexx-parser/] */ /* */ /* Copyright (c) 2026 Josep Maria Blasco */ /* */ /* License: Apache License 2.0 (https://www.apache.org/licenses/LICENSE-2.0) */ /* */ /******************************************************************************/ Parse Arg args -- --live: what ooRexx gives here and now is the expected output of every -- program (the default on Windows, where the expected files, made on -- Unix, do not hold: PARSE SOURCE, the commands, the ends of line...); -- --files: the expected files, also on Windows. -- --dir DIR: the programs of DIR (relative to the RVM, as tests/e2e/cases, -- or absolute) in place of cases/, always --live, with the conventions of -- the suites (see Override). --batch K: only the K-th group of 50 of the -- programs chosen (--size N: of N). live = .File~separator == "\" dir = ""; batch = 0; size = 50; pipes = .False Do While WordPos( Word( args, 1 ), "--live --files --dir --batch --size --pipes" ) > 0 Select Case Word( args, 1 ) When "--live" Then live = .True When "--files" Then live = .False When "--dir" Then Do; dir = Word( args, 2 ); args = SubWord( args, 2 ); End When "--batch" Then Do; batch = Word( args, 2 ); args = SubWord( args, 2 ); End When "--size" Then Do; size = Word( args, 2 ); args = SubWord( args, 2 ); End When "--pipes" Then pipes = .True End args = SubWord( args, 2 ) End Parse Var args engine pattern make = .False If engine == "--make" Then Do make = .True engine = "" End Else If WordPos( engine, "rvm js both" ) == 0 Then Do pattern = engine engine = "both" End If engine == "both" Then engines = "rvm js" Else engines = engine here = FileSpec( "Location", .context~package~name ) rvm = .File~new( here".." )~absolutePath bin = .File~new( rvm"/../.." )~absolutePath cases = here"cases" If dir \== "" Then Do If SysIsFileDirectory( dir ) Then cases = .File~new( dir )~absolutePath Else cases = .File~new( rvm"/"dir )~absolutePath If \ SysIsFileDirectory( cases ) Then Do Say "smoke: no such directory:" dir Exit 255 End live = .True -- (tests/e2e/e2e.sh gives its programs pipes: some ask STDOUT where it is.) If Pos( "e2e", dir ) > 0 Then pipes = .True End Call Value "REXX_PATH", bin, "ENVIRONMENT" Call Value "RVM_CLOCK", "virtual", "ENVIRONMENT" -- Windows: cmd.exe in place of sh (see Run and Quote), TEMP in place of -- TMPDIR, and what the programs write normalized (see Normal). windows = .File~separator == "\" sl = .File~separator base = Value( "TMPDIR", , "ENVIRONMENT" ) If base == "" Then base = Value( "TEMP", , "ENVIRONMENT" ) If base == "" Then base = "/tmp" temp = SysTempFileName( base || sl"rvm-smoke-?????" ) Call SysMkDir temp -- Where the programs that differ leave their files (see Keep): emptied -- now, so that what is there is from this run. keep = base || sl"rvm-smoke-failed" Call SysFileTree keep || sl"*", "old.", "FO" Do i = 1 To old.0 Call SysFileDelete old.i End -- The programs run in a copy of cases/ in the temporary directory (work), -- never where the package is: there a folder that a program (Dropbox, -- OneDrive, an antivirus) watches may hold a file that a run has just -- deleted, and the next run, which makes it again, cannot open it. work = temp || sl"cases" Call SysMkDir work Call SysFileTree cases"/*", "now.", "FO" Do i = 1 To now.0 Call SysFileCopy now.i, work || sl || FileSpec( "Name", now.i ) End -- The files of work now (see Tidy). Call SysFileTree work || sl"*", "now.", "FO" original = .Set~new Do i = 1 To now.0 original~put( now.i ) End Call SysFileTree cases"/*.rex", "files.", "FO" names = .Array~new Do i = 1 To files.0 name = FileSpec( "Name", files.i ) name = Left( name, Length( name ) - 4 ) If pattern \== "", Pos( pattern, name ) == 0 Then Iterate names~append( name ) End names = names~sort If batch > 0 Then Do total = ( names~items + size - 1 ) % size first = ( batch - 1 ) * size + 1 If first > names~items Then Do Say "smoke: there are" total "batches of" size Exit 255 End names = names~section( first, size ) Say "smoke: batch" batch "of" total"," names[1] "to" names[names~items] End start = Time( "E" ) failed = 0 runs = 0 -- First, the classes of the AST with no compiler (astcheck.rex): its -- lines, and one failure if any. If \ make Then Do Address System "rexx" Quote( here"astcheck.rex" ) If rc \= 0 Then failed += 1 End Do name Over names If make Then Do Call Run "rexx" Quote( name".rex" ), name Call Save name runs += 1 Iterate End -- A program that depends on the clock (NAME.live), or every program -- with --live: what ooRexx gives now is the expected output, not the -- files of --make. expected = cases If live | SysIsFile( cases"/"name".live" ) Then Do expected = temp"/expected" If \ SysIsFileDirectory( expected ) Then Call SysMkDir expected If Pos( "-rvm-only", name ) > 0 Then Do -- (no native run) Call Put expected"/"name".out", "" Call Put expected"/"name".err", "" Call Put expected"/"name".rc", "0" || "0a"x End Else Do Call Run "rexx" Quote( name".rex" ), name Call Save name, expected End Call Override name, expected End Do e Over engines~makeArray( " " ) Call RunEngine e, name runs += 1 what = Compare( name, expected ) If what \== "" Then Do failed += 1 Say "FAIL" e name":" what Call Keep name, e, expected End End End Call SysFileTree temp"/*", "left.", "FO" Do i = 1 To left.0 Call SysFileDelete left.i End Call SysFileTree temp"/expected/*", "left.", "FO" Do i = 1 To left.0 Call SysFileDelete left.i End Call SysRmDir temp"/expected" Call SysFileTree work || sl"*", "left.", "FO" Do i = 1 To left.0 Call SysFileDelete left.i End Call SysRmDir work Call SysRmDir temp secs = Format( Time( "E" ) - start, , 0 ) If make Then Do Say "smoke: expected files written for" names~items "programs ("secs"s)" Exit 0 End If failed == 0 Then Say "smoke: OK," runs "runs of" names~items "programs on" engines "("secs"s)" Else Do Say "smoke:" failed "of" runs "runs differ ("names~items "programs on" engines"," secs"s)" If SysIsFileDirectory( keep ) Then Say "smoke: their files are in" keep End Exit failed -- Run 'command' from work (the copy of cases/), with its outputs in the temporary directory. -- The suites' expected files that replace what ooRexx gives (a deliberate -- divergence, or a program that ooRexx does not run): NAME.expected (the -- standard output), NAME.expected-err (the standard error; @CASES@ is the -- directory of the cases, here ""), NAME.expected-rc. Override: Use Arg name, dir If SysIsFile( cases"/"name".expected" ) Then Call Put dir"/"name".out", ReadAll( cases"/"name".expected" ) If SysIsFile( cases"/"name".expected-err" ) Then Call Put dir"/"name".err", ChangeStr( "@CASES@", ReadAll( cases"/"name".expected-err" ), "" ) If SysIsFile( cases"/"name".expected-rc" ) Then Call Put dir"/"name".rc", Strip( Strip( ReadAll( cases"/"name".expected-rc" ), , "0a"x ), , "0d"x ) || "0a"x Return -- Run program 'name' on engine 'e' (rvm or js). -- .RexxInfo~executable is then the RVM's launcher (RVM_EXECUTABLE, as -- tests/oo/oo-e2e.sh: rvm and js/rvm, rvm.cmd and js\rvm.cmd on Windows), so -- that a program started by the program runs on the same RVM. RunEngine: Use Arg e, name If e == "rvm" Then launcher = rvm || sl"rvm" Else launcher = rvm || sl"js"sl"rvm" If windows Then launcher = launcher".cmd" Call Value "RVM_EXECUTABLE", launcher, "ENVIRONMENT" If e == "rvm" Then Call Run "rexx" Quote( rvm"/rvm.rex" ) Quote( name".rex" ), name Else Call Run "node" Quote( rvm"/js/rvm.mjs" ) Quote( name".rex" ), name Call Value "RVM_EXECUTABLE", "", "ENVIRONMENT" Return -- On Windows: "cd /d" (it may be another drive), NUL for /dev/null, and -- timeout.mjs for timeout(1), which Windows does not have. Run: Use Arg command, name If pipes, windows Then -- Standard output and error as pipes (timeout.mjs writes them out; on -- Windows Node's are named pipes). line = "cd /d" Quote( work ) "&& node" Quote( here"timeout.mjs" ) - "--out" Quote( temp || sl"out" ) "--err" Quote( temp || sl"err" ) - "120" command "<" "NUL" Else If pipes Then -- Unix: pipes of the shell, as tests/e2e/e2e.sh (not Node's: they are -- sockets, and ooRexx says a socket is PERSISTENT and then hangs in -- SEEK +0 WRITE CHAR on it); the status in a file of its own. line = "cd" Quote( work ) "&& { { timeout 120" command ""Quote( temp"/status" )"; } 2>&1 1>&3 | cat >"Quote( temp"/err" )";" - "} 3>&1 | cat >"Quote( temp"/out" ) Else If windows Then line = "cd /d" Quote( work ) "&& node" Quote( here"timeout.mjs" ) - "120" command "<" "NUL" ">"Quote( temp || sl"out" ) - "2>"Quote( temp || sl"err" ) Else line = "cd" Quote( work ) "&& timeout 120" command - "<" "/dev/null" ">"Quote( temp"/out" ) "2>"Quote( temp"/err" ) Address System line If pipes, \ windows Then rc = Strip( ChangeStr( "0a"x, ReadAll( temp"/status" ), "" ) ) Call Stream temp"/rc", "C", "Open Write Replace" Call LineOut temp"/rc", rc Call Stream temp"/rc", "C", "Close" Call Tidy Return -- What a program left in work (a file it did not delete: on Windows, its -- "rm" does not exist), deleted, so that every run, ooRexx's and each -- RVM's, starts from the same files. Tidy: -- The session queue too: the programs ooRexx runs here share this one's -- (rxapi's), and lines one of them left (hostemu's FIFO) would be read by -- the next. Do While Queued() > 0 Parse Pull . End Call SysFileTree work || sl"*", "now.", "FO" Do i = 1 To now.0 If \ original~hasIndex( now.i ) Then Call SysFileDelete now.i End Return -- What differs from the expected files ("": nothing). -- A program that differs: its expected files and what engine 'e' gave, -- normalized, in rvm-smoke-failed/ of the temporary directory (never in the -- tree of the project: NAME.expected.KIND and NAME.ENGINE.KIND), to look at -- them or send them. Keep: Use Arg name, e, dir If \ SysIsFileDirectory( keep ) Then Call SysMkDir keep Do kind Over .Array~of( "out", "err", "rc" ) Call Put keep"/"name".expected."kind, ReadAll( dir"/"name"."kind ) Call Put keep"/"name"."e"."kind, Normal( ReadAll( temp"/"kind ) ) End Return Put: Procedure Use Arg file, data Call Stream file, "C", "Open Write Replace" Call CharOut file, data Call Stream file, "C", "Close" Return Compare: Use Arg name, dir diffs = "" Do kind Over .Array~of( "out", "err", "rc" ) want = ReadAll( dir"/"name"."kind ) -- An expected file with CRLF (a checkout that converts the ends of line) If windows Then want = ChangeStr( "0d0a"x, want, "0a"x ) If Normal( ReadAll( temp"/"kind ) ) \== want Then diffs = diffs kind End Return Strip( diffs ) -- Write the expected files (to cases/, or to 'dir'). Save: Use Arg name, dir = ( cases ) Do kind Over .Array~of( "out", "err", "rc" ) file = dir"/"name"."kind Call Stream file, "C", "Open Write Replace" Call CharOut file, Normal( ReadAll( temp"/"kind ) ) Call Stream file, "C", "Close" End Return -- A path to work (where the programs run: the copy of cases/) as "". On Windows, also: the ends of line as on -- Unix (CRLF -> LF), the path found without regard to case (the drive -- letter may come in either), and "\" as "/", so that the -- expected files are the same on every system. Normal: Procedure Expose work windows Use Arg text If \ windows Then Return ChangeStr( work, text, "" ) text = ChangeStr( "0d0a"x, text, "0a"x ) text = text~caselessChangeStr( work, "" ) Return ChangeStr( "\", text, "/" ) ReadAll: Procedure Use Arg file If \ SysIsFile( file ) Then Return "" n = Chars( file ) If n == 0 Then data = "" Else data = CharIn( file, 1, n ) Call Stream file, "C", "Close" Return data -- A word for the shell: 'word' for sh, "word" for cmd.exe (a path on -- Windows cannot contain a double quote). Quote: Procedure Expose windows Use Arg word If windows Then Return '"'word'"' Return "'" || ChangeStr( "'", word, "'\''" ) || "'"