This page describes how the on-site tests will look like and eventually will also contain description of the (big) homework assignment. Small homework assignments are mentioned in the respective lab pages.

Please, have a look at the course guide page for details how the grading works.

On-site tests

This is the schedule for the on-site tests. The test will be held at the beginning of the lab (duration of the test is 45 minutes).

Week (date) Topic
08 (April 7 - April 11) T1: Git versioning system
12 (May 5 - May 7 + May 15) T2: Shell scripting
14 (May 19 - May 23) T3: make build tool

You are expected to come to the lab you have enrolled to.

Because of state holiday on May 8, the T2 examination for Thursday labs will be postponed by a week. We are aware it is not optimal but the schedule for this semester has virtually no complete week (i.e., teaching in all days of a week) during the second half of the semester.

Test will be written on school machines. Make sure you can login there and that your environment is setup comfortably.

Your solution will be submitted through GitLab or through other Git repository: make sure you can perform a clone via a command-line client.

You are allowed to use our webpages, off-line manpages and you can consult your notes and solutions to examples that are part of the lab materials.

You are not allowed to use any other devices (cell phones, your own laptops etc.), consult other on-line resources (the machines will have restricted access to the Internet anyway) or communicate your solution to other students (and vice versa).

In other words, the on-site tests require that you can solve the tasks on your own with technical documentation only.

Any attempt to bypass the above rules (e.g. trying to search StackOverflow on your cell phone) means failing the course on the spot.

You are free to ask for clarification from your teacher if you do not understand the assignment, obviously. We can provide limited hints if it is clear that you are heading in the right direction and need only a little push.

Please, see also the general rules in the course guide.

Notes for the Git CLI exam

Information for students enrolled to the special 24bNSWI177x15 Tuesday lab.

If your SIS/GitLab username starts with [a-j], please, come at 8:50; if your login starts with [k-z], please, come at 9:40.

Update: instructions for the exam will be probably provided in a printed form. Please, let us know in advance (week at least) if this might be an issue for you (e.g., you need a bigger font). Thank you.

You will be expected to perform the following tasks in Git from the command-line (some might be required to execute on the remote machine linux.ms.mff.cuni.cz).

  • Configure your Git environment (author and e-mail)
  • Clone a repository (from gitolite3@linux.ms.mff.cuni.cz or from GitLab or generic HTTPS)
  • Create a commit
  • Create a branch
  • Switch between branches
  • Merge a branch (and solve any conflicts)
  • Push changes (branches) to server

Ensure that you can clone from gitolite3@linux.ms.mff.cuni.cz when using the school machines. Only authentication via public key will be available (i.e. upload your keys to keys/key.[0-9].pub files in your repository before the exam as explained in Lab 05).

To check that this works for you, please, perform the following steps.

Execute ssh -o ForwardAgent=no LOGIN@u-pl1.ms.mff.cuni.cz.

  • This will ask for your regular SIS password and will log you to u-pl1.ms.
  • u-pl1.ms is a virtually the same as any computer in the lab (i.e., the same files in ~).

Execute ssh gitolite3@linux.ms.mff.cuni.cz.

  • This will try to SSH using your keys on u-pl1 to the Gitolite repository.

  • You should see something like the following in the output. The important part is that Gitolite will greet you with your SIS login in the message (even though you are logging in as gitolite3 user); the list of repositories might differ.

    PTY allocation request failed on channel 0
    hello LOGIN, this is gitolite3@linux running gitolite3 3.6.13-5.fc41 on git 2.48.1
    
    R   lab05-LOGIN
    R   lab06-group-sum-ng
    
  • If you see the following, your keys are not setup correctly.

    gitolite3@linux.ms.mff.cuni.cz: Permission denied (publickey,password).
    

Feel free to store the URL gitolite3@linux.ms.mff.cuni.cz somewhere on the local disk in your $HOME so that you do not have to copy it manually during the exam.

You can even setup an alias in your ~/.ssh/config like this which would allow you to clone via git clone exam:lab05-LOGIN.

Host exam
    Hostname linux.ms.mff.cuni.cz
    User gitolite3

The focus of the exam is on working with Git. You will not be required to write any script on your own but we will be working with a repository containing the following script for printing simple bar charts in the console. You will be required to make some small modifications (such as fixing typos) but we will always guide you to the right place in the code.

import argparse
import sys

def parse_config():
    args = argparse.ArgumentParser(description='Console bar plot')
    args.add_argument('--columns', default=60, type=int, metavar='N')
    return args.parse_args()

def load_input(inp):
    values = []
    for line_raw in inp:
        line = line_raw.strip()
        if line.startswith('#') or not line:
            continue
        try:
            val = float(line)
        except ValueError:
            print(f"WARNING: ignoring invalid line '{line}'.", file=sys.stderr)
            continue
        values.append(val)
    return values

def print_barplot(values, scale, symbol):
    for val in values:
        print(symbol * round(val / scale))

def main():
    config = parse_config()
    values = load_input(sys.stdin)
    if not values:
        sys.exit(0)
    coef = max(values) / config.columns
    print_barplot(values, coef, '#')

if __name__ == '__main__':
    main()

Notes for the Shell scripting exam

Information for students enrolled to the special 24bNSWI177x15 Tuesday lab.

If your SIS/GitLab username starts with [a-j], please, come at 8:45; if your login starts with [k-z], please, come at 9:40.

The following list capture the topics (constructs, commands, …) you are expected to know for the exam. The list is not exhaustive (for example, we do not mention all the commands from our mini manual but covers all the major parts.

  • Construct a short pipeline with basic utilities such as cut, uniq, paste, bc or sort.
  • Use I/O redirection.
  • Iterate through lines of a file in a manner of while read ...; do ...; done < input.txt.
  • Use if, for and while constructs.
  • Use test or [ for controlling shell loops and conditions.
  • Capture standard output via $( cmd ).
  • Source external scripts via source or . (dot).
  • Use shell variables and shell functions to better capture the intent of data flow.
  • Understand getopts argument parsing.
  • Use basic regular expressions for searching (grep) or trivial replacements (via sed).

You will submit your solution again through repositories on gitolite3@linux.ms.mff.cuni.cz (again, from school machines). Make sure you remember Git basics (you will not need branching but you will not be able to submit without knowing at least about clone, commit and push).

You will again have access to D3S website with the lab materials and to the linux.ms.mff.cuni.cz machine but you will not have access to GitLab: make sure you clone your repositories in advance (if you need them).

Hints on Git setup are mentioned above.

Unless explicitly allowed, you cannot escape to another language (such as Python, AWK or PERL) during your implementation. In other words, submitting the solution as python3 -c 'import sys; for line in sys.stdin ... is not allowed.

The format of the exam will follow this pattern. You will receive an almost complete implementation of a certain assignment. Your task will be to implement the missing functions to complete the assignment.

The assignment will be split into different shell functions that you will implement. We will provide some basic (automated) tests that will be checking correctness of the individual functions (i.e. while it is recommended to read the whole script to understand the intent of it, it will be possible to implement some of the functions in isolation).

UPDATE: if you clone gitolite3@linux.ms.mff.cuni.cz:t02-example you will have access to a complete example for the exam. During the exam we will work with the same baseline code but for each lab there will be slight modifications of the actual assignment.

For example, the data file might be split into multiple files (perhaps by the lab ID), we might wish to print e-mail instead of student login or generate HTML instead of Markdown in the output (i.e., pipe it through Pandoc).

Please, use this opportunity to see how the code looks like (the skeleton will be the same) or how the tests are organized. It can save you some time during the exam and let you focus on the important aspects instead of deciphering how the files are organized.

While the code in repository t02-example will be used during the exam, the example below can be used for further practice.

The example assignment is to create a shell script that creates a histogram. Let us create the data first (you would have sample data from us, obviously):

mkdir data
for i in $( seq 1 100 ); do echo $(( i % 6 + i % 2 )) > data/$i.txt; done

Then the script will be executed like this:

./histogram.sh data/*.txt

And will print the following:

    0   ################
    2   ##################################
    4   ##################################
    6   ################

And you would receive the following code with instructions to implement functions summarize_input, repeat_char and extend make_histogram.

#!/bin/bash

set -ueo pipefail

# Count number of occurences of input lines.
# Arguments: none
# Input: VALUEs
# Output: VALUE COUNT rows
#
# We can safely assume that lines are identifiers without spaces.
#
# Example:
#  Input:
#    4
#    5
#    4
#  Output:
#    4 2
#    5 1
summarize_input() {
    # FIXME: summarize the input to the right format
    cat "$@"
}

# Repeat character multiple times.
# Arguments: SYMBOL COUNT
# Output: SYMBOL repeated COUNT times on stdout.
repeat_char() {
    # FIXME: print according to input arguments
    echo "===="
}

# Plots a histogram.
# Input: lines, each line contains VALUE COUNT pair
# Output: Trivial histogram, see printf for format in implementation.
make_histogram() {
    local value
    local count

    # FIXME: iterate over all lines (keep the format intact!)
    read value count
    printf '%5s\t%s\n' "$value" "$( repeat_char '#' "$count" )"
}

main() {
    cat "$@" | summarize_input | make_histogram
}

main "$@"

Quizzes

Quizzes will be given on labs 02, 03, 04, 05, 06 and 07.

Small homework tasks

Big homework: project setup

Setup a CI for Python based project and prepare it for further distribution. This will include the following tasks (explained in more detail below).

  • Make the source code into proper Python package.
  • Create GitLab CI job for pytest (after merging their implementation/fixes).
  • Create GitLab CI job for BATS tests (after some fixes and another Git merge).

We expect you will use external tools to drive your implementation but you must understand all the parts before submitting it and you must mark all parts that were not authored by you personally (and if you are using tools such as ChatGPT, you must submit the whole log of your communication with the tool).

Context

In this task you will be working with a simple Python project that is able to render Jinja templates (install Jinja2 package, not Jinja).

As a trivial example (which you can also find in the examples subdirectory of the project repository) it will be able to perform the following transformation.

We will have the following array (list) in JSON:

[
  {
     "name": "Introduction to Linux",
     "code": "NSWI177",
     "homepage": "https://d3s.mff.cuni.cz/teaching/nswi177/"
  },
  {
     "name": "Operating Systems",
     "code": "NSWI200",
     "homepage": "https://d3s.mff.cuni.cz/teaching/nswi200/"
  }
]

We will have the following input file:

Our courses
===========

Below is a list of (almost) all of our courses.

And we will have the following template. Note that control structures of the template use {% (or {%- to strip surrounding whitespace) and {{ for variable expansion.

{{ content }}

{%- for course in data -%}
 * [{{ course.name }} ({{ course.code }})]({{ course.homepage }}) {{ NL }}
{%- endfor %}

When executed with our renderer (exact command is in the project README), we will get the following output.

Our courses
===========

Below is a list of (almost) all of our courses.

* [Introduction to Linux (NSWI177)](https://d3s.mff.cuni.cz/teaching/nswi177/)
* [Operating Systems (NSWI200)](https://d3s.mff.cuni.cz/teaching/nswi200/)

Source code

The source code for the above implementation was already prepared for you and soon you will have access to a new project under teaching/nswi177/2025 subtree in GitLab where you will work.

Do not copy this code to your normal submission repository and work in the new project-LOGIN repository (except for the ai.log as explained below).

The repository also contains several tests. There are unit tests in Python (using pytest) as well as higher-level tests (let us call them integration tests even that might be a bit overstated) written in BATS.

The invocation is described in the project README.

Commit only files that ought to be committed. Definitely do not commit your virtual environment directories, __pycache__ subdirectories or Pythonic .egg and .whl files.

The assignment

Your main task is to setup basic CI on GitLab for this project and prepare the project for distribution.

The CI must execute the Python unit tests and fail the job on any error. The preparation for distribution means that after your changes we will be able to install the templater via pip and have the templater available as nswi177-jinja-templater command.

Your task is not to copy the project to PyPI but only setup your repository on our GitLab.

In other words, the following commands would install the templater into a fresh virtual environment and the invocation of the last command would print a short help from our program (we assume we are in an empty directory that is not related in any way to any clone of your project).

python3 -m venv templater-venv
. ./templater-venv/bin/activate
pip install git+ssh://git@gitlab.mff.cuni.cz/teaching/nswi177/2025/project-LOGIN
nswi177-jinja-templater --help

And for the CI we expect that your project would have a job unittests running the Python tests.

Please, make sure you name the job unittests and you keep all your CI configuration in a single .gitlab-ci.yml file.

The CI should use the python:3.13-alpine image and should install the versions from requirements.txt file. We expect that pytest (and perhaps other test-related libraries) will not be mentioned in the requirements.txt but rather inside requirements-dev.txt file.

You will notice that the tests are not passing as some of the Jinja filters are not implemented.

Do not worry, though. Your coworker Alice already implemented them in her branch in her repository gitolite3@linux.ms.mff.cuni.cz:templater-alice.

Merge her implementation into your repository to get the full implementation.

The merging is a required part of the task and we require that you perform a normal merge (or a fast-forward) but never a rebase.

If you do everything correctly, your CI job log would look like this (we have blurred the used commands for obvious reasons).

Then you will extend the CI to also execute the BATS tests.

We expect that you will add a new job called integrationtests that installs the package (so that the nswi177-jinja-templater command is available) and run all the BATS files in the tests subdirectory (recall that simple pip install . should work like a charm).

For unittests you install dependencies from requirements.txt for best reproducibility while for integrationtests we install the whole package, thus usually with relaxed requirements on the exact versions of the dependencies.

You will need to install bats via apk add first (it is okay to install this package on every CI run).

Note that the current implementation in common.bash invokes the program via call to env PYTHONPATH=src python3 -m nswi177.templater – change this to call nswi177-jinja-templater instead. You will also need to replace --kill-after switch for the timeout command to plain -k as the long variant is not supported in Alpine.

The amount of BATS tests is quite low so you should also merge the work of your co-workers Bob and Charlie into your repository. Again, perform a normal merge and not a rebase when integrating their work.

Bob has his repository at gitolite3@linux.ms.mff.cuni.cz:templater-bob while Charlie put his copy to our website to https://d3s.mff.cuni.cz/f/teaching/nswi177/202425/templater-charlie.git.

In case of conflicts make sure you resolve them correctly – you certainly do not want to drop any of the tests unless they are the same.

To summarize the subtasks, following list might help you.

  • Merge Alice implementation.
  • Setup pyproject.toml, setup.cfg and requirements.txt (and requirements-dev.txt) for project-login project on GitLab.
  • Setup GitLab CI that runs the Python tests in unittests job.
  • Merge tests from Bob and Charlie.
  • Fix invocation of the command in BATS tests.
  • Fix call to timeout to be timeout -k 30 "${timeout}" "$@".
  • Add integrationtests job to run all the BATS tests.

Submission and grading

Submit your solution into the project-LOGIN repository on GitLab.

We will check that the project can be installed via pip install git+https://gitlab.../project-LOGIN/ and that your CI configuration is correct (after all the merges your jobs should be in the green). We will check that the Python code can be executed after pip install -r requirements.txt via python3 -m src.nswi177.templater (or via python -m nswi177.templater if the package itself is also installed) and that the Pytests can be run after installing from requirements-dev.txt.

When you copy fragments from sites such as StackOverflow we expect you will comment them directly in the appropriate sources, communication with AI-driven sites should be stored into exam/project/ai.log file in your normal submission repository (student-LOGIN), again a plain text file with clearly marked portions with your input and with the answers.

The submission deadline is 2025-06-01.

There is no automated testing for this task: after all you are setting the testing for the project.

Please, make sure (e.g., using the list above) you have not forgotten any part. There are no hidden traps or tricks in this assignment, you only need to follow the instructions to complete it successfully.