This document explains the test framework and how to run tests for the ifcc compiler.
Tests are organized in the testfiles/ directory:
testfiles/
├── 00_base/ # Basic tests
│ ├── 00_return42.c
│ ├── 01_return_zero.c
│ └── 02_invalid_program.c
├── 01_variables/ # Variable tests
├── 02_preprocessor/ # Preprocessor tests
├── 03_arithmetic_*/ # Arithmetic tests
└── ...
Each test directory contains C source files that test specific language features.
From project root directory:
make test-allThis runs the test runner (ifcc-test.py) on all test files in testfiles/.
make test-01 # Run test suite 01 (variables)
make test-02 # Run test suite 02 (preprocessor)
make test-03 # Run test suite 03 (arithmetic)make test-x86-01 # Run test suite 01 with x86-64 target
make test-arm-01 # Run test suite 01 with ARM64 targetmake path/to/test_file.cThe test runner is a Python script that:
- Compiles each test file using
ifcc - Assembles and links the output with gcc
- Runs the compiled program
- Compares the exit code with the expected result
Test files are named with a prefix indicating expected behavior:
| Prefix | Description |
|---|---|
00_* to NN_* |
Ordered test number |
The test runner expects:
- Valid programs should return 0 for success
- Each test file may have an associated
.expectedfile with the expected return code
Add a new C file in the appropriate test directory.
If a test file contains //@unsupported at the beginning, it indicates that the feature tested is not supported by the compiler. The test runner will expect the compilation or execution to fail, and will mark it with a special icon (△) instead of treating it as an error.
# Compile
./compiler/ifcc testfiles/00_base/00_return42.c > output.s
# Assemble and link
gcc -o myprogram output.s
# Run
./myprogram; echo $?To verify correctness, compare the output with gcc:
# Compile with ifcc
./compiler/ifcc test.c > ifcc_output.s
gcc -o ifcc_program ifcc_output.s
# Compile with gcc
gcc -o gcc_program test.c
# Run both
./ifcc_program; echo $? # ifcc return code
./gcc_program; echo $? # gcc return codeTo automatically renumber test files in all directories:
make renumberThis ensures tests are numbered sequentially within each directory.
You can force the target platform (x86-64 or ARM64):
make test-x86-01
make test-arm-01