function varargout = simTestCases(obj, model, sldvData, varargin)
    %

    %   Copyright 2009-2021 The MathWorks, Inc.
    obj.initialize(model, sldvData, varargin{1});
    % Turn OFF 'backtrace' mode of warnings. If this mode is turned ON, MATLAB displays stack trace
    % after a warning is invoked. Store the state of 'backtrace' mode before turning it OFF, so that
    % it can be restored to its original value at the end of this function
    warnBTModeName = 'backtrace';
    warnBTModeState = warning('query', warnBTModeName);
    warning('off', warnBTModeName);

    % Restore state of 'backtrace' mode of warning before exiting from this function
    cleanupBacktrace = onCleanup(@()(warning(warnBTModeState.state, warnBTModeName)));

    try
        % Convert all test-cases / counterexamples to time-series format
        obj.convertSldvDataToTimeSeries();
        
        [simOut, covOut] = obj.runTests;

        numTestCases = length(obj.TcIdx);
        
        if ~strcmp(obj.OutputFormat,'SimulationOutput')
            outData(1:numTestCases) = struct('T',[],'X',[],'Y',[]);
            
            timeSaveName = obj.simInput.getModelParameter('TimeSaveName');
            stateSaveName = obj.simInput.getModelParameter('StateSaveName');
            outputSaveName = obj.simInput.getModelParameter('OutputSaveName');
            signalLoggingName = obj.simInput.getModelParameter('SignalLoggingName');
            
            for idx=1:numTestCases
                outData(idx).T = simOut{idx}.find(timeSaveName);
                outData(idx).X = simOut{idx}.find(stateSaveName);
                outData(idx).Y = ...
                    obj.reshapeOutValue(simOut{idx}.find(outputSaveName),...
                    simOut{idx}.find(signalLoggingName));
            end
        else
            outData(1:numTestCases) = Simulink.SimulationOutput;
            for idx=1:numTestCases
                outData(idx) = simOut{idx};
            end
        end
        obj.OutData = outData;
        
        if obj.GetCoverage
            if obj.IsXilMode && obj.isBDExtractedModel
                covOut = obj.fixTopModelCovIdForXIL(covOut);
            end

            % Collect cumulative coverage data, while ignoring
            % the empty covOut{i}. (g2611307)
            % TODO: g2636908: Give warning to the user that testcase{i}
            % produced empty coverage data and we have ignored such empty
            % data while collecting cumulative coverage data.
            cvData = covOut{1};
            jdx = 2;
            while isempty(cvData) && jdx <= numTestCases
                cvData = covOut{jdx};
                jdx = jdx+1;
            end
            for idx=jdx:numTestCases
                if ~isempty(covOut{idx})
                    cvData = cvData+covOut{idx};
                end
            end
            obj.CvData = cvData;
        end
    catch Mex
        obj.handleException(Mex);
    end
    
    varargout{1} = obj.OutData;
    varargout{2} = obj.CvData;

    obj.resetSessionData();
end

