| 1 |
function filename = hashTableName(suite) |
| 2 |
% determines the file name of a hash table |
| 3 |
% |
| 4 |
% The MD5 file is assumed to be in the same directory as the test suite. |
| 5 |
% It has a file name "$SUITE.$ENV.$VER.md5" |
| 6 |
% where the following fields are filled: |
| 7 |
% $ENV: the environment (either "MATLAB" or "Octave") |
| 8 |
% $VER: the version (e.g. "3.8.0" for Octave, "8.3" for MATLAB 2014a) |
| 9 |
% $SUITE: the name (and path) of the test suite |
| 10 |
% |
| 11 |
% For the $VER-part, a fall-back mechanism is present that prefers the exact |
| 12 |
% version but will use the closest available file if such file does not |
| 13 |
% exist. |
| 14 |
[pathstr,name, ext] = fileparts(which(func2str(suite))); |
| 15 |
[env, version] = getEnvironment(); |
| 16 |
ext = sprintf('.%s.%s.md5', env, version); |
| 17 |
relFilename = [name ext]; |
| 18 |
filename = fullfile(pathstr, relFilename); |
| 19 |
|
| 20 |
if ~exist(filename,'file') |
| 21 |
% To avoid having to create a file for each release of the environment, |
| 22 |
% also other versions are tried. The file for different releases are checked |
| 23 |
% in the following order: |
| 24 |
% 1. the currently running version (handled above!) |
| 25 |
% 2. the newest older version (e.g. use R2014b's file in R2015a) |
| 26 |
% 3. the oldest newer version (e.g. use R2014a's file in R2013a) |
| 27 |
pattern = sprintf('%s.%s.*.md5', name, env); |
| 28 |
candidates = dir(fullfile(pathstr, pattern)); |
| 29 |
|
| 30 |
% We just need the file names. |
| 31 |
filenames = arrayfun(@(c)c.name, candidates, 'UniformOutput', false); |
| 32 |
|
| 33 |
% Add the expected version to the results, and sort the names by |
| 34 |
% version (this is the same as alphabetically). |
| 35 |
filenames = sort([filenames; {relFilename}]); |
| 36 |
nFiles = numel(filenames); |
| 37 |
iCurrent = find(ismember(filenames, relFilename)); |
| 38 |
% determine the fall-back candidates: |
| 39 |
iNewestOlder = iCurrent - 1; |
| 40 |
iOldestNewer = iCurrent + 1; |
| 41 |
|
| 42 |
inRange = @(idx)(idx <= nFiles && idx >= 1); |
| 43 |
if inRange(iNewestOlder) |
| 44 |
% use the newest older version |
| 45 |
relFilename = filenames{iNewestOlder}; |
| 46 |
elseif inRange(iOldestNewer) |
| 47 |
% use the oldest newer version |
| 48 |
relFilename = filenames{iOldestNewer}; |
| 49 |
else |
| 50 |
% use the exact version anyhow |
| 51 |
end |
| 52 |
|
| 53 |
filename = fullfile(pathstr, relFilename); |
| 54 |
end |
| 55 |
end |