Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

asg/mem-alloc: Update README and fix test script name #23

Merged
merged 4 commits into from
Oct 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 56 additions & 10 deletions content/assignments/memory-allocator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ The test suite consists of `.c` files that will be dynamically linked to your li
You can find the sources in the `tests/snippets/` directory.
The results of the previous will also be stored in `tests/snippets/` and the reference files are in the `tests/ref/` directory.

The automated checking is performed using `run-tests.py`.
The automated checking is performed using `run_tests.py`.
It runs each test and compares the syscalls made by the `os_*` functions with the reference file, providing a diff if the test failed.

## API
Expand Down Expand Up @@ -180,9 +180,39 @@ gcc -shared -o libosmem.so osmem.o helpers.o ../utils/printf.o

## Testing and Grading

The testing is automated and performed with the `run-tests.py` script from the `tests/` directory.
Testing is automated.
Tests are located in the `tests/` directory:

Before running `run-tests.py`, you first have to build `libosmem.so` in the `src/` directory and generate the test binaries in `tests/snippets`.
```console
student@so:~/.../mem-alloc/tests$ ls -F
Makefile grade.sh@ ref/ run_tests.py snippets/
```

To test and grade your assignment solution, enter the `tests/` directory and run `grade.sh`.
Note that this requires linters being available.
The easiest is to use a Docker-based setup with everything installed, as shown in the section ["Running the Linters"](#running-the-linters).
When using `grade.sh` you will get grades for correctness (maximum `90` points) and for coding style (maximum `10` points).
A successful run will provide you an output ending with:

```console
### GRADE


Checker: 90/ 90
Style: 10/ 10
Total: 100/100


### STYLE SUMMARY


```

### Running the Checker

To run only the checker, use the `run_tests.py` script from the `tests/` directory.

Before running `run_tests.py`, you first have to build `libosmem.so` in the `src/` directory and generate the test binaries in `tests/snippets`.
You can do so using the all-in-one `Makefile` rule from `tests/`: `make check`.

```console
Expand Down Expand Up @@ -243,29 +273,45 @@ test-all ........................ passed ... 5
Total: 90/100
```

**NOTE:** By default, `run-test.py` checks for memory leaks, which can be time-consuming.
To speed up testing, use the `-d` flag or `make check-fast` to skip memory leak checks, but remember to run `make check` before submitting your assignment to ensure it meets all criteria.
**NOTE:** By default, `run_tests.py` checks for memory leaks, which can be time-consuming.
To speed up testing, use the `-d` flag or `make check-fast` to skip memory leak checks.

### Running the Linters

To run the linters, use the `make lint` command in the `tests/` directory.
Note that the linters have to be installed on your system: [`checkpatch.pl`](https://.com/torvalds/linux/blob/master/scripts/checkpatch.pl), [`cpplint`](https://github.com/cpplint/cpplint), [`shellcheck`](https://www.shellcheck.net/) with certain configuration options.
It's easiest to run them in a Docker-based setup with everything configured:

```console
student@so:~/.../mem-alloc/tests$ make lint
[...]
cd .. && checkpatch.pl -f checker/*.sh tests/*.sh
[...]
cd .. && cpplint --recursive src/ tests/ checker/
[...]
cd .. && shellcheck checker/*.sh tests/*.sh
```

### Debugging

`run-tests.py` uses `ltrace` to capture all the libcalls and syscalls performed.
`run_tests.py` uses `ltrace` to capture all the libcalls and syscalls performed.

The output of `ltrace` is formatted to show only top level library calls and nested system calls.
For consistency, the heap start and addresses returned by `mmap()` are replaced with labels.
Every other address is displayed as `<label> + offset`, where the label is the closest mapped address.

`run-tests.py` supports three modes:
`run_tests.py` supports three modes:

- verbose (`-v`), prints the output of the test
- diff (`-d`), prints the diff between the output and the ref
- memcheck (`-m`), prints the diff between the output and the ref and announces memory leaks

If you want to run a single test, you give its name or its path as arguments to `run-tests.py`:
If you want to run a single test, you give its name or its path as arguments to `run_tests.py`:

```console
student@os:~/.../mem-alloc/tests$ python run-tests.py test-all
student@os:~/.../mem-alloc/tests$ python run_tests.py test-all
OR
student@os:~/.../mem-alloc/tests$ python run-tests.py snippets/test-all
student@os:~/.../mem-alloc/tests$ python run_tests.py snippets/test-all
```

### Debugging in VSCode
Expand Down
10 changes: 5 additions & 5 deletions content/assignments/memory-allocator/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ check:

check-fast:
$(MAKE) clean_src clean_snippets src snippets
python run-tests.py -d
python run_tests.py -d

lint:
-cd .. && checkpatch.pl -f src/*.c tests/src/*.c
-cd .. && checkpatch.pl -f checker/*.sh
-cd .. && cpplint --recursive src/ tests/ checker/
-cd .. && shellcheck checker/*.sh
-cd .. && checkpatch.pl -f src/*.c tests/snippets/*.c
-cd .. && checkpatch.pl -f checker/*.sh tests/*.sh
-cd .. && cpplint --recursive src/ tests/
-cd .. && shellcheck checker/*.sh tests/*.sh
# -cd .. && pylint tests/*.py

snippets/%: snippets/%.c
Expand Down
2 changes: 0 additions & 2 deletions content/assignments/memory-allocator/tests/run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,8 +458,6 @@ def parse_args():


def main():
os.makedirs("out", exist_ok=True)

total = 0
test_name, verbose, diff, memcheck = parse_args()

Expand Down
Loading