ttyTest — A PTY Serial Emulator in Zig
PTY_serial_emulator is a small Zig tool that creates a UART-like serial shell over a pseudoterminal (PTY). It gives you an interactive
command environment accessible via screen, minicom, or plain cat — useful
for testing serial protocols, terminal emulators, or just having fun with PTYs.
How it works
The program opens a PTY master/slave pair via /dev/ptmx, configures the slave in raw mode, and creates
a symlink ttyUART0 pointing to the slave device. It then runs an interactive shell over the master
fd — a serial terminal, no hardware required.
In another terminal, connect to the PTY:
The symlink ttyUART0 points to the actual PTY slave (e.g. /dev/pts/5), so any serial-aware
tool can connect to it transparently.
Built-in commands
Once connected, you get a small shell with these commands:
| Command | Description |
|---|---|
help | Show available commands |
hello | Greeting |
echo <text> | Echo back text |
date / time | Show current date/time |
whoami | Show user name |
info | Show system info |
clear | Clear screen |
cowsay <text> | Cow says something |
exit / quit | Disconnect |
Why build this?
PTYs are one of those UNIX mechanisms that feel like magic until you poke at them. This project demystifies the
PTY master/slave dance — open() on /dev/ptmx, grantpt(), unlockpt(), ptsname() — and wraps it in a simple interactive shell. It's also handy as a stand-in serial device
for testing terminal emulators or serial monitor tools.
Building
Running tests