NASA-SW-VnV / CoCoSim

Automated Analysis Framework for Simulink/Stateflow models.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Calls to Z3 from MATLAB fail

mfry90 opened this issue · comments

Issue observed on Ubuntu 20.04 with Matlab 9.8.0.1323502 (R2020a) on commit 35e9bf3.

Symptoms:

When attempting to "Prove properties" of a CoCoSim .slx model, Matlab reports the following error:

(Error)[TOLUSTRE] Simulink To Lustre Syntax check has failed. The parsing error is the following:                                                                                                                  
...                                                                                                                                                                                                                
<Log class="warn" source="parse">Couldn't determine Z3 version</Log>

image

This error occurs in checkSyntaxError.m, when executing a variant of the following line:
[status, output] = system('kind2 --enable interpreter -xml example_PP.KIND2.lus --timeout 60 --z3_bin z3')

Executing the same exact command in a terminal produces no errors.

The same behavior is observed when directly calling Z3 from the terminal and MATLAB, i.e.:
Terminal:

$ z3 -h                                                                                                                                                                                                            
Z3 [version 4.8.10 - 64 bit].                                                                                                                                                                                      

Matlab:

>> [status, output] = system('z3 -h')                                                                                                                                                                              
output =                                                                                                                                                                                                           
                                                                                                                                                                                                                   
    'z3: /usr/local/MATLAB/R2020a/sys/os/glnxa64/libstdc++.so.6: version `GLIBCXX_3.4.26' not found (required by z3)                                                                                               
     '                                                                                                                                                                                                             

Cause:

TLDR: The MATLAB library /usr/local/MATLAB/R2020a/sys/os/glnxa64/libstdc++.so.6 is outdated and Z3 requires a more recent library (for example /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28). See https://www.mathworks.com/matlabcentral/answers/329796-issue-with-libstdc-so-6 for more info.

Fix:

Start MATLAB from the terminal with the LD_PRELOAD flag:
LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.28 /usr/local/MATLAB/R2020a/bin/matlab
This will load the more recent libstdc++.so instead of that provided by MATLAB.

CoCoSim uses many binaries: Kind2, LustreC, Z3, Yices...
Matlab has a problem of detecting these binaries.
The first solution is described by @mfry90 above.
The second solution is to add these binaries to Matlab PATH:

setenv('PATH', ['/usr/local/bin' ':' getenv('PATH')]);

CoCoSim uses the full path of these binaries. If you follow the following instruction, there is no need to add the binaries to the Matlab path.

Solution 1: Follow the INSTALL.md instruction and add these binaries to the Path used by CoCoSim:

You can use our script to install all needed binaries and we take care of adding them to the right path.
In your terminal, go first to scripts folder in cocosim and run the install_cocosim script.

>cd scripts
>./install_cocosim 

If the script failed. You can install the binaries by yourself and copy them to the following paths.
If you have linux machin, change osx by linux.

KIND2 binary: CoCoSim/tools/verfiers/osx/bin/kind2

Z3 binary: CoCoSim/tools/verfiers/osx/bin/z3

LUSTREC binary: CoCoSim/tools/verfiers/osx/bin/lustrec

LUSTRET binary: CoCoSim/tools/verfiers/osx/bin/lustret

LUCTREC_INCLUDE_DIR: CoCoSim/tools/verfiers/osx/include/lustrec

Solution 2: Change the PATH of the binaries to your preference

If you want to customize the binaries paths go to CoCoSim/tools/tools_config.m and change the values of variables KIND2, Z3, LUSTREC, LUSTRET, LUCTREC_INCLUDE_DIR to your preferences.

For example, in line 118 of tools_config.m script you can change the value of KIND2 variable:
From

KIND2 = fullfile(solvers_path, 'bin', 'kind2');

To

KIND2 = '/your/own/path';

While the need to have the binaries' paths set is important (noted in the last post from @hbourbouh), this issue actually isn't driven by a missing binary path. For example, I had previously followed Solution 1 from the last post, and MATLAB is correctly able to find dependent binaries (>> system('kind2 -h; lustrec -help') return the expected results).

The issue raised only occurs with Z3 and is due to MATLAB being unable to find the right stdc++ library that Z3 relies upon. It really has nothing to do with CoCoSim per se, and is more of a bug with MATLAB. Until they make the necessary fix (not sure if they will), the work around that I previously posted will address the issue.

This issue only popped up using Ubuntu 20.04 and Matlab R2020a. I don't see the same issue when using Ubuntu 18.04 and Matlab R2020a.

Thanks @mfry90 for the information. I will keep this issue open.