s21_tetris/materials/instructions_for_testing.md
2024-11-08 07:48:45 +00:00

3.4 KiB
Raw Blame History

Instructions for running tests

In addition to testing for correct output data, the autotest system will check your program and its source code for the following points:

  • Style tests. To check how much the beauty of your code meets the standards, for example, you can test your code using the clang-format utility. The materials/linters folder contains the .clang-format file, which contains the necessary settings for the style test. This configuration file extends its action to all files that lie with it in the directory or in the directories below. So in order for these settings to apply to your source code files, copy .clang-format to the src folder.

    To run the style check, run the following command:
    clang-format -n src/sourcefile_name.c

    To download clang-format, enter one of the following commands in the terminal:
    brew install clang-format
    or if you have root rights (for Ubuntu / Linux Mint / Debian)
    sudo apt install clang-format

    Required version of clang-format:
    Mac 18.1.6
    Linux 18.1.3

    Google Style: https://google.github.io/styleguide/cppguide.html

  • Test for correct operation with memory. When writing C programs, it is very important to watch for memory leaks. To do this the valgrind utility is quite often used in Unix-like operating systems. However, OS X has some troubles with valgrind support, so it is possible to use the leaks utility instead. We will not go into the mechanism of operation of these utilities now — if you are interested, you can read about it on Google.

    LEAKS

    To run your executable file using this utility, type in the terminal:
    leaks -atExit -- ./main.out | grep LEAK:

    Pay your attention that there is | grep LEAK: command. We use it to short leaks output to see only lines with leaks if they are there. If you want to see the whole output, just remove this command.

    When you run your executable file using leaks you may see an error:

    dyld: could not load inserted library /usr/local/lib/libLeaksAtExit.dylib because image not found

    Its because leaks did not find libLeaksAtExit.dylib library.
    You need to type the following commands in this case.

    cd /usr/local/lib  
    sudo ln -s /Applications/Xcode.app/Contents/Developer/usr/lib/libLeaksAtExit.dylib
    

    Additionally:
    Use the -exclude option of leaks to filter out leaks in functions with known memory leaks. This option helps reduce the amount of extra information reported by leaks.

    VALGRIND

    To install it on your computer, type one of the following commands:
    brew install valgrind
    or if you have root rights (for Ubuntu / Linux Mint / Debian)
    sudo apt install valgrind
    To run your executable file using this utility, type in the terminal:
    valgrind --tool=memcheck --leak-check=yes. /main. out

    It is strongly recommended not to use valgrind utility in OS X, use leaks utility instead.

  • Build test. The program can be checked for correct build on a test system environment. This will require Docker installed. If the system has a docker, then you can go to the materials/build directory and run the run.sh script from there. The script will wrap your solution in docker and run it along with a typical build script.