Main Content


Create sandbox for C code unit testing


success = createSandbox


success = createSandbox creates a sandbox folder and subfolders, and returns true if the method successfully creates a sandbox. The folder name is <LibraryFileName>_sandbox, where LibraryFileName is the LibraryFileName property of the sltest.CodeImporter object. This method applies only if the TestType property of the sltest.CodeImporter object is UnitTest.

The created folder subdirectories are:

  • autostub — Contains the auto_stub.h and auto_stub.c files, which are generated only if the imported code has undefined symbols.

  • manualstub — Contains the man_stub.h and man_stub.c files, which you can use to manually stub symbols. The man_stub.h header file includes the aggregated header if the Mode property setting of sltest.CodeImporter.SandboxSettings is GenerateAggregatedHeader.

  • include — Contains the header files required by the sandbox. This folder also contains a generated aggregatedHeader.h or interfaceHeader.h file. An aggregatedHeader.h file is generated if the Mode property setting of sltest.CodeImporter.SandboxSettings is GenerateAggregatedHeader. Otherwise, the folder contains an interfaceHeader.h file.

  • src — Contains copies of the code source files if the CopySource property of the sltest.CodeImporter.SandboxSettings object is true.

createSandbox("Overwrite",overwrite_option) overwrites the existing sandbox. If overwrite_option is "on", the method deletes the existing sandbox directory and creates a new sandbox directory. If overwrite_option is "off", the method deletes all folders except manualstub and generates a new sandbox. The method does not change the manualstub folder or its contents. The default is "off".

Output Arguments

expand all

Whether sandbox creation is successful, returned as a logical value.


expand all

This example assumes you have existing C code files to test.

  1. Create an sltest.CodeImporter object and specify myCodeTest as the Simulink library file name.

    codeimport_obj = sltest.CodeImporter("myCodeTest");

  2. Assign the source files to the SourceFiles property.

    codeimport_obj.CustomCode.SourceFiles = {"myCode1.c","myCode2.c"};

  3. Create the sandbox. To check that the sandbox exists, confirm that success is true.

    success = codeimport_obj.createSandbox

Introduced in R2021a