bugGNU Octave - Bugs: bug #57456, "test rand.cc" produces...

 
 

bug #57456: "test rand.cc" produces onCleanup error

Submitter:  Rik <rik5>
Submitted:  Fri 20 Dec 2019 10:43:05 PM UTC
   
 
Category:  Interpreter Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Regression
Status:  Fixed Assigned to:  jwe
Originator Name:  Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Mon 03 Feb 2020 09:47:13 PM UTC, comment #2: 

Ultimately this came down to the fact that there is no guaranteed ordering to the execution of onCleanup blocks.  I checked in a fix here https://hg.savannah.gnu.org/hgweb/octave/rev/a077eadd1325.

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Sat 01 Feb 2020 02:28:06 AM UTC, comment #1: 

Attaching the file rand.cc-tst which contains the BIST tests.  With this one can start Octave and run


test rand.cc-tst


With version 5.1 this works, with the development branch the result is


warning: onCleanup: error caught while executing cleanup function:
'restore_rand_states' undefined near line 17, column 17


This is a regression.  On the other hand, if this is not the right way to be using %!function and onCleanup then just say so.

The code is

%!function restore_rand_states (seed, state)
%!  rand ("seed", seed.rand);
%!  rande ("seed", seed.rande);
%!  randg ("seed", seed.randg);
%!  randn ("seed", seed.randn);
%!  randp ("seed", seed.randp);
%!  rand ("state", state.rand);
%!  rande ("state", state.rande);
%!  randg ("state", state.randg);
%!  randn ("state", state.randn);
%!  randp ("state", state.randp);
%!endfunction
%!shared __random_statistical_tests__, old_seed, old_state, restore_state
%! ## Flag whether the statistical tests should be run in "make check" or not
%! __random_statistical_tests__ = 0;
%! ## Save and restore the states of each of the random number generators
%! ## that are tested by the unit tests in this file.
%! old_seed.rand = rand ("seed");
%! old_seed.rande = rande ("seed");
%! old_seed.randg = randg ("seed");
%! old_seed.randn = randn ("seed");
%! old_seed.randp = randp ("seed");
%! old_state.rand = rand ("state");
%! old_state.rande = rande ("state");
%! old_state.randg = randg ("state");
%! old_state.randn = randn ("state");
%! old_state.randp = randp ("state");
% restore_state = onCleanup (@() restore_rand_states (old_seed, old_state));


The code can be made to work by putting the %!function after the %!shared declaration.  It was my understanding that %!shared only cleared variables, and not functions, for a %!test block.


(file #48325)

Rik <rik5>
Group administrator
Fri 20 Dec 2019 10:43:05 PM UTC, original submission:  

Code to reproduce:


test rand.cc
warning: onCleanup: error caught while executing cleanup function:
'restore_rand_states' undefined near line 17, column 17


This is probably because of changes to scoping of functions and function handles.  Also, the test.m file is exceedingly complex with try/catch, unwind_protect blocks, and eval'ing of functions in to existence.  It's not a surprise that something small could affect this test.

The test code within rand.cc is


/*
%% Restore all rand* "seed" and "state" values in order, so that the
%% new "state" algorithm remains active after these tests complete.
%!function restore_rand_states (seed, state)
%!  rand ("seed", seed.rand);
%!  rande ("seed", seed.rande);
%!  randg ("seed", seed.randg);
%!  randn ("seed", seed.randn);
%!  randp ("seed", seed.randp);
%!  rand ("state", state.rand);
%!  rande ("state", state.rande);
%!  randg ("state", state.randg);
%!  randn ("state", state.randn);
%!  randp ("state", state.randp);
%!endfunction

%!shared __random_statistical_tests__, old_seed, old_state, restore_state
%! ## Flag whether the statistical tests should be run in "make check" or not
%! __random_statistical_tests__ = 0;
%! ## Save and restore the states of each of the random number generators
%! ## that are tested by the unit tests in this file.
%! old_seed.rand = rand ("seed");
%! old_seed.rande = rande ("seed");
%! old_seed.randg = randg ("seed");
%! old_seed.randn = randn ("seed");
%! old_seed.randp = randp ("seed");
%! old_state.rand = rand ("state");
%! old_state.rande = rande ("state");
%! old_state.randg = randg ("state");
%! old_state.randn = randn ("state");
%! old_state.randp = randp ("state");
%! restore_state = onCleanup (@() restore_rand_states (old_seed, old_state));
*/



Rik <rik5>
Group administrator

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #48325:  rand.cc-tst added by rik5 (15KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 4 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2020-02-03 rik5 StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2020-02-01 rik5 Attached File- Added rand.cc-tst, #48325
        StatusNone Confirmed

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code